BioDynaMo  v1.05.120-25dc9790
algorithm_registry.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_MULTI_SIMULATION_ALGORITHM_ALGORITHM_REGISTRY_H_
16 #define CORE_MULTI_SIMULATION_ALGORITHM_ALGORITHM_REGISTRY_H_
17 
18 #include <unordered_map>
19 
22 #include "core/param/param.h"
23 
24 namespace bdm {
25 namespace experimental {
26 
27 class MultiSimulationManager;
28 
33 
40  Algorithm *GetAlgorithm(const std::string &algo_name);
41 
50  bool AddAlgorithm(const std::string &algo_name, Algorithm *algo);
51 
52  private:
54  std::unordered_map<std::string, Algorithm *> algorithms_;
55 
58 };
59 
60 #define BDM_REGISTER_ALGO(op) \
61  bool op::registered_ = \
62  AlgorithmRegistry::GetInstance()->AddAlgorithm(#op, new op());
63 
66 #define BDM_ALGO_HEADER() \
67  private: \
68  static bool registered_;
69 
70 // Get Optimization Algorithm from registry
72  // Check if the parameters are initialized correctly
73  for (auto param : opt_params->params) {
74  param->Validate();
75  }
76  auto ret =
78  return ret;
79 }
80 
81 } // namespace experimental
82 } // namespace bdm
83 
84 #endif // CORE_MULTI_SIMULATION_ALGORITHM_ALGORITHM_REGISTRY_H_
bdm::OptimizationParam::algorithm
std::string algorithm
Definition: optimization_param.h:38
bdm::experimental::AlgorithmRegistry::algorithms_
std::unordered_map< std::string, Algorithm * > algorithms_
The map containing the algorithms; accessible by their name.
Definition: algorithm_registry.h:54
bdm
Definition: agent.cc:39
bdm::experimental::Algorithm
An interface for creating new optimization algorithms.
Definition: algorithm.h:30
optimization_param.h
bdm::experimental::AlgorithmRegistry
Registry of all optimization algorithms.
Definition: algorithm_registry.h:30
bdm::experimental::AlgorithmRegistry::~AlgorithmRegistry
~AlgorithmRegistry()
Definition: algorithm_registry.cc:21
bdm::OptimizationParam
Definition: optimization_param.h:24
bdm::experimental::AlgorithmRegistry::AddAlgorithm
bool AddAlgorithm(const std::string &algo_name, Algorithm *algo)
Definition: algorithm_registry.cc:46
bdm::experimental::AlgorithmRegistry::GetAlgorithm
Algorithm * GetAlgorithm(const std::string &algo_name)
Definition: algorithm_registry.cc:32
bdm::OptimizationParam::params
std::vector< OptimizationParamType * > params
Definition: optimization_param.h:39
algorithm.h
param.h
bdm::experimental::AlgorithmRegistry::GetInstance
static AlgorithmRegistry * GetInstance()
Singleton class - returns the static instance.
Definition: algorithm_registry.cc:27
bdm::experimental::AlgorithmRegistry::AlgorithmRegistry
AlgorithmRegistry()
bdm::experimental::CreateOptimizationAlgorithm
Algorithm * CreateOptimizationAlgorithm(OptimizationParam *opt_params)
Definition: algorithm_registry.h:71