Space-local list of variables with an open length. More...
#include <gecode/int.hh>
Classes | |
| class | Object |
Public Types | |
| typedef std::function< Var(Space &home, int i)> | Factory |
| Function creating the variable at position i in home. | |
| typedef std::function< void(Space &home, OpenVarList< Var > x, int i)> | Transition |
| Function called after materializing position i. | |
Public Member Functions | |
| OpenVarList (void) | |
| Construct an uninitialized list. | |
| OpenVarList (Space &home, Factory create, int max=Int::Limits::max) | |
| Construct a list using create for each position. | |
| OpenVarList (Space &home, Factory create, Transition t, int max=Int::Limits::max) | |
| Construct a list using create and transition function t. | |
| void | update (Space &home, OpenVarList< Var > &s) |
| Update during cloning. | |
| int | known_length (void) const |
| Return the number of constructed positions (their values may be unassigned). | |
| Var | operator[] (int i) const |
| Return variable at position i, where 0 <= i < known_length(). | |
| IntVar | length (void) const |
| Return the eventual-length variable. | |
| void | append (Space &home, Var x) |
| Append variable x. | |
| void | materialize (Space &home, int n) |
| Materialize the first n variables. | |
| Var | get (Space &home, int i) |
| Require and return the variable at position i. | |
| void | close (Space &home) |
| Close the list at its materialized length. | |
| void | subscribe (Space &home, Propagator &p) |
| Subscribe p to the addition of positions. | |
| void | cancel (Space &home, Propagator &p) |
| Cancel the subscription of p to the addition of positions. | |
| void | reschedule (Space &home, Propagator &p) |
| Reschedule p for the addition of positions. | |
| Public Member Functions inherited from Gecode::LocalHandle | |
| LocalHandle & | operator= (const LocalHandle &lh) |
| Assignment operator. | |
| void | update (Space &home, LocalHandle &lh) |
| Updating during cloning. | |
| ~LocalHandle (void) | |
| Destructor. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Gecode::LocalHandle | |
| LocalHandle (void) | |
| Create local handle pointing to nullptr object. | |
| LocalHandle (LocalObject *lo) | |
| Create local handle that points to local object lo. | |
| LocalHandle (const LocalHandle &lh) | |
| Copy constructor. | |
| LocalObject * | object (void) const |
| Access to the local object. | |
| void | object (LocalObject *n) |
| Modify local object. | |
Detailed Description
class Gecode::OpenVarList< Var >
Space-local list of variables with an open length.
Append variables until the list is closed. The length() variable gives the eventual length; propagation creates the positions required by its minimum. known_length() counts the created positions, and operator[] accesses them. get() creates positions through a requested index and raises the minimum length to include it.
Copies of a handle share the list. update() preserves this sharing within each clone, with independent mutable state. Lists and appended variables must be initialized and belong to the supplied space.
OpenIntVarList and OpenBoolVarList supply variable factories. For other types, pass a factory to OpenVarList<Var>. Constraint and branching overloads depend on the variable type. Var must support default and copy construction, assignment, assigned(), varimp(), and update().
A list can be used in an ordinary Space:
The open-route example introduces construction, search, and printing. The common-pattern example uses an open list for a pattern of unknown length. It avoids allocating variables for the longest possible pattern and marking an unused suffix with a termination symbol.
Member Typedef Documentation
◆ Factory
| typedef std::function<Var(Space& home, int i)> Gecode::OpenVarList< Var >::Factory |
Function creating the variable at position i in home.
The function object is shared between clones. It must be deterministic and safe for concurrent calls. Captured data must be owned or shared and must not be space-local. Returned variables must belong to home and be initialized.
Calls run inside Space::NoGPI. Posted propagators have space-local information and zero AFC, so they do not affect AFC-based selection. Identifiers and groups are available; group changes are local to the space and copied on cloning. Use Space::UseGPI inside the callback for postings that need global information and ordinary AFC. Nested materialization enters its own NoGPI scope. Scopes restore the previous setting on exit, including exceptions.
◆ Transition
| typedef std::function<void(Space& home, OpenVarList<Var> x, int i)> Gecode::OpenVarList< Var >::Transition |
Function called after materializing position i.
Must be deterministic and safe for concurrent calls. Sharing, captured data, and NoGPI scopes follow the Factory contract. The arguments home and x refer to the current space. Both materialize() and direct append() call the transition after the new position is available through indexed access.
Constructor & Destructor Documentation
◆ OpenVarList() [1/3]
| Gecode::OpenVarList< Var >::OpenVarList | ( | void | ) |
Construct an uninitialized list.
Definition at line 288 of file open-var-list.hpp.
◆ OpenVarList() [2/3]
| Gecode::OpenVarList< Var >::OpenVarList | ( | Space & | home, |
| Factory | create, | ||
| int | max = Int::Limits::max ) |
Construct a list using create for each position.
Definition at line 295 of file open-var-list.hpp.
◆ OpenVarList() [3/3]
| Gecode::OpenVarList< Var >::OpenVarList | ( | Space & | home, |
| Factory | create, | ||
| Transition | t, | ||
| int | max = Int::Limits::max ) |
Construct a list using create and transition function t.
Definition at line 301 of file open-var-list.hpp.
Member Function Documentation
◆ update()
| void Gecode::OpenVarList< Var >::update | ( | Space & | home, |
| OpenVarList< Var > & | s ) |
Update during cloning.
Definition at line 317 of file open-var-list.hpp.
◆ known_length()
| int Gecode::OpenVarList< Var >::known_length | ( | void | ) | const |
Return the number of constructed positions (their values may be unassigned).
Definition at line 323 of file open-var-list.hpp.
◆ operator[]()
| Var Gecode::OpenVarList< Var >::operator[] | ( | int | i | ) | const |
Return variable at position i, where 0 <= i < known_length().
Definition at line 329 of file open-var-list.hpp.
◆ length()
| IntVar Gecode::OpenVarList< Var >::length | ( | void | ) | const |
Return the eventual-length variable.
Definition at line 337 of file open-var-list.hpp.
◆ append()
| void Gecode::OpenVarList< Var >::append | ( | Space & | home, |
| Var | x ) |
Append variable x.
Raises the minimum length to include x, then calls the transition if supplied (see Transition). Exceeding the maximum length fails the space. Throws Int::ArgumentSame if x is an unassigned variable already in the list.
Definition at line 343 of file open-var-list.hpp.
◆ materialize()
| void Gecode::OpenVarList< Var >::materialize | ( | Space & | home, |
| int | n ) |
Materialize the first n variables.
Raises the minimum length to at least n and creates the required positions, including any further increase imposed by the transition. Callbacks use the NoGPI scopes described in Factory.
Definition at line 350 of file open-var-list.hpp.
◆ get()
| Var Gecode::OpenVarList< Var >::get | ( | Space & | home, |
| int | i ) |
Require and return the variable at position i.
Calls materialize() with i+1.
Returns an uninitialized variable if home is failed or materialization fails. Throws Int::OutOfLimits for a negative index, an index outside Int::Limits, or (in a nonfailed space) an index at least length().max(). Check for failure before using the result, for example with an integer list:
Definition at line 357 of file open-var-list.hpp.
◆ close()
| void Gecode::OpenVarList< Var >::close | ( | Space & | home | ) |
Close the list at its materialized length.
Calls materialize() for the minimum length, then assigns length() to known_length(). The contained variables need not be assigned.
Definition at line 372 of file open-var-list.hpp.
◆ subscribe()
| void Gecode::OpenVarList< Var >::subscribe | ( | Space & | home, |
| Propagator & | p ) |
Subscribe p to the addition of positions.
This reports construction of positions. Subscribe separately to the length variable or contained variables for length or value changes.
Definition at line 385 of file open-var-list.hpp.
◆ cancel()
| void Gecode::OpenVarList< Var >::cancel | ( | Space & | home, |
| Propagator & | p ) |
Cancel the subscription of p to the addition of positions.
Definition at line 391 of file open-var-list.hpp.
◆ reschedule()
| void Gecode::OpenVarList< Var >::reschedule | ( | Space & | home, |
| Propagator & | p ) |
Reschedule p for the addition of positions.
Definition at line 397 of file open-var-list.hpp.
The documentation for this class was generated from the following files:
- gecode/int.hh
- gecode/int/open-var-list.hpp
