the implicit graph of a grid map, the cells of cost \( C \) and the weights of the moves of type \( W \), whose changes of the costs are told through the subject policy Policy [see Modification.h]
More...
|
| | GridGraph (int rows, int cols, GridMoves moves=GridMoves::FOUR, Corners corners=Corners::NO_CUT, W straight=W(1), std::optional< W > diagonal=std::nullopt, MoveCost model=MoveCost::ENTERED) |
| | the grid of \( \mathit{rows} \times \mathit{cols} \) free cells of cost 1, with no vector; the diagonal cost \( \sqrt{2} \) times the straight one if not given
|
| | GridGraph (int rows, int cols, std::vector< C > cost, GridMoves moves=GridMoves::FOUR, Corners corners=Corners::NO_CUT, W straight=W(1), std::optional< W > diagonal=std::nullopt, MoveCost model=MoveCost::ENTERED) |
| | the grid of \( \mathit{rows} \times \mathit{cols} \) cells of the given costs, \( \mathit{cost}[ r \cdot \mathit{cols} + c ] \) that of the cell \( ( r , c ) \), a cell blocked if its cost is not positive, each move weighed by the cost of the cell that \( \mathit{model} \) names (with no vector, as above, the two models coincide)
|
template<class... O>
requires ( sizeof...( O ) > 0 ) |
| | GridGraph (int rows, int cols, std::vector< C > cost, GridMoves moves, Corners corners, W straight, std::optional< W > diagonal, MoveCost model, O &... o) |
| | the grid of the given costs as above, every parameter given, and the static observers o... of Policy, which must outlive it
|
| int | rows (void) const |
| | the number of rows
|
| int | cols (void) const |
| | the number of columns
|
| GridMoves | moves (void) const |
| | the moves
|
| Corners | corners (void) const |
| | the rule on the corners
|
| MoveCost | moveCost (void) const |
| | the cell whose cost weighs a move
|
| W | straight (void) const |
| | the cost of a move to a side on a map of unit costs
|
| W | diagonal (void) const |
| | the cost of a move to a corner on a map of unit costs
|
| bool | directed (void) const |
| | whether the graph is oriented, i.e., two free cells cost differently
|
| int | n (void) const |
| | the number of nodes, the free cells
|
| int | bound (void) const |
| | the names of the nodes are in \( [ 0 , \mathit{rows} \cdot \mathit{cols}
) \)
|
| bool | hasNode (int u) const |
| | whether \( u \) is a free cell
|
| int | node (int r, int c) const |
| | the node of the cell \( ( r , c ) \)
|
| GridCell | cell (int u) const |
| | the cell \( ( r , c ) \) of the name \( u \)
|
| C | cost (int u) const |
| | the cost of the cell \( u \), not positive if blocked
|
| C | minCost (void) const |
| | the least cost of a free cell, 1 if there is no vector of the costs or no free cell
|
| void | setCost (int u, const C &c) |
| | the cost of the cell \( u \) set to \( c \), the cell blocked if \( c \) is not positive and free otherwise, and CellChanged told with the cost before and \( c \); nothing if the cost is already \( c \)
|
| template<class F> |
| void | forEachAffected (int u, const C &from, const C &to, F &&f) const |
| | \( f( v ) \), in increasing order of \( v \), on each cell \( v \) whose moves in may have been created, removed or weighed differently by a change of the cost of the cell \( u \) from \( \mathit{from} \) to \( \mathit{to} \), i.e., on a superset of the heads of the arcs that the change touched: none if the cell is blocked before and after, \( u \) (under ENTERED) or its free neighbors (under LEFT) if it is free before and after, \( u \) and its free neighbors of the four or the eight moves if it changes between free and blocked; at most nine calls, read on the grid after the change
|
| std::vector< int > | V (void) const |
| | the set of the nodes, in increasing order
|
| std::vector< int > | adj (int u) const |
| | the neighbors of \( u \), in increasing order
|
| template<class F> |
| void | forEachAdj (int u, F &&f) const |
| | \( f( v ) \) on each neighbor \( v \) of \( u \), in increasing order, with no allocation
|
| template<class F> |
| void | forEachEdge (int u, F &&f) const |
| | \( f( v , w ) \) on each neighbor \( v \) of \( u \), \( w \) the cost of the move, in increasing order of \( v \)
|
| template<class F> |
| void | forEachMove (int u, F &&f) const |
| | \( f( v , d ) \) on each neighbor \( v \) of \( u \), in increasing order, \( d \) whether the move is to a corner, with no allocation: the weight of the move is \( \mathit{cost}( x ) \) times diagonal() if \( d \) and straight() if not, \( x \) the cell that moveCost() names
|
template<class D>
requires ( Subject::dynamic ) |
| int | attach (D &o) |
| | attaches the observer \( o \) and gives its number
|
| void | detach (int id) |
| | detaches the observer number \( \mathit{id} \)
|
| Batch | batch (void) |
| | opens a batch: the events are collected until it is closed, and sent coalesced
|
| Subject & | subject (void) |
| | the subject, for ADS::batch() and ADS::quiet()
|
| const Subject & | subject (void) const |
| | the subject
|
| auto | nodes (void) const |
| | the nodes in increasing order, a view on the names that skips the blocked cells
|
template<class W = int, class C = W, class Policy = NoObservers>
class ADS::GridGraph< W, C, Policy >
the implicit graph of a grid map, the cells of cost \( C \) and the weights of the moves of type \( W \), whose changes of the costs are told through the subject policy Policy [see Modification.h]
template<class W = int, class C = W, class Policy = NoObservers>
template<class F>
| void ADS::GridGraph< W, C, Policy >::forEachAffected |
( |
int | u, |
|
|
const C & | from, |
|
|
const C & | to, |
|
|
F && | f ) const |
\( f( v ) \), in increasing order of \( v \), on each cell \( v \) whose moves in may have been created, removed or weighed differently by a change of the cost of the cell \( u \) from \( \mathit{from} \) to \( \mathit{to} \), i.e., on a superset of the heads of the arcs that the change touched: none if the cell is blocked before and after, \( u \) (under ENTERED) or its free neighbors (under LEFT) if it is free before and after, \( u \) and its free neighbors of the four or the eight moves if it changes between free and blocked; at most nine calls, read on the grid after the change
In pseudocode (beyond the book), \( N( u ) \) the cells at a move of \( u \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{forEachAffected}( u , a , c , f ) \cr
2 & \quad \textbf{if}\ a \le 0\ \textbf{and}\ c \le 0
\ \textbf{then}\ \textbf{return} \cr
3 & \quad \textbf{if}\ a > 0\ \textbf{and}\ c > 0\ \textbf{then} \cr
4 & \qquad \textbf{if}\ \text{the cell entered pays}\ \textbf{then}
\ f( u )\ \textbf{else foreach}\ v \in \mathrm{adj}( u )
\ \textbf{do}\ f( v ) \cr
5 & \quad \textbf{else foreach}\ v \in \{ u \} \cup \{ x \in
N( u ) : x \text{ free} \}\ \text{in increasing order}
\ \textbf{do}\ f( v )
\end{array}}
\]
- Precondition
- \( 0 \le u < \mathrm{bound}() \)
template<class W = int, class C = W, class Policy = NoObservers>
the cost of the cell \( u \) set to \( c \), the cell blocked if \( c \) is not positive and free otherwise, and CellChanged told with the cost before and \( c \); nothing if the cost is already \( c \)
In pseudocode (beyond the book), \( \gamma \) the vector of the costs, \( n \) the free cells, \( \gamma_{\mathrm{min}} \) their least cost and \( m \) the free cells of that cost:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{setCost}( u , c ) \cr
2 & \quad a \gets \gamma[ u ];\ \textbf{if}\ a = c\ \textbf{then}
\ \textbf{return} \cr
3 & \quad \gamma[ u ] \gets c \cr
4 & \quad \textbf{if}\ a > 0\ \textbf{then}\ n \gets n - 1;
\ \textbf{if}\ a = \gamma_{\mathrm{min}}\ \textbf{then}\ m
\gets m - 1 \cr
5 & \quad \textbf{if}\ c > 0\ \textbf{then}\ n \gets n + 1;
\ \textbf{if}\ n = 1\ \textbf{or}\ c < \gamma_{\mathrm{min}}
\ \textbf{then}\ ( \gamma_{\mathrm{min}} , m ) \gets ( c , 1 ) \cr
6 & \qquad \textbf{else if}\ c = \gamma_{\mathrm{min}}\ \textbf{then}
\ m \gets m + 1 \cr
7 & \quad \textbf{if}\ n > 0\ \textbf{and}\ m = 0\ \textbf{then}
\ \text{count again } \gamma_{\mathrm{min}} \text{ and } m
\text{ on the free cells} \cr
8 & \quad \mathit{directed} \gets n > 0\ \textbf{and}\ m \ne n \cr
9 & \quad \textbf{if}\ \text{someone wants the event}\ \textbf{then}
\ \text{tell } \mathrm{CellChanged}( u , a , c )
\end{array}}
\]
The test of line 9 is false at compile time with NoObservers, and the change is then the code of the grid alone.
- Precondition
- \( 0 \le u < \mathrm{bound}() \)