Add origin node to arc.

This commit is contained in:
Mikael Capelle 2018-02-20 11:26:04 +01:00
parent 11b07b652b
commit a6e8a22081
3 changed files with 20 additions and 11 deletions

View File

@ -5,7 +5,7 @@ import java.util.ArrayList;
public class Arc { public class Arc {
// Destination node. // Destination node.
private Node dest; private Node origin, destination;
// Length of the road (in meters). // Length of the road (in meters).
private int length; private int length;
@ -22,11 +22,13 @@ public class Arc {
* @param roadInformation * @param roadInformation
* @param points * @param points
*/ */
public Arc(Node dest, int length, RoadInformation roadInformation) { public Arc(Node origin, Node dest, int length, RoadInformation roadInformation) {
this.dest = dest; this.origin = origin;
this.destination = dest;
this.length = length; this.length = length;
this.info = roadInformation; this.info = roadInformation;
this.points = new ArrayList<Point>(); this.points = new ArrayList<Point>();
origin.addSuccessor(this);
} }
/** /**
@ -35,18 +37,27 @@ public class Arc {
* @param roadInformation * @param roadInformation
* @param points * @param points
*/ */
public Arc(Node dest, int length, RoadInformation roadInformation, ArrayList<Point> points) { public Arc(Node origin, Node dest, int length, RoadInformation roadInformation, ArrayList<Point> points) {
this.dest = dest; this.origin = origin;
this.destination = dest;
this.length = length; this.length = length;
this.info = roadInformation; this.info = roadInformation;
this.points = points; this.points = points;
origin.addSuccessor(this);
}
/**
* @return Origin node of this arc.
*/
public Node getOrigin() {
return origin;
} }
/** /**
* @return Destination node of this arc. * @return Destination node of this arc.
*/ */
public Node getDestination() { public Node getDestination() {
return dest; return destination;
} }
/** /**

View File

@ -30,7 +30,7 @@ public class Node implements Comparable<Node> {
* *
* @param arc Arc to the successor. * @param arc Arc to the successor.
*/ */
public void addSuccessor(Arc arc) { protected void addSuccessor(Arc arc) {
successors.add(arc); successors.add(arc);
} }

View File

@ -5,8 +5,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import javax.sound.midi.ControllerEventListener;
import org.insa.graph.Arc; 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;
@ -147,14 +145,14 @@ public class BinaryGraphReader extends BinaryReader implements AbstractGraphRead
Node dest = nodes.get(destNode); Node dest = nodes.get(destNode);
// Add successor to initial arc. // Add successor to initial arc.
orig.addSuccessor(new Arc(dest, length, info, points)); new Arc(orig, dest, length, info, points);
// And reverse arc if its a two-way road. // And reverse arc if its a two-way road.
if (!info.isOneWay()) { if (!info.isOneWay()) {
// Add without segments. // Add without segments.
ArrayList<Point> rPoints = new ArrayList<Point>(points); ArrayList<Point> rPoints = new ArrayList<Point>(points);
Collections.reverse(rPoints); Collections.reverse(rPoints);
dest.addSuccessor(new Arc(orig, length, info, rPoints)); new Arc(dest, orig, length, info, rPoints);
} }
} }