You don’t need to use Expr
any more. Just do:
julia> using JuMP
julia> begin
model = Model()
@variable(model, ir1, start = 3.0)
@variable(model, ir2, start = 3.0)
@variable(model, ir3, start = 3.0)
@variable(model, SP, start = 5.0)
@variable(model, yA == 1.0)
@variable(model, yF == 2.0)
set_LHS = [ir1, ir2, ir3];
set_RHS = [ir1, ir2, ir3, SP, yA, yF]
set_func = Any[+, -, *, max, min]
function make_RHS(set_RHS, set_func)
return rand(set_func)(rand(set_RHS), rand(set_RHS))
end
function make_constr(set_LHS, set_RHS, set_func)
return @constraint(model, rand(set_LHS) == make_RHS(set_RHS, set_func))
end
end
make_constr (generic function with 1 method)
julia> constr1 = make_constr(set_LHS, set_RHS, set_func)
-SP*ir3 + ir2 = 0
julia> constr2 = make_constr(set_LHS, set_RHS, set_func)
-yF*ir3 + ir3 = 0
julia> constr3 = make_constr(set_LHS, set_RHS, set_func)
ir1 - min(ir3, yF) = 0
julia> constr4 = make_constr(set_LHS, set_RHS, set_func)
ir3 - min(ir1, yA) = 0
julia> constr5 = make_constr(set_LHS, set_RHS, set_func)
ir2 - max(ir2, SP) = 0
julia> print(model)
Feasibility
Subject to
ir1 - min(ir3, yF) = 0
ir3 - min(ir1, yA) = 0
ir2 - max(ir2, SP) = 0
-SP*ir3 + ir2 = 0
-yF*ir3 + ir3 = 0
yA = 1
yF = 2