コード例 #1
0
ファイル: ModernPump.java プロジェクト: swise5/modernPump
 /**
  * Make sure the network doesn't have any problems
  *
  * @param n - the network to be tested
  */
 static void testNetworkForIssues(Network n) {
   System.out.println("testing");
   for (Object o : n.allNodes) {
     GeoNode node = (GeoNode) o;
     for (Object p : n.getEdgesOut(node)) {
       sim.field.network.Edge e = (sim.field.network.Edge) p;
       LineString ls = (LineString) ((MasonGeometry) e.info).geometry;
       Coordinate c1 = ls.getCoordinateN(0);
       Coordinate c2 = ls.getCoordinateN(ls.getNumPoints() - 1);
       GeoNode g1 = (GeoNode) e.getFrom();
       GeoNode g2 = (GeoNode) e.getTo();
       if (c1.distance(g1.geometry.getCoordinate()) > 1) System.out.println("found you");
       if (c2.distance(g2.geometry.getCoordinate()) > 1) System.out.println("found you");
     }
   }
 }
コード例 #2
0
ファイル: ModernPump.java プロジェクト: swise5/modernPump
  /**
   * Connect the GeoNode to the given subnetwork using the complete road network
   *
   * @param n - the target node
   * @param subNetwork - the existing subnetwork
   */
  void connectToMajorNetwork(GeoNode n, Network subNetwork) {

    try {
      Bag subNetNodes;
      subNetNodes = (Bag) subNetwork.allNodes.clone();

      // find a path using the whole set of roads in the environment
      AStar pathfinder = new AStar();
      ArrayList<Edge> edges = pathfinder.astarPath(n, new ArrayList<GeoNode>(subNetNodes), roads);

      if (edges == null) return; // maybe no such path exists!

      //  otherwise, add the edges into the subnetwork
      for (Edge e : edges) {
        GeoNode a = (GeoNode) e.getFrom(), b = (GeoNode) e.getTo();
        if (!subNetwork.nodeExists(a) || !subNetwork.nodeExists(b))
          subNetwork.addEdge(a, b, e.info);
      }

    } catch (CloneNotSupportedException e1) {
      e1.printStackTrace();
    }
  }