Message Boards Message Boards

2 Replies
0 Total Likes
View groups...
Share this post:

error during execution function (cannot evaluate twice)

Posted 10 years ago
Hello to all, I am a newbie to Mathematica.
My problem is the first time I run the code works, however, if I run it then it no longer works (without recreating the graph).
 listMaxNodeGraph[grafo_] :=
   Block[{g = grafo},
    Pick[VertexList[g], VertexDegree[g], Max[VertexDegree[g]]]];
 singleNodeMaxGraph[grafo_] :=
   Block[{g = grafo}, listMaxNodeGraph[g][[1]]];
 degreeMaxNodeGraph[grafo_] :=
   Block[{g = grafo}, VertexDegree[g, singleNodeMaxGraph[g]]];
 findNotNeighbour[grafo_, vertice_] :=
   Block[{g = grafo, v = vertice},
   Pick[VertexList[g], AdjacencyMatrix[g][[VertexIndex[g, v]]], 0]];
findNotNeighbourUn[grafo_, vertice_] :=
Block[{g = grafo, v = vertice, notNei},
  Delete[notNei = findNotNeighbour[g, v],
   Position[notNei, v]]];(*Vu^**)
calculatePowerSet[grafo_] :=
Block[{g = grafo,
   li}, (li = findNotNeighbourUn[g, singleNodeMaxGraph[g]];
   Subsets[li, {1, Length[li]}])];
calculateIndipendentSubSet[grafo_] :=
  Block[{g = grafo, grafoU, powerSet,
    x}, (grafoU = VertexDelete[g, singleNodeMaxGraph[g]];
    powerSet = calculatePowerSet[g];
     Table[IndependentVertexSetQ[grafoU, x], {x, powerSet}]])];
listSubGraphIndipendent[grafo_] :=
  Block[{g = grafo, grafoWithOutU, s,
    x}, (grafoWithOutU = VertexDelete[g, singleNodeMaxGraph[g]];
    s = calculateIndipendentSubSet[g];
    Table[VertexDelete[grafoWithOutU, x], {x, s}])];

grafoArt =
Graph[{1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3,
   1 \[UndirectedEdge] 7, 2 \[UndirectedEdge] 3,
   2 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 5,
   4 \[UndirectedEdge] 5, 4 \[UndirectedEdge] 6,
   4 \[UndirectedEdge] 7, 5 \[UndirectedEdge] 7,
   6 \[UndirectedEdge] 7, 6 \[UndirectedEdge] 8,
   7 \[UndirectedEdge] 8, 8 \[UndirectedEdge] 9,
   5 \[UndirectedEdge] 9}, GraphStyle -> "VintageDiagram"]

POSTED BY: Matteo Giostri
2 Replies
Hi Matteo,

I can't reproduce the problem, the code simply produces the same graph upon every evaluation for me. Have you tried this after a kernel restart? Maybe some of your symbols had old definitions that you forgot about but that interfered with the final version of the code...

Sorry I can't be more helpful.

Kind regards,

POSTED BY: Bianca Eifert
Posted 10 years ago
hi Bianca,
  my problem is execute more times the function listSubGraphIndipendent with out  recreate  the graph.
The first result is correct and the subsequent results are incorrect.
POSTED BY: Matteo Giostri
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract