From e19c00a00838e6f8f315bd636ceafccfa7bef478 Mon Sep 17 00:00:00 2001 From: shubham1206agra Date: Mon, 9 May 2022 21:00:51 +0530 Subject: [PATCH] trying to initialize env_type var in same header --- .../environment/CMakeLists.txt | 1 - .../environment/env_type.cpp | 29 ------------------- .../environment/env_type.hpp | 13 +++++++++ 3 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 src/mlpack/methods/reinforcement_learning/environment/env_type.cpp diff --git a/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt b/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt index be5d1f3486..77d822aced 100644 --- a/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt +++ b/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt @@ -2,7 +2,6 @@ # Anything not in this list will not be compiled into mlpack. set(SOURCES env_type.hpp - env_type.cpp mountain_car.hpp cart_pole.hpp continuous_mountain_car.hpp diff --git a/src/mlpack/methods/reinforcement_learning/environment/env_type.cpp b/src/mlpack/methods/reinforcement_learning/environment/env_type.cpp deleted file mode 100644 index 98f0799199..0000000000 --- a/src/mlpack/methods/reinforcement_learning/environment/env_type.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @file methods/reinforcement_learning/environment/env_type.cpp - * @author Nishant Kumar - * - * This file defines the static variables used by the discrete and continuous - * environments. - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#include "env_type.hpp" - -namespace mlpack { -namespace rl { - -// Instantiate static members. - -size_t DiscreteActionEnv::State::dimension = 0; -size_t DiscreteActionEnv::Action::size = 0; -size_t DiscreteActionEnv::rewardSize = 0; - -size_t ContinuousActionEnv::State::dimension = 0; -size_t ContinuousActionEnv::Action::size = 0; -size_t ContinuousActionEnv::rewardSize = 0; - -} // namespace rl -} // namespace mlpack diff --git a/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp b/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp index 46a4c746bf..98bd8963b9 100644 --- a/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp +++ b/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp @@ -206,6 +206,19 @@ class ContinuousActionEnv static size_t rewardSize; }; +#ifndef MLPACK_METHODS_RL_ENVIRONMENT_ENV_TYPE_VARIABLES +#define MLPACK_METHODS_RL_ENVIRONMENT_ENV_TYPE_VARIABLES + +size_t DiscreteActionEnv::State::dimension = 0; +size_t DiscreteActionEnv::Action::size = 0; +size_t DiscreteActionEnv::rewardSize = 0; + +size_t ContinuousActionEnv::State::dimension = 0; +size_t ContinuousActionEnv::Action::size = 0; +size_t ContinuousActionEnv::rewardSize = 0; + +#endif + } // namespace rl } // namespace mlpack