I am new to Julia, and I am trying to define an optimization problem with JuMP. I have a lot of variables (x1,x2,x3....
) that I am trying to define using a for
loop. I want to have the code:
@variable(m, x1>=0)
@variable(m, x2>=0) ...
However I wanted to use a for
loop so I did not have to define every variable manually.
Here is what I have so far:
m = Model()
for i = 1:2
@variable(m,string('x',i)>=0)
end
I know the string('x',i)
part is not right but I am not sure how to do this using Julia.
@defVar(m, x[1:2] >= 0)
I keep getting an error when I try to solve:@setObjective(m, Max, 8x1+12x2) @addConstraint(m, 6x1+8x2<=72) status=solve(m)' gives error:
LoadError: Variable not owned by model present in constraints while loading In[22], in expression starting on line 5` any ideas?? @IainDunning @Lucilla – Katharynkathe