Ejemplo n.º 1
0
  @Override
  protected void initFlow(HierarchicalConfiguration flowCfg) {
    // int node = flowCfg.getInt("[@node]");

    int inLink = flowCfg.getInt("[@inLink]", -1);
    int outLink = flowCfg.getInt("[@outLink]", -1);

    // int next = flowCfg.getInt("[@next]");
    int no = flowCfg.getInt("[@no]", 0);

    Node node;
    Node next;

    if (inLink != -1) {
      Link link = idToLinkMap.get(Id.create(inLink, Link.class));

      node = link.getFromNode();
      next = link.getToNode();
    } else {
      Link link = idToLinkMap.get(Id.create(outLink, Link.class));

      node = link.getToNode();
      next = link.getFromNode();
    }

    int nodeId = Integer.parseInt(node.getId().toString());
    int nextId = Integer.parseInt(next.getId().toString());

    flows[nodeId] = new MATSimFlow(nodeId, inLink, outLink, nextId, no);
  }
Ejemplo n.º 2
0
 private Charger createCharger(Attributes atts) {
   Id<Charger> id = Id.create(atts.getValue("id"), Charger.class);
   Link link = links.get(Id.createLinkId(atts.getValue("link")));
   double power_kW = ReaderUtils.getDouble(atts, "power", DEFAULT_CHARGER_POWER_kW);
   int plugs = ReaderUtils.getInt(atts, "capacity", DEFAULT_CHARGER_CAPACITY);
   return new ChargerImpl(id, power_kW * EvUnitConversions.W_PER_kW, plugs, link);
 }
Ejemplo n.º 3
0
  public static List<ChargerLocation> createLocationsInZones(Iterable<Zone> zones, double power) {
    List<ChargerLocation> locations = new ArrayList<>();
    for (Zone z : zones) {
      locations.add(
          new ChargerLocation(Id.create(z.getId(), ChargerLocation.class), z.getCoord(), power));
    }

    return locations;
  }
  private void prepareMatrices(String statusMatrixFile) {
    wrs = new WeightedRandomSelection<Id<Zone>>();
    Matrix avestatus = MatrixUtils.readMatrices(statusMatrixFile).getMatrix("avg");

    for (Map.Entry<String, ArrayList<Entry>> fromLOR : avestatus.getFromLocations().entrySet()) {
      if (BerlinZoneUtils.isInBerlin(fromLOR.getKey())) {
        wrs.add(
            Id.create(fromLOR.getKey(), Zone.class),
            MatrixUtils.calculateTotalValue(fromLOR.getValue()));
      }
    }
  }
Ejemplo n.º 5
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(VrpConfigUtils.createConfig());
    MatsimNetworkReader nr = new MatsimNetworkReader(scenario);
    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);
    }
  }
Ejemplo n.º 6
0
 public static ChargerLocation createLocation(long id, double x, double y, double power) {
   return new ChargerLocation(Id.create(id, ChargerLocation.class), new Coord(x, y), power);
 }