In the following code, of which I do not report a long series of complicated constraints, I would like to be able to specify in the objective function also the fact that, together with the Min, sum(x[2:nr,:,"G/\\N"])
, I want the Max, sum(x[1,:,"G/\\N"])
.
It’s possible?
How can it be done?
Could something like this work?
Min, sum(x[2:nr,:,"G/\\N"])+1/sum(x[1,:,"G/\\N"])
But I would like to know how it is possible in general to set up an objective function that has many conditions on different groups of variables.
m, M = getdata(path,H[1],H[2],H[3]) # m Matrix, M Dict
using JuMP
import HiGHS
model = Model(HiGHS.Optimizer)
# set_silent(model)
@variable(model, x[i in 1:nr, j in 1:ng, k in ["G", "N", "G/\\N", "G\\/N"]], Bin)
@objective(model, Min, sum(x[2:nr,:,"G/\\N"]))
@constraints(model, begin
# total of G and N for row
opcom[k in ["G", "N"], r in 1:nr], sum(x[r,:,k]) == M[k][r]
# each day must have exactly one G (k==1) and one N (k==2)
daycom[k in ["G", "N"], g in 1:ng], sum(x[:,g,k]) == 1
...
...
end)
function init_model(m)
fixm(i,j, k,b)= begin fix(x[i, j, k], b; force = true); m[i,j]=replace(m[i,j], r"[N|G]"=>"") end
for i in 1:nr, j in 1:ng
m[i, j] == "xx" ? fixm.(i, j, ["G", "N"], 0) :
m[i, j] == "xg" ? fixm(i, j, "G", 0) :
m[i, j] == "xn" ? fixm(i, j, "N", 0) :
m[i,j]∈["G","N"] ? fixm(i, j, m[i,j], 1) :
m[i, j] == "xnG" ? fixm.(i, j, ["N","G"], [0,1]) :
m[i, j] == "xgN" ? fixm.(i, j, ["G","N"], [0,1]) :
m[i, j] == "GN" ? fixm(i, j, "G/\\N", 1) :
nothing
end
end
init_model(m)
optimize!(model)