/** * create edges for this demo graph * @param v an array of Vertices to connect */ void createEdges(String[] v) { graph.addEdge(new Double(Math.random()), v[0], v[1], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[0], v[3], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[0], v[4], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[4], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[3], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[1], v[2], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[1], v[4], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[8], v[2], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[3], v[8], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[6], v[7], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[7], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[0], v[9], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[9], v[8], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[7], v[6], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[6], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[4], v[2], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[5], v[4], EdgeType.DIRECTED); }
/** * Construct a simple Grex with a single transition, and two states. * * @param t * @param src * @param target */ public Grex(T t, S src, S target) { this(); g.addEdge(t, src, target); this.in = src; this.outs.add(target); assertGraph(); }
/** copies src outbounds into dest ones. * * @param src * @param dest */ void mergeOutbounds(S src, S dest) { // copy oldout outbonds into source for (T t : g.getOutEdges(src)) { S sdest = g.getDest(t); g.addEdge(cloneTransition(t), dest, sdest); } }
/** 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; }
S mergeRaw(S s1, S s2) { S s = newState(); Set<T> incomings = new HashSet<T>(); incomings.addAll(g.getInEdges(s1)); incomings.addAll(g.getInEdges(s2)); for (T t : incomings) { S src = g.getSource(t); g.removeEdge(t); g.addEdge(t, src, s); } Set<T> outgoings = new HashSet<T>(); outgoings.addAll(g.getOutEdges(s1)); outgoings.addAll(g.getOutEdges(s2)); for (T t : outgoings) { S dest = g.getDest(t); g.removeEdge(t); g.addEdge(t, s, dest); } g.removeVertex(s1); g.removeVertex(s2); return s; }
graph.addEdge(new TransitionImplementationInstance(graph, impl, ti), srcImpl, destImpl );
/** * 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; }