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; +} 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 diff --git a/src/copt/solutions/ackley.cpp b/src/copt/solutions/bench/ackley.cpp similarity index 87% rename from src/copt/solutions/ackley.cpp rename to src/copt/solutions/bench/ackley.cpp index 7df9b78..31ee231 100644 --- a/src/copt/solutions/ackley.cpp +++ b/src/copt/solutions/bench/ackley.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ ackley* ackley::make(generator* generator, unsigned int size) { @@ -44,7 +46,7 @@ float ackley::calculate_fitness() ackley::ackley(generator* generator, unsigned int size) : solution(generator, size), core::solution(generator, size), - core::solutions::ackley(generator, size) + core::solutions::bench::ackley(generator, size) { } @@ -54,6 +56,7 @@ ackley::~ackley() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/ackley.h b/src/copt/solutions/bench/ackley.h similarity index 90% rename from src/copt/solutions/ackley.h rename to src/copt/solutions/bench/ackley.h index 8bf05e2..6cde830 100644 --- a/src/copt/solutions/ackley.h +++ b/src/copt/solutions/bench/ackley.h @@ -25,10 +25,10 @@ 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 +#ifndef DNN_OPT_COPT_SOLUTIONS_BENCH_ACKLEY +#define DNN_OPT_COPT_SOLUTIONS_BENCH_ACKLEY -#include +#include #include #include @@ -38,9 +38,11 @@ namespace copt { namespace solutions { +namespace bench +{ /** - * @copydoc core::solutions::ackley + * @copydoc core::solutions::bench::ackley * * * @author Jairo Rojas-Delgado @@ -48,7 +50,7 @@ namespace solutions * @date November, 2018 */ class ackley : public virtual solution, - public virtual core::solutions::ackley + public virtual core::solutions::bench::ackley { public: @@ -83,6 +85,7 @@ class ackley : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/alpine.cpp b/src/copt/solutions/bench/alpine.cpp similarity index 85% rename from src/copt/solutions/alpine.cpp rename to src/copt/solutions/bench/alpine.cpp index 2a013c0..a2c2115 100644 --- a/src/copt/solutions/alpine.cpp +++ b/src/copt/solutions/bench/alpine.cpp @@ -1,5 +1,5 @@ #include -#include +#include namespace dnn_opt { @@ -7,6 +7,9 @@ namespace copt { namespace solutions { +namespace bench +{ + alpine* alpine::make(generator* generator, unsigned int size) { @@ -37,7 +40,7 @@ float alpine::calculate_fitness() alpine::alpine(generator* generator, unsigned int size) : solution(generator, size), core::solution(generator, size), - core::solutions::alpine(generator, size) + core::solutions::bench::alpine(generator, size) { } @@ -47,6 +50,7 @@ alpine::~alpine() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/alpine.h b/src/copt/solutions/bench/alpine.h similarity index 95% rename from src/copt/solutions/alpine.h rename to src/copt/solutions/bench/alpine.h index 82fac48..91ae65a 100644 --- a/src/copt/solutions/alpine.h +++ b/src/copt/solutions/bench/alpine.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,8 @@ namespace copt { namespace solutions { +namespace bench +{ /** * @copydoc core::solutions::alpine @@ -47,7 +49,7 @@ namespace solutions * @date November, 2018 */ class alpine : public virtual solution, - public virtual core::solutions::alpine + public virtual core::solutions::bench::alpine { public: @@ -82,6 +84,7 @@ class alpine : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt 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/de_jung.cpp b/src/copt/solutions/bench/de_jung.cpp similarity index 69% rename from src/copt/solutions/de_jung.cpp rename to src/copt/solutions/bench/de_jung.cpp index feceefc..5efcc0a 100644 --- a/src/copt/solutions/de_jung.cpp +++ b/src/copt/solutions/bench/de_jung.cpp @@ -1,5 +1,5 @@ #include -#include +#include namespace dnn_opt { @@ -7,6 +7,8 @@ namespace copt { namespace solutions { +namespace bench +{ de_jung* de_jung::make(generator *generator, unsigned int size) { @@ -19,7 +21,12 @@ de_jung* de_jung::make(generator *generator, unsigned int size) float de_jung::calculate_fitness() { - float result = cblas_sdot(size(), get_params(), 1, get_params(), 1); + float result; + + #pragma omp parallel + { + result = cblas_sdot(size(), get_params(), 1, get_params(), 1); + } solution::calculate_fitness(); @@ -29,7 +36,7 @@ float de_jung::calculate_fitness() de_jung::de_jung(generator* generator, unsigned int size) : solution(generator, size), core::solution(generator, size), - core::solutions::de_jung(generator, size) + core::solutions::bench::de_jung(generator, size) { } @@ -39,6 +46,7 @@ de_jung::~de_jung() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/de_jung.h b/src/copt/solutions/bench/de_jung.h similarity index 91% rename from src/copt/solutions/de_jung.h rename to src/copt/solutions/bench/de_jung.h index fafbf60..d709ed1 100644 --- a/src/copt/solutions/de_jung.h +++ b/src/copt/solutions/bench/de_jung.h @@ -28,7 +28,7 @@ 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 #include @@ -38,16 +38,17 @@ namespace copt { namespace solutions { +namespace bench { /** - * @copydoc core::solutions::de_jung + * @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::de_jung + public virtual core::solutions::bench::de_jung { public: @@ -63,6 +64,7 @@ class de_jung : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt 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/griewangk.cpp b/src/copt/solutions/bench/griewangk.cpp similarity index 86% rename from src/copt/solutions/griewangk.cpp rename to src/copt/solutions/bench/griewangk.cpp index d6edddd..d7b7cab 100644 --- a/src/copt/solutions/griewangk.cpp +++ b/src/copt/solutions/bench/griewangk.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ griewangk* griewangk::make(generator* generator, unsigned int size) { @@ -43,7 +45,7 @@ float griewangk::calculate_fitness() griewangk::griewangk(generator* generator, unsigned int size) : solution(generator, size), core::solution(generator, size), - core::solutions::griewangk(generator, size) + core::solutions::bench::griewangk(generator, size) { } @@ -53,6 +55,7 @@ griewangk::~griewangk() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/griewangk.h b/src/copt/solutions/bench/griewangk.h similarity index 94% rename from src/copt/solutions/griewangk.h rename to src/copt/solutions/bench/griewangk.h index 02f64d1..b6b185e 100644 --- a/src/copt/solutions/griewangk.h +++ b/src/copt/solutions/bench/griewangk.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,8 @@ namespace copt { namespace solutions { +namespace bench +{ /** * @copydoc core::solutions::griewangk @@ -48,7 +50,7 @@ namespace solutions * @date November, 2018 */ class griewangk : public virtual solution, - public virtual core::solutions::griewangk + public virtual core::solutions::bench::griewangk { public: @@ -80,6 +82,7 @@ class griewangk : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/rastrigin.cpp b/src/copt/solutions/bench/rastrigin.cpp similarity index 85% rename from src/copt/solutions/rastrigin.cpp rename to src/copt/solutions/bench/rastrigin.cpp index 6125b36..63f93e0 100644 --- a/src/copt/solutions/rastrigin.cpp +++ b/src/copt/solutions/bench/rastrigin.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ rastrigin* rastrigin::make(generator* generator, unsigned int size) { @@ -38,7 +40,7 @@ float rastrigin::calculate_fitness() rastrigin::rastrigin(generator* generator, unsigned int size ) : solution(generator, size), core::solution(generator, size), - core::solutions::rastrigin(generator, size) + core::solutions::bench::rastrigin(generator, size) { } @@ -48,6 +50,7 @@ rastrigin::~rastrigin() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/rastrigin.h b/src/copt/solutions/bench/rastrigin.h similarity index 94% rename from src/copt/solutions/rastrigin.h rename to src/copt/solutions/bench/rastrigin.h index c7181dd..a67effe 100644 --- a/src/copt/solutions/rastrigin.h +++ b/src/copt/solutions/bench/rastrigin.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,8 @@ namespace copt { namespace solutions { +namespace bench +{ /** * @copydoc core::solutions::rastrigin @@ -47,7 +49,7 @@ namespace solutions * @date November, 2018 */ class rastrigin : public virtual solution, - public virtual core::solutions::rastrigin + public virtual core::solutions::bench::rastrigin { public: @@ -79,6 +81,7 @@ class rastrigin : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/rosenbrock.cpp b/src/copt/solutions/bench/rosenbrock.cpp similarity index 85% rename from src/copt/solutions/rosenbrock.cpp rename to src/copt/solutions/bench/rosenbrock.cpp index a14ada2..d9ab5d5 100644 --- a/src/copt/solutions/rosenbrock.cpp +++ b/src/copt/solutions/bench/rosenbrock.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ rosenbrock* rosenbrock::make(generator* generator, unsigned int size) { @@ -38,7 +40,7 @@ float rosenbrock::calculate_fitness() rosenbrock::rosenbrock(generator* generator, unsigned int size ) : solution(generator, size), core::solution(generator, size), - core::solutions::rosenbrock(generator, size) + core::solutions::bench::rosenbrock(generator, size) { } @@ -48,6 +50,7 @@ rosenbrock::~rosenbrock() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/rosenbrock.h b/src/copt/solutions/bench/rosenbrock.h similarity index 94% rename from src/copt/solutions/rosenbrock.h rename to src/copt/solutions/bench/rosenbrock.h index d711a6f..3f0ba7f 100644 --- a/src/copt/solutions/rosenbrock.h +++ b/src/copt/solutions/bench/rosenbrock.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,8 @@ namespace copt { namespace solutions { +namespace bench +{ /** * @copydoc core::solutions::rosenbrock @@ -47,7 +49,7 @@ namespace solutions * @date November, 2018 */ class rosenbrock : public virtual solution, - public virtual core::solutions::rosenbrock + public virtual core::solutions::bench::rosenbrock { public: @@ -81,6 +83,7 @@ class rosenbrock : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/schwefel.cpp b/src/copt/solutions/bench/schwefel.cpp similarity index 85% rename from src/copt/solutions/schwefel.cpp rename to src/copt/solutions/bench/schwefel.cpp index 954fc2e..ec16338 100644 --- a/src/copt/solutions/schwefel.cpp +++ b/src/copt/solutions/bench/schwefel.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ schwefel* schwefel::make(generator* generator, unsigned int size) { @@ -39,7 +41,7 @@ float schwefel::calculate_fitness() schwefel::schwefel(generator* generator, unsigned int size ) : solution(generator, size), core::solution(generator, size), - core::solutions::schwefel(generator, size) + core::solutions::bench::schwefel(generator, size) { } @@ -49,6 +51,7 @@ schwefel::~schwefel() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/schwefel.h b/src/copt/solutions/bench/schwefel.h similarity index 94% rename from src/copt/solutions/schwefel.h rename to src/copt/solutions/bench/schwefel.h index 9ee9a83..36cc9f2 100644 --- a/src/copt/solutions/schwefel.h +++ b/src/copt/solutions/bench/schwefel.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,8 @@ namespace copt { namespace solutions { +namespace bench +{ /** * @copydoc core::solutions::schwefel @@ -47,7 +49,7 @@ namespace solutions * @date November, 2018 */ class schwefel : public virtual solution, - public virtual core::solutions::schwefel + public virtual core::solutions::bench::schwefel { public: @@ -79,6 +81,7 @@ class schwefel : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/step.cpp b/src/copt/solutions/bench/step.cpp similarity index 85% rename from src/copt/solutions/step.cpp rename to src/copt/solutions/bench/step.cpp index 6ec3c95..0100797 100644 --- a/src/copt/solutions/step.cpp +++ b/src/copt/solutions/bench/step.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ step* step::make(generator* generator, unsigned int size) { @@ -38,7 +40,7 @@ float step::calculate_fitness() step::step(generator* generator, unsigned int size) : solution(generator, size), core::solution(generator, size), - core::solutions::step(generator, size) + core::solutions::bench::step(generator, size) { } @@ -48,6 +50,7 @@ step::~step() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/step.h b/src/copt/solutions/bench/step.h similarity index 95% rename from src/copt/solutions/step.h rename to src/copt/solutions/bench/step.h index 4c29ddb..31ed96c 100644 --- a/src/copt/solutions/step.h +++ b/src/copt/solutions/bench/step.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,8 @@ namespace copt { namespace solutions { +namespace bench +{ /** * @copydoc core::solutions::step @@ -47,7 +49,7 @@ namespace solutions * @date November, 2018 */ class step : public virtual solution, - public virtual core::solutions::step + public virtual core::solutions::bench::step { public: @@ -82,6 +84,7 @@ class step : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/styblinski_tang.cpp b/src/copt/solutions/bench/styblinski_tang.cpp similarity index 84% rename from src/copt/solutions/styblinski_tang.cpp rename to src/copt/solutions/bench/styblinski_tang.cpp index b9da1ad..70202d4 100644 --- a/src/copt/solutions/styblinski_tang.cpp +++ b/src/copt/solutions/bench/styblinski_tang.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace dnn_opt { @@ -8,6 +8,8 @@ namespace copt { namespace solutions { +namespace bench +{ styblinski_tang* styblinski_tang::make(generator* generator, unsigned int size) { @@ -38,7 +40,7 @@ float styblinski_tang::calculate_fitness() styblinski_tang::styblinski_tang(generator* generator, unsigned int size ) : solution(generator, size), core::solution(generator, size), - core::solutions::styblinski_tang(generator, size) + core::solutions::bench::styblinski_tang(generator, size) { } @@ -48,6 +50,7 @@ styblinski_tang::~styblinski_tang() } +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt diff --git a/src/copt/solutions/styblinski_tang.h b/src/copt/solutions/bench/styblinski_tang.h similarity index 94% rename from src/copt/solutions/styblinski_tang.h rename to src/copt/solutions/bench/styblinski_tang.h index 3508cb4..97ee6d6 100644 --- a/src/copt/solutions/styblinski_tang.h +++ b/src/copt/solutions/bench/styblinski_tang.h @@ -28,7 +28,7 @@ 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 #include @@ -38,6 +38,9 @@ namespace copt { namespace solutions { +namespace bench +{ + /** * @copydoc core::solutions::styblinski_tang @@ -47,7 +50,7 @@ namespace solutions * @date November, 2018 */ class styblinski_tang : public virtual solution, - public virtual core::solutions::styblinski_tang + public virtual core::solutions::bench::styblinski_tang { public: @@ -79,6 +82,7 @@ class styblinski_tang : public virtual solution, }; +} // namespace bench } // namespace solutions } // namespace copt } // namespace dnn_opt 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