[gecode-users] Fix IntVar value (MaximizeSpace::cost)

Guido Tack tack at gecode.org
Wed Jan 23 23:31:18 CET 2013


Hi,

I assume that the variables in your model are all integers, but the cost expression involves real numbers (as coefficients or other constants).  You have two options: implement your own propagator for the constraint that represents the cost function. The propagator can compute with floating point numbers internally and avoid the rounding.  Or use the experimental support for floating point variables in the svn trunk (which will be released with Gecode 4.0 soonish).  In any case, as I said, you have to express the cost as a constraint, otherwise branch-and-bound does not work.

Cheers,
Guido

On 24/01/2013, at 4:59 AM, Pascal Francq (Mailing lists) <mailing-list at francq.info> wrote:

> Hi,
> I have create a variable which represents the cost. My problem is that
> this variable is defined by an expression with several very closed real
> numbers that, when transformed in integers, become equals. The result
> found by GeCode makes therefore no sense.
> 
> Le 17/01/13 05:19, Guido Tack a écrit :
>> Hi,
>> the cost function is const, which means that you can't create new
>> variables inside the function.  It has to return an existing variable
>> that is /constrained/ in the model to be equal to the cost.
>> Branch-and-bound relies on the cost being a variable, because it posts
>> constraints on the cost that make sure each solution is better than the
>> previous one.  If you can't express your cost as a constraint, you can't
>> use branch-and-bound.
>> 
>> Cheers,
>> Guido
>> 
>> 
>> On 17/01/2013, at 2:01 AM, Christian Schulte <cschulte at kth.se
>> <mailto:cschulte at kth.se>> wrote:
>> 
>>> Hi,
>>> 
>>> I am not sure I get the question. Is it that you try to return an integer
>>> variable assigned to an integer called res?
>>> 
>>> Then the magic is:
>>> IntVar ret(*this, res, res);
>>> return ret;
>>> Just read up on integer variables in MPG.
>>> 
>>> Best
>>> Christian
>>> 
>>> --
>>> Christian Schulte, www.ict.kth.se/~cschulte/
>>> <http://www.ict.kth.se/~cschulte/>
>>> 
>>> 
>>> -----Original Message-----
>>> From: users-bounces at gecode.org <mailto:users-bounces at gecode.org>
>>> [mailto:users-bounces at gecode.org <mailto:bounces at gecode.org>] On Behalf
>>> Of Pascal Francq (Mailing lists)
>>> Sent: Wednesday, January 16, 2013 2:44 PM
>>> To: users at gecode.org <mailto:users at gecode.org>
>>> Subject: [gecode-users] Fix IntVar value (MaximizeSpace::cost)
>>> 
>>> Hi,
>>> I am using GeCode to find a set of parameters that maximize some
>>> function. I
>>> inherit therefore from the class 'MaximizeSpace' class. The problem is
>>> that
>>> the function to maximize isn't a direct combination of the parameters
>>> determined by GeCode.
>>> So, I need to rewrite the 'virtual IntVar cost(void) const;' method to
>>> compute for each possible combination of the parameters the value of the
>>> function to maximize. But here is my problem : I don't found how to return
>>> this result in the function.
>>> 
>>> virtual MyClass::IntVar cost(void) const {
>>>  int res(function(C)); // C is an 'IntVarArray'
>>>  IntVar ret=res; // <- Here is my problem !!!!!
>>>  return(ret);
>>> }
>>> 
>>> Any idea ?
>>> 
>>> Thanks.
>>> --
>>> Dr. Pascal Francq
>>> Belgium
>>> 
>>> _______________________________________________
>>> Gecode users mailing list
>>> users at gecode.org <mailto: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
>> 
> 
> 
> -- 
> Dr. Pascal Francq
> Belgium
> 
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users




More information about the users mailing list