Solution-specific Visio Discussions > Artistic and Graphical Effects

Applying the Four Color Theorem in VISIO?

(1/4) > >>

Bald Eagle:
I'm playing with the US Map stencil, and was wondering if anyone's automated the Four Color Theorem to apply fill properties to multiple selected objects / subgroups.

https://en.wikipedia.org/wiki/Four_color_theorem

I'm thinking that this might require some VBA, unfortunately most of my coding knowledge is in C++ with a smattering of other languages.
(The last time I actually wrote a macro for an M\$ product was in the mid 90's while making some cool Excel spreadsheets for the now defunct American Cyanamid.   :o )
http://www.nj.com/mercer/index.ssf/2014/09/owners_of_long-vacant_american_cyanamid_site_in_west_windsor_begin_discussions_on_possible_redevelop.html

wapperdude:
I've not seen anyone do this.  Strikes me as difficult for Visio,  unless there is a method in the object model to trace a shapes border.   The bounding,  selection box would be of minimal use.   The newer versions might have the methods needed,  just don't know.

Wapperdude

georgejost:

--- Quote from: Bald Eagle on February 15, 2016, 06:02:25 PM ---I'm playing with the US Map stencil, and was wondering if anyone's automated the Four Color Theorem to apply fill properties to multiple selected objects / subgroups.

--- End quote ---

Very unlikely. To do that, you'd have to understand the proof and the 1200+ isomorphic cases involved

Then you'd would have to understand visio's interfaces

Very rare to get somebody capable of the former interested in the latter

It could be, that real maps are simpler than the 1200 cases tho.

Yacine:
Hi guys,
sorry, but I don't agree with the given answers.
The solution is not completely trivial, but definitely solvable.
Neither is it too difficult, nor is it too special. A solution could color not only maps, but all kind of graphs that need to be colored automatically. So IMHO this is a tool to develop.

In my opinion there would be 2 steps in the solution:

1) Find common borders:
Make a routine that creates a small shape (eg a rectangle). The smaller the more precise, but also the longer the processing.
Find the borders of the selection or use the whole page as canvas.
Now let the shape travel row by row over the whole canvas and check the shapes it overlaps. SpatialNeighborhood is the function to use.
Everytime the shape overlaps 2 or more shapes, you'll have found a border and can use the result of the SpatialNeigborhood to store this border either in the shapes themselves (a user or prop cell) or an adequate construct in Code (array, collection, etc.).
After having filtered out duplicates, you'll have the borders as intelligent data structure.

2) Color the shapes
a) Do it the right way and find - or work out - an algorithm to find the optimal solution.
In about a quater of an hour I did find a complete code in Pascal. This code would need to be translated in VBA, VB.NET or any other suitable language. (Sorry Paul)

b) Use a naive method by starting at shape #1.
Color its neighbors in 3 other colors and mark the colored shapes as finished.
Take the next uncolored shape and repeat the code.
If no solution is found either mark the shape as such (color, text, ...) to let the user correct the result or iterate by tracking back and choosing anoter path (color).

Thank you Bald Eagle for this challenge. I hope you'll keep up and will work out a nice solution for yourself (and the community).
Cheers,
Y.

Bald Eagle:
Heh,
Sure thing, Yacine   ;)
I know how some of you folks just can't be happy without such a challenge to ponder in the off moments of the day, or while in that twilight sleep where "the circus" starts.  Having a light, a pencil, and notepad next to the bed definitely makes for an easier time "getting it out" and letting the brain settle down.   Or sometimes there's just an "ah, screw it" - I wasn't going to bed anytime soon anyway"....    ;D

I would think that one could generate some sort of connectivity diagram / table, and use some attribute about the perimeters to see if shapes are adjacent.   Then start off with some given shape, and color that A.   That leaves B, C, and D.
Must be some way to use that as a process of elimination to puzzle out what color to use for any given shape.
"All ya gotta do is...."    :o

I'll see what I can understand, and what's available on StackOverflow, news.povray.com, Wolfram, etc.
http://mathworld.wolfram.com/Four-ColorTheorem.html

Glad you liked this little puzzle.   :)