Heuristic

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Heuristic Simple representation of how far you have left to go

As you approach the goal, the estimate gets smaller.


4 Cases

H(n) = 0

H(n) = a(n) You can solve a problem nearly instantly.

H(n) <= a(n) Were aiming for this one admissibility. (Where you always underestimate
things.)
A* search is if youre always underestimating, you will always get an optimal solution.

H(n) > a(n)


The heuristic allows you to find the optimal solution faster.
Eg. Heuristic 0 10 max flights.
Valid Heuristic 15 max flights no problem.
If heuristic is overestimating, youre not guaranteed to find the optimal path.
Is c(n) + h(n) > next search states c(n) + h(n)?
SearchState.getCost();
Class heuristic {
Int getValue (searchstate ss) {
Return ss.getFlightsList().size();
}
Int compare (searchState s1, searchstate s2) {
If (s1.getCost() + heuristic.getValue(s1) < s2.getCost() + heuristic.getValue(s2)) {

The difference with having a heuristic inside search class and heuristic outside of your search class is that
the encapsulated one is better design.
E in the assignment is flights.
Search state {
Node: C
parentHistory [1,b]
cost: 10
}
We dont have a list of nodes, we have a list of search states.
Graph contains a bunch of node classes.

class DGNode<E> {
public DGNode(E a) {
this.node = a;
}
public void addChild(E a) {
this.children.add(a);
}

private E node;
private List<E> connections;
}

BFS has:
toVisit (priority queue containing places to visit)
visited (list containing visited places)

parent (list containing parent corresponding to visited places)


Assignment is NOT a graph of cities
Assignment is about searching over "states" not cities
"Start Node" no flights complete
"Destination Node" required flights complete
Consider your start node, you haven't made any flights.
Now consider your destination node, you will have completed all the flights you need to.
How would you 'travel' between these two states?
How would you know if you're approaching the goal state?
Research Strategy Pattern

You might also like