org.matsim.api.core.v01.population.Activity.setEndTime()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中org.matsim.api.core.v01.population.Activity.setEndTime()方法的一些代码示例,展示了Activity.setEndTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.setEndTime()方法的具体详情如下:
包路径:org.matsim.api.core.v01.population.Activity
类名称:Activity
方法名:setEndTime

Activity.setEndTime介绍

暂无

代码示例

代码示例来源:origin: matsim-org/matsim

@Override
public void setEndTime(double seconds) {
  act.setEndTime(seconds);
}

代码示例来源:origin: matsim-org/matsim

public Activity createFinalActivity(String type, Id<Link> newLinkId) {
    Activity newAct = this.pf.createActivityFromLinkId(type, newLinkId);;
    newAct.setEndTime( Double.POSITIVE_INFINITY ) ;
    return newAct ;
  }
//    public Activity createAgentThatKeepsMatsimAlive( String type, Id<Link> newLinkId) {

代码示例来源:origin: matsim-org/matsim

@Override
public void setEndTime(double seconds) {
  this.delegate.setEndTime(seconds);
}
@Override

代码示例来源:origin: matsim-org/matsim

public final void rescheduleActivityEndtime( MobsimAgent agent, int index, double newEndTime ) {
  Activity activity = (Activity) WithinDayAgentUtils.getModifiablePlan(agent).getPlanElements().get(index) ;
  activity.setEndTime(newEndTime);
  WithinDayAgentUtils.resetCaches(agent);
  WithinDayAgentUtils.rescheduleActivityEnd(agent, mobsim);
}
public final Activity replaceActivity(MobsimAgent agent, int index, Activity newAct, String upstreamMode, String downstreamMode ) {

代码示例来源:origin: matsim-org/matsim

public void modifyPopulation(Population population) {
  // modify population: a plan was needed, which contained some properties to be compared with C++
  Person p = population.getPersons().get(Id.create("1", Person.class));
  Plan plan = p.getSelectedPlan();
  List<? extends PlanElement> actsLegs = plan.getPlanElements();
  ((Activity)actsLegs.get(0)).setEndTime(360);
  ((Activity)actsLegs.get(2)).setEndTime(900); // this requires immediate departure after arrival
  ((Activity)actsLegs.get(4)).setEndTime(2000);
}

代码示例来源:origin: matsim-org/matsim

protected Activity createActivity(StayTask task) {
  Activity act = populFactory.createActivityFromLinkId("s", task.getLink().getId());
  act.setStartTime(task.getBeginTime());
  act.setEndTime(task.getEndTime());
  return act;
}

代码示例来源: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

static Plan createPlanFromLinks(Network layer, Person person, String mode, String linkString) {
  Plan plan = PopulationUtils.createPlan(person);
  String[] locationIdSequence = linkString.split(" ");
  for (int aa=0; aa < locationIdSequence.length; aa++) {
    Link location = layer.getLinks().get(Id.create(locationIdSequence[aa], Link.class));
    Activity act;
    act = PopulationUtils.createAndAddActivityFromLinkId(plan, "actOnLink" + locationIdSequence[aa], (Id<Link>) location.getId());
    act.setEndTime(10*3600);
    if (aa != (locationIdSequence.length - 1)) {
      PopulationUtils.createAndAddLeg( plan, mode );
    }
  }
  return plan;
}

代码示例来源: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

@Override
public void run(final Plan plan) {
  for ( Activity act : TripStructureUtils.getActivities( plan , blackList ) ) {
    // this is deliberately simplistic.  Cleanup up of the time information should be done somewhere else.
    if ( !Time.isUndefinedTime( act.getEndTime() ) ) {
      act.setEndTime(mutateTime(act.getEndTime()));
    }
    if ( affectingDuration ) {
      if ( !Time.isUndefinedTime( act.getMaximumDuration() ) ) {
        act.setMaximumDuration(mutateTime(act.getMaximumDuration()));
      }
    }
  }
  // the legs are not doing anything. kai, jun'12
}

代码示例来源: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

private Person createPersonWithPlan(PopulationFactory factory, String id, double homeX, double homeY, double workX, double workY) {
  Person person = factory.createPerson(Id.create(id, Person.class));
  Plan plan = factory.createPlan();
  person.addPlan(plan);
  Activity home1 = factory.createActivityFromCoord("home", new Coord(homeX, homeY));
  home1.setEndTime(8*3600);
  Activity work = factory.createActivityFromCoord("work", new Coord(workX, workY));
  work.setEndTime(17*3600);
  Activity home2 = factory.createActivityFromCoord("home", new Coord(homeX, homeY));
  
  plan.addActivity(home1);
  plan.addLeg(factory.createLeg("car"));
  plan.addActivity(work);
  plan.addLeg(factory.createLeg("car"));
  plan.addActivity(home2);
  
  return person;
}

代码示例来源:origin: matsim-org/matsim

@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 );
}

代码示例来源:origin: matsim-org/matsim

/**
 * Tests that no Exception occurs if an agent has no leg at all, but the only activity has an end time set.
 *
 * @author mrieser
 */
@Test
public void testAgentWithoutLegWithEndtime() {
  Fixture f = new Fixture(isUsingFastCapacityUpdate);
  Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class));
  Plan plan = PersonUtils.createAndAddPlan(person, true);
  Activity act = PopulationUtils.createAndAddActivityFromLinkId(plan, "home", f.link1.getId());
  act.setEndTime(6.0 * 3600);
  f.plans.addPerson(person);
  /* build events */
  EventsManager events = EventsUtils.createEventsManager();
  LinkEnterEventCollector collector = new LinkEnterEventCollector();
  events.addHandler(collector);
  /* run sim */
  QSim sim = createQSim(f, events);
  sim.run();
  /* finish */
  Assert.assertEquals("wrong number of link enter events.", 0, collector.events.size());
}

代码示例来源:origin: matsim-org/matsim

private void createPopulation() {
  Population pop = this.scenario.getPopulation();
  PopulationFactory f = pop.getFactory();
  Person p = f.createPerson(Id.create(1, Person.class));
  pop.addPerson(p);
  Plan plan = f.createPlan();
  p.addPlan(plan);
  Activity act = f.createActivityFromLinkId("home", Id.create(1, Link.class));
  act.setEndTime(2000.0);
  plan.addActivity(act);
  Leg leg = f.createLeg(TransportMode.car);
  plan.addLeg(leg);
  act = f.createActivityFromLinkId("home", Id.create(34, Link.class));
  plan.addActivity(act);
}

代码示例来源:origin: matsim-org/matsim

private void createPopulation(){
    for(int i=1;i<3;i++){
      Id<Person> id = Id.createPersonId(i);
      Person p = population.getFactory().createPerson(id);
      Plan plan = population.getFactory().createPlan();
      p.addPlan(plan);
      Activity a1 = population.getFactory().createActivityFromLinkId("h", link1.getId());
      a1.setEndTime(0*3600);
      Leg leg = population.getFactory().createLeg(TransportMode.car);
      plan.addActivity(a1);
      plan.addLeg(leg);
      LinkNetworkRouteFactory factory = new LinkNetworkRouteFactory();
      NetworkRoute route;
      List<Id<Link>> linkIds = new ArrayList<Id<Link>>();
      route= (NetworkRoute) factory.createRoute(link1.getId(), link3.getId());
      linkIds.add(link2.getId());
      route.setLinkIds(link1.getId(), linkIds, link3.getId());
      leg.setRoute(route);
      Activity a2 = population.getFactory().createActivityFromLinkId("w", link3.getId());
      plan.addActivity(a2);
      population.addPerson(p);
    }
  }
}

代码示例来源:origin: matsim-org/matsim

private Person createPerson(Scenario scenario, String id) {
  
  Person person = scenario.getPopulation().getFactory().createPerson(Id.create(id, Person.class));
  
  Activity from = scenario.getPopulation().getFactory().createActivityFromLinkId("home", Id.create("l0", Link.class));
  Leg leg = scenario.getPopulation().getFactory().createLeg(TransportMode.car);
  Activity to = scenario.getPopulation().getFactory().createActivityFromLinkId("home", Id.create("l2", Link.class));
  from.setEndTime(8*3600);
  leg.setDepartureTime(8*3600);
  
  RouteFactory routeFactory = new LinkNetworkRouteFactory();
  Id<Link> startLinkId = Id.create("l0", Link.class);
  Id<Link> endLinkId = Id.create("l2", Link.class);
  NetworkRoute route = (NetworkRoute) routeFactory.createRoute(startLinkId, endLinkId);
  List<Id<Link>> linkIds = new ArrayList<Id<Link>>();
  linkIds.add(Id.create("l1", Link.class));
  route.setLinkIds(startLinkId, linkIds, endLinkId);
  leg.setRoute(route);
  
  Plan plan = scenario.getPopulation().getFactory().createPlan();
  plan.addActivity(from);
  plan.addLeg(leg);
  plan.addActivity(to);
  
  person.addPlan(plan);
  
  return person;
}

相关文章