Hello,
I want to achieve summation of components with index smaller than i in the expression, and used in constraint. That is to say, the components in level is related to each other, e.g. level[2] is the sum of level[1] and another value. I have tried this, but it failed.
@expression(
model,
level[i = 1:numtime],
initial_level + inflow * sum(raintime[j] for j in 1:i) * 3600 /k
)
for i in 1:numtime
@constraint(model, min_level <= level[i] <= max_level)
end
I got error message. How can I post it correctly?
At In[164]:122: @constraint(model, min_level <= level[i] <= max_level): Unrecognized constraint building format. Tried to invoke build_constraint(error, 274.0334413729147, 230, 275.17), but no such method exists. This is due to specifying an unrecognized function, constraint set, and/or extra positional/keyword arguments.
If you’re trying to create a JuMP extension, you need to implement build_constraint to accomodate these arguments.
Infact, discharge[i] is related to level[i-1], and level[i-1] is related to discharge[i-2]… I don’t know how to coding this relationship, so I used a simple case: discharge is independent to water level, but the level is calculated with discharge.
It would be very nice for you to give me some advice for coding the real relationship between discharge flow rate and water level.
using JuMP
# using Juniper
using AmplNLWriter, Bonmin_jll
using Pavito
using Ipopt
totaltime = 3
deltatime = 12
numtime = Int(totaltime * 24 / deltatime)
totalraintime = 45
inflow = 500
raintime = [0 for i in 1:numtime]
for i in 1:numtime
if (totalraintime - (i-1) * deltatime) > deltatime
raintime[i] = deltatime
else
raintime[i] = max(0, totalraintime - (i-1) * deltatime)
end
end
initial_level = 273
min_level = 230
max_level = 275.17
min_discharge = 0
max_discharge = 3140
inflow = 500
d = 57000
k = 2.090104051e7
model = Model(() -> AmplNLWriter.Optimizer(Bonmin_jll.amplexe))
@variable(model, 0 <= n[1:numtime] <= 60, Int)
@expression(
model,
flow[i = 1:numtime],
(0.685 - 0.19 * n[i] * 0.05 / (initial_level - 261)) * 0.5 * n[i] * sqrt(2 * 9.81 * (initial_level - 261))
)
@expression(
model,
level[i = 1:numtime],
initial_level + (inflow * sum(raintime[j] for j in 1:i) * 3600 - sum(flow[j] for j in 1:i) * 43200)/k
)
@objective(model, Min, sum(flow[i] for i in 1:numtime))
for i in 1:numtime
@constraint(model, min_discharge <= flow[i] <= max_discharge)
@constraint(model, min_level <= level[i] <= max_level)
end
optimize!(model)
@show termination_status(model)
@show primal_status(model)
@show dual_status(model)
@show objective_value(model)
for i in 1:numtime
print(" $(n[i]) = $(value(n[i]))\t")
end