[gecode-users] Adding variables incrementally
Mikael Zayenz Lagerkvist
zayenz at gmail.com
Mon Apr 28 07:47:08 CEST 2008
On Fri, Apr 25, 2008 at 5:28 AM, Malcolm Ryan <malcolmr at cse.unsw.edu.au> wrote:
> In order to save memory, I've been trying to turn my planning code
> into a two stage in which the first stage only creates and constrains
> a certain critical subset of variables. When all the first-stage
> variables have been assigned, additional variables are created and a
> second stage of search occurs. The two stages are not completely
> independent however, and there may be failures in the second stage
> which require backtracking into the first. This should save memeory,
> since the second-stage variables don't have to be carried around
> during the first-stage search.
>
> I was hoping that I could do this simply by adding new variables and
> constraints in the copy constructor at the appropriate moment, but it
> seems that this does not work.
</snip>
> Is there any other way to do a two-stage search like this?
While the copy-constructor is not the right place to add constraints
and variables, there is a more fundamental problem with your scheme.
When all the variables are assigned, all branchings will be finished,
and thus the Space will be solved (status returns SS_SOLVED). The
search will therefore stop the search and return the current solution.
You could program you addition of variables and constraints as a
branching, but since you want to do this when all the original
variables are assigned, then I would suggest the following scheme.
FirstStageSpace first = new FirstStageSpace();
DFSIterator<FirstStageSpace> outerDFS =
new DFSIterator<FirstStageSpace>(first);
while (outerDFS.hasNext()) {
FirstStageSpace firstsolution = outerDFS.next();
SecondStageSpace second =
new SecondStageSpace(firstsolution);
DFSIterator<FirstStageSpace> innerDFS =
new DFSIterator<SecondStageSpace>(second);
if (innerDFS.hasNext()) {
System.out.println(innerDFS.next()); break;
}
}
I've not tested the above code, but I think the idea should be clear.
Cheers,
Mikael
--
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/
More information about the gecode-users
mailing list