@@ -263,36 +263,9 @@ def min_data_check(model, *mandatory_model_components):
263
263
264
264
def _add_min_data_check (model ):
265
265
"""
266
-
267
266
Bind the min_data_check() method to an instance of a Pyomo AbstractModel
268
267
object if it has not already been added. Also add a counter to keep
269
268
track of what to name the next check that is added.
270
-
271
- >>> from switch_model.utilities import _add_min_data_check
272
- >>> mod = AbstractModel()
273
- >>> _add_min_data_check(mod)
274
- >>> mod.set_A = Set(initialize=[1,2])
275
- >>> mod.paramA_full = Param(mod.set_A, initialize={1:'a',2:'b'})
276
- >>> mod.paramA_empty = Param(mod.set_A)
277
- >>> mod.min_data_check('set_A', 'paramA_full')
278
- >>> if hasattr(mod, 'create_instance'):
279
- ... instance_pass = mod.create_instance()
280
- ... else:
281
- ... instance_pass = mod.create()
282
- >>> mod.min_data_check('set_A', 'paramA_empty')
283
- >>> try:
284
- ... if hasattr(mod, 'create_instance'):
285
- ... instance_fail = mod.create_instance()
286
- ... else:
287
- ... instance_fail = mod.create()
288
- ... except ValueError as e:
289
- ... print e # doctest: +NORMALIZE_WHITESPACE
290
- ERROR: Constructing component 'min_data_check_2' from data=None failed:
291
- ValueError: Values are not provided for every element of the mandatory
292
- parameter 'paramA_empty'. Missing data for 2 values, including: [1, 2]
293
- Values are not provided for every element of the mandatory parameter
294
- 'paramA_empty'. Missing data for 2 values, including: [1, 2]
295
-
296
269
"""
297
270
if getattr (model , 'min_data_check' , None ) is None :
298
271
model .__num_min_data_checks = 0
@@ -331,43 +304,6 @@ def check_mandatory_components(model, *mandatory_model_components):
331
304
If an argument is a simple parameter, it must have a value.
332
305
333
306
This does not work with indexed sets.
334
-
335
- EXAMPLE:
336
- >>> from pyomo.environ import *
337
- >>> import switch_model.utilities as utilities
338
- >>> mod = ConcreteModel()
339
- >>> mod.set_A = Set(initialize=[1,2])
340
- >>> mod.paramA_full = Param(mod.set_A, initialize={1:'a',2:'b'})
341
- >>> mod.paramA_empty = Param(mod.set_A)
342
- >>> mod.set_B = Set()
343
- >>> mod.paramB_empty = Param(mod.set_B)
344
- >>> mod.paramC = Param(initialize=1)
345
- >>> mod.paramD = Param()
346
- >>> utilities.check_mandatory_components(mod, 'set_A', 'paramA_full')
347
- True
348
- >>> utilities.check_mandatory_components(mod, 'paramB_empty')
349
- True
350
- >>> utilities.check_mandatory_components(mod, 'paramC')
351
- True
352
- >>> utilities.check_mandatory_components(\
353
- mod, 'set_A', 'paramA_empty') # doctest: +NORMALIZE_WHITESPACE
354
- Traceback (most recent call last):
355
- ...
356
- ValueError: Values are not provided for every element of the mandatory
357
- parameter 'paramA_empty'. Missing data for 2 values, including: [1, 2]
358
- >>> utilities.check_mandatory_components(mod, 'set_A', 'set_B')
359
- Traceback (most recent call last):
360
- ...
361
- ValueError: No data is defined for the mandatory set 'set_B'.
362
- >>> utilities.check_mandatory_components(mod, 'paramC', 'paramD')
363
- Traceback (most recent call last):
364
- ...
365
- ValueError: Value not provided for mandatory parameter 'paramD'
366
-
367
- # Demonstration of incorporating this function into Pyomo's BuildCheck()
368
- >>> mod.min_dat_pass = BuildCheck(\
369
- rule=lambda m: utilities.check_mandatory_components(\
370
- m, 'set_A', 'paramA_full','paramB_empty', 'paramC'))
371
307
"""
372
308
373
309
for component_name in mandatory_model_components :
0 commit comments