Relaxation Graphs

A relaxation graph is a way of simulating the movement of a number of objects which influence each other in various ways. One such way is to join the objects in a loop with elastic bands. Each object is thus connected to two others and is pulled by the tension in the bands. If the objects start off in a random arrangement on a flat surface, and let go, they will move in such a way as to relax all of the bands until they have no tension at all. Only then will they stop.

To simulate this movement, it is sufficient to treat each object in turn, and to move it in a direction that reflects the distance from it to its neighbors. This is a relaxation algorithm on a relaxation graph. The graph for this type of relaxation is a connected ring, where each node is only connected to two others.

Your task is to simulate this type of relaxation for any number of objects, in any starting arrangement, and to repeat the whole procedure any number of time, with different parameters, under user control.

The relaxation algorithm

The diagram below shows a typical starting ring and its eventual relaxed form.

The algorithm can be developed by considering one node in the graph, and its two neighbors:

Moving the central node is done by splitting the lines connecting it and its neighbors into their x and y components, taking a fraction of each and averaging them to form a resultant vector. The fraction is variable, but should take into account the minimum distance between the nodes which corresponds to the length of the elastic band connecting them. The formulae are then as follows:

The component distances are:

The distances are then:

and the moving increments are:

and

where speed is a number that controls how fast the relaxation happens.

Object analysis

The requirements of the project mean that dynamic allocation is a good way to allocate an array of nodes for the graph. Each node will have x and y coordinates in them, and the array that represents the graph will be of pointers to nodes. This ensures that a new graph can be created with a number of nodes requested from the user, and destroyed when it is no longer needed.

Other number to be requested from the user are the speed of relaxation, the minimum elastic band length, and the maximum number of relaxation cycles to be used.

Nodes should be positioned at random in a region 500 by 500 units. Coordinates are best represented by floating-point numbers.

Coding the algorithm

Use the normal program structure: an application class with a "run" function. Classes will be necessary for the graph and for each node in the graph.

The relaxation routine is a graph operation. It is a loop (terminated either by a number of cycles, or the lack of movement of the nodes - eventually they must stop) in which each node is moved in turn according to the scheme above. You can move each node during the cycle, or calculate each node's new position and then move them all at the end of the cycle - it doesn't seem to matter which.

Testing

Of course try your program out on only two nodes - they should move together until their separation is less than the minimum band length. I used the following values in my version:

number of nodes = 2 to 20; speed = 5 to 50; band length = 10 to 100; number of cycles = 100 to 2000

Submitting your assignment

Your program should print out the initial positions of all the nodes, the relaxation speed and the band length, and the final distances around the graph after relaxation. They should all be less than or equal to the band length. Also submit the source code, a problem statement and description, and your object design.

Due date

November 21st. before 5pm.