loco
loco copied to clipboard
Wrong result when using :minimize on product of negative vars
I'm trying to use Loco to minimize the sum of squared errors in a constraint problem, however it seems that the solver is giving the wrong result when the variable ranges go into the negative numbers:
(solutions
[($in :e -5 5)]
:minimize ($* :e :e))
;; => ({:e 5})
Oddly enough, creating a temporary variable solves the issue in this case, but not in a larger model involving multiple squared vars.
(solutions
[($in :e -5 5)
($in :sse -1000 1000 :bounded)
($= :sse ($* :e :e))]
:minimize :sse)
;; => ({:e 0, :sse 0})
Am I doing something wrong here? The docstring for $*
says
One of the arguments can be a number greater than or equal to -1.
which is confusing as to whether it handles both arguments being negative.