119#ifndef __ADS_GridGraph
120 #define __ADS_GridGraph
137#include <type_traits>
177template<
class W =
int ,
class C = W ,
class Policy = NoObservers >
190 using Subject =
typename Policy::template bind< modifications >;
202 std::optional< W >
diagonal = std::nullopt ,
215 std::optional< W >
diagonal = std::nullopt ,
221 template<
class... O >
222 requires(
sizeof...( O ) > 0 )
228 [[nodiscard]]
int rows(
void )
const {
return( f_rows ); }
231 [[nodiscard]]
int cols(
void )
const {
return( f_cols ); }
243 [[nodiscard]] W
straight(
void )
const {
return( f_straight ); }
246 [[nodiscard]] W
diagonal(
void )
const {
return( f_diagonal ); }
249 [[nodiscard]]
bool directed(
void )
const {
return( f_directed ); }
252 [[nodiscard]]
int n(
void )
const {
return( f_n ); }
256 [[nodiscard]]
int bound(
void )
const {
return( f_rows * f_cols ); }
260 return( ( u >= 0 ) && ( u <
bound() ) && open( u ) );
265 [[nodiscard]]
int node(
int r ,
int c )
const;
273 [[nodiscard]] C
cost(
int u )
const;
277 [[nodiscard]] C
minCost(
void )
const {
return( f_min ); }
346 [[nodiscard]] std::vector< int >
V(
void )
const;
350 [[nodiscard]] std::vector< int >
adj(
int u )
const;
379 requires( Subject::dynamic )
381 return( f_sub.attach( o ) );
388 requires( Subject::dynamic )
406 [[nodiscard]]
auto nodes(
void )
const {
407 return( std::views::iota( 0 ,
bound() ) |
408 std::views::filter( [
this ](
int u ) {
return( open( u ) ); } ) );
414 void init( std::optional< W >
diagonal );
417 [[nodiscard]]
bool open(
int u )
const {
418 return( f_cost.empty() || ( f_cost[ u ] > C( 0 ) ) );
423 [[nodiscard]]
bool corner(
bool a ,
bool b )
const {
430 void scan(
int u , G && g )
const;
433 [[nodiscard]]
bool counted(
void )
const;
436 void recount(
void );
441 f_sub.audit( *
this );
451 std::vector< C > f_cost;
455 bool f_directed =
false;
489template<
class W ,
class C ,
class P >
491 const std::vector< int > & S );
498template<
class W =
int >
516template<
class W =
int >
542template<
class W ,
class C ,
class P >
564template<
class W =
double ,
class C =
unsigned char >
577#include "ADS/graph/impl/GridGraph.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The visits of a GRID, the implicit graph whose nodes are the cells of a matrix and whose edges are ...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
the implicit graph of a grid map, the cells of cost and the weights of the moves of type ,...
Definition GridGraph.h:179
const Subject & subject(void) const
the subject
Definition GridGraph.h:400
W straight(void) const
the cost of a move to a side on a map of unit costs
Definition GridGraph.h:243
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 free cells of cost 1, with no vector; the diagonal cost times the straight one if not g...
std::vector< int > V(void) const
the set of the nodes, in increasing order
void forEachMove(int u, F &&f) const
on each neighbor of , in increasing order, whether the move is to a corner, with no allocation: the...
GridMoves moves(void) const
the moves
Definition GridGraph.h:234
C minCost(void) const
the least cost of a free cell, 1 if there is no vector of the costs or no free cell
Definition GridGraph.h:277
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 cells of the given costs, that of the cell , a cell blocked if its cost is not positive...
MoveCost moveCost(void) const
the cell whose cost weighs a move
Definition GridGraph.h:240
C cost(int u) const
the cost of the cell , not positive if blocked
void forEachAdj(int u, F &&f) const
on each neighbor of , in increasing order, with no allocation
typename Policy::template bind< modifications > Subject
the subject
Definition GridGraph.h:190
int n(void) const
the number of nodes, the free cells
Definition GridGraph.h:252
void setCost(int u, const C &c)
the cost of the cell set to , the cell blocked if is not positive and free otherwise,...
C Cost
the type of the costs of the cells
Definition GridGraph.h:184
mod::Changed< mod::Value, int, C > CellChanged
the event of a change of the cost of a cell, the cell its handle
Definition GridGraph.h:186
void forEachAffected(int u, const C &from, const C &to, F &&f) const
, in increasing order of , on each cell whose moves in may have been created, removed or weighed dif...
void detach(int id)
detaches the observer number
Definition GridGraph.h:387
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....
bool hasNode(int u) const
whether is a free cell
Definition GridGraph.h:259
auto nodes(void) const
the nodes in increasing order, a view on the names that skips the blocked cells
Definition GridGraph.h:406
mod::list< CellChanged > modifications
the events
Definition GridGraph.h:188
int rows(void) const
the number of rows
Definition GridGraph.h:228
ADS::Batch< GridGraph > Batch
the channel of a batch, open while it lives [see batch()]
Definition GridGraph.h:192
int node(int r, int c) const
the node of the cell
bool directed(void) const
whether the graph is oriented, i.e., two free cells cost differently
Definition GridGraph.h:249
void forEachEdge(int u, F &&f) const
on each neighbor of , the cost of the move, in increasing order of
GridCell cell(int u) const
the cell of the name
int cols(void) const
the number of columns
Definition GridGraph.h:231
Corners corners(void) const
the rule on the corners
Definition GridGraph.h:237
int attach(D &o)
attaches the observer and gives its number
Definition GridGraph.h:378
Batch batch(void)
opens a batch: the events are collected until it is closed, and sent coalesced
Definition GridGraph.h:395
int bound(void) const
the names of the nodes are in
Definition GridGraph.h:256
std::vector< int > adj(int u) const
the neighbors of , in increasing order
W Weight
the type of the weights
Definition GridGraph.h:183
Subject & subject(void)
the subject, for ADS::batch() and ADS::quiet()
Definition GridGraph.h:398
W diagonal(void) const
the cost of a move to a corner on a map of unit costs
Definition GridGraph.h:246
The GRAPH of chapter 9 and its realizations.
#define ADS_COLD_PATH
a function of a rare path: never inlined, laid out away from the hot code
Definition Portable.h:107
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
GridMoves
the moves of a GridGraph
Definition GridGraph.h:152
W octile(GridCell a, GridCell b, W straight, W diagonal)
the octile distance between the cells and , with and the larger and the smaller of and ,...
MoveCost
which cell of a move of a GridGraph weighs it
Definition GridGraph.h:165
Corners
when a move to a corner of a cell is allowed, the corner free
Definition GridGraph.h:158
W manhattan(GridCell a, GridCell b, W straight=W(1))
the distance of Manhattan between the cells and , , the least cost of a path of moves to the sides o...
W gridHeuristic(const GridGraph< W, C, P > &g, int u, int t)
a lower bound on the cost of a path from to in , consistent, for the A* of Hart,...
GridGraph< W, C > readGridMap(std::istream &in, GridMoves moves=GridMoves::EIGHT, Corners corners=Corners::NO_CUT)
the grid of a map in the format of the benchmarks of Sturtevant: the lines type octile,...
W chebyshev(GridCell a, GridCell b, W straight=W(1))
the distance of Chebyshev between the cells and , , the octile distance when a move to a corner cost...
@ FOUR
to the four sides of a cell
Definition GridGraph.h:153
@ EIGHT
to the sides and to the four corners
Definition GridGraph.h:154
@ LEFT
the cell left: weighed by
Definition GridGraph.h:167
@ ENTERED
the cell entered: weighed by
Definition GridGraph.h:166
@ NO_CUT
if both sides are free
Definition GridGraph.h:161
@ NO_SQUEEZE
if at least one of the two sides is free
Definition GridGraph.h:160
@ CUT
always, even between two blocked sides
Definition GridGraph.h:159
std::vector< std::vector< int > > gridDistances(int rows, int cols, const std::vector< GridCell > &sources, Free &&free, const Moves &moves=FOUR_MOVES)
the distance in moves of each cell of the grid from the nearest source, INF if none reaches it,...
std::pair< int, int > GridCell
a cell of a grid, or a move as the difference of two cells
Definition Grid.h:114
the attribute A of the item of handle changed from from to to
Definition Modification.h:600