How to make PlantUML state diagrams cleaner? - uml

Is there a way to make State diagrams more organized and clean in PlantUML easily?
My fear was the more stuff I add, the more convoluted it becomes and it did happen.
I tried using skinparam linetype ortho setting which made things a bit better but still not enough. Should be using a different type rather than state diagrams which may fit in well? I'm new to PlantUML and still exploring the options.
scale 350 width
state A #khaki
state B #BUSINESS
state C #bisque
state D #APPLICATION
state E #IndianRed
state F #MediumTurquoise
state G #Salmon
state E #HoneyDew
state G #PaleTurquoise
state H #Aqua
state JOIN_STATE_UNDEFINED <<join>>
state JOIN_STATE_FAILED <<join>>
state JOIN_STATE_STARTUP_REQ <<join>>
state JOIN_STATE_SHUT_DOWN <<join>>
[*] --> A
A --> B
B --> C
C -[#Red]-> JOIN_STATE_FAILED
C -[#IndianRed]-> JOIN_STATE_UNDEFINED
C --> D
C --> JOIN_STATE_SHUT_DOWN
D --> JOIN_STATE_SHUT_DOWN
F --> JOIN_STATE_SHUT_DOWN
G --> JOIN_STATE_SHUT_DOWN
H --> JOIN_STATE_SHUT_DOWN
D --> F
D --> D
D -[#Red]-> JOIN_STATE_FAILED
'D --> G : EV_MODULE_STARTUP_REQUEST fails
D -[#IndianRed]-> JOIN_STATE_UNDEFINED
'D --> E : EV_MODULE_STARTUP_REQUEST timeout
F --> G
F -[#Red]-> JOIN_STATE_FAILED
F -[#IndianRed]-> JOIN_STATE_UNDEFINED
G --> H
G -[#Red]-> JOIN_STATE_FAILED
G -[#IndianRed]-> JOIN_STATE_UNDEFINED
E -[#Crimson]-> G
E -[#FireBrick]-> E
E --> A
JOIN_STATE_UNDEFINED -[#IndianRed]-> E
JOIN_STATE_FAILED -[#Red]-> G
JOIN_STATE_SHUT_DOWN --> E
#enduml

Related

pivot table help in excel to get a tree map

i need help in resolving a time consuming job
Input example
part number
where used
a
d
a
l
b
e
c
f
d
g
d
m
g
h
f
i
h
j
l
k
Result tree i need:
a
d
g
h
j
a
l
k
i am using pivot tabe to get this, but i cant arrive at that, kindly provide your guidance to make it

python3 - create list of strings elliptically

EDIT: I do not want your code! just help me think of a nice way to do it :)
I have a string with 25 characters:
ABCDEFGHIKLMNOPQRSTUVWXYZ
and I want to create a matrix5*5 given a position and a direction,
position can be one of the corners and direction can be clock or counter clock.
so if I gave this arguments:
create((0,0), clock)
I want to recive:
["ABCDE", "QRSTF", "PYZUG", "OXWVH", "NMLKI"]
and I could then print it and recieve:
A B C D E
Q R S T F
P Y Z U G
O X W V H
N M L K I

Split a single row of data (dat file) into multiple columns

I want to split a row of data into multiple columns like
a.dat
A B C D E F G H I J K L M N O P Q R S T U
into
b.dat
A B C D E F G
H I J K L M N
O P Q R S T U
I have tried using the pr function
pr -ts" " --columns 7 --across a.dat > b.dat
But it doesn't work, b.dat is the same as a.dat
I like fold for these thingies:
$ fold -w 14 file
A B C D E F G
H I J K L M N
O P Q R S T U
With -w you set the width you desire to have.
Although xargs is more useful if you want to split based on number of fields instead of characters:
$ xargs -n 7 < file
A B C D E F G
H I J K L M N
O P Q R S T U
Regarding your attempt in pr: I don't really know why it is not working, although from some examples I see it doesn't look like the tool for such job.

Red Black Trees: Kahrs version

I'm currently trying to understand the Red-Black tree implementation as given by Okasaki and delete methods by Kahrs (the untyped version).
In the delete implementation a function app is used, which seems to "merging" the children of the node being deleted. And again, the algorithm seems to use the same "break" the Red-Red property rather than black height (please correct me if I'm wrong).. We are always creating Red Nodes (even if we break the Red-Red property). walk down the subtree rooted at the node being deleted, correct the red-red violations, once we reach the leafs, we start going up the path (starting at the "new tree" merge created) fixing the red-red violation up the path.
app :: RB a -> RB a -> RB a
app E x = x
app x E = x
app (T R a x b) (T R c y d) =
case app b c of
T R b' z c' -> T R(T R a x b') z (T R c' y d)
bc -> T R a x (T R bc y d)
app (T B a x b) (T B c y d) =
case app b c of
T R b' z c' -> T R(T B a x b') z (T B c' y d)
bc -> balleft a x (T B bc y d)
app a (T R b x c) = T R (app a b) x c
app (T R a x b) c = T R a x (app b c)
I'm not able to see how we are "not creating" / "fixing" the black height violation? deleting a black node would create bh-1 and bh subtrees at some node up the path.
Results from this paper, looks like this implementation is really fast and that the "merge" method might be the key to answering the increase in speed.
any pointers to an explanation for this "merge" operation would be great.
please note this is not a homework problem or anything else. I'm studying independently the implementations given in Okasaki and fill in the "messy" deletes too.
Thanks.
Given that there is a lot that can be said on this topic, I'll try to stick as closely as possible to your questions, but let me know if I missed something important.
What the hell is app doing?
You are correct in that app breaks the red invariant rather than the black one on the way down and fixes this on the way back up.
It appends or merges two subtrees that obey the order property, black invariant, red invariant, and have the same black-depth into a new tree that also obeys the order property, black invariant, and red invariant. The one notable exception is that the root or app rb1 rb2 sometimes is red and has two red subtrees. Such trees are said to be "infrared". This is dealt with in delete by just setting the root to be black in this line.
case del t of {T _ a y b -> T B a y b; _ -> E}
Claim 1 (Order property) if the inputs rb1 and rb2 obey the order property individually (left subtree < node value < right subtree) and the max value in rb1 is less than the min value in rb2, then app rb1 rb2 also obeys the order property.
This one is easy to prove. In fact, you can even sort of see it when looking at the code - the as always stays to the left of the bs or b's, which always stay to the left of the cs or c's, which always stay to the left of the ds. And the b's and c's also obey this property since they are the result of recursive calls to app with subtrees b and c satisfying the claim.
Claim 2 (Red invariant) if the inputs rb1 and rb2 obey the red invariant (if a node is red, then both its children are black), then so do all the nodes in app rb1 rb2, except for possibly the root. However, the root can be "infrared" only when one of its arguments has a red root.
Proof The proof is by branching on the patterns.
For cases app E x = x and app x E = x the claim is trivial
For app (T R a x b) (T R c y d), the claim hypothesis tells us all of a, b, c, and d are black. It follows that app b c obeys the red invariant fully (it is not infrared).
If app b c matches T R b' z c' then its subtrees b' and c' must be black (and obey the red invariant), so T R (T R a x b') z (T R c' y d) obeys the red-invariant with an infrared root.
Otherwise, app b c produced a black node bc, so T R a x (T R bc y d) obeys the red invariant.
For app (T B a x b) (T B c y d) we only care that app b c will itself obey the red-invariant
If app b c is a red node, it can be infrared but its subtrees b' and c', on the other hand, must obey the red invariant completely. That means T R (T B a x b') z (T B c' y d) also obeys the red invariant.
Now, if bc turns out to be black, we call balleft a x (T B bc y d). The neat thing here is that we already know which two cases of balleft can be triggered: depending on whether a is red or black
balleft (T R a x b) y c = T R (T B a x b) y c
balleft bl x (T B a y b) = balance bl x (T R a y b)
In the first case, what ends up happening is that we swap the color of the left subtree from red to black (and doing so never breaks the red-invariant) and put everything in a red subtree. Then balleft a x (T B bc y d) actually looks like T R (T B .. ..) (T B bc y d), and that obeys the red invariant.
Otherwise, the call to balleft turns into balance a x (T R bc y d) and the whole point of balance is that it fixes root level red violations.
For app a (T R b x c) we know that a and b must be black, so app a b is not infrared, so T R (app a b) x c obeys the red invariant. The same holds for app a (T R b x c) but with letters a, b, and c permuted.
Claim 3 (Black invariant) if the inputs rb1 and rb2 obey the black invariant (any path from the root to the leaves has the same number of black nodes on the way) and have the same black-depth, app rb1 rb2 also obeys the black invariant and has the same black-depth.
Proof The proof is by branching on the patterns.
For cases app E x = x and app x E = x the claim is trivial
For app (T R a x b) (T R c y d) we know that since T R a x b and T R c y d have the same black depth, so do their subtrees a, b, c, and d. By the claim (remember, this is induction!) app b c will also obey the black invariant and have the same black depth. Now, we branch our proof on case app b c of ...
If app b c matches T R b' z c' it is red and its subtrees b' and c' will have the same black depth as app b c (itself), which in turn has the same black depth as a and d, so T R (T R a x b') z (T R c' y d) obeys the black invariant and has the same black depth as its inputs.
Otherwise, app b c produced a black node bc, but again that node has the same black depth as a and d, so T R a x (T R bc y d) as a whole still obeys the black invariant and has the same black depth as its inputs.
For app (T B a x b) (T B c y d) we again know immediately that subtrees a, b, c, and d all have the same black depth as app b c. As before, we branch our proof on case app b c of ...
If app b c is a red node of the form T R b' z c', we again get that b', c', a, and d have the same black-depth, so T R (T B a x b') z (T B c' y d) also has this same black depth
Now, if bc turns out to be black, we apply the same reasoning as in our previous claim to figure out that the output balleft a x (T B bc y d) actually has the form either
T R (T B .. ..) (T B bc y d) where (T B .. ..) is just a recolored as black so the overall tree will satisfy the black invariant and will have black-depth one more than any of a, b, c, or d, which is to say the same black-depth as the inputs T B a x b and T B c y d).
balance a x (T R bc y d) and balance maintains the black invariant.
For app a (T R b x c) or app (T R a x b) c, we know that a, b, and c all have the same black-depth and consequently, which means app a b and app b c have this same black-depth, which means T R (app a b) x c and T R (app a b) x c also have this same black-depth
Why is it fast?
My Racket is a bit rusty so I don't have a great answer to this. In general, app makes delete fast by allowing you to do everything in two steps: you go down to the target site, then you continue downwards to merge the subtrees, then you come back up fixing the invariants as you go, all the way to the root.
In the paper you reference, once you get down to the target site, you call min/delete (I think this is the key difference - the rotations otherwise look pretty similar) which will recursively call itself to find the element in the subtree that you can plop into the target site and the state of the subtree after that element has been taken out. I believe that last part is what hurts the performance of that implementation.

Count if excel not working for letter C

My count if function won't work for the letter "C". I checked for spaces with len function and I am super confused. Thanks for the help.
#of Accident Type
A 28
B 19
C =COUNTIF(A2:A101, "*C*")
D 17
E 9
F 9
Accidents
A
B
D
A
A
F
C
A
C
B
E
B
A
C
F
D
B
C
D
A
A
C
B
E
B
C
E
A
B
A
A
A
B
C
C
D
F
D
B
B
A
F
C
B
A
C
B
E
E
D
A
B
C
E
A
A
F
C
B
D
D
D
B
D
C
A
F
A
A
B
D
E
A
E
D
B
C
A
F
A
C
D
D
A
A
B
A
F
D
C
A
C
B
F
D
A
E
A
C
D
Seems to work fine, but I did not put the asterisks. Each cell (copied form the data example you gave) only has the character : no spaces...
Probably it does not work, because the C is written in Cyrillic. To make sure, whether this is the case, write C in English additionally and try to change the font to something Fancy - e.g. Algerian. Then the two C will be obviously different:
=COUNTIF(A2:A101,"*C*" )
For some reason its working now... I changed the font and messed around with it.
Thanks again for the help!!!!

Resources