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]);
  }
Пример #2
0
  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();
  }
Пример #3
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);
  }
Пример #4
0
  public static void main(String[] args) {
    String dir = "d:\\PP-rad\\poznan\\";
    String networkFile = dir + "network.xml";
    String linkStats = dir + "40.linkstats.txt.gz";
    String polygonFile = dir + "poznan_polygon\\poznan_city_polygon.shp";
    boolean includeBorderLinks = false;
    String filteredLinkStats = dir + "40.linkstats-filtered.txt.gz";

    Geometry polygonGeometry = PolygonBasedFilter.readPolygonGeometry(polygonFile);
    Predicate<Link> linkInsidePolygonPredicate =
        PolygonBasedFilter.createLinkInsidePolygonPredicate(polygonGeometry, includeBorderLinks);

    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimNetworkReader nr = new MatsimNetworkReader(scenario.getNetwork());
    nr.readFile(networkFile);

    Map<Id<Link>, ? extends Link> linkMap = scenario.getNetwork().getLinks();

    try (BufferedReader br = IOUtils.getBufferedReader(linkStats);
        PrintWriter pw = new PrintWriter(IOUtils.getBufferedWriter(filteredLinkStats))) {
      String header = br.readLine();
      pw.println(header);

      String line;
      while ((line = br.readLine()) != null) {
        String linkId = new StringTokenizer(line).nextToken(); // linkId - first column
        Link link = linkMap.get(Id.create(linkId, Link.class));

        if (linkInsidePolygonPredicate.apply(link)) {
          pw.println(line);
        }
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Пример #5
0
  public void run(String plansFilePath, String networkFilePath) {
    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimReader populationReader = new PopulationReader(scenario);
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario.getNetwork());
    networkReader.readFile(networkFilePath);
    populationReader.readFile(plansFilePath);
    int countE = 0;
    int countW = 0;
    int countS = 0;
    int countL = 0;
    int countH = 0;
    int count = 0;
    int work = 0;
    boolean cs = false;
    int number = 0;
    for (Person p : scenario.getPopulation().getPersons().values()) {
      ArrayList<Activity> c = new ArrayList<Activity>();
      Activity a = null;
      cs = false;
      for (PlanElement pe : p.getSelectedPlan().getPlanElements()) {

        if (pe instanceof Activity) {
          a = (Activity) pe;

        } else if (pe instanceof Leg) {

          if (a.getType().startsWith("home")) {

            if (((Leg) pe).getMode().equals("walk_rb")) number++;
            // startWork = true;
          }
        }

        if (pe instanceof Leg) {

          if ((((Leg) pe).getMode().equals("twowaycarsharing"))
              || ((Leg) pe).getMode().equals("walk_rb")) {
            cs = true;

          } else cs = false;

        } else if (pe instanceof Activity) {
          if (cs) {

            if (((Activity) pe).getType().startsWith("work")) {
              if (!c.isEmpty()) work++;
              else {

              }
              countW++;
              // time += (((Activity) pe).getMaximumDuration());
              c.add((Activity) pe);
              count++;
            } else if (((Activity) pe).getType().startsWith("education")) {
              countE++;
              count++;
            } else if (((Activity) pe).getType().startsWith("shop")) {
              countS++;
              count++;
            } else if (((Activity) pe).getType().startsWith("leisure")) {
              countL++;
              count++;
            } else if (((Activity) pe).getType().startsWith("home")) {
              countH++;
              count++;
            }
          }
        }
      }
    }
    System.out.println(work);
    System.out.println(number);
    System.out.println((double) countS / count * 100.0);
    System.out.println((double) countW / count * 100.0);
    System.out.println((double) countE / count * 100.0);
    System.out.println((double) countL / count * 100.0);
    System.out.println((double) countH / count * 100.0);
    System.out.println(count);
    System.out.println((double) countS / count);

    // new PopulationWriter(scenario.getPopulation(),
    // scenario.getNetwork()).writeFileV4(outputFilePath + "/plans_1p.xml");

  }