[gecode-users] sum of IntArgs

Philippe aqwzsxaqwzsx at orange.fr
Mon Aug 12 17:18:10 CEST 2013


Hi to all Geocode authors,


I needed to compute the sum of IntArgs the same way we compute the sum
of IntVarArray. Tell me if i'm wrong, but it seems that this facility
is not natively provided by Gecode. 

For now, i use my own implementation which do the job (i'm not sure of the 
code below but it seems to work).

Don't you think this facility could be useful for other and thus natively 
provided by Gecode ?


Anyway, congratulations for your work. I'm a new user of Gecode and I
really like it !

Cheers,
Philippe


 LinIntExpr 
 sum(const Slice<IntArgs>& slice)
 {
   const Slice<IntArgs>::ArgsType & args = slice;
   return sum(args);
 }

 LinIntExpr 
 sum(const Matrix<IntArgs>& matrix)
 {
   const Matrix<IntArgs>::ArgsType & args = matrix.get_array();
   return sum(args);
 }


 LinIntExpr
 sum(const IntArgs& args)
 {
  int i, sum = 0;
  const int size = args.size();

  for (i = 0 ; i < size ; ++i)    
  {
    sum += args[i];
  }

  return LinIntExpr(sum);
 }






More information about the users mailing list