How can I get the shadow values of this iteration in Julia JuMP?

44 views Asked by At

I'm trying to get the shadow values of the constraints in the 'for' loop:

using JuMP
using GLPK

CI = [30, 70];
d = 170;
Pmin = [ 0, 0];
Pmax = [100, 150];
N = length(CI)

m = Model(GLPK.Optimizer)


@variable(m, 0 <= P[1:N] )
@objective(m, Min, sum(CI[i] * P[i] for i in 1:N))
@constraint(m, c1, sum(P[1:N]) == d)
for i in 1:N
    @constraint(m, Pmin[i] <= P[i] <= Pmax[i])
end

optimize!(m)

Does anyone know how to make it print the shadow value of all constraints? D:

I was trying to develop a economic dispatch problem (I'm new on Julia)

1

There are 1 answers

0
Oscar Dowson On

Option 1: use the specialized JuMP syntax to create a container:

@constraint(m, c2[i in 1:N], Pmin[i] <= P[i] <= Pmax[i])
dual.(c2)

Option 2: use Julia

c2 = Any[]
for i in 1:N
    push!(c2, @constraint(m, Pmin[i] <= P[i] <= Pmax[i]))
end
dual.(c2)

I'd actually write your model differently though:

using JuMP
using HiGHS
CI = [30.0, 70.0]
d = 170
Pmin = [0.0, 0.0]
Pmax = [100.0, 150.0]
N = length(CI)
model = Model(HiGHS.Optimizer)
@variable(model, Pmin[i] <= P[i = 1:N] <= Pmax[i])
@objective(model, Min, CI' * P)
@constraint(model, c1, sum(P) == d)
optimize!(model)
reduced_cost.(P)

I was trying to develop a economic dispatch problem

You might be interested in the tutorial:

https://jump.dev/JuMP.jl/stable/tutorials/applications/power_systems/#Economic-dispatch

(I'm new on Julia)

Hi there! The other place to get help for JuMP/Julia related things is http://jump.dev/forum. It's a bit easier to have a back-and-forth conversation there if you have more questions than StackOverflow.