From 960d1b1845442556c71c91fe418e109162431a65 Mon Sep 17 00:00:00 2001 From: Mikael Capelle Date: Tue, 20 Feb 2018 12:03:02 +0100 Subject: [PATCH] Add constructor from nodes to path. --- src/main/org/insa/graph/Arc.java | 4 +-- .../org/insa/graph/io/BinaryPathReader.java | 25 +++---------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/main/org/insa/graph/Arc.java b/src/main/org/insa/graph/Arc.java index a84c824..05fb727 100644 --- a/src/main/org/insa/graph/Arc.java +++ b/src/main/org/insa/graph/Arc.java @@ -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); } /** diff --git a/src/main/org/insa/graph/io/BinaryPathReader.java b/src/main/org/insa/graph/io/BinaryPathReader.java index 6746014..6f2eeeb 100644 --- a/src/main/org/insa/graph/io/BinaryPathReader.java +++ b/src/main/org/insa/graph/io/BinaryPathReader.java @@ -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 arcs = new ArrayList(); - + // 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); } /**