3

我正在研究最大独立集问题的二次松弛(第22页here),并且发现FindMaximum对于我尝试的每个图都会失败,除非我以最优解作为出发点。这些二次方程式有10-20个变量,所以我期望它们是可以解决的。Mathematica中的二次规划

  1. 有没有办法让Mathematica解决这样的二次方案?
  2. 在Mathematica中是否有一些易于调用的二次编程包?

这里的失败FindMaximum的例子,其次是工作FindMaximum在解决

setupQuadratic[g_Graph] := (
    Ag = AdjacencyMatrix[g]; 
    A = IdentityMatrix[[email protected]@g] - Ag; 
    cons = And @@ Table[0 <= x[v] <= 1, {v, [email protected]}]; 
    vars = x /@ VertexList[g]; 
    indSet = [email protected]; 
    xOpt = Array[Boole[MemberQ[indSet, #]] &, {[email protected]@g}]; 
    ); 

g = GraphData[{"Cubic", {10, 11}}]; 
setupQuadratic[g]; 
FindMaximum[{vars.A.vars, cons}, vars] 
FindMaximum[{vars.A.vars, cons}, Thread[{vars, xOpt}]] 

这里初始化其他图表我试图

{"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}}} 
+0

您链接的文件是非常好的。谢谢! – 2011-03-01 12:19:22

回答

1

似乎Maximize将更好地为您服务。这里是你的函数,它返回的2个结果列表的修改版本 - “手动”之一,由Maximize获得的一个:

Clear[findIVSet]; 
findIVSet[g_Graph] := 
Module[{Ag, A, cons, vars, indSet, indSetFromMaximize, xOpt}, 
    Ag = AdjacencyMatrix[g]; 
    A = IdentityMatrix[[email protected]@g] - Ag; 
    cons = And @@ Table[0 <= x[v] <= 1, {v, [email protected]}]; 
    vars = x /@ VertexList[g]; 
    indSet = [email protected]; 
    xOpt = Array[Boole[MemberQ[indSet, #]] &, {[email protected]@g}]; 
    {indSet, DeleteCases[vars /. ([email protected] 
    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} 
+0

那么,我已经有了FindIndependentVertexSet的独立集,它可能在内部使用类似于你的建议的东西,我真的很想找到最大的原始二次方,Real域 – 2011-03-01 17:48:03

+0

@Yaroslav为什么你对真实域感兴趣?据我所知,在你链接的文章中明确指出,所有变量只能有0或1的值(即Integer域)。而且,就此而言,是什么让你认为真实域的结果与最大独立集问题有什么关系?似乎很清楚,我们并没有在这里寻找局部极值,所以这个约束是很重要的。发现连续约束的极值可能与具有离散约束的极值不同。还是我完全错过了这一点? – 2011-03-01 18:04:00

+0

因为在Integer域中求解它是NP完全的,而实值QP编程是易于处理的。丢弃整数约束是被称为“放松”,和它的作品出奇地好某些类图 - http://cstheory.stackexchange.com/questions/5170/lp-relaxation-of-independent-set – 2011-03-01 18:15:46

0

IMO,FindMaximum并不在这里工作的原因是你的函数的野性。我在变量空间中尝试了1,048,576个采样,并且没有达到比零更高的值。您的最佳起始值为-20。

In[10]:= (x[1]^2 + x[2]^2 + x[3]^2 - 2 x[3] x[4] + x[4]^2 - 
    2 x[2] (x[3] + x[4]) + x[5]^2 - 2 x[3] x[6] - 2 x[5] x[6] + 
    x[6]^2 - 2 x[5] x[7] + x[7]^2 - 2 x[6] x[8] - 2 x[7] x[8] + 
    x[8]^2 - 2 x[7] x[9] + x[9]^2 - 2 x[1] (x[2] + x[5] + x[9]) - 
    2 x[4] x[10] - 2 x[8] x[10] - 2 x[9] x[10] + x[10]^2 /. 
Thread[vars -> #]) & @@@ Tuples[{0.0, 0.333, 0.667, 1.0}, 10] // Max 

Out[10]= 0

In[11]:= (x[1]^2 + x[2]^2 + x[3]^2 - 2 x[3] x[4] + x[4]^2 - 
2 x[2] (x[3] + x[4]) + x[5]^2 - 2 x[3] x[6] - 2 x[5] x[6] + 
x[6]^2 - 2 x[5] x[7] + x[7]^2 - 2 x[6] x[8] - 2 x[7] x[8] + 
x[8]^2 - 2 x[7] x[9] + x[9]^2 - 2 x[1] (x[2] + x[5] + x[9]) - 
2 x[4] x[10] - 2 x[8] x[10] - 2 x[9] x[10] + x[10]^2 /. 
Thread[vars -> #]) & @@@ {xOpt} 

Out[11]= {-20} 
+0

上面的目标简化为'ReplaceAll'后面的'Times [-20,Power [Slot [1],2]]''。评估原始目标的一种方法是'vars.A.vars /。螺纹[瓦尔 - > xOpt]' – 2011-03-01 18:00:33

+0

顺便说一句,上面可如果更换固定''@@@以'/ @'或''#'用{##}'(但不能同时在同一时间!) – 2011-03-01 18:09:11

+0

我扩大了vars.A.vars,因为它可以在我的机器上节省2.3倍的时间。我知道第二部分可能会有不同的写法。我只是这样做,以保持代码的结构相同。 – 2011-03-01 23:40:03

2

可能试试包装位于here的方法。参见问题8

丹尼尔Lichtblau 沃尔夫勒姆研究

+0

有趣,谢谢。的http://mathematica-bits.blogspot.com/2011/03/semidefinite-programming-in-mathematica.html – 2011-03-03 10:01:31

+0

@Yaroslav尼斯位 - 顺便说一句,我也利用二次规划的SDP松弛效果不错工作,Python链接和示例。 – 2011-03-03 16:28:38