@Override public double getStartTime() { return act.getStartTime(); }
@Override public double getStartTime() { return this.delegate.getStartTime() ; }
@Override public void handleLastActivity(Activity act) { this.currentActivityStartTime = act.getStartTime(); this.handleOvernightActivity(act); this.firstActivity = null; }
@Override public double getStartTime() { return this.delegate.getStartTime(); } @Override
@Override public void handleLastActivity(Activity act) { this.currentActivityStartTime = act.getStartTime(); this.handleOvernightActivity(act); this.firstActivity = null; }
public final void handleActivity(Activity activity) { if (activity.getStartTime() != Time.UNDEFINED_TIME) { startActivity(activity.getStartTime(), activity); } if (activity.getEndTime() != Time.UNDEFINED_TIME) { endActivity(activity.getEndTime(), activity); } }
@Override public final void handleActivity(Activity activity) { if (activity.getStartTime() != Time.UNDEFINED_TIME) { startActivity(activity.getStartTime(), activity); } if (activity.getEndTime() != Time.UNDEFINED_TIME) { endActivity(activity.getEndTime(), activity); } }
@Override public void handleActivity(Activity act) { this.score += calcActScore(act.getStartTime(), act.getEndTime(), act); }
@Override public void handleActivity(Activity act) { this.score += calcActScore(act.getStartTime(), act.getEndTime(), act); }
@Override public void startAct(final Activity act, final BufferedWriter out) throws IOException { out.write("\t\t\t<act"); out.write(" type=\"" + act.getType() + "\""); if (act.getCoord() != null) { final Coord coord = coordinateTransformation.transform( act.getCoord() ); out.write(" x100=\"" + coord.getX() + "\""); out.write(" y100=\"" + coord.getY() + "\""); } if (act.getLinkId() != null) out.write(" link=\"" + act.getLinkId() + "\""); if (act.getStartTime() != Integer.MIN_VALUE) out.write(" start_time=\"" + Time.writeTime(act.getStartTime()) + "\""); if (!Time.isUndefinedTime(act.getMaximumDuration())) out.write(" dur=\"" + Time.writeTime(act.getMaximumDuration()) + "\""); if (act.getEndTime() != Integer.MIN_VALUE) out.write(" end_time=\"" + Time.writeTime(act.getEndTime()) + "\""); out.write(" />\n"); }
public ActivitySerializable(Activity act) { coord = new CoordSerializable(act.getCoord()); endTime = act.getEndTime(); facIdString = act.getFacilityId() == null ? null : act.getFacilityId().toString(); linkIdString = act.getLinkId() == null ? null : act.getLinkId().toString(); maximumDuration = act.getMaximumDuration(); startTime = act.getStartTime(); type = act.getType(); }
@Override public void handleActivity(Activity act) { if(act instanceof FreightActivity) { double actStartTime = act.getStartTime(); // log.info(act + " start: " + Time.writeTime(actStartTime)); TimeWindow tw = ((FreightActivity) act).getTimeWindow(); if(actStartTime > tw.getEnd()){ double penalty_score = (-1)*(actStartTime - tw.getEnd())*missedTimeWindowPenalty; assert penalty_score <= 0.0 : "penalty score must be negative"; // log.info("penalty " + penalty_score); score += penalty_score; } double actTimeCosts = (act.getEndTime()-actStartTime)*timeParameter; // log.info("actCosts " + actTimeCosts); assert actTimeCosts >= 0.0 : "actTimeCosts must be positive"; score += actTimeCosts*(-1); } }
private SimpleFeature getActFeature(final String id, final Activity act) { String type = act.getType(); String linkId = act.getLinkId().toString(); Double startTime = act.getStartTime(); Double endTime = act.getEndTime(); double rx = MatsimRandom.getRandom().nextDouble() * this.actBlurFactor; double ry = MatsimRandom.getRandom().nextDouble() * this.actBlurFactor; Coord cc = this.network.getLinks().get(act.getLinkId()).getCoord(); Coord c = new Coord(cc.getX() + rx, cc.getY() + ry); try { return this.actBuilder.buildFeature(null, new Object [] {MGC.coord2Point(c), id, type, linkId, startTime, endTime}); } catch (IllegalArgumentException e) { e.printStackTrace(); } return null; }
private static double calcTripDuration(List<PlanElement> planElements) { double duration = 0.0; for (PlanElement pe : planElements) { if (pe instanceof Activity) { Activity act = (Activity) pe; double endTime = act.getEndTime(); double startTime = act.getStartTime(); if (startTime != Time.UNDEFINED_TIME && endTime != Time.UNDEFINED_TIME) { duration += (endTime - startTime); } } else if (pe instanceof Leg) { Leg leg = (Leg) pe; duration += leg.getTravelTime(); } } return duration; }
@Override public final void handleActivity(Activity activity) { double startTime = activity.getStartTime(); double endTime = activity.getEndTime(); if (Time.isUndefinedTime(startTime) && !Time.isUndefinedTime(endTime)) { for (ActivityScoring activityScoringFunction : this.activityScoringFunctions) { activityScoringFunction.handleFirstActivity(activity); } } else if (!Time.isUndefinedTime(startTime) && !Time.isUndefinedTime(endTime)) { for (ActivityScoring activityScoringFunction : this.activityScoringFunctions) { activityScoringFunction.handleActivity(activity); } } else if (!Time.isUndefinedTime(startTime) && Time.isUndefinedTime(endTime)) { for (ActivityScoring activityScoringFunction : this.activityScoringFunctions) { activityScoringFunction.handleLastActivity(activity); } } else { throw new RuntimeException("Trying to score an activity without start or end time. Should not happen."); } }
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 ); }
@Test public void testCreateNightActivity() { EventsToActivities testee = new EventsToActivities(); MockActivityHandler ah = new MockActivityHandler(); testee.addActivityHandler(ah); testee.reset(0); testee.handleEvent(new ActivityEndEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "home")); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(Time.UNDEFINED_TIME, ah.handledActivity.getActivity().getStartTime(), 1e-8); Assert.assertEquals(10.0, ah.handledActivity.getActivity().getEndTime(), 1e-8); ah.reset(); testee.handleEvent(new ActivityStartEvent(90.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "home")); testee.finish(); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(Time.UNDEFINED_TIME, ah.handledActivity.getActivity().getEndTime(), 1e-8); Assert.assertEquals(90.0, ah.handledActivity.getActivity().getStartTime(), 1e-8); }
@Test public void testDontCreateNightActivityIfNoneIsBeingPerformedWhenSimulationEnds() { EventsToActivities testee = new EventsToActivities(); MockActivityHandler ah = new MockActivityHandler(); testee.addActivityHandler(ah); testee.reset(0); testee.handleEvent(new ActivityEndEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("f1", ActivityFacility.class), "home")); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(Time.UNDEFINED_TIME, ah.handledActivity.getActivity().getStartTime(), 1e-8); Assert.assertEquals(10.0, ah.handledActivity.getActivity().getEndTime(), 1e-8); ah.reset(); testee.finish(); Assert.assertNull(ah.handledActivity); }
@Test public void testCreatesActivty() { EventsToActivities testee = new EventsToActivities(); MockActivityHandler ah = new MockActivityHandler(); testee.addActivityHandler(ah); testee.reset(0); testee.handleEvent(new ActivityStartEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "work")); testee.handleEvent(new ActivityEndEvent(30.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "work")); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(10.0, ah.handledActivity.getActivity().getStartTime(), 1e-8); Assert.assertEquals(30.0, ah.handledActivity.getActivity().getEndTime(), 1e-8); }