public void ComputeCompleteThree() { var actors = new List <Actor> { new Actor(0, "a0"), new Actor(1, "a1"), new Actor(2, "a2"), }; var network = new Network() { Actors = actors, Layers = new List <Layer> { new Layer { Edges = new List <Edge> { new Edge(actors[0], actors[1]), new Edge(actors[0], actors[2]), new Edge(actors[1], actors[2]) } } } }; var cliques = new BronKerbosch().GetMaximalCliques(network); Assert.Collection(cliques, item => Assert.Equal(item, actors)); }
public void InitNodesTest() { var network = new Network() { Actors = new List <Actor> { new Actor(0, "a0"), new Actor(1, "a1"), new Actor(2, "a2") } }; var nodes = new BronKerbosch().InitNodes(network); Assert.Equal(network.Actors, nodes); }
/// <summary> /// Find k-clique communities in network using the percolation method. /// /// A k-clique community is the union of all cliques of size k that /// can be reached through adjacent (sharing k-1 nodes) k-cliques. /// </summary> /// <param name="network">Network in which to find communities.</param> /// <param name="k">Size of smallest clique.</param> /// <returns>List of communities.</returns> public List <Community> GetKCommunities(Network network, int k) { if (k < 2) { throw new ArgumentException("K must be greater than 1."); } var cliques = new BronKerbosch() .GetMaximalCliques(network) .Where(c => c.Count >= k) .ToList(); var membership = AssignMembership(cliques); var cliqueToActor = GetCliqueToActor(cliques); var actorToClique = GetActorToClique(cliqueToActor); var percNetwork = GetPercolationNetwork(cliques, membership, cliqueToActor, k); return(percNetwork.Layers .First() .GetConnectedComponents(percNetwork.Actors) .Select(c => new Community(c.SelectMany(a => actorToClique[a]))) .ToList()); }
public void InitNeighboursTest() { var actors = new List <Actor> { new Actor(0, "a0"), new Actor(1, "a1"), new Actor(2, "a2") }; var network = new Network() { Actors = actors, Layers = new List <Layer> { new Layer { Edges = new List <Edge> { new Edge(actors[0], actors[1]), new Edge(actors[1], actors[2]), } } } }; var neighbours = new BronKerbosch().InitNeighbours(network); Assert.Collection(neighbours[actors[0]], item => Assert.Equal(item, actors[1])); Assert.Collection(neighbours[actors[1]], item => Assert.Equal(item, actors[0]), item => Assert.Equal(item, actors[2])); Assert.Collection(neighbours[actors[2]], item => Assert.Equal(item, actors[1])); }
public void ComputeTwoCompleteThreeConnected() { var actors = new List <Actor> { new Actor(0, "a0"), new Actor(1, "a1"), new Actor(2, "a2"), new Actor(3, "a3"), new Actor(4, "a4"), }; var network = new Network() { Actors = actors, Layers = new List <Layer> { new Layer { Edges = new List <Edge> { new Edge(actors[0], actors[1]), new Edge(actors[0], actors[2]), new Edge(actors[1], actors[2]), new Edge(actors[2], actors[3]), new Edge(actors[2], actors[4]), new Edge(actors[3], actors[4]), } } } }; var cliques = new BronKerbosch().GetMaximalCliques(network); Assert.Collection(cliques, item => Assert.Equal(item, actors.GetRange(0, 3)), item => Assert.Equal(item, actors.GetRange(2, 3))); }