How to make "for all" in the sum of the notations in Julia / JuMP

I am trying to add limitations to the linear optimization problem in Julia using JuMP. I use the sum{} function, but I am having problems with some restrictions. Does anyone know how to write β€œfor everyone” in JuMP (upside down A)? Here is the code that I still have:

 using JuMP m = Model() c= [3 5 2 ; 4 3 5 ; 4 5 3 ; 5 4 3 ; 3 5 4] @variable(m, x[i=1:5,j=1:3] >= 0) @objective(m,Min,sum{c[i,j]*x[i,j],i=1:5,j=1:3}) for i=1:5 @constraint(m, sum{x[i,j],i,j=1:3} <= 480) end 

What I'm trying to get is: enter image description here

I am trying to use the for loop as a replacement for "I am from 1 to 5 for everyone," however I keep getting errors. Is there any other way to do this?

+4
source share
1 answer

In mathematical notation, you sum i and do it for each j . In Julia / JuMP, you can think of "βˆ€" as a for loop ("for everyone") and "Ξ£" as a sum{ } :

 using JuMP m = Model() c= [3 5 2; 4 3 5; 4 5 3; 5 4 3; 3 5 4] # x_ij >= 0 βˆ€ i = 1,...,5, j = 1,...,3 @variable(m, x[i=1:5,j=1:3] >= 0) @objective(m,Min,sum{c[i,j]*x[i,j],i=1:5,j=1:3}) # βˆ€j = 1,...,3 for j in 1:3 @constraint(m, sum{x[i,j],i=1:5} <= 480) end 
+4
source

All Articles