Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
main.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
24#include <cstdlib>
25#include <iostream>
26
27#include <tpl_ca_engine.H>
28#include <tpl_ca_lattice.H>
29#include <tpl_ca_neighborhood.H>
30#include <tpl_ca_rule.H>
31#include <tpl_ca_storage.H>
32
33using namespace Aleph::CA;
34
35namespace
36{
37
39
44std::size_t population(const Grid &frame)
45{
46 std::size_t count = 0;
47 for (ca_size_t r = 0; r < frame.size(0); ++r)
48 for (ca_size_t c = 0; c < frame.size(1); ++c)
49 if (frame.at({static_cast<ca_index_t>(r), static_cast<ca_index_t>(c)}) != 0)
50 ++count;
51 return count;
52}
53
54} // namespace
55
56int main()
57{
58 // Horizontal blinker on a 5x5 torus: three cells in the middle row.
59 Grid seed({5, 5}, 0);
60 seed.set({2, 1}, 1);
61 seed.set({2, 2}, 1);
62 seed.set({2, 3}, 1);
63
66
67 const std::size_t start = population(engine.frame());
68 engine.run(1); // blinker turns vertical, population stays 3.
69 const std::size_t after_one = population(engine.frame());
70 engine.run(1); // returns to the horizontal phase.
71 const std::size_t after_two = population(engine.frame());
72
73 std::cout << "Aleph-w consumer: Game of Life blinker\n"
74 << " population: " << start << " -> " << after_one
75 << " -> " << after_two << '\n';
76
77 const bool ok = start == 3 and after_one == 3 and after_two == 3
78 and engine.frame().at({2, 1}) == 1
79 and engine.frame().at({2, 3}) == 1;
80 if (not ok)
81 {
82 std::cerr << "consumer: blinker did not behave as a period-2 oscillator\n";
83 return EXIT_FAILURE;
84 }
85 std::cout << " find_package(Aleph) integration OK\n";
86 return EXIT_SUCCESS;
87}
Lattice that adds boundary-aware access on top of a storage.
state_type at(const coord_type &c) const
Strict access: throws if c is out of range.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Synchronous double-buffered engine.
const Lattice & frame() const noexcept
Return the current frame.
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
int main()
Definition main.cc:56
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Definition ca-traits.H:63
and
Check uniqueness with explicit hash + equality functors.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
The lattice wraps around on every axis.
Definition ca-traits.H:124
ValueArg< size_t > seed
Definition testHash.C:53
static mt19937 engine
gsl_rng * r
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).