[gecode-users] how to constaint sum of sum with linear constraint

manel askri askri.manel1 at gmail.com
Tue Nov 19 16:08:17 CET 2013


hi everyone!

Thank YOU very much for the help !
 i did ue that and it works, so just to be sur , i attached the constraint
and here what i did to resolve it :

IntArgs res(n*m);
 BoolVarArgs X1(n*m);
 int count=0;
          for (int i=0; i<n; i++)
  {
              for (int j=0; j<m; j++)
             res[count++] = g[i][j];
  }

  int count1=0;
  for (int i=0; i<n; i++)
  {
              for (int j=0; j<m; j++)
             X1[count1++] = X(i,j);
  }
  linear(*this, res,X1, IRT_EQ, gain);//// is this just fine satisfair the
constraint presented in sumof the sum.png


Thank you very much for your help

Manel




2013/11/19 Guido Tack <tack at gecode.org>

> Please have a look at the documentation how to use IntArgs and IntVarArgs.
>  What you want to do is copy the coefficients and variables from your
> matrix into the Args, something like
>
> int count=0;
> for (int i=0; i<n; i++)
>   for (int j=0; j<m; j++) res[count++] = g[i][j];
>
> Cheers,
> Guido
>
>
> On 19 Nov 2013, at 11:55 am, manel askri <askri.manel1 at gmail.com> wrote:
>
> hi
> Thank You for your help but i really didn't get it well with the
> IntVarArgs : this what i did :
>
>                                  IntArgs res(n*m);
>  IntVarArgs X1(n*m);
>  for (int i=0; i<n; i++)
>  {
>   IntArgs res(g[i]);/// here i'm not sur if i will get the whole matrix g
> in the IntArgs res??????
>  }
>  for (int i=0; i<n; i++)
>  {
>  IntVarArgs X1(X.row(i));//// but this is wrong how can i fix this ?? how
> can i put the matrix X which has Boolean variables in the IntVarArgs
> X1??????
>  }
>
>
> Could You please help me with that ????
>
> Thank YOU very much
>
> Manel
>
>
> 2013/11/19 Guido Tack <tack at gecode.org>
>
>> Simply create a new IntArgs and IntVarArgs with the right size and put
>> all the coefficients and variables that you need to sum up into those
>> arrays.  Then you only need to post one linear.
>>
>> Cheers,
>> Guido
>>
>> On 19 Nov 2013, at 8:26 am, manel askri <askri.manel1 at gmail.com> wrote:
>>
>>
>> hi everyone!
>>
>> I want to post a constraint that is the sum of a sum like this
>> *sum(sum (res [ i ] * X.row (i)))=Z, **with 0 < i <n*
>>
>>  but in the documentation MPG I just found the linear constraint that are
>> used to constraint the sum not the sum of sum  :
>>
>> let me explain:
>>
>> I have a matrix : vector < vector <int> > res , and a Boolean matrix X
>> defined as follows: Matrix <BoolVarArray> X (a, m, n);
>>
>> in the following code I had to do this sum :
>>
>> *sum (res [ i ] * X.row (i)) with 0 < i <n* / / here i can not pay this
>> sum for a table because the  2 matrix does not have the same type and i
>> didnt find any prototype of the linear constraint that can do this.
>>
>> Then I had to make this sum :
>>
>> *the sum of the previous sum= Z*
>>
>> so I used this constraint but it appeared that it is false because it
>> does not give me the desired solution :
>> *linear ( * this , res [ i ] X.row ( i ) IRT_EQ , Z) ;*
>>
>> I know that this constraint only to : *sum (res [ i ] * X.row (i)) = Z* ,
>> where 0 < i < n; an dits wrong.
>>
>> you have an idea on correcting this error could you help me please
>>
>> thank you very much for your help
>>
>> Manel
>>
>>
>>
>> _______________________________________________
>> Gecode users mailing list
>> users at gecode.org
>> https://www.gecode.org/mailman/listinfo/gecode-users
>>
>>
>>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20131119/95b68a59/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sumof the sum.png
Type: image/png
Size: 6169 bytes
Desc: not available
URL: <http://www.gecode.org/pipermail/users/attachments/20131119/95b68a59/attachment.png>


More information about the users mailing list