B u `E:@s\ddlZddlmZddlmZmZddlmZmZddl m Z m Z ddl m Z mZddlmZmZddlmZmZed Zd.d d ZGd d d eZddZGdddeZddZGdddeZddZddZGdddeZ ddZ!GdddeZ"d d!Z#Gd"d#d#eZ$d$d%Z%Gd&d'd'eZ&d(d)Z'Gd*d+d+eZ(Gd,d-d-eZ)dS)/N) ComponentMap) Constraint_ConstraintData)Var_VarData) Expression_ExpressionData)Param _ParamData) Objective_ObjectiveData)Block _BlockDataz pyomo.pyspcsJfdd|jdddD}|dk rFt||krFtdj|j|f|S)z Return a list of all annotations of a given type on a Pyomo model. Setting the 'max_allowed' keyword will cause an exception to be raised if more than that many declarations of than annotation type are found on the model. cs4g|],}t|D]\}}t|r||fqqS)varsitems isinstance).0blocknameobj)annotation_typer:/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/pysp/annotations.py sz&locate_annotations..T)active descend_intoNzMToo many annotations of type %s found on model %s. The maximum allowed is %s.)Zblock_data_objectslen ValueError__name__r)modelrZ max_allowed annotationsr)rrlocate_annotationss   r!c@sFeZdZdZdZddZeddZeddZdd Z dd d Z d S)PySP_AnnotationrcCs<t|jdkstt|jt|jks*tt|_d|_dS)Nr)r_ctypesAssertionError _ctypes_datar_data_default)selfrrr__init__/szPySP_Annotation.__init__cCs|jS)N)r')r(rrrdefault5szPySP_Annotation.defaultcCstt|jdkS)Nr)boolrr&)r(rrrhas_declarations9sz PySP_Annotation.has_declarationscOsjt||js&t||js&t|ttfr:|j|f||n,td|jjd dd|jDt |fdS)NzQDeclarations in annotation type %s must be of types %s or Block. Invalid type: %s,css|] }|jVqdS)N)r)rctyperrr Gsz*PySP_Annotation.declare..) rr%r#r r _declare_impl TypeError __class__rjointype)r( componentargskwdsrrrdeclare=s  zPySP_Annotation.declareTc sRgtfdd}x0jD]$j}tddsBq$tjrZ||q$tjr|rx6D]"}|}t|ddrp|||qpWn ||q$ttrf}nttfddD}xv|D]n}|jrxbjD]X}|rxL|j |dddD]}|||qWqx$|j |dddD]}|||q.WqWqWq$WS)a Translates the annotation into a flattened list of (component, annotation_value) pairs. The ctypes argument can be a single component type are a tuple of component types. If any components are found in the annotation not matching those types, an exception will be raised. If 'expand_containers' is set to False, then component containers will not be flattened into the set of components they contain. csB||ft|kr0td|jjjft|dS)Na Component %s was assigned multiple declarations in annotation type %s. To correct this issue, ensure that multiple container components under which the component might be stored (such as a Block and an indexed Constraint) are not simultaneously set in this annotation.)appendid RuntimeErrorrr2radd)r5val) component_idsrr(rr_appendWs z/PySP_Annotation.expand_entries.._appendrTc3s|]}|VqdS)Nr)rindex)r5rrr/vsz1PySP_Annotation.expand_entries..)rr) setr&getattrrr%r#rr rZcomponent_data_objectsZcomponent_objects) r(Zexpand_containersr?Zcomponent_annotation_valuer@rZ block_listrr.r)r5r>rr(rexpand_entriesJsF                zPySP_Annotation.expand_entriesN)T) r __module__ __qualname__r#r%r)propertyr*r,r8rCrrrrr",s   r"cOstdt||S)NzpDEPRECATED: 'PySP_StageCostAnnotation' has been renamed to 'StageCostAnnotation'. Please update your model file.)loggerwarningStageCostAnnotation)r6r7rrrPySP_StageCostAnnotations rJcs8eZdZdZeefZeefZ fddZ ddZ Z S)rIaE This annotation is used to identify the component representing the objective cost associated with a time stage. The declare method should be called with an additional argument that is an integer greater than or equal to one, which signifies the time-stage of the initial component argument. cstt|d|_dS)N)superrIr)r')r()r2rrr)szStageCostAnnotation.__init__cCs*t||kst|dkst||j|<dS)N)intr$r&)r(r5stagerrrr0s z!StageCostAnnotation._declare_impl) rrDrE__doc__rrr#rrr%r)r0 __classcell__rr)r2rrIs   rIcOstdt||S)NzxDEPRECATED: 'PySP_VariableStageAnnotation' has been renamed to 'VariableStageAnnotation'. Please update your model file.)rGrHVariableStageAnnotation)r6r7rrrPySP_VariableStageAnnotations rRcs:eZdZdZeefZeefZ fddZ dddZ Z S)rQa This annotation is used to identify what time-stage a variable belongs to. The declare method should be called with an additional argument that is an integer greater than or equal to one, which signifies the time-stage of the initial component argument. The optional keyword 'derived' can be set to true to imply that a variable belongs to a particular time stage, but does not require non-anticipativity constraints be added when that time stage is not the last. cstt|d|_dS)N)rKrQr)r')r()r2rrr)sz VariableStageAnnotation.__init__FcCs.t||kst|dkst||f|j|<dS)NrL)rMr$r&)r(r5rNZderivedrrrr0s z%VariableStageAnnotation._declare_impl)F) rrDrErOrrr#rrr%r)r0rPrr)r2rrQs   rQcOstdt||S)NzDEPRECATED: 'PySP_ConstraintStageAnnotation' is no longer recognized (constraint stages are automatically inferred). It will be removed in the future. Please update your model file.)rGrH_ConstraintStageAnnotation)r6r7rrrPySP_ConstraintStageAnnotations rTcOstdt||S)NzDEPRECATED: 'ConstraintStageAnnotation' is no longer recognized (constraint stages are automatically inferred). It will be removed in the future. Please update your model file.)rGrHrS)r6r7rrrConstraintStageAnnotations rUcs4eZdZdZefZefZfddZddZ Z S)rSa This annotation is used to identify what time-stage a constraint belongs to. The declare method should be called with an additional argument that is an integer greater than or equal to one, which signifies the time-stage of the initial component argument. cstt|d|_dS)N)rKrSr)r')r()r2rrr)sz#_ConstraintStageAnnotation.__init__cCs*t||kst|dkst||j|<dS)NrL)rMr$r&)r(r5rNrrrr0s z(_ConstraintStageAnnotation._declare_impl) rrDrErOrr#rr%r)r0rPrr)r2rrSs   rScOstdt||S)NzzDEPRECATED: 'PySP_StochasticDataAnnotation' has been renamed to 'StochasticDataAnnotation'. Please update your model file.)rGrHStochasticDataAnnotation)r6r7rrrPySP_StochasticDataAnnotations rWcs6eZdZdZefZefZfddZdddZ Z S)rVa This annotation is used to identify stochastic data locations in constraints or the objective. When calling declare, if the second argument is set to None, this implies that the constant part of the expression (e.g., the constant in the objective or the or rhs of a constraint) should be marked as stochastic. The optional keyword 'distribution' can be set to a data distribution. cstt|d|_dS)N)rKrVr)r')r()r2rrr)sz!StochasticDataAnnotation.__init__NcCs||j|<dS)N)r&)r(r5 distributionrrrr0sz&StochasticDataAnnotation._declare_impl)N) rrDrErOr r#r r%r)r0rPrr)r2rrVs   rVcOstdt||S)NzDEPRECATED: 'PySP_StochasticRHSAnnotation' has been renamed to 'StochasticConstraintBoundsAnnotation'. Please update your model file.)rGrH$StochasticConstraintBoundsAnnotation)r6r7rrrPySP_StochasticRHSAnnotations rZcs6eZdZdZefZefZfddZdddZ Z S)rYa This annotation is used to identify constraints that have stochastic bound data. When calling declare, at most one of the keywords 'lb' or 'ub' can be set to False to disable the annotation on one side of any range type constraints. cstt|d|_dS)NT)rKrYr)r')r()r2rrr)sz-StochasticConstraintBoundsAnnotation.__init__TcCsZ|s |s t|dks |dks t|dks4|dks4t|rH|rHd|j|<n||f|j|<dS)NTF)r$r&)r(r5lbubrrrr0s   z2StochasticConstraintBoundsAnnotation._declare_impl)TT) rrDrErOrr#rr%r)r0rPrr)r2rrYs  rYcOstdt||S)NzDEPRECATED: 'PySP_StochasticMatrixAnnotation' has been renamed to 'StochasticConstraintBodyAnnotation'. Please update your model file.)rGrH"StochasticConstraintBodyAnnotation)r6r7rrrPySP_StochasticMatrixAnnotations r^cs6eZdZdZefZefZfddZdddZ Z S)r]a This annotation is used to identify constraints with stochastic data appearing in the body expression. When calling declare, the 'variables' keyword can be set to a list of variables whose coefficients should be treated as stochastic. Leaving 'variables' at its default of None signifies that coefficients of all variables appearing in the expression should be considered stochastic. cstt|d|_dS)N)rKr]r)r')r()r2rrr)3sz+StochasticConstraintBodyAnnotation.__init__NcCs||j|<dS)N)r&)r(r5 variablesrrrr07sz0StochasticConstraintBodyAnnotation._declare_impl)N) rrDrErOrr#rr%r)r0rPrr)r2rr]$s   r]cOstdt||S)NzDEPRECATED: 'PySP_StochasticObjectiveAnnotation' has been renamed to 'StochasticObjectiveAnnotation'. Please update your model file.)rGrHStochasticObjectiveAnnotation)r6r7rrr"PySP_StochasticObjectiveAnnotation:s racs6eZdZdZefZefZfddZdddZ Z S) r`a3 This annotation is used to identify variable cost-coefficients that are stochastic. When calling declare, the 'variables' keyword can be set to a list of variables whose coefficients should be treated as stochastic. Leaving 'variables' at its default of None signifies that the coefficients of all variables appearing in the expression should be considered stochastic. The 'include_constant' keyword signifies whether or not the constant term in the cost expression should be treated as stochastic (default is True). cstt|d|_dS)N)NT)rKr`r)r')r()r2rrr)Psz&StochasticObjectiveAnnotation.__init__NTcCs||f|j|<dS)N)r&)r(r5r_Zinclude_constantrrrr0Tsz+StochasticObjectiveAnnotation._declare_impl)NT) rrDrErOr r#r r%r)r0rPrr)r2rr`?s   r`cs6eZdZdZefZefZfddZdddZ Z S)"StochasticVariableBoundsAnnotationz This annotation is used to identify variable bounds that are stochastic. When calling declare, at most one of the keywords 'lb' or 'ub' can be set to False to disable the annotation for one of the variable bounds. cstt|d|_dS)N)TT)rKrbr)r')r()r2rrr)csz+StochasticVariableBoundsAnnotation.__init__TcCsF|s |s t|dks |dks t|dks4|dks4t||f|j|<dS)NTF)r$r&)r(r5r[r\rrrr0gs z0StochasticVariableBoundsAnnotation._declare_impl)TT) rrDrErOrr#rr%r)r0rPrr)r2rrbWs  rb)N)*loggingZpyomo.common.collectionsrZpyomo.core.base.constraintrrZpyomo.core.base.varrrZpyomo.core.base.expressionrrZpyomo.core.base.paramr r Zpyomo.core.base.objectiver r Zpyomo.core.base.blockr r getLoggerrGr!objectr"rJrIrRrQrTrUrSrWrVrZrYr^r]rar`rbrrrr s4   ]