On 21 Feb 2012, at 19:20, Wajid Hassan wrote:

> Hi Guido, 
> 
> Thank you for the reply.
> 
> // That is what the element constraint is used for (you'll find it in the 
> documentation).  It works directly on variables, so you don't have to solve 
> the sub-problem on x first.
> 
> I am not sure I follow your point. Let me clarify the question, there are two 
> integer variable arrays Array1[] and Array2[]. Both the arrays are 
> constrained in different ways individually. Then, as a last constraint 
> Array1[] needs to be constrained using the values assigned to Array2[]. So, 
> do u think the following constraint would work or not? 
> 
>> rel(*this, Array2[Array1[some_index].val()] + (something) <= 
>> Array2[another_index]);
> 
> 
> It doesn't give any errors on compilation but I haven't finished the rest of 
> the model yet to be 100% sure if it works correctly or not.

No, that's not how it works, because when you model your problem, the value of 
Array1[some_index].val() is not yet known (an exception will be thrown at 
runtime).  

It also depends a lot on whether some_index and another_index are IntVars or 
simple int constants.  If they are simple ints, the following may work:
rel(*this, element(Array2, Array1[some_index]+(something)) <= 
Array2[another_index]));
If they are IntVars, you need to decompose some more using element.  Please 
read the documentation on element constraints, that should clarify things.

Cheers,
Guido

> 
> Thank you in advance.
> 
> Best regards,
> Wajid
> 
> On Mon, Feb 20, 2012 at 11:04 PM, Guido Tack <[email protected]> wrote:
> On 21 Feb 2012, at 08:33, Wajid Hassan wrote:
> 
>> Hi Christian,
>> 
>> The problem in a nut shell is: 
>> 
>> I have two arrays of integer variables, Array1[x] and Array2[x]. I want to 
>> use the value assigned to the variables in Array1[] as an index of Array2[], 
>> something like this:
>> 
>> rel(*this, Array2[Array1[x].val()] + (something) <= Array2[x+1]);
>> 
>> Is there anything wrong with the above constraint or should this work?
> 
> That is what the element constraint is used for (you'll find it in the 
> documentation).  It works directly on variables, so you don't have to solve 
> the sub-problem on x first.
> 
> Cheers,
> Guido
> 
> -- 
> Guido Tack,
> http://www.csse.monash.edu/~guidot/
> 
> 
> _______________________________________________
> Gecode users mailing list
> [email protected]
> https://www.gecode.org/mailman/listinfo/gecode-users

-- 
Guido Tack,
http://www.csse.monash.edu/~guidot/



_______________________________________________
Gecode users mailing list
[email protected]
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to