2

I am trying to write a linear optimization model in Julia. I have several constraints to add, and I wanted to try and set them using matrices instead of setting each one manually. I have upwards of 5 constraints but I narrowed it down to two just to try and get the code to work. Here is the code I have so far:

m = Model()
@defVar(m, x[1:2] >= 0)
c= [8 12]
@setObjective(m, Max, sum([c[i]*x[i] for i= 1:2]))
A=[6 8 ; 10 20]
B= [72 140]' #bounds
for j=1:2
    @setConstraint(m,sum([A[j,i]*x[i] for i=1:2])<=B[j])
end

When I run this code, the @setObjective function works but the @setConstraints function keeps coming up with the error @setConstraint not defined .
Does anyone know how to fix this or does anyone know a better way to write this using matrices or another shorter way?

Cam
  • 421
  • 2
  • 8
  • 18

1 Answers1

2

The command is @addConstraint (not @setConstraint ) and then it works

Cam
  • 421
  • 2
  • 8
  • 18