This question already has answers here:
Graphviz, changing the size of edge
(2 answers)
Closed last year.
Is it possible to specify the thickness of lines (for edges and nodes) in Graphviz?
I've looked at the documentation about attributes, but I can't seem to find what I'm looking for. I'm surprised if it's not possible though.
Is penwidth what you are looking for?
Specifies the width of the pen, in points, used to draw lines and curves, including the boundaries of edges and clusters. The value is inherited by subclusters. It has no effect on text.
Related
This question already has answers here:
Minimum number of clicks to solve Flood-It-like puzzle
(2 answers)
Closed 7 years ago.
I'm working on a program supposed to solve a "Virus game". In short, we get a I x J board filled with fields coloured from an n-element colour pool. We start by marking the [0,0] field as "visited". The goal is to mark all fields as visited in the lowest amount of steps, each step being: choose a colour from the pool and colour each visited field with it. Then mark each field in regions neighboring visited fields of the same color as them as visited.
I've got some ideas about how to approach this problem, but I'd appreciate it if someone could point me to some good algorithm that I could modify to work in a reasonable time.
Here is the game link for reference if my explaination is unclear http://www.gry.pl/gra/virus_3
I'd completely forgotten about this game, which I used to enjoy playing from time to time.
I would probably just go greedy and pick the move that covers most new squares and, in case of a tie, pick the one that would give me most mobility in the following move.
This question already has answers here:
Find the set of largest contiguous rectangles to cover multiple areas [duplicate]
(3 answers)
Closed 9 years ago.
Suppose I have a grid containing 1's and 0's... How can I find the shortest list of rectangles (really, boundaries) that, together, cover all of the 1's and don't cover any 0's?
Currently, I'm repeatedly finding the largest rectangle in the grid, storing it's dimensions, and setting all of the cells in the area to 0, until they are all set to 0.
My two issues with this are: it seems very efficient, and I can't seem to prove that it actually covers the area in the fewest rectangles but I can't find any scenarios to disprove it either.
Update: I found a grid that disproves the method I described...
0000000
0000010
0111110
0000010
0000000
The horizontal string of 1's is the largest existing rectangle, but once removed, it splits the vertical string of 1's into two small rectangles... Clearly, this could be solved in just 2 rectangles.
A generic depth first search of the solution space may not be the most efficient, but will find the answer. You can even have it output every solution (for example the grid you show has two solutions where every '1' is covered using just two triangles.) This should be easy to implement and then you can use it as a baseline to compare with other methods, both to test them for correctness and to compare times.
A slight modification of your current method would solve that example grid: Find the 'largest' grid in terms of how many currently uncovered squares it covers, and instead of changing squares to '0' have a separate state that means '1' but already covered. This way later rectangles can span these squares but already covered squares don't count toward making rectangles 'larger'. (Of course this only works if you're allowed to have overlapping rectangles.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Basically I'm trying to get a "nice" image where all the small rectangles add up to the big rectangle, kind like:
*Later Edit to clarify some things:
I want to be able to draw something like this in a piece of software. So, what I need is closer to an algorithm.
All I need are some rectangles. I don't need them to have some predefined proportions just that they look like a rectangle. Anything between a square and a 3:1 width/height (or height/width) is fine. The extremely naive approach would be to just divide the width of the enclosing rectangle into the percentage that enclosed rectangles have but this will create thin slices and some of the smaller percentage rectangles will drop bellow 1px.
I need to find a way to split the rectangles on multiple rows.
*Second Edit: Problem SOLVED. I was looking for a TreeMap algorithm (as pointed out by Phpdna). Once I had the keyword I was able to quickly find a couple of python implementations that satisfied my requirements.
Treemap is an algorithm that can pack smaller rectangles into a map. You can recursively subdivide a plane into smaller tiles for example by splitting the plane along the 2 axis and save the result to a tree.
This approach guarantees that the small rectangles always cover the initial rectangle. so does any other approach which starts by constructing rectangles within an existing set of rectangles.
Draw a straight line from one edge of the plane to the opposite edge and parallel to the other two edges. Draw it in a location which produces 2 rectangles whose proportions are pleasing to your eye.
If you want another rectangle, draw a line from the first line, perpendicular to it, and extend that line to the edge of the plane. Again, choose its position so that the line creates rectangles of pleasing proportions. Now you have 3 rectangles.
Now, to get the 4th rectangle, choose one of the existing lines to start from and draw a line perpendicular to it until it reaches either the edge of the plane or an existing line. Again, take care to ensure that the proportions of the rectangles created are pleasing to your eye.
Continue until you have all the rectangles you want.
Personally I think that the above is the easy part, the difficult part is determining algorithmically where to draw the lines. I suggest you think of the Golden Ratio, it cousins the Fibonnaci numbers and other ratios such as the basis of the A series of paper sizes, ie 1:sort(2).
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to pack squares into circles?
I have a problem where I need to fit a bunch of different sized rectangles within a circle. All the rectangles must fit in the circle without overlapping each other and without overflowing the circle.
Assuming the rectangles can fit inside the circle how would one develop an algorithm to distribute them inside the circle?
All I can think of is to randomly distribute the rectangles over and over and test whether the conditions are met (brute-force).
It is a classic constraint problem, brute-force is one way to do it but there are other ways that can be better using things such as heuristics to help guide the algorithm to the solution. You would have to look up some constraint programming and bin packing papers on something like Google Scholar for some better algorithms.
Wikipedia has a good overview:
http://en.wikipedia.org/wiki/Packing_problem
As others have mentioned, an optimal solution (in say minimal area or uniform distriubtion) is likely to be NP-hard. Nevertheless, depending on your needs there are some great algorithms for packing differently sized rectangles into other rectangles. For example: Fast Optimizing Rectangle Packing Algorithm for Building CSS Sprites:
This article describes a fast algorithm to pack a series of rectangles of varying widths and heights into a single enclosing rectangle, with no overlap and in a way that minimizes the amount of wasted space in the enclosing rectangle. [...] shows step by step how the algorithm arrives at the optimal enclosing rectangle.
Note that in the above procedure the bounding rectangle is allowed to vary (nor am I convinced that the solution is the optimal enclosing rectangle). You can approximate a circle by breaking it up into discrete rectangles.
While not a complete solution to what you are looking for, I think this may be a good first step.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
how do I create a line of arbitrary thickness using Bresenham?
How can I use Bresenham algorithm to draw lines of more than a pixel thick?
Do i have to run the algorithm many times with an offset from x and y?
One thing you can do is to calculate using the slope of the line, a unit offset in both orthogonal directions. Multiply this by your thickness, and take the offsets at both endpoints. You now have effectively the bounds of a rotated rectangle. Then, rather than using Bresenham to draw the line, use a fast polygon fill.
No, the simple way is just plot a stencil at every (x, y) location produced by the algorithm that is larger than one pixel, e.g. a disc.
But that's of course inefficient in the sense that you plot the same pixel many times. It's however easy to implement and works robustly with even odd-shaped or multicolored stencils.