/** * Sets the Agent up to proceed along an Edge * * @param edge the GeomPlanarGraphEdge to traverse next */ void setupEdge(GeomPlanarGraphEdge edge) { // clean up on old edge if (currentEdge != null) { ArrayList<AgentCopy> traffic = world.edgeTraffic.get(currentEdge); traffic.remove(this); } currentEdge = edge; // update new edge traffic if (world.edgeTraffic.get(currentEdge) == null) { world.edgeTraffic.put(currentEdge, new ArrayList<AgentCopy>()); } world.edgeTraffic.get(currentEdge).add(this); // set up the new segment and index info LineString line = edge.getLine(); segment = new LengthIndexedLine(line); startIndex = segment.getStartIndex(); endIndex = segment.getEndIndex(); linkDirection = 1; // check to ensure that Agent is moving in the right direction double distanceToStart = line.getStartPoint().distance(location.geometry), distanceToEnd = line.getEndPoint().distance(location.geometry); if (distanceToStart <= distanceToEnd) { // closer to start currentIndex = startIndex; linkDirection = 1; } else if (distanceToEnd < distanceToStart) { // closer to end currentIndex = endIndex; linkDirection = -1; } }
double progress(double val) { double edgeLength = currentEdge.getLine().getLength(); double traffic = world.edgeTraffic.get(currentEdge).size(); double factor = 1000 * edgeLength / (traffic * 5); factor = Math.min(1, factor); return val * linkDirection * factor; }
/** Constructor Function */ public AgentCopy( Gridlock_NorfolkTEST g, String home, String work, GeomPlanarGraphEdge startingEdge, GeomPlanarGraphEdge goalEdge) { world = g; // set up information about where the node is and where it's going homeNode = startingEdge.getDirEdge(0).getFromNode(); workNode = goalEdge.getDirEdge(0).getToNode(); homeTract = home; workTract = work; // set the location to be displayed GeometryFactory fact = new GeometryFactory(); location = new MasonGeometry(fact.createPoint(new Coordinate(10, 10))); Coordinate startCoord = null; startCoord = homeNode.getCoordinate(); updatePosition(startCoord); }