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; }
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); }
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 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 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); }
last = true ; 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);
agent.speed = freespeed; AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, distFromFromNode, agent.lane); position.setColorValueBetweenZeroAndOne( agent.speed) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_DRIVING_CAR); agent.speed = freespeed; AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, distFromFromNode, agent.lane); position.setColorValueBetweenZeroAndOne( agent.speed) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_DRIVING_CAR); agent.lane = lane; agent.speed = 0.0; AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, distFromFromNode, agent.lane); position.setColorValueBetweenZeroAndOne( agent.speed) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_AT_ACTIVITY); agent.lane = lane; agent.speed = 0.0; AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, distFromFromNode, agent.lane); position.setColorValueBetweenZeroAndOne( agent.speed) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_AT_ACTIVITY);
/** * 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 ; }
agent.speed = speed; AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, queueEnd/* + NetworkLayer.CELL_LENGTH*/, lane); position.setColorValueBetweenZeroAndOne( agent.speed) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_DRIVING_CAR); agent.speed = speed; int lane = 1 + (agent.intId % NetworkUtils.getNumberOfLanesAsInt(org.matsim.core.utils.misc.Time.UNDEFINED_TIME, this.link)); AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, distanceOnLink/* + NetworkLayer.CELL_LENGTH*/, lane); position.setColorValueBetweenZeroAndOne( agent.speed) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_DRIVING_CAR); AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, this.effectiveCellSize, lane); position.setColorValueBetweenZeroAndOne( 0.0) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_AT_ACTIVITY); AgentSnapshotInfo position = snapshotInfoFactory.createAgentSnapshotInfo(agent.id, this.link, this.effectiveCellSize, lane); position.setColorValueBetweenZeroAndOne(0.0) ; position.setAgentState(AgentSnapshotInfo.AgentState.PERSON_AT_ACTIVITY);
@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()); } } }
public final void positionAgentGivenDistanceFromFNode(final Collection<AgentSnapshotInfo> positions, Coord startCoord, Coord endCoord, double lengthOfCurve, QVehicle veh, double distanceFromFromNode, Integer lane, double speedValueBetweenZeroAndOne){ // I think that the main reason why this exists as public method is that AssignmentEmulatingQLane wants to use it directly. // The reason for this, in return, is that positionVehiclesAlongLine(...) is a service method for queue models only. kai, apr'16 MobsimDriverAgent driverAgent = veh.getDriver(); AgentSnapshotInfo pos = snapshotInfoFactory.createAgentSnapshotInfo(driverAgent.getId(), startCoord, endCoord, distanceFromFromNode, lane, lengthOfCurve); pos.setColorValueBetweenZeroAndOne(speedValueBetweenZeroAndOne); if (driverAgent instanceof TransitDriverAgent){ pos.setAgentState(AgentState.TRANSIT_DRIVER); } else if ( driverAgent.getMode().equals(TransportMode.car)) { pos.setAgentState(AgentState.PERSON_DRIVING_CAR); } else { pos.setAgentState(AgentState.PERSON_OTHER_MODE ); } if ( scenario.getPopulation().getPersonAttributes().getAttribute( driverAgent.getId().toString(), "marker" ) != null ) { pos.setAgentState( AgentState.PERSON_OTHER_MODE ) ; } this.positionPassengers(positions, veh.getPassengers(), distanceFromFromNode, startCoord, endCoord, lengthOfCurve, lane+5, speedValueBetweenZeroAndOne); // (this is deliberately first memorizing "pos" but then filling in the passengers first) positions.add(pos); }
if (coord == null) { 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());
/** * 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 }
/** * Test the calculation of a vehicles position if the actual link length is * longer than the euklidean distance. * * @author mrieser */ public void testDistanceOnLink_longLink() { 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) 2000, (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, 500, 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 }