Skip to content

Commit 6e0728e

Browse files
committed
Merge pull request #69 from leclere/return-control-state-ef
[DEV] return first control with extensive formulation
2 parents c8d5f0a + 723d499 commit 6e0728e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-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+
error("Extensive formulation not solved to optimality. Change the model")
101102
end
102103

103104
end

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ facts("SDDP algorithm: 1D case") do
118118
noise_scenarios = simulate_scenarios(model.noises,params.forwardPassNumber)
119119

120120
sddp_costs = 0
121+
122+
context("Unsolvable extensive formulation") do
123+
model_ef = StochDynamicProgramming.LinearDynamicLinearCostSPmodel(n_stages, u_bounds,
124+
x0, cost, dynamic, laws)
125+
x_bounds_ef = [(-2., -1.)]
126+
set_state_bounds(model_ef, x_bounds_ef)
127+
@fact_throws extensive_formulation(model_ef, params)
128+
end
129+
121130
context("Linear cost") do
122131
# Compute bellman functions with SDDP:
123132
V, pbs = solve_SDDP(model, params, 0)

0 commit comments

Comments
 (0)