本文整理汇总了Java中org.jgrapht.graph.SimpleGraph类的典型用法代码示例。如果您正苦于以下问题:Java SimpleGraph类的具体用法?Java SimpleGraph怎么用?Java SimpleGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleGraph类属于org.jgrapht.graph包,在下文中一共展示了SimpleGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBipartiteMatching2
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Random test graph 2
*/
public void testBipartiteMatching2(){
UndirectedGraph<Integer, DefaultEdge> graph = new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
List<Integer> partition1=Arrays.asList(new Integer[]{0,1,2,3,4,5});
List<Integer> partition2=Arrays.asList(new Integer[]{6,7,8,9,10,11});
Graphs.addAllVertices(graph, partition1);
Graphs.addAllVertices(graph,partition2);
DefaultEdge e00=graph.addEdge(partition1.get(0), partition2.get(0));
DefaultEdge e01=graph.addEdge(partition1.get(0), partition2.get(1));
DefaultEdge e04=graph.addEdge(partition1.get(0), partition2.get(4));
DefaultEdge e10=graph.addEdge(partition1.get(1), partition2.get(0));
DefaultEdge e13=graph.addEdge(partition1.get(1), partition2.get(3));
DefaultEdge e21=graph.addEdge(partition1.get(2), partition2.get(1));
DefaultEdge e32=graph.addEdge(partition1.get(3), partition2.get(2));
DefaultEdge e34=graph.addEdge(partition1.get(3), partition2.get(4));
DefaultEdge e42=graph.addEdge(partition1.get(4), partition2.get(2));
DefaultEdge e52=graph.addEdge(partition1.get(5), partition2.get(2));
DefaultEdge e55=graph.addEdge(partition1.get(5), partition2.get(5));
HopcroftKarpBipartiteMatching<Integer,DefaultEdge> bm=new HopcroftKarpBipartiteMatching<Integer,DefaultEdge>(graph,new HashSet<Integer>(partition1),new HashSet<Integer>(partition2));
assertEquals(6, bm.getMatching().size(), 0);
List<DefaultEdge> l1 = Arrays.asList(new DefaultEdge[] {e21, e13, e00, e42, e34, e55});
Set<DefaultEdge> matching = new HashSet<DefaultEdge>(l1);
assertEquals(matching, bm.getMatching());
}
示例2: generateCompleteGraph
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
private Graph<AutomatVertex, DefaultEdge> generateCompleteGraph(int size) {
LOG.info("--- generateCompleteGraph ---");
//Create the CompleteGraphGenerator object
final Graph<AutomatVertex, DefaultEdge> completeGraph = new SimpleGraph<>(DefaultEdge.class);
final CompleteGraphGenerator<AutomatVertex, DefaultEdge> completeGenerator = new CompleteGraphGenerator<>(size);
//Create the VertexFactory so the generator can create vertices
final VertexFactory<AutomatVertex> vFactory = new ClassBasedVertexFactory<>(AutomatVertex.class);
LOG.info("Generating complete graph");
//Use the CompleteGraphGenerator object to make completeGraph a
//complete graph with [size] number of vertices
completeGenerator.generateGraph(completeGraph, vFactory, null);
return completeGraph;
}
示例3: nonPlanarRandomGraphStructure
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Creates a naive, random, not necessarily planar graph
*/
@Deprecated
public static UndirectedGraph<RegionSetup, DefaultEdge> nonPlanarRandomGraphStructure(
final double populationPerRegionMean,
final double populationStandardDeviation,
UniformDistributionRNG rng,
IntegerInterval numberOfRegionsInterval,
IntegerInterval averageAdjacenciesPerRegionInterval
) {
int numberOfRegions = rng.nextInt(numberOfRegionsInterval);
int numberOfAdjacencies = rng.nextInt(averageAdjacenciesPerRegionInterval) * numberOfRegions;
RandomGraphGenerator<RegionSetup, DefaultEdge> randomGraphGenerator = new RandomGraphGenerator<>(
numberOfRegions, numberOfAdjacencies, rng.nextLong());
SimpleGraph<RegionSetup, DefaultEdge> targetGraph = new SimpleGraph<>(DefaultEdge.class);
VertexFactory<RegionSetup> vertexFactory = () -> new RegionSetup(populationPerRegionMean, populationStandardDeviation, "randomly created");
randomGraphGenerator.generateGraph(targetGraph, vertexFactory, null);
return targetGraph;
}
示例4: deserialize
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
@Override
public UnmodifiableUndirectedGraph<MRVMRegionsMap.Region, DefaultEdge> deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonArray jsonArray = json.getAsJsonArray();
Set<SerializedRegion> serializedRegions = new HashSet<>();
Map<Integer, MRVMRegionsMap.Region> regionsById = new HashMap<>();
SimpleGraph<MRVMRegionsMap.Region, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
for (int i = 0; i < jsonArray.size(); i++) {
JsonElement regionElement = jsonArray.get(i);
SerializedRegion r = context.deserialize(regionElement, SerializedRegion.class);
serializedRegions.add(r);
regionsById.put(r.getNode().getId(), r.getNode());
graph.addVertex(r.getNode());
}
for (SerializedRegion serializedRegion : serializedRegions) {
Set<Integer> neighbors = serializedRegion.getNeighbors();
for (Integer neighborId : neighbors) {
graph.addEdge(serializedRegion.getNode(), regionsById.get(neighborId));
}
}
return new UnmodifiableUndirectedGraph<>(graph);
}
示例5: getGraph
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Convert an FNSS Topology to a JGraphT graph.
*
* @param topology FNSS Topology object
* @return A JGraphT graph
*/
public static Graph<String, Edge> getGraph(Topology topology) {
Graph<String, Edge> graph = null;
if (topology.isDirected()) {
graph = new DefaultDirectedGraph<String, Edge>(Edge.class);
} else {
graph = new SimpleGraph<String, Edge>(Edge.class);
}
for(String node : topology.getAllNodes()) {
graph.addVertex(node);
}
for(Pair<String, String> endpoints : topology.getAllEdges()) {
Edge edge = topology.getEdge(endpoints);
graph.addEdge(endpoints.getU(), endpoints.getV(), edge);
}
return graph;
}
示例6: partitionConstrainedWithCoarseningAndRandomRestart
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Uses the idea of coarsening to reduce the size of the search space by reducing the size of the basic graph G.<br/>
* Employs a Random Restart policy (see Section 5.1 in the paper) by generating a different basic graph each run while using a deterministic algorithm to obtain the initial state.<br/> If the basic graph is not meant to change, use the other implementation.
* @param sc (See SearchConfiguration class)
* @param generator used to generate different basic graphs each run in the Random Restart policy.
* @param rand the RNG which the generator will use.
* @param initialLimitOnMaxNodesExpanded the initial value for the limit on the number of nodes to be expanded before terminating the search and starting a new run.
* @param increamentInLimit how much the limit will increase, this method uses a linear increase policy.
* @param afterCoarseningSize the size of the basic graph G after coarsening (i.e. k in the paper).
* @return a partitioning of the basic graph G that is isomorphic to the constraint graph C.
*/
public static GraphPartitioningState partitionConstrainedWithCoarseningAndRandomRestart(SearchConfiguration sc,int basicGraphSize,BasicGraphGenerator generator,Random rand, int initialLimitOnMaxNodesExpanded,int increamentInLimit, int afterCoarseningSize )
{
if(sc.getBasicGraph() == null)
{
sc.setBasicGraph(generator.generate(basicGraphSize,rand));
}
int GSize = GraphUtil.sizeOf(sc.getBasicGraph());
int limit = initialLimitOnMaxNodesExpanded;
GraphPartitioningState result = null;
while(result == null)
{
result = partitionConstrainedWithCoarsening(sc,rand,afterCoarseningSize,limit);
if(result == null)
{
limit += increamentInLimit;
SimpleGraph<Node,Border> G = generator.generate(GSize,rand);
sc.setBasicGraph(G);
}
}
return result;
}
示例7: partitionConstrainedWithCoarseningAndRandomRestart
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Uses the idea of coarsening to reduce the size of the search space by reducing the size of the basic graph G.<br/>
* Employs a Random Restart policy (see Section 5.1 in the paper) by generating a different basic graph each run while using a deterministic algorithm to obtain the initial state.<br/> If the basic graph is not meant to change, use the other implementation.
* @param sc (See SearchConfiguration class)
* @param generator used to generate different basic graphs each run in the Random Restart policy.
* @param rand the RNG which the generator will use.
* @param initialLimitOnMaxNodesExpanded the initial value for the limit on the number of nodes to be expanded before terminating the search and starting a new run.
* @param increamentInLimit how much the limit will increase, this method uses a linear increase policy.
* @param afterCoarseningSize the size of the basic graph G after coarsening (i.e. k in the paper).
* @return a partitioning of the basic graph G that is isomorphic to the constraint graph C.
*/
public static InitialStateActionsPair partitionConstrainedWithCoarseningAndRandomRestart(SearchConfiguration sc,int basicGraphSize,BasicGraphGenerator generator,Random rand, int initialLimitOnMaxNodesExpanded,int increamentInLimit, int afterCoarseningSize )
{
if(sc.getBasicGraph() == null)
{
sc.setBasicGraph(generator.generate(basicGraphSize,rand));
}
int GSize = GraphUtil.sizeOf(sc.getBasicGraph());
int limit = initialLimitOnMaxNodesExpanded;
InitialStateActionsPair result = null;
while(result == null)
{
result = partitionConstrainedWithCoarsening(sc,rand,afterCoarseningSize,limit);
if(result == null)
{
limit += increamentInLimit;
SimpleGraph<Node,Border> G = generator.generate(GSize,rand);
sc.setBasicGraph(G);
}
}
return result;
}
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:34,代码来源:ConstrainedGraphPartitioningReturnActions.java
示例8: getPartitionsBorders
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* @param G
* @return An array of the edges of the quotient graph <b>G</b>
*/
public static PartitionBorder[] getPartitionsBorders(SimpleGraph<Partition, PartitionBorder> G) {
Set<PartitionBorder> vertexSet = G.edgeSet();
PartitionBorder[] pars = new PartitionBorder[vertexSet.size()];
vertexSet.toArray(pars);
return pars;
}
示例9: isCreatingAGap
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
*
* @param node
* @param graph
* @return whether a path will exist between any pair of the neighbors of
* the passed node after its removal from the graph G.Where G is the graph induced by the partition to which the node belongs
*/
public static boolean isCreatingAGap(Node node, SimpleGraph<Node, Border> graph)
{
ListenableUndirectedGraph<Node, Border> parGraph = buildPartitionListenableGraph(node.getContainer(), graph);
NeighborIndex<Node, Border> ni = new NeighborIndex<Node, Border>(parGraph);
List<Node> adjacents = ni.neighborListOf(node);
ConnectivityInspector<Node, Border> inspector = new ConnectivityInspector<Node, Border>(parGraph);
parGraph.addGraphListener(inspector);
parGraph.removeVertex(node);
for (int i = 0; i < adjacents.size(); i++) {
for (int j = 0; j < adjacents.size(); j++) {
if (i != j) {
if (!inspector.pathExists(adjacents.get(i), adjacents.get(j))) {
return true;
}
}
}
}
return false;
}
示例10: buildPartitionListenableGraph
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Builds a listenable graph based on the adjacency of the members of the
* passed partition,deciding if an edge exist between any two members will
* be based on the passed graph
*
* @param par
* @param graph
* @return a listenable graph
*/
public static ListenableUndirectedGraph<Node, Border> buildPartitionListenableGraph(Partition par, SimpleGraph<Node, Border> graph) {
ListenableUndirectedGraph<Node, Border> parGraph = new ListenableUndirectedGraph<Node, Border>(Border.class);
ArrayList<Node> members = par.getMembers();
for (int i = 0; i < members.size(); i++)
{
parGraph.addVertex(members.get(i));
}
for (int i = 0; i < members.size(); i++) {
for (int j = 0; j < members.size(); j++) {
if (i != j) {
if (graph.containsEdge(members.get(i), members.get(j))) {
parGraph.addEdge(members.get(i), members.get(j), new Border(members.get(i), members.get(j)));
}
}
}
}
return parGraph;
}
示例11: toAdjacencyMatrix
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
public static double[][] toAdjacencyMatrix(SimpleGraph graph) {
Set set1 = graph.vertexSet();
Iterator it1 = set1.iterator();
double[][] adj = new double[set1.size()][set1.size()];
int i = 0, j = 0;
while (it1.hasNext()) {
Object p1 = it1.next();
Set set2 = graph.vertexSet();
Iterator it2 = set2.iterator();
j = 0;
while (it2.hasNext()) {
Object p2 = it2.next();
if (graph.containsEdge(p1, p2)) {
adj[i][j] = 1;
} else {
adj[i][j] = 0;
}
j++;
}
i++;
}
return adj;
}
示例12: degreeMatrix
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
public static double[][] degreeMatrix(SimpleGraph graph) {
Set set = graph.vertexSet();
Iterator it = set.iterator();
double[][] deg = new double[set.size()][set.size()];
int i = 0, j = 0;
while (it.hasNext()) {
Object p = it.next();
deg[i][j] = graph.degreeOf(p);
i++;
j++;
}
return deg;
}
示例13: partitionKernelClustering
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Obtaines a graph partitioning of the passed graph using the algorithm described in:
* "Luh Yen, Francois Fouss, Christine Decaestecker, Pascal Francq, and Marco Saerens. 2007.
Graph Nodes Clustering Based on the Commute-Time Kernel. Springer Berlin Heidelberg, Berlin, Heidelberg,
1037�1045. https://doi.org/10.1007/978-3-540-71701-0_117"
and implemented by https://github.com/trickl/trickl-graph
* @param graph
* @param numPartitions
* @param randomBase
*/
public static GraphPartitioningState partitionKernelClustering(SimpleGraph<Node, Border> graph, int numPartitions,boolean randomBase) {
GraphPartitioningState partitionsGraph = new GraphPartitioningState();
PartitionByKernelClustering<Node, Border> partioner = new PartitionByKernelClustering<Node, Border>();
partioner.partition(graph, numPartitions);
Map<Node, Integer> map = partioner.getPartition();
Iterator<Entry<Node, Integer>> it = map.entrySet().iterator();
int base = secondaryRand.nextInt(Integer.MAX_VALUE);
Partition[] pars = new Partition[numPartitions];
for (int i = 0; i < pars.length; i++) {
if(randomBase)
pars[i] = new Partition(base+i);
else
pars[i] = new Partition(i);
}
while (it.hasNext()) {
Entry<Node, Integer> e = it.next();
pars[e.getValue()].addMember(e.getKey());
}
for (int i = 0; i < pars.length; i++) {
partitionsGraph.addVertex(pars[i]);
}
buildQuotientGraph(partitionsGraph, graph);
return partitionsGraph;
}
示例14: partitionToNodeGraph
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
*
* Convert the partitioning into another graph where the nodes are Node instead of Partition and where the members are part of the Node.cluster
* . Neighbors are NOT copied
* @param oldGraph
* @return Quotient Graph --> Basic Graph
*/
public static SimpleGraph<Node, Border> partitionToNodeGraph(SimpleGraph<Partition, PartitionBorder> oldGraph) {
SimpleGraph<Node, Border> newGraph = new SimpleGraph<Node, Border>(Border.class);
Partition[] pars = GraphUtil.getPartitions(oldGraph);
PartitionBorder[] borders = GraphUtil.getPartitionsBorders(oldGraph);
HashMap<Partition, Node> hashMap = new HashMap<Partition, Node>();
for (int i = 0; i < pars.length; i++)
{
Node n = new Node(i, pars[i].getMembers());
newGraph.addVertex(n);
hashMap.put(pars[i], n);
}
for (int i = 0; i < borders.length; i++) {
Border b = new Border(hashMap.get(borders[i].getP1()), hashMap.get(borders[i].getP2()));
newGraph.addEdge(b.getN1(), b.getN2(), b);
}
return newGraph;
}
示例15: createHypotheticalGraph
import org.jgrapht.graph.SimpleGraph; //导入依赖的package包/类
/**
* Creates and returns a new quotient graph that is the result of removing the
* passed node from the passed basic graph G. This method
* doesn't change the passed graphs but returns a fresh copy.
* @param quotientGraph
* @param basicGraph
* @param node
*/
public static GraphPartitioningState createHypotheticalGraph(GraphPartitioningState quotientGraph, SimpleGraph<Node, Border> basicGraph, Node node) {
GraphPartitioningState newQuotientGraph = new GraphPartitioningState();
// To preserve the removed nodes in the new hypothetical graph
newQuotientGraph.addAllToRemoved(quotientGraph.getRemoved());
Partition[] oldPars = GraphUtil.getPartitions(quotientGraph);
newQuotientGraph.addToRemoved(node);
for (int p = 0; p < oldPars.length; p++) {
Partition tmp =oldPars[p].clone();
int index = tmp.getMembers().indexOf(node);
if (index != -1) {
tmp.getMembers().remove(index);
}
newQuotientGraph.addVertex(tmp);
}
buildQuotientGraph(newQuotientGraph, basicGraph);
return newQuotientGraph;
}