Closed aferragu closed 2 years ago
With the current release of Convex, I get
ERROR: LoadError: MethodError: no method matching iterate(::Convex.MultiplyAtom)
Closest candidates are:
iterate(::Core.SimpleVector) at essentials.jl:568
iterate(::Core.SimpleVector, ::Any) at essentials.jl:568
iterate(::ExponentialBackOff) at error.jl:199
when running your code, which seems much better than silently giving the wrong answer. Removing the broadcast on the constraints (which then matches the examples in https://convexjl.readthedocs.io/en/stable/types.html#constraints, for example) gives
julia> p.optval
160.0
julia> x.value
3×1 Array{Float64,2}:
60.0
90.0
10.0
Is this right?
Yeah that solution is valid. I was a user of Convex.jl but since migrated to JuMP. That day I was quickly solving an LP checking for some exam solutions and found it didn't work right and reported.
Ok, great!
On the one hand, I think using broadcasted notation could make sense for Convex, but on the other, I don’t think there’s really another way to interpret the non-broadcasted constraints besides elementwise. I think it isn’t good if broadcasted notation doesn’t error and gives a different result though. So I’ll submit a pull request to add some tests to make sure that the broadcasted notation errors, and update the docs to explicitly point out that one should not use broadcasted constraints. Then if that goes through maybe we can close this issue.
Hmm, well I realized
x = Variable(5)
y = rand(5)
C = x .== y
yields that C
is a vector of constraints, essentially,
[ x[i] == y[i] for i = 1:5 ]
It could be someone is using this for some purpose, although I'm not sure. So I'm not sure we want to disallow broadcasting entirely. Maybe the simplest fix is to add a test to check the formulation from your first post yields an error (with a reference to this issue), and if the broadcasting in R*x .<= y
ever gets returned to Convex (even by accident), the failing test will prompt a check of this issue to make sure it's being used sensibly.
Closing in favor of https://github.com/jump-dev/Convex.jl/issues/479
I'm using Julia v0.6.1 with Mosek.jl v0.8.2 and the latest Convex.jl master installed via Pkg.checkout. I'm trying to solve a simple resource allocation problem, which is an LP of the form:
And I obtain as output:
Which is clearly non-optimal (x=[60;0;100] works better).
Using SCS the problem is the same:
I suspected an issue with broadcasting in
p.constraints+=R*x.<=C
. In fact inserting the constraints separately yields the correct answer.