2
$\begingroup$

Given:

dag1 = {"scst" \[DirectedEdge] "stel", "scst" \[DirectedEdge] "sfin", 
   "scst" \[DirectedEdge] "sbus", "scst" \[DirectedEdge] "swhl", 
   "scst" \[DirectedEdge] "ma6", "sfin" \[DirectedEdge] "stel", 
   "sfin" \[DirectedEdge] "sbus", "sfin" \[DirectedEdge] "swhl", 
   "sbus" \[DirectedEdge] "stel", "sbus" \[DirectedEdge] "ma6", 
   "swhl" \[DirectedEdge] "sbus", "swhl" \[DirectedEdge] "ma6"};

The following code intends to extract all the edges directed towards the vertex "sfin". However, it gives an empty set!

EdgeList[dag1, _ -> "sfin"]

Given a directed graph dag1, I like to extract the set of vertices having directed edges towards vertex "sfin", such as

{"sfin", "scst"}       for vertex "sfin"
{"bus", "stel", "ma6"} for vertex "sbus", etc. 

Note that the vertex of interest is the first element in the above two example sets.

$\endgroup$

1 Answer 1

3
$\begingroup$

Inside EdgeList you must use DirectedEdge instead of Rule

EdgeList[dag1, _ \[DirectedEdge] "sfin"]

enter image description here

EdgeList[dag1, _ \[DirectedEdge] "sfin" | "sfin" \[DirectedEdge] _]

enter image description here

$\endgroup$
4
  • $\begingroup$ Why? In the documentation, a directed arrow is used, which I replicated it. I got it. The shape of the arrow is slightly different!!! $\endgroup$ Commented Nov 6, 2023 at 18:54
  • $\begingroup$ The second part of my question is to construct the vertex sets as described in the question above. Can you also address to that? $\endgroup$ Commented Nov 6, 2023 at 18:59
  • 1
    $\begingroup$ @TugrulTemel VertexInComponent[dag1, "sfin"] or VertexOutComponent[dag1, "sbus", 1] ? $\endgroup$
    – halmir
    Commented Nov 6, 2023 at 19:51
  • $\begingroup$ @halmir: VertexIn/Out components give a different result. I simply like to get the list of vertices having directed In links to a given vertex. Since the graph given dag1 is a layered DAG, the result should be a list of vertices (acting as inputs) to a given vertex. I want to write the DAG as a set of functions, such as "sfin"=f["scst"] or "swhl"=f["scst", "sfin"] etc. $\endgroup$ Commented Nov 6, 2023 at 21:06

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.