@Override public Activity createActivityFromCoord(final String actType, final Coord coord) { Activity act = new ActivityImpl(actType) ; act.setCoord(coord); return act ; }
public static void setCoord(Activity activity, Coord coord) { if (activity instanceof Activity) { ((Activity) activity).setCoord(coord); } else if (activity instanceof LCActivity) { ((LCActivity) activity).setCoord(coord); } else throw new RuntimeException("Unexpected type of activity was found: " + activity.getClass().toString() + ". Aborting!"); }
public static Activity createAndAddActivityFromCoord( Plan plan, String type, Coord coord ) { Activity act = getFactory().createActivityFromCoord(type, coord) ; plan.addActivity(act); act.setCoord(coord); return act ; } public static Activity createAndAddActivityFromLinkId( Plan plan, String type, Id<Link> linkId ) {
@Override public void run(final GroupPlans plans) { final List<Facility> groupChoiceSet = choiceSet.getGroupChoiceSet( plans ); for ( Plan plan : plans.getAllIndividualPlans() ) { for ( Activity act : TripStructureUtils.getActivities( plan , choiceSet.filter ) ) { assert act.getType().equals( choiceSet.type ); final Facility choice = groupChoiceSet.get( random.nextInt( groupChoiceSet.size() ) ); ((Activity) act).setCoord( choice.getCoord() ); ((Activity) act).setLinkId( choice.getLinkId() ); if ( choice instanceof Identifiable ) { ( (Activity) act ).setFacilityId( ((Identifiable)choice).getId() ); } else { throw new RuntimeException( Facility.FACILITY_NO_LONGER_IDENTIFIABLE ) ; } } } }
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(); } }
protected boolean modifyLocation(Activity act, Coord startCoord, Coord endCoord, double radius, int trialNr) { ArrayList<ActivityFacility> choiceSet = this.computeChoiceSetCircle(startCoord, endCoord, radius, act.getType()); if (choiceSet.size()>1) { //final Facility facility=(Facility)choiceSet.toArray()[ // MatsimRandom.random.nextInt(choiceSet.size())]; final ActivityFacility facility = choiceSet.get(super.random.nextInt(choiceSet.size())); act.setFacilityId(facility.getId()); act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId()); act.setCoord(facility.getCoord()); return true; } // else ... return false; }
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; }
private void setNewLocationForAct(Activity act, int length) { ActivityFacilityImpl facility = this.facilitiesOfType.get(act.getType())[super.random.nextInt(length)]; act.setFacilityId(facility.getId()); act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId()); act.setCoord(facility.getCoord()); } }
protected final boolean modifyLocation(Activity act, Coord startCoord, Coord endCoord, double radius) { double midPointX = (startCoord.getX() + endCoord.getX()) / 2.0; double midPointY = (startCoord.getY() + endCoord.getY()) / 2.0; ArrayList<ActivityFacility> facilitySet = (ArrayList<ActivityFacility>) this.quadTreesOfType.get(this.defineFlexibleActivities.getConverter().convertType(act.getType())). getDisk(midPointX, midPointY, radius); ActivityFacility facility = null; if (facilitySet.size() > 1) { facility = facilitySet.get(super.random.nextInt(facilitySet.size())); } else { return false; } act.setFacilityId(facility.getId()); act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId()); act.setCoord(facility.getCoord()); return true; }
private void mutateLocations( final String type, final List<Activity> activitiesToMutate) { final Coord coordBarycenter = calcBarycenterCoord( activitiesToMutate ); final double angle = random.nextDouble() * Math.PI; final double distance = nextNormalDouble() * config.getStandardDeviation(); final ActivityFacility fac = getFacility( type, coordBarycenter, angle, distance ); for ( Activity act : activitiesToMutate ) { ((Activity) act).setFacilityId( fac.getId() ); ((Activity) act).setLinkId( fac.getLinkId() ); ((Activity) act).setCoord( fac.getCoord() ); } }
private static void changeLocation( final Collection<Subchain> subchains, final ActivityFacility facility) { for ( Subchain subchain : subchains ) { ((Activity) subchain.getToMove()).setFacilityId( facility.getId() ); ((Activity) subchain.getToMove()).setLinkId( facility.getLinkId() ); ((Activity) subchain.getToMove()).setCoord( facility.getCoord() ); } }
public static void enrichScenario(final Scenario scenario) { final Config config = scenario.getConfig(); final GroupReplanningConfigGroup weights = (GroupReplanningConfigGroup) config.getModule( GroupReplanningConfigGroup.GROUP_NAME ); if ( config.households().getInputFile()!=null && weights.getUseLimitedVehicles() ) { scenario.addScenarioElement( VehicleRessources.ELEMENT_NAME, new HouseholdBasedVehicleRessources( scenario.getHouseholds() ) ); } for (Person person : scenario.getPopulation().getPersons().values()) { for (Plan plan : person.getPlans()) { for (Activity act : TripStructureUtils.getActivities( plan , EmptyStageActivityTypes.INSTANCE )) { if (act.getCoord() != null) continue; if (act.getLinkId() == null) throw new NullPointerException(); act.setCoord( scenario.getNetwork().getLinks().get( act.getLinkId() ).getCoord() ); } } } }
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 ); }
((Activity) activityH1).setCoord(scenario.getNetwork().getLinks().get(activityH1.getLinkId()).getCoord()); ((Activity) activityW1).setCoord(scenario.getNetwork().getLinks().get(activityW1.getLinkId()).getCoord()); ((Activity) activityH2).setCoord(scenario.getNetwork().getLinks().get(activityH2.getLinkId()).getCoord());
((Activity) home1).setCoord(new Coord(x3, (double) 500)); home1.setEndTime(7.0 * 3600); work.setEndTime(17.0 * 3600); final double y1 = -8000; ((Activity) work).setCoord(new Coord((double) 5000, y1)); ((Activity) shop).setCoord(new Coord((double) 5000, y)); ((Activity) home2).setCoord(new Coord(x2, (double) 500)); home2.setEndTime(21 * 3600); ((Activity) home2).setCoord(new Coord(x1, (double) 500)); home2.setEndTime(22 * 3600); ((Activity) home2).setCoord(new Coord(x, (double) 500));