/** * create some vertices * @param count how many to create * @return the Vertices in an array */ private String[] createVertices(int count) { String[] v = new String[count]; for (int i = 0; i < count; i++) { v[i] = "V"+i; graph.addVertex(v[i]); } return v; }
@Override public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType) { this.validateEdgeType(edgeType); Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints); if (new_endpoints == null) return false; edges.put(edge, new_endpoints); V source = new_endpoints.getFirst(); V dest = new_endpoints.getSecond(); if (!containsVertex(source)) this.addVertex(source); if (!containsVertex(dest)) this.addVertex(dest); getIncoming_internal(dest).add(edge); getOutgoing_internal(source).add(edge); return true; }
@Override public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType) { this.validateEdgeType(edgeType); Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints); if (new_endpoints == null) { return false; } edges.put(edge, new_endpoints); V source = new_endpoints.getFirst(); V dest = new_endpoints.getSecond(); if (!containsVertex(source)) { this.addVertex(source); } if (!containsVertex(dest)) { this.addVertex(dest); } getIncoming_internal(dest).add(edge); getOutgoing_internal(source).add(edge); return true; }
/** simply clone this all transition and vertices in the target graph * * @param target * @return */ <G extends Grex<S, T>> Map<S, S> copyGraphInto(G target) { Map<S, S> map = new HashMap<S, S>(); for (S s : this.g.getVertices()) { S c = target.newState(); // clone map.put(s, c); // keep for transition clone target.g.addVertex(c); // append to the new graph } for (T t : this.g.getEdges()) target.g.addEdge(target.cloneTransition(t), map.get(this.g.getSource(t)), map.get(this.g.getDest(t))); return map; }
StateImplementation impl = new StateImplementation(graph, st, guideName); stateMap.put(st, impl); graph.addVertex(impl); if (st == language.start) start = impl;
/** * Create the default graph representation of a transformation graph. The * default graph is an overview without the IN- and OUT-nodes. * * @param graph * the graph to represent * @return the representation */ public static Graph<BoostedNode, String> createOverviewDirectedGraph( TransformationGraph graph) { DirectedSparseMultigraph<BoostedNode, String> result = new DirectedSparseMultigraph<>(); Set<BoostedNode> nodes = BoostedNodeUtils.getAllNodesOfGraph(graph .getRootOfGraph()); // add the nodes for (BoostedNode node : nodes) { result.addVertex(node); } // add edges between nodes for (BoostedNode node : nodes) { for (BoostedNode outPoint : node.getOutPoints()) { for (BoostedNode inPoint : node.getSuccessorInPoints(outPoint)) result.addEdge(new UID().toString(), node, inPoint .getZoomOut(null).getKey()); } // out points are sufficient, otherwise all edges would be // duplicated } return result; }