public static void main(String[] args) { Gbl.assertIf(args.length >=1 && args[0]!="" ); run(ConfigUtils.loadConfig(args[0])); // makes some sense to not modify the config here but in the run method to help with regression testing. }
public NetworkRoutingInclAccessEgressModule( final String mode, final PopulationFactory populationFactory, final Network network, final LeastCostPathCalculator routeAlgo, PlansCalcRouteConfigGroup calcRouteConfig) { Gbl.assertNotNull(network); Gbl.assertIf( network.getLinks().size()>0 ) ; // otherwise network for mode probably not defined this.network = network; this.routeAlgo = routeAlgo; this.mode = mode; this.populationFactory = populationFactory; this.stageActivityType = this.mode + " interaction"; if ( !calcRouteConfig.isInsertingAccessEgressWalk() ) { throw new RuntimeException("trying to use access/egress but not switched on in config. " + "currently not supported; there are too many other problems") ; } }
public static Trip findTripStartingAtActivity( final Activity activity, final Plan plan, StageActivityTypes stageActivities ) { Gbl.assertIf( ! stageActivities.isStageActivity( activity.getType()) ) ; List<Trip> trips = getTrips( plan, stageActivities ) ; for ( Trip trip : trips ) { if ( trip.getOriginActivity().equals( activity ) ) { return trip ; } } return null ; }
public static Trip findTripEndingAtActivity(Activity activity, Plan plan, StageActivityTypes stageActivities ) { Gbl.assertIf( ! stageActivities.isStageActivity( activity.getType()) ) ; List<Trip> trips = getTrips(plan.getPlanElements(), stageActivities ) ; for ( Trip trip : trips ) { if ( activity.equals( trip.getDestinationActivity() ) ) { return trip; } } return null ; } public static Trip findTripStartingAtActivity( final Activity activity, final Plan plan, StageActivityTypes stageActivities ) {
@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; } }
@Deprecated // use "decideOnCoord..." public static Coord computeCoordFromActivity( Activity act, ActivityFacilities facs, Network network, Config config ) { // the following might eventually become configurable by config. kai, feb'16 if ( act.getFacilityId()==null ) { if ( act.getCoord()!=null ) { return act.getCoord() ; } else { Gbl.assertNotNull( network ); Link link = network.getLinks().get( act.getLinkId() ) ; return link.getCoord() ; } } else { Gbl.assertIf( facs!=null ) ; ActivityFacility facility = facs.getFacilities().get( act.getFacilityId() ) ; Gbl.assertIf( facility!=null ); return facility.getCoord() ; } }
public static Trip findCurrentTrip( PlanElement currentPlanElement, Plan plan, StageActivityTypes stageActivities ) { if ( currentPlanElement instanceof Activity ) { Gbl.assertIf( stageActivities.isStageActivity( ((Activity)currentPlanElement).getType() ) ) ; } List<Trip> trips = getTrips(plan.getPlanElements(), stageActivities ) ; for ( Trip trip : trips ) { int index = trip.getTripElements().indexOf( currentPlanElement ) ; if ( index != -1 ) { return trip ; } } return null ; } public static Trip findTripEndingAtActivity(Activity activity, Plan plan, StageActivityTypes stageActivities ) {
public static Collection<SimpleFeature> getAllFeatures(final String filename) { try { File dataFile = new File(filename); log.info( "will try to read from " + dataFile.getAbsolutePath() ) ; Gbl.assertIf( dataFile.exists() ); FileDataStore store = FileDataStoreFinder.getDataStore(dataFile); SimpleFeatureSource featureSource = store.getFeatureSource(); SimpleFeatureIterator it = featureSource.getFeatures().features(); List<SimpleFeature> featureSet = new ArrayList<SimpleFeature>(); while (it.hasNext()) { SimpleFeature ft = it.next(); featureSet.add(ft); } it.close(); store.dispose(); return featureSet; } catch (IOException e) { throw new UncheckedIOException(e); } }
Gbl.assertIf( linkIdFromActivity!=null ); return linkIdFromActivity ; } else {
public BasicPlanAgentImpl(Plan plan2, Scenario scenario, EventsManager events, MobsimTimer simTimer) { this.plan = PopulationUtils.unmodifiablePlan(plan2) ; // yy MZ suggests, and I agree, to always give the agent a full plan, and consume that plan as the agent goes. kai, nov'14 this.scenario = scenario ; this.events = events ; this.simTimer = simTimer ; List<PlanElement> planElements = this.getCurrentPlan().getPlanElements(); if (planElements.size() > 0) { Activity firstAct = (Activity) planElements.get(0); // this.setCurrentLinkId( firstAct.getLinkId() ) ; final Id<Link> linkId = PopulationUtils.computeLinkIdFromActivity(firstAct, scenario.getActivityFacilities(), scenario.getConfig() ); Gbl.assertIf( linkId!=null ); this.setCurrentLinkId( linkId ); this.setState(MobsimAgent.State.ACTIVITY) ; calculateAndSetDepartureTime(firstAct); } }
public static void configure( AllowsConfiguration ao ) { Gbl.assertIf( ao instanceof Controler); // we need the scenario; otherwise find other way Controler controler = (Controler) ao; Carriers carriers = (Carriers) controler.getScenario().getScenarioElement( CARRIERS ); final CarrierModule carrierModule = new CarrierModule( carriers ); carrierModule.setPhysicallyEnforceTimeWindowBeginnings( true ); ao.addOverridingModule( carrierModule ) ; ao.addOverridingModule( new AbstractModule(){ @Override public void install(){ // yyyy these two are just quick fixes in order to get the material up and running without having it all in the run script. bind( CarrierPlanStrategyManagerFactory.class ).toInstance( () -> null ); bind( CarrierScoringFunctionFactory.class ).to( CarrierScoringFunctionFactoryImpl.class ) ; } } ) ; }
/** * Informs the simulation that the specified agent wants to depart from its * current activity. The simulation can then put the agent onto its vehicle * on a link or teleport it to its destination. * */ private void arrangeAgentDeparture(final MobsimAgent agent) { double now = this.getSimTimer().getTimeOfDay(); Id<Link> linkId = agent.getCurrentLinkId(); Gbl.assertIf( linkId!=null ); events.processEvent(new PersonDepartureEvent(now, agent.getId(), linkId, agent.getMode())); for (DepartureHandler departureHandler : this.departureHandlers) { if (departureHandler.handleDeparture(now, agent, linkId)) { return; } } log.warn("no departure handler wanted to handle the departure of agent " + agent.getId()); // yy my intuition is that this should be followed by setting the agent state to abort. kai, nov'14 }
@Override public final Id<Vehicle> getPlannedVehicleId() { NetworkRoute route = (NetworkRoute) this.getCurrentLeg().getRoute(); // if casts fail: illegal state. if (route.getVehicleId() != null) { return route.getVehicleId(); } Gbl.assertIf( scenario.getConfig().qsim().getUsePersonIdForMissingVehicleId() ); return Id.create(this.getId(), Vehicle.class); // we still assume the vehicleId is the agentId if no vehicleId is given. } @Override
@Override public double computeContributionOfOpportunity(ActivityFacility origin, final AggregationObject destination, Double departureTime) { Person person = null ; // I think that this is ok ActivityFacilitiesFactory activityFacilitiesFactory = new ActivityFacilitiesFactoryImpl(); ActivityFacility destinationFacility = activityFacilitiesFactory.createActivityFacility(null, destination.getNearestNode().getCoord()); Gbl.assertNotNull(tripRouter); List<? extends PlanElement> plan = tripRouter.calcRoute(mode, origin, destinationFacility, departureTime, person); // Vehicle vehicle = null ; // I think that this is ok double utility = 0.; List<Leg> legs = TripStructureUtils.getLegs(plan); // TODO Doing it like this, the pt interaction (e.g. waiting) times will be omitted! Gbl.assertIf(!legs.isEmpty()); for (Leg leg : legs) { // Add up all utility components of leg utility += leg.getRoute().getDistance() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfDistance(); utility += leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfTraveling() / 3600.; utility += -leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getPerforming_utils_hr() / 3600.; } // Utility based on opportunities that are attached to destination node double sumExpVjkWalk = destination.getSum(); // exp(beta * a) * exp(beta * b) = exp(beta * (a+b)) return Math.exp(this.planCalcScoreConfigGroup.getBrainExpBeta() * utility) * sumExpVjkWalk; } }
Gbl.assertIf( tripAfterAct!=null ); // there could also just be a sequence of activities?! if ( downstreamMode==null ) { final String currentMainMode = this.tripRouter.getMainModeIdentifier().identifyMainMode( tripAfterAct.getTripElements() );
case fromFile: case setInScenario: Gbl.assertIf(! this.activityFacilities.getFacilities().isEmpty() ); break; case onePerActivityLinkInPlansFile:
Gbl.assertIf( maxCountValue > 0. ); dataset1.addSeries("f1x", new double[][] {{100.0, maxCountValue},{100.0, maxCountValue}}); dataset1.addSeries("f2x", new double[][] {{100.0, maxCountValue},{200.0, 2*maxCountValue}});
Gbl.assertIf( result.size()==1); Leg newLeg = (Leg) result.get(0) ;