@Override public void addAgent(AgentSnapshotInfo position) { //drop all parking vehicles if (position.getAgentState() == AgentSnapshotInfo.AgentState.PERSON_AT_ACTIVITY) return; String buffer = position.getId().toString() + "\t" + (int)this.currentTime + "\t0\t0\t1\t0\t" + position.getColorValueBetweenZeroAndOne() // link(0), from node(0), lane(1), dist(0), speed + "\t1\t0\t" + position.getId().toString() // vehtype(1), acceleration(0), driver-id + "\t0\t" + position.getEasting() // # of passengers(0), easting + "\t" + position.getNorthing() + "\t0" // elevation + "\t0" // azimuth + "\t"+ "0" + "\n"; // user(0) try { out.write(buffer); } catch (IOException e) { e.printStackTrace(); } }
private void addHolePosition(final Collection<AgentSnapshotInfo> positions, double distanceFromFromNode, Hole veh, double curvedLength, Coord upstreamCoord, Coord downstreamCoord) { Integer lane = 20 ; double speedValue = 1. ; AgentSnapshotInfo pos = this.snapshotInfoFactory.createAgentSnapshotInfo(Id.create("hole", Person.class), upstreamCoord, downstreamCoord, distanceFromFromNode, lane, curvedLength); pos.setColorValueBetweenZeroAndOne(speedValue); pos.setAgentState(AgentState.PERSON_OTHER_MODE ); positions.add(pos); }
private void readAgent(ByteBuffer in, SceneGraph graph) { String id = ByteBufferUtils.getString(in); float x = in.getFloat(); float y = in.getFloat(); int int1 = in.getInt() ; int int2 = in.getInt() ; float float1 = in.getFloat() ; AgentSnapshotInfo agInfo = snapshotFactory.createAgentSnapshotInfo(Id.create(id, Person.class), x, y, 0., 0.) ; agInfo.setAgentState( al[int1] ) ; agInfo.setUserDefined( int2 ) ; agInfo.setColorValueBetweenZeroAndOne(float1); graph.getAgentPointLayer().addAgent(agInfo); }
private static Color standardColoringScheme(AgentSnapshotInfo agInfo) { if ( agInfo.getAgentState()==AgentState.PERSON_DRIVING_CAR ) { return redToGreenColorizer.getColorZeroOne(agInfo.getColorValueBetweenZeroAndOne()); } else if ( agInfo.getAgentState()==AgentState.PERSON_AT_ACTIVITY ) { return Color.ORANGE; } else if ( agInfo.getAgentState()==AgentState.PERSON_OTHER_MODE ) { return Color.MAGENTA; } else if ( agInfo.getAgentState()==AgentState.TRANSIT_DRIVER ) { return Color.BLUE; } else { return Color.YELLOW; } }
private static Color taxicabColoringScheme(AgentSnapshotInfo agInfo) { // ===============TAXI COLOURING=============== if (agInfo.getId().toString().startsWith("taxi")) { if (agInfo.getAgentState() == AgentState.PERSON_DRIVING_CAR) { return Color.YELLOW ; } else { return Color.BLACK ; } } else { //===============REGULAR COLOURING=============== return standardColoringScheme( agInfo ) ; } }
@Override public void writeConstData(ByteBuffer out) throws IOException { out.putInt(this.schedule.getFacilities().size()); for (TransitStopFacility facility : this.schedule.getFacilities().values()) { ByteBufferUtils.putString(out, facility.getId().toString()); if (facility.getLinkId() != null) { // yyyy would most probably make sense to have something that generates coordinates for facilities Link link = this.network.getLinks().get( facility.getLinkId() ) ; if ( link==null ) { log.warn( " link not found; linkId: " + facility.getLinkId() ) ; ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } else { ByteBufferUtils.putString(out, facility.getLinkId().toString()); AgentSnapshotInfo ps = agentSnapshotInfoFactory.createAgentSnapshotInfo(Id.create(facility.getId(), Person.class), link, 0.9*link.getLength(), 0) ; Point2D.Double point = OTFServerQuadTree.transform(new Coord(ps.getEasting(), ps.getNorthing())); out.putDouble(point.getX()) ; out.putDouble(point.getY()) ; } } else { ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } } }
this.posBuffers.add(this.vertexIN); this.vertexIN.put((float)agInfo.getEasting()); this.vertexIN.put((float)agInfo.getNorthing()); this.id2coord.put(Arrays.hashCode(agInfo.getId().toString().toCharArray()),this.count);
/** * Put the vehicles from the waiting list in positions. Their actual position doesn't matter, PositionInfo provides a * constructor for handling this situation. */ public final int positionVehiclesFromWaitingList(final Collection<AgentSnapshotInfo> positions, final Link link, int cnt2, final Queue<QVehicle> waitingList) { for (QVehicle veh : waitingList) { Collection<Identifiable<?>> peopleInVehicle = VisUtils.getPeopleInVehicle(veh); boolean first = true; for (Identifiable passenger : peopleInVehicle) { cnt2++ ; AgentSnapshotInfo passengerPosition = snapshotInfoFactory.createAgentSnapshotInfo(passenger.getId(), link, 0.9*link.getLength(), cnt2); // for the time being, same position as facilities if (passenger.getId().toString().startsWith("pt")) { passengerPosition.setAgentState(AgentState.TRANSIT_DRIVER); } else if (first) { passengerPosition.setAgentState(AgentState.PERSON_DRIVING_CAR); } else { passengerPosition.setAgentState(AgentState.PERSON_OTHER_MODE); } positions.add(passengerPosition); first = false; } } return cnt2 ; }
@Override public void addAgent(final AgentSnapshotInfo position) { if (position.getAgentState() != AgentSnapshotInfo.AgentState.PERSON_AT_ACTIVITY) { this.positions.add(position); } }
private static Color byIdColoringScheme(AgentSnapshotInfo agInfo) { String idstr = agInfo.getId().toString() ; int val = 8 ; if ( idstr.hashCode()%val==0 ) { return Color.red ; } else if (idstr.hashCode()%val==1 ) { return Color.orange ; } else if (idstr.hashCode()%val==2 ) { return Color.yellow ; } else if (idstr.hashCode()%val==3 ) { return Color.green ; } else if (idstr.hashCode()%val==4 ) { return Color.blue ; } else if (idstr.hashCode()%val==5 ) { return Color.cyan ; } else if (idstr.hashCode()%val==6 ) { return Color.magenta ; } else if (idstr.hashCode()%val==7 ) { return Color.pink ; } else { return Color.black; } }
Link link = net.getLinks().get(act.getLinkId()); AgentSnapshotInfo pi = snapshotInfoFactory.createAgentSnapshotInfo(agentId, link, 0.9*link.getLength(), 0); coord = new Coord(pi.getEasting(), pi.getNorthing());
private static Color bvgColoringScheme(AgentSnapshotInfo agInfo) { if ( agInfo.getAgentState()==AgentState.PERSON_DRIVING_CAR ) { return Color.DARK_GRAY; } else if ( agInfo.getAgentState()==AgentState.PERSON_AT_ACTIVITY ) { return Color.ORANGE; } else if ( agInfo.getAgentState()==AgentState.TRANSIT_DRIVER ) { String idstr = agInfo.getId().toString(); if ( idstr.endsWith("_B") ) { return Color.MAGENTA; } else if ( idstr.endsWith("_T") ) { return Color.RED; } else if ( idstr.endsWith("_S")) { return Color.GREEN; } else if ( idstr.endsWith("_U")) { return Color.BLUE; } else { return Color.ORANGE; } } else { return Color.YELLOW; } }
public final int positionAgentsInActivities(final Collection<AgentSnapshotInfo> positions, Link link, Collection<MobsimAgent> agentsInActivities, int cnt2) { for (MobsimAgent pa : agentsInActivities) { AgentSnapshotInfo agInfo = snapshotInfoFactory.createAgentSnapshotInfo(pa.getId(), link, 0.9*link.getLength(), cnt2) ; agInfo.setAgentState( AgentState.PERSON_AT_ACTIVITY ) ; positions.add(agInfo) ; cnt2++ ; } return cnt2; }
@Override public void writeDynData(ByteBuffer out) throws IOException { out.putFloat((float)0.) ; positions.clear(); this.src.getVisData().addAgentSnapshotInfo( positions); if (showParked) { out.putInt(positions.size()); for (AgentSnapshotInfo pos : positions) { writeAgent(pos, out); } } else { int valid = 0; for (AgentSnapshotInfo pos : positions) { if (pos.getAgentState() != AgentState.PERSON_AT_ACTIVITY) valid++; } out.putInt(valid); for (AgentSnapshotInfo pos : positions) { if (pos.getAgentState() != AgentState.PERSON_AT_ACTIVITY) writeAgent(pos, out); } } }
private static void writeAgent(AgentSnapshotInfo agInfo, ByteBuffer out) { String id = agInfo.getId().toString(); ByteBufferUtils.putString(out, id); Point2D.Double point = OTFServerQuadTree.transform(new Coord(agInfo.getEasting(), agInfo.getNorthing())); out.putFloat((float) point.getX()); out.putFloat((float) point.getY()); out.putInt(agInfo.getAgentState().ordinal() ) ; out.putInt(agInfo.getUserDefined()); out.putFloat((float)agInfo.getColorValueBetweenZeroAndOne()); }
/** * Test the calculation of a vehicles position if the actual link length is * shorter than the euklidean distance. * * @author mrieser */ public void testDistanceOnLink_shortLink() { Network network = NetworkUtils.createNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create("1", Node.class), new Coord((double) 0, (double) 0)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create("2", Node.class), new Coord((double) 1000, (double) 1000)); final Node fromNode = node1; final Node toNode = node2; Link link1 = NetworkUtils.createAndAddLink(network,Id.create("1", Link.class), fromNode, toNode, (double) 1000, (double) 10, (double) 9999, (double) 1 ); // place the vehicle at one quarter of the link SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); AgentSnapshotInfo posInfo = new AgentSnapshotInfoFactory(linkWidthCalculator).createAgentSnapshotInfo(Id.create(1, Person.class), link1, 250, 0); assertEquals(260.60660171779824, posInfo.getEasting(), epsilon); assertEquals(239.3933982822018, posInfo.getNorthing(), epsilon); // These numbers became a little weird when I moved vehicles away from the center of a link. Kai, Dec/08 // These numbers changed again when I mad the orthogonal offset adaptive. kai, aug/10 // Made the orthogonal offsets non-adaptive again. kai, feb'13 }
final void positionPassengers(Collection<AgentSnapshotInfo> positions, Collection<? extends PassengerAgent> passengers, double distanceOnLink, Coord startCoord, Coord endCoord, double lengthOfCurve, Integer lane, double speedValueBetweenZeroAndOne) { int cnt = passengers.size(); int laneInt = 2*(cnt+1); if (lane != null){ laneInt += lane; } for (PassengerAgent passenger : passengers) { int lanePos = laneInt - 2*cnt ; AgentSnapshotInfo passengerPosition = snapshotInfoFactory.createAgentSnapshotInfo(passenger.getId(), startCoord, endCoord, distanceOnLink, lanePos, lengthOfCurve); passengerPosition.setColorValueBetweenZeroAndOne(speedValueBetweenZeroAndOne); passengerPosition.setAgentState(AgentState.PERSON_OTHER_MODE); // in 2010, probably a passenger positions.add(passengerPosition); cnt-- ; } }
private static Color gtfsColoringScheme(AgentSnapshotInfo agInfo) { if ( agInfo.getAgentState()==AgentState.PERSON_DRIVING_CAR ) { return Color.DARK_GRAY; } else if ( agInfo.getAgentState()==AgentState.PERSON_AT_ACTIVITY ) { return Color.ORANGE; } else if ( agInfo.getAgentState()==AgentState.TRANSIT_DRIVER ) { String idstr = agInfo.getId().toString(); if ( idstr.endsWith("bus") ) { return Color.MAGENTA; } else if ( idstr.endsWith("tram") ) { return Color.RED; } else if ( idstr.endsWith("rail")) { return Color.GREEN; } else if ( idstr.endsWith("subway")) { return Color.BLUE; } else { return Color.ORANGE; } } else { return Color.YELLOW; } }
private void readAgent(ByteBuffer in, SceneGraph sceneGraph) { // yyyy there is a very similar method in OTFAgentsListHandler. with a more robust format, they should be united. kai, apr'10 String id = ByteBufferUtils.getString(in); float x = in.getFloat(); float y = in.getFloat(); int userdefined = in.getInt(); float colorValue = in.getFloat(); int state = in.getInt(); AgentSnapshotInfo agInfo = snapshotFactory.createAgentSnapshotInfo(Id.create(id, Person.class), x, y, 0., 0.); agInfo.setColorValueBetweenZeroAndOne(colorValue); agInfo.setUserDefined(userdefined); agInfo.setAgentState(AgentState.values()[state]); sceneGraph.getAgentPointLayer().addAgent(agInfo); }
passengerPosition.setAgentState(AgentState.TRANSIT_DRIVER); } else if (last) { passengerPosition.setAgentState(AgentState.PERSON_DRIVING_CAR); } else { passengerPosition.setAgentState(AgentState.PERSON_OTHER_MODE);