Hey guys, I’m quite curious about the JuMP model object. Once I construct a JuMP model where all variables and expressions are organized into one model instance which goes through many scripts and it worked. It could be solved propriately and results could be accessed.
But then I started to construct the model from smaller models. Taking objective as example, it consists of many other cost terms which are defined in other scripts. For example
## Initialize model objective function
@expression(m, eObj, 0)
...(define other variables and expressions as well as constraints)
## Define model objective function
@objective(m, Min, eObj)
...
## Another objective
@expression(m, ePObj, 0)
...
## Add it into main objective
m[:eObj] += m[:ePObj]
But either gurobi or highs solver gives zero objective in the log, and results could be accessed with non-zero values, which is strange since the ePObj is proven not zero in the output files.
I don’t know if I fully understand the problem. Do you have a reproducible example?
This works for me:
julia> using JuMP
julia> model = Model();
julia> @variable(model, x)
x
julia> @expression(model, eObj, x)
x
julia> @objective(model, Min, eObj)
x
julia> print(model)
Min x
Subject to
julia> eObj += x
2 x
julia> @objective(model, Min, eObj)
2 x
julia> print(model)
Min 2 x
Subject to