Permalink
Browse files

playback timer showing time of day. calculate real vessel speeds for …

…playback. fix deviations from straight path in trajectories.
  • Loading branch information...
1 parent fdf9d9e commit 906fb10711ebf42386d8fa57364ef554e4976383 @cavvia committed Feb 20, 2011
Showing with 149 additions and 35 deletions.
  1. +1 −1 ControlPanel.pde
  2. +2 −1 Flowprint.pde
  3. +24 −8 Network.pde
  4. +2 −2 NetworkImporter.pde
  5. +32 −0 Route.pde
  6. +27 −4 Trip.pde
  7. +6 −2 TripComparator.pde
  8. +1 −1 TripsImporter.pde
  9. +54 −16 Vessel.pde
View
@@ -123,7 +123,7 @@ class ControlPanel
r3.setId(ControlPanel.MODE);
r3.addItem("topology",ControlPanel.TOPOLOGY);
r3.addItem("flow",ControlPanel.FLOW);
- r3.activate("topology");
+ r3.activate(DEFAULT_MODE);
r3.setItemsPerRow(2);
r3.setSpacingColumn(80);
}
View
@@ -13,14 +13,15 @@
static final int PANE_WIDTH = 1000;
static final int PANE_HEIGHT = 800;
static final int DEFAULT_NET = 4;
+ static final String DEFAULT_MODE = "flow";
static final String ROOT_DIR = "/casa/Flowprint"; //change this
static final String VIDEO_FILE = "flowprint8.mov";
static final String PDF_FILE = "reach-vis.pdf";
boolean debug = true;
boolean video = false;
boolean attribs = false; //whether to visualise node attributes
boolean trueAspectRatio = false;
- boolean trails = false;
+ boolean trails = true;
/**
* CONFIGURATION END
View
@@ -23,6 +23,7 @@ class Network
NetworkImporter importer;
public int selectedNode = 0;
private List tripVessels;
+ private TripsTimer timer;
public Network()
{
@@ -75,6 +76,7 @@ class Network
this.vessels = new Vessel[t];
this.createVessels();
if(this.shouldShowTrips()) {
+ this.timer = new TripsTimer();
this.startTripsMode();
}
}
@@ -264,19 +266,31 @@ class Network
debug("STARTING TRIPS MODE");
this.tripVessels = new ArrayList<Vessel>();
this.createTripVessels();
+ this.timer.start();
+ }
+
+ public float getPixelsPerMeter()
+ {
+ return new Float(PANE_WIDTH)/(MaxX - MinX);
+ }
+
+ public float getTripSpeed()
+ {
+ return this.timer.speed;
}
private void createTripVessels()
{
int dayOfWeek = 3;
List trips = this.importer.getTrips(dayOfWeek);
- for(int i=0;i<800;i++) {
+ for(int i=0;i<1000;i++) {
Trip trip = (Trip)trips.get(i);
- debug(trip.time);
+ debug(trip.startTime);
Route r = trip.getRoute();
if(r != null) {
- Vessel v = new Vessel(r);
+ Vessel v = new Vessel(trip);
this.tripVessels.add(v);
+ this.timer.schedule(v,trip);
r.printStops();
}
}
@@ -286,10 +300,7 @@ class Network
private void updateVessels()
{
if(this.shouldShowTrips()) {
- for (int i=0; i < this.tripVessels.size(); i++) {
- Vessel v = (Vessel)this.tripVessels.get(i);
- v.update();
- }
+ this.timer.update();
} else {
for (int i = 0; i < this.activeVesselNum; i++) {
this.vessels[i].update();
@@ -307,9 +318,14 @@ class Network
}
}
+ public boolean isInTripsMode()
+ {
+ return this.shouldShowTrips();
+ }
+
public boolean isIncrementalGrowth()
{
- return cp.growth == ControlPanel.INCREMENTAL_GROWTH;
+ return cp.growth == ControlPanel.INCREMENTAL_GROWTH && !this.isInTripsMode();
}
public boolean shouldRenderFlows()
View
@@ -187,8 +187,8 @@ class NetworkImporter extends Importer
}
private String getTripsFilePath() {
- //return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/xaa";
- return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/" + this.filePrefix + "_trips.csv";
+ return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/xaa";
+ //return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/" + this.filePrefix + "_trips.csv";
}
public boolean hasTrips() {
View
@@ -14,6 +14,7 @@ class Route {
public int maxBusCount = 0;
private String originID;
private boolean constructed = false;
+ public float length;
java.util.List stopList;
public Route(String name) {
@@ -38,6 +39,11 @@ class Route {
}
return this.totalLength;
}
+
+ public float getRouteLengthPixels()
+ {
+ return this.getRouteLength() * net.getPixelsPerMeter();
+ }
public void addStops(String[] pieces,Boolean named)
{
@@ -135,6 +141,16 @@ class Route {
//this.printStops();
this.constructed = true;
}
+
+ public Stop getDestination()
+ {
+ return (Stop)net.aStop.get(this.stops[this.stops.length-1]);
+ }
+
+ public Stop getOrigin()
+ {
+ return (Stop)net.aStop.get(this.stops[0]);
+ }
/*
* @desc Recursive path finding algorithm
@@ -166,6 +182,22 @@ class Route {
{
return this.originID.equals(id);
}
+
+ /**
+ * @return Length of trip, in pixels
+ */
+ public double getLength()
+ {
+ Stop origin = this.getOrigin();
+ Stop dest = this.getDestination();
+ if(origin!= null && dest!= null) {
+ this.length = sqrt(pow(abs(dest.getCoords().x - origin.getCoords().x),2) + pow(abs(dest.getCoords().y - origin.getCoords().y),2));
+ return this.length;
+ } else {
+ debug("NO ORIGIN " + origin.ID);
+ return 0.0;
+ }
+ }
private void printStops()
{
View
@@ -2,21 +2,23 @@ class Trip
{
public int origin;
public int destination;
- public String time;
+ public String startTime;
+ public String endTime;
public int date;
private Route route;
- public Trip(int date,int from,int to,String time)
+ public Trip(int date,int from,int to,String start,String end)
{
this.date = date;
this.origin = from;
this.destination = to;
- this.time = time;
+ this.startTime = start;
+ this.endTime = end;
}
public String toString()
{
- return this.date + " " + this.origin + " " + this.destination + " " + this.time;
+ return this.date + " " + this.origin + " " + this.destination + " " + this.getStartDate().toString();
}
public Stop getOrigin()
@@ -38,4 +40,25 @@ class Trip
{
return this.route;
}
+
+ public Date getStartDate()
+ {
+ String[] times = split(this.startTime,":");
+ return new Date(2011,1,1,int(times[0]),int(times[1]));
+ }
+
+ public Date getEndDate()
+ {
+ String[] times = split(this.endTime,":");
+ return new Date(2011,1,1,int(times[0]),int(times[1]));
+ }
+
+ /**
+ * @return Int duration (in secs)
+ */
+ public float getDuration()
+ {
+ return (this.getEndDate().getTime() - this.getStartDate().getTime())/1000;
+ }
+
}
View
@@ -1,11 +1,15 @@
class TripComparator implements Comparator
{
+
+ /**
+ * @desc Sort trips by time of day
+ */
public int compare (Object trip1, Object trip2)
{
Trip t1 = (Trip)trip1;
Trip t2 = (Trip)trip2;
- String[] h1 = split(t1.time,":");
- String[] h2 = split(t2.time,":");
+ String[] h1 = split(t1.startTime,":");
+ String[] h2 = split(t2.startTime,":");
if (int(h1[0]) == int(h2[0])) {
return (int(h1[1]) > int(h2[1])) ? 1 : -1;
} else {
View
@@ -34,7 +34,7 @@ class TripsImporter extends Importer
String tripStr = tripLines[i];
String[] tripInfo = split(tripStr,",");
int dayOfWeek = int(tripInfo[0]);
- this.trips[dayOfWeek].add(new Trip(dayOfWeek,int(tripInfo[1]),int(tripInfo[2]),tripInfo[3]));
+ this.trips[dayOfWeek].add(new Trip(dayOfWeek,int(tripInfo[1]),int(tripInfo[2]),tripInfo[3],tripInfo[4]));
}
debug("LOADED TRIPS");
}
View
@@ -14,12 +14,15 @@ class Vessel
float _x;
float _y;
float linkLength;
+ float routeLengthPx;
+ private float speed;
Point destCoords;
+ Point originCoords;
Stop dest;
Stop origin;
String[] stops;
-
+ Trip trip;
int journeyNum = 1;
int nullStops = 0;
@@ -29,6 +32,20 @@ class Vessel
//debug("created vessel on " + route.name + " route");
this._x = 0;
this._y = 0;
+ this.setSpeed(BUS_SPEED);
+ }
+
+ public Vessel(Trip trip) {
+ this.route = trip.getRoute();
+ this.trip = trip;
+ this.stops = this.route.getStops().clone();
+ //debug("created vessel on " + route.name + " route");
+ this._x = 0;
+ this._y = 0;
+ this.routeLengthPx = this.route.getRouteLengthPixels();
+ Float f = new Float((this.routeLengthPx/trip.getDuration())*net.getTripSpeed());
+ this.setSpeed(f);
+ debug("speed is "+ this.speed);
}
private void placeAtOrigin()
@@ -49,11 +66,11 @@ class Vessel
return;
}
- Point originCoords = dest.getCoords();
- this.origin = dest;
- this._x = originCoords.x;
- this._y = originCoords.y;
- //debug(this.dest.getId() + " origin");
+ this.originCoords = dest.getCoords();
+ this.origin = dest;
+ this._x = this.originCoords.x;
+ this._y = this.originCoords.y;
+ //debug(this.dest.getId() + " origin");
this.drawme();
}
@@ -82,6 +99,10 @@ class Vessel
this.drawme();
}
+ private void setSpeed(float speed) {
+ this.speed = speed;
+ }
+
private void printTrajectory()
{
if(!(dest == null)) {
@@ -94,21 +115,31 @@ class Vessel
private void moveToDest()
{
float xdiff,ydiff;
- if(cp.dynamics == ControlPanel.SWARM) {
- xdiff = (this.destCoords.x - this._x) * BUS_SPEED;
- ydiff = (this.destCoords.y - this._y) * BUS_SPEED;
+ if(net.isInTripsMode()) {
+ float xDist = this.destCoords.x - this.originCoords.x;
+ float yDist = this.destCoords.y - this.originCoords.y;
+ //debug("linkdist "+ this.linkLength + " " + this.routeLengthPx);
+ float edgeLength = (this.linkLength > 0) ? this.linkLength : this.routeLengthPx;
+ xdiff = xDist * this.speed/edgeLength;
+ ydiff = yDist * this.speed/edgeLength;
+ }
+ else if(cp.dynamics == ControlPanel.SWARM) {
+ xdiff = (this.destCoords.x - this._x) * this.speed;
+ ydiff = (this.destCoords.y - this._y) * this.speed;
} else {
if(!this.beyondMidPoint()) { //accelerate to midpoint
- xdiff = 0.05 + this.distanceFromOrigin() * BUS_SPEED/80;
- ydiff = 0.05 + this.distanceFromOrigin() * BUS_SPEED/80;
+ xdiff = 0.05 + this.distanceFromOrigin() * this.speed/80;
+ ydiff = 0.05 + this.distanceFromOrigin() * this.speed/80;
} else { //decelerate to dest
- xdiff = (this.destCoords.x - this._x) * BUS_SPEED;
- ydiff = (this.destCoords.y - this._y) * BUS_SPEED;
+ xdiff = (this.destCoords.x - this._x) * this.speed;
+ ydiff = (this.destCoords.y - this._y) * this.speed;
}
}
- if(abs(xdiff) > MAX_SPEED) xdiff *= MAX_SPEED/abs(xdiff);
- if(abs(ydiff) > MAX_SPEED) ydiff *= MAX_SPEED/abs(ydiff);
+ if(!net.isInTripsMode()) {
+ if(abs(xdiff) > MAX_SPEED) xdiff *= MAX_SPEED/abs(xdiff);
+ if(abs(ydiff) > MAX_SPEED) ydiff *= MAX_SPEED/abs(ydiff);
+ }
this._x += xdiff;
this._y += ydiff;
@@ -170,8 +201,10 @@ class Vessel
if(destIndex < this.getStops().length-1) {
Stop orig = this.getDestination();
if(orig != null) this.origin = orig;
+ this.originCoords = this.origin.getCoords();
destIndex++;
this.refreshDestination();
+ this.calcLinkLength();
if(cp.dynamics == ControlPanel.BUS) {
this.calcLinkLength();
}
@@ -212,9 +245,14 @@ class Vessel
public void drawme()
{
- int alphax = trails ? 3 : 40;
+ int alphax = trails ? 5 : 40;
fill(#FFFFFF,alphax);
stroke(#FFFFFF,alphax);
+
+ if(net.isInTripsMode() && this.journeyNum > 1) {
+ return;//no render
+ }
+
ellipse(this._x + net.getXOffset(),this._y - net.getYOffset(),1,1);
}

0 comments on commit 906fb10

Please sign in to comment.