[gecode-users] constraints on solved spaces
Guido Tack
tack at ps.uni-sb.de
Tue Feb 5 09:20:15 CET 2008
stanio at cs.tu-berlin.de wrote:
> A question:
>
> When I post a constraint on a solved space, it seems to be not
> always propagated ... And this _not_always_ is what I am
> worrying about - I want to know what is the rule.
The rule is that some easy inferences may be done immediately on
posting the constraint, but full propagation only happens when you
call status.
> What I
> mean is prety much like this:
> ---- code -----
> int
> get_weight(){
> IntVar weight(this, 0, Limits::Int::int_max);
> linear(this, this->vars, IRT_EQ, weight);
> /*
> this->status();
> */
> return weight.val();
> }
> ---- code -----
>
> I invoke this function like
> solved_space->get_weight()
> from within the constrain() function (for BAB search).
> Without the line
> this->status();
> I experienced assertion fault due to weight.max() !=
> weight.min() : max, min remained the same as at the time of
> initialization of weight.
Although this works (if you use status), it is not the recommended way
of doing it. What you should really do is:
int
get_weight() {
int w = 0;
for (int i=0; i<vars.size(); i++)
w += vars[i].val();
return w;
}
The problem with your approach is that if you add variables and
constraints, you're not guaranteed that all the variables will be
assigned after calling status. It works in the above example, because
you add a single constraint, and the new variable can be computed as a
function from the old variables. As soon as you try something more
involved, you may need a nested search to actually determine the
values. Another disadvantage is that your version will be
considerably slower than a simple computation of the sum.
> Then I added the commented line and it worked fine.
>
> But... I have another function I invoke on solved spaces,
> which workes fine without the status() invocation.
>
> What do I have to know about constraints on solved spaces?
> Could you short explain, or give a hint for reading?
Constraints on solved spaces are exactly the same as on unsolved
spaces. You're not guaranteed to get a solution without search.
Cheers,
Guido
More information about the gecode-users
mailing list