How to get a non-linear layout in class diagram? - plantuml

A class diagram seems to always be linear - either in horizontal or, if I add left to right direction, vertical.
However, in many cases the layout could do a better use of the screen space. Check this one out:
This last diagram could easily have A as a center in the middle of the screen and then have all other classes around it.
I know that PlantUML uses Graphviz behind the curtains to do the layout, which supports a variety of styles. So, can I tell PlantUML to do something smarter when it comes to class diagrams?

Do you mean something like
produced by
B -l-* A
C -l-* A
A *-r- D
A *-r- E
I defined the classes in ascending order A, B, ..E. Check out the Layout Section of the new Hitchhiker's Guide for details. Or the Section Changing arrows direction in the class diagram page of plantuml.com.
(Tested in Linux Mint 20 Ulyana, Emacs 26.3, org mode 9.3.1, PlantUml 1.2018.13 src block, graphviz 2.43.0)

Looking at the code of your second example, we see it has horizontal associations, e.g., A *- B. If you always use vertical associations, e.g. A *-- B, GraphViz does always does a better job:
A *-- B
A *-- C
A *-- D
A *-- E
A *-- F
A *-- G
A *-- H
A *-- I
A *-- J

Related

Rubik's cube Thistlethwaite algotithm, check for good edges

I'm trying to build a rubik's cube solver in C using the Thistlethwaite algorithm.
I'm storing a cube as an array of 6 uint64_t integers (Faces).
Each of this faces stores 8 colors as one byte.
This structure let's me easily rotate faces using bit manipulation but I wonder if I should use something else that would be more appropriate for the Thistlethwaite algorithm.
The issue I'm having is checking if a cube is contained in the sub group G1 <L, R, F, B, U2,D2>
From what I understand, a cube that has correctly orientated edges is contained in this subgroup.
(see https://www.jaapsch.net/puzzles/thistle.htm)
The paper at the end of the page clearly indicates how to check if an edge is good or not but I could not find a way to implement it.
The question I have is: How to check in code if an edge is correctly oriented given a scrambled cube ?
According to the article, page 1:
Getting into G1
An edge piece is BAD if in taking it home an odd
number of quarter-turns of U and D faces is needed; otherwise it is GOOD
A different way of putting this: if you can manage to bring an edge home without ever using a U or D turn (so only turning the L, F, R and B faces), then an edge is good, otherwise it is bad.
So let's say you have a scrambled cube and are looking at one particular edge piece. Identify the position where it should end up (obviously based on the centre pieces). Let's say that one of the two colours of this edge is red. Then identify where the current place of that red face is in the following image:
Do the same for the place where that red side should end up.
If both places have the same colour (yellow or blue) in the above image, then the edge is good. If they have different colours in the above image, then the edge is bad.
You can easily see that if you had taken the other colour side of the edge in question (the not-red one), you would arrive at the same conclusion with this method.
Up to you to translate this to your data structure.

Retrieve inferred object property filler in OWL ontology

How can I retrieve for each class in my ontology O all (inferred) existential restrictions?
My current approach is to iterate over all pairs of classes and object properties, and check if the restriction is satisfied:
for each subclass (C, D) in Classes(O) × Classes(O):
for each property P defined in Object properties(O):
if C and P some D is satisfiable:
yield (C, P, D)
This is pretty slow as I am working with the vaccine ontology which has 4557 classes and 107 object properties. Even it is a one-time computation, I may learn something from seeing better approaches.
Using the OWLKnowledgeExplorerReasoner from JFact as suggested here did not work because it crashed when retrieving the neighbour labels (see my test case)
Can you suggest any improved solution using OWLAPI, Protégé or any other tool? Also, it would be nice to only retrieve the most specific filler classes.
Thanks!
First of all, your check is wrong. For an empty ontology C and P some D would be satisfiable, which is not what you want. You have to check whether C and not (P some D) is unsatisfiable (alternatively, you can just check isSubsumedBy(C, P some D)).
You can improve the exploration time if you use some techniques that are used for classification, e.g.:
if C is a subclass of P some D, then so are all sub-classes of C
if C is not a subclass of P some D, then so are all super-classes of C
Similar rules for sub/super classes/properties of P and D
You can give names to all the P some Thing expressions. After classification you can restrict the search for C only to sub-classes of these concepts.
It also helps if you can narrow down the problem. Do you really need to check all pairs and all properties?
Using the OWLKnowledgeExplorerReasoner from JFact as suggested here did not work because it crashed when retrieving the neighbour labels (Exception Unreachable situation!).
Could you please provide a test case and a full stacktrace of the problem so we can fix it? Did you try to use the same with FaCT++?

Create a view which is a vector created from different columns?

For matrices A, B, and C, and some integer i, is there an easy way to make view whose result is
vec([A[:,i];B[:,i];C[:,i]])
without creating any temporaries? My current try is:
A = rand(4,4); B = rand(4,4); C = rand(4,4)
[#view(A[:,1]);#view(B[:,1]);#view(C[:,1])]
that obviously creates the vector at the end instead of a view to the four columns stacked as a vector.
It looks like you're looking for a lazy version of cat. Here's one implementation:
lazy cat http://www.mrwallpaper.com/wallpapers/Lazy-Cat.jpg
But in all seriousness, consider the (still experimental) solution ahwillia has here: CatViews.jl. In your situation, CatView(#view(A[:,1]), #view(B[:,1]), #view(C[:,1])) would work.

Check if pixel is inside a polygon

I want to know certain method so that i can tell if a pixel is inside a 4-point polygon or quadrilateral figure (not necessarily to be rectangle) given the 4 co-ordinates of that polygon.
I tried several methods, but none of them worked really well.
Thanx and Regards
Uday Gupta
A simple method is to use areas : You first decompose your polygon into two triangles ABC and CDA, and check whether the point is in either triangle.
For that, assuming the triangle ABC for example and your point to test is M, you can test whether the area of the triangle ABC is equal to the sum of the areas of ABM + BCM + CAM.
Computing the area of a triangle is done using half the norm of the cross product.
Another solution that directly uses cross products can be found here:
http://www.blackpawn.com/texts/pointinpoly/default.html

Recognizing tetris pieces in C

I have to make an application that recognizes inside an black and white image a piece of tetris given by the user. I read the image to analyze into an array.
How can I do something like this using C?
Assuming that you already loaded the images into arrays, what about using regular expressions?
You don't need exact shape matching but approximately, so why not give it a try!
Edit: I downloaded your doc file. You must identify a random pattern among random figures on a 2D array so regex isn't suitable for this problem, lets say that's the bad news. The good news is that your homework is not exactly image processing, and it's much easier.
It's your homework so I won't create the code for you but I can give you directions.
You need a routine that can create a new piece from the original pattern/piece rotated. (note: with piece I mean the 4x4 square - all the cells of it)
You need a routine that checks if a piece matches an area from the 2D image at position x,y - the matching area would have corners (x-2, y-2, x+1, y+1).
You search by checking every image position (x,y) for a match.
Since you must use parallelism you can create 4 threads and assign to each thread a different rotation to search.
You might not want to implement that from scratch (unless required, of course) ... I'd recommend looking for a suitable library. I've heard that OpenCV is good, but never done any work with machine vision myself so I haven't tested it.
Search for connected components (i.e. using depth-first search; you might want to avoid recursion if efficiency is an issue; use your own stack instead). The largest connected component should be your tetris piece. You can then further analyze it (using the shape, the size or some kind of border description)
Looking at the shapes given for tetris pieces in Wikipedia, called "I,J,L,O,S,T,Z", it seems that the ratios of the sides of the bounding box (easy to find given a binary image and C) reveal whether you have I (4:1) or O (1:1); the other shapes are 2:3.
To detect which of the remaining shapes you have (J,L,S,T, or Z), it looks like you could collect the length and position of the shape's edges that fall on the bounding box's edges. Thus, T would show 3 and 1 along the 3-sides, and 1 and 1 along the 2 sides. Keeping track of the positions helps distinguish J from L, S from Z.

Resources