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.

Combinatorica\`` functions consider different things to beGraph`'s. Related: Use of MinimumSpanningTree – Jacob Akkerboom Mar 13 '14 at 12:11