コード例 #1
0
 private void writeAct(final Activity act, final BufferedWriter out) throws IOException {
   out.write("\t\t\t<act type=\"");
   out.write(act.getType());
   out.write("\"");
   if (act.getLinkId() != null) {
     out.write(" link=\"");
     out.write(act.getLinkId().toString());
     out.write("\"");
   }
   if (act.getFacilityId() != null) {
     out.write(" facility=\"");
     out.write(act.getFacilityId().toString());
     out.write("\"");
   }
   if (act.getCoord() != null) {
     final Coord coord = coordinateTransformation.transform(act.getCoord());
     out.write(" x=\"");
     out.write(Double.toString(coord.getX()));
     out.write("\" y=\"");
     out.write(Double.toString(coord.getY()));
     out.write("\"");
   }
   if (act.getStartTime() != Time.UNDEFINED_TIME) {
     out.write(" start_time=\"");
     out.write(Time.writeTime(act.getStartTime()));
     out.write("\"");
   }
   if (act != null) {
     Activity a = act;
     if (a.getMaximumDuration() != Time.UNDEFINED_TIME) {
       out.write(" max_dur=\"");
       out.write(Time.writeTime(a.getMaximumDuration()));
       out.write("\"");
     }
   }
   if (act.getEndTime() != Time.UNDEFINED_TIME) {
     out.write(" end_time=\"");
     out.write(Time.writeTime(act.getEndTime()));
     out.write("\"");
   }
   out.write(" />\n");
 }
コード例 #2
0
  /**
   * Contains rules about when to leave an Activity, considering the current time and the properties
   * of the Activity. Specifically, determines how maximum duration and specific end time are played
   * against each other.
   *
   * @param act The Activity
   * @param now The current simulation time
   * @param activityDurationInterpretation The name of one of several rules of how to interpret
   *     Activity fields.
   * @return The departure time
   */
  static double calculateDepartureTime(
      Activity act,
      double now,
      PlansConfigGroup.ActivityDurationInterpretation activityDurationInterpretation) {
    if (act.getMaximumDuration() == Time.UNDEFINED_TIME
        && (act.getEndTime() == Time.UNDEFINED_TIME)) {
      // yyyy does this make sense?  below there is at least one execution path where this should
      // lead to an exception.  kai, oct'10
      return Double.POSITIVE_INFINITY;
    } else {
      double departure = 0;
      if (activityDurationInterpretation.equals(
          PlansConfigGroup.ActivityDurationInterpretation.minOfDurationAndEndTime)) {
        // person stays at the activity either until its duration is over or until its end time,
        // whatever comes first
        if (act.getMaximumDuration() == Time.UNDEFINED_TIME) {
          departure = act.getEndTime();
        } else if (act.getEndTime() == Time.UNDEFINED_TIME) {
          departure = now + act.getMaximumDuration();
        } else {
          departure = Math.min(act.getEndTime(), now + act.getMaximumDuration());
        }
      } else if (activityDurationInterpretation.equals(
          PlansConfigGroup.ActivityDurationInterpretation.endTimeOnly)) {
        if (act.getEndTime() != Time.UNDEFINED_TIME) {
          departure = act.getEndTime();
        } else {
          throw new IllegalStateException(
              "activity end time not set and using something else not allowed.");
        }
      } else if (activityDurationInterpretation.equals(
          PlansConfigGroup.ActivityDurationInterpretation.tryEndTimeThenDuration)) {
        // In fact, as of now I think that _this_ should be the default behavior.  kai, aug'10
        if (act.getEndTime() != Time.UNDEFINED_TIME) {
          departure = act.getEndTime();
        } else if (act.getMaximumDuration() != Time.UNDEFINED_TIME) {
          departure = now + act.getMaximumDuration();
        } else {
          throw new IllegalStateException(
              "neither activity end time nor activity duration defined; don't know what to do.");
        }
      } else {
        throw new IllegalStateException("should not happen");
      }

      if (departure < now) {
        // we cannot depart before we arrived, thus change the time so the time stamp in events will
        // be right
        //			[[how can events not use the simulation time?  kai, aug'10]]
        departure = now;
        // actually, we will depart in (now+1) because we already missed the departing in this time
        // step
      }
      return departure;
    }
  }