@Override public Object clone() { DirectedGraph<V, E> copy = new DirectedGraph<V, E>(); copy.addGraph(this); return copy; } }
public void addEdge(V soure, V target) { addEdge(soure, target, null, 0, true); }
public List<V> topologicalSort(boolean readOnly) { DirectedGraph<V, E> graph = (!readOnly) ? this : (DirectedGraph<V, E>)clone(); List<V> list = new ArrayList<V>(); while (true) { Vertex v = graph.getFirst(); if (v == null) { break; } list.add(v.getValue()); graph.removeVertex(v); } return list; }
Vertex source = getVertex(sourceValue); if (source == null) { return null; Vertex target = getVertex(targetValue); if (target == null) { return null; Edge direct = getEdge(source, target); path = new Path(); if (direct != null) { Node nextNode = null; while (!otherNodes.isEmpty()) { nextNode = extractMin(otherNodes); if (nextNode.vertex == target) { path = getPath(nextNode);
public void addEdge(V source, V target, E edgeValue, int weight, boolean publicEdge) { // Fix for TUSCANY-3456 // First check if we already has an edge Edge edge = getEdge(source, target); if (edge != null) { // An existing edge has higher weight, let's replace it if (edge.weight > weight) { logger.fine("An edge exists with higher weight: " + edge); removeEdge(edge); } else { // Don't add this edge logger.fine("An edge exists with lower weight: " + edge); return; } } Vertex s = getVertex(source); if (s == null) { s = new Vertex(source); vertices.put(source, s); } Vertex t = getVertex(target); if (t == null) { t = new Vertex(target); vertices.put(target, t); } edge = new Edge(s, t, edgeValue, weight, publicEdge); s.outEdges.put(t, edge); t.inEdges.put(s, edge); }
public List<Transformer> getTransformerChain(String sourceType, String resultType) { loadTransformers(); String source = sourceType; String result = resultType; List<Transformer> transformers = new ArrayList<Transformer>(); // First check if there is a direct path, if yes, use it regardless of the weight DirectedGraph<Object, Transformer>.Edge link = graph.getEdge(sourceType, resultType); if (link != null) { transformers.add(link.getValue()); } else { DirectedGraph<Object, Transformer>.Path path = graph.getShortestPath(source, result); if (path == null) { return null; } for (DirectedGraph<Object, Transformer>.Edge edge : path.getEdges()) { transformers.add(edge.getValue()); } } return transformers; }
public Transformer getTransformer(String sourceType, String resultType) { loadTransformers(); DirectedGraph<Object, Transformer>.Edge edge = graph.getEdge(sourceType, resultType); return (edge == null) ? null : edge.getValue(); }
Vertex source = getVertex(sourceValue); if (source == null) { return null; Vertex target = getVertex(targetValue); if (target == null) { return null; Edge direct = getEdge(source, target); path = new Path(); if (direct != null) { Node nextNode = null; while (!otherNodes.isEmpty()) { nextNode = extractMin(otherNodes); if (nextNode.vertex == target) { path = getPath(nextNode);
public void addEdge(V source, V target, E edgeValue, int weight, boolean publicEdge) { // Fix for TUSCANY-3456 // First check if we already has an edge Edge edge = getEdge(source, target); if (edge != null) { // An existing edge has higher weight, let's replace it if (edge.weight > weight) { logger.fine("An edge exists with higher weight: " + edge); removeEdge(edge); } else { // Don't add this edge logger.fine("An edge exists with lower weight: " + edge); return; } } Vertex s = getVertex(source); if (s == null) { s = new Vertex(source); vertices.put(source, s); } Vertex t = getVertex(target); if (t == null) { t = new Vertex(target); vertices.put(target, t); } edge = new Edge(s, t, edgeValue, weight, publicEdge); s.outEdges.put(t, edge); t.inEdges.put(s, edge); }
public List<Transformer> getTransformerChain(String sourceType, String resultType) { loadTransformers(); String source = sourceType; String result = resultType; List<Transformer> transformers = new ArrayList<Transformer>(); // First check if there is a direct path, if yes, use it regardless of the weight DirectedGraph<Object, Transformer>.Edge link = graph.getEdge(sourceType, resultType); if (link != null) { transformers.add(link.getValue()); } else { DirectedGraph<Object, Transformer>.Path path = graph.getShortestPath(source, result); if (path == null) { return null; } for (DirectedGraph<Object, Transformer>.Edge edge : path.getEdges()) { transformers.add(edge.getValue()); } } return transformers; }
private Path getPath(Node t) { if (t.distance == Integer.MAX_VALUE) { return NULL_PATH; } Path path = new Path(); Node u = t; while (u.previous != null) { Edge edge = getEdge(u.previous.vertex, u.vertex); path.addEdge(edge); u = u.previous; } return path; }
public List<V> topologicalSort(boolean readOnly) { DirectedGraph<V, E> graph = (!readOnly) ? this : (DirectedGraph<V, E>)clone(); List<V> list = new ArrayList<V>(); while (true) { Vertex v = graph.getFirst(); if (v == null) { break; } list.add(v.getValue()); graph.removeVertex(v); } return list; }
@Override public Object clone() { DirectedGraph<V, E> copy = new DirectedGraph<V, E>(); copy.addGraph(this); return copy; } }
public void addEdge(V soure, V target) { addEdge(soure, target, null, 0, true); }
private Path getPath(Node t) { if (t.distance == Integer.MAX_VALUE) { return NULL_PATH; } Path path = new Path(); Node u = t; while (u.previous != null) { Edge edge = getEdge(u.previous.vertex, u.vertex); path.addEdge(edge); u = u.previous; } return path; }
public void addGraph(DirectedGraph<V, E> otherGraph) { for (Vertex v : otherGraph.vertices.values()) { for (Edge e : v.outEdges.values()) { addEdge(e.sourceVertex.value, e.targetVertex.value, e.value, e.weight, true); } } }