, Maximize
. , 2 - "" , Maximize
:
Clear[findIVSet];
findIVSet[g_Graph] :=
Module[{Ag, A, cons, vars, indSet, indSetFromMaximize, xOpt},
Ag = AdjacencyMatrix[g];
A = IdentityMatrix[Length@VertexList@g] - Ag;
cons = And @@ Table[0 <= x[v] <= 1, {v, VertexList@g}];
vars = x /@ VertexList[g];
indSet = FindIndependentVertexSet@g;
xOpt = Array[Boole[MemberQ[indSet,
{indSet, DeleteCases[vars /. (Last@
Maximize[{vars.A.vars, cons}, vars,Integers] /. (x[i_] -> 1) :> (x[i] -> i)), 0]}];
:
In[32]:= graphs = GraphData /@ {"DodecahedralGraph", "FruchtGraph",
"TruncatedPrismGraph", "TruncatedTetrahedralGraph", {"Cubic", {10, 2}}, {"Cubic", {10,
3}}, {"Cubic", {10, 4}}, {"Cubic", {10, 6}}, {"Cubic", {10,
7}}, {"Cubic", {10, 11}}, {"Cubic", {10, 12}}, {"Cubic", {12,
5}}, {"Cubic", {12, 6}}, {"Cubic", {12, 7}}, {"Cubic", {12,
9}}, {"Cubic", {12, 10}}};
In[33]:= sets = findIVSet /@ graphs
Out[33]= {{{1, 2, 3, 8, 10, 11, 17, 20}, {5, 6, 7, 8, 14, 15, 17, 18}},
{{2, 4, 6, 11, 12}, {2, 4, 6, 11, 12}}, {{2, 7, 10, 12, 16, 18}, {8, 11, 13, 16, 17, 18}},
{{1, 4, 7, 12}, {4, 7, 9, 12}}, {{2,3, 8, 9}, {2, 3, 8, 9}}, {{1, 4, 7, 10}, {2, 5, 8, 9}},
{{1, 4, 7, 10}, {2, 4, 7, 9}}, {{2, 4, 5, 8}, {3, 6, 7, 9}}, {{2, 5, 8, 9}, {2, 5, 8, 9}},
{{1, 3, 7, 10}, {4, 5, 8, 9}}, {{1, 6, 8, 9}, {2, 3, 6, 10}}, {{1, 6, 7, 12}, {4, 5, 9, 10}},
{{3, 4, 7, 8, 12}, {3, 4, 7, 8, 12}}, {{1, 5, 8, 9}, {4, 5, 10, 11}},
{{1, 5, 6, 9, 10}, {3, 4, 7, 8, 12}}, {{3, 4, 7, 9, 10}, {3, 4, 7, 9, 10}}}
"" , Maximize
, ,
. Maximize
- , :
In[34]:= MapThread[IndependentVertexSetQ, {graphs, sets[[All, 2]]}]
Out[34]= {True, True, True, True, True, True, True, True, True, True, True, True, True,
True, True,True}