/** @param args */
  public static void main(String[] args) {
    Network network = NetworkUtils.createNetwork();
    new MatsimNetworkReader(network)
        .readFile(
            "../../../shared-svn/studies/jbischoff/multimodal/berlin/input/10pct/network.final10pct.xml.gz");
    NetworkFilterManager m = new NetworkFilterManager(network);
    m.addLinkFilter(
        new NetworkLinkFilter() {

          @Override
          public boolean judgeLink(Link l) {
            if (l.getAllowedModes().contains(TransportMode.car)) return true;
            else return false;
          }
        });
    Network network2 = m.applyFilters();
    new NetworkWriter(network2)
        .write(
            "../../../shared-svn/studies/jbischoff/multimodal/berlin/input/10pct/network.final10pct_car.xml.gz");
  }
Example #2
0
  @Override
  public void run() {
    if (scenario instanceof MutableScenario) {
      ((MutableScenario) scenario).setLocked();
      // see comment in ScenarioImpl. kai, sep'14
    }

    /*
     * Create single-mode network here and hand it over to PersonPrepareForSim. Otherwise, each instance would create its
     * own single-mode network. However, this assumes that the main mode is car - which PersonPrepareForSim also does. Should
     * be probably adapted in a way that other main modes are possible as well. cdobler, oct'15.
     */
    final Network net;
    if (NetworkUtils.isMultimodal(network)) {
      log.info(
          "Network seems to be multimodal. Create car-only network which is handed over to PersonPrepareForSim.");
      TransportModeNetworkFilter filter = new TransportModeNetworkFilter(network);
      net = NetworkUtils.createNetwork();
      HashSet<String> modes = new HashSet<>();
      modes.add(TransportMode.car);
      filter.filter(net, modes);
    } else {
      net = network;
    }

    // make sure all routes are calculated.
    ParallelPersonAlgorithmRunner.run(
        population,
        globalConfigGroup.getNumberOfThreads(),
        new ParallelPersonAlgorithmRunner.PersonAlgorithmProvider() {
          @Override
          public AbstractPersonAlgorithm getPersonAlgorithm() {
            return new MyPersonPrepareForSim(
                new PlanRouter(tripRouterProvider.get(), activityFacilities), scenario, net);
          }
        });
    if (population instanceof Lockable) {
      ((Lockable) population).setLocked();
    }
  }
Example #3
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;
  }
  public static void main(String[] args) {
    Scenario scenario;
    scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new NetworkReaderMatsimV2(scenario.getNetwork()).readFile(args[0]);
    Network network = scenario.getNetwork();
    Network net = NetworkUtils.createNetwork();
    Set<String> modes = new HashSet<>();
    modes.add(TransportMode.car);
    new TransportModeNetworkFilter(network).filter(net, modes);
    new NetworkCleaner().run(net);
    MatsimRandom.reset(123);
    DrunkDudePathfinder stochasticRouter =
        new DrunkDudePathfinder(
            net,
            new TravelDisutility() {

              @Override
              public double getLinkTravelDisutility(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }

              @Override
              public double getLinkMinimumTravelDisutility(Link link) {
                return link.getLength() / link.getFreespeed();
              }
            },
            new TravelTime() {

              @Override
              public double getLinkTravelTime(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }
            },
            0.5);
    SimpleNetworkPainter networkPainter = new SimpleNetworkPainter(400, 400);
    networkPainter.setNetworkTransformation(network);
    stochasticRouter.setNetworkPainter(networkPainter);
    //        stochasticRouter.calcLeastCostPath(network.getNodes().get(Id.createNodeId("11_311")),
    //                network.getNodes().get(Id.createNodeId("18_566")), 3600, null, null);
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.addAll(net.getNodes().values());
    Node[] nodesArray = nodeSet.toArray(new Node[nodeSet.size()]);

    long currentTimeMillis = -System.currentTimeMillis();
    for (int i = 0; i < 1e3; i++) {
      int[] ints = Sample.sampleMfromN(2, nodesArray.length);
      System.out.println(nodesArray[ints[0]] + " " + nodesArray[ints[1]]);
      stochasticRouter.calcLeastCostPath(
          nodesArray[ints[0]], nodesArray[ints[1]], 3600, null, null);
    }
    currentTimeMillis += System.currentTimeMillis();
    System.out.println(currentTimeMillis);

    Dijkstra dijkstra =
        new Dijkstra(
            net,
            new TravelDisutility() {

              @Override
              public double getLinkTravelDisutility(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }

              @Override
              public double getLinkMinimumTravelDisutility(Link link) {
                return link.getLength() / link.getFreespeed();
              }
            },
            new TravelTime() {

              @Override
              public double getLinkTravelTime(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }
            },
            null);
    currentTimeMillis = -System.currentTimeMillis();
    for (int i = 0; i < 1e3; i++) {
      int[] ints = Sample.sampleMfromN(2, nodesArray.length);
      dijkstra.calcLeastCostPath(nodesArray[ints[0]], nodesArray[ints[1]], 3600, null, null);
    }
    currentTimeMillis += System.currentTimeMillis();
    System.out.println(currentTimeMillis);
  }