Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stochastic variables make the SDDP model infeasible #640

Closed
BaiYansong-bys opened this issue Jul 10, 2023 · 5 comments
Closed

stochastic variables make the SDDP model infeasible #640

BaiYansong-bys opened this issue Jul 10, 2023 · 5 comments

Comments

@BaiYansong-bys
Copy link

BaiYansong-bys commented Jul 10, 2023

Hi,
I have encountered such a problem, my model includes 20 stages, sce0 is vector{vector{Float64}} with 144 elements, Pro0 is vector{Float64} with 144 elements. pw_s is defined as stochastic variables. if I write this, the model can be solved:

if stage == 1
@constraint(sp, [i in 1:NW], pw[i]<=pw_l[i,stage]*(1)*uw[i])#pw_s[i]
else
SDDP.parameterize(sp,sce0,Pro0) do omga
     JuMP.fix.(pw_s,omga);
end
@constraint(sp, [i in 1:NW], pw[i]<=pw_l[i,stage]*(1)*uw[i])     
end

if I write this, the model cannot be solved:

if stage == 1
@constraint(sp, [i in 1:NW], pw[i]<=pw_l[i,stage]*(1)*uw[i])#pw_s[i]
else
SDDP.parameterize(sp,sce0,Pro0) do omga
     JuMP.fix.(pw_s,omga);
end
@constraint(sp, [i in 1:NW], pw[i]<=pw_l[i,stage]*(1+0*pw_s[i])*uw[i])     
end

The prompt error is as follows:
ERROR: LoadError: Unable to retrieve solution from (20, 1).
Termination status: OPTIMAL
Primal status: FEASIBLE_POINT
Dual status: NO_SOLUTION.
A MathOptFormat file was written to subproblem.mof.json.
See https://odow.github.io/SDDP.jl/latest/tutorial/06_warnings/#Numerical-stability-1
for more information.

In theory, pw_ s[i] * 0==0, why are the results different?

@odow
Copy link
Owner

odow commented Jul 11, 2023

Presumably, because your constraint is now a quadratic function, and the solver you are using cannot return the dual of a quadratic program.

I'd do something like

SDDP.parameterize(sp,sce0,Pro0) do omga
     for i in 1:NW
          # Note the -, needed because normalized constraint is pw[i] - uw[i] <= 0
          set_normalized_coefficient(c_stochastic, uw[i], -pw_l[i,stage]*(1+omga))
     end
end
@constraint(sp, c_stochastic[i in 1:NW], pw[i] <= uw[i]) 

@BaiYansong-bys
Copy link
Author

BaiYansong-bys commented Jul 12, 2023

Thanks a lot, Oscar, there still have some trouble.
If I express the code as follows,

NW = 2
SDDP.parameterize(sp,[[0.2,0.3],[0,-0.1]],[0.5,0.5]) do omga
     for i in 1:NW
          # Note the -, needed because normalized constraint is pw[i] - uw[i] <= 0
          set_normalized_coefficient(c_stochastic, uw[i], -pw_l[i,stage]*(1+omga[i]))
     end
end
@constraint(sp, c_stochastic[i in 1:NW], pw[i] <= uw[i]) 

I find some errors, set_normalized_coefficient seems to have errors because the input cannot be "c_stochastic", the error is as follows:
LoadError: MethodError: no method matching set_normalized_coefficient(::Vector{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}, ScalarShape}}, ::VariableRef, ::Float64)
Closest candidates are:
set_normalized_coefficient(::ConstraintRef{var"#s140", MathOptInterface.ConstraintIndex{F, S}, Shape} where {var"#s140"<:AbstractModel, Shape<:AbstractShape},
::Any, ::Any) where {S, T, F<:Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}}} at C:\Users\Lenovo.julia\packages\JuMP\klrjG\src\constraints.jl:596

I found this expression seems to work,

        SDDP.parameterize(sp, [[0.2,0.3],[0,-0.1]],[0.5,0.5]) do omga#sce0,Pro0
                #JuMP.fix.(pw_s, omga)
            #for i in 1:NW
                set_normalized_coefficient(c_stochastic1, uw[1], -pw_l[1,stage]*(1+omga[1]))
                set_normalized_coefficient(c_stochastic2, uw[2], -pw_l[2,stage]*(1+omga[2]))
                #
            #end
        end
        @constraint(sp, c_stochastic1, pw[1]<=uw[1])
        @constraint(sp, c_stochastic2, pw[2]<=uw[2])

Can the code above be more concise?

@odow
Copy link
Owner

odow commented Jul 12, 2023

I guess I meant set_normalized_coefficient(c_stochastic[i], I can't test the code without a reproducible example.

@BaiYansong-bys
Copy link
Author

Thanks, Oscar, it can work with the above code.

@odow
Copy link
Owner

odow commented Jul 15, 2023

Closing as completed. Please re-open if you have any other questions.

@odow odow closed this as completed Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants