[gecode-users] Value selection when branching
Lars Otten
ottenl at student.chalmers.se
Thu Feb 9 19:49:59 CET 2006
Hi again,
On 02/07/06 17:16, Lars Otten wrote:
> I've just put up an order for Knuth's book at our library, I will look into
> this and let you know how it works out. Thanks for the hints so far. :)
As promised I want to give you a brief update:
Things worked out quite well. I created a new class ViewValRandBranching,
which inherits from ViewValBranching with two additional fields (for the
random seeds). Upon creation of the branching these fields are initialised
to random numbers from a random number generator similar to the one in
test/random.cc pointed out by Mikael; one field is used as random seed for
view selection, the other one for value selection.
Now the two important methods are basically just wrappers around the old ones:
ViewValRandBranching<View,Val,ViewSel,ValSel>::branch(void) {
unsigned int tmpseed = ge_srand(); // get current random seed
ge_srand(rseedView); // set 'private' random seed
unsigned int s = ViewValBranching<View,Val,ViewSel,ValSel>::branch();
ge_srand(tmpseed); // restore original random seed
return s;
}
ViewValRandBranching<View,Val,ViewSel,ValSel>::commit
(Space* home, unsigned int a, BranchingDesc* d) {
unsigned int tmpseed = ge_srand(); // get current random seed
ge_srand(rseedVal); // set 'private' random seed
ExecStatus s =
ViewValBranching<View,Val,ViewSel,ValSel>::commit(home, a, d);
ge_srand(tmpseed); // restore original random seed
return s;
}
And, lo and behold, now it seems to work! The same tests I did earlier (e.g.
with all-intervall) now nicely return the same number of solutions for all
different random seeds I tried (also the same number as the nonrandom
version). :-)
Thanks for the help with this,
/Lars
More information about the gecode-users
mailing list