Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ca_boundary_policies_example.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
43# include <iomanip>
44# include <iostream>
45# include <string>
46
47# include <ca-traits.H>
48# include <tpl_ca_storage.H>
49# include <tpl_ca_lattice.H>
50
51using namespace Aleph;
52using namespace Aleph::CA;
53
54namespace
55{
57 template <typename Boundary>
59 {
60 Lattice<Dense_Cell_Storage<int, 2>, Boundary> lat({ 3, 3 }, 0);
61 for (ca_index_t i = 0; i < 3; ++i)
62 for (ca_index_t j = 0; j < 3; ++j)
63 lat.set({ i, j }, static_cast<int>(i * 10 + j));
64 return lat;
65 }
66
70 template <typename Lat>
71 void render(const std::string & title, const Lat & lat)
72 {
73 std::cout << "\n=== " << title << " ===\n";
74 std::cout << " ";
75 for (ca_index_t j = -2; j <= 4; ++j)
76 std::cout << std::setw(4) << j;
77 std::cout << "\n";
78 for (ca_index_t i = -2; i <= 4; ++i)
79 {
80 std::cout << " i=" << std::setw(2) << i << " ";
81 for (ca_index_t j = -2; j <= 4; ++j)
82 {
83 const int v = lat.at_safe({ i, j });
84 const bool inside =
85 (i >= 0 and i < 3 and j >= 0 and j < 3);
86 std::cout << (inside ? '[' : ' ')
87 << std::setw(2) << v
88 << (inside ? ']' : ' ');
89 }
90 std::cout << "\n";
91 }
92 }
93}
94
95int main()
96{
97 std::cout << "Aleph::CA — boundary policies side-by-side\n";
98 std::cout << "==========================================\n";
99 std::cout << "Centre lattice: 3x3 with cell(i,j) = i*10 + j.\n";
100 std::cout << "Brackets [..] mark cells inside the lattice;\n";
101 std::cout << "everything else is resolved by `at_safe` through\n";
102 std::cout << "the boundary policy.\n";
103
104 render("OpenBoundary (out-of-range = 0)",
106
107 render("ToroidalBoundary (wrap on each axis)",
109
110 render("ReflectiveBoundary (mirror, no repeat)",
112
113 render("ConstantBoundary<int, 99>",
115
116 return 0;
117}
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
void set(const coord_type &c, const state_type &v)
Strict write: throws if c is out of range.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
Definition ca-traits.H:60
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
Constant-value boundary.
Definition ca-traits.H:138
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).