-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5a15d9
commit db24718
Showing
17 changed files
with
289 additions
and
125 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/hisrc/gtfs/graph/builder/GraphBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.hisrc.gtfs.graph.builder; | ||
|
||
import org.hisrc.gtfs.graph.model.edge.TransitionEdge; | ||
import org.hisrc.gtfs.graph.model.vertex.TemporalVertex; | ||
import org.onebusaway.gtfs.model.Stop; | ||
|
||
public interface GraphBuilder { | ||
|
||
public TemporalVertex addParentStationVertex(Stop stop, int time); | ||
|
||
public TemporalVertex addArrivalVertex(final Stop stop, | ||
final int arrivalTime); | ||
|
||
public TemporalVertex addDepartureVertex(final Stop stop, | ||
final int departureTime); | ||
|
||
public TransitionEdge addArrivalDepartureEdge(TemporalVertex arrivalVertex, | ||
TemporalVertex departureVertex, int cost); | ||
|
||
public TransitionEdge addDepartureArrivalEdge(TemporalVertex arrivalVertex, | ||
TemporalVertex departureVertex, int cost); | ||
|
||
public TransitionEdge addParentChildEdge(TemporalVertex parentVertex, | ||
TemporalVertex childVertex); | ||
|
||
public TransitionEdge addChildParentEdge(TemporalVertex childVertex, | ||
TemporalVertex parentVertex); | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
core/src/main/java/org/hisrc/gtfs/graph/builder/jgrapht/JGraphTGraphBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.hisrc.gtfs.graph.builder.jgrapht; | ||
|
||
import org.hisrc.gtfs.graph.builder.GraphBuilder; | ||
import org.hisrc.gtfs.graph.model.edge.ArrivalDepartureEdge; | ||
import org.hisrc.gtfs.graph.model.edge.ChildParentEdge; | ||
import org.hisrc.gtfs.graph.model.edge.DepartureArrivalEdge; | ||
import org.hisrc.gtfs.graph.model.edge.ParentChildEdge; | ||
import org.hisrc.gtfs.graph.model.edge.TransitionEdge; | ||
import org.hisrc.gtfs.graph.model.vertex.ArrivalVertex; | ||
import org.hisrc.gtfs.graph.model.vertex.DepartureVertex; | ||
import org.hisrc.gtfs.graph.model.vertex.ParentStationVertex; | ||
import org.hisrc.gtfs.graph.model.vertex.TemporalVertex; | ||
import org.jgrapht.DirectedGraph; | ||
import org.jgrapht.EdgeFactory; | ||
import org.jgrapht.graph.DirectedMultigraph; | ||
import org.onebusaway.gtfs.model.Stop; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class JGraphTGraphBuilder implements GraphBuilder { | ||
|
||
private DirectedGraph<TemporalVertex, TransitionEdge> graph = new DirectedMultigraph<TemporalVertex, TransitionEdge>( | ||
new EdgeFactory<TemporalVertex, TransitionEdge>() { | ||
@Override | ||
public TransitionEdge createEdge(TemporalVertex start, | ||
TemporalVertex stop) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}); | ||
|
||
private Logger logger = LoggerFactory.getLogger(JGraphTGraphBuilder.class); | ||
|
||
public TemporalVertex addParentStationVertex(Stop stop, int time) { | ||
final ParentStationVertex vertex = new ParentStationVertex(stop, time); | ||
graph.addVertex(vertex); | ||
return vertex; | ||
} | ||
|
||
public TemporalVertex addArrivalVertex(final Stop stop, | ||
final int arrivalTime) { | ||
final TemporalVertex arrivalNode = new ArrivalVertex(stop, arrivalTime); | ||
graph.addVertex(arrivalNode); | ||
return arrivalNode; | ||
} | ||
|
||
public TemporalVertex addDepartureVertex(final Stop stop, | ||
final int departureTime) { | ||
final TemporalVertex departureNode = new DepartureVertex(stop, | ||
departureTime); | ||
graph.addVertex(departureNode); | ||
return departureNode; | ||
} | ||
|
||
public TransitionEdge addParentChildEdge(final TemporalVertex childVertex, | ||
final TemporalVertex parentVertex) { | ||
// logger.info("Adding [" + parentVertex + "-pc->" + childVertex + "]"); | ||
final ParentChildEdge edge = new ParentChildEdge(); | ||
graph.addEdge(parentVertex, childVertex, edge); | ||
|
||
return edge; | ||
} | ||
|
||
public TransitionEdge addChildParentEdge(final TemporalVertex childVertex, | ||
final TemporalVertex parentVertex) { | ||
// logger.info("Adding [" + childVertex + "-cp->" + parentVertex + "]"); | ||
ChildParentEdge edge = new ChildParentEdge(); | ||
graph.addEdge(childVertex, parentVertex, edge); | ||
return edge; | ||
} | ||
|
||
public TransitionEdge addArrivalDepartureEdge( | ||
final TemporalVertex arrivalVertex, | ||
final TemporalVertex departureVertex, int cost) { | ||
// logger.info("Adding [" + arrivalNode + "-" + departureNode + "]"); | ||
final TransitionEdge edge = new ArrivalDepartureEdge(cost); | ||
graph.addEdge(arrivalVertex, departureVertex, edge); | ||
return edge; | ||
} | ||
|
||
public TransitionEdge addDepartureArrivalEdge( | ||
final TemporalVertex departureVertex, | ||
final TemporalVertex arrivalVertex, final int cost) { | ||
final TransitionEdge edge = new DepartureArrivalEdge(cost); | ||
graph.addEdge(departureVertex, arrivalVertex, edge); | ||
return edge; | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
core/src/main/java/org/hisrc/gtfs/graph/model/TemporalStopArrivalNode.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
core/src/main/java/org/hisrc/gtfs/graph/model/TemporalStopDepartureNode.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
core/src/main/java/org/hisrc/gtfs/graph/model/TransitionEdge.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
core/src/main/java/org/hisrc/gtfs/graph/model/TransitionType.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
core/src/main/java/org/hisrc/gtfs/graph/model/edge/ArrivalDepartureEdge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisrc.gtfs.graph.model.edge; | ||
|
||
|
||
public class ArrivalDepartureEdge extends TransitionEdge { | ||
|
||
public ArrivalDepartureEdge(int cost) { | ||
super(cost); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/java/org/hisrc/gtfs/graph/model/edge/ChildParentEdge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisrc.gtfs.graph.model.edge; | ||
|
||
|
||
public class ChildParentEdge extends TransitionEdge { | ||
|
||
public ChildParentEdge() { | ||
super(0); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/java/org/hisrc/gtfs/graph/model/edge/DepartureArrivalEdge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisrc.gtfs.graph.model.edge; | ||
|
||
|
||
public class DepartureArrivalEdge extends TransitionEdge { | ||
|
||
public DepartureArrivalEdge(int cost) { | ||
super(cost); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/java/org/hisrc/gtfs/graph/model/edge/ParentChildEdge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisrc.gtfs.graph.model.edge; | ||
|
||
|
||
public class ParentChildEdge extends TransitionEdge { | ||
|
||
public ParentChildEdge() { | ||
super(0); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/org/hisrc/gtfs/graph/model/edge/TransitionEdge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hisrc.gtfs.graph.model.edge; | ||
|
||
public class TransitionEdge { | ||
|
||
private final int cost; | ||
|
||
public TransitionEdge(int cost) { | ||
this.cost = cost; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/org/hisrc/gtfs/graph/model/vertex/ArrivalVertex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hisrc.gtfs.graph.model.vertex; | ||
|
||
import org.onebusaway.gtfs.model.Stop; | ||
|
||
public class ArrivalVertex extends TemporalVertex { | ||
|
||
public ArrivalVertex(Stop stop, int time) { | ||
super(stop, time); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/org/hisrc/gtfs/graph/model/vertex/DepartureVertex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hisrc.gtfs.graph.model.vertex; | ||
|
||
import org.onebusaway.gtfs.model.Stop; | ||
|
||
public class DepartureVertex extends TemporalVertex { | ||
|
||
public DepartureVertex(Stop stop, int time) { | ||
super(stop, time); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/java/org/hisrc/gtfs/graph/model/vertex/ParentStationVertex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisrc.gtfs.graph.model.vertex; | ||
|
||
import org.onebusaway.gtfs.model.Stop; | ||
|
||
public class ParentStationVertex extends TemporalVertex { | ||
|
||
public ParentStationVertex(Stop stop, int time) { | ||
super(stop, time); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...rc/gtfs/graph/model/TemporalStopNode.java → ...fs/graph/model/vertex/TemporalVertex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.