@Override public final PlanElement getCurrentPlanElement() { return this.plan.getPlanElements().get(this.currentPlanElementIndex); } @Override
@Override public void addActivity(Activity act) { this.delegate.addActivity(act); }
@Override public void addLeg(Leg leg) { this.delegate.addLeg(leg); }
/** loads a copy of an existing plan, but keeps the person reference * * @param in a plan who's data will be loaded into this plan * @param out **/ public static void copyFromTo(final Plan in, Plan out) { out.getPlanElements().clear(); out.setScore(in.getScore()); out.setType(in.getType()); for (PlanElement pe : in.getPlanElements()) { if (pe instanceof Activity) { out.getPlanElements().add(createActivity((Activity) pe)); } else if (pe instanceof Leg) { out.getPlanElements().add( createLeg( (Leg) pe ) ) ; } else { throw new IllegalArgumentException("unrecognized plan element type discovered"); } } AttributesUtils.copyAttributesFromTo(in, out ); }
private static void startPlan(final Plan plan, final BufferedWriter out) throws IOException { out.write("\t\t<plan"); if (plan.getScore() != null) { out.write(" score=\""); out.write(plan.getScore().toString()); out.write("\""); } if (PersonUtils.isSelected(plan)) out.write(" selected=\"yes\""); else out.write(" selected=\"no\""); if ((plan.getType() != null)) { out.write(" type=\""); out.write(plan.getType()); out.write("\""); } out.write(">\n"); }
public void addTrip(NetworkRoute networkRoute, String transportMode) { Activity lastActivity; if (!plan.getPlanElements().isEmpty()) { lastActivity = (Activity) plan.getPlanElements().get(plan.getPlanElements().size()-1); assert lastActivity.getLinkId().equals(networkRoute.getStartLinkId()); } else { lastActivity = PopulationUtils.createActivityFromLinkId(activityType, networkRoute.getStartLinkId()); plan.addActivity(lastActivity); } Leg leg = PopulationUtils.createLeg(transportMode); leg.setRoute(networkRoute); plan.addLeg(leg); Activity activity = PopulationUtils.createActivityFromLinkId(activityType, networkRoute.getEndLinkId()); plan.addActivity(activity); }
@Override public Plan createNewPlanInstance() { final PopulationFactory fact = createPopulationFactory(); final Id<Link> id1 = Id.create( 1, Link.class ); final Id<Link> id3 = Id.create( 3, Link.class ); final Plan plan = fact.createPlan(); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); plan.addLeg( fact.createLeg( TransportMode.walk ) ); plan.addActivity( fact.createActivityFromLinkId( "w" , id3 ) ); plan.addLeg( fact.createLeg( TransportMode.walk ) ); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); return plan; } };
public PlanSerializable(Plan plan) { planElements = new ArrayList<>(); for (PlanElement planElement : plan.getPlanElements()) if (planElement instanceof Activity) planElements.add(new ActivitySerializable((Activity) planElement)); else planElements.add(new LegSerializable((Leg) planElement)); personId = plan.getPerson().getId().toString(); score = plan.getScore(); // score = 0.0; type = plan.getType(); if (plan instanceof PlanGenome) { PlanGenome planGenome = (PlanGenome) plan; genome = planGenome.getGenome(); pSimScore = planGenome.getpSimScore(); scoreComponents = planGenome.getScoreComponents(); } }
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 void testPlanWithoutLegs() { Plan plan = PopulationUtils.createPlan(); Coord dummyCoord = new Coord((double) 0, (double) 0); plan.addActivity(PopulationUtils.createActivityFromCoord("h", dummyCoord)); new TransitActsRemover().run(plan); assertEquals(1, plan.getPlanElements().size()); // this mostly checks that there is no exception }
@Override protected double calcStat(final Plan plan) { final Double score = plan.getScore(); return score == null ? Double.NaN : score; }
@Override public void testZeroScore() { this.network = createNetwork(); PlanSelector<Plan,Person> selector = getPlanSelector(); Link l1 = network.getLinks().get(Id.create("1", Link.class)); Link l6 = network.getLinks().get(Id.create("6", Link.class)); Link l7 = network.getLinks().get(Id.create("7", Link.class)); Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(person); Activity a = PopulationUtils.createActivityFromLinkId("h", l6.getId()); Activity b = PopulationUtils.createActivityFromLinkId("w", l7.getId()); Leg leg = PopulationUtils.createLeg(TransportMode.car); leg.setDepartureTime(0.0); leg.setTravelTime(10.0); leg.setTravelTime( 10.0 - leg.getDepartureTime() ); NetworkRoute r = RouteUtils.createLinkNetworkRouteImpl(l6.getId(), l7.getId()); ArrayList<Id<Link>> srcRoute = new ArrayList<Id<Link>>(); srcRoute.add(l1.getId()); r.setLinkIds(l6.getId(), srcRoute, l7.getId()); r.setDistance(RouteUtils.calcDistanceExcludingStartEndLink(r, network)); leg.setRoute(r); p1.addActivity(a); p1.addLeg(leg); p1.addActivity(b); p1.setScore(0.0); person.addPlan(p1); assertNotNull(selector.selectPlan(person)); }
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++; } }
@Test public void testPlanAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); final Leg leg = population.getFactory().createLeg( "SUV" ); plan.addActivity( population.getFactory().createActivityFromLinkId( "speech" , Id.createLinkId( 1 ))); plan.addLeg( leg ); plan.addActivity( population.getFactory().createActivityFromLinkId( "tweet" , Id.createLinkId( 2 ))); plan.getAttributes().putAttribute( "beauty" , 0.000001d ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Plan readPlan = readPerson.getSelectedPlan() ; Assert.assertEquals( plan.getAttributes().getAttribute( "beauty" ) , readPlan.getAttributes().getAttribute( "beauty" ) ); }
private void startPlan(final Plan plan, final BufferedWriter out) throws IOException { out.write("\t\t<plan"); if (plan.getScore() != null) { out.write(" score=\""); out.write(plan.getScore().toString()); out.write("\""); } if (PersonUtils.isSelected(plan)) out.write(" selected=\"yes\""); else out.write(" selected=\"no\""); if ((plan.getType() != null)) { out.write(" type=\""); out.write(plan.getType()); out.write("\""); } out.write(">\n"); this.attributesWriter.writeAttributes( "\t\t\t\t" , out , plan.getAttributes() ); }
@Override public final void finishIteration() { // I separated this from "writeExperiencedPlans" so that it can be called separately even when nothing is written. Can't say // if the design might be better served by an iteration ends listener. kai, feb'17 for (Map.Entry<Id<Person>, Plan> entry : this.agentRecords.entrySet()) { Plan plan = entry.getValue(); if (scoringFunctionsForPopulation != null) { plan.setScore(scoringFunctionsForPopulation.getScoringFunctionForAgent(entry.getKey()).getScore()); if (plan.getScore().isNaN()) { log.warn("score is NaN; plan:" + plan.toString()); } } } }
@Override public void setScore(Double score) { this.delegate.setScore(score); }
private void startPlan(final Attributes atts) { String sel = atts.getValue("selected"); boolean selected; if (sel.equals("yes")) { selected = true; } else if (sel.equals("no")) { selected = false; } else { throw new NumberFormatException("Attribute 'selected' of Element 'Plan' is neither 'yes' nor 'no'."); } this.routeDescription = null; this.currplan = PersonUtils.createAndAddPlan(this.currperson, selected); String scoreString = atts.getValue("score"); if (scoreString != null) { double score = Double.parseDouble(scoreString); this.currplan.setScore(score); } String type = atts.getValue(ATTR_TYPE); this.currplan.setType(type); }