I want to construct a dictionary where the keys are the subsets of the vertex set $V$ of a randomly generated graph and the values are the maximal indipendent sets (denoted MI in the code) for which the function:
$$w(A,B)=\sum\limits_{i\in A\triangle B}2^i \quad \text{where} \quad A\triangle B=(A\setminus B) \cup (B\setminus A) $$
is minimized, for $A\subset V$ and $B\subset MI$. I am having difficulties on encoding the information in a dictionary. I have spent quite some time and I can not figure out how to do it. Here is the code:
sage: from sage.graphs.independent_sets import IndependentSets
sage: def generate(n):
... n_0=randint(1,n)
... G=graphs.RandomGNP(n_0,0.4)
... V=set(G.vertices())
... MI=list(IndependentSets(G, maximal = True))
... d={}
...
... for i in Subsets(V):
... alpha_i=[]
... print(i)
... for j in MI:
... delta_ij=set(i).symmetric_difference(set(j))
... print(delta_ij)
...
... alpha_ij=0
... for k in delta_ij:
... alpha_ij=alpha_ij+2^k
... print(alpha_ij)
... alpha_i.append(alpha_ij)
... print(alpha_i)
...
... ll=MI[alpha_i.index(min(alpha_i))]
... d.update(tupple(i):ll)
... print('*******')
...
... print("dictionary",d)
When I compile it I get
Traceback (most recent call last):
...
SyntaxError: invalid syntax
Basically it wont let me use MI[alpha_i.index(min(alpha_i))]
as a value. In other cases I tried to use lists as values and it seemed to work.