BioDynaMo  v1.05.119-a4ff3934
particle_swarm_param.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_OPTIMIZATION_PARAM_TYPE_PARTICLE_SWARM_PARAM_H_
16 #define CORE_MULTI_SIMULATION_OPTIMIZATION_PARAM_TYPE_PARTICLE_SWARM_PARAM_H_
17 
18 #include <string>
19 
21 #include "core/util/log.h"
22 
23 namespace bdm {
24 
28  ParticleSwarmParam() = default;
29  ParticleSwarmParam(const std::string& name, real_t min, real_t max, real_t iv)
30  : OptimizationParamType(name),
31  lower_bound(min),
32  upper_bound(max),
33  initial_value(iv) {
34  Validate();
35  };
36 
37  void Validate() const override {
38  if (lower_bound > upper_bound) {
39  Log::Fatal(
40  "ParticleSwarmParam", "Tried to initialize parameter '", param_name,
41  "' with a lower_bound value higher than upper_bound: ", lower_bound,
42  " > ", upper_bound);
43  }
44  }
45 
46  OptimizationParamType* GetCopy() const override {
47  return new ParticleSwarmParam(*this);
48  }
49 
50  real_t GetValue(int n) const override {
51  Log::Fatal("ParticleSwarmParam::GetValue",
52  "Invalid operation! Values are obtained through the "
53  "optimization library.");
54  return 0.0;
55  }
56 
57  uint32_t GetNumElements() const override {
58  Log::Fatal("ParticleSwarmParam::GetValue", "Invalid operation!");
59  return 0.0;
60  }
61 
62  // The minimum value
64  // THe maximum value
66  // The stride
69 };
70 
71 } // namespace bdm
72 
73 #endif // CORE_MULTI_SIMULATION_OPTIMIZATION_PARAM_TYPE_PARTICLE_SWARM_PARAM_H_
optimization_param_type.h
bdm::ParticleSwarmParam::GetNumElements
uint32_t GetNumElements() const override
Definition: particle_swarm_param.h:57
bdm
Definition: agent.cc:39
bdm::ParticleSwarmParam::GetCopy
OptimizationParamType * GetCopy() const override
Definition: particle_swarm_param.h:46
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::OptimizationParamType
An interface for creating different types of optimization parameters.
Definition: optimization_param_type.h:27
bdm::OptimizationParamType::param_name
std::string param_name
Definition: optimization_param_type.h:52
bdm::ParticleSwarmParam::Validate
void Validate() const override
Definition: particle_swarm_param.h:37
bdm::ParticleSwarmParam::BDM_CLASS_DEF_OVERRIDE
BDM_CLASS_DEF_OVERRIDE(ParticleSwarmParam, 1)
bdm::ParticleSwarmParam::ParticleSwarmParam
ParticleSwarmParam()=default
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
log.h
bdm::ParticleSwarmParam::ParticleSwarmParam
ParticleSwarmParam(const std::string &name, real_t min, real_t max, real_t iv)
Definition: particle_swarm_param.h:29
bdm::ParticleSwarmParam::GetValue
real_t GetValue(int n) const override
Definition: particle_swarm_param.h:50
bdm::ParticleSwarmParam::upper_bound
real_t upper_bound
Definition: particle_swarm_param.h:65
bdm::ParticleSwarmParam::lower_bound
real_t lower_bound
Definition: particle_swarm_param.h:63
bdm::ParticleSwarmParam
Definition: particle_swarm_param.h:27
bdm::ParticleSwarmParam::initial_value
real_t initial_value
Definition: particle_swarm_param.h:67