[gecode-users] Question about: Float variables, Literals and/or Constants

Mikael Zayenz Lagerkvist zayenz at gmail.com
Thu Dec 17 07:53:02 CET 2009


Hi,

The float variables are not yet truly integrated into Gecode, so I would not
advise to use them currently.

As for how to express the multiplication with a constant, I would suggest
you use the minimodel interface:
    post(*this, d*mutualSize == n*resultSize);

Cheers,
Mikael

2009/12/17 Holger Winnemoeller <holger.winnemoeller at gmail.com>

> I wonder if I have found the best solution to the following problem (I
> doubt it):
>
> inventory = {0,1,2,3,4, ... , N}
> subsetA = some subset of inventory
>
> Goal: Give me a resultSet with elements from inventory given the following
> constraints
>
> *  fraction X of items in resultSet are from subSetA
> *  some other constraints (lets not worry about that here)
>
> pseudocode notation of a solution might be:
>
> IntVar resultSize = cardinality(resultSet);
> SetVar mutualSet = intersection(resultSet, subsetA);
> IntVar mutualSize = cardinality(mutualSet);
>
> FloatVar f = div(mutualSize, resultSize);
> rel(div, EQ, X);
>
> Now, while I did find a FloatVar class, it's in the namespace
> Gecode::FlatZinc::AST, not Gecode, and I have a feeling its use is not
> analogous to IntVar.
>
> So, fair enough, I can just repose the constraint:
>
>                 |mutualSet| / |resultSet| = X, where X can be approximated
> by n/d
>
> <==> d * |mutualSet| = n * |resultSet|, all of which can be expressed in
> Int's
>
> So, my solution ends up being:
>
>         IntVar lhs (*this, 0, d * setB.size());        // worst-case
> domain
>     IntVar rhs (*this, 0, n * inventory.size());   // worst-case domain
>
>     // Q1: I would love to write the following lines, but I may not use
> integer literals in the mult call. Is there a better way?
>     //mult(*this, mutualSize, d, lhs);
>     //mult(*this, resultSize, n, rhs);
>
>     // Q2: Is this the way to specify the constant that I want to use? It
> seems very roundabout...
>     IntVar numerator(*this, n,n);
>     IntVar denominator(*this, d,d);
>
>     mult(*this, mutualSize, denominator, lhs);
>     mult(*this, resultSize, numerator,   rhs);
>
>     rel(*this, lhs, IRT_EQ, rhs);
>
> The thing is, I do get the correct solution using this approach, but I feel
> like I am misusing Gecode, and that there is a cleaner way to express what I
> want. So to summarize my questions:
>
>    - Is there a way to just use a Float constraint?
>    - If not (have to use Quotient approach), is there a way to express the
>    multiplication using integer literals?
>    - If not, is there a way to specify an integer constant without
>    defining a one-element domain for it?
>    - Or am I crazy, and the solution I give is adequate?
>
>
> Thanks for your help,
> Holger.
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>


-- 
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20091217/58dd0c0b/attachment-0001.htm>


More information about the users mailing list