Skip to content

Instantly share code, notes, and snippets.

@joaquimg
Created July 2, 2017 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaquimg/71b658948848ed7d7fab4ab7fc70e078 to your computer and use it in GitHub Desktop.
Save joaquimg/71b658948848ed7d7fab4ab7fc70e078 to your computer and use it in GitHub Desktop.
JuMP query example
using JuMP
m = Model()
# Variables section
@variable(m, x[1:10] >= 0)
@variable(m, y[1:10] >= 0)
@variable(m, z >= 0)
# Constraints section
# <=
@constraint(m, sum(x[i] for i in 1:10) + z <= 48)
# >=
@constraint(m, -1(sum(y[i] for i in 1:10 if isodd(i) && i <= 5) + z) <= 17)
# igualdade
for i in 1:3
@constraint(m, y[i] -z <= 0)
@constraint(m, -y[i] +z <= 0)
end
@objective(m, Min, 3x[6] + sum(y[i] for i in 2:4 if iseven(i)) - 876z)
c = JuMP.prepAffObjective(m)
b_lb, b_ub = JuMP.prepConstrBounds(m)
# b_lb, b_ub pode sem +-Inf
A = JuMP.prepConstrMatrix(m)
# A is sparse, for dense Adense = full(A)
var_lb = copy(m.colLower)
var_ub = copy(m.colUpper)
# JuMP standard form
# min c'*x
# s.t.
# b_lb <= Ax <= b_ub
# var_lb <= x <= var_ub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment