B @`@sddlmZmZddlmmmZddlmZm Z ddl m Z m Z ddl m Z ddlmmmZddlZddlmZddlmZddlmZdd lmZdd lmZmZddlZdd lm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&m'Z'e(e)Z*Gd dde!Z+ddZ,ddZ-ddZ.ddZ/ddZ0ddZ1ddZ2ddZ3dd Z4d!d"Z5d#d$Z6d%d&Z7d'd(Z8d)d*Z9d+d,Z:d-d.Z;e<Z=e2e=d/<e3e=d0<e4e=d1<e5e=d2<e6e=d3<e7e=d4<e8e=d5<e9e=d6<e:e=d7<e;e=d8<d9d:Z>d;d<Z?e<Z@e,e@ejA<e.e@ejB<e0e@ejC<e/e@ejD<e-e@ejE<e,e@ejF<e1e@ejG<e>e@ejH<e,e@ejI<e.e@ejJ<e0e@ejK<e/e@ejL<e-e@ejM<e1e@ejN<e>e@ejO<e?e@e<e?e@e<d=d>ZPd?d@ZQdAdBZRdCdDZSdEdFZTdGdHZUdIdJZVdKdLZWdMdNZXdOdPZYdQdRZZdSdTZ[dUdVZ\dWdXZ]dYdZZ^d[d\Z_e<Z`eWe`d/<eXe`d0<eYe`d1<eZe`d2<e[e`d3<e\e`d4<e]e`d5<e^e`d6<e_e`d7<eTe`d8<d]d^Zad_d`Zbe<ZcePecejA<eRecejB<eUecejC<eSecejD<eQecejE<ePecejF<eVecejG<eaecejH<ePecejI<eRecejJ<eUecejK<eSecejL<eQecejM<eVecejN<eaecejO<ebece<ebece<dadbZdGdcddddeZeGdedfdfeZfdgdhZgdidjZhdvdpdqZdrdsZiGdtduduejZkdS)w) ComponentMap ComponentSetN)ExpressionValueVisitoridentify_variables)nonpyomo_leaf_typesvalue)is_fixed)Block) Constraint)Var)Disjunct)_GeneralExpressionDataSimpleExpression)InfeasibleConstraintExceptionPyomoException) ConfigBlock ConfigValueInNonNegativeFloatNonNegativeIntc@s eZdZdS) FBBTExceptionN)__name__ __module__ __qualname__rr;/tmp/pip-unpacked-wheel-bi3529v6/pyomo/contrib/fbbt/fbbt.pyr@src CsLt|jdkst|j\}}||\}}||\}}t||||||<dS)an Parameters ---------- node: pyomo.core.expr.numeric_expr.ProductExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). N)lenargsAssertionErrorintervalmul) node bnds_dictfeasibility_tolarg1arg2lb1ub1lb2ub2rrr)_prop_bnds_leaf_to_root_ProductExpressionDs    r+c Csh|d}||\}}x@td|D].}||}||\}} t|||| \}}q&W||f||<dS)aj Parameters ---------- node: pyomo.core.expr.numeric_expr.SumExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). rN)argrangenargsr add) r"r#r$Zarg0lbubir-r)r*rrr%_prop_bnds_leaf_to_root_SumExpressionYs    r4c CsPt|jdkst|j\}}||\}}||\}}tj|||||d||<dS)ao Parameters ---------- node: pyomo.core.expr.numeric_expr.DivisionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r)r$N)rrrr div) r"r#r$r%r&r'r(r)r*rrr*_prop_bnds_leaf_to_root_DivisionExpressionps    r6c CsLt|jdkst|j\}}||\}}||\}}t||||||<dS)aj Parameters ---------- node: pyomo.core.expr.numeric_expr.PowExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). rN)rrrr power) r"r#r$r%r&r'r(r)r*rrr%_prop_bnds_leaf_to_root_PowExpressions    r8cCs>t|jdkst|jd}||\}}t|||||<dS)aq Parameters ---------- node: pyomo.core.expr.numeric_expr.ReciprocalExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr inv)r"r#r$r-r'r(rrr,_prop_bnds_leaf_to_root_ReciprocalExpressions  r:cCs@t|jdkst|jd}||\}}tdd||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr sub)r"r#r$r-r'r(rrr*_prop_bnds_leaf_to_root_NegationExpressions  r<cCs<t|jdkst|jd}||\}}t||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr exp)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_exps  r>cCs<t|jdkst|jd}||\}}t||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr log)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_logs  r@cCs<t|jdkst|jd}||\}}t||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr log10)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_log10s  rBcCs<t|jdkst|jd}||\}}t||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr sin)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_sins  rDcCs<t|jdkst|jd}||\}}t||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr cos)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_coss  rFcCs<t|jdkst|jd}||\}}t||||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr tan)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_tan&s  rHcCsHt|jdkst|jd}||\}}t||tj tj|||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr asininf)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_asin:s  rKcCsHt|jdkst|jd}||\}}t||tj tj|||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr acosrJ)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_acosNs  rMcCsFt|jdkst|jd}||\}}t||tj tj||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rN)rrrr atanrJ)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_atanbs  rOcCs@t|jdkst|jd}||\}}t||dd||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r,rg?N)rrrr r7)r"r#r$r-r'r(rrr_prop_bnds_leaf_to_root_sqrtvs  rPr=r?rArCrErGrIrLrNsqrtcCs8|tkr"t||||ntj tjf||<dS)at Parameters ---------- node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). N)getname_unary_leaf_to_root_mapr rJ)r"r#r$rrr/_prop_bnds_leaf_to_root_UnaryFunctionExpressions rTcCs||j\}}||f||<dS)a Propagate bounds from children to parent Parameters ---------- node: pyomo.core.base.expression._GeneralExpressionData bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). N)expr)r"r#r$expr_lbexpr_ubrrr)_prop_bnds_leaf_to_root_GeneralExpressionsrXcCst|jdkst|j\}}||\}}||\}}||\} } t||| | |\} } t|||||\} }| |krx| }| |kr| }| | kr| } || kr|} ||f||<| | f||<dS)an Parameters ---------- node: pyomo.core.expr.numeric_expr.ProductExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). rN)rrrr r5)r"r#r$r%r&lb0ub0r'r(r)r*_lb1_ub1_lb2_ub2rrr)_prop_bnds_root_to_leaf_ProductExpressions"     r_c Cs t}|||d||\}}xNtd|D]<}||d\}}|||\} } |t||| | q6W|||ddkr|||ddf||d<|||ddkr||dd|f||d<xttd|D]}||\}}||d\} } |||\} }t||| |\} } t||| | \}}| | krj| } | | krx| } || kr|} ||kr|}| | f||d<| |f|||<qW||d\}}|d\}}||kr|}||kr|}||f||d<dS)a  This function is a bit complicated. A simpler implementation would loop through each argument in the sum and do the following: bounds_on_arg_i = bounds_on_entire_sum - bounds_on_sum_of_args_excluding_arg_i and the bounds_on_sum_of_args_excluding_arg_i could be computed for each argument. However, the computational expense would grow approximately quadratically with the length of the sum. Thus, we do the following. Consider the expression y = x1 + x2 + x3 + x4 and suppose we have bounds on y. We first accumulate bounds to obtain a list like the following [(x1)_bounds, (x1+x2)_bounds, (x1+x2+x3)_bounds, (x1+x2+x3+x4)_bounds] Then we can propagate bounds back to x1, x2, x3, and x4 with the following (x4)_bounds = (x1+x2+x3+x4)_bounds - (x1+x2+x3)_bounds (x3)_bounds = (x1+x2+x3)_bounds - (x1+x2)_bounds (x2)_bounds = (x1+x2)_bounds - (x1)_bounds Parameters ---------- node: pyomo.core.expr.numeric_expr.ProductExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). rr,N) listappendr-r.r/r r0reversedr;)r"r#r$Zaccumulated_boundsrYrZr3Z_lb0Z_ub0r[r\r'r(r)r*r]r^r1r2_lb_ubrrr%_prop_bnds_root_to_leaf_SumExpressionsD& $$        recCst|jdkst|j\}}||\}}||\}}||\} } t||| | \} } tj|||||d\} }| |krx| }| |kr| }| | kr| } || kr|} ||f||<| | f||<dS)ao Parameters ---------- node: pyomo.core.expr.numeric_expr.DivisionExpression bnds_dict: ComponentMap feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). r)r$N)rrrr r!r5)r"r#r$r%r&rYrZr'r(r)r*r[r\r]r^rrr*_prop_bnds_root_to_leaf_DivisionExpression@s"     rfc Cst|jdkst|j\}}||\}}||\}}||\} } tj||| | |||d\} } | |krh| }| |krt| }||f||<t|r| | krn|}||krJ|}||fS)zg This function ensures that lb is not less than var.lb and that ub is not greater than var.ub. N)rr1r2r rJ)varr1r2Zorig_lbZorig_ubrrr_check_and_reset_bounds s  rc@s*eZdZdZd ddZddZdd Zd S) _FBBTVisitorLeafToRootz This walker propagates bounds from the variables to each node in the expression tree (all the way to the root node). -C6?:0yE>cCs||_||_||_dS)aw Parameters ---------- bnds_dict: ComponentMap integer_tol: float feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). N)r# integer_tolr$)selfr#rr$rrr__init__!s z_FBBTVisitorLeafToRoot.__init__cCs:|jtkr"t|j||j|jntj tjf|j|<dS)N) __class___prop_bnds_leaf_to_root_mapr#r$r rJ)rr"valuesrrrvisit2s z_FBBTVisitorLeafToRoot.visitcCs|jtkr||f|j|<dS|r|rcCs||_||_||_dS)aw Parameters ---------- bnds_dict: ComponentMap integer_tol: float feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). N)r#rr$)rr#rr$rrrr]s z_FBBTVisitorRootToLeaf.__init__cCsdS)Nr)rr"rrrrrnsz_FBBTVisitorRootToLeaf.visitcCs`|jtkrX|j|\}}t|t||jkr6tdt|t||jkrTtddS|r|j|\}}|j|\}}||kr||j|krtd|||n2||j8}||j7}t |||\}}||f|j|<|t j krtd||t j krtd|| s"| r|t j krLtt|t||j}|t j krttt|t||j}t |||\}}||f|j|<|t j kr|||t j kr||dS|s |j|\}}t|t||jkrtdt|t||jkrtddS|jtkrDt|j||j|jntdtt|dS)Nz"Detected an infeasible constraint.)TNzZLower bound ({1}) computed for variable {0} is larger than the computed upper bound ({2}).z/Computed a lower bound of +inf for variable {0}z0Computed an upper bound of -inf for variable {0}z`Unsupported expression type for FBBT: {0}. Bounds will not be improved in this part of the tree.)FN)rrr#absrr$rrr{rr rJZ is_binary is_integermaxmathfloorceilrminsetlbsetubr_prop_bnds_root_to_leaf_mapryrzrtype)rr"r1r2rrrrqsZ            z._FBBTVisitorRootToLeaf.visiting_potential_leafN)rr)rrrrrrrrrrrrWs rc Cs~|js tSt}t||jd}||jt|j}t|j}|dkrPt j }|dkr^t j }||j\}}|||jks|||jkrt d t ||jr|||jkr|||jkr|||kr|}||kr|}||f||j<t||j|jd}||jt} xj|D]^\} } | jtkr0q| r|| \}}|t j krXd}|t j krhd}||f| | <qW| S)a Feasibility based bounds tightening for a constraint. This function attempts to improve the bounds of each variable in the constraint based on the bounds of the constraint and the bounds of the other variables in the constraint. For example: >>> import pyomo.environ as pe >>> from pyomo.contrib.fbbt.fbbt import fbbt >>> m = pe.ConcreteModel() >>> m.x = pe.Var(bounds=(-1,1)) >>> m.y = pe.Var(bounds=(-2,2)) >>> m.z = pe.Var() >>> m.c = pe.Constraint(expr=m.x*m.y + m.z == 1) >>> fbbt(m.c) >>> print(m.z.lb, m.z.ub) -1.0 3.0 Parameters ---------- con: pyomo.core.base.constraint.Constraint constraint on which to perform fbbt config: ConfigBlock see documentation for fbbt Returns ------- new_var_bounds: ComponentMap A ComponentMap mapping from variables a tuple containing the lower and upper bounds, respectively, computed from FBBT. )r$Nz2Detected an infeasible constraint during FBBT: {0})rr$)activerrr$dfs_postorder_stackbodyrlowerupperr rJrr{r deactivate_satisfied_constraintsZ deactivaterritemsrrr) conconfigr#ZvisitorArcrdr1r2ZvisitorBnew_var_bounds_node_bndsrrr _fbbt_consH        rcCst}t}t}t}d}x|jtddddD]}x|t|jD]n}||krVt||<|jdkrntj ||<nt |j||<|j dkrtj||<nt |j ||<|| |q@W|d7}q0WxJ|jt ddddD]4} | r| | j | | j | j | j f|| <qWd} t} x|jtddddD]}t||} | d7} || x~| D]r\}} | \}}|dk r||||jkr| ||||<|dk rR||||jkrR| ||||<qRWq(Wxt| dkr| ||jkrP| }x||D]}t||} | d7} || x~| D]r\} } | \}}|dk rl||| |jkrl| | ||| <|dk r,||| |jkr,| | ||| <q,WqWqW|S)aC Feasibility based bounds tightening (FBBT) for a block or model. This loops through all of the constraints in the block and performs FBBT on each constraint (see the docstring for _fbbt_con()). Through this processes, any variables whose bounds improve by more than tol are collected, and FBBT is performed again on all constraints involving those variables. This process is continued until no variable bounds are improved by more than tol. Parameters ---------- m: pyomo.core.base.block.Block or pyomo.core.base.PyomoModel.ConcreteModel config: ConfigBlock See the docs for fbbt Returns ------- new_var_bounds: ComponentMap A ComponentMap mapping from variables a tuple containing the lower and upper bounds, respectively, computed from FBBT. rT)ctyper descend_intosortNr,)rcomponent_data_objectsr rrr`r1r rJrr2rar rrrrrupdaterimprovement_tolr0rmax_iterpop)mrrZvar_to_con_mapZvar_lbsZvar_ubsZn_conscvZ_vZn_fbbtZ improved_vars_new_var_boundsbndsZvlbZvubZ_vlbZ_vubrrr _fbbt_blocksv                     rFh㈵>:0yE>rp-C6?cCst}t|tddhd}t|td}t|td} t|td} t|td} |d||d||d| |d| |d| t} |jtkr| rx:| D]} t ||}| |qWnt ||}| |n8|jt thkrt||}| |ntd t|| S) ad Perform FBBT on a constraint, block, or model. For more control, use _fbbt_con and _fbbt_block. For detailed documentation, see the docstrings for _fbbt_con and _fbbt_block. Parameters ---------- comp: pyomo.core.base.constraint.Constraint or pyomo.core.base.block.Block or pyomo.core.base.PyomoModel.ConcreteModel deactivate_satisfied_constraints: bool If deactivate_satisfied_constraints is True and a constraint is always satisfied, then the constranit will be deactivated integer_tol: float If the lower bound computed on a binary variable is less than or equal to integer_tol, then the lower bound is left at 0. Otherwise, the lower bound is increased to 1. If the upper bound computed on a binary variable is greater than or equal to 1-integer_tol, then the upper bound is left at 1. Otherwise the upper bound is decreased to 0. feasibility_tol: float If the bounds computed on the body of a constraint violate the bounds of the constraint by more than feasibility_tol, then the constraint is considered infeasible and an exception is raised. This tolerance is also used when performing certain interval arithmetic operations to ensure that none of the feasible region is removed due to floating point arithmetic and to prevent math domain errors (a larger value is more conservative). max_iter: int Used for Blocks only (i.e., comp.ctype == Block). When performing FBBT on a Block, we first perform FBBT on every constraint in the Block. We then attempt to identify which constraints to repeat FBBT on based on the improvement in variable bounds. If the bounds on a variable improve by more than improvement_tol, then FBBT is performed on the constraints using that Var. However, this algorithm is not guaranteed to converge, so max_iter limits the total number of times FBBT is performed to max_iter times the number of constraints in the Block. improvement_tol: float Used for Blocks only (i.e., comp.ctype == Block). When performing FBBT on a Block, we first perform FBBT on every constraint in the Block. We then attempt to identify which constraints to repeat FBBT on based on the improvement in variable bounds. If the bounds on a variable improve by more than improvement_tol, then FBBT is performed on the constraints using that Var. Returns ------- new_var_bounds: ComponentMap A ComponentMap mapping from variables a tuple containing the lower and upper bounds, respectively, computed from FBBT. TF)defaultdomainrrr$rrz*Cannot perform FBBT on objects of type {0})rrrrrZdeclarerrr is_indexedrrrr r rrr{r)comprrr$rrrZ dsc_configZinteger_tol_configZ ft_configZ mi_configZimprovement_tol_configrZ_crrrrfbbtos0+               rcCsJt}t|}||||\}}|tj kr4d}|tjkrBd}||fS)z Compute bounds on an expression based on the bounds on the variables in the expression. Parameters ---------- expr: pyomo.core.expr.numeric_expr.ExpressionBase Returns ------- lb: float ub: float N)rrrr rJ)rUr#Zvisitorr1r2rrrcompute_bounds_on_exprs     rc@s0eZdZddZddZd ddZd d d Zd S) BoundsManagercCst|_t|_|jtkr\|rHx6|D]}|jt |j q,Wq|jt |j n.x,|j tddddD]}|jt |j qpWdS)NT)rrr) r_varsr` _saved_boundsrr rrrrrr)rrrrrrrs zBoundsManager.__init__cCs6t}x|jD]}|j|jf||<qW|j|dS)N)rrr1r2rra)rrrrrr save_boundss zBoundsManager.save_boundscCsB|j|}x0|D]$\}}|\}}||||qWdS)N)rrrrr)rZndxrrrr1r2rrr pop_boundss   zBoundsManager.pop_boundsTcCsL|r |x:|D].\}}||jkr|\}}||||qWdS)N)rrrrr)rrZsave_current_boundsrrr1r2rrr load_boundss  zBoundsManager.load_boundsN)r)T)rrrrrrrrrrrrs r)Frrrpr)lZpyomo.common.collectionsrrZpyomo.core.expr.numeric_exprcorerUZ numeric_exprZpyomo.core.expr.visitorrrZpyomo.core.expr.numvaluerrrZpyomo.contrib.fbbt.intervalcontribrr rZpyomo.core.base.blockr Zpyomo.core.base.constraintr Zpyomo.core.base.varr Z pyomo.gdpr Zpyomo.core.base.expressionr rloggingZpyomo.common.errorsrrZpyomo.common.configrrrrr getLoggerrryrr+r4r6r8r:r<r>r@rBrDrFrHrKrMrOrPdictrSrTrXrZProductExpressionZDivisionExpressionZReciprocalExpressionZ PowExpressionZ SumExpressionZMonomialTermExpressionZNegationExpressionZUnaryFunctionExpressionZNPV_ProductExpressionZNPV_DivisionExpressionZNPV_ReciprocalExpressionZNPV_PowExpressionZNPV_SumExpressionZNPV_NegationExpressionZNPV_UnaryFunctionExpressionr_rerfrjrkrlrmrnrorqrrrsrtrurvrwrxr|r}rrrrrrrobjectrrrrr s      %               !K!%               ;iT[ H