org.jgrapht.graph.SimpleDirectedWeightedGraph Java Examples

The following examples show how to use org.jgrapht.graph.SimpleDirectedWeightedGraph. 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: SimpleRoadMapPlanner.java    From coordination_oru with GNU General Public License v3.0 6 votes vote down vote up
private void buildGraphs() {
	this.graph = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
	
	metaCSPLogger.info("Updating the roadmap with the given graph ...");
	
	for (String v : locations.keySet()) {
		this.graph.addVertex(v);
		metaCSPLogger.info("Added vertex " + v + ".");
	}
	
	for (String from : locations.keySet()) {
		for (String to : locations.keySet()) {
			if (!from.equals(to)) {
				if (paths.containsKey(from+"->"+to)) {
					PoseSteering[] path = paths.get(from+"->"+to);
					DefaultWeightedEdge e = addEdge(graph, from, to, (double)path.length);
					metaCSPLogger.info("Added edge " + e);
				}
			}
		}	
	}
}
 
Example #2
Source File: SimpleRoadMapPlanner.java    From coordination_oru with GNU General Public License v3.0 6 votes vote down vote up
@Override
public AbstractMotionPlanner getCopy() {
	SimpleRoadMapPlanner ret = new SimpleRoadMapPlanner();
	ret.setFootprint(this.footprintCoords);
	ret.om = this.om;
	ret.locations.putAll(this.locations);
	ret.paths.putAll(this.paths);
	ret.removedVertices.addAll(this.removedVertices);
	ret.removedEdges.putAll(this.removedEdges);
	ret.graph = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
	for (String v : this.graph.vertexSet()) ret.graph.addVertex(v);
	for (DefaultWeightedEdge e : this.graph.edgeSet()) {
		DefaultWeightedEdge e1 = ret.graph.addEdge(this.graph.getEdgeSource(e),this.graph.getEdgeTarget(e));
		ret.graph.setEdgeWeight(e1, this.graph.getEdgeWeight(e));
	}
	return ret;
}
 
Example #3
Source File: SimpleRoadMapPlanner.java    From coordination_oru with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void clearObstacles() {
	
	if (this.noMap) this.om = null;
	else this.om.clearObstacles();
	
	//Restore the original graph
	if (removedVertices.isEmpty() && removedEdges.isEmpty()) return;
	this.graph = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
	
	//Tracking changes
	for (String v : removedVertices) this.graph.addVertex(v);
	for (DefaultWeightedEdge e : removedEdges.keySet()) {
		DefaultWeightedEdge e1 = this.graph.addEdge(removedEdges.get(e).getSource(),removedEdges.get(e).getTarget());
		this.graph.setEdgeWeight(e1, removedEdges.get(e).getWeight());
	}
	removedVertices.clear();
	removedEdges.clear();
}
 
Example #4
Source File: Missions.java    From coordination_oru with GNU General Public License v3.0 6 votes vote down vote up
private static void buildGraph() {
	
	graph = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
	
	metaCSPLogger.info("Updating the roadmap...");
	
	for (String oneLoc : locations.keySet()) {
		graph.addVertex(oneLoc);
		metaCSPLogger.info("Added vertex " + oneLoc);
	}
	
	for (String from : locations.keySet()) {
		for (String to : locations.keySet()) {
			if (!from.equals(to)) {
				if (isKnownPath(from, to)) {
					DefaultWeightedEdge e = graph.addEdge(from, to);
					//PoseSteering[] path = loadKnownPath(from, to);
					PoseSteering[] path = paths.get(from+"->"+to);
					graph.setEdgeWeight(e, path.length);
					metaCSPLogger.info("Added edge " + e);
				}
			}
		}	
	}
}
 
Example #5
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 #6
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 5 votes vote down vote up
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedInterLayerGraph(){
	SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
	TEDBlock.lock();
	try{
		graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) interLayerGraph.clone();
	} finally{
		TEDBlock.unlock();
	}
	return graphCopy;
}
 
Example #7
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 5 votes vote down vote up
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedLowerLayerkGraph(){
	SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
	TEDBlock.lock();
	try{
		graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) lowerLayerGraph.clone();
	} finally{
		TEDBlock.unlock();
	}
	return graphCopy;
}
 
Example #8
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 5 votes vote down vote up
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedUpperLayerkGraph(){
	SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
	TEDBlock.lock();
	try{
		graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) upperLayerGraph.clone();
	} finally{
		TEDBlock.unlock();
	}
	return graphCopy;
}
 
Example #9
Source File: SimpleITTEDB.java    From netphony-topology with Apache License 2.0 5 votes vote down vote up
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedNetworkGraph(){
	it_site_id_domain_ed=new Hashtable <Object,Object>();
	resource_id_domain_ed=new Hashtable <Object,Object>();
	SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) networkGraph.clone();
	log = LoggerFactory.getLogger("PCEServer");
	return graphCopy;
}
 
Example #10
Source File: SimpleTEDB.java    From netphony-topology with Apache License 2.0 5 votes vote down vote up
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedNetworkGraph(){
	SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
	TEDBlock.lock();
	try{
		graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) networkGraph.clone();
	} finally{
		TEDBlock.unlock();
	}
	return graphCopy;
}
 
Example #11
Source File: GroupLinkage.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
private float getSimilarity(SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> simGraph, int verticesNum) {
    float numerator = 0;
    float denominator = verticesNum; //m1+m2
    for (DefaultWeightedEdge e : simGraph.edgeSet()) {
        numerator += simGraph.getEdgeWeight(e);
        denominator -= 1.0;
    }
    return numerator / denominator;
}
 
Example #12
Source File: GroupLinkage.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
@Override
public float executeComparison(Comparison comparison) {
    final Queue<SimilarityEdge> similarityQueue = getSimilarityEdges(comparison);
    final SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> similarityGraph = getSimilarityGraph(similarityQueue);
    int verticesNum = entityModelsD1[comparison.getEntityId1()].length;
    if (isCleanCleanER) {
        verticesNum += entityModelsD2[comparison.getEntityId2()].length;
    } else {
        verticesNum += entityModelsD1[comparison.getEntityId2()].length;
    }

    return getSimilarity(similarityGraph, verticesNum);
}
 
Example #13
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 #14
Source File: SimpleTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getNetworkGraph() {
	return networkGraph;
}
 
Example #15
Source File: SimpleTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public void createGraph(){
	networkGraph = new SimpleDirectedWeightedGraph<Object, IntraDomainEdge>(IntraDomainEdge.class);
	reachabilityEntry = new ReachabilityEntry();
}
 
Example #16
Source File: ModelBasedGraphGenerator.java    From JQF with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private Graph<Integer, DefaultEdge> createGraph() {
    Class<? extends DefaultEdge> edgeClass =
            model.weighted() ? DefaultWeightedEdge.class : DefaultEdge.class;

    if (model.loops()) {
        if (model.multiGraph() == false) {
            throw new IllegalArgumentException("Self-loops are only supported " +
                    "with multi-graphs");
        }
        if (isDirected()) {
            if (model.weighted()) {
                return new DirectedWeightedPseudograph<>(edgeClass);
            } else {
                return new DirectedPseudograph<>(edgeClass);
            }
        } else {
            if (model.weighted()) {
                return new WeightedPseudograph<>(edgeClass);
            } else {
                return new Pseudograph<>(edgeClass);
            }
        }
    } else {
        if (model.multiGraph()) {
            if (isDirected()) {
                if (model.weighted()) {
                    return new DirectedWeightedMultigraph<>(edgeClass);
                } else {
                    return new DirectedMultigraph<>(edgeClass);
                }
            } else {
                if (model.weighted()) {
                    return new WeightedMultigraph<>(edgeClass);
                } else {
                    return new Multigraph<>(edgeClass);
                }
            }
        } else {
            if (isDirected()) {
                if (model.weighted()) {
                    return new SimpleDirectedWeightedGraph<>(edgeClass);
                } else {
                    return new SimpleDirectedGraph<>(edgeClass);
                }
            } else {
                if (model.weighted()) {
                    return new SimpleWeightedGraph<>(edgeClass);
                } else {
                    return new SimpleGraph<>(edgeClass);
                }
            }
        }
    }

}
 
Example #17
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);
	}
}
 
Example #18
Source File: MDTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getDuplicatedNetworkGraph() {
	return networkGraph;
}
 
Example #19
Source File: SimpleITTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public void setNetworkGraph(
		SimpleDirectedWeightedGraph<Object, IntraDomainEdge> networkGraph) {
	this.networkGraph = networkGraph;
}
 
Example #20
Source File: SimpleITTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getNetworkGraph() {
	return networkGraph;
}
 
Example #21
Source File: ITMDTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getDuplicatedNetworkGraph() {
	// TODO Auto-generated method stub
	return networkGraph;
}
 
Example #22
Source File: SimpleTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public void setNetworkGraph(
		SimpleDirectedWeightedGraph<Object, IntraDomainEdge> networkGraph) {
	this.networkGraph = networkGraph;
}
 
Example #23
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public void setInterLayerGraph(
		SimpleDirectedWeightedGraph<Object, IntraDomainEdge> interLayerGraph) {
	this.interLayerGraph = interLayerGraph;
}
 
Example #24
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getInterLayerGraph() {
	return interLayerGraph;
}
 
Example #25
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public void setLowerLayerGraph(
		SimpleDirectedWeightedGraph<Object, IntraDomainEdge> lowerLayerGraph) {
	this.lowerLayerGraph = lowerLayerGraph;
}
 
Example #26
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getLowerLayerGraph() {
	return lowerLayerGraph;
}
 
Example #27
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public void setUpperLayerGraph(
		SimpleDirectedWeightedGraph<Object, IntraDomainEdge> upperLayerGraph) {
	this.upperLayerGraph = upperLayerGraph;
}
 
Example #28
Source File: MultiLayerTEDB.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getUpperLayerGraph() {
	return upperLayerGraph;
}
 
Example #29
Source File: FileTEDBUpdater.java    From netphony-topology with Apache License 2.0 2 votes vote down vote up
/**
 * Reads a specific layer from a Network XML file
 * It can treat all domains as a single domain
 * @param fileName Name of the XML file
 * @param layer Layer
 * @param allDomains if all domains are read or not 
 * @param lambdaIni first lambda (n)
 * @param lambdaEnd last lamnda (n)
 * @return Graph of the network
 */

public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName, String layer,boolean allDomains,int lambdaIni, int lambdaEnd) {
	return FileTEDBUpdater.readNetwork(fileName,layer,allDomains,0,Integer.MAX_VALUE, false);
}
 
Example #30
Source File: FileTEDBUpdater.java    From netphony-topology with Apache License 2.0 2 votes vote down vote up
/**
 * Reads a specific layer from a Network XML file
 * It can treat all domains as a single domain
 * @param fileName Name of the XML file
 * @param layer Layer 
 * @param allDomains if all domains are read or not 
 * @return Graph of the network
 */
public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName,String layer,boolean allDomains){
	return FileTEDBUpdater.readNetwork(fileName,layer,allDomains,0,Integer.MAX_VALUE, false);
}