Skip to content

Commit b64c2c7

Browse files
committed
[DEV] return first control with extensive formulation
1 parent 77d7b06 commit b64c2c7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

examples/dynamic_example.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ using StochDynamicProgramming, JuMP, Clp
1616
const SOLVER = ClpSolver()
1717
# const SOLVER = CplexSolver(CPX_PARAM_SIMDISPLAY=0)
1818

19-
const N_STAGES = 5
20-
const N_SCENARIOS = 1
19+
const N_STAGES = 3
20+
const N_SCENARIOS = 2
2121

2222
const DIM_STATES = 1
23-
const DIM_CONTROLS = 1
23+
const DIM_CONTROLS = 2
2424
const DIM_ALEAS = 1
2525

2626

@@ -177,11 +177,12 @@ end
177177
#Solve the problem and try nb_iter times to generate random data in case of infeasibility
178178
unsolve = true
179179
sol = 0
180+
firstControl = zeros(DIM_CONTROLS*N_SCENARIOS)
180181
i = 0
181182
nb_iter = 10
182183

183184
while i<nb_iter
184-
sol, status = extensive_formulation(model,params)
185+
sol, firstControl, status = extensive_formulation(model,params)
185186
if (status == :Optimal)
186187
unsolve = false
187188
break
@@ -204,6 +205,7 @@ if (unsolve)
204205
else
205206
a,b = solve_dams(modelbis,paramsbis)
206207
println("solution =",sol)
208+
println("firstControl =", firstControl)
207209
println("V0 = ", b[1].lambdas[1,:]*X0+b[1].betas[1])
208210
end
209211

src/extensiveFormulation.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ function extensive_formulation(model,
9595
solved = (status == :Optimal)
9696

9797
if solved
98-
return getObjectiveValue(mod), status
98+
firstControl = collect(values(getValue(u)))[1:DIM_CONTROL*laws[1].supportSize]
99+
return getObjectiveValue(mod), firstControl, status
99100
else
100-
return -1., status
101+
return -1., -1., status
101102
end
102103

103104
end

0 commit comments

Comments
 (0)