I have a module that automatically outputs (in dot format) functions written in some kind of assembly language (the IR of my compiler). The nodes are the basic blocks printed using the 'record' shape. The problem is that the edges take a strange route, for example:
digraph {
node [shape = record];
n0[label="{<name> entry | <body> store i, 0\nstore sum, 0\ngoto test | {<target> target}}"];
n1[label="{<name> test | <body> t2 = load i\nif t4, body, done | {<true> true | <false> false}}"]
n2[label="{<name> body | <body> t5 = load sum\ngoto test | {<target> target}}"];
n3[color=firebrick3, label="{<name> done | <body> t9 = load sum\nret t9}}"];
n0:target:s -> n1:name:n
n1:true:s -> n2:name:n
n1:false:s -> n3:name:n
n2:target:s -> n1:name:n
}
And an image:
What can I do so that the edge from 'target' to 'test' is placed on the left side?
The simplest non-guru way is force that wayward link to attach on the "west" sides.
n2:target:w -> n1:name:w
This might work okay for this case. A more general way, but takes more thinking and coding, but would allow the edge to attach to the :s and :n if you desire that, is add an invisible node of size zero (color=white, or there might be a visibility attribute) and get from n2 to n1 using two edges. Have the arrowhead on only one of them. The invisible node would have to sit to the left of n1 or n2. Alas, my graphvis-fu is not strong enough to create a working example; maybe someone else can create one.
Related
I have a structure where a node either "Leads_to" another node or is "Colored_in" some color. The "Colored_in" relation and the color are just simplified additional information.
I now want for each leaf node regarding "Leads_to" all information of the parent nodes, as well as their additional information over the "Colored_in" relation.
To simplify this I will give a small sample of what I want:
CREATE (A:Key {name:'a'}),
(B:Key {name:'b'}),
(C:Key {name:'c'}),
(D:Key {name:'d'}),
(Black:Color {color:'black'}),
(Blue:Color {color:'blue'}),
(A)-[:Leads_to]->(B),
(A)-[:Leads_to]->(C),
(B)-[:Leads_to]->(D),
(A)-[:Colored_in]->(Black),
(B)-[:Colored_in]->(Blue),
(C)-[:Colored_in]->(Blue),
(D)-[:Colored_in]->(Black)
This code will create the following structure:
A-->Black
/ \
/ \
Blue<--B C-->Blue
/
/
Black<--D
This is just roughly drawn and both "Blue"s and "Black"s refer to the same instance of either "Blue" or "Black".
And as a result I want something like:
[{{name:'a',{color:'black'}; name:'b', {color:'blue'}; name:'d',{color:'black'}},
{{name:'a',{color:'black'}; name:'c', {color:'blue'}}]
Additionally a color can not "Leads_to" something nor be "Colored_in" something. This is just an example, the real path can be much longer. Also the nested result does not have to be in the format above, the parents just have to be clearly separated from each other (Ex.: ";") and should be in the right order.
Edit:
Maybe it helps, that not all potential information from other relations is required, but just from one relation in this case "Colored_in" and the name is fixed and the properties are known.
So maybe something like this?
MATCH path = (leaf:Key)-[:Leads_to*]->(end)
WHERE NOT ()-[:Leads_to]->(leaf) AND NOT (end)-[:Leads_to]->()
RETURN [node in nodes(path) | node {.name, color: [(node)-[:Colored_in]->(colorNode) | colorNode.color][0]}] as result
This uses list comprehension, map projection, and pattern comprehension so, for each node in each matched path, it outputs a custom map of the node name, and the color of the node's attached :Color node.
Results:
╒══════════════════════════════════════════════════════════════════════╕
│"result" │
╞══════════════════════════════════════════════════════════════════════╡
│[{"name":"a","color":"black"},{"name":"b","color":"blue"},{"name":"d",│
│"color":"black"}] │
├──────────────────────────────────────────────────────────────────────┤
│[{"name":"a","color":"black"},{"name":"c","color":"blue"}] │
└──────────────────────────────────────────────────────────────────────┘
StackOverflow is denoted as a place for AwesomeWM community support.
I would like to have a dedicated Tag in my AwesomeWM config where only three particular application will be running all the time. I managed to create new tag using sample config, and I managed to filer the applications using awful.rules.rules and place them into the tag.
I am experiencing troubles in understanding how AwesomeWM layout engine really works. I would like to achieve the following: three static columns of fixed widths, each application is located at its own column, when focus changes then no rearrangement happens, when any application is not running, then its reserved place is remain empty.
___________________
| | | |
| | | |
| A | B | C |
| | | |
| | | |
___________________
How do I specify layout in such case? Should I write my own one? Can I use flexible layout and specify position for client? What is the recommended correct way to achieve my goal?
I am experiencing troubles in understanding how AwesomeWM layout engine really works
A layout is a table with two entries:
name is a string containing, well, the name of the layout
arrange is a function that is called to arrange the visible clients
So you really only need to write an arrange function that arranges clients in the way you want. The argument to this function is the result of awful.layout.parameters, but you really need to care about
.clients is a list of clients that should be arranged.
.workarea is the available space for the clients.
.geometries is where your layout writes back the assigned geometries of clients
I would recommend to read some of the existing layouts to see how they work. For example, the max layout is as simple as:
function(p)
for _, c in pairs(p.clients) do
p.geometries[c] = {
x = p.workarea.x,
y = p.workarea.y,
width = p.workarea.width,
height = p.workarea.height
}
end
end
Should I write my own one? Can I use flexible layout and specify position for client?
Well, the above is the write-own-layout approach. Alternatively, you could also make your clients floating and assign them a geometry via awful.rules. Just have properties = { floating = true, geometry = { x = 42, y = 42, width = 42, height = 42 } }. However, with this you could e.g. accidentally move one of your clients.
What is the recommended correct way to achieve my goal?
Pick one. there is no "just one correct answer".
So I have simple graph. The most left nodes are 'Team' class. The second most right (gray one) is 'Sport' class node.
I need to find all Teams which relates to specific Sport
When I have only one Team node this query works:
MATCH {class:Team, as: team} --> {class: Sport, maxDepth: 10}
RETURN team.Abbreviation
After I've added second node of 'Team' class I've started to get this error:
java.lang.RuntimeException: Invalid pattern to match!
If I remove 'maxDepth' it works but returns nothing
What should I do to make it work?
It's definitely a bug, I'm checking it.
As a quick work-around you can add a condition to the first element in the pattern, so that you force the executor to start from there:
MATCH {class:Team, as: team, where:(true)} --> {class: Sport, maxDepth: 10}
RETURN team.Abbreviation
Even better, remove the "class" from the right hand:
MATCH {class:Team, as: team} --> {where: (#class = 'Sport'), maxDepth: 10}
RETURN team.Abbreviation
The problem here is that the pattern is being evaluated in the wrong direction (from right to left), with the above work-around you are forcing OrientDB to evaluate it from left to right
I have read other similar questions and answers on this site, but can't seem to find the answer to my particular problem. I am trying to encode a maze in Prolog.
From region 0, you can move freely to regions 1 or region 3. From region 3, you can move freely to region 0, region 4, or region 5, etc. I want to find the all paths of length 7 from the beginning to the end (from 0 to 14). I have encoded the problem in the following manner in SWI-Prolog:
region(0).
region(1).
region(2).
region(3).
region(4).
region(5).
region(6).
region(7).
region(8).
region(9).
region(10).
region(11).
region(12).
region(13).
region(14).
region(15).
connection(0,1). %connection exists between these two regions
connection(0,3).
connection(1,2).
connection(1,8).
connection(1,7).
connection(3,4).
connection(3,5).
connection(7,9).
connection(7,5).
connection(7,8).
connection(5,6).
connection(8,10).
connection(8,11).
connection(11,12).
connection(11,13).
connection(13,15).
connection(13,14).
double_link(X,Y) :-
region(X),
region(Y),
( connection(X,Y) | connection(Y,X) ). %can go from region X to region Y, and vice versa
path(X,Y) :-
double_link(X,Y).
path(X,Y) :-
double_link(X,Z),
path(Z,Y).
When I execute path(14,0). I get true. However, when I execute path(0,14)., I run out of local stack space. I don't know how that can be. Thanks for any help!
You said:
When I execute path(14,0). I get true.
That is half of the truth! Oh, even less than that! In fact you get true not once but many times!
?- path(14,0).
true
; true
; true
; true
; true
; true
; ... .
There is a simple way to avoid typing ; or SPACE all the time. Simply use the goal false.
?- path(14,0), false
loops.
And now, you can also add such false-goals into your program. In this manner you are ruling out parts of the program ; and if the remaining part still loops, you know that there must be a problem there. This is what I got:
region(0) :- false.
% ...
region(12) :- false.
region(13).
region(14).
region(15) :- false.
connection(0,1) :- false.
% ...
connection(13,15) :- false.
connection(13,14).
double_link(X,Y) :-
region(X),
region(Y),
( connection(X,Y) ; connection(Y,X) ).
path(X,Y) :- false,
double_link(X,Y).
path(X,Y) :-
double_link(X,Z),
path(Z,Y), false.
So in this remaining part that loop has to be addressed. It should be now self-explanatory, isn't it?
The problem arises because you can go in circles in the maze. E.g. in your maze you have the connections 0 - 1 - 7 - 5 - 3 - 0. You have not taken any measures to ensure that the search does not follow those circles blindly.
A usual approach would be to add an argument to your path predicate that contains the already visited regions (initially empty). Then you have to ensure when you go to a new location X that X is not in that list (e.g. with nonmember(X,Visited)).
I'm working on a patch that plays samples from a piano, which works in xcode to build an piano app for ipad. I'm trying to add an adsr to create sustain, but I can't seem to get it working. Could someone point me in the right direction? Thanks!
Patch:
https://docs.google.com/file/d/0B4-qHDgzbDB3VUlwM09FSEowZWM/edit
The ADSR is just an evelope which you are using to multiply the sound output with. However it is meant to be on a temporal axis together with the trigger of the sound. When I look at your patch I notice another thing: Why are you reloading the samples into the arrays every time you trigger them? The arrays should be filled on startup of the app, like this:
[loadbang]
|
[read -resize c1.wav c1Array(
|
[soundfiler]
Later, when you actually just want to play back, you do
[r c1]
|
[t b]
|
[tabplay~ c1Array]
|
[throw~]
and at one central point in your patch you can have
[catch~]
|
[dac~]
(add the main voulme there). Notice there are no connections between the three parts!