B _? @sdZddlmZddlZddlZddlmZddlmZe dZ ddZ d d Z d d Z dddZddZddZe e e eedZddZdS)z/Helper functions for variable reinitialization.)divisionN)range)Varzpyomo.contrib.multistartcCs t||S)N)randomuniform)vallbubr C/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/contrib/multistart/reinit.pyrandsr cCs$||||kr|n|}||dS)z2Midpoint between current value and farthest bound.r )rrr far_boundr r r midpoint_guess_and_boundsrcCs$||||kr|n|}t||S)z7Random choice between current value and farthest bound.)rr)rrr rr r r rand_guess_and_boundsr cCst|||}t|S)zDRandom choice among evenly distributed set of values between bounds.)linspacerchoice)rrr Z divisionsZset_distributed_valsr r r rand_distributeds rcCs ||dS)Ng?r )rrr r r r simple_midpoint$srcsfddtDS)zLinearly spaced range.cs$g|]}|dqS)r ).0x)lowernupperr r *szlinspace..)r)rrrr )rrrr r(sr)r rrrZmidpointcCsx|jtddD]}|s|s&q|jdks:|jdkr\|jstd|j |j|jfq|j dk rl|j n|j|jd}t |j ||j|j|_ qWdS)zrReinitializes all variable values in the model. Excludes fixed, noncontinuous, and unbounded variables. T)ctypeZ descend_intoNzSkipping reinitialization of unbounded variable %s with bounds (%s, %s). To suppress this message, set the suppress_unbounded_warning flag.r ) Zcomponent_data_objectsrZis_fixedZ is_continuousrr Zsuppress_unbounded_warningloggerwarningnamevalue strategiesZstrategy)modelconfigvarrr r r reinitialize_variables6s r&)r)__doc__ __future__rloggingrZ six.movesrZ pyomo.corer getLoggerrr rrrrrr"r&r r r r s$