/** * Constructor * * @param eventsMonitors */ protected PerceptHandler(final EventsMonitorRegistry eventsMonitors) { Gbl.assertNotNull( eventsMonitors ); this.eventsMonitors = eventsMonitors ; }
public NetworkRoutingModule( final String mode, final PopulationFactory populationFactory, final Network network, final LeastCostPathCalculator routeAlgo) { Gbl.assertNotNull(network); // Gbl.assertIf( network.getLinks().size()>0 ) ; // otherwise network for mode probably not defined // makes many tests fail. this.network = network; this.routeAlgo = routeAlgo; this.mode = mode; this.populationFactory = populationFactory; }
public final void putAccessibilityContributionCalculator(String mode, AccessibilityContributionCalculator calculator) { LOG.info("Adding accessibility contribution calculator for " + mode + "."); Gbl.assertNotNull(calculator); this.calculators.put(mode , calculator) ; }
public EditPlans( QSim mobsim, TripRouter tripRouter, EditTrips editTrips ) { Gbl.assertNotNull( this.mobsim = mobsim ); Gbl.assertNotNull( this.tripRouter = tripRouter ); Gbl.assertNotNull( this.editTrips = editTrips ) ; Gbl.assertNotNull( this.pf = mobsim.getScenario().getPopulation().getFactory() ) ; } public boolean addActivityAtEnd(MobsimAgent agent, Activity activity, String routingMode) {
@Override public final Scenario getScenario() { if (this.injectorCreated) { Gbl.assertNotNull(this.injector); return this.injector.getInstance(Scenario.class); } else { if ( scenario == null ) { log.error( "Trying to get Scenario before it was instanciated."); log.error( "When passing a config file or a config file path to the Controler constructor," ); log.error( "Scenario will be loaded first when the run() method is invoked." ); throw new IllegalStateException( "Trying to get Scenario before is was instanciated." ); } return this.scenario; } }
@Override public final void notifyArrivalOnLinkByNonNetworkMode(final Id<Link> linkId) { Gbl.assertNotNull(linkId); this.setCurrentLinkId( linkId ) ; }
public double getMaximumVelocityFromLinkSpeedCalculator(QVehicle veh, double now) { final LinkSpeedCalculator linkSpeedCalculator = AbstractQLink.this.linkSpeedCalculator; Gbl.assertNotNull(linkSpeedCalculator); return linkSpeedCalculator.getMaximumVelocity(veh, AbstractQLink.this.link, now) ; }
/** * This method supports a cache where ids are stored and re-used per type. */ public static <T> Id<T> create(final String key, final Class<T> type) { Map<String, Id<?>> map = cache.get(type); if (map == null) { map = new ConcurrentHashMap<String, Id<?>>(); cache.put(type, map); } Gbl.assertNotNull(key); Id<?> id = map.get(key); if (id == null) { id = new IdImpl<T>(key); map.put(key, id); } return (Id<T>) id; }
public final void parse(final URL url) throws UncheckedIOException { Gbl.assertNotNull(url); this.theSource = url.toString(); log.info("starting to parse xml from url " + this.theSource + " ..."); System.out.flush(); if (url.getFile().endsWith(".gz")) { try { parse(new InputSource(new GZIPInputStream(url.openStream()))); } catch (IOException e) { throw new RuntimeException(e); } } else { parse(new InputSource(url.toExternalForm())); } }
@Override public final void notifyMoveOverNode(Id<Link> newLinkId) { if (expectedLinkWarnCount < 10 && !newLinkId.equals(this.cachedNextLinkId)) { log.warn("Agent did not end up on expected link. Ok for within-day replanning agent, otherwise not. Continuing " + "anyway ... This warning is suppressed after the first 10 warnings.") ; expectedLinkWarnCount++; } Gbl.assertNotNull(newLinkId); this.basicPlanAgentDelegate.setCurrentLinkId( newLinkId ) ; this.basicPlanAgentDelegate.incCurrentLinkIndex(); this.cachedNextLinkId = null; //reset cached nextLink }
/** * 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; }
@Override public void run(Plan plan) { Plan newPlan = executedPlans.getExecutedPlans().get( plan.getPerson().getId() ) ; Gbl.assertNotNull( newPlan ) ; PopulationUtils.copyFromTo(newPlan, plan); } };
public static Id<Link> decideOnLinkIdForActivity( Activity act, Scenario sc ) { if ( act.getFacilityId() !=null ) { final ActivityFacility facility = sc.getActivityFacilities().getFacilities().get( act.getFacilityId() );; if ( facility==null ) { throw new RuntimeException("facility ID given but not in facilities container") ; } Gbl.assertNotNull( facility.getLinkId() ); return facility.getLinkId(); } Gbl.assertNotNull( act.getLinkId() ); return act.getLinkId() ; } public static Coord decideOnCoordForActivity( Activity act, Scenario sc ) {
private void handleActivityEndEvent(ActivityEndEvent ev) { Map<Id<Person>, Monitor> toRemove = new HashMap<>(); Id<Person> driverId = ev.getPersonId(); Gbl.assertNotNull(driverId); Monitor monitor = monitors.get(EndedActivity).get(driverId); if (monitor != null) { if (monitor.getAgentId().equals( ev.getPersonId()) && monitor.getLinkId().equals( ev.getLinkId())) { if (monitor.getHandler().handle(monitor.getAgentId(), monitor.getLinkId(), monitor.getEvent())) { toRemove.put(driverId,monitor); } } } synchronized (monitors.get(EndedActivity)) { monitors.get(EndedActivity).entrySet().removeAll(toRemove.entrySet()); } }
private void handleLinkEnterEvent(LinkEnterEvent ev) { Map<Id<Person>, Monitor> toRemove = new HashMap<>(); LinkEnterEvent event = ev; Id<Person> driverId = this.getDriverOfVehicle(event.getVehicleId()); Gbl.assertNotNull(driverId); Monitor monitor = monitors.get(EnteredLink).get(driverId); if (monitor != null) { if (monitor.getAgentId().equals(driverId) && event.getLinkId().equals(monitor.getLinkId())) { if (monitor.getHandler().handle(monitor.getAgentId(), monitor.getLinkId(), monitor.getEvent())) { toRemove.put(driverId,monitor); } } } synchronized (monitors.get(EnteredLink)) { monitors.get(EnteredLink).entrySet().removeAll(toRemove.entrySet()); } }
private void createAndAddSignalGroupsFromData(SignalSystem system){ //process information of SignalGroupsData object and create the signal groups Map<Id<SignalGroup>, SignalGroupData> signalGroupDataMap = this.signalsData.getSignalGroupsData().getSignalGroupDataBySystemId(system.getId()); for (SignalGroupData signalGroupData : signalGroupDataMap.values()){ SignalGroup group = new SignalGroupImpl(signalGroupData.getId()); for (Id<Signal> signalId : signalGroupData.getSignalIds()){ Signal signal = system.getSignals().get(signalId); Gbl.assertNotNull(signal); group.addSignal(signal); } system.addSignalGroup(group); } }
public static Config loadConfig(final URL url, ConfigGroup... customModules) throws UncheckedIOException { Gbl.assertNotNull(url); Config config = new Config(); config.addCoreModules(); for (ConfigGroup customModule : customModules) { config.addModule(customModule); } new ConfigReader(config).parse(url); config.setContext(url); return config; }
public static Point getRandomPointInFeature( Random rnd, SimpleFeature ft ) { Gbl.assertNotNull(ft ); Point p = null; double x, y; // generate a random point until a point inside the feature geometry is found do { x = ft.getBounds().getMinX() + rnd.nextDouble() * (ft.getBounds().getMaxX() - ft.getBounds().getMinX()); y = ft.getBounds().getMinY() + rnd.nextDouble() * (ft.getBounds().getMaxY() - ft.getBounds().getMinY()); p = MGC.xy2Point(x, y); } while ( ! (((Geometry) ft.getDefaultGeometry()).contains(p)) ); return p; }
@Override public boolean handle(String agentID, String actionID, Object[] args) { // assertions: MobsimAgent mobsimAgent = model.getMobsimAgentFromIdString(agentID) ; Gbl.assertNotNull(mobsimAgent) ; Gbl.assertIf( args.length >= 1 ); Gbl.assertIf( args[0] instanceof MATSimModel.RoutingMode) ; // could have some default MATSimModel.RoutingMode routingMode = (MATSimModel.RoutingMode)args[0]; if (WithinDayAgentUtils.isOnReplannableCarLeg(mobsimAgent)) { model.getReplanner().editTrips().replanCurrentTrip(mobsimAgent, 0.0, routingMode.name()); } return true; } }
/** * 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()); }