예제 #1
0
 private void expandLandmarkTo() {
   LandmarksToTravelTimeComparator comparator =
       new LandmarksToTravelTimeComparator(this.nodeData, this.landmarkIdx);
   PriorityQueue<Node> pendingNodes = new PriorityQueue<>(100, comparator);
   LandmarksData role = (LandmarksData) this.nodeData.get(this.landmark);
   role.setToLandmarkTravelTime(this.landmarkIdx, 0.0);
   role.setFromLandmarkTravelTime(this.landmarkIdx, 0.0);
   pendingNodes.add(this.landmark);
   while (!pendingNodes.isEmpty()) {
     Node node = pendingNodes.poll();
     double toTravTime =
         ((LandmarksData) this.nodeData.get(node)).getToLandmarkTravelTime(this.landmarkIdx);
     LandmarksData role2;
     for (Link l : node.getInLinks().values()) {
       Node n = l.getFromNode();
       double linkTravTime = this.costFunction.getLinkMinimumTravelDisutility(l);
       role2 = (LandmarksData) this.nodeData.get(n);
       double totalTravelTime = toTravTime + linkTravTime;
       if (role2.getToLandmarkTravelTime(this.landmarkIdx) > totalTravelTime) {
         role2.setToLandmarkTravelTime(this.landmarkIdx, totalTravelTime);
         pendingNodes.add(n);
       }
     }
   }
 }
예제 #2
0
 @Override
 public void setup() {
   //        size(1800,1000);
   background(255);
   strokeWeight(16);
   textFont(createFont("Arial", 12));
   textAlign(TOP, RIGHT);
   for (Node node : network.getNodes().values()) {
     if (minX > node.getCoord().getX()) minX = (float) node.getCoord().getX();
     if (maxX < node.getCoord().getX()) maxX = (float) node.getCoord().getX();
     if (minY > node.getCoord().getY()) minY = (float) node.getCoord().getY();
     if (maxY < node.getCoord().getY()) maxY = (float) node.getCoord().getY();
   }
   for (Link link : network.getLinks().values()) {
     if (link.getCapacity() < minCap) {
       minCap = (float) link.getCapacity();
     }
     if (link.getCapacity() > maxCap) maxCap = (float) link.getCapacity();
   }
   for (Link link : network.getLinks().values()) {
     strokeWeights.put(link.getId(), map((float) link.getCapacity(), minCap, maxCap, 10f, 160f));
   }
   smooth();
   // frameRate(3);
   // ArcBall arcball = new ArcBall(this);
 }
예제 #3
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);
  }
예제 #4
0
  /** @param args */
  public static void main(String[] args) {

    String input = args[0];
    String output = args[1];

    /* Read the network. */
    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario.getNetwork()).readFile(input);

    /* Transform each node. */
    CoordinateTransformation ct =
        TransformationFactory.getCoordinateTransformation(
            TransformationFactory.WGS84, "EPSG:25832");
    //		CoordinateTransformation ct =
    // TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84,TransformationFactory.DHDN_GK4);

    //		CoordinateTransformation ct =
    // TransformationFactory.getCoordinateTransformation("EPSG:25832",TransformationFactory.WGS84);
    //		CoordinateTransformation ct =
    // TransformationFactory.getCoordinateTransformation(TransformationFactory.DHDN_GK4,TransformationFactory.WGS84);

    for (Node node : scenario.getNetwork().getNodes().values()) {
      ((Node) node).setCoord(ct.transform(node.getCoord()));
    }

    /* Write the resulting network. */
    new NetworkWriter(scenario.getNetwork()).write(output);
  }
  /**
   * writing the accessibility measures into csv file.
   *
   * <p>Design thoughs:
   *
   * <ul>
   *   <li>yyyy I am not sure why it is meaningful to use zones or nodes for the coordinates.
   *       Accessibility refers directly to coordinates, and maybe directly to zones (if averaged).
   *       --> remove eventually. kai, jul'13
   *       <ul>
   */
  @Override
  public void setZoneAccessibilities(
      ActivityFacility startZone, Node node, Map<Modes4Accessibility, Double> accessibilities) {
    // (this is what, I think, writes the urbansim data, and should thus better not be touched. kai,
    // feb'14)

    try {
      assert (accessibilityDataWriter != null);
      accessibilityDataWriter.write(
          startZone.getId().toString()
              + ","
              + startZone.getCoord().getX()
              + ","
              + startZone.getCoord().getY()
              + ","
              + node.getId()
              + ","
              + node.getCoord().getX()
              + ","
              + node.getCoord().getY());
      for (Modes4Accessibility mode : Modes4Accessibility.values()) {
        accessibilityDataWriter.write("," + accessibilities.get(mode));
      }
      accessibilityDataWriter.newLine();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
예제 #6
0
  private void assignVolumesToLinks(final NetworkImpl network) {
    computeTotalLinkCapacities(network);

    Iterator<Integer> n_it = this.fromZone.getNodes().iterator();
    while (n_it.hasNext()) {
      Integer n_i = n_it.next();
      Node node = network.getNodes().get(Id.create(n_i, Node.class));

      for (Link l : node.getOutLinks().values()) {
        if (this.totalOutLinkCapacity > 0.0) {
          this.outLinkVolumes.add(
              new MyLink(l.getId(), this.volume * l.getCapacity() / this.totalOutLinkCapacity));
        } else {
          this.outLinkVolumes.add(new MyLink(l.getId(), 0.0));
        }
      }
    }

    n_it = this.toZone.getNodes().iterator();
    while (n_it.hasNext()) {
      Integer n_i = n_it.next();
      Node node = network.getNodes().get(Id.create(n_i, Node.class));

      for (Link l : node.getInLinks().values()) {
        if (this.totalInLinkCapacity > 0.0) {
          this.inLinkVolumes.add(
              new MyLink(l.getId(), this.volume * l.getCapacity() / this.totalInLinkCapacity));
        } else {
          this.inLinkVolumes.add(new MyLink(l.getId(), 0.0));
        }
      } // for
    } // while
  } // assignVolumesToLinks
예제 #7
0
  @Override
  public void run(final Network network) {
    super.run(network);

    log.info("Putting landmarks on network...");
    long now = System.currentTimeMillis();
    landmarks = landmarker.identifyLandmarks(landmarkCount, network);
    log.info("done in " + (System.currentTimeMillis() - now) + " ms");

    log.info("Initializing landmarks data");
    for (Node node : network.getNodes().values()) {
      this.nodeData.put(node, new LandmarksData(this.landmarkCount));
    }

    int nOfThreads = this.numberOfThreads;
    if (nOfThreads > this.landmarks.length) {
      nOfThreads = this.landmarks.length;
    }
    if (nOfThreads < 2) {
      nOfThreads = 2; // always use at least two threads
    }
    log.info(
        "Calculating distance from each node to each of the "
            + this.landmarkCount
            + " landmarks using "
            + nOfThreads
            + " threads...");
    now = System.currentTimeMillis();

    ExecutorService executor = Executors.newFixedThreadPool(nOfThreads);
    for (int i = 0; i < this.landmarks.length; i++) {
      executor.execute(new Calculator(i, this.landmarks[i], this.nodeData, this.costFunction));
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
      log.info("wait for landmarks Calculator to finish...");
      try {
        executor.awaitTermination(10, TimeUnit.MINUTES);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }

    for (Node node : network.getNodes().values()) {
      LandmarksData r = getNodeData(node);
      r.updateMinMaxTravelTimes();
    }

    for (Node node : network.getNodes().values()) {
      LandmarksData r = getNodeData(node);
      for (int i = 0; i < this.landmarks.length; i++) {
        if (r.getMinLandmarkTravelTime(i) > r.getMaxLandmarkTravelTime(i)) {
          log.info("Min > max for node " + node.getId() + " and landmark " + i);
        }
      }
    }

    log.info("done in " + (System.currentTimeMillis() - now) + " ms");
  }
 /**
  * Returns the data for the given node. Creates a new NodeData if none exists yet.
  *
  * @param n The Node for which to return the data.
  * @return The data for the given Node
  */
 protected DijkstraNodeData getData(final Node n) {
   DijkstraNodeData r = this.nodeData.get(n.getId());
   if (null == r) {
     r = new DijkstraNodeData();
     this.nodeData.put(n.getId(), r);
   }
   return r;
 }
예제 #9
0
 @Override
 public int compare(final Node n1, final Node n2) {
   double c1 = getCost(n1);
   double c2 = getCost(n2);
   if (c1 < c2) return -1;
   if (c1 > c2) return +1;
   return n1.getId().compareTo(n2.getId());
 }
예제 #10
0
  // Create external Facilities that are used by transit traffic agents.
  private static void createExternalFacilities(Scenario scenario, Set<Id<Node>> externalNodes) {

    ActivityFacilities activityFacilities = scenario.getActivityFacilities();
    ActivityFacilitiesFactory factory = activityFacilities.getFactory();

    /*
     * We check for all OutLinks of all external nodes if they already host a facility. If not,
     * a new facility with a tta ActivityOption will be created and added.
     */
    for (Id<Node> id : externalNodes) {
      Node externalNode = scenario.getNetwork().getNodes().get(id);

      for (Link externalLink : externalNode.getOutLinks().values()) {
        ActivityFacility facility = activityFacilities.getFacilities().get(externalLink.getId());

        // if already a facility exists we have nothing left to do
        if (facility != null) continue;

        /*
         * No Facility exists at that link therefore we create and add a new one.
         */
        double fromX = externalLink.getFromNode().getCoord().getX();
        double fromY = externalLink.getFromNode().getCoord().getY();
        double toX = externalLink.getToNode().getCoord().getX();
        double toY = externalLink.getToNode().getCoord().getY();

        double dX = toX - fromX;
        double dY = toY - fromY;

        double length = Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2));

        double centerX = externalLink.getCoord().getX();
        double centerY = externalLink.getCoord().getY();

        /*
         * Unit vector that directs with an angle of 90° away from the link.
         */
        double unitVectorX = dY / length;
        double unitVectorY = -dX / length;

        Coord coord = new Coord(centerX + unitVectorX, centerY + unitVectorY);

        facility =
            activityFacilities
                .getFactory()
                .createActivityFacility(
                    Id.create(externalLink.getId().toString(), ActivityFacility.class), coord);
        activityFacilities.addActivityFacility(facility);
        ((ActivityFacilityImpl) facility).setLinkId(externalLink.getId());

        ActivityOption activityOption = factory.createActivityOption(ttaActivityType);
        activityOption.addOpeningTime(new OpeningTimeImpl(0 * 3600, 24 * 3600));
        activityOption.setCapacity(capacity);
        facility.addActivityOption(activityOption);
      }
    }
  }
예제 #11
0
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    String networkPath = args[0];
    String newNetworkPath = args[1];
    String shapeFilePath = args[2];

    // String shapeFile = "C:/Work/Roadpricing Scenarios/SiouxFalls/Network/SiouxFalls_nodes.shp";

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

    new NetworkReaderMatsimV1(scenario).parse(networkPath);
    Network network = scenario.getNetwork();
    Map<Id<Node>, ? extends Node> nodes = network.getNodes();

    Double x = 0.0;
    Double y = 0.0;

    System.out.println(shapeFilePath);
    ShapeFileReader shapeFileReader = new ShapeFileReader();
    Collection<SimpleFeature> fts = shapeFileReader.readFileAndInitialize(shapeFilePath);
    log.info("Shape file contains " + fts.size() + " features!");

    for (SimpleFeature ft : fts) {
      Geometry geo = (Geometry) ft.getDefaultGeometry();
      Coordinate[] coordinates = geo.getCoordinates();
      Collection<Property> properties = ft.getProperties("Id");

      System.out.println(
          "Feature: "
              + ft.getID()
              + ","
              + ft.getIdentifier().toString()
              + ","
              + ft.getName().toString());

      for (int i = 0; i < coordinates.length; i++) {
        System.out.print(coordinates[i].x + "," + coordinates[i].y + "   ");
        x = coordinates[i].x;
        y = coordinates[i].y;
      }

      for (Property p : properties) {
        System.out.println("Value: " + p.getValue().toString());
        Node node = nodes.get(Id.create(p.getValue().toString(), Node.class));
        node.getCoord().setXY(x, y);
        System.out.println("Name: " + p.getName().toString());
        System.out.println("Descriptor: " + p.getDescriptor().toString());
      }
      System.out.println();
      System.out.println();

      NetworkWriter writer = new NetworkWriter(network);
      writer.write(newNetworkPath);
    }
  }
예제 #12
0
  private Coord centerOfMass(Collection<Node> nodes) {
    double xsum = 0;
    double ysum = 0;

    for (Node node : nodes) {
      xsum += node.getCoord().getX();
      ysum += node.getCoord().getY();
    }

    double n = nodes.size();
    return new Coord(xsum / n, ysum / n);
  }
예제 #13
0
 public void run() {
   for (Node n : this.sc.getNetwork().getNodes().values()) {
     CoordImpl c = (CoordImpl) n.getCoord();
     Coordinate cc = new Coordinate(c.getX(), c.getY());
     try {
       JTS.transform(cc, cc, transform);
     } catch (TransformException e) {
       e.printStackTrace();
     }
     c.setXY(cc.x, cc.y);
   }
 }
예제 #14
0
 public void add() {
   List<Link> links = ((BusLaneAdderPanel) layersPanels.get(PanelIds.ONE)).getLinks();
   Node prevNode = links.get(0).getFromNode();
   for (Link link : links)
     if (!link.getAllowedModes().contains("bus")) {
       exitSave();
       JOptionPane.showMessageDialog(this, "Wrong path, network saved");
     }
   for (int i = 0; i < links.size(); i++) {
     Link link = links.get(i);
     Node node = null;
     if (link.getNumberOfLanes() == 1) {
       Set<String> modes = new HashSet<String>();
       modes.add("bus");
       link.setAllowedModes(modes);
       node = link.getToNode();
     } else {
       Node oldNode = link.getToNode();
       if (i == links.size() - 1 || oldNode.getInLinks().size() + oldNode.getOutLinks().size() > 2)
         node = oldNode;
       else {
         node =
             network
                 .getFactory()
                 .createNode(
                     Id.createNodeId("fl" + oldNode.getId().toString()), oldNode.getCoord());
         network.addNode(node);
       }
       LinkImpl newLink =
           (LinkImpl)
               network
                   .getFactory()
                   .createLink(Id.createLinkId("fl" + link.getId().toString()), prevNode, node);
       Set<String> modes = new HashSet<String>();
       modes.add("car");
       newLink.setAllowedModes(modes);
       newLink.setCapacity(link.getCapacity());
       newLink.setFreespeed(link.getFreespeed());
       newLink.setLength(link.getLength());
       newLink.setNumberOfLanes(link.getNumberOfLanes() - 1);
       newLink.setOrigId(((LinkImpl) link).getOrigId());
       newLink.setType(((LinkImpl) link).getType());
       network.addLink(newLink);
       Set<String> modes2 = new HashSet<String>();
       modes2.add("bus");
       link.setAllowedModes(modes2);
       link.setCapacity(900);
       link.setNumberOfLanes(1);
     }
     prevNode = node;
   }
   ((BusLaneAdderPanel) layersPanels.get(PanelIds.ONE)).clearSelection();
 }
예제 #15
0
  public void convertCoordinates(Network net, String outputFile) {

    CoordinateTransformation ct =
        TransformationFactory.getCoordinateTransformation(
            "EPSG:32719", TransformationFactory.WGS84);

    for (Node node : net.getNodes().values()) {
      Coord newCoord = ct.transform(node.getCoord());
      ((NodeImpl) node).setCoord(newCoord);
    }

    new NetworkWriter(net).write(outputFile);
  }
예제 #16
0
 public Node getNearestNode(double x, double y) {
   Coord point = new Coord(x, y);
   Node nearest = links.get(0).getFromNode();
   double nearestDistance = CoordUtils.calcEuclideanDistance(point, nearest.getCoord());
   for (Link link : links) {
     double distance = CoordUtils.calcEuclideanDistance(point, link.getToNode().getCoord());
     if (distance < nearestDistance) {
       nearestDistance = distance;
       nearest = link.getToNode();
     }
   }
   return nearest;
 }
예제 #17
0
 public void addLinkNetwork(Node fromNode, Node toNode) {
   Id<Link> linkId = Id.create(network.getLinks().size() * 2, Link.class);
   network.addLink(network.getFactory().createLink(linkId, fromNode, toNode));
   try {
     PrintWriter writer =
         new PrintWriter(new FileWriter(RoutesPathsGenerator.NEW_NETWORK_LINKS_FILE, true));
     writer.println(linkId);
     writer.println(fromNode.getId());
     writer.println(toNode.getId());
     writer.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #18
0
 private Link getNewLink(Node fromNode, Node toNode) {
   Link link =
       networkFactory.createLink(
           Id.create(prefix + linkIdCounter++, Link.class), fromNode, toNode);
   if (fromNode == toNode) {
     link.setLength(50);
   } else {
     link.setLength(CoordUtils.calcDistance(fromNode.getCoord(), toNode.getCoord()));
   }
   link.setFreespeed(80.0 / 3.6);
   link.setCapacity(10000);
   link.setNumberOfLanes(1);
   link.setAllowedModes(this.transitModes);
   return link;
 }
예제 #19
0
  /*package*/ void addConnectorLinks() {

    QuadTree<Node> quadTree = getNodesQuadTree();
    NetworkFactory factory = network.getFactory();

    /*
     * Try to use the centroid of the polygon. If that does not lie within
     * the polygon, use an interior point.
     */
    for (Entry<Integer, SimpleFeature> entry : zonesMap.entrySet()) {
      int zoneId = entry.getKey();
      SimpleFeature zone = entry.getValue();

      if (SpecialZones.skipZone(zone)) continue;

      Geometry polygon = (Geometry) zone.getDefaultGeometry();
      Point point = polygon.getCentroid();
      if (!polygon.contains(point)) point = polygon.getInteriorPoint();

      /*
       * Convert coordinate from WGS84 to EPSG:28992 (Netherlands Projection)
       */
      Coord wgs84Coord = new Coord(point.getCoordinate().x, point.getCoordinate().y);
      Coord nodeCoord = ct.transform(wgs84Coord);

      Id<Node> nodeId = Id.create(String.valueOf(zoneId), Node.class);
      network.addNode(factory.createNode(nodeId, nodeCoord));

      Node networkConnectorNode = quadTree.getClosest(nodeCoord.getX(), nodeCoord.getY());
      Id<Node> networkConnectorNodeId = networkConnectorNode.getId();

      double length = CoordUtils.calcDistance(nodeCoord, networkConnectorNode.getCoord());

      Id<Link> linkFromId = Id.create(String.valueOf(zoneId) + "from", Link.class);
      Link fromLink = factory.createLink(linkFromId, nodeId, networkConnectorNodeId);
      fromLink.setLength(length);
      fromLink.setCapacity(this.connectorCapacity);
      fromLink.setFreespeed(this.connectorLinkFreeSpeed);
      network.addLink(fromLink);

      Id<Link> linkToId = Id.create(String.valueOf(zoneId) + "to", Link.class);
      Link toLink = factory.createLink(linkToId, networkConnectorNodeId, nodeId);
      toLink.setLength(length);
      toLink.setCapacity(this.connectorCapacity);
      toLink.setFreespeed(this.connectorLinkFreeSpeed);
      network.addLink(toLink);
    }
  }
예제 #20
0
    @Override
    public int compare(final Node n1, final Node n2) {

      double c1 =
          ((LandmarksData) this.roleData.get(n1)).getFromLandmarkTravelTime(this.landmarkIndex);
      double c2 =
          ((LandmarksData) this.roleData.get(n2)).getFromLandmarkTravelTime(this.landmarkIndex);

      if (c1 < c2) {
        return -1;
      }
      if (c1 > c2) {
        return +1;
      }
      return n1.getId().compareTo(n2.getId());
    }
예제 #21
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);
  }
예제 #22
0
 public Node createNode(double x, double y) {
   Node node =
       network
           .getFactory()
           .createNode(Id.create("n" + network.getNodes().size(), Node.class), new Coord(x, y));
   network.addNode(node);
   try {
     PrintWriter writer =
         new PrintWriter(new FileWriter(RoutesPathsGenerator.NEW_NETWORK_NODES_FILE, true));
     writer.println(node.getId());
     writer.println(node.getCoord().getX());
     writer.println(node.getCoord().getY());
     writer.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return node;
 }
예제 #23
0
  public void createDilutedPlans(
      final Coord center, final double radius, final String fromFile, final String toFile) {
    final Map<Id<Link>, Link> areaOfInterest = new HashMap<>();

    Network network = this.scenario.getNetwork();

    log.info("extracting aoi:");
    log.info("  center: " + center.getX() + " / " + center.getY());
    log.info("  radius: " + radius);
    for (Link link : network.getLinks().values()) {
      final Node from = link.getFromNode();
      final Node to = link.getToNode();
      if ((CoordUtils.calcDistance(from.getCoord(), center) <= radius)
          || (CoordUtils.calcDistance(to.getCoord(), center) <= radius)) {
        System.out.println("    link " + link.getId().toString());
        areaOfInterest.put(link.getId(), link);
      }
    }
    log.info("  # links in aoi: " + areaOfInterest.size());

    log.info("creating diluted dpopulation:");
    log.info("  input-file:  " + fromFile);
    log.info("  output-file: " + toFile);
    PopulationImpl pop =
        (PopulationImpl)
            ((MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()))
                .getPopulation();
    pop.setIsStreaming(true);

    PopulationWriter writer = new PopulationWriter(pop, this.scenario.getNetwork());
    writer.startStreaming(toFile);

    final PersonIntersectAreaFilter filter =
        new PersonIntersectAreaFilter(writer, areaOfInterest, network);
    filter.setAlternativeAOI(center, radius);
    pop.addAlgorithm(filter);

    new MatsimPopulationReader(new PseudoScenario(this.scenario, pop)).readFile(fromFile);

    writer.closeStreaming();

    pop.printPlansCount();
    log.info("persons in output: " + filter.getCount());
  }
  /**
   * Expands the given Node in the routing algorithm; may be overridden in sub-classes.
   *
   * @param outNode The Node to be expanded.
   * @param toNode The target Node of the route.
   * @param pendingNodes The set of pending nodes so far.
   */
  protected void relaxNode(
      final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) {

    DijkstraNodeData outData = getData(outNode);
    double currTime = outData.getTime();
    double currCost = outData.getCost();
    for (Link l : outNode.getOutLinks().values()) {
      relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, null);
    }
  }
  public GeoPosition getNetworkCenter() {
    if (this.networkCenter != null) {
      return this.networkCenter;
    }
    Envelope e = new Envelope();
    for (Node node : this.sc.getNetwork().getNodes().values()) {

      // ignore end nodes
      if (node.getId().toString().contains("en")) continue;

      e.expandToInclude(MGC.coord2Coordinate(node.getCoord()));
    }
    Coord centerC = new CoordImpl((e.getMaxX() + e.getMinX()) / 2, (e.getMaxY() + e.getMinY()) / 2);
    CoordinateTransformation ct2 =
        new GeotoolsTransformation(this.sc.getConfig().global().getCoordinateSystem(), "EPSG:4326");
    centerC = ct2.transform(centerC);
    this.networkCenter = new GeoPosition(centerC.getY(), centerC.getX());

    return this.networkCenter;
  }
예제 #26
0
  private void initMappings(ZoneCollection zones, String zoneIdKey) {
    node2Zone = new ConcurrentHashMap<>();
    zone2Node = new ConcurrentHashMap<>();

    for (Node node : network.getNodes().values()) {
      Coordinate c = new Coordinate(node.getCoord().getX(), node.getCoord().getY());
      Zone zone = zones.get(c);
      if (zone != null) {
        String id = zone.getAttribute(zoneIdKey);
        node2Zone.put(node.getId(), id);

        Collection<Node> nodes = zone2Node.get(id);
        if (nodes == null) {
          nodes = new HashSet<>();
          zone2Node.put(id, nodes);
        }
        nodes.add(node);
      }
    }
  }
예제 #27
0
 NodeClusteringAlgorithm(
     String algorithmName,
     Network network,
     String linkMethodName,
     String[] argTypes,
     Object[] args) {
   this.flowValues = new ArrayList<>();
   this.internalFlowMethodParameterTypes = argTypes;
   this.internalFlowMethod = getLinkGetMethodWithArgTypes(linkMethodName, argTypes);
   NodeCluster.linkMethod = internalFlowMethod;
   NodeCluster.args = args;
   this.internalFlowMethodParameters = args;
   if (argTypes != null || args != null)
     logger.info("Using args " + internalFlowMethodParameters.toString());
   logger = Logger.getLogger("NodeClusterer");
   this.network = network;
   links = new LinkedHashMap<>(network.getLinks().size());
   for (Link l : network.getLinks().values()) {
     links.put(l.getId(), new ClusterLink((Link) l));
   }
   setNodes(new LinkedHashMap<Id, ClusterNode>(network.getNodes().size()));
   leafNodeClusters = new TreeMap<>();
   int i = 0;
   for (Node n : network.getNodes().values()) {
     getNodes().put(n.getId(), new ClusterNode((Node) n));
     leafNodeClusters.put(
         i,
         new NodeCluster(
             getNodes().get(n.getId()),
             this,
             0,
             i,
             internalFlowMethod,
             internalFlowMethodParameters));
     i++;
   }
   this.pointersToClusterLevels = new TreeMap<>();
   this.pointersToClusterLevels.put(0, new ArrayList<>(leafNodeClusters.values()));
   this.setAlgorithmName(algorithmName);
 }
예제 #28
0
  public static void main(String[] args) {

    //		Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    //		NetworkImpl network = (NetworkImpl) scenario.getNetwork();
    //		CoordinateTransformation ct =
    //
    //	TransformationFactory.getCoordinateTransformation(TransformationFactory.GK4,TransformationFactory.WGS84);
    //		OsmNetworkReader reader = new OsmNetworkReader(scenario.getNetwork(), ct);
    //		reader.parse("C:/Users/Tille/WORK/Cottbus/Cottbus-pt/Demand_input/network_pt_cap60.xml");
    //
    //		NetworkWriter writer = new NetworkWriter(scenario.getNetwork());
    //		writer.write("C:/Users/Tille/WORK/Cottbus/Cottbus-pt/Demand_input/transformiert.xml");
    //

    String input = "C:/Users/Tille/WORK/Cottbus/Cottbus-pt/Demand_input/bearbeitetWGS84.xml";
    String output = "C:/Users/Tille/WORK/Cottbus/Cottbus-pt/Demand_input/RUECKtransformiert.xml";

    /* Read the network. */
    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario.getNetwork()).readFile(input);

    /* Transform each node. */
    CoordinateTransformation ct =
        TransformationFactory.getCoordinateTransformation(
            TransformationFactory.WGS84, "EPSG:25833");
    //		CoordinateTransformation ct =
    // TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84,TransformationFactory.DHDN_GK4);

    //		CoordinateTransformation ct =
    // TransformationFactory.getCoordinateTransformation("EPSG:25833",TransformationFactory.WGS84);
    //		CoordinateTransformation ct =
    // TransformationFactory.getCoordinateTransformation(TransformationFactory.DHDN_GK4,TransformationFactory.WGS84);

    for (Node node : scenario.getNetwork().getNodes().values()) {
      ((Node) node).setCoord(ct.transform(node.getCoord()));
    }

    /* Write the resulting network. */
    new NetworkWriter(scenario.getNetwork()).write(output);
  }
예제 #29
0
  private void decomposePassPaths(Map<Link, Set<Path>> routes, MLCell j) {
    Network network = optimContext.network;
    Map<Id<Node>, ? extends Node> nodenetwork = network.getNodes();
    ArrayList<MLArray> paths = j.cells();
    for (MLArray path : paths) {
      MLCell cellpath = (MLCell) path;
      if (path.getM() != 0) {
        List<Node> nodelist = new ArrayList<Node>();
        List<Link> linklist = new ArrayList<Link>();
        MLDouble route = (MLDouble) (cellpath.get(0));
        double[][] nodes = route.getArray();
        for (int i = 0; i < nodes.length - 1; i++) {
          int currnode = (int) nodes[i][0];
          int nextnode = (int) nodes[i + 1][0];
          Node start = nodenetwork.get(Id.createNodeId(Integer.toString(currnode)));
          Node finish = nodenetwork.get(Id.createNodeId(Integer.toString(nextnode)));
          nodelist.add(start);
          Collection<? extends Link> possiblelinks = start.getOutLinks().values();
          for (Link l : possiblelinks) {
            if (l.getToNode().equals(finish)) {
              linklist.add(l);
              break;
            }
          }
          if (i == nodes.length - 2) {
            nodelist.add(finish);
          }

          Path temppath = convertNodeListtoPath(nodelist, linklist);
          if (routes.get(linklist.get(0)) == null) { // add path to routelist
            routes.put(linklist.get(0), new HashSet<Path>());
          }
          routes.get(linklist.get(0)).add(temppath);
        }
      }
    }
  }
예제 #30
0
  // iterate over all nodes to find all external nodes
  private static final Set<Id<Node>> getExternalNodes(
      Scenario scenario, Map<Integer, SimpleFeature> zonalShapes) {

    Set<Id<Node>> externalNodes = new TreeSet<Id<Node>>();
    for (Node node : scenario.getNetwork().getNodes().values()) {
      Coord pointCoord = toWGS84CoordinateTransformation.transform(node.getCoord());
      Point point =
          geometryFactory.createPoint(new Coordinate(pointCoord.getX(), pointCoord.getY()));

      SimpleFeature pointZone = null;
      for (SimpleFeature zone : zonalShapes.values()) {
        Geometry polygon = (Geometry) zone.getDefaultGeometry();
        if (polygon.contains(point)) {
          pointZone = zone;
          break;
        }
      }

      // if the point is not contained in any Zone it is an external node.
      if (pointZone == null) externalNodes.add(node.getId());
    }

    return externalNodes;
  }