Java Code Examples for org.jgrapht.graph.SimpleDirectedWeightedGraph#addVertex()

The following examples show how to use org.jgrapht.graph.SimpleDirectedWeightedGraph#addVertex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupLinkage.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
private SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> getSimilarityGraph(Queue<SimilarityEdge> seQueue) {
    final SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> graph = new SimpleDirectedWeightedGraph<>(DefaultWeightedEdge.class);
    while (seQueue.size() > 0) {
        SimilarityEdge se = seQueue.remove();
        int i = se.getModel1Pos();
        int j = se.getModel2Pos();
        String label1 = "a" + i;
        String label2 = "b" + j;
        if (!(graph.containsVertex(label1) || graph.containsVertex(label2))) {//only if both vertices don't exist
            graph.addVertex(label1);
            graph.addVertex(label2);
            DefaultWeightedEdge e = graph.addEdge(label1, label2);
            graph.setEdgeWeight(e, se.getSimilarity());
        }
    }

    return graph;
}
 
Example 2
Source File: SimpleRoadMapPlanner.java    From coordination_oru with GNU General Public License v3.0 5 votes vote down vote up
private DefaultWeightedEdge addEdge(SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> graph, String source, String target, double weight) {
	graph.addVertex(source);
	graph.addVertex(target);
	DefaultWeightedEdge e = graph.addEdge(source,target);
	graph.setEdgeWeight(e, weight);
	return e;
}
 
Example 3
Source File: TEDUpdaterController.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public static void parseRemainingLinksFromXML(DomainTEDB TEDB, String interDomainFile) 
{
	Hashtable<Integer,MyEdge> interDomainLinks = readInterDomainFile(interDomainFile);
	Map<Integer, MyEdge> map = interDomainLinks;
	Iterator<Map.Entry<Integer, MyEdge>> it = map.entrySet().iterator();
	while (it.hasNext()) 
	{
		Map.Entry<Integer, MyEdge> entry = it.next();

		MyEdge edgeAux = entry.getValue(); 
		
		IntraDomainEdge edge= new IntraDomainEdge();
		edge.setSrc_if_id(new Long(edgeAux.source_port));
		edge.setDst_if_id(new Long(edgeAux.dest_port));
		
		TE_Information tE_info = new TE_Information();
		tE_info.setNumberWLANs(15);
		tE_info.initWLANs();
		
		tE_info.setVlanLink(true);
		tE_info.setVlan(edgeAux.vlan);
		
		edge.setTE_info(tE_info);
		
		
		System.out.println("Adding InterDomain Edge!!::Vlan::"+edgeAux.vlan);
		
		
		SimpleDirectedWeightedGraph sdwg =  ((SimpleTEDB)TEDB).getNetworkGraph();
		if (!sdwg.containsVertex(new RouterInfoPM(edgeAux.source)))
		{
			sdwg.addVertex(new RouterInfoPM(edgeAux.source));
		}
		
		if (!sdwg.containsVertex(new RouterInfoPM(edgeAux.dest)))
		{
			sdwg.addVertex(new RouterInfoPM(edgeAux.dest));
		}
		
		
		((SimpleTEDB)TEDB).getNetworkGraph().addEdge(new RouterInfoPM(edgeAux.source), new RouterInfoPM(edgeAux.dest), edge);
	}
}