Return a value from function
- To: mathgroup at smc.vnet.net
- Subject: [mg97668] Return a value from function
- From: Mite <mitemeister at gmail.com>
- Date: Wed, 18 Mar 2009 04:54:49 -0500 (EST)
I'm using Mathematica 6. Trying to count the Maximum Independent Vertex Set in a graph g. I'm using recursive calls to a function. I think that when I call a return on a function that is called from its recursive predecesor, the two functions finish. Is that possible, or is it only me thinking wrong. If its possible, how can i solve this. Here is the code: Needs["Combinatorica`"] g = CompleteGraph[5]; g = DeleteEdge[g, {1, 2}]; g = DeleteEdge[g, {3, 2}]; g = DeleteEdge[g, {1, 3}]; g = DeleteEdge[g, {1, 5}]; g = DeleteEdge[g, {3, 5}]; g = DeleteEdge[g, {2, 5}]; ShowLabeledGraph[g] n1 = 0; n2 = 0; func = Function[g1, deg = 0; degrees = Degrees[g1]; temp = 0; For[i = 1, i <= V[g1], i++, If[degrees[[i]] > 0, deg = deg + degrees[[i]];]]; deg = Divide[deg, 2]; Print["Degree: ", deg]; v = V[g1]; If[deg == 0, Print["true, V[G] = ", v]; Return[v]; Print["Ret ne rabote"];, Print["false, V[G] = ", v]; v = V[g1]; Print["Izbrana tocka ", v]; n1 = func[DeleteVertex[g1, v]]; Print["N1 = ", n1]; n2 = func[DeleteVertices[g1, Neighborhood[g1, v, 1]]]; Print["N2 = ", n2]; Print["Max = ", Max[n1, n2]] Return[Max[n1, n2]]];]; Print[func[g]]