Wolfram mathematica Combinatica`PlanarQ不';行不通

Wolfram mathematica Combinatica`PlanarQ不';行不通,wolfram-mathematica,mathematica-8,Wolfram Mathematica,Mathematica 8,为什么PlanarQ不返回“真”或“假”?您可能需要: g1=Graph[{UndirectedEdge[a,b]}]; GraphQ[g1] (* OUT: True *) (*Needs["Combinatorica`"]*) PlanarQ[g1] (* OUT: PlanarQ[.-.] *) Combinatorica`PlanarQ[g1] (* OUT: Combinatorica`PlanarQ[.-.] *) 但是,我不需要检查v

为什么PlanarQ不返回“真”或“假”?

您可能需要:

 g1=Graph[{UndirectedEdge[a,b]}];
 GraphQ[g1]
 (*
   OUT: True
 *)
   (*Needs["Combinatorica`"]*)
 PlanarQ[g1]
 (*
    OUT: PlanarQ[.-.]
 *)
 Combinatorica`PlanarQ[g1]
 (*
   OUT: Combinatorica`PlanarQ[.-.]
 *)

但是,我不需要检查v8。

您的图形不是一个
Combinatica
图形,而是一个
系统
图形。您需要显式地指定上下文

Needs["GraphUtilities`"]
Needs["Combinatorica`"]

cg1 = ToCombinatoricaGraph[g1];

PlanarQ[cg1]

这将返回
True
,但是,一般来说,这个过程是一个痛苦的过程,而且相当麻烦。我相信Combinatica即将出局,我建议你不要使用它。

请注意,Combinatica即将出局。然而,三个月前,Graph项目的一位负责人告诉我,没有计划为System Graph重新实现特定于算法的接口,如
BrelazColoring
。因此,有些东西可能需要
Combinatica
一段时间,解决这一问题的一种方法是尝试将System'Graph用于所有事情,将
Combinatica
排除在包路径之外,并通过显式地将图形对象转换为Combinatica'Graph对象来使用Combinatica函数,调用Combinatica`函数,然后转换回系统图

下面是我用来解决TomD报告的订购问题的
relabelGraph
函数

Needs["GraphUtilities`"];
g1 = System`Graph[{UndirectedEdge[a, b]}];
Combinatorica`PlanarQ[
  GraphUtilities`ToCombinatoricaGraph[g1]]
下面是使用它的一种方法。这将产生类似于
IndexGraph
的结果,但使用排序的
VertexList

relabelGraph[g_Graph,labeling_]:=Module[{vcoords,gstyle,labelMap,adjMat,newOrder,newCoords,verts},
    verts=VertexList@g;
    vcoords=VertexCoordinates/.AbsoluteOptions[g,VertexCoordinates];
    gstyle=GraphStyle/.AbsoluteOptions[g,GraphStyle];
    labelMap=Thread[Range[Length[verts]]->labeling];

    adjMat=Normal@AdjacencyMatrix[g];
    newOrder=Ordering[VertexList[g]/.labelMap];

    newCoords=Thread[(VertexList[g]/.labelMap)->vcoords];

    AdjacencyGraph[adjMat[[newOrder,newOrder]],VertexCoordinates->newCoords,GraphStyle->gstyle]
];

包中的
graphUsage.nb
中描述了我的一些其他“烦恼修复”功能。这也只是一个注释

我想特别提醒大家注意
ToCombinatoricaGraph
中可能存在的错误以及可能的解决方法。这可能与原来的问题无关

另外,我使用的是Mma 7,所以在v8中可能会解决问题

如果我定义一个图如下

g=relabelGraph[g,Range@Length@VertexList@g];
gr1的图形批次

比较以下各项:

Needs["Combinatorica`"]

Needs["GraphUtilities`"]

gr1 = {2 -> 4, 4 -> 3, 3 -> 1}
输出

我使用的解决方法是尽可能忽略组合图,而是使用排序对转换为组合图

比如说

{{2, 4}, {4, 3}, {3, 1}}
{{1, 2}, {2, 3}, {3, 4}}
{{1, 2}, {2, 3}, {3, 4}}
输出

另一个例子,
Degrees

比较

{{2, 4}, {4, 3}, {3, 1}}
{{2, 4}, {3, 1}, {4, 3}}
输出

我还将举一个例子,因为我在这里被严重“抓到”(当时我不知道)

输出

(只有第二个答案是正确的)

我已经向Wolfram报告了这件事。看起来,它与通过
ToCombinatoricaGraph
创建图时顶点的重新排序有关。以下是部分答复(2009年)

边缘和边缘主义者 不在ToCombinatoriGraph上运行 对象,因为Combinatica包是在此之前开发的 功能,并且结构尚未调整以适应操作 用这些 功能

{2, 3}
{3, 4}
跑 如果遇到任何其他问题,或者有任何问题,请让 我 知道

在我看来,
ToCombinatoricaGraph
需要小心使用(尽可能避免)。然而,在很多情况下(包括在原始问题的其他答案中给出的用法),它可能没有区别


就我个人而言,我不希望看到Combinatica软件包消失。它包含许多有用的函数(如果文档非常糟糕的话)

我遇到了几个与顶点排序相关的错误。我的解决办法是确保VertexList@g已排序。这也给出了更自然的邻接矩阵,在我的答案中添加了如何实现这一点的示例
{{2, 4}, {4, 3}, {3, 1}}
{{2, 4}, {3, 1}, {4, 3}}
Degrees@MakeSimple@ToCombinatoricaGraph[gr1]
VertexList@MakeSimple@ToCombinatoricaGraph[gr1]
{1, 2, 2, 1}
{1, 2, 3, 4}
Degrees@MakeSimple@FromOrderedPairs@EdgeList@gr1
VertexList@MakeSimple@FromOrderedPairs@EdgeList@gr1

{1, 1, 2, 2}
{1, 2, 3, 4}
LabeledTreeToCode@MakeSimple@ToCombinatoricaGraph@gr1
LabeledTreeToCode@MakeSimple@FromOrderedPairs@EdgeList@gr1
{2, 3}
{3, 4}
Our development team is currently working to update the Combinatorica
package so that these functions will be compatible.  If you happen to