Пример #1
0
  private Population getTestPopulation() {
    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml");

    Link link1 = network.getLinks().get(Id.create(1, Link.class));
    Link link20 = network.getLinks().get(Id.create(20, Link.class));

    Population population = scenario.getPopulation();

    Person person;
    PlanImpl plan;
    LegImpl leg;
    NetworkRoute route;

    person = PopulationUtils.createPerson(Id.create("1", Person.class));
    plan = PersonUtils.createAndAddPlan(person, true);
    ActivityImpl a = plan.createAndAddActivity("h", link1.getId());
    a.setEndTime(7.0 * 3600);
    leg = plan.createAndAddLeg(TransportMode.car);
    route = new LinkNetworkRouteImpl(link1.getId(), link20.getId());
    route.setLinkIds(link1.getId(), NetworkUtils.getLinkIds("6 15"), link20.getId());
    leg.setRoute(route);
    plan.createAndAddActivity("w", link20.getId());
    population.addPerson(person);

    person = PopulationUtils.createPerson(Id.create("2", Person.class));
    plan = PersonUtils.createAndAddPlan(person, true);
    ActivityImpl a2 = plan.createAndAddActivity("h", link1.getId());
    a2.setEndTime(7.0 * 3600 + 5.0 * 60);
    leg = plan.createAndAddLeg(TransportMode.car);
    route = new LinkNetworkRouteImpl(link1.getId(), link20.getId());
    route.setLinkIds(link1.getId(), NetworkUtils.getLinkIds("6 15"), link20.getId());
    leg.setRoute(route);
    plan.createAndAddActivity("w", link20.getId());
    population.addPerson(person);

    person = PopulationUtils.createPerson(Id.create("3", Person.class));
    plan = PersonUtils.createAndAddPlan(person, true);
    ActivityImpl a3 = plan.createAndAddActivity("h", link1.getId());
    a3.setEndTime(7.0 * 3600 + 10.0 * 60);
    leg = plan.createAndAddLeg(TransportMode.car);
    route = new LinkNetworkRouteImpl(link1.getId(), link20.getId());
    route.setLinkIds(link1.getId(), NetworkUtils.getLinkIds("5 14"), link20.getId());
    leg.setRoute(route);
    plan.createAndAddActivity("w", link20.getId());
    population.addPerson(person);

    return population;
  }
Пример #2
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;
  }
Пример #3
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;
   }
 }
  private TransitRoute createRoute(
      Id<TransitRoute> routeID, TransitStopFacility startStop, TransitStopFacility endStop) {

    FreespeedTravelTimeAndDisutility tC = new FreespeedTravelTimeAndDisutility(-6.0, 0.0, 0.0);
    LeastCostPathCalculator routingAlgo = new Dijkstra(this.net, tC, tC);

    Node startNode = this.net.getLinks().get(startStop.getLinkId()).getToNode();
    Node endNode = this.net.getLinks().get(endStop.getLinkId()).getFromNode();

    int startTime = 0 * 3600;

    // get Route
    Path path = routingAlgo.calcLeastCostPath(startNode, endNode, startTime, null, null);
    NetworkRoute route = new LinkNetworkRouteImpl(startStop.getLinkId(), endStop.getLinkId());
    route.setLinkIds(
        startStop.getLinkId(), NetworkUtils.getLinkIds(path.links), endStop.getLinkId());

    // get stops at Route
    List<TransitRouteStop> stops = new LinkedList<TransitRouteStop>();

    // first stop
    TransitRouteStop routeStop =
        this.tS.getFactory().createTransitRouteStop(startStop, startTime, startTime);
    stops.add(routeStop);

    // additional stops
    for (Link link : path.links) {
      startTime += link.getLength() / link.getFreespeed();
      if (this.tS.getFacilities().get(link.getId()) == null) {
        continue;
      }
      routeStop =
          this.tS
              .getFactory()
              .createTransitRouteStop(
                  this.tS.getFacilities().get(link.getId()), startTime, startTime);
      stops.add(routeStop);
    }

    // last stop
    startTime +=
        this.net.getLinks().get(endStop.getLinkId()).getLength()
            / this.net.getLinks().get(endStop.getLinkId()).getFreespeed();
    routeStop = this.tS.getFactory().createTransitRouteStop(endStop, startTime, startTime);
    stops.add(routeStop);

    // register departure
    TransitRoute transitRoute =
        this.tS.getFactory().createTransitRoute(routeID, route, stops, "pt");

    return transitRoute;
  }