Ok thanks that runs now, but it does appear to be quite what I want. See printed output below.
Maybe I’m not properly specifying the vectors b and c or the matrix A? Or do I need to somehow specify the type of x?
Just copied your code. Still getting same error: @constraint(model, $(Expr(:escape, :A)) * $(Expr(:escape, :x)) <= b): Unexpected vector in scalar constraint. Did you mean to use the dot comparison operators like .==, .<=, and .>= instead?
You seem to work in a Jupyter notebook there - you might get into spaghetti issues with the cells: please make sure you are executing the model = Model(HiGHS.Optimizer) before running the other operations on the model.
Yeah I’m in Jupyter notebook. I executed that line first. I also tried restarting the kernel to make sure no other cell is messing with things. I still get same error with the matrix approach (i.e. without specifying the components of x explicitly).
Here you have my vs-code naive execution - it just works:
Anyway - to answer your question: I cannot call myself an expert on JuMP - so if you need a contribution at that level for your specific problem, I think it is best to leave this to other users that might be more qualified.
However, for reference, here is the solution I proposed (which you seem to have issues in executing without getting an error):
A = [1 0; 0 1]
b = [1;1]
c = [1,0]
model = Model(HiGHS.Optimizer)
@variable(model, x[1:2] >= 0)
@constraint(model, A*x <= b)
@objective(model, Max, sum(c .* x));
# [x - 1, x - 1] ∈ MathOptInterface.Nonpositives(2)
# x ≥ 0
# x ≥ 0
I wish you luck.
P. S. I see that you actually added [x - 1, x - 1] ∈ MathOptInterface.Nonpositives(2) to your constraint: please note that I indicated that as an output that satisfied your stated expectations, not instructed actually to build a constraint from that. The actual instruction was above that paragraph:
I was intrigued by what’s happening, so here is my two cents. First case:
@variable(model, x >= 0) ###Creates a scalar variable x
@constraint(model, A*x .<= b)
JuMP doesn’t know that x is supposed to be a vector. If x is a scalar, then A*x=[x 0;0 x]. Using A*x.<=b gives a column-wise comparisons: [x;0]<=[1;1] and [0;x]<=[1;1], which, in turn, give the element-wise scalar constraints x<=1, 0<=1, 0<=1, x<=1.
Telling JuMP that x is a vector
@variable(model, x[1:2] >= 0) ###Creates a vector variable x with x and x
If x is a vector of size 2x1, then A*x is also a vector of size 2x1. And whereas both A*x<=b and A*x.<=b give mathematically the same constraints, numerically they can differ, see: Constraints · JuMP.
Using @constraint(model, A*x .<= b) we get four separate scalar constraints (two from the matrix multiplication, two from the definition of x):
Using @constraint(model, A*x <= b) we get one vector constraint from the matrix multiplication and two scalar constraints from the definition of x: