1

I'm trying to generate a random geometric graph. When evaluating HighlightGraph, even if I am passing graph object Mathematica always gives error like

A graph object is expected at position 1 in RowBox[{"HighlightGraph", "[", RowBox[{InterpretationBox[StyleBox[RowBox[{...`

How can I solve this problem. I am new to Mathematica programming and am using Mathematica 9. my code is..

v = {};
For[i = 1, i <= n, i++, v = Append[v, {{Random[], Random[]}}]];
g = Graph[{}, v];
keyrings = {};
        For[i = 1, i <= n, i++,
            keyring = {};
            If[P == K, 
                For[k = 1, Length[keyring] < K, k++,
                        keyring = Append[keyring, k]
                    ],
                (* P > K *)
                For[k = 1, Length[keyring] < K, k++,
                        key = Random[Integer, {1, P}];
                        If[MemberQ[keyring, key] == False,
                            keyring = Append[keyring, key]
                        ]
                    ]
            ];
            keyrings = Append[keyrings, keyring];
        ];
For[i = 1, i <= n, i++,
            For[j = i + 1, j <= n, j++, 
                xi = Extract[Extract[Extract[v, i], 1], 1];
                xj = Extract[Extract[Extract[v, j], 1], 1];
                yi = Extract[Extract[Extract[v, i], 1], 2];
                yj = Extract[Extract[Extract[v, j], 1], 2];
                If[dist[xi, yi, xj, yj][[1]] < rc, 
                        If[
     Extract[keyrings, {i}] ⋂ 
       Extract[keyrings, {j}] != {},
                            g = AddEdge[g, {{i, j}}],
                            (* Else *)
                            Print["No secure link between ", i, " ", j]
                        ]
                    ]
            ]
        ];
HighlightGraph[g, {NeighborhoodGraph[g, 1], Labeled[1, 1]}];
Print[ShowGraph[g]]
]
]

Please tell me where I have made a mistake.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
user11609
  • 13
  • 5

1 Answers1

1

Don't use Combinatorica. It's been obsolete since Version 8. Take a look at RandomGraph. With that you should be to get what you want. For example,

HighlightGraph[RandomGraph[{5, 6}], {1 -> 3}]

randgraph

Note

When one loads Combinatorica in V8 or later, one gets the message

General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionality. The package now being loaded may conflict with this. Please see the Compatibility Guide for details.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • i used this but giving error every time as mentioned in the question..i've inclued the code too..plz see – user11609 Mar 13 '14 at 12:30
  • i've removed combinatorica still did not get the output – user11609 Mar 13 '14 at 12:32
  • Ah, I suspected it might be, but I never saw this statement. If it is true that it is (fully?) obsolete, then this should get many upvotes :). – Jacob Akkerboom Mar 13 '14 at 12:33
  • @user11609. Did you start a fresh Mathematica session to get rid of Combinatorica? As look as it's loaded, you will have problems. – m_goldberg Mar 13 '14 at 12:49
  • yeah i did that too but still didn't get output....i'm trying this last three days and got nothing till now,, – user11609 Mar 13 '14 at 12:58
  • after removing Combinatorica ShowGraph is also not executing.. Instead of using HighlightGraph if i use GraphHighlight then error removed from program but still didn't get the highlighted graph...whats the problem?? and here i haven't used inbuilt random graph of mathematica.. – user11609 Mar 13 '14 at 13:13
  • ShowGraph, AddEdge are Combinatorica function and also code you are running need to load Combinatorica. You better use other code to generate graph like one in the answer of http://mathematica.stackexchange.com/questions/38589/random-geometric-graph-generation-problem – halmir Mar 13 '14 at 14:56
  • @halmir..in the given link, code with System graph functionality i am unable put HighlightGraph function, plz help a little more by telling where should i change in order to get highlighted adjacent edges from any given vertex. – user11609 Mar 13 '14 at 16:44
  • @user11609 which code did you try? if you set g = RandomKeyGeoGraph[...]; then HighlightGraph[g, ..] should work. – halmir Mar 13 '14 at 19:59
  • From Compatibility/tutorial/Combinatorica, we have "As of Version 8, much of the functionality covered by Combinatorica has been implemented in the Mathematica kernel." But I think probably not all functionality. – Jacob Akkerboom Mar 17 '14 at 16:30