/** * This constructor is used by reflection. It's signature mustn't be changed or it won't work anymore. :-( */ public LanesBasedWidthCalculator(final Network network, final Double coef) { double w = network.getEffectiveLaneWidth(); if (Double.isNaN(w)) { log.warn("Effective lane width in network is set to Double.NaN. Set a real value in your network.xml to make this tool work with this value. Using 3.75 as effective lane width..."); this.effectiveLaneWidth = 3.75; } else { this.effectiveLaneWidth = w; } this.widthCoefficient = coef; }
@Override public void startLinks(final Network network, final BufferedWriter out) throws IOException { out.write("\t<links"); if (network.getCapacityPeriod() != Integer.MIN_VALUE) { out.write(" capperiod=\"" + Time.writeTime(network.getCapacityPeriod()) + "\""); } out.write(" effectivecellsize=\"" + network.getEffectiveCellSize() + "\""); out.write(" effectivelanewidth=\"" + network.getEffectiveLaneWidth() + "\""); out.write(">\n"); }
@Override public void startLinks(final Network network, final BufferedWriter out) throws IOException { out.write("\t<links"); if (network.getCapacityPeriod() != Integer.MIN_VALUE) { out.write(" capperiod=\"" + Time.writeTime(network.getCapacityPeriod()) + "\""); } out.write(" effectivecellsize=\"" + network.getEffectiveCellSize() + "\""); out.write(" effectivelanewidth=\"" + network.getEffectiveLaneWidth() + "\""); out.write(">\n"); }
@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); }
@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
@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 public OTFVisConfigGroup getOTFVisConfig() { OTFVisConfigGroup otfVisConfig = ConfigUtils.addOrGetModule(this.scenario.getConfig(), OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class); if (otfVisConfig == null) { otfVisConfig = new OTFVisConfigGroup(); } double effLaneWidth = this.scenario.getNetwork().getEffectiveLaneWidth() ; if (! Double.isNaN(effLaneWidth)){ otfVisConfig.setEffectiveLaneWidth( effLaneWidth ) ; } return otfVisConfig ; }
@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 ; }
public OTFFileWriter(Scenario scenario, String outfilename) { this.connect = new OTFConnectionManager(); this.connect.connectLinkToWriter(OTFLinkAgentsHandler.Writer.class); this.connect.connectWriterToReader(OTFLinkAgentsHandler.Writer.class, OTFLinkAgentsHandler.class); this.outFileName = outfilename; this.quad = new SnapshotWriterQuadTree(scenario.getNetwork()); this.quad.initQuadTree(connect); this.writer = new OTFAgentsListHandler.Writer(); this.writer.setSrc(new VisData() { @Override public Collection<AgentSnapshotInfo> addAgentSnapshotInfo(Collection<AgentSnapshotInfo> inPositions) { inPositions.addAll(positions); return inPositions; } }); if (ConfigUtils.addOrGetModule(scenario.getConfig(), OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class) != null) { ConfigUtils.addOrGetModule(scenario.getConfig(), OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class).setEffectiveLaneWidth(scenario.getNetwork().getEffectiveLaneWidth()); } OTFClientControl.getInstance().setOTFVisConfig(ConfigUtils.addOrGetModule(scenario.getConfig(), OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class)); try { this.zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(this.outFileName), FILE_BUFFERSIZE)); this.writeQuad(); this.writeConstData(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
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; }
@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); }
if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() );
/** * Tests if the default values of a network instance are the same as the defaults specified in the network_v1.dtd */ @Test public void testDefaultValues(){ Network net = new NetworkImpl(); Assert.assertEquals(7.5, net.getEffectiveCellSize(), 0.0); Assert.assertEquals(3.75, net.getEffectiveLaneWidth(), 0.0); Assert.assertEquals(3600.0, net.getCapacityPeriod(), 0.0); Node node1 = NetworkUtils.createNode(Id.create(1, Node.class), new Coord((double) 0, (double) 0)); Node node2 = NetworkUtils.createNode(Id.create(2, Node.class), new Coord((double) 1000, (double) 0)); net.addNode(node1); net.addNode(node2); final NetworkFactory nf = net.getFactory(); Gbl.assertNotNull(nf); Link link = nf.createLink(Id.create(1, Link.class), node1, node2); Assert.assertEquals(1, link.getAllowedModes().size()); Assert.assertEquals("car", link.getAllowedModes().iterator().next()); }
@Test public void testGetWidth_laneWidthNaN() { Network net = NetworkUtils.createNetwork(); Node n1 = net.getFactory().createNode(Id.create("1", Node.class), new Coord((double) 0, (double) 0)); Node n2 = net.getFactory().createNode(Id.create("2", Node.class), new Coord((double) 1000, (double) 0)); net.addNode(n1); net.addNode(n2); Link l1 = net.getFactory().createLink(Id.create("1", Link.class), n1, n2); l1.setNumberOfLanes(2.0); Assert.assertEquals("The default in the Network is set to a value that is possibly not conform to the default in network_v1.dtd", 3.75, net.getEffectiveLaneWidth(), 1e-10); ((Network)net).setEffectiveLaneWidth(1.0); double w = new LanesBasedWidthCalculator((Network) net, 1.0).getWidth(l1); Assert.assertFalse(Double.isNaN(w)); Assert.assertEquals(2.0, w, 1e-10); }