Skip to content

Commit

Permalink
Issue #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Jul 11, 2015
1 parent b5a15d9 commit db24718
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 125 deletions.
29 changes: 29 additions & 0 deletions core/src/main/java/org/hisrc/gtfs/graph/builder/GraphBuilder.java
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);

}
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;
}
}

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions core/src/main/java/org/hisrc/gtfs/graph/model/TransitionEdge.java

This file was deleted.

This file was deleted.

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);
}

}
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);
}

}
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);
}

}
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);
}

}
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;
}

}
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);
}

}
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);
}

}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.hisrc.gtfs.graph.model;
package org.hisrc.gtfs.graph.model.vertex;

import org.onebusaway.gtfs.model.Stop;

public abstract class TemporalStopNode {
public abstract class TemporalVertex {

// Reference to the stop
private final Stop stop;
// Time point
private final int time;

public TemporalStopNode(Stop stop, int time) {
public TemporalVertex(Stop stop, int time) {
super();
this.stop = stop;
this.time = time;
Expand Down
Loading

0 comments on commit db24718

Please sign in to comment.