B @`?:@sdgZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lZdd lZed Zd dZGdddeZe dGdddeZGdddeeZGdddeZd S)Arc)Port)ActiveComponentData)ActiveIndexedComponentUnindexedComponent_set)apply_indexed_rule)ModelComponentFactory) is_debug_set)ConstructionTimer) iteritems)refNz pyomo.networkcCst|tk r~y t|}Wntk r0d}YnX|dksFt|dkrRtd||rd|\}}d}nd}}t||||d}nd|kr||d<|S)NzAValue for arc '%s' is not either a dict or a two-member iterable.)source destinationportsdirectedr)typedicttuple TypeErrorlen ValueError)valsrnamerrrr5/tmp/pip-unpacked-wheel-bi3529v6/pyomo/network/arc.py_iterable_to_dicts$    rcseZdZdZdZdddZfddZdd Zed d Z e Z ed d Z e Z eddZ eddZeddZddZddZZS)_ArcDataam This class defines the data for a single Arc Attributes ---------- source: `Port` The source Port when directed, else None. Aliases to src. destination: `Port` The destination Port when directed, else None. Aliases to dest. ports: `tuple` A tuple containing both ports. If directed, this is in the order (source, destination). directed: `bool` True if directed, False if not expanded_block: `Block` A reference to the block on which expanded constraints for this arc were placed )_ports _directed_expanded_blockNcKsD|dk rt|nd|_d|_d|_d|_d|_t|r@||dS)NT) weakref_refZ _component_activerrr r set_value)self componentkwdsrrr__init__Isz_ArcData.__init__cs0tt|}xtjD]}t||||<qW|S)N)superr __getstate__ __slots__getattr)r$statei) __class__rrr)Ys z_ArcData.__getstate__cCsF|j}|dk r.y t||Stk r,YnXtd|jj|fdS)z/Returns `self.expanded_block.name` if it existsNz!'%s' object has no attribute '%s')expanded_blockr+AttributeErrorr.__name__)r$rZebrrr __getattr__cs z_ArcData.__getattr__cCs|jr|jdk r|jdSdS)Nr)rr)r$rrrrqsz_ArcData.sourcecCs|jr|jdk r|jdSdS)N)rr)r$rrrr{sz_ArcData.destinationcCs|jS)N)r)r$rrrrsz_ArcData.portscCs|jS)N)r)r$rrrrsz_ArcData.directedcCs|jS)N)r )r$rrrr/sz_ArcData.expanded_blockc Cs|jdk r|jn|j}t|||j}|dd}|dd}|dd}|dd}t|rtdddd t |D|dk r|dkr|dkr|r|dk ry|\}}d}Wqtd |jYqXn|std |j| ||||j dk rHt |}x|j D]}|j |qW|jrH|jj||jj||dk rZt|n||f|_|dk |_t |}x|jD]}|j |q~W|jr|j||j|dS) z#Set the port attributes on this arcNrrrrz0set_value passed unrecognized keywords in val: z css|]\}}d||fVqdS)z%s = %sNr).0kvrrr sz%_ArcData.set_value..zYFailed to unpack 'ports' argument of arc '%s'. Argument must be a 2-member tuple or list.zTPassed False value for 'directed' for arc '%s', but specified source or destination.)rZparent_component_init_directedrrpoprrjoinr _validate_portsrr!Z_arcsremoverZ_destsrZ_sourcesrrappend) r$rdrrrrZ weakref_selfportrrrr#sT             z_ArcData.set_valuec Csd|j}|dk r|dk s"|dk r.t|dt|ttfksJt|dkrVt|dxr|D]j}y<|jtk rt|d|jn|rt|d|jWq\t k rt|dt |Yq\Xq\Wn|dks|dkrt|dx|df|d fgD]\}}yH|jtk r(t|d |j|fn |rHt|d |j|fWqt k rxt|d t ||fYqXqWdS) NzArc %s: zEcannot specify 'source' or 'destination' when using 'ports' argument.r zBargument 'ports' must be list or tuple containing exactly 2 Ports.z.found object '%s' in 'ports' not of type Port.zBfound indexed Port '%s' in 'ports', must use single Ports for Arc.z>must specify both 'source' and 'destination' for directed Arc.rrz %s object '%s' not of type Port.z=found indexed Port '%s' as %s, must use single Ports for Arc.) rrrlistrrctyper is_indexedr0str)r$rrrmsgpZsiderrrr;sJ     z_ArcData._validate_ports)N)r1 __module__ __qualname____doc__r*r'r)r2propertyrsrcrdestrrr/r#r; __classcell__rr)r.rr3s       :rz(Component used for connecting two Ports.csBeZdZdZeZfddZfddZd ddZd d Z Z S) ra Component used for connecting the members of two Port objects Parameters ---------- source: `Port` A single Port for a directed arc. Aliases to src. destination: `Port` A single`Port for a directed arc. Aliases to dest. ports A two-member list or tuple of single Ports for an undirected arc directed: `bool` Set True for directed. Use along with `rule` to be able to return an implied (source, destination) tuple. rule: `function` A function that returns either a dictionary of the arc arguments or a two-member iterable of ports csL|tkrtt||S|r4|dtkr>t|dkr>ttSttSdS)Nrr3)rr(__new__rr SimpleArc IndexedArc)clsargsr&)r.rrrM s  z Arc.__new__cs|d|dd}|d|dd}|dd}|dd|_|dd|_|dttt|j|||dkr|dkr|dkrd|_nt|||d |_dS) NrrJrrKrrZrulerA)rrr) r9r8_rule setdefaultrr(r' _init_valsr)r$rQr&rrr)r.rrr's  z Arc.__init__Nc Csttrtd|j|jr"dSt|}d|_|jdkrH|jdkrHdS|jdk rj|jdk rjtd|j| }| s|jdkr|j}|j |d<n^y||}Wn>t k rt d}td|jt|j|fYnXt||j |j}|d|n|jdk rtd|jx|jD]~}yt||j||}WnFt k rt d}td |jt|t|j|fYnXt||j |j}|||q&W|dS) zInitialize the ArczConstructing Arc %sNTzMCannot specify rule along with source/destination/ports keywords for arc '%s'rr3z5Rule failed when generating values for arc %s: %s: %szHArc '%s': Cannot initialize multiple indices of an arc with single portszCRule failed when generating values for arc %s with index %s: %s: %s)r loggerdebugr _constructedr rRrTr_parentrBr8 Exceptionsysexc_infoerrorrr1rZ_setitem_when_not_present IndexError_indexrrCreport)r$dataZtimerZ self_parenttmperridxrrr construct$sV         z Arc.constructcCs:dt|fd|r|jndfd|jfgt|dddfS)z4Return data that will be printed for this component.SizeZIndexNActive)ZPortsZDirectedrfcSs"|jdk rd|jnd|j|jgS)Nz(%s, %s))rractive)r5r6rrrdszArc._pprint..)rrBr^rgr )r$rrr_pprint\s   z Arc._pprint)N) r1rFrGrHrZ_ComponentDataClassrMr'rdrirLrr)r.rrs    8cs$eZdZddZfddZZS)rNcOs"t||tj|f||dS)N)rr'r)r$rQr&rrrr'ks zSimpleArc.__init__cs\|jstd|jt|jdkr,||jd<ytt||Wn|jd=YnXdS)z Set the port attributes on this arc. If these values are being reassigned, note that the defaults are still None, so you may need to repass some attributes. zhSetting the value of arc '%s' before the Arc has been constructed (there is currently no object to set).rN)rWrrr_datar(rNr#)r$r)r.rrr#os  zSimpleArc.set_value)r1rFrGr'r#rLrr)r.rrNisrNcs(eZdZfddZeddZZS)rOcsd|_tt|j||dS)N)r r(rOr')r$rQr&)r.rrr'szIndexedArc.__init__cCs|jS)N)r )r$rrrr/szIndexedArc.expanded_block)r1rFrGr'rIr/rLrr)r.rrOs rO)__all__Zpyomo.network.portrZpyomo.core.base.componentrZ!pyomo.core.base.indexed_componentrrZpyomo.core.base.miscrZpyomo.core.base.pluginrZpyomo.common.logr Zpyomo.common.timingr sixr weakrefr r!loggingrZ getLoggerrUrrregisterrrNrOrrrr s$         Cs