@@ -140,34 +140,41 @@ Returns :
140140function sdp_optimize (model:: SPModel ,
141141 param:: SDPparameters ,
142142 display= true :: Bool )
143-
143+
144144 function true_fun (x... )
145145 return true
146146 end
147147 function zero_fun (x... )
148148 return 0
149149 end
150-
150+
151151 if isa (model,PiecewiseLinearCostSPmodel)|| isa (model,LinearDynamicLinearCostSPmodel)
152+ function cons_fun (t,x,u,w)
153+ test = true
154+ for i in 1 : model. dimStates
155+ test &= (x[i]>= model. xlim[i][1 ])& (x[i]<= model. xlim[i][2 ])
156+ end
157+ return test
158+ end
152159 if in (:finalCostFunction ,fieldnames (model))
153- SDPmodel = StochDynProgModel (model, model. finalCostFunction, true_fun )
160+ SDPmodel = StochDynProgModel (model, model. finalCostFunction, cons_fun )
154161 else
155- SDPmodel = StochDynProgModel (model, zero_fun, true_fun )
162+ SDPmodel = StochDynProgModel (model, zero_fun, cons_fun )
156163 end
157164 elseif isa (model,StochDynProgModel)
158165 SDPmodel = model
159166 else
160- error (" cannot build StochDynProgModel from current SPmodel. You need to implement
167+ error (" cannot build StochDynProgModel from current SPmodel. You need to implement
161168 a new StochDynProgModel constructor." )
162169 end
163-
170+
164171 # Display start of the algorithm in DH and HD cases
165172 if (param. infoStructure == " DH" )
166173 V = sdp_solve_DH (SDPmodel, param, display)
167174 elseif (param. infoStructure == " HD" )
168175 V = sdp_solve_HD (SDPmodel, param, display)
169176 else
170- error (" param.infoStructure is neither 'DH' nor 'HD'" )
177+ error (" param.infoStructure is neither 'DH' nor 'HD'" )
171178 end
172179
173180 return V
@@ -198,7 +205,7 @@ Returns :
198205function sdp_solve_DH (model:: StochDynProgModel ,
199206 param:: SDPparameters ,
200207 display= true :: Bool )
201-
208+
202209 TF = model. stageNumber
203210 next_state = zeros (Float64, model. dimStates)
204211 law = model. noises
@@ -264,10 +271,10 @@ function sdp_solve_DH(model::StochDynProgModel,
264271 w_sample = samples[:, w]
265272 proba = probas[w]
266273 next_state = model. dynamics (t, x, u, w_sample)
267-
268-
274+
275+
269276 if model. constraints (t, next_state, u, w_sample)
270-
277+
271278 count_admissible_w = count_admissible_w + proba
272279 ind_next_state = real_index_from_variable (next_state, x_bounds, x_steps)
273280 next_V = Vitp[ind_next_state... ]
@@ -438,8 +445,9 @@ Returns :
438445- V(x0) (Float64)
439446"""
440447function get_value (model:: SPModel ,param:: SDPparameters ,V:: Array{Float64} )
441- ind_x0 = index_from_variable (model. initialState, model. xlim, param. stateSteps)
442- return V[ind_x0... ,1 ]
448+ ind_x0 = real_index_from_variable (model. initialState, model. xlim, param. stateSteps)
449+ Vi = value_function_interpolation (model, V, 1 )
450+ return Vi[ind_x0... ,1 ]
443451end
444452
445453
0 commit comments