[gecode-users] Unexpected propagation/search behaviour

Mikael 'Zayenz' Lagerkvist zayenz at kth.se
Mon Jan 23 07:35:13 CET 2006


Hi,

On 1/23/06, Lars Otten <ottenl at student.chalmers.se> wrote:
> propagate(Space* home) {
>   for (int i=0; i<n; ++i) {
>     //... do stuff for x and y
>     if (z[i].assigned() && <z[i] not yet treated> ) {
>       //... some preparations, like creating IdxView instances
>       Element::ViewDom<IntView,IntView>::post(home,z,z.size(),x[i],z[i]);
>       Element::ViewDom<IntView,IntView>::post(home,z,z.size(),y[i],z[i]);
>     }
>   }
>   //...
> }

I have one comment on the above code. When calling the post-methods,
it is very important to always check the return-value for possible
failure. The code should look something like the following.

   if (z[i].assigned() && <z[i] not yet treated> ) {
     //... some preparations, like creating IdxView instances
     if(Element::ViewDom<IntView,IntView>::post(home,z,z.size(),x[i],z[i])
== ES_FAILED)
       return ES_FAILED;
     if(Element::ViewDom<IntView,IntView>::post(home,z,z.size(),y[i],z[i])
== ES_FAILED)
       return ES_FAILED;
   }

When a failure is detected, the space may no longer be in a consistent
state. Therefore it is important to stop computing with it.

Cheers,
Mikael

--
Mikael 'Zayenz' Lagerkvist, http://www.imit.kth.se/~zayenz/




More information about the gecode-users mailing list