Exemplo n.º 1
0
  private void startAct(final Attributes atts) {
    ActivityImpl act = null;
    if (atts.getValue("link") != null) {
      final Id<Link> linkId = Id.create(atts.getValue("link"), Link.class);
      act = this.currplan.createAndAddActivity(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 = this.currplan.createAndAddActivity(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;
  }
Exemplo n.º 2
0
 private void startAct(final Attributes atts) {
   Coord coord = null;
   if (atts.getValue("link") != null) {
     Id<Link> linkId = Id.create(atts.getValue("link"), Link.class);
     this.curract = this.currplan.createAndAddActivity(atts.getValue(ATTR_TYPE), linkId);
     if ((atts.getValue("x") != null) && (atts.getValue("y") != null)) {
       coord =
           new Coord(
               Double.parseDouble(atts.getValue("x")), Double.parseDouble(atts.getValue("y")));
       this.curract.setCoord(coord);
     }
   } else if ((atts.getValue("x") != null) && (atts.getValue("y") != null)) {
     coord =
         new Coord(Double.parseDouble(atts.getValue("x")), Double.parseDouble(atts.getValue("y")));
     this.curract = this.currplan.createAndAddActivity(atts.getValue(ATTR_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("start_time")));
   this.curract.setMaximumDuration(Time.parseTime(atts.getValue("dur")));
   this.curract.setEndTime(Time.parseTime(atts.getValue("end_time")));
   String fId = atts.getValue("facility");
   if (fId != null) {
     this.curract.setFacilityId(Id.create(fId, ActivityFacility.class));
   }
   if (this.routeDescription != null) {
     Id<Link> startLinkId = null;
     if (this.prevAct.getLinkId() != null) {
       startLinkId = this.prevAct.getLinkId();
     }
     Id<Link> endLinkId = null;
     if (this.curract.getLinkId() != null) {
       endLinkId = this.curract.getLinkId();
     }
     this.currRoute.setStartLinkId(startLinkId);
     this.currRoute.setEndLinkId(endLinkId);
     if (this.currRoute instanceof NetworkRoute) {
       ((NetworkRoute) this.currRoute)
           .setLinkIds(
               startLinkId,
               NetworkUtils.getLinkIds(
                   RouteUtils.getLinksFromNodes(
                       NetworkUtils.getNodes(this.network, this.routeDescription))),
               endLinkId);
     } else {
       this.currRoute.setRouteDescription(this.routeDescription.trim());
     }
     this.routeDescription = null;
     this.currRoute = null;
   }
 }