Graphviz set edge initial direction - graphviz

When I draw a diagram with spline=ortho graphviz sometimes draws edges that go down and then left or right:
+--[ ]
| |
v |
[ ] +->[ ]
How can I specify that edges should depart horizontally from a node?
+--[ ]--+
| |
v v
[ ] [ ]

This is currently (Version 2.38) not working. The compass points are not implemented for spline=ortho. see Issue 352

Related

Netlogo - find the closest agent based on Manhattan distance

I am modelling a big warehouse operations (see below pic).
I have implemented a vertex on each patch (green dots) and link them so that I could compute the shortest path (using dijkstra algorithm) from each vertex to all other vertices, stored in a table (dictionary) of each vertex. This process is done during setup stage and is quite time-consuming. Then the yellow inventory cells (rectangle) will issue the demand request for task fulfillment.
The forklift truck (some in the path) is assuming to stay put on one of the vertex (node) when it's not busy. When get the demand request, it will ask its current standing vertex (node) to get the starting_node and the end_node of the inventory cell it is going to. Then the forklift ask the starting_node to get the shortest path from its table to get the shortest path (combination of nodes) and drive to the end_node (the yellow cell).
Currently, the yellow cells just randomly pick free forklift truck in the warehouse. As a further development, I want to add the function that allows the yellow cell to identify the free truck that is closest to it based on the actual distance (not the euclidean distance built in Netlogo). As there are many trucks so it's not good to use "foreach" to loop through all available trucks and compute the actual distance using above method. You could use primitive "distance myself" to locate the truck quickly but that's not accurate. Is there a good way to identify the closest truck with a faster computational method?
I don't know if this would work with your current setup, but you may also find the nw extension helpful. For example, try this setup (I apologize for the length, just approximating your world):
extensions [ nw ]
breed [ nodes node ]
breed [ trucks truck ]
breed [ cells cell ]
to setup
ca
resize-world -29 29 -14 14
ask patches with [ ( pxcor mod 5 = 0 or pycor = 0 ) ] [
set pcolor grey
sprout-nodes 1 [
set size 0.5
set shape "circle"
set color green
]
]
ask nodes [
create-links-with turtles-on neighbors4 [
set color green
]
]
ask n-of 5 nodes [
hatch 1 [
set size 1
set color red
set breed trucks
set shape "car"
]
]
ask n-of 2 trucks [
set color blue
]
ask one-of nodes [
ask one-of neighbors with [ pcolor = black ] [
sprout-cells 1 [
set size 1.5
set shape "box"
set color yellow
]
]
]
reset-ticks
end
Gives a simple world like this:
You can use the nw extension to calculate the distances on the fly, rather than storing them in a per-cell table, and have the forklifts (trucks, here) follow the shortest path. More details in comments:
to summon-nearest-truck
; Treat blue trucks as 'empty' and ready to go to a cell
let ready-trucks trucks with [ color = blue ]
; Get the nodes associated with those ready trucks
let truck-proxies turtle-set map [ i -> [nodes-on patch-here] of i ] sort ready-trucks
; Randomly ask one of the cells to
ask one-of cells [
; Choose one of the neighboring road nodes as a proxy for distance calculation
let node-proxy one-of nodes-on neighbors4
; Get the node proxy to:
ask node-proxy [
; Find the nearest (by network distance) trucks, and select the node
; located on the same patch as that truck
let my-truck-proxy min-one-of truck-proxies [length ( nw:turtles-on-path-to myself) ]
; Get that truck-proxy node to generate the path to the original asking node
; and have the appropriate truck follow that path
ask my-truck-proxy [
; Generate the path to follow
let path-to-follow nw:turtles-on-path-to myself
; Highlight that path for visualization
ask turtle-set path-to-follow [
set color orange
]
; Get the truck ready to move
let ready-truck one-of trucks-here with [ color = blue ]
ask ready-truck[
set color yellow
]
; Move that truck along the path-to-follow
ask ready-truck [
foreach path-to-follow [
n ->
face n
move-to n
; For visualization only
wait 0.1
]
]
]
]
]
end
This has the yellow box summon the nearest truck based on the length of nw:turtles-on-path-to that is returned. That truck follows the path to the summoning node:

How to create double labelled edges in Graphviz?

I would like to create more than one label for one edge. The result I'm interested in looks like this:
Note that the edge {0,2} has two labels: e and z. One is above the edge, the other one - below. This is the exact outcome I want. How can I achieve this?
Have you tried
digraph G {
graph [ splines = false rankdir="LR" ]
a -> b [ label = "foo" ];
a -> b [ label = "bar" ];
}
I've checked it using http://www.webgraphviz.com/
Result looks like
Taken from stackoverflow question Graphviz, grouping the same edges

Finding all the rectangles within a given rectangle that do not intersect with an arbitrary shape

I need to find an algorithm to find the least number of overlapping rectangles within a given rectangle R that do not intersect with the union of a set of other rectangles contained within R. These inner rectangles can overlap. Here's a terrible ASCII drawing of an example R:
A-----------------B-------------------------+
| |
| |
| |
| |
| +--------+ |
| |........| |
| |........| |
C +---D........| |
| |.........+--+ |
| |.........| |
| ++........+------+ |
| |...............| |
G +---H...........| |
| |...........| |
| |...........| |
| |...........| |
| +-----------+ |
| |
| |
| |
E-------------I----F------------------------+
The rectangles here would include (A, D), (A, I), (G, F). This seems like a problem for which the solution is well-understood, but for which I simply lack the vocabulary. Any answers, pointers, RTFMs cheerfully and gratefully accepted. Thanks!
EDIT: As per #Paul's observation below, what I'm trying to do is find a set of rectangles that cover the space in R without covering any of polygon comprised of the union of the inner set. If that makes sense.
I believe this is one possible way to solve.
I will refer to the overlapping rectangles as "white", and the ones in the solution as "black"
First of all, let's assume we have a data structure suitable for search on intersection. One possible data structure is an Interval Tree, using points on one of the coordinates as intervals (for example, if a rectangle is defined by two points (x0,y0) and (x1, y1), use (x0, y1) as interval. The link also explain how to extend to higher dimensions (in your case you need 2).
I won't go in the detail of an implementation of such data structure, but let's assume we have one called Rectangles, with the following API defined:
void add(Rectangle r)
void remove(Rectangle r)
Rectangle[] getIntersecting(Rectangle r)
Rectangle[] getAdjacent(Rectangle r)
Ok, now create two instances of Rectangles called black and white. Initialize white with all the white rectangles. Initializie black with the R rectangle (the whole domain).
For each rectangle rw in white get the array arr of intersecting rectangles from black.
For each rectangle rb in black, determine the result of rw-rb. This is a set set of 0, 1, 2, 3 or 4 rectangles, depending on how the two rectangles intersect.
remove rw from white, and add the content of set to it. This may require merging rectangles from set with rectangle already in white, if such rectangles together form a larger rectangle (they're adjacent sharing one side)
remove rb from black
repeat from 1 until there are no more rectangles in black
Using some basic math, we could say the solution to your problem would be the decomposition of the rectilinear polygon R \ union(rs), where union(rs) represents the polygon inside R. Calculating R \ union(rs) can be done using the Greiner-Hormann-algorithm. Note that this step will result in a polygon with holes and - only if the inner polygon contains holes - multiple other polygons. The decomposition is described here (this is only an approximation, but i wasn't able to find a precise algorithm so far).

Arrange rectangles to anchor points without overlap

I have a set of rectangles of different size. Each rectangle has an anchor point on the 2 dimensional plane where the center of the rectangle should be placed. The rectangles should not overlap and the center of a rectangle should be as close as possible to its anchor point. So if the center of the rectangle_i is vector c_i and its anchor point is vector a_i then the target function would be min(sum_i((c_i - a_i)^2)). I am looking for an algorithm that approaches the optimal solution as much as possible in O(n).
The rectangles can not be rotated.
The inputs of the problem are:
the size of n rectangle
for each rectangle the coordinates of the associated anchor point.
The output should be the position of the rectangles i.e. coordinates of the center of each rectangle.
In the example below x signs the center of the rectangle and o the anchor points:
+-----------+
| |
+-----------+| x |
| || o |
| x |+-----------+
| o | +-------------+
+-----------+ | o |
+---------+| x |
| o || |
| x |+-------------+
| |
+---------+

Putting graph on a grid

I have a directed graph with no loops with the following additional information:
Every vertex has outdegree at most 4.
Every edge is labeled 'up', 'right', 'down' or 'left'.
If there is an 'up' edge from A to B, then there is a 'down' edge from B to A (i.e. it is symmetric).
All edges which start at the same vertex have different labels.
I am looking for an algorithm that would assign 2d integer coordinates to each vertex, such that y(B) > y(A) whenever there is an 'up' edge from A to B, and similarly for other types of edges. Moreover, edges should not intersect.
For example, this is a picture of such a graph with 8 vertices:
1-------2---3
| |
| 4 |
| | |
5---6---7---8
Note, that y(4) < y(1), since otherwise there would be intersecting edges.
I realize that the solution is far from unique, so one may require the result to have the minimal size in some sense.

Resources