1
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ Built in Mathematica functions and Combinatorica` functions consider different things to be Graph's. Related: Use of MinimumSpanningTree $\endgroup$ Mar 13, 2014 at 12:11
  • $\begingroup$ @user11609 it would be helpful to give a small example to work out where the problem arises $\endgroup$
    – ubpdqn
    Mar 13, 2014 at 12:11
  • $\begingroup$ @m_goldberg I am confused about your opinion on Backquotes in titles. By the way, do you know how (if that is possible) to add "comments" (invisible text) to a queston/answer (maybe using html)? In the linked Q&A I would want to add the word backtick as a comment for search purposes. $\endgroup$ Mar 13, 2014 at 12:27
  • $\begingroup$ @ubpdqn....i have edited the question and written the code..plz see $\endgroup$
    – user11609
    Mar 13, 2014 at 12:29
  • 1
    $\begingroup$ @JacobAkkerboom. I think this is a case where back ticks are OK. $\endgroup$
    – m_goldberg
    Mar 13, 2014 at 12:29

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ i used this but giving error every time as mentioned in the question..i've inclued the code too..plz see $\endgroup$
    – user11609
    Mar 13, 2014 at 12:30
  • $\begingroup$ i've removed combinatorica still did not get the output $\endgroup$
    – user11609
    Mar 13, 2014 at 12:32
  • $\begingroup$ 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 :). $\endgroup$ Mar 13, 2014 at 12:33
  • $\begingroup$ @user11609. Did you start a fresh Mathematica session to get rid of Combinatorica? As look as it's loaded, you will have problems. $\endgroup$
    – m_goldberg
    Mar 13, 2014 at 12:49
  • $\begingroup$ yeah i did that too but still didn't get output....i'm trying this last three days and got nothing till now,, $\endgroup$
    – user11609
    Mar 13, 2014 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.