本文整理汇总了Java中org.jgrapht.graph.DirectedMultigraph类的典型用法代码示例。如果您正苦于以下问题:Java DirectedMultigraph类的具体用法?Java DirectedMultigraph怎么用?Java DirectedMultigraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectedMultigraph类属于org.jgrapht.graph包,在下文中一共展示了DirectedMultigraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: approximateSteinerTree
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
/**
* Computes an approximation of a directed minimum steiner tree.
* @param graph The graph of which the minimum steiner tree should be computed
* @param startVertex The vertex at which the directed minimum steiner tree should be rooted.
* @param vertices A set of vertices that should be included in the minimum steiner tree.
* @return A tree representation of the computed tree.
*/
public static <V, E> Tree<V> approximateSteinerTree(DirectedWeightedPseudograph<V, E> graph, V startVertex, Set<V> vertices) {
// 1. Construct the metric closure for the given set of vertices.
DirectedWeightedPseudograph<V, MetricClosureEdge<V>> metricClosure = createMetricClosure(graph, vertices);
// 2. Compute the edges that compose an aborescence of the metric closure (aka. directed minimum spanning tree).
Set<MetricClosureEdge<V>> arborescenceEdges = minimumArborescenceEdges(metricClosure, startVertex);
// 3. Reduce the metric closure by removing all edges not computed before.
metricClosure.removeAllEdges(inverseEdgeSet(metricClosure, arborescenceEdges));
// 4. Reconstruct a graph containing all vertices of the original graph.
DirectedMultigraph<V, DefaultEdge> steinerTreeGraphApproximation = reconstructGraphFromMetricClosure(metricClosure);
// 5. Construct a tree representation.
Tree<V> steinerTree = constructSteinerTreeApproximation(startVertex, steinerTreeGraphApproximation);
return steinerTree;
}
示例2: reconstructGraphFromMetricClosure
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
/**
* Reconstructs the original graph from a metric closure (i.e. a graph that contains all vertices that were used in the edges of the metric closure).
* @param metricClosure a metric closure
* @return The reconstructed graph
*/
public static <T> DirectedMultigraph<T, DefaultEdge> reconstructGraphFromMetricClosure(DirectedWeightedPseudograph<T, MetricClosureEdge<T>> metricClosure) {
DirectedMultigraph<T, DefaultEdge> reconstructedGraph = new DirectedMultigraph<>(DefaultEdge.class);
for (MetricClosureEdge<T> edge : metricClosure.edgeSet()) {
T previousVertex = metricClosure.getEdgeSource(edge);
T endVertex = metricClosure.getEdgeTarget(edge);
reconstructedGraph.addVertex(previousVertex);
reconstructedGraph.addVertex(endVertex);
for (T subedge : edge.path) {
if (reconstructedGraph.addVertex(subedge)) {
reconstructedGraph.addEdge(previousVertex, subedge);
}
previousVertex = subedge;
}
reconstructedGraph.addEdge(previousVertex, endVertex);
}
return reconstructedGraph;
}
示例3: toSubgraph
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
/**
* Creates the subgraph of g1 containing all the edges from the edge product in the vertices of this EdgeProductGraph
* @param edgeProductVertices if (and only if) these vertices induce a complete subgraph in this EdgeProductGraph, then the result
* will be the a common subgraph of g1 and g2.
* @return a subgraph of g1
*/
public Graph<V,E> toSubgraph(Set<EdgeProduct<E>> edgeProductVertices){
Graph<V,E> result;
if(g1 instanceof DirectedGraph){
result = new DirectedMultigraph<V,E>(g1.getEdgeFactory());
} else {
result = new Multigraph<V,E>(g1.getEdgeFactory());
}
//Add the left Edge (including vertices) from all the EdgeProducts in vertices
for(EdgeProduct<E> ep: edgeProductVertices){
E edge = ep.getLeft();
V vSource = g1.getEdgeSource(edge);
V vTarget = g1.getEdgeTarget(edge);
result.addVertex(vSource);
result.addVertex(vTarget);
result.addEdge(vSource, vTarget, edge);
}
return result;
}
示例4: createGraph
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
private DirectedMultigraph<String, String> createGraph() throws IOException {
DirectedMultigraph<String, String> graph = new DirectedMultigraph<String, String>(new UnsupportedEdgeFactory<String, String>());
ObjectProducer<String, String> objectProducer = new ObjectProducer<String, String>() {
@Override
public String createEdge(String source, String target, String edgeLabel) {
return source + "-->" + target + ":" + edgeLabel;
}
@Override
public String createVertex(String vertexLabel) {
return vertexLabel;
}
};
new SimpleGraphReader<String, String>(graph, objectProducer).readGraph(new StringReader(GRAPH_CONTENT));
return graph;
}
示例5: testCutCycles
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
@Test
public void testCutCycles() throws IOException {
DirectedPseudograph<String, String> source = createGraph();
DirectedGraph<String, String> target = new DirectedMultigraph<>(new UnsupportedEdgeFactory<String, String>());
target = new MinimumEdgesCycleCut<String, String>(source, target).cutCycles();
assertTrue(source.edgeSet().contains("a-->b:ab1"));
assertFalse(target.edgeSet().contains("a-->b:ab1"));
assertTrue(source.edgeSet().contains("e-->b:eb1"));
assertFalse(target.edgeSet().contains("e-->b:eb1"));
assertTrue(source.edgeSet().contains("x-->y:xy1"));
assertFalse(target.edgeSet().contains("x-->y:xy1"));
assertTrue(source.edgeSet().contains("v-->v:vv1"));
assertTrue(source.edgeSet().contains("v-->v:vv2"));
assertFalse(target.edgeSet().contains("v-->v:vv1"));
assertFalse(target.edgeSet().contains("v-->v:vv2"));
}
示例6: getGraphByTask
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
/**
* Helper methods
*/
private DirectedMultigraph<TaskDefinition, Edge> getGraphByTask(Program prog, Vector<DirectedMultigraph<TaskDefinition, Edge>> task_graphs, String task) {
for (int i = 0; i < task_graphs.size(); i++) {
if(task_graphs.get(i).containsVertex(prog.getTaskDefinition(task)) == true) {
return task_graphs.get(i);
}
}
return null;
}
示例7: TaskGraph
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
public TaskGraph(DirectedMultigraph<TaskDefinition, Edge> graph, Vector<Flow> all_flows) {
this.graph = graph;
this.all_flows = all_flows;
this.sinks = new Vector<TaskDefinition>();
this.sorted = new Vector<TaskDefinition>();
this.priority = 100;
// Process graph for useful info to put in the template
getSinksAndSource();
sortTasks();
determineGraphPriority();
}
示例8: copyGraph
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
/**
* Shallow-copy the graph from origGraph to this.
* Does NOT remove anything from this graph, or alter origGraph
*
* @param origGraph
*/
private void copyGraph(DirectedMultigraph<Node, Node> origGraph) {
for (Node sourceV : origGraph.vertexSet()) {
this.addVertex(sourceV);
for (Node edge : origGraph.outgoingEdgesOf(sourceV)) {
Node targetV = origGraph.getEdgeTarget(edge);
if (!this.containsVertex(targetV)) {
this.addVertex(targetV);
}
this.addEdge(sourceV, targetV, edge);
}
}
}
示例9: addSuperclass
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
public void addSuperclass(String className, String superName, int access) {
String classNameWithDots = ResourceList.getClassNameFromResourcePath(className);
String superNameWithDots = ResourceList.getClassNameFromResourcePath(superName);
if (inheritanceGraph == null) {
inheritanceGraph = new DirectedMultigraph<>(
DefaultEdge.class);
}
inheritanceGraph.addVertex(classNameWithDots);
inheritanceGraph.addVertex(superNameWithDots);
inheritanceGraph.addEdge(superNameWithDots, classNameWithDots);
}
示例10: getHostNode
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
protected NodeTemplate getHostNode(DirectedMultigraph<NodeTemplate, RelationshipTemplate> graph,
NodeTemplate taskNode) {
return graph
.incomingEdgesOf(taskNode)
.stream()
.filter(
relationship -> HOST_CAPABILITY_NAME.equals(relationship.getTargetedCapabilityName()))
.map(graph::getEdgeSource)
// if more than 1 node is present -> IllegalArgumentException
.collect(MoreCollectors.toOptional())
.orElseThrow(() -> new IllegalArgumentException(
String.format("No hosting node provided for node <%s>", taskNode.getName())));
}
示例11: getParentNodes
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
protected List<NodeTemplate> getParentNodes(String parentCapabilityName,
DirectedMultigraph<NodeTemplate, RelationshipTemplate> graph,
NodeTemplate taskNode) {
return graph
.incomingEdgesOf(taskNode)
.stream()
.filter(
relationship -> parentCapabilityName.equals(relationship.getTargetedCapabilityName()))
.map(graph::getEdgeSource)
.collect(Collectors.toList());
}
示例12: getHostCapability
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
protected Capability getHostCapability(
DirectedMultigraph<NodeTemplate, RelationshipTemplate> graph, NodeTemplate taskNode) {
NodeTemplate hostNode = getHostNode(graph, taskNode);
// at this point we're sure that it exists
return hostNode.getCapabilities().get(HOST_CAPABILITY_NAME);
}
示例13: buildTask
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
@Override
public ChronosJob buildTask(DirectedMultigraph<NodeTemplate, RelationshipTemplate> graph,
NodeTemplate taskNode, String taskId) {
ChronosJob job = super.buildTask(graph, taskNode, taskId);
if (job.getCmd() == null) { // command is required in chronos
throw new ToscaException(String.format(
"<command> property of node <%s> must be provided", taskNode.getName()));
}
toscaService
.<ScalarPropertyValue>getTypedNodePropertyByName(taskNode, "retries")
.ifPresent(property -> job.setRetries(Ints
.saturatedCast(toscaService.parseScalarPropertyValue(property, IntegerType.class))));
toscaService
.<ScalarPropertyValue>getTypedNodePropertyByName(taskNode, "schedule")
.ifPresent(property -> job.setSchedule(property.getValue()));
toscaService
.<ScalarPropertyValue>getTypedNodePropertyByName(taskNode, "description")
.ifPresent(property -> job.setDescription(property.getValue()));
toscaService
.<ScalarPropertyValue>getTypedNodePropertyByName(taskNode, "epsilon")
.ifPresent(property -> job.setEpsilon(property.getValue()));
return job;
}
示例14: createGroup
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
protected Group createGroup(Deployment deployment) {
ArchiveRoot ar = toscaService
.prepareTemplate(deployment.getTemplate(), deployment.getParameters());
Map<String, NodeTemplate> nodes = Optional
.ofNullable(ar.getTopology())
.map(Topology::getNodeTemplates)
.orElseGet(HashMap::new);
// don't check for cycles, already validated at web-service time
DirectedMultigraph<NodeTemplate, RelationshipTemplate> graph =
toscaService.buildNodeGraph(nodes, false);
TopologicalOrderIterator<NodeTemplate, RelationshipTemplate> orderIterator =
new TopologicalOrderIterator<>(graph);
List<NodeTemplate> orderedMarathonApps = CommonUtils
.iteratorToStream(orderIterator)
.filter(node -> toscaService.isOfToscaType(node, ToscaConstants.Nodes.MARATHON))
.collect(Collectors.toList());
Group group = new Group();
List<App> apps = new ArrayList<>();
for (NodeTemplate marathonNode : orderedMarathonApps) {
MarathonApp marathonTask = buildTask(graph, marathonNode, marathonNode.getName());
List<Resource> resources = resourceRepository
.findByToscaNodeNameAndDeployment_id(marathonNode.getName(), deployment.getId());
resources.forEach(resource -> resource.setIaasId(marathonTask.getId()));
marathonTask.setInstances(resources.size());
App marathonApp = generateExternalTaskRepresentation(marathonTask);
apps.add(marathonApp);
}
group.setApps(apps);
return group;
}
示例15: buildNodeGraph
import org.jgrapht.graph.DirectedMultigraph; //导入依赖的package包/类
@Override
public DirectedMultigraph<NodeTemplate, RelationshipTemplate> buildNodeGraph(
Map<String, NodeTemplate> nodes, boolean checkForCycles) {
DirectedMultigraph<NodeTemplate, RelationshipTemplate> graph =
new DirectedMultigraph<>(RelationshipTemplate.class);
nodes.entrySet().forEach(nodeEntry -> {
NodeTemplate toNode = nodeEntry.getValue();
graph.addVertex(toNode);
Map<String, RelationshipTemplate> relationships =
Optional.ofNullable(toNode.getRelationships()).orElseGet(HashMap::new);
relationships.values().forEach(relationship -> {
NodeTemplate fromNode = nodes.get(relationship.getTarget());
graph.addVertex(fromNode);
graph.addEdge(fromNode, toNode, relationship);
});
});
if (checkForCycles) {
CycleDetector<NodeTemplate, RelationshipTemplate> cycleDetector = new CycleDetector<>(graph);
Set<NodeTemplate> cyclyingNodes = cycleDetector.findCycles();
if (!cyclyingNodes.isEmpty()) {
String message = "Found node depencency loop in TOSCA topology; involved nodes: "
+ Arrays.toString(cyclyingNodes.stream().map(NodeTemplate::getName).toArray());
LOG.error(message);
throw new ValidationException(message);
}
}
return graph;
}