本文整理了Java中org.matsim.api.core.v01.population.Activity.setFacilityId()
方法的一些代码示例,展示了Activity.setFacilityId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.setFacilityId()
方法的具体详情如下:
包路径:org.matsim.api.core.v01.population.Activity
类名称:Activity
方法名:setFacilityId
暂无
代码示例来源:origin: matsim-org/matsim
public static void setFacilityId(Activity activity, Id<ActivityFacility> facilityId) {
if (activity instanceof Activity) {
((Activity) activity).setFacilityId(facilityId);
} else if (activity instanceof LCActivity) {
((LCActivity) activity).setFacilityId(facilityId);
} else throw new RuntimeException("Unexpected type of activity was found: " + activity.getClass().toString() + ". Aborting!");
}
代码示例来源:origin: matsim-org/matsim
@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 ) ;
}
}
}
}
代码示例来源:origin: matsim-org/matsim
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();
}
}
代码示例来源:origin: matsim-org/matsim
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();
}
}
代码示例来源:origin: matsim-org/matsim
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;
}
代码示例来源:origin: matsim-org/matsim
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());
}
}
代码示例来源:origin: matsim-org/matsim
@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);
}
代码示例来源:origin: matsim-org/matsim
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;
}
}
代码示例来源:origin: matsim-org/matsim
@Override
public void handleEvent(ActivityEndEvent event) {
Activity activity = activities.get(event.getPersonId());
if (activity == null) {
Activity firstActivity = PopulationUtils.createActivityFromLinkId(event.getActType(), event.getLinkId());
firstActivity.setFacilityId(event.getFacilityId());
activity = firstActivity;
}
activity.setEndTime(event.getTime());
for (ActivityHandler activityHandler : activityHandlers) {
activityHandler.handleActivity(new PersonExperiencedActivity(event.getPersonId(), activity));
}
activities.remove(event.getPersonId());
}
代码示例来源:origin: matsim-org/matsim
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;
}
}
代码示例来源:origin: matsim-org/matsim
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;
}
代码示例来源:origin: matsim-org/matsim
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() );
}
}
代码示例来源:origin: matsim-org/matsim
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() );
}
}
代码示例来源:origin: matsim-org/matsim
private static Activity createActivityFromLocationId(
final boolean anchorAtFacilities,
final PopulationFactory fact,
final String type,
final Id<?> loc) {
final Id<Link> linkLoc = anchorAtFacilities ? Id.create( "nowhere", Link.class ) : Id.create(loc, Link.class);
final Activity act = fact.createActivityFromLinkId( type , linkLoc );
if (anchorAtFacilities) {
final Id<ActivityFacility> facLoc = Id.create(loc, ActivityFacility.class) ;
((Activity) act).setFacilityId( facLoc );
}
return act;
}
代码示例来源:origin: matsim-org/matsim
public void handleEvent(ActivityEndEvent event) {
if (currentActivity == null) {
Activity firstActivity = PopulationUtils.createActivityFromLinkId(event.getActType(), event.getLinkId());
firstActivity.setFacilityId(event.getFacilityId());
currentActivity = firstActivity;
}
currentActivity.setEndTime(event.getTime());
scoringFunction.handleActivity(currentActivity);
activityFinished(event.getActType(), event.getTime());
}
代码示例来源:origin: matsim-org/matsim
static Plan createPlanFromFacilities(ActivityFacilitiesImpl layer, Person person, String mode, String facString) {
Plan plan = PopulationUtils.createPlan(person);
String[] locationIdSequence = facString.split(" ");
for (int aa=0; aa < locationIdSequence.length; aa++) {
ActivityFacility location = layer.getFacilities().get(Id.create(locationIdSequence[aa], ActivityFacility.class));
Activity act;
act = PopulationUtils.createAndAddActivity(plan, "actAtFacility" + locationIdSequence[aa]);
act.setFacilityId(location.getId());
act.setEndTime(10*3600);
if (aa != (locationIdSequence.length - 1)) {
PopulationUtils.createAndAddLeg( plan, mode );
}
}
return plan;
}
代码示例来源:origin: matsim-org/matsim
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++;
}
}
代码示例来源:origin: matsim-org/matsim
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++;
}
}
代码示例来源:origin: matsim-org/matsim
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 );
}
代码示例来源:origin: matsim-org/matsim
@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);
}
内容来源于网络,如有侵权,请联系作者删除!