GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
Loading...
Searching...
No Matches
Topology.h
Go to the documentation of this file.
1#ifndef TOPOLOGY_H
2#define TOPOLOGY_H
3
4#pragma once
5
6#include <stdexcept>
7#include <vector>
8
9namespace galib {
10
11 namespace internal {
15 struct NodeLinks {
17 std::vector<std::size_t> neighbors_out;
19 std::vector<std::size_t> neighbors_in;
20 };
21 }
22
28 class Topology {
29 private:
30 std::size_t num_nodes_m;
31
32 protected:
34 [[nodiscard]] std::size_t getNumNodes() const { return num_nodes_m; }
35
36 public:
37 virtual ~Topology() = default;
38
44 explicit Topology(const std::size_t num_nodes) : num_nodes_m(num_nodes) {
45 if (num_nodes < 2) {
46 throw std::invalid_argument("Number of nodes must be greater than 1");
47 }
48 };
49
55 [[nodiscard]] virtual internal::NodeLinks getLinks(std::size_t node) const = 0;
56 };
57
58}
59
60#endif // TOPOLOGY_H
Abstract base class for archipelago topologies.
Definition Topology.h:28
virtual internal::NodeLinks getLinks(std::size_t node) const =0
Determines the neighbors for a specific island rank.
virtual ~Topology()=default
std::size_t getNumNodes() const
Returns the total number of nodes in the topology.
Definition Topology.h:34
Topology(const std::size_t num_nodes)
Constructs a topology for a specific number of nodes.
Definition Topology.h:44