# error during execution function  (cannot evaluate twice)

**URL:** <https://community.wolfram.com/t/error-during-execution-function-cannot-evaluate-twice/1807>\
**Category:** Questions\
**Tags:** graphs-and-networks\
**Created:** [March 26, 2014, 10:43am UTC](https://community.wolfram.com/t/error-during-execution-function-cannot-evaluate-twice/1807 "2014-03-26T10:43:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gio03gio](https://avatars.discourse-cdn.com/v4/letter/g/9dc877/32.png) [@gio03gio](https://community.wolfram.com/u/gio03gio)\
**Post date:** [March 26, 2014, 10:43am UTC](https://community.wolfram.com/t/error-during-execution-function-cannot-evaluate-twice/1807/1 "2014-03-26T10:43:16Z")

</div>

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).  
Why?

```auto
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];
    Pick[powerSet, 
     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"]

listSubGraphIndipendent[grafoArt]

```

---

<div class="post-metadata">

**Author:** ![biancaeifert](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/biancaeifert/32/1245_2.png) [@biancaeifert](https://community.wolfram.com/u/biancaeifert)\
**Post date:** [March 27, 2014, 1:53pm UTC](https://community.wolfram.com/t/error-during-execution-function-cannot-evaluate-twice/1807/2 "2014-03-27T13:53:28Z")

</div>

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,

Bianca

---

<div class="post-metadata">

**Author:** ![gio03gio](https://avatars.discourse-cdn.com/v4/letter/g/9dc877/32.png) [@gio03gio](https://community.wolfram.com/u/gio03gio)\
**Post date:** [March 27, 2014, 2:49pm UTC](https://community.wolfram.com/t/error-during-execution-function-cannot-evaluate-twice/1807/3 "2014-03-27T14:49:22Z")

</div>

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.
