Hi,

you could decompose the element constraint by posting implications instead, 
such as x=i implies y=a[i] for all i.

Regarding the rounding, you're right, your approach should work (and just using 
a channel directly forces the float var to take an integral value).

Cheers,
Guido

-- 
GUIDO TACK                  
Senior Lecturer

Information Technology
Monash University
Level 6, Room 6.40, Building H, Caulfield Campus
900 Dandenong Road
Caulfield East VIC 3145
Australia

T: +61 3 9903 1214                      
E: guido.t...@monash.edu <mailto:guido.t...@monash.edu>
http://www.csse.monash.edu/~guidot/ <http://www.csse.monash.edu/~guidot/>


> On 21 Nov. 2016, at 6:02 am, Dani G <daniel.garcialore...@gmail.com> wrote:
> 
> Hello all, 
> 
> These ares my first question, thanks for this library, I found it very 
> interesting and the tutorial is really great.
> 
> I'm using the last version of Gecode 5.0. In the project I'm working on I 
> need to use float variables (the problem include exponential calculations 
> that need to be precise), although I'm trying to minimize their use as much 
> as possible by converting Floats into Into Ints. Two questions arises:
> 
> - I couldn't find a "element" constraint for FloatVarArray, and it would 
> really help me. I don't know if I could easily reimplemented it using the 
> example of the constraint for Int variables, or there will be some problem? 
> Should I find a different modelling, like using a linear constraint using a 
> 0,1 vector?
> 
> - To minimize the use of Float variables I want to round my Float 
> calculations using two digits and then convert them to Int using a channel 
> constraint. I imagine that I need to take into account the rouding if i want 
> to make it work. This sounds right?
> 
> IntVar time; // Variable used in other constraints
> FloatVar time_float(home, TIME_MIN, TIME_MAX); // conversion to float
> 
> channel(home, time, time_float); // conversion to float for the calculations
> 
> // float calculation, this will obviously wil be any float number
> FloatVar activity_float= expr(home, c1 * exp( c2 * time_float); 
> 
> // Rounded version of activity multiplied by 100 to be converted into Int
> FloatVar activity_float_rounded100(home, ACTIVITY_MIN, ACTIVITY_MAX);
> 
> // Rounding up, and multiplying by 100 to keep the desired precision
> rel(home, activity_float_rounded100   >= 100* activity_float);
> rel(home, activity_float_rounded100-1 <  100* activity_float);
> 
> IntVar activity_int(home, ACTIVITY_MIN, ACTIVITY_MAX); // rounded activity by 
> 100
> channel(home,activity_int, activity_float_rounded100); 
> 
> // now activity_int can be used in other int constraints
> 
> I bellieve that if I apply directly the channel to activity_float, the 
> exponential constraint will fail as channel will force activity to be exactly 
> equal to the Int value, am I right?
> 
> 
> Thank you very much your work and for your thoughts
> 
> Best regards
> 
> Daniel
> 
> 
> _______________________________________________
> Gecode users mailing list
> users@gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users

_______________________________________________
Gecode users mailing list
users@gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to