Skip to content

Commit

Permalink
Merge pull request jgrapht#372 from d-michail/graph-generators-fix1
Browse files Browse the repository at this point in the history
Minor bug fix in Barabasi-Albert graph generator
  • Loading branch information
jkinable authored Mar 5, 2017
2 parents c4c73bc + d1e9e0b commit 6f4473a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,18 @@ public void generateGraph(
/*
* Create complete graph with m0 nodes
*/
List<V> nodes = new ArrayList<>(n * m);
Set<V> oldNodes = new HashSet<>(target.vertexSet());
Set<V> newNodes = new HashSet<>();
new CompleteGraphGenerator<V, E>(m0).generateGraph(target, vertexFactory, resultMap);
target.vertexSet().stream().filter(v -> !oldNodes.contains(v)).forEach(nodes::add);
target.vertexSet().stream().filter(v -> !oldNodes.contains(v)).forEach(newNodes::add);

List<V> nodes = new ArrayList<>(n * m);
nodes.addAll(newNodes);
/*
* Augment node list to have node multiplicity equal to m0-1.
* Augment node list to have node multiplicity equal to min(1,m0-1).
*/
for (int i = 0; i < m0 - 2; i++) {
nodes.addAll(target.vertexSet());
nodes.addAll(newNodes);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,20 @@ public void testDirectedWithOneInitialNode()

assertEquals(20, g.vertexSet().size());
}

@Test
public void testUndirectedWithGraphWhichAlreadyHasSomeVertices()
{
final long seed = 5;

GraphGenerator<Integer, DefaultEdge, Integer> gen =
new BarabasiAlbertGraphGenerator<>(3, 2, 10, seed);
Graph<Integer, DefaultEdge> g = new SimpleGraph<>(DefaultEdge.class);
g.addVertex(1000);
gen.generateGraph(g, new IntegerVertexFactory(), null);

assertEquals(11, g.vertexSet().size());
}


}

0 comments on commit 6f4473a

Please sign in to comment.