예제 #1
0
 public Node split(EmbeddedGraph embeddedGraph, Edge edge) {
   Graph originalGraph = embeddedGraph.getGraph();
   Node newNode = originalGraph.createDummyNode();
   originalGraph.removeEdge(edge);
   List<Edge> newEdges = ListSequence.fromList(new ArrayList<Edge>());
   ListSequence.fromList(newEdges).addElement(originalGraph.connect(edge.getSource(), newNode));
   ListSequence.fromList(newEdges).addElement(originalGraph.connect(newNode, edge.getTarget()));
   MapSequence.fromMap(mySplittedEdges).put(edge, newEdges);
   List<Face> facesToProcess = ListSequence.fromList(new ArrayList<Face>());
   ListSequence.fromList(facesToProcess)
       .addSequence(ListSequence.fromList(embeddedGraph.getAdjacentFaces(edge)));
   for (Face face : ListSequence.fromList(facesToProcess)) {
     List<Dart> darts = face.getDarts();
     int pos = 0;
     while (ListSequence.fromList(darts).getElement(pos).getEdge() != edge) {
       pos++;
     }
     Dart dartToReplace = ListSequence.fromList(darts).getElement(pos);
     for (Edge newEdge : ListSequence.fromList(newEdges)) {
       if (ListSequence.fromList(newEdge.getAdjacentNodes()).contains(dartToReplace.getSource())) {
         embeddedGraph.setDart(face, pos, new Dart(newEdge, dartToReplace.getSource()));
       }
     }
     for (Edge newEdge : ListSequence.fromList(newEdges)) {
       if (ListSequence.fromList(newEdge.getAdjacentNodes()).contains(dartToReplace.getTarget())) {
         embeddedGraph.insertDart(face, pos + 1, new Dart(newEdge, newNode));
       }
     }
   }
   return newNode;
 }
예제 #2
0
 @Override
 protected void processEdge(Edge edge, Node source) {
   if (MapSequence.fromMap(getDfsState()).get(edge.getOpposite(source)) == Dfs.BEFORE) {
     myOuterFace.addLast(new Dart(edge, source));
   } else {
     SetSequence.fromSet(myBackEdges).addElement(edge);
   }
 }
예제 #3
0
 public void splitFace(EmbeddedGraph embeddedGraph, Face face, Edge newEdge) {
   List<Node> nodes = newEdge.getAdjacentNodes();
   Graph originalGraph = embeddedGraph.getGraph();
   List<Face> newFaces = ListSequence.fromList(new ArrayList<Face>());
   ListSequence.fromList(newFaces).addElement(new Face(originalGraph));
   ListSequence.fromList(newFaces).addElement(new Face(originalGraph));
   Iterator<Dart> dartItr = ListSequence.fromList(face.getDarts()).iterator();
   Dart cur;
   do {
     cur = dartItr.next();
   } while (!(ListSequence.fromList(nodes).contains(cur.getSource())));
   Dart first = cur;
   Node found = cur.getSource();
   Node toFind = ListSequence.fromList(nodes).getElement(0);
   if (toFind == found) {
     toFind = ListSequence.fromList(nodes).getElement(1);
   }
   do {
     ListSequence.fromList(newFaces).getElement(0).addLast(cur);
     cur = dartItr.next();
   } while (cur.getSource() != toFind);
   ListSequence.fromList(newFaces).getElement(0).addLast(new Dart(newEdge, cur.getSource()));
   ListSequence.fromList(newFaces).getElement(1).addLast(new Dart(newEdge, first.getSource()));
   ListSequence.fromList(newFaces).getElement(1).addLast(cur);
   while (dartItr.hasNext()) {
     cur = dartItr.next();
     ListSequence.fromList(newFaces).getElement(1).addLast(cur);
   }
   dartItr = ListSequence.fromList(face.getDarts()).iterator();
   cur = dartItr.next();
   while (cur != first) {
     ListSequence.fromList(newFaces).getElement(1).addLast(cur);
     cur = dartItr.next();
   }
   embeddedGraph.removeFace(face);
   for (Face newFace : ListSequence.fromList(newFaces)) {
     embeddedGraph.addFace(newFace);
   }
   if (embeddedGraph.isOuterFace(face)) {
     embeddedGraph.setOuterFace(ListSequence.fromList(newFaces).getElement(1));
   }
 }
 public static void getRepresentation(
     EmbeddedGraph embeddedGraph,
     Set<Edge> edgesToBeStraight,
     Map<Dart, Integer> bends,
     Map<Dart, Integer> angles) {
   Graph graph = embeddedGraph.getGraph();
   Graph network = new Graph();
   Node center = network.createNode();
   Map<Edge, Integer> low = MapSequence.fromMap(new HashMap<Edge, Integer>());
   Map<Edge, Integer> capacity = MapSequence.fromMap(new HashMap<Edge, Integer>());
   Map<Edge, Integer> cost = MapSequence.fromMap(new HashMap<Edge, Integer>());
   Map<Node, Node> nodeMap = MapSequence.fromMap(new HashMap<Node, Node>());
   for (Node node : ListSequence.fromList(graph.getNodes())) {
     Node networkNode = network.createNode();
     MapSequence.fromMap(nodeMap).put(node, networkNode);
     Edge edge = network.connect(center, networkNode);
     MapSequence.fromMap(low).put(edge, 4);
     MapSequence.fromMap(capacity).put(edge, MapSequence.fromMap(low).get(edge));
     MapSequence.fromMap(cost).put(edge, 0);
   }
   Map<Face, Node> faceMap = MapSequence.fromMap(new HashMap<Face, Node>());
   for (Face face : ListSequence.fromList(embeddedGraph.getFaces())) {
     Node node = network.createNode();
     MapSequence.fromMap(faceMap).put(face, node);
     Edge edge = network.connect(node, center);
     if (embeddedGraph.isOuterFace(face)) {
       MapSequence.fromMap(low).put(edge, 2 * ListSequence.fromList(face.getDarts()).count() + 4);
     } else {
       MapSequence.fromMap(low).put(edge, 2 * ListSequence.fromList(face.getDarts()).count() - 4);
     }
     MapSequence.fromMap(capacity).put(edge, MapSequence.fromMap(low).get(edge));
     MapSequence.fromMap(cost).put(edge, 0);
   }
   Map<Dart, Edge> dartBendMap = MapSequence.fromMap(new HashMap<Dart, Edge>());
   Map<Dart, Edge> dartAngleMap = MapSequence.fromMap(new HashMap<Dart, Edge>());
   for (Face face : ListSequence.fromList(embeddedGraph.getFaces())) {
     Node faceNode = MapSequence.fromMap(faceMap).get(face);
     for (Dart dart : ListSequence.fromList(face.getDarts())) {
       Edge edge = network.connect(MapSequence.fromMap(nodeMap).get(dart.getSource()), faceNode);
       MapSequence.fromMap(dartAngleMap).put(dart, edge);
       MapSequence.fromMap(low).put(edge, 1);
       MapSequence.fromMap(capacity).put(edge, 4);
       MapSequence.fromMap(cost).put(edge, 0);
       List<Face> faces = embeddedGraph.getAdjacentFaces(dart.getEdge());
       Node oppositeFaceNode;
       if (ListSequence.fromList(faces).getElement(0) == face) {
         oppositeFaceNode =
             MapSequence.fromMap(faceMap).get(ListSequence.fromList(faces).getElement(1));
       } else {
         oppositeFaceNode =
             MapSequence.fromMap(faceMap).get(ListSequence.fromList(faces).getElement(0));
       }
       edge = network.connect(faceNode, oppositeFaceNode);
       MapSequence.fromMap(dartBendMap).put(dart, edge);
       MapSequence.fromMap(low).put(edge, 0);
       if (SetSequence.fromSet(edgesToBeStraight).contains(dart.getEdge())) {
         MapSequence.fromMap(capacity).put(edge, 0);
       } else {
         MapSequence.fromMap(capacity).put(edge, Integer.MAX_VALUE / 2);
       }
       MapSequence.fromMap(cost).put(edge, 1);
     }
   }
   if (SHOW_INFO > 0) {
     System.out.println("Constructed network:");
     for (Node node : ListSequence.fromList(graph.getNodes())) {
       System.out.println("for node " + node + ": " + MapSequence.fromMap(nodeMap).get(node));
     }
     for (Face face : ListSequence.fromList(embeddedGraph.getFaces())) {
       System.out.println("for face " + face + ": " + MapSequence.fromMap(faceMap).get(face));
     }
     for (Edge edge : ListSequence.fromList(network.getEdges())) {
       System.out.println(
           "edge "
               + edge
               + ": low = "
               + MapSequence.fromMap(low).get(edge)
               + ", cap = "
               + MapSequence.fromMap(capacity).get(edge)
               + ", cost = "
               + MapSequence.fromMap(cost).get(edge));
     }
   }
   Map<Edge, Integer> circulation =
       MinCostCirculation.getCirculation(network, low, capacity, cost);
   for (Dart dart : SetSequence.fromSet(MapSequence.fromMap(dartBendMap).keySet())) {
     MapSequence.fromMap(bends)
         .put(
             dart,
             MapSequence.fromMap(circulation).get(MapSequence.fromMap(dartBendMap).get(dart)));
     MapSequence.fromMap(angles)
         .put(
             dart,
             MapSequence.fromMap(circulation).get(MapSequence.fromMap(dartAngleMap).get(dart)));
   }
   if (SHOW_INFO > 0) {
     System.out.println("bends: " + bends);
     System.out.println("angles: " + angles);
   }
 }
예제 #5
0
 @Override
 protected void postprocess(Node node, Edge from) {
   if (from != null) {
     myOuterFace.addLast(new Dart(from, node));
   }
 }