[gecode-users] Re: Var indexes-help

penche21 penche21 penche21 at hotmail.com
Fri Jan 26 12:09:19 CET 2007


Hi again,

Thanks for the advice, it works smooth now.
But one last question about the Var equalities.

suppose Var A, B and an integer array I
Let A to be the one possible values of index i where  B=I[i]

sth like;
for all indexes i
if " A equals I[i]" then "B can be assigned to i"

but I couldnot find a way to imply the equality of VAR&Intger on another 
VAR's possible values.

I kept some BoolVars for assignability but ...
I will really appreciate if you can pop up a constraint for that.

Cheers,
Penche

>From: "Mikael Zayenz Lagerkvist" <zayenz at gmail.com>
>To: penche <penche21 at hotmail.com>
>CC: users at gecode.org

>Subject: Re: [gecode-users] Re: Var indexes-help
>Date: Tue, 9 Jan 2007 08:10:37 +0100
>
>On 1/8/07, penche <penche21 at hotmail.com> wrote:
>><pekczynski at ...> writes:
>>
>> >
>> > Hi there,
>> > I think using the element constraint is the correct choice.
>> > Maybe the little example I attached will help you out.
>> > At least you can use the element constraint to model
>> >
>> > B[C[i-1]]=A[i]
>> >
>> > and indeed the alg also does
>> >
>> > A[i]=B[C[i-1]]
>> >
>> > see 
>>http://www.gecode.org/gecode-doc-latest/group__TaskIntIntElement.html
>> >
>> > > 2) I also tried 'element' to express this constraint
>> > >
>> > > Int Var x;
>> > > element(this, B, C.get(i - 1), x);
>> > > rel(this,A.get(i),IRT_EQ,x);
>> >
>> > So this was quite right, but you can directly use
>> >
>> >  element(this, B, C[i - 1], A[i]);
>> >
>> > so you don't need the rel constraint.
>> >
>> > If there are any further questions, let us know.
>> > :-D
>> > Cheers
>> > Patrick
>> >
>> >
>> > Attachment (arrayex.cc): application/octet-stream, 1932 bytes
>> >
>> > _______________________________________________
>> > Gecode users mailing list
>> > users at ...
>> > https://www.gecode.org/mailman/listinfo/gecode-users
>> >
>>
>>Thank you, I now see rel is useless and element is just enough.
>>But one point is; we will need Var indexes inevitable when the relations
>>get nested.
>>
>>For example; A[i] = B [ C [A[j]] ]
>>
>>1) obviously rel does not work.
>>rel(this, A.get(i), IRT_EQ, B.get(C.get(A.get(j))))
>>
>>2) I tried to introduce new Vars, but below did not work also.
>>
>>IntVar intermediate1= new IntVar(this,min,max);
>>IntVar intermediate2= new IntVar(this,min, max);
>>
>>element(this, C, A.get(j), intermediate1);
>>element(this, B, intermediate1, intermediate2);
>>
>>rel(this, A.get(i), IRT_EQ, intermediate2);
>>
>>3) Any way to write this constraint?
>
>The element constraint implements A[I]=V where A is a VarArray of
>integer variables and I and V are integer variables. If you want your
>index variable to be looked up in another variable array, then this is
>another element constraint. Thus something like 2 is the correct way
>to model your desired constraints.
>
>One thing to note is that you can skip intermediate2, and directly
>replace it with A.get(i). This gives the following code:
>
>  IntVar intermediate1= new IntVar(this,min,max);
>  element(this, C, A.get(j), intermediate1);
>  element(this, B, intermediate1, A.get(j));
>
>this implements B[C[A[i]]] = A[j]. The only direct reason I see that
>this would not work is if min and max are wrong. Safe, unconstraining
>bounds are min=0 and max=B.size().
>
>Cheers,
>Mikael
>
>--
>Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/

_________________________________________________________________
Yagmura yakalanmamak için sadece semsiyenize degil, MSN hava durumuna 
güvenin! http://www.msn.com.tr/havadurumu/





More information about the gecode-users mailing list