本文整理汇总了Java中org.jgrapht.graph.DirectedWeightedMultigraph类的典型用法代码示例。如果您正苦于以下问题:Java DirectedWeightedMultigraph类的具体用法?Java DirectedWeightedMultigraph怎么用?Java DirectedWeightedMultigraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectedWeightedMultigraph类属于org.jgrapht.graph包,在下文中一共展示了DirectedWeightedMultigraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addGraph
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static DirectedWeightedMultigraph<Long, RelationshipEdge> addGraph(
DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> g, String label,
DirectedWeightedMultigraph<Long, RelationshipEdge> graph) {
System.out.println("Add Graph");
for (Long vertex : g.vertexSet()) {
graph.addVertex(vertex);
}
for (DefaultWeightedEdge e : g.edgeSet()) {
graph.addEdge(g.getEdgeSource(e), g.getEdgeTarget(e),
new RelationshipEdge<Long>(g.getEdgeSource(e), g.getEdgeTarget(e), label));
RelationshipEdge<Long> edge = graph.getEdge(g.getEdgeSource(e), g.getEdgeTarget(e));
graph.setEdgeWeight(edge, g.getEdgeWeight(e));
System.out.println("Edge added");
}
return graph;
}
示例2: getGraphFromLinkMap
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
/** <p>Obtains a {@code JGraphT} graph from a given link map.</p>
*
* @param nodes Collection of nodes
* @param links List of links
* @return {@code JGraphT} graph */
public static org.jgrapht.Graph<Node, Link> getGraphFromLinkMap(Collection<Node> nodes, Collection<Link> links)
{
org.jgrapht.Graph<Node, Link> graph = new DirectedWeightedMultigraph<Node, Link>(Link.class);
for (Node node : nodes)
graph.addVertex(node);
if (links != null)
{
for (Link link : links)
{
Node originNode = link.getOriginNode();
Node destinationNode = link.getDestinationNode();
if (!graph.containsVertex(originNode)) throw new RuntimeException("Bad"); //graph.addVertex(originNode);
if (!graph.containsVertex(destinationNode)) throw new RuntimeException("Bad"); //graph.addVertex(destinationNode);
graph.addEdge(originNode, destinationNode, link);
}
}
return graph;
}
示例3: getGraphFromDemandMap
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
/** <p>Obtains a {@code JGraphT} graph from a given link map.</p>
*
* @param demands List of demands
* @return {@code JGraphT} graph */
public static org.jgrapht.Graph<Node, Demand> getGraphFromDemandMap(List<Demand> demands)
{
org.jgrapht.Graph<Node, Demand> graph = new DirectedWeightedMultigraph<Node, Demand>(Demand.class);
if (demands != null)
{
for (Demand demand : demands)
{
Node originNode = demand.getIngressNode();
Node destinationNode = demand.getEgressNode();
if (!graph.containsVertex(originNode)) graph.addVertex(originNode);
if (!graph.containsVertex(destinationNode)) graph.addVertex(destinationNode);
graph.addEdge(originNode, destinationNode, demand);
}
}
return graph;
}
示例4: getGraphFromRouteMap
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
/** <p>Obtains a {@code JGraphT} graph from a given route map.</p>
*
* @param demands List of demands
* @return {@code JGraphT} graph */
public static org.jgrapht.Graph<Node, Route> getGraphFromRouteMap(List<Route> routes)
{
org.jgrapht.Graph<Node, Route> graph = new DirectedWeightedMultigraph<Node, Route>(Route.class);
if (routes != null)
{
for (Route route : routes)
{
Node originNode = route.getIngressNode();
Node destinationNode = route.getEgressNode();
if (!graph.containsVertex(originNode)) graph.addVertex(originNode);
if (!graph.containsVertex(destinationNode)) graph.addVertex(destinationNode);
graph.addEdge(originNode, destinationNode, route);
}
}
return graph;
}
示例5: doIt
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
logCommand(logger, workspace);
Alignment alignment = AlignmentManager.Instance().getAlignment(
alignmentId);
// Save the original alignment for undo
oldAlignment = alignment.getAlignmentClone();
oldGraph = (DirectedWeightedMultigraph<Node, DefaultLink>) alignment
.getGraph().clone();
try {
alignment.addForcedInternalNode(new Label(nodeUri));
if(!this.isExecutedInBatch())
alignment.align();
} catch (JSONException e) {
logger.error("Error adding Internal Node:" , e);
}
return WorksheetUpdateFactory.createSemanticTypesAndSVGAlignmentUpdates(worksheetId, workspace);
}
示例6: doIt
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
logCommand(logger, workspace);
Alignment alignment = AlignmentManager.Instance().getAlignment(
alignmentId);
// Save the original alignment for undo
oldAlignment = alignment.getAlignmentClone();
oldGraph = (DirectedWeightedMultigraph<Node, DefaultLink>) alignment
.getGraph().clone();
try {
alignment.deleteForcedInternalNode(nodeId);
if(!this.isExecutedInBatch())
alignment.align();
} catch (JSONException e) {
logger.error("Error adding Internal Node:" , e);
}
return WorksheetUpdateFactory.createSemanticTypesAndSVGAlignmentUpdates(worksheetId, workspace);
}
示例7: SemanticModel
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public SemanticModel(Workspace workspace, Worksheet worksheet,
String id,
DirectedWeightedMultigraph<Node, LabeledLink> graph,
SuperSelection sel) {
this.workspace = workspace;
this.worksheet = worksheet;
this.id = id;
this.graph = graph;
this.selection = sel;
this.setLearnedTypesForColumnNodes();
this.setUserTypesForColumnNodes();
this.sourceColumns = this.getColumnNodes();
this.mappingToSourceColumns = new HashMap<ColumnNode, ColumnNode>();
for (ColumnNode c : this.sourceColumns)
this.mappingToSourceColumns.put(c, c);
}
示例8: getTriples
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
private Set<String> getTriples(DirectedWeightedMultigraph<Node, LabeledLink> g, HashMap<Node,String> nodeIds) {
String separator = "|";
Set<String> triples = new HashSet<String>();
if (g == null)
return triples;
String s, p, o, triple;
for (LabeledLink l : g.edgeSet()) {
// FIXME: this line skips the links corresponding to the semantic types
// if (!(l.getTarget() instanceof InternalNode))
// continue;
s = nodeIds.get(l.getSource());
o = nodeIds.get(l.getTarget());
p = l.getLabel().getUri();
triple = s + separator + p + separator + o;
// System.out.println(triple);
triples.add(triple);
}
return triples;
}
示例9: asDirectedGraph
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static DirectedGraph<Node, DefaultLink> asDirectedGraph(UndirectedGraph<Node, DefaultLink> undirectedGraph) {
if (undirectedGraph == null) {
logger.debug("graph is null.");
return null;
}
DirectedGraph<Node, DefaultLink> g = new DirectedWeightedMultigraph<Node, DefaultLink>(DefaultLink.class);
for (Node v : undirectedGraph.vertexSet())
g.addVertex(v);
for (DefaultLink e: undirectedGraph.edgeSet())
g.addEdge(e.getSource(), e.getTarget(), e);
return g;
}
示例10: asDefaultGraph
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static DirectedWeightedMultigraph<Node, DefaultLink> asDefaultGraph(DirectedWeightedMultigraph<Node, LabeledLink> graph) {
if (graph == null) {
logger.debug("graph is null.");
return null;
}
DirectedWeightedMultigraph<Node, DefaultLink> g = new DirectedWeightedMultigraph<Node, DefaultLink>(DefaultLink.class);
for (Node v : graph.vertexSet())
g.addVertex(v);
for (DefaultLink e: graph.edgeSet())
g.addEdge(e.getSource(), e.getTarget(), e);
return g;
}
示例11: asLabeledGraph
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static DirectedWeightedMultigraph<Node, LabeledLink> asLabeledGraph(DirectedWeightedMultigraph<Node, DefaultLink> graph) {
if (graph == null) {
logger.debug("graph is null.");
return null;
}
DirectedWeightedMultigraph<Node, LabeledLink> g = new DirectedWeightedMultigraph<Node, LabeledLink>(LabeledLink.class);
for (Node v : graph.vertexSet())
g.addVertex(v);
for (DefaultLink e: graph.edgeSet())
if (e instanceof LabeledLink)
g.addEdge(e.getSource(), e.getTarget(), (LabeledLink)e);
return g;
}
示例12: exportJson
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static void exportJson(DirectedWeightedMultigraph<Node, DefaultLink> graph, String filename) throws IOException {
logger.info("exporting the graph to json ...");
File file = new File(filename);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream out = new FileOutputStream(file);
JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
//writer.setIndent(" ");
try {
writeGraph(graph, writer);
// writeGraph(workspace, worksheet, graph, writer);
} catch (Exception e) {
logger.error("error in writing the model in json!");
e.printStackTrace();
} finally {
writer.close();
}
logger.info("export is done.");
}
示例13: importJson
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static DirectedWeightedMultigraph<Node, DefaultLink> importJson(String filename) throws IOException {
File file = new File(filename);
if (!file.exists()) {
logger.error("cannot open the file " + filename);
}
FileInputStream in = new FileInputStream(file);
JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
try {
return readGraph(reader);
} catch (Exception e) {
logger.error("error in reading the model from json!");
e.printStackTrace();
return null;
} finally {
reader.close();
}
}
示例14: writeGraph
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
public static void writeGraph(DirectedWeightedMultigraph<Node, DefaultLink> graph, JsonWriter writer) throws IOException {
writer.beginObject();
writer.name("nodes");
writer.beginArray();
if (graph != null)
for (Node n : graph.vertexSet())
writeNode(writer, n);
// writeNode(workspace, worksheet, writer, n);
writer.endArray();
writer.name("links");
writer.beginArray();
if (graph != null)
for (DefaultLink l : graph.edgeSet())
writeLink(writer, l);
writer.endArray();
writer.endObject();
}
示例15: ModelLearningGraph
import org.jgrapht.graph.DirectedWeightedMultigraph; //导入依赖的package包/类
protected ModelLearningGraph(OntologyManager ontologyManager, ModelLearningGraphType type) throws IOException {
this.ontologyManager = ontologyManager;
File file = new File(getGraphJsonName());
if (!file.exists()) {
this.initializeFromJsonRepository();
} else {
logger.info("loading the alignment graph ...");
DirectedWeightedMultigraph<Node, DefaultLink> graph =
GraphUtil.importJson(getGraphJsonName());
if (type == ModelLearningGraphType.Compact)
this.graphBuilder = new GraphBuilderTopK(ontologyManager, graph);
else
this.graphBuilder = new GraphBuilder(ontologyManager, graph, false);
this.nodeIdFactory = this.graphBuilder.getNodeIdFactory();
logger.info("loading is done!");
}
if (this.graphBuilder.getGraph() != null) {
logger.info("number of nodes: " + this.graphBuilder.getGraph().vertexSet().size());
logger.info("number of links: " + this.graphBuilder.getGraph().edgeSet().size());
}
this.lastUpdateTime = System.currentTimeMillis();
}