0
$\begingroup$

I have a graph and i want a module to run through all the edges of this graph and check whether (u,v) edge is in this graph and (v,u) edge is in another given graph.

$\endgroup$
  • $\begingroup$ What have you tried so far? Where did you get stuck? EdgeList and MemberQ are helpful for a direct approach. $\endgroup$ – Szabolcs Jul 25 '15 at 16:17
  • $\begingroup$ Well i need a loop to go through every edge and to check this, and i don't know how to do that. I have this code, but it doesn't work $\endgroup$ – Nasi Jofce Jul 25 '15 at 22:31
  • $\begingroup$ edgelist = {s -> 1, s -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 3 -> t, 4 -> 3, 4 -> t}; createVector[C_] := Module[{newVec {}, l = Length[C], a, b}, For[i = 0, i < Length[edgelist], i++, For[j = 0, j < l, j++, If[edgelist[i] == C[j], Append[newVec, 1]; Break, If[ MatchQ[edgelist[i], {__a -> __b}] && MatchQ[C[i], {__b -> __a}], Append[newVec, -1]; Break, Append[newVec, 0]; ]; ] ] newVec ]; $\endgroup$ – Nasi Jofce Jul 25 '15 at 22:33
  • 1
    $\begingroup$ I don't understand; what's all that looping about? If you have an edge list why can't you simply check to see if your edge is in it? $\endgroup$ – Mr.Wizard Jul 25 '15 at 23:50
  • $\begingroup$ can you give me a sample code how to check this? for example let's check the edge (1->2) $\endgroup$ – Nasi Jofce Jul 26 '15 at 10:05
1
$\begingroup$
edgelist = {s -> 1, s -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 3 -> t, 4 -> 3, 4 -> t};

MemberQ[edgelist, 1 -> 2]
(* False *)

MemberQ[edgelist, 2 -> 1]
(* True *)
$\endgroup$
  • $\begingroup$ Is there a way to loop through all the edges of this graph and to find if they are on this graph or not. for examle s->1 is from this graph but 1->s isn't. $\endgroup$ – Nasi Jofce Jul 26 '15 at 13:26
  • $\begingroup$ @NasiJofce Look up Table, Do, Outer, and/or Subsets. I think you need to spend some time learning the basics. $\endgroup$ – Michael E2 Jul 26 '15 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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