Add constructor from nodes to path.

This commit is contained in:
Mikael Capelle 2018-02-20 12:03:02 +01:00
parent 237edea766
commit 960d1b1845
2 changed files with 5 additions and 24 deletions

View File

@ -70,8 +70,8 @@ public class Arc {
/** /**
* @return Minimum time required to travel this arc, in seconds. * @return Minimum time required to travel this arc, in seconds.
*/ */
public float getMinimumTravelTime() { public double getMinimumTravelTime() {
return getLength() * 3600f / (info.getMaximumSpeed() * 1000f); return getLength() * 3600.0 / (info.getMaximumSpeed() * 1000.0);
} }
/** /**

View File

@ -4,10 +4,10 @@ import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import org.insa.graph.Arc;
import org.insa.graph.Graph; import org.insa.graph.Graph;
import org.insa.graph.Node; import org.insa.graph.Node;
import org.insa.graph.Path; import org.insa.graph.Path;
import org.insa.graph.Path.CreationMode;
public class BinaryPathReader extends BinaryReader implements AbstractPathReader { public class BinaryPathReader extends BinaryReader implements AbstractPathReader {
@ -36,8 +36,6 @@ public class BinaryPathReader extends BinaryReader implements AbstractPathReader
// Number of nodes in the path (without first and last). // Number of nodes in the path (without first and last).
int nbNodes = dis.readInt(); int nbNodes = dis.readInt();
ArrayList<Arc> arcs = new ArrayList<Arc>();
// Skip (duplicate) first and last node // Skip (duplicate) first and last node
readNode(graph); readNode(graph);
readNode(graph); readNode(graph);
@ -48,24 +46,7 @@ public class BinaryPathReader extends BinaryReader implements AbstractPathReader
nodes.add(readNode(graph)); nodes.add(readNode(graph));
} }
Node current = nodes.get(0); return new Path(graph, nodes, CreationMode.SHORTEST_TIME);
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);
} }
/** /**