Beispiel #1
0
  /** @param args */
  public static void main(String[] args) {
    Header.printHeader(SurveyParser.class.toString(), args);

    SurveyParser sp = new SurveyParser(args[0], Integer.parseInt(args[1]));
    sp.parsePersons(args[2]);
    sp.parseHouseholds(args[3]);
    sp.parseDerivedHouseholdAssets(args[4]);
    sp.parseDiaryTrips(args[5]);

    sp.writePopulation(args[6], sp.getScenario());

    Scenario surveySc = sp.filterScenarioToSurveyRespondents();
    sp.cleanUpScenario(surveySc);
    sp.writePopulation(args[7], surveySc);

    /* Finish off with some basic population statistics. */
    LOG.info("---------------------------------------");
    LOG.info(" Number of households: " + surveySc.getHouseholds().getHouseholds().size());
    LOG.info("    Number of persons: " + surveySc.getPopulation().getPersons().size());
    LOG.info("---------------------------------------");
    PopulationUtils.printActivityStatistics(
        args[7] + (args[7].endsWith("/") ? "" : "/") + "population.xml.gz");

    /* Some arbitrary checks. Remove once done. */
    LOG.info("              Number of observed zones: " + sp.zoneMap.size());
    LOG.info("  Number of unknown activity locations: " + numberOfUnknownActivityLocations);
    LOG.info("Number of (fixable) activity locations: " + numberOfFixableActivityLocations);

    Header.printFooter();
  }
  public static void main(String[] args) {
    Header.printHeader(ComprehensivePopulationReader.class.toString(), args);

    String inputFolder = args[0];
    ComprehensivePopulationReader csr = new ComprehensivePopulationReader();
    csr.parse(inputFolder);

    Header.printFooter();
  }
  /** @param args */
  public static void main(String[] args) {
    Header.printHeader(CapeTownPopulationBuilder.class.toString(), args);

    String censusPopulationFolder = args[0]; /* This should be in WGS84_SA_Albers. */
    String outputFolder = args[1];
    outputFolder += outputFolder.endsWith("/") ? "" : "/";

    setup(outputFolder, censusPopulationFolder);

    Header.printFooter();
  }
  /** @param args */
  public static void main(String[] args) {
    Header.printHeader(Census2001SampleParser.class.toString(), args);
    String householdFilename = args[0];
    String personFilename = args[1];
    String geographyFilename = args[2];
    String outputFolder = args[3];

    Census2001SampleParser cs = new Census2001SampleParser();
    cs.parseHouseholdMap(householdFilename);
    cs.parseGeography(geographyFilename);
    cs.parsePersons(personFilename);

    cs.buildPopulation();
    cs.writePopulationAndAttributes(outputFolder);

    Header.printFooter();
  }
  /** @param args */
  public static void main(String[] args) {
    Header.printHeader(checkShoppingTypes.class.toString(), args);

    Scenario sc = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimReader pr = new PopulationReader(sc);
    pr.readFile(args[0]);

    int s1 = 0;
    int s2 = 0;
    int s3 = 0;
    int s4 = 0;
    int s5 = 0;

    for (Id id : sc.getPopulation().getPersons().keySet()) {
      Plan plan = sc.getPopulation().getPersons().get(id).getSelectedPlan();
      for (PlanElement pe : plan.getPlanElements()) {
        if (pe instanceof Activity) {
          Activity act = (Activity) pe;
          String s = act.getType();
          if (s.equalsIgnoreCase("s1")) {
            s1++;
          } else if (s.equalsIgnoreCase("s2")) {
            s2++;
          } else if (s.equalsIgnoreCase("s3")) {
            s3++;
          } else if (s.equalsIgnoreCase("s4")) {
            s4++;
          } else if (s.equalsIgnoreCase("s5")) {
            s5++;
          }
        }
      }
    }

    LOG.info("  s1: " + s1);
    LOG.info("  s2: " + s2);
    LOG.info("  s3: " + s3);
    LOG.info("  s4: " + s4);
    LOG.info("  s5: " + s5);

    Header.printFooter();
  }
  public static void main(String[] args) {
    Header.printHeader(RunCapeTownFreight.class.toString(), args);

    String folder = args[0] + (args[0].endsWith("/") ? "" : "/");
    Machine machine = Machine.valueOf(args[1]);

    /* Check if output folder exists, and DELETE if it is there. */
    File f = new File(folder + "output/");
    if (f.exists() && f.isDirectory()) {
      LOG.warn("Deleting the output folder " + folder + "output/");
      FileUtils.delete(f);
    }

    /* Set up the simulation run. */
    Config config = setupConfig(folder, machine);
    Scenario sc = setupScenario(config);
    Controler controler = setupControler(sc);

    controler.run();

    Header.printFooter();
  }
  /**
   * Executing the vehicle activity chain extractor for the 12 months March 2013 to February 2014.
   *
   * @param args the following (all required) arguments, in this sequence:
   *     <ol>
   *       <li>the folder containing the processed monthly folders; and
   *       <li>the number of threads over which the job will be spread.
   *     </ol>
   */
  public static void main(String[] args) {
    Header.printHeader(MonthlyFileExtractor.class.toString(), args);

    String processedFolder = args[0];
    int numberOfThreads = Integer.parseInt(args[1]);
    String vehicleStatusFile = args[2];

    List<File> inputFiles = GrainUtils.getVehicleFolders(processedFolder);
    for (File month : inputFiles) {
      LOG.info("====> Processing month " + month.getAbsolutePath());

      /* Create the output folder. */
      String outputFolder =
          month.getParentFile()
              + (month.getParentFile().getAbsolutePath().endsWith("/") ? "" : "/")
              + "xml/";
      boolean created = new File(outputFolder).mkdirs();
      if (!created) {
        LOG.error("Could not create the output folder " + outputFolder);
        LOG.error("====> Skipping the month.");
      } else {
        String[] sa = {
          month.getAbsolutePath(),
          vehicleStatusFile,
          outputFolder,
          String.valueOf(numberOfThreads),
          String.valueOf(60 * 60 * 5), /* 5 hours. */
          String.valueOf(60), /* 60 seconds */
          "WGS84_SA_Albers"
        };

        MyMultiThreadChainExtractor.main(sa);
        LOG.info("====> Done processing month.");
      }
    }

    Header.printFooter();
  }
  /** @param args */
  public static void main(String[] args) {
    Header.printHeader(ExtractVehiclesForSollyFrans.class.toString(), args);

    String path = "/home/jwjoubert/Documents/data/Digicore/ByMonth/201403/SollyFrans/xml/";
    String output = "/home/jwjoubert/Documents/data/Digicore/ByMonth/201403/SollyFrans/chains.csv";
    List<File> list =
        FileUtils.sampleFiles(new File(path), 100, FileUtils.getFileFilter(".xml.gz"));

    CoordinateTransformation ct =
        TransformationFactory.getCoordinateTransformation("WGS84_SA_Albers", "WGS84");

    BufferedWriter bw = IOUtils.getBufferedWriter(output);
    try {
      bw.write("Vehicle,Chain,Activity,X,Y,Long,Lat,Start,End");
      bw.newLine();

      for (File f : list) {
        DigicoreVehicleReader_v1 dvr = new DigicoreVehicleReader_v1();
        dvr.readFile(f.getAbsolutePath());
        DigicoreVehicle v = dvr.getVehicle();
        bw.write(v.getId().toString());
        bw.write(",");

        int chain = 1;
        for (DigicoreChain c : v.getChains()) {
          int act = 1;
          for (DigicoreActivity a : c.getAllActivities()) {
            Coord coord = a.getCoord();
            Coord coordWgs84 = ct.transform(coord);

            String s =
                String.format(
                    "%s,%d,%d,%.0f,%.0f,%.6f,%.6f,%s,%s\n",
                    v.getId().toString(),
                    chain,
                    act,
                    coord.getX(),
                    coord.getY(),
                    coordWgs84.getX(),
                    coordWgs84.getY(),
                    getNiceDate(a.getStartTimeGregorianCalendar()),
                    getNiceDate(a.getEndTimeGregorianCalendar()));
            bw.write(s);
            act++;
          }
          chain++;
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
      throw new RuntimeException("Cannot write to " + output);
    } finally {
      try {
        bw.close();
      } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Cannot close " + output);
      }
    }

    Header.printFooter();
  }
Beispiel #9
0
  public static void main(String[] args) {
    Header.printHeader(PopulationParser2.class.toString(), args);

    /* Read in arguments*/
    int pmin = Integer.parseInt(args[0]);
    int radius = Integer.parseInt(args[1]);
    int minRuns = Integer.parseInt(args[2]);
    int numberRuns = Integer.parseInt(args[3]);
    int minPopulations = Integer.parseInt(args[4]);
    int numberPopulations = Integer.parseInt(args[5]);
    String saShapefile = args[6];
    String gautengShapefile = args[7];
    String ctShapefile = args[8];
    String eThekwiniShapefile = args[9];
    int numberOfThreads = Integer.parseInt(args[10]);

    //		PopulationParser2 pp2 = new PopulationParser2();
    //		PopulationParser pp = new PopulationParser();
    //		String outputFile = "./populationAnalyser.csv";
    String outputFile =
        "C:/Users/sumarie/Documents/Honneurs/SVC 791/Data/TrainingSyntheticPopulations/populationAnalyser.csv";

    /*Read in all four shapefiles*/
    Geometry southAfrica = getGeometryFromShapeFile(saShapefile, 1);
    Geometry gauteng = getGeometryFromShapeFile(gautengShapefile, 1);
    Geometry capeTown = getGeometryFromShapeFile(ctShapefile, 2);
    Geometry eThekwini = getGeometryFromShapeFile(eThekwiniShapefile, 1);

    Map<Integer, List<int[]>> consolidatedMap = new TreeMap<Integer, List<int[]>>();

    /* Iterate through the 100 populations and populate the populationMap.
     * To run through all 100 populations, set minRuns = 1, numberRuns = 11,
     * minPopulations = 0, and numberPopulations = 10.
     */
    for (int i = minRuns; i < numberRuns; i++) {
      for (int j = minPopulations; j < numberPopulations; j++) {

        Counter counter = new Counter("   vehicle # ");
        /* Set up multi-threaded infrastructure */
        ExecutorService threadExecutor = Executors.newFixedThreadPool(numberOfThreads);
        List<Future<List<int[]>>> jobs = new ArrayList<Future<List<int[]>>>();

        /* Parse this population */
        //				String populationFile =
        // String.format("results%d/trainingPopulation_%d_%d_%d_%d.xml.gz", i, pmin, radius, i, j);
        String populationFile =
            String.format(
                "C:/Users/sumarie/Documents/Honneurs/SVC 791/Data/TrainingSyntheticPopulations/trainingPopulation_%d_%d_%d_%d.xml.gz",
                pmin, radius, i, j);
        int population = j * 10 + i;
        String populationOutputFile =
            String.format(
                "C:/Users/sumarie/Documents/Honneurs/SVC 791/Data/TrainingSyntheticPopulations/population_%d.csv",
                population);
        //				String populationOutputFile = String.format("./population_%d.csv", population);

        LOG.info("Reading population " + population);
        PopulationParser2 pp2 = new PopulationParser2();
        Collection<? extends Person> personCollection = pp2.readPopulation(populationFile);
        //				Collection<? extends Person> personCollection = pp2.readPopulation(populationFile);
        Iterator<? extends Person> iterator = personCollection.iterator();

        while (iterator.hasNext()) {
          Person vehicle = iterator.next();
          Plan selectedPlan = vehicle.getSelectedPlan();
          Callable<List<int[]>> job =
              new ExtractorCallable(
                  selectedPlan, southAfrica, gauteng, capeTown, eThekwini, counter);
          Future<List<int[]>> result = threadExecutor.submit(job);
          jobs.add(result);
        }

        /* Shutdown threadExecutor */
        threadExecutor.shutdown();
        while (!threadExecutor.isTerminated()) {}
        counter.printCounter();

        /* Consolidate output */
        LOG.info("Consolidating output...");

        List<int[]> consolidatedPopulationInfo = new ArrayList<int[]>();
        int[] hourArray = new int[24];
        int[] activityArray = new int[72];
        int[] areaArray = new int[9];
        int[] hourArray1 = new int[24];
        int[] activityArray1 = new int[72];
        int[] hourArray2 = new int[24];
        int[] activityArray2 = new int[72];
        int[] hourArray3 = new int[24];
        int[] activityArray3 = new int[72];
        int[] hourArray4 = new int[24];
        int[] activityArray4 = new int[72];
        int[] hourArray5 = new int[24];
        int[] activityArray5 = new int[72];
        int[] hourArray6 = new int[24];
        int[] activityArray6 = new int[72];
        int[] hourArray7 = new int[24];
        int[] activityArray7 = new int[72];
        int[] hourArray8 = new int[24];
        int[] activityArray8 = new int[72];
        int[] hourArray9 = new int[24];
        int[] activityArray9 = new int[72];

        consolidatedPopulationInfo.add(areaArray);
        consolidatedPopulationInfo.add(hourArray);
        consolidatedPopulationInfo.add(activityArray);
        consolidatedPopulationInfo.add(hourArray1);
        consolidatedPopulationInfo.add(activityArray1);
        consolidatedPopulationInfo.add(hourArray2);
        consolidatedPopulationInfo.add(activityArray2);
        consolidatedPopulationInfo.add(hourArray3);
        consolidatedPopulationInfo.add(activityArray3);
        consolidatedPopulationInfo.add(hourArray4);
        consolidatedPopulationInfo.add(activityArray4);
        consolidatedPopulationInfo.add(hourArray5);
        consolidatedPopulationInfo.add(activityArray5);
        consolidatedPopulationInfo.add(hourArray6);
        consolidatedPopulationInfo.add(activityArray6);
        consolidatedPopulationInfo.add(hourArray7);
        consolidatedPopulationInfo.add(activityArray7);
        consolidatedPopulationInfo.add(hourArray8);
        consolidatedPopulationInfo.add(activityArray8);
        consolidatedPopulationInfo.add(hourArray9);
        consolidatedPopulationInfo.add(activityArray9);

        try {
          for (Future<List<int[]>> job : jobs) {
            List<int[]> thisJob = job.get();
            int indexArray = 0;
            for (int[] intArray : thisJob) {
              for (int k = 0; k < intArray.length; k++) {
                int valueAtK = intArray[k];
                consolidatedPopulationInfo.get(indexArray)[k] += valueAtK;
              }
              indexArray++;
            }
          }
        } catch (ExecutionException e) {
          e.printStackTrace();
          throw new RuntimeException("Couldn't get thread job result.");
        } catch (InterruptedException e) {
          e.printStackTrace();
          throw new RuntimeException("Couldn't get thread job result.");
        }
        consolidatedMap.put(population, consolidatedPopulationInfo);
        writeOnePopulationInfo(populationOutputFile, consolidatedPopulationInfo, population);
      }
    }
    writeAllPopulations(outputFile, consolidatedMap);

    Header.printFooter();
  }
 public static void main(String[] args) {
   Header.printHeader(GeneratePopulations.class.toString(), args);
   run(args);
   Header.printFooter();
 }