Add constructor from nodes to path.
This commit is contained in:
parent
237edea766
commit
960d1b1845
2 changed files with 5 additions and 24 deletions
|
@ -70,8 +70,8 @@ public class Arc {
|
|||
/**
|
||||
* @return Minimum time required to travel this arc, in seconds.
|
||||
*/
|
||||
public float getMinimumTravelTime() {
|
||||
return getLength() * 3600f / (info.getMaximumSpeed() * 1000f);
|
||||
public double getMinimumTravelTime() {
|
||||
return getLength() * 3600.0 / (info.getMaximumSpeed() * 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,10 +4,10 @@ import java.io.DataInputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.insa.graph.Arc;
|
||||
import org.insa.graph.Graph;
|
||||
import org.insa.graph.Node;
|
||||
import org.insa.graph.Path;
|
||||
import org.insa.graph.Path.CreationMode;
|
||||
|
||||
public class BinaryPathReader extends BinaryReader implements AbstractPathReader {
|
||||
|
||||
|
@ -35,9 +35,7 @@ public class BinaryPathReader extends BinaryReader implements AbstractPathReader
|
|||
|
||||
// Number of nodes in the path (without first and last).
|
||||
int nbNodes = dis.readInt();
|
||||
|
||||
ArrayList<Arc> arcs = new ArrayList<Arc>();
|
||||
|
||||
|
||||
// Skip (duplicate) first and last node
|
||||
readNode(graph);
|
||||
readNode(graph);
|
||||
|
@ -48,24 +46,7 @@ public class BinaryPathReader extends BinaryReader implements AbstractPathReader
|
|||
nodes.add(readNode(graph));
|
||||
}
|
||||
|
||||
Node current = nodes.get(0);
|
||||
for (int i = 1; i < nodes.size(); ++i) {
|
||||
Node node = nodes.get(i);
|
||||
Arc minArc = null;
|
||||
for (Arc arc: current.getSuccessors()) {
|
||||
if (arc.getDestination().equals(node)
|
||||
&& (minArc == null || arc.getMinimumTravelTime() < minArc.getMinimumTravelTime())) {
|
||||
minArc = arc;
|
||||
}
|
||||
}
|
||||
arcs.add(minArc);
|
||||
if (minArc == null) {
|
||||
System.out.println("No arc found between nodes " + current.getId() + " and " + node.getId() + "\n");
|
||||
}
|
||||
current = node;
|
||||
}
|
||||
|
||||
return new Path(graph, arcs);
|
||||
return new Path(graph, nodes, CreationMode.SHORTEST_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue