-
Notifications
You must be signed in to change notification settings - Fork 62
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
Multiplying random variables will result in an error. This is related to nonlinear programming. #739
Comments
JuMP implements `fixed variables by adding a new decision variable with fixed bounds. This means that HiGHS does not support quadratic constraints. Instead, you should use I didn't run your code, but something like this should work: using SDDP, HiGHS, Test
function demo()
model = SDDP.LinearPolicyGraph(;
stages = 5,
upper_bound = 30.0,
sense = :Max,
optimizer = HiGHS.Optimizer,
) do sp, t
p1 = 2.0
p2 = 1.0 # PLACEHOLDER
@variable(sp, 0 <= x1, SDDP.State, initial_value = 0.0)
@variable(sp, 0 <= x2, SDDP.State, initial_value = 0.0)
@variable(sp, 0 <= x3, SDDP.State, initial_value = 10.0)
@variables(sp, begin
fx1
fx2
cash
end)
@constraints(sp, begin
x1.out == x1.in - fx1
x2.out == x2.in - fx2
c_cash, cash == p1 * fx1 + p2 * fx2
x3.out == x3.in + cash
end)
if t < 5
@stageobjective(sp, cash)
else
@stageobjective(sp, cash + p1 * x1.out + p2 * x2.out)
end
Ω = [-1.75, 0.08, 1.93]
P = [0.25, 0.5, 0.25]
SDDP.parameterize(sp, Ω, P) do ω
p2 = ω + p1 * 0.8
# Note the `-p2` becuase `fx2` appears on the right-hand side
set_normalized_coefficient(c_cash, fx2, -p2)
if t == 5
set_objective_coefficient(sp, x2.out, p2)
end
return
end
end
SDDP.train(model)
return
end
demo() |
Any other questions? If not, I will close this issue. |
thank you!This approach solved my problem. |
In the code above, my variable p1 is obtained through a transition matrix. However, I want to modify the probabilities of the random variable ‘P’ to also be based on the transition probability matrix [[0.2, 0.4, 0.4], [0.3, 0.3, 0.4], [0.4, 0.1, 0.5]]. This means the current random value is dependent on the previous random value. How should I modify this part of the code? |
How? It is the node in a lattice?
You can do stuff like: if p1 > 0.5
P = [0.25, 0.5, 0.25]
else
P = [0.5, 0.5, 0.0]
end |
I am currently using the following method to solve this issue, not sure if it's correct.
|
You cannot do this. Ignoring SDDP.jl, can you write out, in math, what your stochastic process is? How are You need to formulate your model as a policy graph, where the support and probability vectors depend only on the index of the node. I don't fully understand your problem formulation, but you likely need to build a Markov chain with two dimensions: one for julia> P_I = [0.5 0.5 0.0; 0.5 0.0 0.5; 0.0 0.5 0.5]
3×3 Matrix{Float64}:
0.5 0.5 0.0
0.5 0.0 0.5
0.0 0.5 0.5
julia> P_J = [0.2 0.4 0.4; 0.3 0.3 0.4; 0.4 0.1 0.5]
3×3 Matrix{Float64}:
0.2 0.4 0.4
0.3 0.3 0.4
0.4 0.1 0.5
julia> indices = [(i, j) for i in 1:size(P_I, 1) for j in 1:size(P_J, 1)]
9-element Vector{Tuple{Int64, Int64}}:
(1, 1)
(1, 2)
(1, 3)
(2, 1)
(2, 2)
(2, 3)
(3, 1)
(3, 2)
(3, 3)
julia> trannsition_matrix = [
P1[i1, i2] * P2[j1, j2] for (i1, j1) in indices, (i2, j2) in indices
]
9×9 Matrix{Float64}:
0.1 0.2 0.2 0.1 0.2 0.2 0.0 0.0 0.0
0.15 0.15 0.2 0.15 0.15 0.2 0.0 0.0 0.0
0.2 0.05 0.25 0.2 0.05 0.25 0.0 0.0 0.0
0.1 0.2 0.2 0.0 0.0 0.0 0.1 0.2 0.2
0.15 0.15 0.2 0.0 0.0 0.0 0.15 0.15 0.2
0.2 0.05 0.25 0.0 0.0 0.0 0.2 0.05 0.25
0.0 0.0 0.0 0.1 0.2 0.2 0.1 0.2 0.2
0.0 0.0 0.0 0.15 0.15 0.2 0.15 0.15 0.2
0.0 0.0 0.0 0.2 0.05 0.25 0.2 0.05 0.25 If there is correlation between |
Any other questions? |
Closing because this seems resolved. Please comment if you have other questions. |
My model involves the multiplication of results with random variables and other variables, followed by an error occurring.
MathOptInterface.UnsupportedConstraint{MathOptInterface.ScalarQuadraticFunction{Float64}, MathOptInterface.EqualTo{Float64}}: `MathOptInterface.ScalarQuadraticFunction{Float64}`-in-`MathOptInterface.EqualTo{Float64}` constraint is not supported by the model.
the code like this
I have reviewed solutions to similar issues in the problem thread, but they do not apply to my specific case. What should I do to resolve this problem?
The text was updated successfully, but these errors were encountered: