node by node copy

Erik Zuurbier F.S.A.Zuurbier@inter.nl.net
Sun, 4 Jan 1998 09:06:56 +0100 (MET)


Hi,
I am writing an optimization program in which a large and complicated
datastructure is used to encode a candidate solution to a (scheduling,
planning, rostering, etc.) problem. Guided partly by random numbers, the
program then goes through a long series of manipulations/perturbations
of this datastructure, each time measuring the solution quality. This
all works in the spirit of Simulated Annealing. Part of the idea is
that at regular intervals, the program makes a back-up copy of the 
datastructure. After that it carries on working on the original. Then
a while later, it compares the solution quality achieved, with the
solution quality of the back-up. The program continues with the best.

The good thing is that I can use unique arrays in the datastructure
to achieve an acceptable speed in this optimization program.
The bad thing is that I don't know how to make a back-up copy of the
datastructure so that the uniqueness-check in the Clean compiler will
be satisfied. I think I need a function with the following type.

Copy :: *a -> (*a,*a)

But instead of just creating an extra reference to its argument, which
the uniqueness-system would rightfully not allow, it should make a
node by node copy of its argument, so that a completely detached data-
structure is made, after which destructive updates can be done on
each of them. Is this possible in Clean? I think my application would
justify it.

I think (but I am not completely sure) that I could do it by writing
the back-up copy to a file, and read it back in later, but that is
of course slow. It may also be possible by using the new Object IO
library's message passing (which makes lazy copies, if I am not
mistaken). Both of these solutions seem too complicated and cumbersome
though.

Can someone write the Copy function for me?

Regards Erik Zuurbier