From 662f708fc1c1ede9f4ad18d7428334ba34da6d94 Mon Sep 17 00:00:00 2001 From: alejandrom247 Date: Thu, 4 Jun 2020 17:13:26 -0400 Subject: [PATCH 1/5] Add parallel imp of bench and fixes dependencies issues --- src/copt/solutions/bench/ackley.cpp | 62 +++++++++++++ src/copt/solutions/bench/ackley.h | 93 ++++++++++++++++++++ src/copt/solutions/bench/alpine.cpp | 56 ++++++++++++ src/copt/solutions/bench/alpine.h | 92 +++++++++++++++++++ src/copt/solutions/bench/brown_function.cpp | 61 +++++++++++++ src/copt/solutions/bench/brown_function.h | 89 +++++++++++++++++++ src/copt/solutions/bench/chung_reynolds.cpp | 57 ++++++++++++ src/copt/solutions/bench/chung_reynolds.h | 89 +++++++++++++++++++ src/copt/solutions/bench/cosine_mixture.cpp | 65 ++++++++++++++ src/copt/solutions/bench/cosine_mixture.h | 89 +++++++++++++++++++ src/copt/solutions/bench/csendes.cpp | 57 ++++++++++++ src/copt/solutions/bench/csendes.h | 89 +++++++++++++++++++ src/copt/solutions/bench/de_jung.cpp | 52 +++++++++++ src/copt/solutions/bench/de_jung.h | 72 +++++++++++++++ src/copt/solutions/bench/deb1.cpp | 63 +++++++++++++ src/copt/solutions/bench/deb1.h | 88 ++++++++++++++++++ src/copt/solutions/bench/deb3.cpp | 64 ++++++++++++++ src/copt/solutions/bench/deb3.h | 88 ++++++++++++++++++ src/copt/solutions/bench/dixonp.cpp | 61 +++++++++++++ src/copt/solutions/bench/dixonp.h | 88 ++++++++++++++++++ src/copt/solutions/bench/eggh.cpp | 62 +++++++++++++ src/copt/solutions/bench/eggh.h | 88 ++++++++++++++++++ src/copt/solutions/bench/expo.cpp | 57 ++++++++++++ src/copt/solutions/bench/expo.h | 88 ++++++++++++++++++ src/copt/solutions/bench/giunta.cpp | 63 +++++++++++++ src/copt/solutions/bench/giunta.h | 88 ++++++++++++++++++ src/copt/solutions/bench/griewangk.cpp | 61 +++++++++++++ src/copt/solutions/bench/griewangk.h | 90 +++++++++++++++++++ src/copt/solutions/bench/rastrigin.cpp | 56 ++++++++++++ src/copt/solutions/bench/rastrigin.h | 89 +++++++++++++++++++ src/copt/solutions/bench/rosenbrock.cpp | 56 ++++++++++++ src/copt/solutions/bench/rosenbrock.h | 91 +++++++++++++++++++ src/copt/solutions/bench/schwefel.cpp | 57 ++++++++++++ src/copt/solutions/bench/schwefel.h | 89 +++++++++++++++++++ src/copt/solutions/bench/step.cpp | 56 ++++++++++++ src/copt/solutions/bench/step.h | 92 +++++++++++++++++++ src/copt/solutions/bench/styblinski_tang.cpp | 56 ++++++++++++ src/copt/solutions/bench/styblinski_tang.h | 90 +++++++++++++++++++ 38 files changed, 2804 insertions(+) create mode 100644 src/copt/solutions/bench/ackley.cpp create mode 100644 src/copt/solutions/bench/ackley.h create mode 100644 src/copt/solutions/bench/alpine.cpp create mode 100644 src/copt/solutions/bench/alpine.h create mode 100755 src/copt/solutions/bench/brown_function.cpp create mode 100755 src/copt/solutions/bench/brown_function.h create mode 100755 src/copt/solutions/bench/chung_reynolds.cpp create mode 100755 src/copt/solutions/bench/chung_reynolds.h create mode 100755 src/copt/solutions/bench/cosine_mixture.cpp create mode 100755 src/copt/solutions/bench/cosine_mixture.h create mode 100755 src/copt/solutions/bench/csendes.cpp create mode 100755 src/copt/solutions/bench/csendes.h create mode 100644 src/copt/solutions/bench/de_jung.cpp create mode 100644 src/copt/solutions/bench/de_jung.h create mode 100755 src/copt/solutions/bench/deb1.cpp create mode 100755 src/copt/solutions/bench/deb1.h create mode 100644 src/copt/solutions/bench/deb3.cpp create mode 100644 src/copt/solutions/bench/deb3.h create mode 100644 src/copt/solutions/bench/dixonp.cpp create mode 100644 src/copt/solutions/bench/dixonp.h create mode 100755 src/copt/solutions/bench/eggh.cpp create mode 100755 src/copt/solutions/bench/eggh.h create mode 100755 src/copt/solutions/bench/expo.cpp create mode 100755 src/copt/solutions/bench/expo.h create mode 100755 src/copt/solutions/bench/giunta.cpp create mode 100755 src/copt/solutions/bench/giunta.h create mode 100644 src/copt/solutions/bench/griewangk.cpp create mode 100644 src/copt/solutions/bench/griewangk.h create mode 100644 src/copt/solutions/bench/rastrigin.cpp create mode 100644 src/copt/solutions/bench/rastrigin.h create mode 100644 src/copt/solutions/bench/rosenbrock.cpp create mode 100644 src/copt/solutions/bench/rosenbrock.h create mode 100644 src/copt/solutions/bench/schwefel.cpp create mode 100644 src/copt/solutions/bench/schwefel.h create mode 100644 src/copt/solutions/bench/step.cpp create mode 100644 src/copt/solutions/bench/step.h create mode 100644 src/copt/solutions/bench/styblinski_tang.cpp create mode 100644 src/copt/solutions/bench/styblinski_tang.h diff --git a/src/copt/solutions/bench/ackley.cpp b/src/copt/solutions/bench/ackley.cpp new file mode 100644 index 0000000..31ee231 --- /dev/null +++ b/src/copt/solutions/bench/ackley.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +ackley* ackley::make(generator* generator, unsigned int size) +{ + auto* result = new ackley(generator, size); + + result->init(); + + return result; +} + +float ackley::calculate_fitness() +{ + int n = size(); + float summatory_1 = 0; + float summatory_2 = 0; + float result = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n; i++) + { + summatory_1 += pow(params[i], 2); + summatory_2 += cos(2 * 3.141592653f * params[i]); + } + + result = -20 * exp(-0.2 * sqrt(summatory_1 / n)) ; + result += -exp(summatory_2 / n) + 20 + 2.718281828f; + + return result; +} + +ackley::ackley(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::ackley(generator, size) +{ + +} + +ackley::~ackley() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/ackley.h b/src/copt/solutions/bench/ackley.h new file mode 100644 index 0000000..6cde830 --- /dev/null +++ b/src/copt/solutions/bench/ackley.h @@ -0,0 +1,93 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_ACKLEY +#define DNN_OPT_COPT_SOLUTIONS_BENCH_ACKLEY + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::ackley + * + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class ackley : public virtual solution, + public virtual core::solutions::bench::ackley +{ +public: + + /** + * @brief Returns an instance of the ackley class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return an instance of ackley class. + */ + static ackley* make(generator* generator, unsigned int size = 10); + + virtual ~ackley(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for this class. + * + * @param generator an instance of a generator class. + * The generator is used to initialize the parameters of this + * solution. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + ackley(generator* generator, unsigned int size = 10 ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/alpine.cpp b/src/copt/solutions/bench/alpine.cpp new file mode 100644 index 0000000..a2c2115 --- /dev/null +++ b/src/copt/solutions/bench/alpine.cpp @@ -0,0 +1,56 @@ +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + + +alpine* alpine::make(generator* generator, unsigned int size) +{ + auto* result = new alpine(generator, size); + + result->init(); + + return result; +} + +float alpine::calculate_fitness() +{ + int n = size(); + float result = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n; i++) + { + result += std::fabs(params[i] * sin(params[i]) + 0.1 * params[i]); + } + + return std::fabs(result); +} + +alpine::alpine(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::alpine(generator, size) +{ + +} + +alpine::~alpine() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/alpine.h b/src/copt/solutions/bench/alpine.h new file mode 100644 index 0000000..91ae65a --- /dev/null +++ b/src/copt/solutions/bench/alpine.h @@ -0,0 +1,92 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_ALPINE +#define DNN_OPT_COPT_SOLUTIONS_ALPINE + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::alpine + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class alpine : public virtual solution, + public virtual core::solutions::bench::alpine +{ +public: + + /** + * @brief Returns an instance of the alpine class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return an instance of alpine class. + */ + static alpine* make(generator* generator, unsigned int size = 10); + + virtual ~alpine(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for this class. + * + * @param generator an instance of a generator class. + * The generator is used to initialize the parameters of this + * solution. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + alpine(generator* generator, unsigned int size = 10 ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/brown_function.cpp b/src/copt/solutions/bench/brown_function.cpp new file mode 100755 index 0000000..35aea73 --- /dev/null +++ b/src/copt/solutions/bench/brown_function.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +brown* brown::make(generator *generator, unsigned int size) +{ + auto* result = new brown(generator, size); + + result->init(); + + return result; +} + +float brown::calculate_fitness() +{ + float result = 0; + float* params = get_params(); + float result1; + float result2; + + solution::calculate_fitness(); + + int length = size(); + #pragma omp parallel for shared(length, params) reduction(+:result) + for(int i = 0; i < length - 1; i+=2) + { + result1 = pow(params[i], 2.0f * pow(params[i + 1], 2.0f) + 2.0f); + result2 = pow(params[i + 1], 2.0f * pow(params[i], 2.0f) + 2.0f); + result = result1 + result2; + } + + + return result; +} + +brown::brown(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::brown(generator, size) +{ + +} + +brown::~brown() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/brown_function.h b/src/copt/solutions/bench/brown_function.h new file mode 100755 index 0000000..2147445 --- /dev/null +++ b/src/copt/solutions/bench/brown_function.h @@ -0,0 +1,89 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_BROWN +#define DNN_OPT_COPT_SOLUTIONS_BENCH_BROWN + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::brown + * + * + * @author Alejandro Ruiz Madruga + * @version 1.0 + * @date March, 2020 + */ +class brown : public virtual solution, + public virtual core::solutions::bench::brown +{ +public: + + /** + * @brief Returns an instance of the brown class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 5. + * + * @return an instance of brown class. + */ + static brown* make(generator* generator, unsigned int size = 5); + + virtual ~brown(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 5. + */ + brown(generator* generator, unsigned int size = 5); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/chung_reynolds.cpp b/src/copt/solutions/bench/chung_reynolds.cpp new file mode 100755 index 0000000..0683c17 --- /dev/null +++ b/src/copt/solutions/bench/chung_reynolds.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +chung_r* chung_r::make(generator *generator, unsigned int size) +{ + auto* result = new chung_r(generator, size); + + result->init(); + + return result; +} + +float chung_r::calculate_fitness() +{ + float result = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = size(); + + #pragma omp parallel for shared(length, params) reduction(+:result) + for(int i = 0; i < length; i++) + { + result = pow(params[i], 2.0f); + } + + return pow(result, 2.0f); +} + +chung_r::chung_r(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::chung_r(generator, size) +{ + +} + +chung_r::~chung_r() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/chung_reynolds.h b/src/copt/solutions/bench/chung_reynolds.h new file mode 100755 index 0000000..08a4378 --- /dev/null +++ b/src/copt/solutions/bench/chung_reynolds.h @@ -0,0 +1,89 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_CHUNG_R +#define DNN_OPT_COPT_SOLUTIONS_BENCH_CHUNG_R + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::chung_r + * + * + * @author Alejandro Ruiz Madruga + * @version 1.0 + * @date March, 2020 + */ +class chung_r : public virtual solution, + public virtual core::solutions::bench::chung_r +{ +public: + + /** + * @brief Returns an instance of the chung_r class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 200. + * + * @return an instance of chung_r class. + */ + static chung_r* make(generator* generator, unsigned int size = 200); + + virtual ~chung_r(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 200. + */ + chung_r(generator* generator, unsigned int size = 200); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/cosine_mixture.cpp b/src/copt/solutions/bench/cosine_mixture.cpp new file mode 100755 index 0000000..e9fa86f --- /dev/null +++ b/src/copt/solutions/bench/cosine_mixture.cpp @@ -0,0 +1,65 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +cosine_m* cosine_m::make(generator *generator, unsigned int size) +{ + auto* result = new cosine_m(generator, size); + + result->init(); + + return result; +} + +float cosine_m::calculate_fitness() +{ + float result1 = 0; + float result2 = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = size(); + #pragma omp parallel for shared(length, params) reduction(+:result1) + for(int i = 0; i < length; i++) + { + result1 = cos(5.0f * 3.14f * params[i]); + } + + result1 *= -(0.1f); + + #pragma omp parallel for shared(length, params) reduction(+:result2) + for(int j = 0; j < length; j++) + { + result2 = pow(params[j], 2.0f); + } + + return result1 - result2; +} + +cosine_m::cosine_m(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::cosine_m(generator, size) +{ + +} + +cosine_m::~cosine_m() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/cosine_mixture.h b/src/copt/solutions/bench/cosine_mixture.h new file mode 100755 index 0000000..550fd55 --- /dev/null +++ b/src/copt/solutions/bench/cosine_mixture.h @@ -0,0 +1,89 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_COSINE_M +#define DNN_OPT_COPT_SOLUTIONS_BENCH_COSINE_M + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::cosine_m + * + * + * @author Alejandro Ruiz Madruga + * @version 1.0 + * @date March, 2020 + */ +class cosine_m : public virtual solution, + public virtual core::solutions::bench::cosine_m +{ +public: + + /** + * @brief Returns an instance of the cosine_m class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 2. + * + * @return an instance of cosine_m class. + */ + static cosine_m* make(generator* generator, unsigned int size = 2); + + virtual ~cosine_m(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 2. + */ + cosine_m(generator* generator, unsigned int size = 2); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/csendes.cpp b/src/copt/solutions/bench/csendes.cpp new file mode 100755 index 0000000..912e993 --- /dev/null +++ b/src/copt/solutions/bench/csendes.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +csendes* csendes::make(generator *generator, unsigned int size) +{ + auto* result = new csendes(generator, size); + + result->init(); + + return result; +} + +float csendes::calculate_fitness() +{ + float result = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = size(); + + #pragma omp parallel for shared(length,params) reduction(+:result) + for(int i = 0; i < length; i++) + { + result = pow(params[i], 6.0f) * (2.0f + sin(1.0f / params[i])); + } + + return result; +} + +csendes::csendes(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::csendes(generator, size) +{ + +} + +csendes::~csendes() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace core +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/csendes.h b/src/copt/solutions/bench/csendes.h new file mode 100755 index 0000000..9a59d0f --- /dev/null +++ b/src/copt/solutions/bench/csendes.h @@ -0,0 +1,89 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_CSENDES +#define DNN_OPT_COPT_SOLUTIONS_BENCH_CSENDES + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::csendes + * + * + * @author Alejandro Ruiz Madruga + * @version 1.0 + * @date March, 2020 + */ +class csendes : public virtual solution, + public virtual core::solutions::bench::csendes +{ +public: + + /** + * @brief Returns an instance of the csendes class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 2. + * + * @return an instance of csendes class. + */ + static csendes* make(generator* generator, unsigned int size = 2); + + virtual ~csendes(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 2. + */ + csendes(generator* generator, unsigned int size = 2); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/de_jung.cpp b/src/copt/solutions/bench/de_jung.cpp new file mode 100644 index 0000000..5efcc0a --- /dev/null +++ b/src/copt/solutions/bench/de_jung.cpp @@ -0,0 +1,52 @@ +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +de_jung* de_jung::make(generator *generator, unsigned int size) +{ + auto* result = new de_jung(generator, size); + + result->init(); + + return result; +} + +float de_jung::calculate_fitness() +{ + float result; + + #pragma omp parallel + { + result = cblas_sdot(size(), get_params(), 1, get_params(), 1); + } + + solution::calculate_fitness(); + + return result; +} + +de_jung::de_jung(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::de_jung(generator, size) +{ + +} + +de_jung::~de_jung() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/de_jung.h b/src/copt/solutions/bench/de_jung.h new file mode 100644 index 0000000..d709ed1 --- /dev/null +++ b/src/copt/solutions/bench/de_jung.h @@ -0,0 +1,72 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_DE_JUNG +#define DNN_OPT_COPT_SOLUTIONS_DE_JUNG + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench { + +/** + * @copydoc core::solutions::bench::de_jung + * + * @author Jairo Rojas-Delgado + * @date December, 2017 + * @version 1.0 + */ +class de_jung : public virtual solution, + public virtual core::solutions::bench::de_jung +{ +public: + + static de_jung* make(generator* generator, unsigned int size = 10); + + virtual ~de_jung(); + +protected: + + virtual float calculate_fitness() override; + + de_jung(generator* generator, unsigned int size = 10); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/deb1.cpp b/src/copt/solutions/bench/deb1.cpp new file mode 100755 index 0000000..a4fcc0d --- /dev/null +++ b/src/copt/solutions/bench/deb1.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +deb1* deb1::make(generator *generator, unsigned int size) +{ + auto* result = new deb1(generator, size); + + result->init(); + + return result; +} + +float deb1::calculate_fitness() +{ + float result = 0; + float pos = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = size(); + + #pragma omp parallel for shared(length,params) reduction(+:pos) + for(int i = 0; i < length; i++) + { + pos = sin(5.0f * 3.14f * params[i]); + } + + #pragma omp master + { + pos = pow(pos, 6.0f); + result = -(1.0f / length) * pos; + } + return result; +} + +deb1::deb1(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::deb1(generator, size) +{ + +} + +deb1::~deb1() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/deb1.h b/src/copt/solutions/bench/deb1.h new file mode 100755 index 0000000..d15f5ad --- /dev/null +++ b/src/copt/solutions/bench/deb1.h @@ -0,0 +1,88 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_DEB1 +#define DNN_OPT_COPT_SOLUTIONS_BENCH_DEB1 + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::deb1 + * + * @author Alejandro Ruiz Madruga + * @date March, 2020 + * @version 1.0 + */ +class deb1 : public virtual solution, + public virtual core::solutions::bench::deb1 +{ +public: + + /** + * @brief Returns an instance of the deb1 class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 2. + * + * @return an instance of deb1 class. + */ + static deb1* make(generator* generator, unsigned int size = 2); + + virtual ~deb1(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 2. + */ + deb1(generator* generator, unsigned int size = 2); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/deb3.cpp b/src/copt/solutions/bench/deb3.cpp new file mode 100644 index 0000000..20eeeaa --- /dev/null +++ b/src/copt/solutions/bench/deb3.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +deb3* deb3::make(generator *generator, unsigned int size) +{ + auto* result = new deb3(generator, size); + + result->init(); + + return result; +} + +float deb3::calculate_fitness() +{ + float result = 0; + float pos = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = size(); + + #pragma omp parallel for shared(length, params) reduction(+:pos) + for(int i = 0; i < length; i++) + { + pos = sin(5.0f * 3.14f * (pow(params[i], 0.75f) - 0.05f)); + } + + #pragma omp master + { + pos = pow(pos, 6.0f); + result = -(1.0f / length) * pos; + } + + return result; +} + +deb3::deb3(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::deb3(generator, size) +{ + +} + +deb3::~deb3() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/deb3.h b/src/copt/solutions/bench/deb3.h new file mode 100644 index 0000000..9275b14 --- /dev/null +++ b/src/copt/solutions/bench/deb3.h @@ -0,0 +1,88 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_DEB3 +#define DNN_OPT_COPT_SOLUTIONS_BENCH_DEB3 + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::deb3 + * + * @author Alejandro Ruiz Madruga + * @date March, 2020 + * @version 1.0 + */ +class deb3 : public virtual solution, + public virtual core::solutions::bench::deb3 +{ +public: + + /** + * @brief Returns an instance of the deb1 class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 2. + * + * @return an instance of deb3 class. + */ + static deb3* make(generator* generator, unsigned int size = 2); + + virtual ~deb3(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 2. + */ + deb3(generator* generator, unsigned int size = 2); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/dixonp.cpp b/src/copt/solutions/bench/dixonp.cpp new file mode 100644 index 0000000..f008f8b --- /dev/null +++ b/src/copt/solutions/bench/dixonp.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +dixonp* dixonp::make(generator *generator, unsigned int size) +{ + auto* result = new dixonp(generator, size); + + result->init(); + + return result; +} + +float dixonp::calculate_fitness() +{ + float result = 0; + float* params = get_params(); + float sum = 0; + + solution::calculate_fitness(); + + int length = size(); + float binom = pow(params[0] + 1.0f, 2.0f); + + #pragma omp parallel for shared(length, params) reduction(+:sum) + for(int i = 1; i < length; i++) + { + sum = i * pow(2 * pow(params[i], 2.0f) - params[i - 1], 2.0f); + } + + result = binom + sum; + + return result; +} + +dixonp::dixonp(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::dixonp(generator, size) +{ + +} + +dixonp::~dixonp() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/dixonp.h b/src/copt/solutions/bench/dixonp.h new file mode 100644 index 0000000..3dbe602 --- /dev/null +++ b/src/copt/solutions/bench/dixonp.h @@ -0,0 +1,88 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_DIXONP +#define DNN_OPT_COPT_SOLUTIONS_BENCH_DIXONP + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::dixonp + * + * @author Alejandro Ruiz Madruga + * @date March, 2020 + * @version 1.0 + */ +class dixonp : public virtual solution, + public virtual core::solutions::bench::dixonp +{ +public: + + /** + * @brief Returns an instance of the dixonp class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 20. + * + * @return an instance of dixonp class. + */ + static dixonp* make(generator* generator, unsigned int size = 20); + + virtual ~dixonp(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 20. + */ + dixonp(generator* generator, unsigned int size = 20); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/eggh.cpp b/src/copt/solutions/bench/eggh.cpp new file mode 100755 index 0000000..64846d6 --- /dev/null +++ b/src/copt/solutions/bench/eggh.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +eggh* eggh::make(generator *generator, unsigned int size) +{ + auto* result = new eggh(generator, size); + + result->init(); + + return result; +} + +float eggh::calculate_fitness() +{ + float br1 = 0; + float br2 = 0; + float* params = get_params(); + float result = 0; + + solution::calculate_fitness(); + + int length = size(); + + #pragma omp parallel for shared(length, params) reduction(+:result) + for(int i = 0; i < length - 1; i+=2) + { + br1 = -(params[i + 1] + 47.0f) * sin(sqrt(abs(params[i + 1] + params[i] + / 2.0f + 47.0f))); + br2 = params[i] * sin(sqrt(abs(params[i] - (params[i + 1] + 47.0f)))); + result = br1 - br2; + } + + return result; +} + +eggh::eggh(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::eggh(generator, size) +{ + +} + +eggh::~eggh() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/eggh.h b/src/copt/solutions/bench/eggh.h new file mode 100755 index 0000000..e3d7ad9 --- /dev/null +++ b/src/copt/solutions/bench/eggh.h @@ -0,0 +1,88 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_EGG_H +#define DNN_OPT_COPT_SOLUTIONS_BENCH_EGG_H + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::eggh + * + * @author Alejandro Ruiz Madruga + * @date March, 2020 + * @version 1.0 + */ +class eggh : public virtual solution, + public virtual core::solutions::bench::eggh +{ +public: + + /** + * @brief Returns an instance of the eggh class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 1024. + * + * @return an instance of eggh class. + */ + static eggh* make(generator* generator, unsigned int size = 1024); + + virtual ~eggh(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 1024. + */ + eggh(generator* generator, unsigned int size = 1024); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/expo.cpp b/src/copt/solutions/bench/expo.cpp new file mode 100755 index 0000000..755e433 --- /dev/null +++ b/src/copt/solutions/bench/expo.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +expo* expo::make(generator *generator, unsigned int size) +{ + auto* result = new expo(generator, size); + + result->init(); + + return result; +} + +float expo::calculate_fitness() +{ + float result = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = size(); + + #pragma omp parallel for shared(length, params) reduction(+:result) + for(int i = 0; i < length; i++) + { + result = pow(params[i], 2.0f); + } + + return -exp(-0.5f * result); +} + +expo::expo(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::expo(generator, size) +{ + +} + +expo::~expo() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/expo.h b/src/copt/solutions/bench/expo.h new file mode 100755 index 0000000..e1a0d3f --- /dev/null +++ b/src/copt/solutions/bench/expo.h @@ -0,0 +1,88 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_EXPO +#define DNN_OPT_COPT_SOLUTIONS_BENCH_EXPO + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::expo + * + * @author Alejandro Ruiz Madruga + * @date March, 2020 + * @version 1.0 + */ +class expo : public virtual solution, + public virtual core::solutions::bench::expo +{ +public: + + /** + * @brief Returns an instance of the expo class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 2. + * + * @return an instance of expo class. + */ + static expo* make(generator* generator, unsigned int size = 2); + + virtual ~expo(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 2. + */ + expo(generator* generator, unsigned int size = 2); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/giunta.cpp b/src/copt/solutions/bench/giunta.cpp new file mode 100755 index 0000000..07e47f4 --- /dev/null +++ b/src/copt/solutions/bench/giunta.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +giunta* giunta::make(generator *generator, unsigned int size) +{ + auto* result = new giunta(generator, size); + + result->init(); + + return result; +} + +float giunta::calculate_fitness() +{ + float result = 0; + float term1 = 0; + float term2 = 0; + float term3 = 0; + float* params = get_params(); + + solution::calculate_fitness(); + + int length = 2; + + #pragma omp parallel for shared(length, params) reduction(+:result) + for(int i = 0; i < length; i++) + { + term1 = sin((16.0f / 15.0f) * params[i] - 1.0f); + term2 = pow(sin((16.0f / 15.0f) * params[i] - 1.0f), 2.0f); + term3 = 1.0f / 50.0f * sin(4.0f * ((16.0f / 15.0f) * params[i] - 1.0f)); + result = term1 + term2 + term3; + } + + return 0.6f + result; +} + +giunta::giunta(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::giunta(generator, size) +{ + +} + +giunta::~giunta() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace core +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/giunta.h b/src/copt/solutions/bench/giunta.h new file mode 100755 index 0000000..71e1c5b --- /dev/null +++ b/src/copt/solutions/bench/giunta.h @@ -0,0 +1,88 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_GIUNTA +#define DNN_OPT_COPT_SOLUTIONS_BENCH_GIUNTA + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::bench::giunta + * + * @author Alejandro Ruiz Madruga + * @date March, 2020 + * @version 1.0 + */ +class giunta : public virtual solution, + public virtual core::solutions::bench::giunta +{ +public: + + /** + * @brief Returns an instance of the giunta class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 1024. + * + * @return an instance of giunta class. + */ + static giunta* make(generator* generator, unsigned int size = 2); + + virtual ~giunta(); + +protected: + + virtual float calculate_fitness(); + + /** + * @brief This is the basic contructor for this class. + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 2. + */ + giunta(generator* generator, unsigned int size = 2); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/griewangk.cpp b/src/copt/solutions/bench/griewangk.cpp new file mode 100644 index 0000000..d7b7cab --- /dev/null +++ b/src/copt/solutions/bench/griewangk.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +griewangk* griewangk::make(generator* generator, unsigned int size) +{ + auto* result = new griewangk(generator, size); + + result->init(); + + return result; +} + +float griewangk::calculate_fitness() +{ + int n = size(); + float* params = get_params(); + float summatory = 0; + float multiplier = 1; + float result = 0; + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n; i++) + { + summatory += pow(params[i], 2.0) / 4000; + multiplier *= cos(params[i] / sqrt(i + 1)); + } + + result = summatory - multiplier + 1; + + return result; +} + +griewangk::griewangk(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::griewangk(generator, size) +{ + +} + +griewangk::~griewangk() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/griewangk.h b/src/copt/solutions/bench/griewangk.h new file mode 100644 index 0000000..b6b185e --- /dev/null +++ b/src/copt/solutions/bench/griewangk.h @@ -0,0 +1,90 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_GRIEWANGK +#define DNN_OPT_COPT_SOLUTIONS_GRIEWANGK + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::griewangk + * + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class griewangk : public virtual solution, + public virtual core::solutions::bench::griewangk +{ +public: + + /** + * @brief Returns an instance of the griewangk class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return a pointer to an instance of the griewangk class. + */ + static griewangk* make(generator* generator, unsigned int size = 10); + + virtual ~griewangk(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief Thhe basic contructor for this class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + griewangk(generator* generator, unsigned int size = 10); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/rastrigin.cpp b/src/copt/solutions/bench/rastrigin.cpp new file mode 100644 index 0000000..63f93e0 --- /dev/null +++ b/src/copt/solutions/bench/rastrigin.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +rastrigin* rastrigin::make(generator* generator, unsigned int size) +{ + auto* result = new rastrigin(generator, size); + + result->init(); + + return result; +} + +float rastrigin::calculate_fitness() +{ + int n = size(); + float* params = get_params(); + float result = 10 * size(); + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n; i++) + { + result += pow(params[i], 2) - 10 * cos(2 * 3.141592653f * params[i]); + } + + return result; +} + +rastrigin::rastrigin(generator* generator, unsigned int size ) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::rastrigin(generator, size) +{ + +} + +rastrigin::~rastrigin() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/rastrigin.h b/src/copt/solutions/bench/rastrigin.h new file mode 100644 index 0000000..a67effe --- /dev/null +++ b/src/copt/solutions/bench/rastrigin.h @@ -0,0 +1,89 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_RASTRIGIN +#define DNN_OPT_COPT_SOLUTIONS_RASTRIGIN + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::rastrigin + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class rastrigin : public virtual solution, + public virtual core::solutions::bench::rastrigin +{ +public: + + /** + * @brief Returns an instance of the rastrigin class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return a pointer to an instance of the rastrigin class. + */ + static rastrigin* make(generator* generator, unsigned int size = 10); + + virtual ~rastrigin(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for the ratrigin class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + rastrigin(generator* generator, unsigned int size ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/rosenbrock.cpp b/src/copt/solutions/bench/rosenbrock.cpp new file mode 100644 index 0000000..d9ab5d5 --- /dev/null +++ b/src/copt/solutions/bench/rosenbrock.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +rosenbrock* rosenbrock::make(generator* generator, unsigned int size) +{ + auto* result = new rosenbrock(generator, size); + + result->init(); + + return result; +} + +float rosenbrock::calculate_fitness() +{ + int n = size(); + float* params = get_params(); + float result = 0; + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n - 1; i++) + { + result += 100 * pow(params[i + 1] - pow(params[i], 2), 2) + pow(params[i] - 1, 2); + } + + return result; +} + +rosenbrock::rosenbrock(generator* generator, unsigned int size ) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::rosenbrock(generator, size) +{ + +} + +rosenbrock::~rosenbrock() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/rosenbrock.h b/src/copt/solutions/bench/rosenbrock.h new file mode 100644 index 0000000..3f0ba7f --- /dev/null +++ b/src/copt/solutions/bench/rosenbrock.h @@ -0,0 +1,91 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_ROSENBROCK +#define DNN_OPT_COPT_SOLUTIONS_ROSENBROCK + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::rosenbrock + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class rosenbrock : public virtual solution, + public virtual core::solutions::bench::rosenbrock +{ +public: + + /** + * @brief Returns an instance of the rosenbrock class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return an instance of rosenbrock class. + */ + static rosenbrock* make(generator* generator, unsigned int size = 10); + + virtual ~rosenbrock(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for this class. + * + * @param generator an instance of a generator class. + * The generator is used to initialize the parameters of this + * solution. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + rosenbrock(generator* generator, unsigned int size ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/schwefel.cpp b/src/copt/solutions/bench/schwefel.cpp new file mode 100644 index 0000000..ec16338 --- /dev/null +++ b/src/copt/solutions/bench/schwefel.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +schwefel* schwefel::make(generator* generator, unsigned int size) +{ + auto* result = new schwefel(generator, size); + + result->init(); + + return result; +} + +float schwefel::calculate_fitness() +{ + int n = size(); + float* params = get_params(); + + solution::calculate_fitness(); + + float result = 0; + + #pragma omp simd + for(int i = 0; i < n; i++) + { + result += params[i] * sin(sqrt(fabs(params[i]))); + } + + return -1 * result / n; +} + +schwefel::schwefel(generator* generator, unsigned int size ) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::schwefel(generator, size) +{ + +} + +schwefel::~schwefel() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/schwefel.h b/src/copt/solutions/bench/schwefel.h new file mode 100644 index 0000000..36cc9f2 --- /dev/null +++ b/src/copt/solutions/bench/schwefel.h @@ -0,0 +1,89 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_SCHWEFEL +#define DNN_OPT_COPT_SOLUTIONS_SCHWEFEL + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::schwefel + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class schwefel : public virtual solution, + public virtual core::solutions::bench::schwefel +{ +public: + + /** + * @brief Returns an instance of the schwefel class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return a pointer to an instance of the schwefel class. + */ + static schwefel* make(generator* generator, unsigned int size = 10); + + virtual ~schwefel(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for this class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + schwefel(generator* generator, unsigned int size ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/step.cpp b/src/copt/solutions/bench/step.cpp new file mode 100644 index 0000000..0100797 --- /dev/null +++ b/src/copt/solutions/bench/step.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +step* step::make(generator* generator, unsigned int size) +{ + auto* result = new step(generator, size); + + result->init(); + + return result; +} + +float step::calculate_fitness() +{ + float result = 0; + float* params = get_params(); + int n = size(); + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n; i++) + { + result += std::pow(std::floor(params[i]), 2); + } + + return result; +} + +step::step(generator* generator, unsigned int size) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::step(generator, size) +{ + +} + +step::~step() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/step.h b/src/copt/solutions/bench/step.h new file mode 100644 index 0000000..31ed96c --- /dev/null +++ b/src/copt/solutions/bench/step.h @@ -0,0 +1,92 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_STEP +#define DNN_OPT_COPT_SOLUTIONS_STEP + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +/** + * @copydoc core::solutions::step + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class step : public virtual solution, + public virtual core::solutions::bench::step +{ +public: + + /** + * @brief Returns an instance of the step class. + * + * @param generator an instance of a generator class. The + * generator is used to initialize the parameters of this solution. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return an instance of step class. + */ + static step* make(generator* generator, unsigned int size = 10); + + virtual ~step(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for this class. + * + * @param generator an instance of a generator class. + * The generator is used to initialize the parameters of this + * solution. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + step(generator* generator, unsigned int size = 10 ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif diff --git a/src/copt/solutions/bench/styblinski_tang.cpp b/src/copt/solutions/bench/styblinski_tang.cpp new file mode 100644 index 0000000..70202d4 --- /dev/null +++ b/src/copt/solutions/bench/styblinski_tang.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + +styblinski_tang* styblinski_tang::make(generator* generator, unsigned int size) +{ + auto* result = new styblinski_tang(generator, size); + + result->init(); + + return result; +} + +float styblinski_tang::calculate_fitness() +{ + int n = size(); + float* params = get_params(); + float result = 0; + + solution::calculate_fitness(); + + #pragma omp simd + for(int i = 0; i < n; i++) + { + result += pow(params[i], 4) + 16 * pow(params[i], 2) + 5 * params[i]; + } + + return result / 2; +} + +styblinski_tang::styblinski_tang(generator* generator, unsigned int size ) +: solution(generator, size), + core::solution(generator, size), + core::solutions::bench::styblinski_tang(generator, size) +{ + +} + +styblinski_tang::~styblinski_tang() +{ + +} + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt diff --git a/src/copt/solutions/bench/styblinski_tang.h b/src/copt/solutions/bench/styblinski_tang.h new file mode 100644 index 0000000..97ee6d6 --- /dev/null +++ b/src/copt/solutions/bench/styblinski_tang.h @@ -0,0 +1,90 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DNN_OPT_COPT_SOLUTIONS_STYBLINSKI_TANG +#define DNN_OPT_COPT_SOLUTIONS_STYBLINSKI_TANG + +#include +#include +#include + +namespace dnn_opt +{ +namespace copt +{ +namespace solutions +{ +namespace bench +{ + + +/** + * @copydoc core::solutions::styblinski_tang + * + * @author Jairo Rojas-Delgado + * @version 1.0 + * @date November, 2018 + */ +class styblinski_tang : public virtual solution, + public virtual core::solutions::bench::styblinski_tang +{ +public: + + /** + * @brief Returns an instance the styblinski_tang class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + * + * @return an instance of styblinski_tang class. + */ + static styblinski_tang* make(generator* generator, unsigned int size = 10); + + virtual ~styblinski_tang(); + +protected: + + virtual float calculate_fitness() override; + + /** + * @brief The basic contructor for this class. + * + * @param generator an instance of a generator class. + * + * @param size is the number of parameters for this solution. Default is 10. + */ + styblinski_tang(generator* generator, unsigned int size ); + +}; + +} // namespace bench +} // namespace solutions +} // namespace copt +} // namespace dnn_opt + +#endif From 764f095490d10a8475cd6b49d6cde9f48b6af56f Mon Sep 17 00:00:00 2001 From: alejandrom247 Date: Wed, 10 Jun 2020 23:44:49 -0400 Subject: [PATCH 2/5] Move class of benchmark implmentation to bench directory --- src/copt/solutions/ackley.cpp | 59 ----------------- src/copt/solutions/ackley.h | 90 -------------------------- src/copt/solutions/alpine.cpp | 52 --------------- src/copt/solutions/alpine.h | 89 ------------------------- src/copt/solutions/de_jung.cpp | 44 ------------- src/copt/solutions/de_jung.h | 70 -------------------- src/copt/solutions/griewangk.cpp | 58 ----------------- src/copt/solutions/griewangk.h | 87 ------------------------- src/copt/solutions/rastrigin.cpp | 53 --------------- src/copt/solutions/rastrigin.h | 86 ------------------------ src/copt/solutions/rosenbrock.cpp | 53 --------------- src/copt/solutions/rosenbrock.h | 88 ------------------------- src/copt/solutions/schwefel.cpp | 54 ---------------- src/copt/solutions/schwefel.h | 86 ------------------------ src/copt/solutions/step.cpp | 53 --------------- src/copt/solutions/step.h | 89 ------------------------- src/copt/solutions/styblinski_tang.cpp | 53 --------------- src/copt/solutions/styblinski_tang.h | 86 ------------------------ 18 files changed, 1250 deletions(-) delete mode 100644 src/copt/solutions/ackley.cpp delete mode 100644 src/copt/solutions/ackley.h delete mode 100644 src/copt/solutions/alpine.cpp delete mode 100644 src/copt/solutions/alpine.h delete mode 100644 src/copt/solutions/de_jung.cpp delete mode 100644 src/copt/solutions/de_jung.h delete mode 100644 src/copt/solutions/griewangk.cpp delete mode 100644 src/copt/solutions/griewangk.h delete mode 100644 src/copt/solutions/rastrigin.cpp delete mode 100644 src/copt/solutions/rastrigin.h delete mode 100644 src/copt/solutions/rosenbrock.cpp delete mode 100644 src/copt/solutions/rosenbrock.h delete mode 100644 src/copt/solutions/schwefel.cpp delete mode 100644 src/copt/solutions/schwefel.h delete mode 100644 src/copt/solutions/step.cpp delete mode 100644 src/copt/solutions/step.h delete mode 100644 src/copt/solutions/styblinski_tang.cpp delete mode 100644 src/copt/solutions/styblinski_tang.h diff --git a/src/copt/solutions/ackley.cpp b/src/copt/solutions/ackley.cpp deleted file mode 100644 index 7df9b78..0000000 --- a/src/copt/solutions/ackley.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -ackley* ackley::make(generator* generator, unsigned int size) -{ - auto* result = new ackley(generator, size); - - result->init(); - - return result; -} - -float ackley::calculate_fitness() -{ - int n = size(); - float summatory_1 = 0; - float summatory_2 = 0; - float result = 0; - float* params = get_params(); - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n; i++) - { - summatory_1 += pow(params[i], 2); - summatory_2 += cos(2 * 3.141592653f * params[i]); - } - - result = -20 * exp(-0.2 * sqrt(summatory_1 / n)) ; - result += -exp(summatory_2 / n) + 20 + 2.718281828f; - - return result; -} - -ackley::ackley(generator* generator, unsigned int size) -: solution(generator, size), - core::solution(generator, size), - core::solutions::ackley(generator, size) -{ - -} - -ackley::~ackley() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/ackley.h b/src/copt/solutions/ackley.h deleted file mode 100644 index 8bf05e2..0000000 --- a/src/copt/solutions/ackley.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_ACKLEY -#define DNN_OPT_COPT_SOLUTIONS_ACKLEY - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::ackley - * - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class ackley : public virtual solution, - public virtual core::solutions::ackley -{ -public: - - /** - * @brief Returns an instance of the ackley class. - * - * @param generator an instance of a generator class. The - * generator is used to initialize the parameters of this solution. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return an instance of ackley class. - */ - static ackley* make(generator* generator, unsigned int size = 10); - - virtual ~ackley(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for this class. - * - * @param generator an instance of a generator class. - * The generator is used to initialize the parameters of this - * solution. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - ackley(generator* generator, unsigned int size = 10 ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/alpine.cpp b/src/copt/solutions/alpine.cpp deleted file mode 100644 index 2a013c0..0000000 --- a/src/copt/solutions/alpine.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -alpine* alpine::make(generator* generator, unsigned int size) -{ - auto* result = new alpine(generator, size); - - result->init(); - - return result; -} - -float alpine::calculate_fitness() -{ - int n = size(); - float result = 0; - float* params = get_params(); - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n; i++) - { - result += std::fabs(params[i] * sin(params[i]) + 0.1 * params[i]); - } - - return std::fabs(result); -} - -alpine::alpine(generator* generator, unsigned int size) -: solution(generator, size), - core::solution(generator, size), - core::solutions::alpine(generator, size) -{ - -} - -alpine::~alpine() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/alpine.h b/src/copt/solutions/alpine.h deleted file mode 100644 index 82fac48..0000000 --- a/src/copt/solutions/alpine.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_ALPINE -#define DNN_OPT_COPT_SOLUTIONS_ALPINE - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::alpine - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class alpine : public virtual solution, - public virtual core::solutions::alpine -{ -public: - - /** - * @brief Returns an instance of the alpine class. - * - * @param generator an instance of a generator class. The - * generator is used to initialize the parameters of this solution. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return an instance of alpine class. - */ - static alpine* make(generator* generator, unsigned int size = 10); - - virtual ~alpine(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for this class. - * - * @param generator an instance of a generator class. - * The generator is used to initialize the parameters of this - * solution. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - alpine(generator* generator, unsigned int size = 10 ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/de_jung.cpp b/src/copt/solutions/de_jung.cpp deleted file mode 100644 index feceefc..0000000 --- a/src/copt/solutions/de_jung.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -de_jung* de_jung::make(generator *generator, unsigned int size) -{ - auto* result = new de_jung(generator, size); - - result->init(); - - return result; -} - -float de_jung::calculate_fitness() -{ - float result = cblas_sdot(size(), get_params(), 1, get_params(), 1); - - solution::calculate_fitness(); - - return result; -} - -de_jung::de_jung(generator* generator, unsigned int size) -: solution(generator, size), - core::solution(generator, size), - core::solutions::de_jung(generator, size) -{ - -} - -de_jung::~de_jung() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/de_jung.h b/src/copt/solutions/de_jung.h deleted file mode 100644 index fafbf60..0000000 --- a/src/copt/solutions/de_jung.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_DE_JUNG -#define DNN_OPT_COPT_SOLUTIONS_DE_JUNG - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::de_jung - * - * @author Jairo Rojas-Delgado - * @date December, 2017 - * @version 1.0 - */ -class de_jung : public virtual solution, - public virtual core::solutions::de_jung -{ -public: - - static de_jung* make(generator* generator, unsigned int size = 10); - - virtual ~de_jung(); - -protected: - - virtual float calculate_fitness() override; - - de_jung(generator* generator, unsigned int size = 10); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/griewangk.cpp b/src/copt/solutions/griewangk.cpp deleted file mode 100644 index d6edddd..0000000 --- a/src/copt/solutions/griewangk.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -griewangk* griewangk::make(generator* generator, unsigned int size) -{ - auto* result = new griewangk(generator, size); - - result->init(); - - return result; -} - -float griewangk::calculate_fitness() -{ - int n = size(); - float* params = get_params(); - float summatory = 0; - float multiplier = 1; - float result = 0; - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n; i++) - { - summatory += pow(params[i], 2.0) / 4000; - multiplier *= cos(params[i] / sqrt(i + 1)); - } - - result = summatory - multiplier + 1; - - return result; -} - -griewangk::griewangk(generator* generator, unsigned int size) -: solution(generator, size), - core::solution(generator, size), - core::solutions::griewangk(generator, size) -{ - -} - -griewangk::~griewangk() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/griewangk.h b/src/copt/solutions/griewangk.h deleted file mode 100644 index 02f64d1..0000000 --- a/src/copt/solutions/griewangk.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_GRIEWANGK -#define DNN_OPT_COPT_SOLUTIONS_GRIEWANGK - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::griewangk - * - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class griewangk : public virtual solution, - public virtual core::solutions::griewangk -{ -public: - - /** - * @brief Returns an instance of the griewangk class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return a pointer to an instance of the griewangk class. - */ - static griewangk* make(generator* generator, unsigned int size = 10); - - virtual ~griewangk(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief Thhe basic contructor for this class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - griewangk(generator* generator, unsigned int size = 10); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/rastrigin.cpp b/src/copt/solutions/rastrigin.cpp deleted file mode 100644 index 6125b36..0000000 --- a/src/copt/solutions/rastrigin.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -rastrigin* rastrigin::make(generator* generator, unsigned int size) -{ - auto* result = new rastrigin(generator, size); - - result->init(); - - return result; -} - -float rastrigin::calculate_fitness() -{ - int n = size(); - float* params = get_params(); - float result = 10 * size(); - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n; i++) - { - result += pow(params[i], 2) - 10 * cos(2 * 3.141592653f * params[i]); - } - - return result; -} - -rastrigin::rastrigin(generator* generator, unsigned int size ) -: solution(generator, size), - core::solution(generator, size), - core::solutions::rastrigin(generator, size) -{ - -} - -rastrigin::~rastrigin() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/rastrigin.h b/src/copt/solutions/rastrigin.h deleted file mode 100644 index c7181dd..0000000 --- a/src/copt/solutions/rastrigin.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_RASTRIGIN -#define DNN_OPT_COPT_SOLUTIONS_RASTRIGIN - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::rastrigin - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class rastrigin : public virtual solution, - public virtual core::solutions::rastrigin -{ -public: - - /** - * @brief Returns an instance of the rastrigin class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return a pointer to an instance of the rastrigin class. - */ - static rastrigin* make(generator* generator, unsigned int size = 10); - - virtual ~rastrigin(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for the ratrigin class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - rastrigin(generator* generator, unsigned int size ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/rosenbrock.cpp b/src/copt/solutions/rosenbrock.cpp deleted file mode 100644 index a14ada2..0000000 --- a/src/copt/solutions/rosenbrock.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -rosenbrock* rosenbrock::make(generator* generator, unsigned int size) -{ - auto* result = new rosenbrock(generator, size); - - result->init(); - - return result; -} - -float rosenbrock::calculate_fitness() -{ - int n = size(); - float* params = get_params(); - float result = 0; - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n - 1; i++) - { - result += 100 * pow(params[i + 1] - pow(params[i], 2), 2) + pow(params[i] - 1, 2); - } - - return result; -} - -rosenbrock::rosenbrock(generator* generator, unsigned int size ) -: solution(generator, size), - core::solution(generator, size), - core::solutions::rosenbrock(generator, size) -{ - -} - -rosenbrock::~rosenbrock() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/rosenbrock.h b/src/copt/solutions/rosenbrock.h deleted file mode 100644 index d711a6f..0000000 --- a/src/copt/solutions/rosenbrock.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_ROSENBROCK -#define DNN_OPT_COPT_SOLUTIONS_ROSENBROCK - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::rosenbrock - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class rosenbrock : public virtual solution, - public virtual core::solutions::rosenbrock -{ -public: - - /** - * @brief Returns an instance of the rosenbrock class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return an instance of rosenbrock class. - */ - static rosenbrock* make(generator* generator, unsigned int size = 10); - - virtual ~rosenbrock(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for this class. - * - * @param generator an instance of a generator class. - * The generator is used to initialize the parameters of this - * solution. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - rosenbrock(generator* generator, unsigned int size ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/schwefel.cpp b/src/copt/solutions/schwefel.cpp deleted file mode 100644 index 954fc2e..0000000 --- a/src/copt/solutions/schwefel.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -schwefel* schwefel::make(generator* generator, unsigned int size) -{ - auto* result = new schwefel(generator, size); - - result->init(); - - return result; -} - -float schwefel::calculate_fitness() -{ - int n = size(); - float* params = get_params(); - - solution::calculate_fitness(); - - float result = 0; - - #pragma omp simd - for(int i = 0; i < n; i++) - { - result += params[i] * sin(sqrt(fabs(params[i]))); - } - - return -1 * result / n; -} - -schwefel::schwefel(generator* generator, unsigned int size ) -: solution(generator, size), - core::solution(generator, size), - core::solutions::schwefel(generator, size) -{ - -} - -schwefel::~schwefel() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/schwefel.h b/src/copt/solutions/schwefel.h deleted file mode 100644 index 9ee9a83..0000000 --- a/src/copt/solutions/schwefel.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_SCHWEFEL -#define DNN_OPT_COPT_SOLUTIONS_SCHWEFEL - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::schwefel - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class schwefel : public virtual solution, - public virtual core::solutions::schwefel -{ -public: - - /** - * @brief Returns an instance of the schwefel class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return a pointer to an instance of the schwefel class. - */ - static schwefel* make(generator* generator, unsigned int size = 10); - - virtual ~schwefel(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for this class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - schwefel(generator* generator, unsigned int size ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/step.cpp b/src/copt/solutions/step.cpp deleted file mode 100644 index 6ec3c95..0000000 --- a/src/copt/solutions/step.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -step* step::make(generator* generator, unsigned int size) -{ - auto* result = new step(generator, size); - - result->init(); - - return result; -} - -float step::calculate_fitness() -{ - float result = 0; - float* params = get_params(); - int n = size(); - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n; i++) - { - result += std::pow(std::floor(params[i]), 2); - } - - return result; -} - -step::step(generator* generator, unsigned int size) -: solution(generator, size), - core::solution(generator, size), - core::solutions::step(generator, size) -{ - -} - -step::~step() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/step.h b/src/copt/solutions/step.h deleted file mode 100644 index 4c29ddb..0000000 --- a/src/copt/solutions/step.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_STEP -#define DNN_OPT_COPT_SOLUTIONS_STEP - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::step - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class step : public virtual solution, - public virtual core::solutions::step -{ -public: - - /** - * @brief Returns an instance of the step class. - * - * @param generator an instance of a generator class. The - * generator is used to initialize the parameters of this solution. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return an instance of step class. - */ - static step* make(generator* generator, unsigned int size = 10); - - virtual ~step(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for this class. - * - * @param generator an instance of a generator class. - * The generator is used to initialize the parameters of this - * solution. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - step(generator* generator, unsigned int size = 10 ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif diff --git a/src/copt/solutions/styblinski_tang.cpp b/src/copt/solutions/styblinski_tang.cpp deleted file mode 100644 index b9da1ad..0000000 --- a/src/copt/solutions/styblinski_tang.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -styblinski_tang* styblinski_tang::make(generator* generator, unsigned int size) -{ - auto* result = new styblinski_tang(generator, size); - - result->init(); - - return result; -} - -float styblinski_tang::calculate_fitness() -{ - int n = size(); - float* params = get_params(); - float result = 0; - - solution::calculate_fitness(); - - #pragma omp simd - for(int i = 0; i < n; i++) - { - result += pow(params[i], 4) + 16 * pow(params[i], 2) + 5 * params[i]; - } - - return result / 2; -} - -styblinski_tang::styblinski_tang(generator* generator, unsigned int size ) -: solution(generator, size), - core::solution(generator, size), - core::solutions::styblinski_tang(generator, size) -{ - -} - -styblinski_tang::~styblinski_tang() -{ - -} - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt diff --git a/src/copt/solutions/styblinski_tang.h b/src/copt/solutions/styblinski_tang.h deleted file mode 100644 index 3508cb4..0000000 --- a/src/copt/solutions/styblinski_tang.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -Copyright (c) 2018, Jairo Rojas-Delgado -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -* Neither the name of the nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DNN_OPT_COPT_SOLUTIONS_STYBLINSKI_TANG -#define DNN_OPT_COPT_SOLUTIONS_STYBLINSKI_TANG - -#include -#include -#include - -namespace dnn_opt -{ -namespace copt -{ -namespace solutions -{ - -/** - * @copydoc core::solutions::styblinski_tang - * - * @author Jairo Rojas-Delgado - * @version 1.0 - * @date November, 2018 - */ -class styblinski_tang : public virtual solution, - public virtual core::solutions::styblinski_tang -{ -public: - - /** - * @brief Returns an instance the styblinski_tang class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - * - * @return an instance of styblinski_tang class. - */ - static styblinski_tang* make(generator* generator, unsigned int size = 10); - - virtual ~styblinski_tang(); - -protected: - - virtual float calculate_fitness() override; - - /** - * @brief The basic contructor for this class. - * - * @param generator an instance of a generator class. - * - * @param size is the number of parameters for this solution. Default is 10. - */ - styblinski_tang(generator* generator, unsigned int size ); - -}; - -} // namespace solutions -} // namespace copt -} // namespace dnn_opt - -#endif From 8dc48c299a4f3dd312e9d8615b45af6547e5177a Mon Sep 17 00:00:00 2001 From: alejandrom247 Date: Wed, 10 Jun 2020 23:48:28 -0400 Subject: [PATCH 3/5] Add includes of the new benchmark functions in the library header --- src/dnn_opt.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/dnn_opt.h b/src/dnn_opt.h index ba1ac0d..29976ed 100644 --- a/src/dnn_opt.h +++ b/src/dnn_opt.h @@ -114,16 +114,26 @@ /* solutions */ #include - #include - #include - #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include + #include + #include + #include #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include /* layers */ #include From 155e931be49267962066415698295ed8ea61825d Mon Sep 17 00:00:00 2001 From: jairodelgado Date: Thu, 11 Jun 2020 16:05:00 -0400 Subject: [PATCH 4/5] Add missing destructor of csv reader --- src/copt/readers/csv_reader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/copt/readers/csv_reader.cpp b/src/copt/readers/csv_reader.cpp index 77bc916..fda395b 100644 --- a/src/copt/readers/csv_reader.cpp +++ b/src/copt/readers/csv_reader.cpp @@ -6,7 +6,7 @@ namespace dnn_opt namespace copt { namespace readers -{ +{ csv_reader* csv_reader::make(std::string file_name, int in_dim, int out_dim, char sep, bool header) { @@ -19,6 +19,11 @@ csv_reader::csv_reader(std::string file_name, int in_dim, int out_dim, char sep, } +csv_reader::~csv_reader() +{ + +} + } // namespace readers } // namespace copt } // namespace dnn_opt From 87812129572ff37ebdcd9fc231de27540991f47a Mon Sep 17 00:00:00 2001 From: jairodelgado Date: Thu, 11 Jun 2020 16:19:18 -0400 Subject: [PATCH 5/5] Add time bench example --- examples/benchmark/CMakeLists.txt | 10 ++++ examples/benchmark/fitness_time.cpp | 77 +++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 examples/benchmark/fitness_time.cpp diff --git a/examples/benchmark/CMakeLists.txt b/examples/benchmark/CMakeLists.txt index da6e42f..1910ceb 100644 --- a/examples/benchmark/CMakeLists.txt +++ b/examples/benchmark/CMakeLists.txt @@ -1,18 +1,28 @@ ADD_EXECUTABLE(benchmark benchmark.cpp) +ADD_EXECUTABLE(fitness_time fitness_time.cpp) + TARGET_INCLUDE_DIRECTORIES(benchmark PRIVATE ../common) +TARGET_INCLUDE_DIRECTORIES(fitness_time PRIVATE ../common) IF(ENABLE_CORE) TARGET_LINK_LIBRARIES(benchmark dnn_opt_core) + TARGET_LINK_LIBRARIES(fitness_time dnn_opt_core) ENDIF(ENABLE_CORE) IF(ENABLE_COPT) TARGET_LINK_LIBRARIES(benchmark dnn_opt_copt) + TARGET_LINK_LIBRARIES(fitness_time dnn_opt_copt) ENDIF(ENABLE_COPT) IF(ENABLE_CUDA) TARGET_LINK_LIBRARIES(benchmark dnn_opt_cuda) + TARGET_LINK_LIBRARIES(fitness_time dnn_opt_cuda) ENDIF(ENABLE_CUDA) SET_TARGET_PROPERTIES(benchmark PROPERTIES CXX_STANDARD 11 CXXSTANDARD_REQUIRED YES) SET_TARGET_PROPERTIES(benchmark PROPERTIES LINKER_LANGUAGE CXX) +SET_TARGET_PROPERTIES(fitness_time PROPERTIES CXX_STANDARD 11 CXXSTANDARD_REQUIRED YES) +SET_TARGET_PROPERTIES(fitness_time PROPERTIES LINKER_LANGUAGE CXX) + + diff --git a/examples/benchmark/fitness_time.cpp b/examples/benchmark/fitness_time.cpp new file mode 100644 index 0000000..cc2e27e --- /dev/null +++ b/examples/benchmark/fitness_time.cpp @@ -0,0 +1,77 @@ +/* +Copyright (c) 2018, Jairo Rojas-Delgado +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the nor the +names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include + +#include +#include + +using namespace std; +using namespace std::chrono; + +#ifdef ENABLE_CUDA +using namespace dnn_opt::cuda; +#elif ENABLE_COPT +using namespace dnn_opt::copt; +#elif ENABLE_CORE +using namespace dnn_opt::core; +#endif + +int main(int argc, char** argv) +{ + /* command line argument collection */ + + int n = input("-n", 100, argc, argv); + int p = input("-p", 40, argc, argv); + int eta = input("-eta", 1000, argc, argv); + int solution_type = input("-s", 8, argc, argv); + + auto* generator = generators::uniform::make(-10.0f, 10.0f); + auto* solution = create_solution(solution_type, n, generator); + + solution->generate(); + + auto start = high_resolution_clock::now(); + + for(int i = 0; i < eta; i++) + { + solution->fitness(); + solution->set_modified(true); + } + + auto end = high_resolution_clock::now(); + float time = duration_cast(end - start).count(); + + cout << time << endl; + + delete solution; + delete generator; + + return 0; +}