org.matsim.api.core.v01.population.Activity类的使用及代码示例

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

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

Activity介绍

[英]Specifies the kind of activity an agent performs during its day.
[中]指定代理在一天中执行的活动类型。

代码示例

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

public BasicFacility(
    final Activity act) {
  this.coord = act.getCoord();
  this.id = act.getFacilityId();
  this.link = act.getLinkId();
}

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

private static double updateTime(
    final double currTime,
    final Activity act) {
  double e = act.getEndTime();
  double d = act.getMaximumDuration();
  return e != Time.UNDEFINED_TIME ? e :
    currTime + ( d != Time.UNDEFINED_TIME ? d : 0 );
}

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

private Id<? extends BasicLocation> getLocationId(Activity activity) {
  return activity.getFacilityId()!=null ?
    activity.getFacilityId() :
    activity.getLinkId();
}

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

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

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

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

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

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

private void fillEvents(
    final Plan plan,
    final Queue<LocationEvent> events) {
  final Id personId = plan.getPerson().getId();
  double lastEnd = 0;
  int ind = 0;
  for ( Activity act : TripStructureUtils.getActivities( plan , stages ) ) {
    final Id loc = act.getFacilityId();
    final LocationEvent event =
      new LocationEvent(
          ind++,
          personId,
          act.getType(),
          loc,
          lastEnd );
    // correct times if inconsistent
    lastEnd = Math.max(
      lastEnd,
      act.getEndTime() != Time.UNDEFINED_TIME ?
        act.getEndTime() :
        lastEnd + act.getMaximumDuration() );
    if ( log.isTraceEnabled() ) {
      log.trace( "add event "+event+" to queue" );
    }
    events.add( event );
  }
}

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

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

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

private boolean judgeByBeeline(final Activity fromAct, final Activity toAct) {
  if (this.aoiCenter == null) {
    // we cannot use the bee-line decision if we don't know the alternative aoi-center
    return false;
  }
  Coord fromCoord = fromAct.getCoord();
  Coord toCoord = toAct.getCoord();
  if (fromCoord == null) {
    fromCoord = this.network.getLinks().get(fromAct.getLinkId()).getCoord();
  }
  if (toCoord == null) {
    toCoord = this.network.getLinks().get(toAct.getLinkId()).getCoord();
  }
  return (CoordUtils.distancePointLinesegment(fromCoord, toCoord, this.aoiCenter) <= this.aoiRadius);
}

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

@Override
public Coord getCoord() {
  return this.delegate.getCoord() ;
}

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

@Override
public String getType() {
  return this.delegate.getType();
}
@Override

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

private void initializeActivity(Activity act, double now) {
  this.setState(MobsimAgent.State.ACTIVITY) ;
  this.getEvents().processEvent( new ActivityStartEvent(now, this.getId(), this.getCurrentLinkId(), act.getFacilityId(), act.getType()));
  calculateAndSetDepartureTime(act);
  getModifiablePlan(); // this is necessary to make the plan modifiable, so that setting the start time (next line) is actually feasible. kai/mz, oct'16
  ((Activity) getCurrentPlanElement()).setStartTime(now);
}

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

private static double updateNow(
    final double now,
    final PlanElement pe) {
  if (pe instanceof Activity) {
    Activity act = (Activity) pe;
    double endTime = act.getEndTime();
    double startTime = act.getStartTime();
    double dur = (act instanceof Activity ? ((Activity) act).getMaximumDuration() : Time.UNDEFINED_TIME);
    if (endTime != Time.UNDEFINED_TIME) {
      // use fromAct.endTime as time for routing
      return endTime;
    }
    else if ((startTime != Time.UNDEFINED_TIME) && (dur != Time.UNDEFINED_TIME)) {
      // use fromAct.startTime + fromAct.duration as time for routing
      return startTime + dur;
    }
    else if (dur != Time.UNDEFINED_TIME) {
      // use last used time + fromAct.duration as time for routing
      return now + dur;
    }
    else {
      throw new RuntimeException("activity has neither end-time nor duration." + act);
    }
  }
  double tt = ((Leg) pe).getTravelTime();
  return now + (tt != Time.UNDEFINED_TIME ? tt : 0);
}

代码示例来源: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());
}

相关文章