@Override public void setStartTime(double seconds) { act.setStartTime(seconds); }
@Override public void setStartTime(double seconds) { this.delegate.setStartTime(seconds); } @Override
private void startAct(final Attributes atts) { if (atts.getValue(ATTR_ACT_LINK) != null) { Id<Link> linkId = Id.create(atts.getValue(ATTR_ACT_LINK), Link.class); final Id<Link> linkId1 = linkId; this.curract = PopulationUtils.createAndAddActivityFromLinkId(this.currplan, atts.getValue(ATTR_ACT_TYPE), linkId1); if ((atts.getValue(ATTR_ACT_X) != null) && (atts.getValue(ATTR_ACT_Y) != null)) { final Coord coord = parseCoord( atts ); this.curract.setCoord(coord); } } else if ((atts.getValue(ATTR_ACT_X) != null) && (atts.getValue(ATTR_ACT_Y) != null)) { final Coord coord = parseCoord( atts ); this.curract = PopulationUtils.createAndAddActivityFromCoord(this.currplan, atts.getValue(ATTR_ACT_TYPE), coord); } else { throw new IllegalArgumentException("In this version of MATSim either the coords or the link must be specified for an Act."); } this.curract.setStartTime(Time.parseTime(atts.getValue(ATTR_ACT_STARTTIME))); this.curract.setMaximumDuration(Time.parseTime(atts.getValue(ATTR_ACT_MAXDUR))); this.curract.setEndTime(Time.parseTime(atts.getValue(ATTR_ACT_ENDTIME))); String fId = atts.getValue(ATTR_ACT_FACILITY); if (fId != null) { this.curract.setFacilityId(Id.create(fId, ActivityFacility.class)); } if (this.routeDescription != null) { finishLastRoute(); } }
private void startAct(final Attributes atts) { if (atts.getValue(ATTR_ACT_LINK) != null) { Id<Link> linkId = Id.create(atts.getValue(ATTR_ACT_LINK), Link.class); final Id<Link> linkId1 = linkId; this.curract = PopulationUtils.createAndAddActivityFromLinkId(this.currplan, atts.getValue(ATTR_ACT_TYPE), linkId1); if ((atts.getValue(ATTR_ACT_X) != null) && (atts.getValue(ATTR_ACT_Y) != null)) { final Coord coord = parseCoord( atts ); this.curract.setCoord(coord); } } else if ((atts.getValue(ATTR_ACT_X) != null) && (atts.getValue(ATTR_ACT_Y) != null)) { final Coord coord = parseCoord( atts ); this.curract = PopulationUtils.createAndAddActivityFromCoord(this.currplan, atts.getValue(ATTR_ACT_TYPE), coord); } else { throw new IllegalArgumentException("In this version of MATSim either the coords or the link must be specified for an Act."); } this.curract.setStartTime(Time.parseTime(atts.getValue(ATTR_ACT_STARTTIME))); this.curract.setMaximumDuration(Time.parseTime(atts.getValue(ATTR_ACT_MAXDUR))); this.curract.setEndTime(Time.parseTime(atts.getValue(ATTR_ACT_ENDTIME))); String fId = atts.getValue(ATTR_ACT_FACILITY); if (fId != null) { this.curract.setFacilityId(Id.create(fId, ActivityFacility.class)); } if (this.routeDescription != null) { finishLastRoute(); } }
private void startAct(final Attributes atts) { if (atts.getValue("zone") != null) { log.info("The attribute 'zone' of <act> will be ignored"); } Activity act; if (atts.getValue("link") != null) { Id<Link> linkId = Id.create(atts.getValue("link"), Link.class); final Id<Link> linkId1 = linkId; act = PopulationUtils.createAndAddActivityFromLinkId(this.currplan, atts.getValue("type"), linkId1); if (atts.getValue(ATTR_X100) != null && atts.getValue(ATTR_Y100) != null) { final Coord coord = parseCoord( atts ); act.setCoord(coord); } } else if (atts.getValue(ATTR_X100) != null && atts.getValue(ATTR_Y100) != null) { final Coord coord = parseCoord( atts ); act = PopulationUtils.createAndAddActivityFromCoord(this.currplan, atts.getValue("type"), coord); } else { throw new IllegalArgumentException("Either the coords or the link must be specified for an Act."); } act.setStartTime(Time.parseTime(atts.getValue("start_time"))); act.setMaximumDuration(Time.parseTime(atts.getValue("dur"))); act.setEndTime(Time.parseTime(atts.getValue("end_time"))); if (this.routeNodes != null) { this.currroute.setLinkIds(this.prevAct.getLinkId(), NetworkUtils.getLinkIds(RouteUtils.getLinksFromNodes(NetworkUtils.getNodes(this.network, this.routeNodes))), act.getLinkId()); this.routeNodes = null; this.currroute = null; } this.prevAct = act; }
private void startAct(final Attributes atts) { Activity act = null; if (atts.getValue("link") != null) { final Id<Link> linkId = Id.create(atts.getValue("link"), Link.class); act = PopulationUtils.createAndAddActivityFromLinkId(this.currplan, atts.getValue("type"), linkId); if (atts.getValue(ATTR_X100) != null && atts.getValue(ATTR_Y100) != null) { final Coord coord = parseCoord( atts ); act.setCoord(coord); } } else if (atts.getValue(ATTR_X100) != null && atts.getValue(ATTR_Y100) != null) { final Coord coord = parseCoord( atts ); act = PopulationUtils.createAndAddActivityFromCoord(this.currplan, atts.getValue("type"), coord); } else { throw new IllegalArgumentException("Either the coords or the link must be specified for an Act."); } act.setStartTime(Time.parseTime(atts.getValue("start_time"))); act.setMaximumDuration(Time.parseTime(atts.getValue("dur"))); act.setEndTime(Time.parseTime(atts.getValue("end_time"))); if (this.routeNodes != null) { this.currroute.setLinkIds(this.prevAct.getLinkId(), NetworkUtils.getLinkIds(RouteUtils.getLinksFromNodes(NetworkUtils.getNodes(this.network, this.routeNodes))), act.getLinkId()); this.routeNodes = null; this.currroute = null; } this.prevAct = act; }
@Override public void handleEvent(ActivityStartEvent event) { Activity activity = PopulationUtils.createActivityFromLinkId(event.getActType(), event.getLinkId()); activity.setFacilityId(event.getFacilityId()); activity.setStartTime(event.getTime()); activities.put(event.getPersonId(), activity); }
protected Activity createActivity(StayTask task) { Activity act = populFactory.createActivityFromLinkId("s", task.getLink().getId()); act.setStartTime(task.getBeginTime()); act.setEndTime(task.getEndTime()); return act; }
public void handleEvent(ActivityStartEvent event) { Activity activity = PopulationUtils.createActivityFromLinkId(event.getActType(), event.getLinkId()); activity.setFacilityId(event.getFacilityId()); activity.setStartTime(event.getTime()); if(event.getActType().equals(FreightConstants.END)){ activity.setEndTime(Time.UNDEFINED_TIME); scoringFunction.handleActivity(activity); } else{ TourActivity tourActivity = getTourActivity(); assert activity.getLinkId().toString().equals(tourActivity.getLocation().toString()) : "linkId of activity is not equal to linkId of tourActivity. This must not be."; FreightActivity freightActivity = new FreightActivity(activity, tourActivity.getTimeWindow()); currentActivity = freightActivity; } }
public Activity getActivity() { Activity activity = PopulationUtils.createActivityFromCoordAndLinkId(type, coord.getCoord(), linkIdString == null ? null : Id.createLinkId(linkIdString)); activity.setEndTime(endTime); activity.setFacilityId(facIdString == null ? null : Id.create(facIdString, ActivityFacility.class)); activity.setMaximumDuration(maximumDuration); activity.setStartTime(startTime); return activity; } }
act.setStartTime(0); act.setMaximumDuration(act.getEndTime()); } else if (cnt == max) { double time = leg.getDepartureTime() + leg.getTravelTime(); act.setStartTime(time); if (time < 24*3600) { time = 24*3600; act.setStartTime(leg.getDepartureTime() + leg.getTravelTime()); act.setEndTime(act.getStartTime()+act.getMaximumDuration());
act.setStartTime(Time.UNDEFINED_TIME) ;
private void initializeActivity(Activity act, double now) { this.setState(MobsimAgent.State.ACTIVITY) ; this.getEvents().processEvent( new ActivityStartEvent(now, this.getId(), this.getCurrentLinkId(), act.getFacilityId(), act.getType())); calculateAndSetDepartureTime(act); getModifiablePlan(); // this is necessary to make the plan modifiable, so that setting the start time (next line) is actually feasible. kai/mz, oct'16 ((Activity) getCurrentPlanElement()).setStartTime(now); }
private static void copyPlanFieldsToFrom(Plan planTarget, LCPlan planTemplate) { planTarget.setScore(planTemplate.getScore()); int actLegIndex = 0; for (PlanElement pe : planTarget.getPlanElements()) { if (pe instanceof Activity) { LCActivity actTemplate = ((LCActivity) planTemplate.getPlanElements().get(actLegIndex)); ((Activity) pe).setEndTime(actTemplate.getEndTime()); ((Activity) pe).setCoord(actTemplate.getCoord()); ((Activity) pe).setFacilityId(actTemplate.getFacilityId()); ((Activity) pe).setLinkId(actTemplate.getLinkId()); ((Activity) pe).setMaximumDuration(actTemplate.getMaximumDuration()); ((Activity) pe).setStartTime(actTemplate.getStartTime()); ((Activity) pe).setType(actTemplate.getType()); } else if (pe instanceof Leg) { LCLeg legTemplate = ((LCLeg) planTemplate.getPlanElements().get(actLegIndex)); Leg r = ((Leg) pe); r.setTravelTime( legTemplate.getArrivalTime() - r.getDepartureTime() ); ((Leg) pe).setDepartureTime(legTemplate.getDepartureTime()); ((Leg) pe).setMode(legTemplate.getMode()); ((Leg) pe).setRoute(legTemplate.getRoute()); ((Leg) pe).setTravelTime(legTemplate.getTravelTime()); } else throw new RuntimeException("Unexpected PlanElement type was found: " + pe.getClass().toString() + ". Aborting!"); actLegIndex++; } }
private static void copyPlanFieldsToFrom1(Plan planTarget, Plan planTemplate) { planTarget.setScore(planTemplate.getScore()); int actLegIndex = 0; for (PlanElement pe : planTarget.getPlanElements()) { if (pe instanceof Activity) { Activity actTemplate = ((Activity) planTemplate.getPlanElements().get(actLegIndex)); ((Activity) pe).setEndTime(actTemplate.getEndTime()); ((Activity) pe).setCoord(actTemplate.getCoord()); ((Activity) pe).setFacilityId(actTemplate.getFacilityId()); ((Activity) pe).setLinkId(actTemplate.getLinkId()); ((Activity) pe).setMaximumDuration(actTemplate.getMaximumDuration()); ((Activity) pe).setStartTime(actTemplate.getStartTime()); ((Activity) pe).setType(actTemplate.getType()); } else if (pe instanceof Leg) { Leg legTemplate = ((Leg)planTemplate.getPlanElements().get(actLegIndex)); Leg r = ((Leg) pe); r.setTravelTime( legTemplate.getDepartureTime() + legTemplate.getTravelTime() - r.getDepartureTime() ); ((Leg) pe).setDepartureTime(legTemplate.getDepartureTime()); ((Leg) pe).setMode(legTemplate.getMode()); ((Leg) pe).setRoute(legTemplate.getRoute()); ((Leg) pe).setTravelTime(legTemplate.getTravelTime()); } else throw new RuntimeException("Unexpected PlanElement type was found: " + pe.getClass().toString() + ". Aborting!"); actLegIndex++; } }
public static void copyFromTo(Activity act, Activity newAct) { Coord coord = act.getCoord() == null ? null : new Coord(act.getCoord().getX(), act.getCoord().getY()); // (we don't want to copy the coord ref, but rather the contents!) newAct.setCoord(coord); newAct.setType( act.getType() ); newAct.setLinkId(act.getLinkId()); newAct.setStartTime(act.getStartTime()); newAct.setEndTime(act.getEndTime()); newAct.setMaximumDuration(act.getMaximumDuration()); newAct.setFacilityId(act.getFacilityId()); AttributesUtils.copyAttributesFromTo( act , newAct ); }
activityH1.setStartTime(0.0); activityH1.setEndTime(8.0*3600); activityW1.setStartTime(8.0*3600); activityW1.setEndTime(16.0*3600); activityH2.setStartTime(16.0*3600); activityH2.setEndTime(24.0*3600);
@Test public void testActivitiesScoredDifferently() { final Scenario sc = createTestScenario(); final CharyparNagelScoringFunctionFactory functionFactory = new CharyparNagelScoringFunctionFactory( sc ); final ScoringFunction function1 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 1 ) ) ); final ScoringFunction function2 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 2 ) ) ); final Activity act = PopulationUtils.createActivityFromCoordAndLinkId("chill", null, null); act.setStartTime( 8 * 3600d ); act.setEndTime( 18 * 3600d ); function1.handleActivity( act ); function1.finish(); function2.handleActivity( act ); function2.finish(); Assert.assertFalse( "same score for legs of agents in different subpopulations", Math.abs( function1.getScore() - function2.getScore() ) < 1E-9 ); }
@Override protected void setUp() throws Exception { super.setUp(); final Config config = ConfigUtils.createConfig(); final Scenario scenario = ScenarioUtils.createScenario( config ); this.facilities = scenario.getActivityFacilities() ; // create facilities, activities in it and open times final ActivityFacilitiesFactory facilitiesFactory = this.facilities.getFactory(); Coord defaultCoord = new Coord(0.0, 0.0); ActivityFacility testFacility = facilitiesFactory.createActivityFacility(Id.create(0, ActivityFacility.class), defaultCoord) ; this.facilities.addActivityFacility(testFacility); ActivityOption ao = facilitiesFactory.createActivityOption("shop") ; testFacility.addActivityOption(ao); ao.addOpeningTime(new OpeningTimeImpl(6.0 * 3600, 11.0 * 3600)); ao.addOpeningTime(new OpeningTimeImpl(13.0 * 3600, 19.0 * 3600)); // here, we don't test the scoring function itself, but just the method to retrieve opening times // we don't really need persons and plans, they're just used to initialize the ScoringFunction object final PopulationFactory pf = scenario.getPopulation().getFactory(); this.person = pf.createPerson(Id.create(1, Person.class)); Plan plan = pf.createPlan() ; this.person.addPlan(plan); Activity act = pf.createActivityFromCoord("shop", defaultCoord ) ; plan.addActivity(act); act.setFacilityId(testFacility.getId()); act.setStartTime(8.0 * 3600); act.setEndTime(16.0 * 3600); }
route2.setDistance(20000.0); Activity act1b = PopulationUtils.createAndAddActivityFromLinkId(plan1, "work", (Id<Link>)null);//, 7.0*3600+100, Time.UNDEFINED_TIME, Time.UNDEFINED_TIME, false); act1b.setStartTime(f.secondLegStartTime + f.secondLegTravelTime); ScoringFunction sf1 = getScoringFunctionInstance(f, person1); sf1.handleActivity(act1a);