Exemplo n.º 1
0
  /** @param args */
  public static void main(String[] args) {

    Config config = ConfigUtils.createConfig();

    config.controler().setLastIteration(0);
    config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
    Collection<String> sf = new ArrayList<>();
    sf.add("otfvis");
    config.controler().setSnapshotFormat(sf);
    config.controler().setWriteSnapshotsInterval(1);

    config.qsim().setStartTime(0);
    config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime);
    config.qsim().setEndTime(10. * 3600.);
    config.qsim().setSimEndtimeInterpretation(EndtimeInterpretation.onlyUseEndtime);

    config.qsim().setNumberOfThreads(1);

    config.qsim().setSnapshotPeriod(1);

    OTFVisConfigGroup otfconf =
        ConfigUtils.addOrGetModule(config, OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class);
    otfconf.setColoringScheme(ColoringScheme.byId);

    Scenario scenario = ScenarioUtils.createScenario(config);

    Network net = scenario.getNetwork();
    NetworkFactory nf = net.getFactory();
    Node node1 = nf.createNode(Id.createNodeId(1), new Coord(0., 0.));
    net.addNode(node1);
    Node node2 = nf.createNode(Id.createNodeId(2), new Coord(LEN * 7.5, 0.));
    net.addNode(node2);
    Node node3 = nf.createNode(Id.createNodeId(3), new Coord(0., -LEN * 7.5));
    net.addNode(node3);
    Node node4 = nf.createNode(Id.createNodeId(4), new Coord(0., LEN * 7.5));
    net.addNode(node4);
    Link link = nf.createLink(Id.createLinkId("1-2"), node1, node2);
    link.setLength(LEN * 7.5);
    net.addLink(link);
    //		Link link2 = nf.createLink(Id.createLinkId("1-3"), node1, node3) ;
    //		link.setLength( LEN*7.5 );
    //		net.addLink( link2 ) ;

    Controler controler = new Controler(scenario);

    controler.addOverridingModule(
        new AbstractModule() {
          @Override
          public void install() {
            bind(QNetworkFactory.class).to(MyQNetworkFactory.class);
          }
        });

    controler.addOverridingModule(new OTFVisLiveModule());
    controler.addOverridingModule(new OTFVisFileWriterModule());

    controler.run();
  }
Exemplo n.º 2
0
  public static void main(String[] args) {

    // Dummy MATSim scenario including dummy network
    Config conf = ConfigUtils.createConfig();
    conf.global().setCoordinateSystem("EPSG:3395");
    Scenario sc = ScenarioUtils.createScenario(conf);
    //		Sim2DConfig conf2d = Sim2DConfigUtils.createConfig();
    //		Sim2DScenario sc2d = Sim2DScenarioUtils.createSim2dScenario(conf2d);
    //		sc.addScenarioElement(Sim2DScenario.ELEMENT_NAME,sc2d);
    Network net = sc.getNetwork();
    NetworkFactory fac = net.getFactory();
    Node n0 = fac.createNode(Id.create("0", Node.class), new Coord(minX, minY));
    Node n1 = fac.createNode(Id.create("1", Node.class), new Coord(minX, maxY));
    Node n2 = fac.createNode(Id.create("2", Node.class), new Coord(maxX, maxY));
    Node n3 = fac.createNode(Id.create("3", Node.class), new Coord(maxX, minY));
    net.addNode(n0);
    net.addNode(n1);
    net.addNode(n2);
    net.addNode(n3);

    // visualization stuff
    EventsManager em = new EventsManagerImpl();
    EventBasedVisDebuggerEngine vis = new EventBasedVisDebuggerEngine(sc);
    em.addHandler(vis);

    // routing algorithm - for now standard Dijkstra could be replaced by A*  in future
    Dijkstra d = new Dijkstra(env);

    // dummy data
    int number = 20;
    for (double time = 0; time <= 1000; time++) {
      List<XYVxVyEventImpl> events = createDummyData(MatsimRandom.getRandom().nextInt(21), time);

      List<TwoDObject> objs = new ArrayList<TwoDObject>();
      for (XYVxVyEventImpl e : events) {
        em.processEvent(e); // needed for visualization
        objs.add(e);
      }

      System.out.println("");
      LinearQuadTreeLD quad = new LinearQuadTreeLD(objs, env, em);

      // routing
      List<Quad> fromL = quad.query(new Envelope(0, 0.1, 0, 0.1));
      Quad from = fromL.get(0);
      List<Quad> toL = quad.query(new Envelope(19.9, 20, 19.9, 20));
      Quad to = toL.get(0);
      LinkedList<Quad> path = d.computeShortestPath(quad, from, to);
      path.addFirst(from);
      draw(path, em);
      //			to.getEnvelope().get
      try {
        Thread.sleep(2000); // to slow it down a bit
      } catch (InterruptedException e1) {
        e1.printStackTrace();
      }
    }
  }
Exemplo n.º 3
0
 public void add() {
   List<Link> links = ((BusLaneAdderPanel) layersPanels.get(PanelIds.ONE)).getLinks();
   Node prevNode = links.get(0).getFromNode();
   for (Link link : links)
     if (!link.getAllowedModes().contains("bus")) {
       exitSave();
       JOptionPane.showMessageDialog(this, "Wrong path, network saved");
     }
   for (int i = 0; i < links.size(); i++) {
     Link link = links.get(i);
     Node node = null;
     if (link.getNumberOfLanes() == 1) {
       Set<String> modes = new HashSet<String>();
       modes.add("bus");
       link.setAllowedModes(modes);
       node = link.getToNode();
     } else {
       Node oldNode = link.getToNode();
       if (i == links.size() - 1 || oldNode.getInLinks().size() + oldNode.getOutLinks().size() > 2)
         node = oldNode;
       else {
         node =
             network
                 .getFactory()
                 .createNode(
                     Id.createNodeId("fl" + oldNode.getId().toString()), oldNode.getCoord());
         network.addNode(node);
       }
       LinkImpl newLink =
           (LinkImpl)
               network
                   .getFactory()
                   .createLink(Id.createLinkId("fl" + link.getId().toString()), prevNode, node);
       Set<String> modes = new HashSet<String>();
       modes.add("car");
       newLink.setAllowedModes(modes);
       newLink.setCapacity(link.getCapacity());
       newLink.setFreespeed(link.getFreespeed());
       newLink.setLength(link.getLength());
       newLink.setNumberOfLanes(link.getNumberOfLanes() - 1);
       newLink.setOrigId(((LinkImpl) link).getOrigId());
       newLink.setType(((LinkImpl) link).getType());
       network.addLink(newLink);
       Set<String> modes2 = new HashSet<String>();
       modes2.add("bus");
       link.setAllowedModes(modes2);
       link.setCapacity(900);
       link.setNumberOfLanes(1);
     }
     prevNode = node;
   }
   ((BusLaneAdderPanel) layersPanels.get(PanelIds.ONE)).clearSelection();
 }
Exemplo n.º 4
0
  void ktiPtRoutesPerformanceTest(final String[] args) {

    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Config config = scenario.getConfig();
    KtiConfigGroup ktiConfigGroup = new KtiConfigGroup();
    config.addModule(ktiConfigGroup);
    ConfigReader reader = new ConfigReader(config);
    reader.readFile(args[0]);

    Network network = scenario.getNetwork();

    NodeImpl node = null;

    node = new NodeImpl(Id.create(1, Node.class));
    final double x = -824635.0;
    final double y = -799519.0;
    node.setCoord(new Coord(x, y));
    network.addNode(node);

    node = new NodeImpl(Id.create(2, Node.class));
    node.setCoord(new Coord(2732681.5, 2625289.25));
    network.addNode(node);

    PlansCalcRouteKtiInfo plansCalcRouteKtiInfo = new PlansCalcRouteKtiInfo(ktiConfigGroup);
    plansCalcRouteKtiInfo.prepare(network);

    int skip = 1;
    int max = 100000;
    for (int i = 0; i < max; i++) {
      String expectedRouteDescription = "kti=300614=6616=456.78=4258=8500301";
      KtiPtRoute testee = new KtiPtRoute(null, null, plansCalcRouteKtiInfo);
      testee.setRouteDescription(expectedRouteDescription);
      if (i == skip) {
        logger.info("Constructed " + i + " KtiPtRoute objects with processing route descriptions.");
        skip += max / 10;
      }
    }
    logger.info("Constructed " + max + " KtiPtRoute objects with processing route descriptions.");
  }
  private Network createNetwork(Scenario sc) {
    Network net = sc.getNetwork();
    if (net.getCapacityPeriod() != 3600.0) {
      throw new IllegalStateException();
    }

    ((NetworkImpl) net).setEffectiveLaneWidth(1.0);
    NetworkFactory fac = net.getFactory();
    net.addNode(fac.createNode(idN1, new Coord(-500, 0)));
    net.addNode(fac.createNode(idN2, new Coord(-300, 0)));
    net.addNode(fac.createNode(idN3, new Coord(-100, 100)));
    net.addNode(fac.createNode(idN4, new Coord(-100, -100)));
    net.addNode(fac.createNode(idN5, new Coord(100, 100)));
    net.addNode(fac.createNode(idN6, new Coord(100, -100)));
    net.addNode(fac.createNode(idN7, new Coord(300, 0)));
    net.addNode(fac.createNode(idN8, new Coord(500, 0)));

    this.createAndAddLinks(idL12, idL21, idN1, idN2, net);
    this.createAndAddLinks(idL23, idL32, idN2, idN3, net);
    this.createAndAddLinks(idL24, idL42, idN2, idN4, net);
    this.createAndAddLinks(idL35, idL53, idN3, idN5, net);
    this.createAndAddLinks(idL46, idL64, idN4, idN6, net);
    this.createAndAddLinks(idL57, idL75, idN5, idN7, net);
    this.createAndAddLinks(idL67, idL76, idN6, idN7, net);
    this.createAndAddLinks(idL78, idL87, idN7, idN8, net);

    return net;
  }
Exemplo n.º 6
0
  private static Network filterNetwork(Network network) {
    CoordinateTransformation transform =
        TransformationFactory.getCoordinateTransformation(
            TransformationFactory.CH1903_LV03_GT, TransformationFactory.DHDN_GK4);
    //		CoordinateTransformation transform =
    // TransformationFactory.getCoordinateTransformation(TransformationFactory.CH1903_LV03_GT,
    // "WGS84_UTM32T");

    Network net = NetworkUtils.createNetwork();
    RoadPricingSchemeImpl rps = new RoadPricingSchemeImpl();
    RoadPricingReaderXMLv1 rpr = new RoadPricingReaderXMLv1(rps);
    rpr.parse(linksToFilter);
    Set<Id<Link>> linkList = rps.getTolledLinkIds();
    for (Link link : network.getLinks().values()) {
      Id linkId = link.getId();
      if (linkList.contains(linkId)) {
        Id fromId = link.getFromNode().getId();
        Id toId = link.getToNode().getId();
        Coord fromNodeCoord = link.getFromNode().getCoord();
        Coord toNodeCoord = link.getToNode().getCoord();
        Coord fromNodeTransformed = transform.transform(fromNodeCoord);
        Coord toNodeTransformed = transform.transform(toNodeCoord);
        //				Node newFromNode = net.getFactory().createNode(fromId, fromNodeCoord);
        //				Node newToNode = net.getFactory().createNode(toId, toNodeCoord);
        Node newFromNode = net.getFactory().createNode(fromId, fromNodeTransformed);
        Node newToNode = net.getFactory().createNode(toId, toNodeTransformed);
        if (!net.getNodes().containsKey(fromId)) {
          net.addNode(newFromNode);
        }
        if (!net.getNodes().containsKey(toId)) {
          net.addNode(newToNode);
        }
        Link ll = net.getFactory().createLink(link.getId(), newFromNode, newToNode);
        net.addLink(ll);
      }
    }
    return net;
  }
  /*package*/ void addConnectorLinks() {

    QuadTree<Node> quadTree = getNodesQuadTree();
    NetworkFactory factory = network.getFactory();

    /*
     * Try to use the centroid of the polygon. If that does not lie within
     * the polygon, use an interior point.
     */
    for (Entry<Integer, SimpleFeature> entry : zonesMap.entrySet()) {
      int zoneId = entry.getKey();
      SimpleFeature zone = entry.getValue();

      if (SpecialZones.skipZone(zone)) continue;

      Geometry polygon = (Geometry) zone.getDefaultGeometry();
      Point point = polygon.getCentroid();
      if (!polygon.contains(point)) point = polygon.getInteriorPoint();

      /*
       * Convert coordinate from WGS84 to EPSG:28992 (Netherlands Projection)
       */
      Coord wgs84Coord = new Coord(point.getCoordinate().x, point.getCoordinate().y);
      Coord nodeCoord = ct.transform(wgs84Coord);

      Id<Node> nodeId = Id.create(String.valueOf(zoneId), Node.class);
      network.addNode(factory.createNode(nodeId, nodeCoord));

      Node networkConnectorNode = quadTree.getClosest(nodeCoord.getX(), nodeCoord.getY());
      Id<Node> networkConnectorNodeId = networkConnectorNode.getId();

      double length = CoordUtils.calcDistance(nodeCoord, networkConnectorNode.getCoord());

      Id<Link> linkFromId = Id.create(String.valueOf(zoneId) + "from", Link.class);
      Link fromLink = factory.createLink(linkFromId, nodeId, networkConnectorNodeId);
      fromLink.setLength(length);
      fromLink.setCapacity(this.connectorCapacity);
      fromLink.setFreespeed(this.connectorLinkFreeSpeed);
      network.addLink(fromLink);

      Id<Link> linkToId = Id.create(String.valueOf(zoneId) + "to", Link.class);
      Link toLink = factory.createLink(linkToId, networkConnectorNodeId, nodeId);
      toLink.setLength(length);
      toLink.setCapacity(this.connectorCapacity);
      toLink.setFreespeed(this.connectorLinkFreeSpeed);
      network.addLink(toLink);
    }
  }
Exemplo n.º 8
0
 public Node createNode(double x, double y) {
   Node node =
       network
           .getFactory()
           .createNode(Id.create("n" + network.getNodes().size(), Node.class), new Coord(x, y));
   network.addNode(node);
   try {
     PrintWriter writer =
         new PrintWriter(new FileWriter(RoutesPathsGenerator.NEW_NETWORK_NODES_FILE, true));
     writer.println(node.getId());
     writer.println(node.getCoord().getX());
     writer.println(node.getCoord().getY());
     writer.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return node;
 }
Exemplo n.º 9
0
  /**
   * Tests that a custom scoring function factory doesn't get overwritten in the initialization
   * process of the Controler.
   *
   * @author mrieser
   */
  @Test
  public void testSetScoringFunctionFactory() {
    final Config config = this.utils.loadConfig(null);
    config.controler().setLastIteration(0);

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(config);
    // create a very simple network with one link only and an empty population
    Network network = scenario.getNetwork();
    Node node1 = network.getFactory().createNode(Id.create(1, Node.class), new Coord(0, 0));
    Node node2 = network.getFactory().createNode(Id.create(2, Node.class), new Coord(100, 0));
    network.addNode(node1);
    network.addNode(node2);
    Link link = network.getFactory().createLink(Id.create(1, Link.class), node1, node2);
    link.setLength(100);
    link.setFreespeed(1);
    link.setCapacity(3600.0);
    link.setNumberOfLanes(1);

    final Controler controler = new Controler(scenario);
    controler.getConfig().controler().setCreateGraphs(false);
    controler.getConfig().controler().setWriteEventsInterval(0);
    controler.setScoringFunctionFactory(new DummyScoringFunctionFactory());

    controler.addOverridingModule(
        new AbstractModule() {
          @Override
          public void install() {
            bindMobsim()
                .toProvider(
                    new Provider<Mobsim>() {
                      @Override
                      public Mobsim get() {
                        return new FakeMobsim();
                      }
                    });
          }
        });
    controler.setDumpDataAtEnd(false);
    controler.run();

    assertTrue(
        "Custom ScoringFunctionFactory was not set.",
        controler.getScoringFunctionFactory() instanceof DummyScoringFunctionFactory);
  }
Exemplo n.º 10
0
  /* (non-Javadoc)
   * @see org.matsim.core.api.internal.NetworkRunnable#run(org.matsim.api.core.v01.network.Network)
   */
  @Override
  public void run(Network network) {
    Queue<Node> pendingNodes = new LinkedList<Node>(network.getNodes().values());

    double[] env = NetworkUtils.getBoundingBox(pendingNodes);
    QuadTree<Node> quadTree = new QuadTree<Node>(env[0], env[1], env[2], env[3]);
    for (Node node : pendingNodes) {
      quadTree.put(node.getCoord().getX(), node.getCoord().getY(), node);
    }

    long linkIdCounter = 100000000000L;

    while (!pendingNodes.isEmpty()) {
      Node node = pendingNodes.poll();

      double radius = 30;

      double minx = node.getCoord().getX() - radius;
      double miny = node.getCoord().getY() - radius;
      double maxx = node.getCoord().getX() + radius;
      double maxy = node.getCoord().getY() + radius;

      Set<Node> intersectionNodes = new HashSet<Node>(20);
      quadTree.getRectangle(minx, miny, maxx, maxy, intersectionNodes);

      if (intersectionNodes.size() > 1) {
        Set<Node> sourceNodes = new HashSet<Node>();
        Map<Node, Set<Link>> inLinks = new HashMap<Node, Set<Link>>();
        Set<Node> targetNodes = new HashSet<Node>();
        Map<Node, Set<Link>> outLinks = new HashMap<Node, Set<Link>>();

        for (Node intersectionNode : intersectionNodes) {
          for (Link link : intersectionNode.getInLinks().values()) {
            Node fromNode = link.getFromNode();

            double x = fromNode.getCoord().getX();
            double y = fromNode.getCoord().getY();

            if (!(x > minx && y > miny && x < maxx && y < maxy)) {
              sourceNodes.add(fromNode);

              Set<Link> links = inLinks.get(fromNode);
              if (links == null) {
                links = new HashSet<Link>();
                inLinks.put(fromNode, links);
              }
              links.add(link);
            }
          }

          for (Link link : intersectionNode.getOutLinks().values()) {
            Node toNode = link.getToNode();

            double x = toNode.getCoord().getX();
            double y = toNode.getCoord().getY();

            if (!(x > minx && y > miny && x < maxx && y < maxy)) {
              targetNodes.add(toNode);

              Set<Link> links = outLinks.get(toNode);
              if (links == null) {
                links = new HashSet<Link>();
                outLinks.put(toNode, links);
              }
              links.add(link);
            }
          }
        }

        for (Node intersectionNode : intersectionNodes) {
          network.removeNode(intersectionNode.getId());
          quadTree.remove(
              intersectionNode.getCoord().getX(),
              intersectionNode.getCoord().getY(),
              intersectionNode);
          pendingNodes.remove(intersectionNode);
        }

        NetworkFactory factory = network.getFactory();

        Node centerNode = factory.createNode(node.getId(), centerOfMass(intersectionNodes));
        network.addNode(centerNode);
        quadTree.put(centerNode.getCoord().getX(), centerNode.getCoord().getY(), centerNode);

        for (Node source : sourceNodes) {
          Link newLink =
              factory.createLink(Id.create(linkIdCounter++, Link.class), source, centerNode);
          network.addLink(newLink);
          Set<Link> origLinks = inLinks.get(source);
          assignProps(origLinks, newLink);
        }

        for (Node target : targetNodes) {
          Link newLink =
              factory.createLink(Id.create(linkIdCounter++, Link.class), centerNode, target);
          network.addLink(newLink);
          Set<Link> origLinks = outLinks.get(target);
          assignProps(origLinks, newLink);
        }
      }
    }
  }
Exemplo n.º 11
0
  private static void testRestrictedNetwork(final Config config) throws Exception {
    // create a simple scenario, with two parallel links,
    // a long one for cars, a short one for pt.
    final Scenario scenario = ScenarioUtils.createScenario(config);
    Network net = scenario.getNetwork();

    Node n1 =
        net.getFactory().createNode(Id.create(1, Node.class), new Coord((double) 0, (double) 0));
    Node n2 =
        net.getFactory().createNode(Id.create(2, Node.class), new Coord((double) 0, (double) 0));
    Node n3 =
        net.getFactory().createNode(Id.create(3, Node.class), new Coord((double) 0, (double) 0));
    Node n4 =
        net.getFactory().createNode(Id.create(4, Node.class), new Coord((double) 0, (double) 0));

    Link l1 = net.getFactory().createLink(Id.create("l1", Link.class), n1, n2);
    Link l2c = net.getFactory().createLink(Id.create("l2c", Link.class), n2, n3);
    Link l2pt = net.getFactory().createLink(Id.create("l2pt", Link.class), n2, n3);
    Link l3 = net.getFactory().createLink(Id.create("l3", Link.class), n3, n4);

    l2c.setAllowedModes(Collections.singleton(TransportMode.car));
    l2c.setLength(1000);
    l2pt.setAllowedModes(Collections.singleton(TransportMode.pt));
    l2pt.setLength(10);

    net.addNode(n1);
    net.addNode(n2);
    net.addNode(n3);
    net.addNode(n4);

    net.addLink(l1);
    net.addLink(l2c);
    net.addLink(l2pt);
    net.addLink(l3);

    Injector injector =
        Injector.createInjector(
            scenario.getConfig(),
            new AbstractModule() {
              @Override
              public void install() {
                install(
                    AbstractModule.override(
                        Arrays.asList(new TripRouterModule()),
                        new AbstractModule() {
                          @Override
                          public void install() {
                            bind(Scenario.class).toInstance(scenario);
                            addTravelTimeBinding("car")
                                .toInstance(
                                    new FreespeedTravelTimeAndDisutility(config.planCalcScore()));
                            addTravelDisutilityFactoryBinding("car")
                                .toInstance(new OnlyTimeDependentTravelDisutilityFactory());
                          }
                        }));
              }
            });

    // create the factory, get a router, route.
    Provider<TripRouter> factory = injector.getProvider(TripRouter.class);

    TripRouter router = factory.get();

    List<? extends PlanElement> trip =
        router.calcRoute(
            TransportMode.car,
            new LinkFacility(l1),
            new LinkFacility(l3),
            0,
            PersonImpl.createPerson(Id.create("toto", Person.class)));

    Leg l = (Leg) trip.get(0);

    // actual test
    NetworkRoute r = (NetworkRoute) l.getRoute();

    Assert.assertEquals("unexpected route length " + r.getLinkIds(), 1, r.getLinkIds().size());

    Assert.assertEquals("unexpected link", l2c.getId(), r.getLinkIds().get(0));
  }
Exemplo n.º 12
0
  /** Checks that routes are found when using a monomodal network (ie modes are not restricted) */
  @Test
  public void testMonomodalNetwork() throws Exception {
    final Config config = ConfigUtils.createConfig();
    final Scenario scenario = ScenarioUtils.createScenario(config);
    Network net = scenario.getNetwork();

    Node n1 =
        net.getFactory().createNode(Id.create(1, Node.class), new Coord((double) 0, (double) 0));
    Node n2 =
        net.getFactory().createNode(Id.create(2, Node.class), new Coord((double) 0, (double) 0));
    Node n3 =
        net.getFactory().createNode(Id.create(3, Node.class), new Coord((double) 0, (double) 0));
    Node n4 =
        net.getFactory().createNode(Id.create(4, Node.class), new Coord((double) 0, (double) 0));

    Link l1 = net.getFactory().createLink(Id.create("l1", Link.class), n1, n2);
    Link l2long = net.getFactory().createLink(Id.create("l2long", Link.class), n2, n3);
    Link l2short = net.getFactory().createLink(Id.create("l2short", Link.class), n2, n3);
    Link l3 = net.getFactory().createLink(Id.create("l3", Link.class), n3, n4);

    l2long.setLength(1000);
    l2short.setLength(10);

    net.addNode(n1);
    net.addNode(n2);
    net.addNode(n3);
    net.addNode(n4);

    net.addLink(l1);
    net.addLink(l2long);
    net.addLink(l2short);
    net.addLink(l3);

    // create the factory, get a router, route.
    Injector injector =
        Injector.createInjector(
            scenario.getConfig(),
            new AbstractModule() {
              @Override
              public void install() {
                install(
                    AbstractModule.override(
                        Arrays.asList(new TripRouterModule()),
                        new AbstractModule() {
                          @Override
                          public void install() {
                            bind(Scenario.class).toInstance(scenario);
                            addTravelTimeBinding("car")
                                .toInstance(
                                    new FreespeedTravelTimeAndDisutility(config.planCalcScore()));
                            addTravelDisutilityFactoryBinding("car")
                                .toInstance(new OnlyTimeDependentTravelDisutilityFactory());
                          }
                        }));
              }
            });

    TripRouter router = injector.getInstance(TripRouter.class);

    List<? extends PlanElement> trip =
        router.calcRoute(
            TransportMode.car,
            new LinkFacility(l1),
            new LinkFacility(l3),
            0,
            PersonImpl.createPerson(Id.create("toto", Person.class)));

    Leg l = (Leg) trip.get(0);

    // actual test
    NetworkRoute r = (NetworkRoute) l.getRoute();

    Assert.assertEquals("unexpected route length " + r.getLinkIds(), 1, r.getLinkIds().size());

    Assert.assertEquals("unexpected link", l2short.getId(), r.getLinkIds().get(0));
  }
Exemplo n.º 13
0
  private static void createNetwork(Scenario sc) {
    Network net = sc.getNetwork();
    NetworkFactory fac = net.getFactory();

    double length = 60;
    double width = 20;

    int id = 0;
    Node n0 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(0, 0));
    Node n1 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length, 0));
    Node n2 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length, length));
    Node n3 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(0, length));
    net.addNode(n0);
    net.addNode(n1);
    net.addNode(n2);
    net.addNode(n3);
    id = 0;
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n0, n1);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n1, n2);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n2, n3);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n3, n0);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n1, n0);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n2, n1);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n3, n2);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n0, n3);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
  }
  public static void main(String[] args) throws IOException {
    List<Setting> settings = new ArrayList<>();
    for (double w = 2.9; w < 3; w += 0.05) {
      settings.add(new Setting(w, 3, 3, 500, 0, w, w));
    }
    for (double w = .4; w < 3; w += 0.2) {
      settings.add(new Setting(3, 3, w, 500, 0, w, w));
    }
    for (double w = 0.8; w <= 3; w += 0.2) {
      settings.add(new Setting(w, 3, 3, 500, 0, w, w));
    }

    AbstractCANetwork.EMIT_VIS_EVENTS = false;
    USE_SPH = true;
    for (int R = 12; R <= 12; R++) {
      CASingleLaneDensityEstimatorSPH.H = R;
      CAMultiLaneDensityEstimatorSPH.H = R;
      CASingleLaneDensityEstimatorSPA.RANGE = R;
      CASingleLaneDensityEstimatorSPHII.H = R;
      CASingleLaneDensityEstimatorSPAII.RANGE = R;
      try {
        bw =
            new BufferedWriter(
                new FileWriter(new File("/Users/laemmel/devel/bipedca/ant/uni" + R)));
      } catch (IOException e) {
        e.printStackTrace();
      }

      for (Setting s : settings) {
        System.out.println(s);
        Config c = ConfigUtils.createConfig();
        c.global().setCoordinateSystem("EPSG:3395");
        Scenario sc = ScenarioUtils.createScenario(c);

        // VIS only
        Sim2DConfig conf2d = Sim2DConfigUtils.createConfig();
        Sim2DScenario sc2d = Sim2DScenarioUtils.createSim2dScenario(conf2d);
        sc.addScenarioElement(Sim2DScenario.ELEMENT_NAME, sc2d);

        Network net = sc.getNetwork();
        ((NetworkImpl) net).setCapacityPeriod(1);
        NetworkFactory fac = net.getFactory();

        int l = 8;
        int res = 20;
        Node n0 = fac.createNode(Id.createNodeId("0"), new CoordImpl(20 - res, 0));
        Node n1 = fac.createNode(Id.createNodeId("1"), new CoordImpl(20, 0));
        Node n2 = fac.createNode(Id.createNodeId("2"), new CoordImpl(24, 0));
        Node n2ex = fac.createNode(Id.createNodeId("2ex"), new CoordImpl(24, 20));
        Node n3 = fac.createNode(Id.createNodeId("3"), new CoordImpl(24 + l, 0));
        Node n3ex = fac.createNode(Id.createNodeId("3ex"), new CoordImpl(24 + l, -20));
        Node n4 = fac.createNode(Id.createNodeId("4"), new CoordImpl(24 + 4 + l, 0));
        Node n5 = fac.createNode(Id.createNodeId("5"), new CoordImpl(24 + 4 + res + l, 0));
        net.addNode(n5);
        net.addNode(n4);
        net.addNode(n3ex);
        net.addNode(n3);
        net.addNode(n2ex);
        net.addNode(n2);
        net.addNode(n1);
        net.addNode(n0);

        Link l0 = fac.createLink(Id.createLinkId("0"), n0, n1);
        Link l0rev = fac.createLink(Id.createLinkId("0rev"), n1, n0);
        Link l1 = fac.createLink(Id.createLinkId("1"), n1, n2);
        Link l1rev = fac.createLink(Id.createLinkId("1rev"), n2, n1);
        Link l2 = fac.createLink(Id.createLinkId("2"), n2, n3);
        Link l2rev = fac.createLink(Id.createLinkId("2rev"), n3, n2);
        Link l2ex = fac.createLink(Id.createLinkId("2ex"), n2, n2ex);
        Link l3 = fac.createLink(Id.createLinkId("3"), n3, n4);
        Link l3ex = fac.createLink(Id.createLinkId("3ex"), n3, n3ex);
        Link l3rev = fac.createLink(Id.createLinkId("3rev"), n4, n3);
        Link l4 = fac.createLink(Id.createLinkId("4"), n4, n5);
        Link l4rev = fac.createLink(Id.createLinkId("4rev"), n5, n4);

        l0.setLength(res);
        l1.setLength(4);

        l0rev.setLength(res);
        l1rev.setLength(4);

        l2rev.setLength(l);
        l2.setLength(l);

        l3rev.setLength(4);
        l3.setLength(4);
        l4rev.setLength(res);
        l4.setLength(res);
        l3ex.setLength(20);
        l2ex.setLength(20);

        net.addLink(l4);
        net.addLink(l4rev);
        net.addLink(l1);
        net.addLink(l0);
        net.addLink(l2);
        net.addLink(l2rev);
        net.addLink(l1rev);
        net.addLink(l0rev);
        net.addLink(l3rev);
        net.addLink(l3);
        net.addLink(l3ex);
        net.addLink(l2ex);

        double bl = s.bL;
        double bc = s.bCor;
        double br = s.bR;
        double bexR = s.bexR;
        double bexL = s.bexL;

        l0.setCapacity(5);
        l0rev.setCapacity(5);
        l1.setCapacity(bl);
        l1rev.setCapacity(bl);
        l2.setCapacity(bc);
        l2rev.setCapacity(bc);
        l3.setCapacity(br);
        l3rev.setCapacity(br);
        l4.setCapacity(5);
        l4rev.setCapacity(5);
        l3ex.setCapacity(bexR);
        l2ex.setCapacity(bexL);

        List<Link> linksLR = new ArrayList<Link>();
        linksLR.add(l0);
        linksLR.add(l1);
        linksLR.add(l2);
        linksLR.add(l3ex);
        List<Link> linksRL = new ArrayList<Link>();
        linksRL.add(l4rev);
        linksRL.add(l3rev);
        linksRL.add(l2rev);
        linksRL.add(l2ex);

        for (int i = 0; i < 1; i++) {
          for (double th = 1; th <= 1; th += 0.15) {
            runIt(net, linksLR, linksRL, sc, th, s);
          }
          // for (double th = .26; th <= .4; th += 0.01) {
          // runIt(net, linksLR, sc, th);
          // }
          // for (double th = .45; th < .5; th += 0.05) {
          // runIt(net, linksLR, sc, th);
          // }
          // for (double th = .5; th <= 1.; th += 0.1) {
          // runIt(net, linksLR, sc, th);
          // }
        }
      }
      bw.close();
    }
  }
  public void testTransitRouteCopy() {
    Config config = super.loadConfig(null);
    config.scenario().setUseTransit(true);
    config.scenario().setUseVehicles(true);
    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(config);

    Id<Node> nodeId1 = Id.create("1", Node.class);
    Id<Node> nodeId2 = Id.create("2", Node.class);
    Id<Node> nodeId3 = Id.create("3", Node.class);
    Id<Link> linkId1 = Id.create("1", Link.class);
    Id<Link> linkId2 = Id.create("2", Link.class);

    // build network
    Network network = scenario.getNetwork();
    NetworkFactory nBuilder = network.getFactory();
    Node node1 = nBuilder.createNode(nodeId1, scenario.createCoord(0, 0));
    Node node2 = nBuilder.createNode(nodeId2, scenario.createCoord(1000, 0));
    Node node3 = nBuilder.createNode(nodeId3, scenario.createCoord(2000, 0));
    network.addNode(node1);
    network.addNode(node2);
    network.addNode(node3);
    Link link1 = nBuilder.createLink(linkId1, node1, node2);
    Link link2 = nBuilder.createLink(linkId2, node2, node3);
    network.addLink(link1);
    network.addLink(link2);

    // build schedule
    TransitSchedule schedule = scenario.getTransitSchedule();
    TransitScheduleFactory sBuilder = schedule.getFactory();

    TransitStopFacility stopF1 =
        sBuilder.createTransitStopFacility(
            Id.create("1", TransitStopFacility.class), scenario.createCoord(1000.0, 0), false);
    TransitStopFacility stopF2 =
        sBuilder.createTransitStopFacility(
            Id.create("2", TransitStopFacility.class), scenario.createCoord(2000.0, 0), false);
    stopF1.setLinkId(link1.getId());
    stopF2.setLinkId(link2.getId());
    schedule.addStopFacility(stopF1);
    schedule.addStopFacility(stopF2);

    TransitLine tLine1 = sBuilder.createTransitLine(Id.create("1", TransitLine.class));

    TransitRouteStop stop1 = sBuilder.createTransitRouteStop(stopF1, 0, 0);
    TransitRouteStop stop2 = sBuilder.createTransitRouteStop(stopF2, 100, 100);
    ArrayList<TransitRouteStop> stops = new ArrayList<TransitRouteStop>();
    stops.add(stop1);
    stops.add(stop2);

    NetworkRoute netRoute = new LinkNetworkRouteImpl(link1.getId(), link2.getId());
    netRoute.setLinkIds(link1.getId(), Collections.<Id<Link>>emptyList(), link2.getId());
    TransitRoute tRoute1 =
        sBuilder.createTransitRoute(Id.create("1", TransitRoute.class), netRoute, stops, "bus");

    tRoute1.addDeparture(sBuilder.createDeparture(Id.create("1", Departure.class), 7.0 * 3600));
    tLine1.addRoute(tRoute1);
    schedule.addTransitLine(tLine1);

    // build vehicles
    new CreateVehiclesForSchedule(schedule, scenario.getVehicles()).run();

    // build population
    Population population = scenario.getPopulation();
    PopulationFactory pBuilder = population.getFactory();
    Person person1 = pBuilder.createPerson(Id.create("1", Person.class));
    Plan plan = pBuilder.createPlan();
    Activity homeAct = pBuilder.createActivityFromLinkId("h", linkId1);
    homeAct.setEndTime(7.0 * 3600);
    plan.addActivity(homeAct);
    Leg leg = pBuilder.createLeg(TransportMode.pt);
    ExperimentalTransitRoute tRoute = new ExperimentalTransitRoute(stopF1, tLine1, tRoute1, stopF2);
    leg.setRoute(tRoute);
    plan.addLeg(leg);
    plan.addActivity(pBuilder.createActivityFromLinkId("w", linkId2));
    person1.addPlan(plan);
    population.addPerson(person1);

    // prepare config
    config.controler().setFirstIteration(0);
    config.controler().setLastIteration(1);

    ActivityParams params = new ActivityParams("h");
    params.setTypicalDuration(16.0 * 3600);
    config.planCalcScore().addActivityParams(params);
    params = new ActivityParams("w");
    params.setTypicalDuration(8.0 * 3600);
    config.planCalcScore().addActivityParams(params);

    StrategySettings tam = new StrategySettings(Id.create(1, StrategySettings.class));
    tam.setStrategyName("TimeAllocationMutator");
    tam.setWeight(1.0);
    config.strategy().addStrategySettings(tam);

    // run
    Controler controler = new Controler(scenario);
    controler.getConfig().controler().setWriteEventsInterval(0);
    controler.setCreateGraphs(false);
    controler.run();

    // checks
    assertEquals(1, population.getPersons().size());
    assertEquals(2, person1.getPlans().size());
    assertEquals(
        ExperimentalTransitRoute.class,
        ((Leg) person1.getPlans().get(0).getPlanElements().get(1)).getRoute().getClass());
    assertEquals(
        ExperimentalTransitRoute.class,
        ((Leg) person1.getPlans().get(1).getPlanElements().get(1)).getRoute().getClass());
  }
Exemplo n.º 16
0
  private static int createNetwork(Scenario sc) {
    Network net = sc.getNetwork();
    NetworkFactory fac = net.getFactory();

    double length = 30;
    double width = 20;

    int id = 0;
    Node n0 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(0, 0));
    Node n1 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length, 0));
    net.addNode(n0);
    net.addNode(n1);

    List<Node> someNodes = new ArrayList<>();
    for (double y = -30; y <= 30; y += 10) {
      Node n = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length * 3, y));
      net.addNode(n);
      someNodes.add(n);
    }
    Node n2 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length * 4, 0));
    Node n3 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length * 5, 0));
    net.addNode(n2);
    net.addNode(n3);
    id = 0;
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n0, n1);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
      Link l0Rev = fac.createLink(Id.createLinkId(id++), n1, n0);
      net.addLink(l0Rev);
      l0Rev.setCapacity(width);
      l0Rev.setLength(length);
    }
    int cnt = 0;
    for (Node n : someNodes) {
      {
        Link l0 = fac.createLink(Id.createLinkId(id++), n1, n);
        net.addLink(l0);
        l0.setCapacity(width / someNodes.size());
        l0.setLength(length * 2); // ?check!!
        if (cnt++ % 2 != 0) {
          Link l0Rev = fac.createLink(Id.createLinkId(id++), n, n1);
          net.addLink(l0Rev);
          l0Rev.setCapacity(width / someNodes.size());
          l0Rev.setLength(length * 2);
        }
      }

      {
        Link l0 = fac.createLink(Id.createLinkId(id++), n, n2);
        net.addLink(l0);
        l0.setCapacity(width / someNodes.size());
        l0.setLength(length); // ?check!!
        Link l0Rev = fac.createLink(Id.createLinkId(id++), n2, n);
        net.addLink(l0Rev);
        l0Rev.setCapacity(width / someNodes.size());
        l0Rev.setLength(length);
      }
    }
    int ret;
    {
      ret = id++;
      Link l0 = fac.createLink(Id.createLinkId(ret), n2, n3);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }
    {
      Link l0 = fac.createLink(Id.createLinkId(id++), n3, n2);
      net.addLink(l0);
      l0.setCapacity(width);
      l0.setLength(length);
    }

    Set<String> modes = new HashSet<>();
    modes.add("walkct");
    for (Link l : net.getLinks().values()) {
      l.setAllowedModes(modes);
      l.setFreespeed(20);
    }
    return ret;
  }