Skip to content

Commit

Permalink
rework RemainingWeightHeuristic interface
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed May 21, 2013
1 parent ebb1598 commit 35376db
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public ShortestPathTree getShortestPathTree(RoutingRequest options, double relTi

// heuristic calc could actually be done when states are constructed, inside state
State initialState = new State(options);
double initialWeight = heuristic.computeInitialWeight(initialState, rctx.target);
heuristic.initialize(initialState, rctx.target);
spt.add(initialState);

// Priority Queue.
Expand All @@ -112,8 +112,7 @@ public ShortestPathTree getShortestPathTree(RoutingRequest options, double relTi
int initialSize = rctx.graph.getVertices().size();
initialSize = (int) Math.ceil(2 * (Math.sqrt((double) initialSize + 1)));
OTPPriorityQueue<State> pq = qFactory.create(initialSize);
// this would allow continuing a search from an existing state
pq.insert(initialState, initialWeight);
pq.insert(initialState, 0);

// options = options.clone();
// /** max walk distance cannot be less than distances to nearest transit stops */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ public BidirectionalRemainingWeightHeuristic(Graph graph) {
}

@Override
public double computeInitialWeight(State s, Vertex target) {
public void initialize(State s, Vertex target) {
recalculate(s.getVertex(), target, s.getOptions(), false);
return computeForwardWeight(s, target);
}

@Override
Expand Down Expand Up @@ -188,10 +187,6 @@ private void recalculate(Vertex origin, Vertex target, RoutingRequest options,
}
}

@Override
public void reset() {
}

/**
* RemainingTimeHeuristic interface
*/
Expand All @@ -218,4 +213,10 @@ public RemainingWeightHeuristic getInstanceForSearch(RoutingRequest opt) {
}
}

@Override
public void reset() {}

@Override
public void abort() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class DefaultRemainingWeightHeuristic implements RemainingWeightHeuristic
private double targetY;

@Override
public double computeInitialWeight(State s, Vertex target) {
public void initialize(State s, Vertex target) {
this.options = s.getOptions();
this.useTransit = options.getModes().isTransit();
this.maxSpeed = getMaxSpeed(options);
Expand All @@ -56,9 +56,6 @@ public double computeInitialWeight(State s, Vertex target) {

targetX = target.getX();
targetY = target.getY();

return distanceLibrary.fastDistance(s.getVertex().getY(), s.getVertex().getX(), targetY,
targetX) / maxSpeed;
}

/**
Expand Down Expand Up @@ -157,6 +154,8 @@ public static double getMaxSpeed(RoutingRequest options) {
}

@Override
public void reset() {
}
public void reset() {}

@Override
public void abort() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public LBGRemainingWeightHeuristic(Graph g, RoutingRequest opt) {
}

@Override
public double computeInitialWeight(State s, Vertex target) {
public void initialize(State s, Vertex target) {
recalculate(target);
return 0;
}

@Override
Expand Down Expand Up @@ -96,15 +95,17 @@ private void recalculate(Vertex target) {
}
}

@Override
public void reset() {
}

private static class GraphAndDirection extends T2<Graph, Boolean> {
private static final long serialVersionUID = 20110901L;

public GraphAndDirection(Graph g, Boolean i) {
super(g, i);
}
}

@Override
public void reset() {}

@Override
public void abort() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,26 @@ the License, or (props, at your option) any later version.
*/
public interface RemainingWeightHeuristic extends Serializable {

/**
* It is important to evaluate the initial weight before computing additional weights,
* because this method also performs any one-time setup and precomputation that will be used
* by the heuristic during the search.
*/
public double computeInitialWeight(State s, Vertex target);
/**
* Perform any one-time setup and pre-computation that will be needed by later calls to
* computeForwardWeight/computeReverseWeight.
*/
public void initialize(State s, Vertex target);

public double computeForwardWeight(State s, Vertex target);

public double computeReverseWeight(State s, Vertex target);

/**
* Reset any cached data in the heuristic
*/
/** Reset any cached data in the heuristic, e.g. between rounds of a retrying path service. */
public void reset();

/** Cancel computation. Useful for heuristics running in background threads. */
public void abort();

}


// Perhaps directionality should also be defined during the setup,
// instead of having two separate methods for the two directions.
// We might not even need a setup method if the routing options are just passed into the
// constructor.

This file was deleted.

Loading

0 comments on commit 35376db

Please sign in to comment.