本文整理汇总了Java中org.jgrapht.Graphs.addAllVertices方法的典型用法代码示例。如果您正苦于以下问题:Java Graphs.addAllVertices方法的具体用法?Java Graphs.addAllVertices怎么用?Java Graphs.addAllVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.Graphs
的用法示例。
在下文中一共展示了Graphs.addAllVertices方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBipartiteMatching2
import org.jgrapht.Graphs; //导入方法依赖的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: populateSig
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Method to be called only when SigValue IDREFs have been fully unmarshalled,
* to populate the target SIG.
*
* @param sig the (rather empty) sig to be completed
*/
public void populateSig (SIGraph sig)
{
final InterIndex index = sig.getSystem().getSheet().getInterIndex();
// Allocate vertices
Graphs.addAllVertices(sig, interRefs);
Graphs.addAllVertices(sig, interDefs);
for (Inter inter : sig.vertexSet()) {
inter.setSig(sig);
index.insert(inter);
}
// Allocate edges
for (RelationValue rel : relations) {
try {
Inter source = index.getEntity(rel.sourceId);
Inter target = index.getEntity(rel.targetId);
sig.addEdge(source, target, rel.relation);
} catch (Throwable ex) {
logger.error("Error unmarshalling relation " + rel + " ex:" + ex, ex);
}
}
}
示例3: testBipartiteMatching1
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Random test graph 1
*/
public void testBipartiteMatching1(){
UndirectedGraph<Integer, DefaultEdge> graph = new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
List<Integer> partition1=Arrays.asList(new Integer[]{0,1,2,3});
List<Integer> partition2=Arrays.asList(new Integer[]{4,5,6,7});
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 e02=graph.addEdge(partition1.get(0), partition2.get(2));
DefaultEdge e10=graph.addEdge(partition1.get(1), partition2.get(0));
DefaultEdge e11=graph.addEdge(partition1.get(1), partition2.get(1));
DefaultEdge e12=graph.addEdge(partition1.get(1), partition2.get(2));
DefaultEdge e20=graph.addEdge(partition1.get(2), partition2.get(0));
DefaultEdge e21=graph.addEdge(partition1.get(2), partition2.get(1));
HopcroftKarpBipartiteMatching<Integer,DefaultEdge> bm=new HopcroftKarpBipartiteMatching<Integer,DefaultEdge>(graph,new HashSet<Integer>(partition1),new HashSet<Integer>(partition2));
assertEquals(3, bm.getMatching().size(), 0);
List<DefaultEdge> l1 = Arrays.asList(new DefaultEdge[] {e11, e02, e20});
Set<DefaultEdge> matching = new HashSet<DefaultEdge>(l1);
assertEquals(matching, bm.getMatching());
}
示例4: findBarPeaks
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Use individual staff projections to retrieve bar peaks.
*/
private void findBarPeaks ()
{
// Analysis staff per staff
for (Staff staff : staffManager.getStaves()) {
StaffProjector projector = new StaffProjector(sheet, staff, this);
projectors.add(projector);
projector.process();
Graphs.addAllVertices(this, projector.getPeaks());
}
}
示例5: buildRelationships
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Compute the matrix of inter-chords relationships.
*/
private void buildRelationships ()
{
// Sort measure standard chords by abscissa
List<AbstractChordInter> stdChords = new ArrayList<AbstractChordInter>(
stack.getStandardChords());
Collections.sort(stdChords, Inter.byAbscissa);
// Populate graph with chords
Graphs.addAllVertices(graph, stdChords);
// BeamGroup-based relationships
inspectBeams();
// Mirror-based relationships
inspectMirrors();
// RootStem-based relationships
inspectRootStems();
// Finally, default location-based relationships
inspectLocations(stdChords);
if (logger.isDebugEnabled()) {
dumpRelationships(stdChords);
}
}
示例6: getSubGraph
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Extract a subgraph limited to the provided set of glyphs.
*
* @param set the provided set of glyphs
* @param graph the global graph to extract from
* @param checkEdges true if glyph edges may point outside the provided set.
* @return the graph limited to glyph set and related edges
*/
public static SimpleGraph<Glyph, GlyphLink> getSubGraph (Set<Glyph> set,
SimpleGraph<Glyph, GlyphLink> graph,
boolean checkEdges)
{
// Which edges should be extracted for this set?
Set<GlyphLink> setEdges = new LinkedHashSet<GlyphLink>();
for (Glyph glyph : set) {
Set<GlyphLink> glyphEdges = graph.edgesOf(glyph);
if (!checkEdges) {
setEdges.addAll(glyphEdges); // Take all edges
} else {
// Keep only the edges that link within the set
for (GlyphLink link : glyphEdges) {
Glyph opposite = Graphs.getOppositeVertex(graph, link, glyph);
if (set.contains(opposite)) {
setEdges.add(link);
}
}
}
}
SimpleGraph<Glyph, GlyphLink> subGraph = new SimpleGraph<Glyph, GlyphLink>(GlyphLink.class);
Graphs.addAllVertices(subGraph, set);
Graphs.addAllEdges(subGraph, graph, setEdges);
return subGraph;
}
示例7: example1
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Example on undirected graph
*/
public static void example1(){
//Define a new Undirected Graph. For simplicity we'll use a simple, unweighted graph, but in reality this class is mainly used
//in combination with weighted graphs for TSP problems.
Graph<Integer, DefaultEdge> undirectedGraph=new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
Graphs.addAllVertices(undirectedGraph, Arrays.asList(1,2,3,4,5,6));
undirectedGraph.addEdge(1, 2);
undirectedGraph.addEdge(2, 3);
undirectedGraph.addEdge(3, 4);
undirectedGraph.addEdge(4, 1);
undirectedGraph.addEdge(1, 5);
undirectedGraph.addEdge(4, 5);
undirectedGraph.addEdge(5, 6);
undirectedGraph.addEdge(2, 6);
undirectedGraph.addEdge(3, 6);
//Define the x_e values for every edge e\in E
Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>();
edgeValueMap.put(undirectedGraph.getEdge(1,2), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(2,3), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(3,4), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(4,1), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(1,5), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(4,5), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(5,6), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(2,6), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(3,6), 1.0);
//Invoke the separator
SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(undirectedGraph);
separator.separateSubtour(edgeValueMap);
System.out.println("Has found a violated subtour: "+separator.hasSubtour());
System.out.println("Cut value: "+separator.getCutValue());
System.out.println("Cut set: "+separator.getCutSet());
//The returned cut set is: {2,3,6}. This leads to the cut: \sum_{e\in \delta{2,3,6}} x_e >=2
}
示例8: example2
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Example on directed graph
*/
public static void example2(){
//Define a new Directed Graph. For simplicity we'll use a simple, unweighted graph.
Graph<Integer, DefaultEdge> directedGraph=new SimpleDirectedGraph<Integer, DefaultEdge>(DefaultEdge.class);
Graphs.addAllVertices(directedGraph, Arrays.asList(1,2,3,4,5,6));
directedGraph.addEdge(1, 2);
directedGraph.addEdge(2, 3);
directedGraph.addEdge(3, 4);
directedGraph.addEdge(4, 1);
directedGraph.addEdge(1, 4);
directedGraph.addEdge(1, 5);
directedGraph.addEdge(5, 1);
directedGraph.addEdge(4, 5);
directedGraph.addEdge(5, 4);
directedGraph.addEdge(6, 2);
directedGraph.addEdge(3, 6);
//Define the x_e values for every edge e\in E
Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>();
edgeValueMap.put(directedGraph.getEdge(1,2), 0.0);
edgeValueMap.put(directedGraph.getEdge(2,3), 1.0);
edgeValueMap.put(directedGraph.getEdge(3,4), 0.0);
edgeValueMap.put(directedGraph.getEdge(4,1), 0.5);
edgeValueMap.put(directedGraph.getEdge(1,4), 0.5);
edgeValueMap.put(directedGraph.getEdge(1,5), 0.5);
edgeValueMap.put(directedGraph.getEdge(5,1), 0.5);
edgeValueMap.put(directedGraph.getEdge(4,5), 0.5);
edgeValueMap.put(directedGraph.getEdge(5,4), 0.5);
edgeValueMap.put(directedGraph.getEdge(6,2), 1.0);
edgeValueMap.put(directedGraph.getEdge(3,6), 1.0);
//Invoke the separator
SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(directedGraph);
separator.separateSubtour(edgeValueMap);
System.out.println("Has found a violated subtour: "+separator.hasSubtour());
System.out.println("Cut value: "+separator.getCutValue());
System.out.println("Cut set: "+separator.getCutSet());
//The returned cut set is: {2,3,6}. This leads to the cut: \sum_{e\in \delta{2,3,6}} x_e >=2
}
示例9: testUndirectedGraphWithSubtour
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Test 1 - Undirected, incomplete graph with a subtour.
*/
public void testUndirectedGraphWithSubtour(){
//Define a new Undirected Graph. For simplicity we'll use a simple, unweighted graph, but in reality this class is mainly used
//in combination with weighted graphs for TSP problems.
Graph<Integer, DefaultEdge> undirectedGraph=new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
Graphs.addAllVertices(undirectedGraph, Arrays.asList(1,2,3,4,5,6));
undirectedGraph.addEdge(1, 2);
undirectedGraph.addEdge(2, 3);
undirectedGraph.addEdge(3, 4);
undirectedGraph.addEdge(4, 1);
undirectedGraph.addEdge(1, 5);
undirectedGraph.addEdge(4, 5);
undirectedGraph.addEdge(5, 6);
undirectedGraph.addEdge(2, 6);
undirectedGraph.addEdge(3, 6);
//Define the x_e values for every edge e\in E
Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>();
edgeValueMap.put(undirectedGraph.getEdge(1,2), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(2,3), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(3,4), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(4,1), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(1,5), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(4,5), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(5,6), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(2,6), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(3,6), 1.0);
//Invoke the separator
SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(undirectedGraph);
separator.separateSubtour(edgeValueMap);
assertTrue(separator.hasSubtour());
assertEquals(0, separator.getCutValue(), PRECISION);
assertEquals(new HashSet<Integer>(Arrays.asList(2,3,6)), separator.getCutSet());
}
示例10: testUndirectedGraphWithoutSubtour
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Test 2 - Undirected, incomplete graph without a subtour.
*/
public void testUndirectedGraphWithoutSubtour(){
//Define a new Undirected Graph. For simplicity we'll use a simple, unweighted graph, but in reality this class is mainly used
//in combination with weighted graphs for TSP problems.
Graph<Integer, DefaultEdge> undirectedGraph=new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
Graphs.addAllVertices(undirectedGraph, Arrays.asList(1,2,3,4,5,6));
undirectedGraph.addEdge(1, 2);
undirectedGraph.addEdge(2, 3);
undirectedGraph.addEdge(3, 4);
undirectedGraph.addEdge(4, 1);
undirectedGraph.addEdge(1, 5);
undirectedGraph.addEdge(4, 5);
undirectedGraph.addEdge(5, 6);
undirectedGraph.addEdge(2, 6);
undirectedGraph.addEdge(3, 6);
//Define the x_e values for every edge e\in E
Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>();
edgeValueMap.put(undirectedGraph.getEdge(1,2), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(2,3), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(3,4), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(4,1), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(1,5), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(4,5), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(5,6), 0.0);
edgeValueMap.put(undirectedGraph.getEdge(2,6), 1.0);
edgeValueMap.put(undirectedGraph.getEdge(3,6), 1.0);
//Invoke the separator
SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(undirectedGraph);
separator.separateSubtour(edgeValueMap);
assertFalse(separator.hasSubtour());
assertEquals(2, separator.getCutValue(), PRECISION);
}
示例11: testDirectedGraphWithSubtour
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Test 3 - Directed, incomplete graph without a subtour.
*/
public void testDirectedGraphWithSubtour(){
//Define a new Directed Graph. For simplicity we'll use a simple, unweighted graph.
Graph<Integer, DefaultEdge> directedGraph=new SimpleDirectedGraph<Integer, DefaultEdge>(DefaultEdge.class);
Graphs.addAllVertices(directedGraph, Arrays.asList(1,2,3,4,5,6));
directedGraph.addEdge(1, 2);
directedGraph.addEdge(2, 3);
directedGraph.addEdge(3, 4);
directedGraph.addEdge(4, 1);
directedGraph.addEdge(1, 4);
directedGraph.addEdge(1, 5);
directedGraph.addEdge(5, 1);
directedGraph.addEdge(4, 5);
directedGraph.addEdge(5, 4);
directedGraph.addEdge(6, 2);
directedGraph.addEdge(3, 6);
//Define the x_e values for every edge e\in E
Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>();
edgeValueMap.put(directedGraph.getEdge(1,2), 0.0);
edgeValueMap.put(directedGraph.getEdge(2,3), 1.0);
edgeValueMap.put(directedGraph.getEdge(3,4), 0.0);
edgeValueMap.put(directedGraph.getEdge(4,1), 0.5);
edgeValueMap.put(directedGraph.getEdge(1,4), 0.5);
edgeValueMap.put(directedGraph.getEdge(1,5), 0.5);
edgeValueMap.put(directedGraph.getEdge(5,1), 0.5);
edgeValueMap.put(directedGraph.getEdge(4,5), 0.5);
edgeValueMap.put(directedGraph.getEdge(5,4), 0.5);
edgeValueMap.put(directedGraph.getEdge(6,2), 1.0);
edgeValueMap.put(directedGraph.getEdge(3,6), 1.0);
//Invoke the separator
SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(directedGraph);
separator.separateSubtour(edgeValueMap);
assertTrue(separator.hasSubtour());
assertEquals(0, separator.getCutValue(), PRECISION);
assertEquals(new HashSet<Integer>(Arrays.asList(2,3,6)), separator.getCutSet());
}
示例12: testEmptyMatching
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Find a maximum matching on a graph without edges
*/
public void testEmptyMatching(){
UndirectedGraph<Integer, DefaultEdge> graph = new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
List<Integer> partition1=Arrays.asList(new Integer[]{0});
List<Integer> partition2=Arrays.asList(new Integer[]{1});
Graphs.addAllVertices(graph, partition1);
Graphs.addAllVertices(graph,partition2);
HopcroftKarpBipartiteMatching<Integer,DefaultEdge> bm=new HopcroftKarpBipartiteMatching<Integer,DefaultEdge>(graph,new HashSet<Integer>(partition1),new HashSet<Integer>(partition2));
assertEquals(Collections.EMPTY_SET, bm.getMatching());
}
示例13: cutCycles
import org.jgrapht.Graphs; //导入方法依赖的package包/类
public DirectedGraph<V, E> cutCycles() {
Set<CutPoint<V, E>> cutPoints = new HashSet<>(findCutPoints());
Graphs.addAllVertices(targetGraph, sourceGraph.vertexSet());
for (E e : sourceGraph.edgeSet()) {
V s = sourceGraph.getEdgeSource(e);
V t = sourceGraph.getEdgeTarget(e);
CutPoint<V, E> cp = new CutPoint<>(s, t);
if (!cutPoints.contains(cp)) {
targetGraph.addEdge(s, t, e);
}
}
return targetGraph;
}
示例14: SubtourSeparator
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* This method instantiates the Subtour Separator. The input can be any type of graph: directed, undirected, or mixed,
* complete or incomplete, weighted or without weights. Internally, this class converts the given graph to a undirected graph.
* Multiple edges between two vertices i,j, for example two direct arc (i,j) and (j,i)) are aggregated into in undirected edge (i,j).
* WARNING: if the input graph is modified, i.e. edges or vertices are added/removed then the behavior of this class is undefined!
* A new instance should of this class should be made if this happens!
* @param inputGraph input graph
*/
public SubtourSeparator(Graph<V,E> inputGraph){
this.inputGraph=inputGraph;
this.workingGraph=new SimpleWeightedGraph<>(DefaultWeightedEdge.class);
Graphs.addAllVertices(workingGraph, inputGraph.vertexSet());
for(E edge : inputGraph.edgeSet())
Graphs.addEdge(workingGraph, inputGraph.getEdgeSource(edge), inputGraph.getEdgeTarget(edge),0);
}