UserSpace.absref#
- UserSpace.absref(**kwargs)[source]#
Set references in absolute mode.
Creates references that maintain fixed bindings regardless of inheritance or space derivation. Absolute references always point to the exact object specified, even when accessed from derived spaces. The mode of a reference is relevant only when modelx objects, such as cells or spaces, are assigned to the reference.
This is a convenience method equivalent to calling
set_ref()withrefmode="absolute"for each reference.Absolute vs Relative:
Absolute: Reference always points to the same object
Relative: Reference adjusts based on inheritance context
- Parameters:
**kwargs – Keyword arguments where each key is the reference name and each value is the object to reference. Multiple references can be set in a single call.
Example
In the example below, a cells
foois defined in SpaceS.abs_fooin SpaceSis defined as an absolute reference tofoo, whilerel_foois defined as a relative reference.When Space
Sis inherited byS[y],abs_foocontinues to point toS.foo, whilerel_foopoints toS[y].foo, which uses the parameteryin stead ofS.y:>>> import modelx as mx >>> s = mx.new_space('S') >>> @mx.defcells ... def foo(x): ... return x + y >>> s.absref(abs_foo=foo) >>> s.relref(rel_foo=foo) >>> s.y = 0 >>> s.parameters = 'y' >>> s[1].abs_foo(10) # Absolute reference to S.foo 10 >>> s[1].rel_foo(10) # Relative reference to S[1].foo 11