@@ -43,6 +43,11 @@ def _setup(nlp):
4343 orig_var_data = [
4444 (v , (v .lower , v .upper , v .domain , v .fixed , v .value )) for v in orig_vars
4545 ]
46+ for v , vdata in orig_var_data :
47+ if vdata [2 ].isdiscrete ():
48+ raise RuntimeError (
49+ 'Initialization module currently only supports continuous models.'
50+ )
4651 return orig_var_data
4752
4853
@@ -137,18 +142,19 @@ def initialize_with_piecewise_linear_approximation(
137142
138143 orig_var_data = _setup (nlp )
139144
140- res = _initialize_with_piecewise_linear_approximation (
141- nlp = nlp ,
142- mip_solver = mip_solver ,
143- nlp_solver = nlp_solver ,
144- default_bound = default_bound ,
145- max_iter = max_pwl_refinement_iter ,
146- num_cons_to_refine_per_iter = num_pwl_cons_to_refine_per_iter ,
147- aggressive_substitution = aggressive_substitution ,
148- bounds_tol = bounds_tol ,
149- )
150-
151- _cleanup (orig_var_data )
145+ try :
146+ res = _initialize_with_piecewise_linear_approximation (
147+ nlp = nlp ,
148+ mip_solver = mip_solver ,
149+ nlp_solver = nlp_solver ,
150+ default_bound = default_bound ,
151+ max_iter = max_pwl_refinement_iter ,
152+ num_cons_to_refine_per_iter = num_pwl_cons_to_refine_per_iter ,
153+ aggressive_substitution = aggressive_substitution ,
154+ bounds_tol = bounds_tol ,
155+ )
156+ finally :
157+ _cleanup (orig_var_data )
152158
153159 return res
154160
@@ -219,18 +225,19 @@ def initialize_with_LP_approximation(
219225 if lp_solver is None :
220226 lp_solver = _get_solver ('gurobi_persistent' , 'LP solver' )
221227
222- res = _initialize_with_LP_approximation (
223- nlp = nlp ,
224- lp_solver = lp_solver ,
225- nlp_solver = nlp_solver ,
226- default_bound = default_bound ,
227- num_samples = num_samples_per_nonlinear_constraint ,
228- seed = seed ,
229- use_univariate_nonlinear_decomposition = use_univariate_nonlinear_decomposition ,
230- aggressive_substitution = aggressive_substitution ,
231- )
232-
233- _cleanup (orig_var_data )
228+ try :
229+ res = _initialize_with_LP_approximation (
230+ nlp = nlp ,
231+ lp_solver = lp_solver ,
232+ nlp_solver = nlp_solver ,
233+ default_bound = default_bound ,
234+ num_samples = num_samples_per_nonlinear_constraint ,
235+ seed = seed ,
236+ use_univariate_nonlinear_decomposition = use_univariate_nonlinear_decomposition ,
237+ aggressive_substitution = aggressive_substitution ,
238+ )
239+ finally :
240+ _cleanup (orig_var_data )
234241
235242 return res
236243
@@ -279,10 +286,11 @@ def initialize_with_global_opt(
279286 if global_solver is None :
280287 global_solver = _get_solver ('gurobi_direct_minlp' , 'global NLP solver' )
281288
282- res = _initialize_with_global_solver (
283- nlp = nlp , global_solver = global_solver , nlp_solver = nlp_solver
284- )
285-
286- _cleanup (orig_var_data )
289+ try :
290+ res = _initialize_with_global_solver (
291+ nlp = nlp , global_solver = global_solver , nlp_solver = nlp_solver
292+ )
293+ finally :
294+ _cleanup (orig_var_data )
287295
288296 return res
0 commit comments