Linear: Int vs Float

25 views
Skip to first unread message

John

unread,
Jun 15, 2022, 9:34:38 AM6/15/22
to Gecode
Hello. I have the following simple problem case:
  • 50 IntVars, each with a domain from 0 to 49.
  • A FloatVar.
  • A 50*50 array given as input, associating each variable-value assignment with a cost of type double.
I would like the FloatVar to hold the total cost representing a solution. That is, the sum of all the respective costs of each variable-value assignment. To do this, I create a boolean array to map whether a specific variable is assigned to a specific value or not. Then I channel this boolean array to a float array, so I can finally use it in a linear constraint, with FRT_EQ. 

Running this example, it takes 8 seconds to find the first solution. But if I make a version of the problem where the costs are integers (and also remove the channel constraint, since linear can support a mix of int and boolean arrays, but not float and boolean), then I get the response instantly. 

Why is this happening? Is there a better way to model, something that I am missing, or is it inevitable because of the nature of floating types?
I can provide minimal working example code if needed.

Thank you!

Mikael Zayenz Lagerkvist

unread,
Jun 15, 2022, 11:11:43 AM6/15/22
to gec...@googlegroups.com
Hi,

While I can't say anything about your particular use-case without
seeing the model, float variables behave somewhat differently than
integer variables when used in a constraint programming solver.

If it is possible to scale the costs up to have integer values (say,
if the costs are of the form 15.37, scaling all costs by 100), that is
probably a good idea.

Cheers,
Mikael
> --
> You received this message because you are subscribed to the Google Groups "Gecode" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gecode+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/gecode/7f64d716-1d53-4cb0-8c66-2ea53cc512ban%40googlegroups.com.



--
Mikael Zayenz Lagerkvist
Reply all
Reply to author
Forward
0 new messages