I'm looking for a way to remove an unacceptable line crossing in a simple dot script. There is no line-crossing when the code is executed in http://www.webgraphviz.com/, but there is a line-crossing when the exact same code is executed in a Jupyter notebook. I'd be grateful for a suggestion of how to remove the line-crossing in Jupyter, that is, to make the layout in Jupyter look like the layout in webgraphviz.
Here is the dot code:
Digraph X {
rankdir=LR;
{rank=same; a b}
{rank=same; d c}
z -> a
a -> b
b -> c
c -> d
d -> a
}
In http://www.webgraphviz.com/, it displays as follows:
But, in Jupyter, it displays as follows, with an unacceptable line-crossing:
The jupyter code is the following:
import graphviz
graphviz.Source('''Digraph X {
rankdir=LR;
{rank=same; a b}
{rank=same; d c}
z -> a
a -> b
b -> c
c -> d
d -> a
}''')
This took some trial and error and piecing together clues from https://graphviz.gitlab.io/_pages/doc/info/attrs.html
import graphviz
graphviz.Source('''Digraph X {
rankdir=RL;
{rank=sink; z}
{rank=same; c d}
{rank=same; a b}
z -> a
a -> b
b -> c [constraint=false]
c -> d [constraint=false]
d -> a
}''')
Related
I know it is possible to run 1 set of tasks in parallel. For example, something like this:
begin >> [A, B, C, D,E] >> end
would run A, B, C, D, E all in parallel. However, I want to do something like this such that after begin, there are two workflows running in parallel. Something like:
A -> B -> C
begin -> -> end
D -> E -> F
What would be the correct syntax to achieve this?
Every split is like a starting point.
start_dag = start_task()
end_dag = end_task()
a = DummyOperator(task_id="a")
b = DummyOperator(task_id="b")
c = DummyOperator(task_id="c")
d = DummyOperator(task_id="d")
e = DummyOperator(task_id="e")
f = DummyOperator(task_id="f")
(start_dag >> [a, d])
(a >> b >> c >> end_dag)
(d >> e >> f >> end_dag)
I have a 2D map as input from a file ,line by line and I want to save it and run a Bfs or Dijkstra to find the shortest path from Start (marked as S ) to end (marked as E),what's the proper structure to save the information? My implementation in c++ was with a graph,but I find it hard to do so in sml,because I can't link the nodes both ways.
You can do it using mutable arrays. This is an extremely minimal adjacency matrix implementation using an array of array of int option. The edge between vertex i and j is given by the value in the ith row and jth column. If the value is None then there is no edge and if the value is Some w than the edge exists and has weight w.
let is_some opt =
match opt with
| None -> false
| _ -> true;;
let unwrap opt =
match opt with
| None -> raise (Failure "unwrapped None")
| Some x -> x;;
let add_edge g u v w =
let us = Array.get g u in
Array.set us v (Some w);;
let get_edge g u v =
let us = Array.get g u in
Array.get us v;;
let make_graph vertices =
Array.make_matrix vertices vertices None;;
let neighbors g u =
Array.get g u |>
Array.to_list |>
List.filter is_some |>
List.mapi (fun i o -> (i, unwrap o));;
let g = make_graph 4;;
add_edge g 0 1 2;;
add_edge g 0 2 3;;
add_edge g 0 3 5;;
add_edge g 1 2 7;;
add_edge g 1 3 11;;
add_edge g 2 3 13;;
add_edge g 3 0 17;;
List.iter (fun (v, e) -> Printf.printf "0-(%i)->%i\n" e v) (neighbors g 0);;
This is in OCaml, but the differences between SML and OCaml are, for the most part, minor.
With the following dot code
digraph DG {
G -> V;
G -> E;
G -> P;
G -> C;
}
I generate the following graph
How could I move the node G in the centre? That is I wish to get something like this:
p.s. My experiments with setting the rank of the edge didn't work out.
For the general case, the easiest thing to do is to use twopi or neato instead of dot as your layout engine.
Twopi:
Neato:
If you're truly confined to dot, this will give you close to what you want, though you'll have to customize each graph.
digraph g
{
P -> G [dir=back];
subgraph clusterGVE {
{rank=same V; G; E;}
G -> V [constraint=false];
G -> E;
color=invis;
};
G -> C;
}
I have an undirected graph with the following schema:
graph G {
A -- B;
B -- C;
C -- D;
D -- A;
}
The graph is top to bottom as you see yourself. But I wanted to be in the form of a rectangle where A is top-left and D is bottom-right and I don't really have a clue how to do it.
graph G {
A [
label = A
pos = "0,0!"
]
B [
label = B
pos = "5,0!"
]
C [
label = C
pos = "5,5!"
]
D [
label = D
pos = "0,5!"
]
A -- B;
B -- C;
C -- D;
D -- A;
}
and use neato to generate the image file. (it did not work with dot for me)
I have got another solution without neato I guess that renders with dot properly.
graph G{
{rank=same A B}
{rank=same C D}
A -- B;
B -- C;
D -- A;
D -- C;
}
I'm having problems with edges overlapping each other. In my previous question of how to force the nodes to be in the same column, found out how to force the nodes in to one column, but this causes some other problems to appear.
digraph exmp {
A -> B -> C -> D -> E
C -> F [constraint=false]
A -> C [style="dotted", constraint=false]
A -> D [style="dotted", constraint=false]
B -> D [constraint=false]
D -> A [style="dashed", constraint=false]
C -> A [style="dashed", constraint=false]
E -> F [style="invis"]
F -> G
E -> C [constraint="false"]
}
Renders to:
alt text http://img98.imageshack.us/img98/8324/wrong2.gif
My problem is that the edges from E -> C and C -> F are starting/ending at the same point in the node C and the dashed and dotted edges are all on the right side of the nodes.
How could I tell specific edges to go to the right side of the node?
After a message in the graphviz mail list I've found that's at least possible to remove the E -> C and C -> F overlapping problem.
The simplest solution is to use a
compass point port:
C:e -> F [constraint=false]
-- Emden