@Override void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1) { double effectiveCellSize = ((Network)network).getEffectiveCellSize() ; SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() ); } AbstractAgentSnapshotInfoBuilder snapshotBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); this.context = new NetsimEngineContext(events, effectiveCellSize, agentCounter, snapshotBuilder, qsimConfig, mobsimTimer, linkWidthCalculator ) ; this.netsimEngine = netsimEngine1 ; } @Override QNodeI createNetsimNode(Node node) {
public SnapshotGenerator(final Network network, final double snapshotPeriod, final QSimConfigGroup config) { this.network = network; int initialCapacity = (int)(network.getLinks().size()*1.1); this.eventLinks = new HashMap<>(initialCapacity, 0.95f); this.linkList = new ArrayList<>(initialCapacity); this.eventAgents = new HashMap<>(1000, 0.95f); this.snapshotPeriod = snapshotPeriod; this.capCorrectionFactor = config.getFlowCapFactor() / network.getCapacityPeriod(); this.storageCapFactor = config.getStorageCapFactor(); this.snapshotStyle = config.getSnapshotStyle(); if (! Double.isNaN( config.getLinkWidthForVis() )){ this.linkWidthCalculator.setLinkWidthForVis( config.getLinkWidthForVis() ); } if (! Double.isNaN(network.getEffectiveLaneWidth())){ this.linkWidthCalculator.setLaneWidth(network.getEffectiveLaneWidth()); } reset(-1); }
public void drawLink() { GL2 gl = GLContext.getCurrentGL().getGL2(); if (drawLinkAsLine) { gl.glLineWidth(1); gl.glBegin(GL2.GL_LINES); gl.glVertex2f(quad[0].x, quad[0].y); gl.glVertex2f(quad[1].x, quad[1].y); gl.glEnd(); } else { linkWidthCalculator.setLaneWidth(OTFClientControl.getInstance().getOTFVisConfig().getEffectiveLaneWidth()); linkWidthCalculator.setLinkWidthForVis(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidth()); float width = (float) linkWidthCalculator.calculateLinkWidth(this.nrLanes); final Point2D.Float ortho = calcOrtho(this.quad[0].x, this.quad[0].y, this.quad[1].x, this.quad[1].y, width); // (yy this is where the width of the links for drawing is set) this.quad[2] = new Point2D.Float(this.quad[0].x + ortho.x, this.quad[0].y + ortho.y); this.quad[3] = new Point2D.Float(this.quad[1].x + ortho.x, this.quad[1].y + ortho.y); //Draw quad TextureCoords co = new TextureCoords(0,0,1,1); gl.glBegin(GL2.GL_QUADS); gl.glTexCoord2f(co.right(),co.bottom()); gl.glVertex3f(quad[0].x, quad[0].y, 0); gl.glTexCoord2f(co.right(),co.top()); gl.glVertex3f(quad[1].x, quad[1].y, 0); gl.glTexCoord2f(co.left(), co.top()); gl.glVertex3f(quad[3].x, quad[3].y, 0); gl.glTexCoord2f(co.left(),co.bottom()); gl.glVertex3f(quad[2].x, quad[2].y, 0); gl.glEnd(); } }
/** * 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 }
public void recalculatePositions(VisLinkWLanes linkData, SnapshotLinkWidthCalculator linkWidthCalculator) { double linkWidth = linkWidthCalculator.calculateLinkWidth(linkData.getNumberOfLanes()) ; linkData.setLinkWidth(linkWidth); Point2D.Double linkStartCenter = this.calculatePointOnLink(linkData, 0.0, 0.5); double laneOffset = - noLanesFloor / 2 * linkWidthCalculator.getLaneWidth(); if (noLanesFloor % 2 == 0){ laneOffset = laneOffset + (linkWidthCalculator.getLaneWidth()/2); Point2D.Double drivingLaneEnd = this.calcPoint(laneEnd, linkData.getLinkOrthogonalVector(), laneOffset); lane.addDrivingLane(i, drivingLaneStart, drivingLaneEnd); laneOffset = laneOffset + linkWidthCalculator.getLaneWidth();
/** * creator based on Coord * @param curveLength lengths are usually different (usually longer) than the euclidean distances between the startCoord and endCoord */ public AgentSnapshotInfo createAgentSnapshotInfo(Id<Person> agentId, Coord startCoord, Coord endCoord, double distanceOnLink, Integer lane, double curveLength) { PositionInfo info = new PositionInfo() ; info.setId(agentId) ; double lanePosition = this.linkWidthCalculator.calculateLanePosition(lane); Gbl.assertNotNull( startCoord ); Gbl.assertNotNull( endCoord ); calculateAndSetPosition(info, startCoord, endCoord, distanceOnLink, curveLength, lanePosition) ; return info; }
/** * 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 }
/** * Generate snapshot info based on Link. * * Comments:<ul> * <li>One could argue that this method should not know about Links at all, * but it shortens code at several places, and since Link is a standard interface, I see no reason to not provide this * as a service. * </ul> */ public AgentSnapshotInfo createAgentSnapshotInfo(Id<Person> agentId, Link link, double distanceOnLink, int lane) { PositionInfo info = new PositionInfo() ; info.setId(agentId) ; double lanePosition = this.linkWidthCalculator.calculateLanePosition(lane); calculateAndSetPosition(info, link.getFromNode().getCoord(), link.getToNode().getCoord(), distanceOnLink, link.getLength(), lanePosition ); return info; }
@Override void initializeFactory( AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1 ) { this.netsimEngine = netsimEngine1; double effectiveCellSize = network.getEffectiveCellSize() ; SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() ); } AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, agentSnapshotInfoBuilder, qsimConfig, mobsimTimer, linkWidthCalculator ); } @Override
private void recalculatePositions() { SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLaneWidth(OTFClientControl.getInstance().getOTFVisConfig().getEffectiveLaneWidth()); linkWidthCalculator.setLinkWidthForVis(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidth()); for (VisLinkWLanes linkData : this.lanesLinkData.values()){ this.laneModelBuilder.recalculatePositions(linkData, linkWidthCalculator); } }
@Override void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1) { this.netsimEngine = netsimEngine1 ; double effectiveCellSize = network.getEffectiveCellSize() ; SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() ); } AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, agentSnapshotInfoBuilder, qsimConfig, mobsimTimer, linkWidthCalculator ); delegate.initializeFactory(agentCounter, mobsimTimer, netsimEngine1); }
@Override void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface arg2) { network = arg2.getNetsimNetwork().getNetwork(); double effectiveCellSize = ( network).getEffectiveCellSize() ; SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() ); } AbstractAgentSnapshotInfoBuilder snapshotInfoBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); this.context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, snapshotInfoBuilder, qsimConfig, mobsimTimer, linkWidthCalculator ) ; this.netsimEngine = arg2 ; }
@Override void initializeFactory( AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1 ) { this.netsimEngine = netsimEngine1; double effectiveCellSize = scenario.getNetwork().getEffectiveCellSize() ; SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( scenario.getConfig().qsim().getLinkWidthForVis() ); linkWidthCalculator.setLaneWidth( scenario.getNetwork().getEffectiveLaneWidth() ); AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, agentSnapshotInfoBuilder, scenario.getConfig().qsim(), mobsimTimer, linkWidthCalculator ); } @Override
@Override void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface simEngine1) { SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( scenario.getConfig().qsim().getLinkWidthForVis() ); linkWidthCalculator.setLaneWidth( scenario.getNetwork().getEffectiveLaneWidth() ); AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); this.netsimEngine = simEngine1; this.context = new NetsimEngineContext( events, scenario.getNetwork().getEffectiveCellSize(), agentCounter, agentSnapshotInfoBuilder, scenario.getConfig().qsim(), mobsimTimer, linkWidthCalculator ); delegate.initializeFactory(agentCounter, mobsimTimer, simEngine1); }
public static OnTheFlyServer startServerAndRegisterWithQSim(Config config, Scenario scenario, EventsManager events, QSim qSim, NonPlanAgentQueryHelper nonPlanAgentQueryHelper) { OnTheFlyServer server = OnTheFlyServer.createInstance(scenario, events, qSim, nonPlanAgentQueryHelper); if (config.transit().isUseTransit()) { Network network = scenario.getNetwork(); TransitSchedule transitSchedule = scenario.getTransitSchedule(); // TransitQSimEngine transitEngine = qSim.getTransitEngine(); // AgentTracker agentTracker = transitEngine.getAgentTracker(); // AgentSnapshotInfoFactory snapshotInfoFactory = qSim.getVisNetwork().getagentsnapshotinfofactory(); SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( config.qsim().getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() ); } AgentSnapshotInfoFactory snapshotInfoFactory = new AgentSnapshotInfoFactory(linkWidthCalculator); for ( AgentTracker agentTracker : qSim.getAgentTrackers() ) { FacilityDrawer.Writer facilityWriter = new FacilityDrawer.Writer(network, transitSchedule, agentTracker, snapshotInfoFactory); server.addAdditionalElement(facilityWriter); } } server.pause(); return server; }
SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( config.qsim().getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() );