Advertisement

Genetic Algorithm in realtime path layout

Started by February 23, 2006 10:05 AM
2 comments, last by bluntman 18 years, 11 months ago
I am in the process of creating a user interface for setting up constraint systems (for mapping 3D animation), which basically involves a lot of boxes with tabs for input and output and a lot of lines connecting tabs to each other (outputs of one box go to inputs of another). This is what it looks like at the moment: constraintSystem.jpg This is a very simple system I threw together in testing (it doesn't actually do anything useful), and I expect most systems that will be created with this program to be far more complex (10x as many boxes at least). What I want to do is tidy up the display by having the connecting lines automatically arrange themselves in the neatest way they can using right angles only. I want it to be a realtime so that the lines will reposition as the user moves boxes around. I have been told that the GA is the method usually used to solve these kind of systems, but GA uses random functions to generate populations which would mean a realtime update would jump about a lot (I would imagine). The system I am thinking of using to represent the routes is like so: All calculation is done from the input to the output. There are nodes along the line. Each node contains a fractional distance along the line, and a flag to tell it whether it should be drawn horizontal then vertical, or vice versa

Horizontal then vertical looks like this:
    node        
      *-------*[box2] input
      |  horiz
      |vert
      |
[box2]* output
Vertical then horizontal looks like this:
              *[box2] input
              |  
              |vert
       horiz  |
[box2]*-------*node       
output




The distance along the line of the first node is of course calculated and fixed as there is only two positions it can be and still form a right angle. To add another node, a position is chosen along the line and the line is split:

    node        
      *-------*[box2] input
      |  
      *new node
      |
[box2]* output




Then the segment of line containing the first node can be randomly flipped to being either horizontal then vertical or vice versa.

Horizontal then vertical:
            
      *-------*[box2]
      |  
      *
      |
[box2]* 
Vertical then horizontal
            
               *[box2]
               |  
      *--------*
      |
[box2]*




This process can be repeated however many times and the fitness function is a combination of the distance of the line, and how many other boxes and lines it intersects. I would like the result to look something like this: constraintSystem2.jpg The problem (as I said above) is that random splits are going to be different everytime, and as it is going to be realtime I can't calculate to the exact best solution, so the lines will jump about unpleasantly. Has anyone here got any ideas about better methods or tweaks that I can use? Thanks alot!! PS. Could someone please tell me how to keep leading spaces so I don't have to use source boxes for ASCII art?! [Edited by - bluntman on February 23, 2006 10:24:59 AM]
This is a graph layout problem. There is an immense amount of literature on solving such problems, with GAs being just one possible approach (and not the one that I would start with). You can start with Google and try also Citeseer and scholar.google.com; try using 'graph layout' as a starting point. Typically, methods for graph layout revolve around solving constraint satisfaction problems.

Cheers,

Timkin
Advertisement
Thanks Timkin, I am pulling apart graphviz to see if I can find what I want.
Sometimes its just a matter of knowing what something is even called!
AP:
I am using OpenGL and C++ for the constraints interface, trying to make it portable.

This topic is closed to new replies.

Advertisement