Example #1
0
  public void createLink(Point2D p1, Point2D p2) {
    final Singularity2 s1 = points.get(p1);
    final Singularity2 s2 = points.get(p2);
    if (s1 == null || s2 == null) {
      throw new IllegalArgumentException();
    }
    final Line2D.Double line = new Line2D.Double(p1, p2);

    s1.addLineSegment(line);
    s2.addLineSegment(line);
    lines.add(line);
  }
Example #2
0
  List<Neighborhood2> getShortestPathToInternal(Point2D start, Point2D end) {
    final Dijkstra dijkstra = new Dijkstra();
    if (points.containsKey(start) == false || points.containsKey(end) == false) {
      throw new IllegalArgumentException();
    }
    final Vertex vStart = dijkstra.addVertex(start);
    final Vertex vEnd = dijkstra.addVertex(end);
    final Map<Neighborhood2, Vertex> vertexes = new LinkedHashMap<Neighborhood2, Vertex>();
    for (Singularity2 s : points.values()) {
      for (Neighborhood2 n : s.getNeighborhoods()) {
        final Vertex v = dijkstra.addVertex(n);
        vertexes.put(n, v);
        if (n.getCenter().equals(start)) {
          vStart.addAdjacencies(v, 0.01);
        }
        if (n.getCenter().equals(end)) {
          v.addAdjacencies(vEnd, 0.01);
        }
      }
    }

    for (Vertex v1 : vertexes.values()) {
      for (Vertex v2 : vertexes.values()) {
        final Neighborhood2 n1 = (Neighborhood2) v1.getData();
        final Neighborhood2 n2 = (Neighborhood2) v2.getData();
        if (n1.getCenter().equals(n2.getCenter())) {
          continue;
        }
        final Line2D.Double line = new Line2D.Double(n1.getCenter(), n2.getCenter());
        if (isStrictCrossing(line)) {
          continue;
        }
        if (n1.isConnectable(n2) == false) {
          continue;
        }
        final double dist = n1.getCenter().distance(n2.getCenter());
        v1.addAdjacencies(v2, dist);
        v2.addAdjacencies(v1, dist);
        // Log.println("=(" + n1 + ") (" + n2 + ") " + dist);
      }
    }

    final List<Vertex> list = dijkstra.getShortestPathTo(vStart, vEnd);
    if (list.size() < 2) {
      throw new IllegalStateException("list=" + list);
    }
    final List<Neighborhood2> result = new ArrayList<Neighborhood2>();
    for (Vertex v : list.subList(1, list.size() - 1)) {
      result.add((Neighborhood2) v.getData());
    }
    return result;
  }