/// <summary> /// Finds the largest clique in which nodeId is a member and returns all cliques of that size which meet that criterion. /// </summary> /// <param name="socialNetworkMatrix">The INetworkMatrix instance being searched.</param> /// <param name="nodeId">The ID for the node of interest.</param> /// <returns>The collection of ICliqueMatrix instances of maximal size which include nodeId as a member.</returns> public static IEnumerable<ICliqueMatrix> FindLargestCliqueInvolvingNode(INetworkMatrix socialNetworkMatrix, int nodeId) { var relatedNodes = new List<int>(Enumerable.Range(1, socialNetworkMatrix.NodeCount).Where<int>( secondNodeId => socialNetworkMatrix.NodesRelate(nodeId, secondNodeId) )); var tuple = CreateSubnetworkFromNodeIds(socialNetworkMatrix, relatedNodes); var subnetwork = tuple.Item1; var map = tuple.Item2; var inverseMap = tuple.Item3; // uses the smaller subnetwork created from the related nodes of nodeId to search for a clique of maximal size, // of which we are guaranteed that nodeId is a member (since it is related to all nodes in this subnetwork) // // in turn, this collection of maximal cliques is mapped back to a collection of ICliqueMatrix instances where // the node IDs reflect the node IDs of the original socialNetworkMatrix return FindLargestClique(subnetwork) .Select<ICliqueMatrix, ICliqueMatrix>( cliqueOfSubnet => NetworkMatrixFactory.CreateCliqueMatrix( cliqueOfSubnet.MemberNodeIds.Select<int, int>( subnetId => inverseMap[subnetId] ), socialNetworkMatrix.NodeCount) ); }