コード例 #1
0
  @Test
  public void testOutsideTollTime() {
    Config config = matsimTestUtils.loadConfig(null);
    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    Fixture.createNetwork2(scenario);

    // a basic toll where only the morning hours are tolled
    RoadPricingSchemeImpl toll = new RoadPricingSchemeImpl();
    toll.setType("area");
    toll.addLink(Id.createLinkId("5"));
    toll.addLink(Id.createLinkId("11"));
    toll.addCost(8 * 3600, 10 * 3600, 1.0); // high costs!

    Fixture.createPopulation2(scenario);
    Population population = scenario.getPopulation();

    runOnAll(testee(scenario, toll), population);
    Id id1 = Id.createPersonId("1");
    LegImpl leg1 = getLeg1(population, id1);
    LegImpl leg2 = getLeg3(population, id1);

    Fixture.compareRoutes(
        "2 5 6",
        (NetworkRoute)
            leg1
                .getRoute()); // agent should take shortest route, as tolls are not active at that
                              // time
    Fixture.compareRoutes("8 11 12", (NetworkRoute) leg2.getRoute());
  }
コード例 #2
0
ファイル: MyRuns.java プロジェクト: Janekdererste/matsim
  /**
   * Used this routine for MeisterEtAl_Heureka_2008 paper, plot of number of deps, arrs by activity
   * type to visualize the time distribution from microcensus.
   */
  public static void analyseInitialTimes(Config config) {

    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    // initialize scenario with events from a given events file
    // - network
    logger.info("Reading network xml file...");
    new MatsimNetworkReader(scenario).readFile(scenario.getConfig().network().getInputFile());
    logger.info("Reading network xml file...done.");
    // - population
    PersonAlgorithm pa = new PersonAnalyseTimesByActivityType(TIME_BIN_SIZE);
    ArrayList<PersonAlgorithm> plansAlgos = new ArrayList<PersonAlgorithm>();
    plansAlgos.add(pa);

    PopulationImpl matsimAgentPopulation = (PopulationImpl) scenario.getPopulation();
    matsimAgentPopulation.setIsStreaming(true);
    PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(scenario.getConfig().plans().getInputFile());
    matsimAgentPopulation.printPlansCount();
    int[][] numDeps = ((PersonAnalyseTimesByActivityType) pa).getNumDeps();
    MyRuns.writeAnArray(numDeps, "output/deptimes.txt");
    int[][] numArrs = ((PersonAnalyseTimesByActivityType) pa).getNumArrs();
    MyRuns.writeAnArray(numArrs, "output/arrtimes.txt");
    int[][] numTraveling = ((PersonAnalyseTimesByActivityType) pa).getNumTraveling();
    MyRuns.writeAnArray(numTraveling, "output/traveling.txt");
  }
コード例 #3
0
  @Override
  public void run() {
    String eventsFile1 = "output/ITERS/it.10/10.events.xml.gz";
    String eventsFile2 = "outputBridgeClosed/ITERS/it.20/20.events.xml.gz";
    EventsManager before = EventsUtils.createEventsManager();
    EventsManager after = EventsUtils.createEventsManager();

    String network = "output/output_network.xml.gz";
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario).readFile(network);

    for (Entry<Id<Link>, ? extends Link> entry : scenario.getNetwork().getLinks().entrySet()) {
      linkDeltas.put(entry.getKey(), new AnalysisLink());
    }

    before.addHandler(new Before());
    after.addHandler(new After());

    new MatsimEventsReader(before).readFile(eventsFile1);
    new MatsimEventsReader(after).readFile(eventsFile2);

    initFeatureType();

    ArrayList<SimpleFeature> features = new ArrayList<SimpleFeature>();
    for (Entry<Id<Link>, ? extends Link> entry : scenario.getNetwork().getLinks().entrySet()) {
      features.add(getFeature(entry.getValue()));
    }

    ShapeFileWriter.writeGeometries(features, "output/delta-network");
  }
コード例 #4
0
  public static void main(String[] args) {
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario).readFile("../../input/network.xml");

    TravelTimeCalculator ttc =
        new TravelTimeCalculator(
            network, 60, 30 * 3600, scenario.getConfig().travelTimeCalculator());
    LeastCostPathTree st =
        new LeastCostPathTree(
            ttc.getLinkTravelTimes(),
            new RandomizingTimeDistanceTravelDisutility.Builder(TransportMode.car)
                .createTravelDisutility(
                    ttc.getLinkTravelTimes(), scenario.getConfig().planCalcScore()));
    Node origin = network.getNodes().get(Id.create(1, Node.class));
    st.calculate(network, origin, 8 * 3600);
    Map<Id<Node>, NodeData> tree = st.getTree();
    for (Map.Entry<Id<Node>, NodeData> e : tree.entrySet()) {
      Id<Node> id = e.getKey();
      NodeData d = e.getValue();
      if (d.getPrevNodeId() != null) {
        System.out.println(id + "\t" + d.getTime() + "\t" + d.getCost() + "\t" + d.getPrevNodeId());
      } else {
        System.out.println(id + "\t" + d.getTime() + "\t" + d.getCost() + "\t" + "0");
      }
    }
  }
コード例 #5
0
  public static void main(String[] args) {

    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimReader populationReader = new PopulationReader(scenario);
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario.getNetwork());
    networkReader.readFile(args[1]);
    populationReader.readFile(args[2]);

    ObjectAttributes bla = new ObjectAttributes();

    new ObjectAttributesXmlReader(bla).readFile(args[0]);

    for (Person p : scenario.getPopulation().getPersons().values()) {
      String act = "home";
      if (bla.getAttribute(p.getId().toString(), "earliestEndTime_leisure") != null)
        act = act + ",leisure";
      //	if (bla.getAttribute(p.getId().toString(), "earliestEndTime_work") != null)
      //		act = act + ",work";
      if (bla.getAttribute(p.getId().toString(), "earliestEndTime_shop") != null)
        act = act + ",shop";
      //	if (bla.getAttribute(p.getId().toString(), "earliestEndTime_education") != null)
      //		act = act + ",education";

      bla.putAttribute(p.getId().toString(), "activities", act);
    }

    ObjectAttributesXmlWriter betaWriter = new ObjectAttributesXmlWriter(bla);
    betaWriter.writeFile(args[3]);
  }
コード例 #6
0
ファイル: MyRuns.java プロジェクト: Janekdererste/matsim
  public void analyzeModeChainFeasibility(Config config) {

    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    // initialize scenario with events from a given events file
    // - network
    logger.info("Reading network xml file...");
    Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario).readFile(config.network().getInputFile());
    logger.info("Reading network xml file...done.");

    // - facilities
    logger.info("Reading facilities xml file...");
    ActivityFacilities facilities = scenario.getActivityFacilities();
    new MatsimFacilitiesReader(scenario).parse(config.facilities().getInputFile());
    logger.info("Reading facilities xml file...");

    // - population
    PersonAnalyzeModeChainFeasibility pa =
        new PersonAnalyzeModeChainFeasibility(facilities, network);
    ArrayList<PersonAlgorithm> plansAlgos = new ArrayList<PersonAlgorithm>();
    plansAlgos.add(pa);

    PopulationImpl matsimAgentPopulation = (PopulationImpl) scenario.getPopulation();
    matsimAgentPopulation.setIsStreaming(true);
    matsimAgentPopulation.addAlgorithm(pa);
    PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(config.plans().getInputFile());

    logger.info("Number of selected plans which are infeasible: " + pa.getNumInfeasiblePlans());
  }
コード例 #7
0
  private void createLanes(MutableScenario scenario) {
    double laneLenght = 50.0;
    LaneDefinitions11 lanes11 = new LaneDefinitions11Impl();
    LaneDefinitionsFactory11 factory = lanes11.getFactory();
    // lanes for link 12
    LanesToLinkAssignment11 lanesForLink12 = factory.createLanesToLinkAssignment(idL12);
    lanes11.addLanesToLinkAssignment(lanesForLink12);
    LaneData11 link12lane1 = factory.createLane(idL12L1);
    lanesForLink12.addLane(link12lane1);
    link12lane1.addToLinkId(idL23);
    link12lane1.setStartsAtMeterFromLinkEnd(laneLenght);

    LaneData11 link12lane2 = factory.createLane(idL12L2);
    lanesForLink12.addLane(link12lane2);
    link12lane2.addToLinkId(idL24);
    link12lane2.setStartsAtMeterFromLinkEnd(laneLenght);

    // lanes for link 87
    LanesToLinkAssignment11 lanesForLink87 = factory.createLanesToLinkAssignment(idL87);
    lanes11.addLanesToLinkAssignment(lanesForLink87);
    LaneData11 link87lane1 = factory.createLane(idL87L1);
    lanesForLink87.addLane(link87lane1);
    link87lane1.addToLinkId(idL76);
    link87lane1.setStartsAtMeterFromLinkEnd(laneLenght);

    LaneData11 link87lane2 = factory.createLane(idL87L2);
    lanesForLink87.addLane(link87lane2);
    link87lane2.addToLinkId(idL75);
    link87lane2.setStartsAtMeterFromLinkEnd(laneLenght);

    // convert to 2.0 format and save in scenario
    LaneDefinitionsV11ToV20Conversion.convertTo20(
        lanes11, scenario.getLanes(), scenario.getNetwork());
  }
コード例 #8
0
  public static void main(String[] args) {
    String path2MATSimNetwork = args[0];
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario.getNetwork());
    networkReader.readFile(path2MATSimNetwork);
    Network network = scenario.getNetwork();
    String speedFactor = args[1];
    String capacityFactor = args[2];
    radius = Integer.parseInt(args[3]);

    final BufferedWriter out = IOUtils.getBufferedWriter(args[4]);
    try {
      // Header
      out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      out.newLine();
      out.write(
          "<networkChangeEvents xmlns=\"http://www.matsim.org/files/dtd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.matsim.org/files/dtd http://www.matsim.org/files/dtd/networkChangeEvents.xsd\">");
      out.newLine();
      // reduce capacity and speed:
      out.write("    <networkChangeEvent startTime=\"07:00:00\">");
      out.newLine();
      for (Link link : network.getLinks().values()) {
        if (isLinkAffected(link)) {
          out.write("        <link refId=\"" + link.getId().toString() + "\"/>");
          out.newLine();
        }
      }
      out.write("        <flowCapacity type=\"scaleFactor\" value=\"" + capacityFactor + "\"/>");
      out.newLine();
      out.write("        <freespeed type=\"scaleFactor\" value=\"" + speedFactor + "\"/>");
      out.newLine();
      out.write("    </networkChangeEvent>");
      out.newLine();
      // reset capacity and speed:
      for (Link link : network.getLinks().values()) {
        if (isLinkAffected(link)) {
          out.write("    <networkChangeEvent startTime=\"09:00:00\">");
          out.newLine();
          out.write("        <link refId=\"" + link.getId().toString() + "\"/>");
          out.newLine();
          out.write(
              "        <flowCapacity type=\"absolute\" value=\"" + link.getCapacity() + "\"/>");
          out.newLine();
          out.write("        <freespeed type=\"absolute\" value=\"" + link.getFreespeed() + "\"/>");
          out.newLine();
          out.write("    </networkChangeEvent>");
          out.newLine();
        }
      }
      // Footer:
      out.write("</networkChangeEvents>");
      out.newLine();

      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #9
0
ファイル: GeneralLib.java プロジェクト: nkuehnel/matsim
 /**
  * @param facilitiesFile
  * @return
  */
 @Deprecated // use centralized infrastructure
 public static ActivityFacilities readActivityFacilities(String facilitiesFile) {
   MutableScenario scenario =
       (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
   ActivityFacilities facilities = scenario.getActivityFacilities();
   new MatsimFacilitiesReader(scenario).readFile(facilitiesFile);
   return facilities;
 }
コード例 #10
0
ファイル: GeneralLib.java プロジェクト: nkuehnel/matsim
  /*
   * Reads the network from the network file.
   */
  @Deprecated // use centralized infrastructure
  public static Network readNetwork(String networkFile) {
    MutableScenario sc = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    sc.getConfig().setParam("network", "inputNetworkFile", networkFile);

    ScenarioUtils.loadScenario(sc);

    return sc.getNetwork();
  }
コード例 #11
0
 private static Population getPopulationTypesTransitLine(Scenario scenario, String[] args) {
   scenario.getConfig().transit().setUseTransit(true);
   (new TransitScheduleReader(scenario)).readFile(args[4]);
   TransitLine line =
       scenario.getTransitSchedule().getTransitLines().get(Id.create(args[5], TransitLine.class));
   MutableScenario sc = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
   Population population = PopulationUtils.createPopulation(sc.getConfig(), sc.getNetwork());
   for (Person person : scenario.getPopulation().getPersons().values())
     if (isRelatedWithLine(person, line))
       population.addPerson(new PersonImplPops(person, Id.create(line.getId(), Population.class)));
     else population.addPerson(new PersonImplPops(person, PersonImplPops.DEFAULT_POP_ID));
   return population;
 }
コード例 #12
0
ファイル: GeneralLib.java プロジェクト: nkuehnel/matsim
  /*
   * Reads the population from the plans file.
   */
  @Deprecated // use centralized infrastructure
  public static Scenario readScenario(
      String plansFile, String networkFile, String facilititiesPath) {
    MutableScenario sc = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    sc.getConfig().setParam("plans", "inputPlansFile", plansFile);
    sc.getConfig().setParam("network", "inputNetworkFile", networkFile);
    sc.getConfig().setParam("facilities", "inputFacilitiesFile", facilititiesPath);

    ScenarioUtils.loadScenario(sc);

    return sc;
  }
コード例 #13
0
  /** Tests a few cases where the router can decide if it is better to pay the toll or not. */
  @Test
  public void testBestAlternatives() {
    Config config = matsimTestUtils.loadConfig(null);
    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    Fixture.createNetwork2(scenario);

    // a basic toll where only the morning hours are tolled
    RoadPricingSchemeImpl toll = new RoadPricingSchemeImpl();
    toll.setType("area");
    toll.addLink(Id.createLinkId("5"));
    toll.addLink(Id.createLinkId("11"));
    Cost morningCost = toll.addCost(6 * 3600, 10 * 3600, 0.12);
    /* Start with a rather low toll. The toll is also so low, because we only
     * have small network with short links: the cost to travel across one link
     * is: 20s * (-6 EUR / h) = 20 * (-6) / 3600 = 0.03333
     */

    Fixture.createPopulation2(scenario);
    Population population = scenario.getPopulation();

    Id id1 = Id.createPersonId("1");

    // case 1: toll only in morning, it is cheaper to drive around
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 3 4 6", (NetworkRoute) getLeg1(population, id1).getRoute());
    Fixture.compareRoutes("8 11 12", (NetworkRoute) getLeg3(population, id1).getRoute());

    // case 2: now add a toll in the afternoon too, so it is cheaper to pay the toll
    Cost afternoonCost = toll.addCost(14 * 3600, 18 * 3600, 0.12);
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 5 6", (NetworkRoute) getLeg1(population, id1).getRoute());
    Fixture.compareRoutes("8 11 12", (NetworkRoute) getLeg3(population, id1).getRoute());

    // case 3: change the second leg to a non-car mode, than it should be the same as case 1
    String oldMode = getLeg3(population, id1).getMode();
    getLeg3(population, id1).setMode(TransportMode.pt);
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 3 4 6", (NetworkRoute) getLeg1(population, id1).getRoute());
    // and change the mode back
    getLeg3(population, id1).setMode(oldMode);

    // case 4: now remove the costs and add them again, but with a higher amount
    toll.removeCost(morningCost);
    toll.removeCost(afternoonCost);
    toll.addCost(6 * 3600, 10 * 3600, 0.7);
    toll.addCost(14 * 3600, 18 * 3600, 0.7);
    // the agent should now decide to drive around
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 3 4 6", (NetworkRoute) getLeg1(population, id1).getRoute());
  }
コード例 #14
0
ファイル: MyRuns.java プロジェクト: Janekdererste/matsim
  public static Population initMatsimAgentPopulation(
      final String inputFilename,
      final boolean isStreaming,
      final ArrayList<PersonAlgorithm> algos,
      MutableScenario scenario) {

    PopulationImpl population = (PopulationImpl) scenario.getPopulation();

    System.out.println("  reading plans xml file... ");
    population.setIsStreaming(isStreaming);

    if (isStreaming) {
      // add plans algos for streaming
      if (algos != null) {
        for (PersonAlgorithm algo : algos) {
          population.addAlgorithm(algo);
        }
      }
    }
    PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(inputFilename);
    population.printPlansCount();
    System.out.println("  done.");

    return population;
  }
コード例 #15
0
ファイル: GeneralLib.java プロジェクト: nkuehnel/matsim
  /**
   * TODO: write test.
   *
   * @param persons
   * @param outputPlansFileName
   * @param network
   */
  public static void writePersons(
      Collection<? extends Person> persons,
      String outputPlansFileName,
      Network network,
      MutableScenario scenario) {
    PopulationWriter popWriter =
        new PopulationWriter(
            PopulationUtils.createPopulation(scenario.getConfig(), scenario.getNetwork()), network);
    popWriter.writeStartPlans(outputPlansFileName);

    for (Person person : persons) {
      popWriter.writePerson(person);
    }

    popWriter.writeEndPlans();
  }
コード例 #16
0
  public InternalControler(
      MutableScenario scenario,
      double fare,
      boolean calculate_inVehicleTimeDelayEffects,
      boolean calculate_waitingTimeDelayEffects,
      boolean calculate_capacityDelayEffects,
      boolean marginalCostPricingPt,
      boolean calculate_carCongestionEffects,
      boolean marginalCostPricingCar) {

    this.calculate_inVehicleTimeDelayEffects = calculate_inVehicleTimeDelayEffects;
    this.calculate_waitingTimeDelayEffects = calculate_waitingTimeDelayEffects;
    this.calculate_capacityDelayEffects = calculate_capacityDelayEffects;
    this.marginalCostPricingPt = marginalCostPricingPt;
    this.calculate_carCongestionEffects = calculate_carCongestionEffects;
    this.marginalCostPricingCar = marginalCostPricingCar;
    this.scenario = scenario;
    this.fare = fare;

    this.CONSTANT_PT =
        scenario.getConfig().planCalcScore().getModes().get(TransportMode.pt).getConstant();
    log.info("Pt constant set to " + this.CONSTANT_PT);

    //		this.LATE_ARRIVAL = -1. * this.PERFORMING * 2.; // coming early (which is the opportunity
    // costs of time) multiplied by 3 --> multiplying by 2 (see Hollander 2006)

  }
コード例 #17
0
  public static void main(String[] args) {

    String dataPath = "/Volumes/DATA 1 (WD 2 TB)/SimMethanaOutput_120215/";
    String populationFile =
        "/Volumes/DATA 1 (WD 2 TB)/SimMethanaOutput_120215/w8-18_homo/output_plans.xml.gz";
    String individualSelectedScoreFile =
        "/Volumes/DATA 1 (WD 2 TB)/SimMethanaOutput_120215/w8-18_homo/individualSelectedBenefits";

    File directory = new File(dataPath);
    File[] fList = directory.listFiles();

    for (File file : fList) {
      if (file.isDirectory()) {
        HashMap<String, String> scoreMap = new HashMap<String, String>();
        MutableScenario scenario =
            (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());

        System.out.println(file.getAbsolutePath());
        populationFile = file.getAbsolutePath() + "/output_plans.xml.gz";
        individualSelectedScoreFile = file.getAbsolutePath() + "/individualSelectedBenefits.csv";

        new PopulationReaderMatsimV5(scenario).readFile(populationFile);
        System.out.println("   Population size: " + scenario.getPopulation().getPersons().size());

        // Read selected plan score
        System.out.println("   Reading population from: " + populationFile);
        for (Person person : scenario.getPopulation().getPersons().values()) {
          scoreMap.put(person.getId().toString(), person.getSelectedPlan().getScore().toString());
        }

        System.out.println("   Map size: " + scoreMap.size());
        // Write selected plan scores;
        System.out.println(
            "   Writting individial selected plan scores to: " + individualSelectedScoreFile);
        Writer writer = new Writer();
        writer.creteFile(individualSelectedScoreFile);

        for (String personId : scoreMap.keySet()) {
          writer.writeLine(personId + "," + scoreMap.get(personId));
        }

        writer.close();
      }
    }

    System.out.println("Done!");
  }
コード例 #18
0
ファイル: PersonDataCS.java プロジェクト: matsim-org/matsim
  public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimReader populationReader = new PopulationReader(scenario);
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario.getNetwork());
    networkReader.readFile(args[1]);
    populationReader.readFile(args[0]);

    final BufferedWriter outLinkrb = IOUtils.getBufferedWriter(args[2]);
    final BufferedWriter outLinkff = IOUtils.getBufferedWriter(args[3]);

    for (Person p : scenario.getPopulation().getPersons().values()) {
      boolean rb = false;
      boolean ff = false;
      Person pImpl = p;
      Plan plan = p.getSelectedPlan();

      for (PlanElement pe : plan.getPlanElements()) {

        if (pe instanceof Leg) {

          if (((Leg) pe).getMode().equals("cs_fix_gas") && !rb) {
            outLinkrb.write(p.getId().toString() + " ");
            outLinkrb.write(Integer.toString(PersonUtils.getAge(pImpl)) + " ");
            outLinkrb.write(PersonUtils.getSex(pImpl) + " ");
            outLinkrb.write(PersonUtils.getCarAvail(pImpl));
            outLinkrb.newLine();
            rb = true;

          } else if (((Leg) pe).getMode().equals("cs_flex_gas") && !ff) {
            outLinkff.write(p.getId().toString() + " ");
            outLinkff.write(Integer.toString(PersonUtils.getAge(pImpl)) + " ");
            outLinkff.write(PersonUtils.getSex(pImpl) + " ");
            outLinkff.write(PersonUtils.getCarAvail(pImpl));
            outLinkff.newLine();
            ff = true;
          }
        }
      }
    }
    outLinkrb.flush();
    outLinkrb.close();
    outLinkff.flush();
    outLinkff.close();
  }
コード例 #19
0
  public static void main(String[] args) {
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario.getNetwork());
    networkReader.readFile(args[0]);

    int numberOfLinks = 0;
    double length = 0.0;
    double length1 = 0.0;
    double length2 = 0.0;
    double length3 = 0.0;
    Node previousNode1 = null;
    Node previousNode2 = null;
    for (Link l : scenario.getNetwork().getLinks().values()) {
      if (previousNode1 != null) {

        if (l.getFromNode().getId() != previousNode2.getId()
            && l.getToNode().getId() != previousNode1.getId()) {
          numberOfLinks++;
          length += l.getLength();
          if (l.getFreespeed() > 24.99) {
            length1 += l.getLength();
          } else if (l.getFreespeed() < 13.88) {
            length3 += l.getLength();

          } else length2 += l.getLength();
        }
      } else {
        numberOfLinks++;
        length += l.getLength();
        if (l.getFreespeed() > 24.99) {
          length1 += l.getLength();
        } else if (l.getFreespeed() < 13.88) {
          length3 += l.getLength();

        } else length2 += l.getLength();
      }
      previousNode1 = l.getFromNode();
      previousNode2 = l.getToNode();
    }
    System.out.println(numberOfLinks);
    System.out.println(length / 1000);
    System.out.println(length1 / 1000);
    System.out.println(length2 / 1000);
    System.out.println(length3 / 1000);
  }
コード例 #20
0
  public static void runEventsProcessing(Properties properties) {
    boolean isTransit = false;
    MutableScenario scenario =
        (MutableScenario)
            ScenarioUtils.createScenario(
                ConfigUtils.loadConfig(properties.get("configFile").toString()));
    scenario.getConfig().transit().setUseTransit(true);
    if (!properties.get("transitScheduleFile").toString().equals("")) {
      new TransitScheduleReader(scenario)
          .readFile(properties.get("transitScheduleFile").toString());
      isTransit = true;
    }
    new MatsimNetworkReader(scenario).readFile(properties.get("networkFile").toString());

    EventsManager eventsManager = EventsUtils.createEventsManager();
    EventsToTravelDiaries test;
    // if(linkTrafficComponent.isSelected()){
    // test = new EventsToPlanElements(
    // scenario.getTransitSchedule(), scenario.getNetwork(),
    // scenario.getConfig(),new File(postgresPropertiesComponent.getText())
    // ,tableSuffixComponent.getText());
    // }else{
    if (isTransit) {
      test =
          new EventsToTravelDiaries(
              scenario.getTransitSchedule(), scenario.getNetwork(), scenario.getConfig());

    } else {
      test = new EventsToTravelDiaries(scenario);
    }
    // }
    eventsManager.addHandler(test);
    new MatsimEventsReader(eventsManager).readFile(properties.get("eventsFile").toString());

    try {

      test.writeSimulationResultsToTabSeparated(
          properties.get("outputPath").toString(), properties.get("tableSuffix").toString());

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println("Number of stuck vehicles/passengers: " + test.getStuck());
  }
コード例 #21
0
  public static void main(String[] args) {
    MutableScenario s = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    s.getConfig().transit().setUseTransit(true);
    s.getConfig().scenario().setUseVehicles(true);

    Vehicles v = s.getTransitVehicles();
    TransitSchedule ts = s.getTransitSchedule();
    PopulationImpl p = (PopulationImpl) s.getPopulation();

    new MatsimNetworkReader(s).readFile(NETWORK);
    new VehicleReaderV1(v).readFile(VEHICLES);
    new TransitScheduleReader(s).readFile(SCHEDULE);
    log.info("build transit router...");
    TransitRouterConfig tRConfig =
        new TransitRouterConfig(
            s.getConfig().planCalcScore(),
            s.getConfig().plansCalcRoute(),
            s.getConfig().transitRouter(),
            s.getConfig().vspExperimental());

    TransitRouterImpl router = new TransitRouterImpl(tRConfig, ts);

    PtRouter ptR = new PtRouter(router);

    p.setIsStreaming(true);
    p.addAlgorithm(ptR);

    log.info("start processing persons...");
    new MatsimPopulationReader(s).readFile(PLANS);

    ptR.close();
  }
コード例 #22
0
ファイル: PRPrepareRunner.java プロジェクト: sebhoerl/matsim
 private void loadScenario() {
   Config config = scenario.getConfig();
   config.transit().setUseTransit(true);
   config.scenario().setUseVehicles(true);
   config.transit().setTransitScheduleFile(scheduleFile);
   config.transit().setVehiclesFile(vehiclesFile);
   config.network().setInputFile(networkFile);
   ScenarioUtils.loadScenario(scenario);
 }
コード例 #23
0
  /** @param args */
  public static void main(String[] args) {
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Network net = scenario.getNetwork();
    MatsimIo.loadNetwork(DgPaths.IVTCHNET, scenario);
    Population plansCmcf = MatsimIo.loadPlans(cmcfPlansFile, net);
    Population plans = MatsimIo.loadPlans(plansFile, net);
    for (Person p : plans.getPersons().values()) {
      Plan pl = p.getSelectedPlan();
      Leg l = ((PlanImpl) pl).getNextLeg(((PlanImpl) pl).getFirstActivity());
      Plan plcmcf = plansCmcf.getPersons().get(p.getId()).getSelectedPlan();
      Leg lcmcf = ((PlanImpl) plcmcf).getNextLeg(((PlanImpl) plcmcf).getFirstActivity());
      l.setRoute(lcmcf.getRoute());
    }
    MatsimIo.writePlans(plans, net, outPlansFile);

    log.info("done");
  }
コード例 #24
0
ファイル: MyRuns.java プロジェクト: Janekdererste/matsim
  void moveInitDemandToDifferentNetwork(final String[] args) {

    // read ivtch demand
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Config config = scenario.getConfig();
    MeisterkConfigGroup meisterkConfigGroup = new MeisterkConfigGroup();
    config.addModule(meisterkConfigGroup);
    ConfigReader reader = new ConfigReader(config);
    reader.readFile(args[0]);
    MatsimRandom.reset(config.global().getRandomSeed());

    ScenarioUtils.loadScenario(scenario);

    Population population = scenario.getPopulation();
    Network network = scenario.getNetwork();

    // remove links and routes
    PersonRemoveLinkAndRoute personRemoveLinkAndRoute = new PersonRemoveLinkAndRoute();
    personRemoveLinkAndRoute.run(population);

    // switch to new network in scenario

    // this is what I found ...
    //		ScenarioImpl scenario2 = (ScenarioImpl)
    // ScenarioUtils.createScenario(ConfigUtils.createConfig());
    //		new MatsimNetworkReader(scenario2).parse(config.getParam(MeisterkConfigGroup.GROUP_NAME,
    // "inputSecondNetworkFile"));
    //		scenario.setNetwork(scenario2.getNetwork());

    // ... but I think we can just give the existing scenario to the reader, so I am changing this.
    // There is so much commented out in this
    // code that it is probably no longer used anyways. kai, sep'15
    new MatsimNetworkReader(scenario)
        .parse(config.getParam(MeisterkConfigGroup.GROUP_NAME, "inputSecondNetworkFile"));

    // run XY2Links
    XY2Links xY2Links = new XY2Links();

    // write out new initial demand
    // new PopulationWriter(population,
    // network).write(null);//scenario.getConfig().plans().getOutputFile());

  }
コード例 #25
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    MutableScenario scenario1 =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    PopulationReader populationReader1 = new MatsimPopulationReader(scenario1);
    MatsimNetworkReader networkReader1 = new MatsimNetworkReader(scenario1);
    networkReader1.readFile(args[0]);
    populationReader1.readFile(args[1]);

    MutableScenario scenario2 =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    PopulationReader populationReader2 = new MatsimPopulationReader(scenario2);
    MatsimNetworkReader networkReader2 = new MatsimNetworkReader(scenario2);
    networkReader2.readFile(args[0]);
    populationReader2.readFile(args[2]);

    int car = 0;
    int pt = 0;
    int walk = 0;
    int bike = 0;
    for (Person p : scenario2.getPopulation().getPersons().values()) {

      for (PlanElement pe :
          scenario1
              .getPopulation()
              .getPersons()
              .get(p.getId())
              .getSelectedPlan()
              .getPlanElements()) {

        if (pe instanceof Leg) {

          if (((Leg) pe).getMode().equals("car")) car++;
          else if (((Leg) pe).getMode().equals("pt")) pt++;
          else if (((Leg) pe).getMode().equals("walk")) walk++;
          else if (((Leg) pe).getMode().equals("bike")) bike++;
        }
      }
    }

    System.out.println(car + " " + pt + " " + bike + " " + walk);
  }
コード例 #26
0
  @Test
  public void test_RunTutorial() {
    Config config = this.utils.loadConfig("test/scenarios/pt-tutorial/config.xml");
    config.planCalcScore().setWriteExperiencedPlans(true);
    config.controler().setLastIteration(0);
    config.plans().setInputFile("test/scenarios/pt-tutorial/population2.xml");
    Controler controler = new Controler(config);
    controler
        .getConfig()
        .controler()
        .setOverwriteFileSetting(
            OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);
    controler.getConfig().controler().setCreateGraphs(false);
    controler.run();

    MutableScenario s = (MutableScenario) controler.getScenario();
    Assert.assertNotNull(s.getTransitSchedule());
    Assert.assertEquals(4, s.getTransitSchedule().getFacilities().size());
    Assert.assertEquals(1, s.getTransitSchedule().getTransitLines().size());
  }
コード例 #27
0
ファイル: MyRuns.java プロジェクト: Janekdererste/matsim
  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.");
  }
コード例 #28
0
  /** @param args */
  public static void main(String[] args) {
    String netFile = filePath + networkName + inFileType;
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    Network net;
    if (!filterLinks) {
      net = scenario.getNetwork();
      new MatsimNetworkReader(scenario.getNetwork()).readFile(netFile);
    } else {
      Network network = scenario.getNetwork();
      new MatsimNetworkReader(scenario.getNetwork()).readFile(netFile);
      net = filterNetwork(network);
    }
    //		new Links2ESRIShape(net, filePath + networkName + outFileType,
    // TransformationFactory.WGS84).write();
    //		new Links2ESRIShape(net, filePath + networkName + outFileType,
    // TransformationFactory.CH1903_LV03_GT).write();
    //		new Links2ESRIShape(net, filePath + networkName + outFileType,
    // TransformationFactory.DHDN_GK4).write();
    new Links2ESRIShape(net, filePath + networkName + outFileType, "EPSG:32646").write();
    //		new Links2ESRIShape(net, filePath + networkName + outFileType, "WGS84_UTM32T").write();
  }
コード例 #29
0
  /**
   * Tests cases where the agent must pay the toll because one of its activities is on a tolled link
   */
  @Test
  public void testTolledActLink() {
    Config config = matsimTestUtils.loadConfig(null);
    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    Fixture.createNetwork2(scenario);

    // a basic toll where only the morning hours are tolled
    RoadPricingSchemeImpl toll = new RoadPricingSchemeImpl();
    toll.setType("area");
    Id.createLinkId("7");
    toll.addCost(6 * 3600, 10 * 3600, 0.06);

    Fixture.createPopulation2(scenario);
    Population population = scenario.getPopulation();

    runOnAll(testee(scenario, toll), population);
    Id id1 = Id.createPersonId("1");

    Fixture.compareRoutes(
        "2 5 6",
        (NetworkRoute) getLeg1(population, id1).getRoute()); // agent should take shortest route
    Fixture.compareRoutes("8 11 12", (NetworkRoute) getLeg3(population, id1).getRoute());
  }
コード例 #30
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();
    }
  }