B @`b@s6dZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z ddlmZmZmZddlmZdd lmZmZmZmZdd lmZdd lmZdd lmZmZdd l m!Z!erddl"m#Z$n ddl%m#Z$e&dZ'ddZ(dddZ)GdddeZ*Gddde*Z+e,dGddde$eZ-dS))_LinearConstraintDataMatrixConstraint compile_block_linear_constraintsN)ref) is_debug_set)Any)SortComponentsVar)is_fixedvalue ZeroConstant)ModelComponentFactory) ConstraintIndexedConstraintSimpleConstraint_ConstraintData)native_numeric_types)generate_standard_repn) iteritemsPY3)xrange)Mappingz pyomo.corecCsT|dkrt|dS|dkr,t|ddS|dkrDt|ddSt|ddS)Ng@@z Bg.Az KBgeAz MBz GB)str)xr:/tmp/pip-unpacked-wheel-bi3529v6/pyomo/repn/beta/matrix.py _label_bytes-s rFTc) s|rtdtd|j|s0td|jg}g}g}g} g} dd} t} |r`tdtjtjB} dd|jd | |d D}t}|rtd || t} |rtd gx"|D]} |j t | d dqWt ddt Dt}|rtd|| t} |r(tdg}g}g}t}t}d}d}dg}x|D]x}t|drl|`x^|jtd | d d D]F}t|trtt|dkr|||fqt|t}xtt|D]\}}|jjtks|jdkr|r|||fn|||f|||ft |j}|j!dksFtg}g}t|j"dkrj|rqn4fdd|j"D}|#||j$dk st|j$}||dt|| || ||t|7}|d7}| |j%}| |j&} t'|j(}!| |dk r||!nd| | dk r,| |!nd|dk rb| dk rb|j)sb| tj*tj+BnV|j)rx| tj,n@|dk r| dkst| tj*n| dk st| tj+tj-||<qWqWqVWt|}"t}|rtd|| t} |rtdd}#d}$x$|D]\}}|.||$d7}$qWx|D]\}}|#d7}#qDWx,|D]$\}}|.||#d7}#|$d7}$q`Wx2|D]*\}}t|dkr|.||$d7}$qWt}|rtd|#|$ftd|| t} |rtdt/|}%t ddt |%Dfdd|D}fdd|%D}&t}|rbtd || t} |rtd!td"|rd#nd$|rd%nd&}'t00d'|}t00d'|}t00|'|}t00|'| } t00d(| } t}|r|1d|j2|1d|j2|1d|j2| 1d| j2| 1d| j2}(td)td*t3|td+t3|"td,t3|td-t3t4|(td.|| |5|t||"||||| | |& dS)/Nz3Compiling linear constraints on block with name: %sz@Attempting to compile block '%s' with unconstructed component(s)cSs0|dkr dSt|rt|Stdt|dS)Nznon-fixed bound: )r r ValueErrorr)exprrr _get_boundTs z4compile_block_linear_constraints.._get_boundzSorting active blocks...cSsg|]}|qSrr).0_brrr `sz4compile_block_linear_constraints..T)activesort descend_intoz(Time to sort active blocks: %.2f secondsz(Collecting variables on active blocks...F)r%r&css|]\}}t||fVqdS)N)id)r!indexvardatarrr ysz3compile_block_linear_constraints..z8Time to collect variables on active blocks: %.2f secondsz&Compiling active linear constraints...r_repncsg|]}t|qSr)r')r!r))VarIDToVarSymbolrrr#sz7Time to compile active linear constraints: %.2f secondsz'Removing compiled constraint objects...z=Eliminated %s constraints and %s Constraint container objectsz8Time to remove compiled constraint objects: %.2f secondsz$Assigning variable column indices...css|]\}}||fVqdS)Nr)r!columnsymbolrrrr*scsg|] }|qSrr)r!r0)VarSymbolToColumnIndexrrr#scsg|] }|qSrr)r!Z var_symbol)VarSymbolToVarObjectrrr#sz4Time to assign variable column indices: %.2f secondsz7Converting compiled constraint data to array storage...z) - Using %s precision for numeric valuesZsingledoublefdLBzSparse Matrix Dimension:z - Rows: z - Cols: z - Nonzeros: zCompiled Data Storage: zGTime to convert compiled constraint data to array storage: %.2f seconds)6printnameZis_constructed RuntimeErrortimerindicesZ alphabeticalZblock_data_objectsextendZcomponent_data_objectsr dict enumeratesethasattrr+Zcomponent_objectsr isinstancerAssertionErrorlenappendrlistrbody __class__rZpolynomial_degreeaddrZnonlinear_exprZ linear_varsupdateZ linear_coefslowerupperr constantequality LowerBound UpperBoundEqualityZSkipZ del_componentsortedarray buffer_infoitemsizerrZ add_component))Z parent_blockZconstraint_nameZskip_trivial_constraintsZsingle_precision_storageverboser&ZSparseMat_pRowsZSparseMat_jColsZSparseMat_ValsZRangesZ RangeTypesr start_timeZ sortOrderZ all_blocksZ stop_timeblockZconstraint_data_to_removeZ%empty_constraint_containers_to_removeZconstraint_containers_to_removeZconstraint_containers_to_checkZreferenced_variable_symbolsnnznrows constraintZ singletonr(Zconstraint_dataZrepnZrow_variable_symbolsZrow_coefficientsr6UrMncolsZconstraints_removedZconstraint_containers_removedZColumnIndexToVarSymbolZColumnIndexToVarObjectZnumber_storageZ storage_bytesr)r-r1r2rr:sf                                        F rc@seZdZdZdZdddZdS)ra This class defines the data for a single linear constraint in canonical form. Constructor arguments: component The Constraint object that owns this data. Public class attributes: active A boolean that is true if this constraint is active in the model. body The Pyomo expression for this constraint lower The Pyomo expression for the lower bound upper The Pyomo expression for the upper bound equality A boolean that indicates whether this is an equality constraint strict_lower A boolean that indicates whether this constraint uses a strict lower bound strict_upper A boolean that indicates whether this constraint uses a strict upper bound variables A tuple of variables comprising the body of this constraint coefficients A tuple of coefficients matching the order of variables that comprise the body of this constraint constant A number representing the aggregation of any constant/fixed items found in the body of this constraint Private class attributes: _component The objective component. _active A boolean that indicates whether this data is active rNcCs |dk rt|nd|_d|_dS)NT) weakref_ref _component_active)selfr( componentrrr__init__rsz_LinearConstraintData.__init__)N)__name__ __module__ __qualname____doc__ __slots__rcrrrrrNs rcseZdZdZdZd)ddZfddZd*d d Zd d Zd dZ ddZ ddZ ddZ e ddZe ddZeZe ddZe ddZe ddZe dd Ze d!d"Ze d#d$Ze d%d&Zd'd(ZZS)+_LinearMatrixConstraintDataa  This class defines the data for a single linear constraint derived from a canonical form Ax=b constraint. Constructor arguments: component The Constraint object that owns this data. Public class attributes: active A boolean that is true if this constraint is active in the model. body The Pyomo expression for this constraint lower The Pyomo expression for the lower bound upper The Pyomo expression for the upper bound equality A boolean that indicates whether this is an equality constraint strict_lower A boolean that indicates whether this constraint uses a strict lower bound strict_upper A boolean that indicates whether this constraint uses a strict upper bound variables A tuple of variables comprising the body of this constraint coefficients A tuple of coefficients matching the order of variables that comprise the body of this constraint constant A number representing the aggregate of any constants found in the body of this constraint Private class attributes: _component The objective component. _active A boolean that indicates whether this data is active _indexNcCs2|dk rt|nd|_d|_|dks(t||_dS)NTr)r^r_r`rCrj)rar(rbrrrrcs  z$_LinearMatrixConstraintData.__init__cstt|}|j|d<|S)zL This method must be defined because this class uses slots. rj)superri __getstate__rj)raresult)rHrrrls z(_LinearMatrixConstraintData.__getstate__Tc sx|}|}|j}|j|j|jy,tfddt||||dDStt fk rr|rndSXdS)zC Compute the value of the body of this constraint. c3s$|]}||VqdS)Nr)r!p)jcolsvalsvarmaprrr*sz7_LinearMatrixConstraintData.__call__..r,N) parent_componentr(_prows_jcols_varmap_valssumrr TypeError)ra exceptioncompr(prowsr)rorprqr__call__sz$_LinearMatrixConstraintData.__call__cCs|j}|dk o|tdkS)zYReturns :const:`False` when the lower bound is :const:`None` or negative infinityNz-inf)rKfloat)raZlbrrrhas_lbsz"_LinearMatrixConstraintData.has_lbcCs|j}|dk o|tdkS)zYReturns :const:`False` when the upper bound is :const:`None` or positive infinityNinf)rLr})raZubrrrhas_ubsz"_LinearMatrixConstraintData.has_ubcCs|j|dS)z Returns the value of L-f(x) for constraints of the form: L <= f(x) (<= U) (U >=) f(x) >= L N)rK)rarrrlslacksz"_LinearMatrixConstraintData.lslackcCs|j|dS)z Returns the value of U-f(x) for constraints of the form: (L <=) f(x) <= U U >= f(x) (>= L) N)rL)rarrruslacksz"_LinearMatrixConstraintData.uslackcCs|jS)N)rj)rarrrr(sz!_LinearMatrixConstraintData.indexcsh|}|j}|j|j||j||jdkr6dStfddt||j||jdD}|S)z4A tuple of variables comprising the constraint body.r,rc3s(|] }|js|VqdS)N)fixed)r!rn)rorqrrr*sz8_LinearMatrixConstraintData.variables..)rrrsrtrurjtupler)rarzr{ variablesr)rorqrrs z%_LinearMatrixConstraintData.variablescsp|}|j}|j|j|j||j||jdkr.)rrrsrtrvrurjrr)rarzr{Zcoefsr)rorprqr coefficientssz(_LinearMatrixConstraintData.coefficientscst|}|j}|j|j|j||j||jdkr.) rrrsrtrvrurjrrrw)rarzr{Ztermsr)rorprqrrM!s z$_LinearMatrixConstraintData.constantcsp|}|}|j}|j|j|j||j||jdkrDtStfddt ||||dDS)z+Access the body of a constraint expression.r,c3s"|]}||VqdS)Nr)r!rn)rorprqrrr*Asz3_LinearMatrixConstraintData.body..) rrr(rsrtrurvrjr rwr)rarzr(r{r)rorprqrrG6sz _LinearMatrixConstraintData.bodycCs2|}|}|j|tj@r.|jd|SdS)z2Access the lower bound of a constraint expression.N)rrr( _range_typesrrO_ranges)rarzr(rrrrKEs z!_LinearMatrixConstraintData.lowercCs6|}|}|j|tj@r2|jd|dSdS)z2Access the upper bound of a constraint expression.rr,N)rrr(rrrPr)rarzr(rrrrLNs z!_LinearMatrixConstraintData.uppercCs|j|tj@tjkS)z.) rloggerdebugr9Z _constructedrirrrDr_data)radatar)rrar constructs zMatrixConstraint.constructcCs |j|S)N)r)rakeyrrr __getitem__szMatrixConstraint.__getitem__cCs |jS)N)r__len__)rarrrrszMatrixConstraint.__len__cCstddtt|DS)Ncss|] }|VqdS)Nr)r!rrrrr*sz,MatrixConstraint.__iter__..)iterrrD)rarrr__iter__szMatrixConstraint.__iter__cCstdS)N)r)rar(rrrrrIszMatrixConstraint.addcCstdS)N)r)rarrr __delitem__szMatrixConstraint.__delitem__)N)rdrerfrrPrQrOrZNoBoundrcrrrrrIrrrrrrps  r)FFFT).__all__r;loggingrSweakrefrr^Zpyomo.common.logrZpyomo.core.base.set_typesrZpyomo.core.baserr Zpyomo.core.base.numvaluer r r Zpyomo.core.base.pluginr Zpyomo.core.base.constraintrrrrZpyomo.core.expr.numvaluerZ pyomo.repnrsixrrZ six.movesrcollections.abcrZcollections_Mapping collections getLoggerrrrrriregisterrrrrr s@          /t