ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 28 Feb 2021 03:06:31 +0100$k$-independence number in graphshttps://ask.sagemath.org/question/55936/k-independence-number-in-graphs/ I know how to find the independence number in graphs in sagemath. I want to obtain a new parameter called $k$-independence number in graphs which means the maximum size of a set of vertices at pairwise distance greater than $k$.
Would you please tell me how I can find this parameter in a graph?Sat, 27 Feb 2021 16:49:39 +0100https://ask.sagemath.org/question/55936/k-independence-number-in-graphs/Answer by Max Alekseyev for <p>I know how to find the independence number in graphs in sagemath. I want to obtain a new parameter called $k$-independence number in graphs which means the maximum size of a set of vertices at pairwise distance greater than $k$. </p>
<p>Would you please tell me how I can find this parameter in a graph?</p>
https://ask.sagemath.org/question/55936/k-independence-number-in-graphs/?answer=55941#post-id-55941For a given graph $G$, we can construct a new graph $H$ on the same set of vertices as $G$ such that two vertices $u$ and $v$ are connected in $H$ iff the distance between $u,v$ in $G$ is greater than $k$. Then the $k$-independence number of $G$ equals the clique number of $H$.
Here is a sample code, which computes 1-independence number of Petersen graph.
from sage.graphs.distances_all_pairs import distances_all_pairs
def k_independence_number(G,k):
D = distances_all_pairs(G) # pairwise distances
H = Graph([ G.vertices(), [(u,v) for u,N in D.items() for v,d in N.items() if d>k] ])
return H.clique_number()
print( k_independence_number(graphs.PetersenGraph(),1) )
Sun, 28 Feb 2021 03:06:31 +0100https://ask.sagemath.org/question/55936/k-independence-number-in-graphs/?answer=55941#post-id-55941