diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/AUTHORS b/branches/ParadisEO-GPU/paradiseo-gpu/AUTHORS new file mode 100644 index 000000000..a1f03b80a --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/AUTHORS @@ -0,0 +1,5 @@ +Authors: + Boufaras Karima + Thé Van Luong + + diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/CMakeLists.txt b/branches/ParadisEO-GPU/paradiseo-gpu/CMakeLists.txt new file mode 100644 index 000000000..7d9225e79 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/CMakeLists.txt @@ -0,0 +1,131 @@ +###################################################################################### +### 0) Set your application properties +###################################################################################### +# check cmake version compatibility +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# Here define your project name +PROJECT(Paradiseo-GPU) + +SET(PACKAGE_BUGREPORT "paradiseo-help@lists.gforge.inria.fr" CACHE STRING "Package bug report" FORCE) +SET(PACKAGE_NAME "ParadisEO-GPU - Moving Objects GPU" CACHE STRING "Package name" FORCE) +SET(PACKAGE_STRING "ParadisEO-GPU 1.0" CACHE STRING "GPU Package string full name" FORCE) +SET(PACKAGE_VERSION "1.0" CACHE STRING "Package version" FORCE) +SET(GLOBAL_VERSION "1.0" CACHE STRING "Global version" FORCE) +SET(VERSION "1.0.0" CACHE STRING "Version" FORCE) + +# regular expression checking +INCLUDE_REGULAR_EXPRESSION("^.*$" "^$") + +# set a language for the entire project. +ENABLE_LANGUAGE(CXX) +ENABLE_LANGUAGE(C) + +###################################################################################### + + ########################################## + # Find Cuda package # + ########################################## + + +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/cuda" ${CMAKE_MODULE_PATH}) +find_package(CUDA QUIET REQUIRED) + +# Check if CUDA was found + if (CUDA_FOUND) + message("CUDA found") + else() + message("CUDA not found") + endif() + +###################################################################################### +### 1) Include the install configuration file where are defined the main variables +###################################################################################### + +INCLUDE(${CMAKE_SOURCE_DIR}/install.cmake) + +###################################################################################### + +###################################################################################### +### 2) Include the sources +###################################################################################### + + ########################################## + # Include required modules & utilities # + ########################################## + +INCLUDE(CMakeBackwardCompatibilityCXX) + +INCLUDE(FindDoxygen) + +INCLUDE(CheckLibraryExists) + +INCLUDE(Dart OPTIONAL) + +# Set a special flag if the environment is windows (should do the same in a config.g file) +IF (WIN32) + ADD_DEFINITIONS(-D_WINDOWS=1) +ENDIF (WIN32) + +###################################################################################### + + ######################### + # Manage the build type # + ######################### + +# the user should choose the build type on windows environments,excepted under cygwin (default=none) +SET(CMAKE_DEFAULT_BUILD_TYPE "Release" CACHE STRING "Variable that stores the default CMake build type" FORCE) + +FIND_PROGRAM(MEMORYCHECK_COMMAND + NAMES purify valgrind + PATHS + "/usr/local/bin /usr/bin [HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]" + DOC "Path to the memory checking command, used for memory error detection.") + +IF(NOT CMAKE_BUILD_TYPE) + SET( CMAKE_BUILD_TYPE + ${CMAKE_DEFAULT_BUILD_TYPE} CACHE STRING + "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." + FORCE) +ENDIF(NOT CMAKE_BUILD_TYPE) + +IF(WIN32 AND NOT CYGWIN) + IF(CMAKE_CXX_COMPILER MATCHES cl) + IF(NOT WITH_SHARED_LIBS) + IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008") + SET(CMAKE_CXX_FLAGS "/nologo /Gy") + SET(CMAKE_CXX_FLAGS_DEBUG "/W3 /MTd /Z7 /Od") + SET(CMAKE_CXX_FLAGS_RELEASE "/w /MT /O2 /wd4530") + SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE") + ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008") + ENDIF(NOT WITH_SHARED_LIBS) + ENDIF(CMAKE_CXX_COMPILER MATCHES cl) +ELSE(WIN32 AND NOT CYGWIN) + IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2 -g -pg -fprofile-arcs -ftest-coverage -Wall -Wextra -Wno-unused-parameter") + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") + SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -O6") + ENDIF(CMAKE_COMPILER_IS_GNUCXX) +ENDIF(WIN32 AND NOT CYGWIN) + +IF(CMAKE_BUILD_TYPE MATCHES Debug) + ADD_DEFINITIONS(-DCMAKE_VERBOSE_MAKEFILE=ON) +ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) + +EXECUTE_PROCESS( + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${PARADISEO_GPU_SRC_DIR}/CTestCustom.cmake + ${PARADISEO_GPU_BIN_DIR}/CTestCustom.cmake) +########################################################################################################################################## +###################################################################################### +### 3) Link the librairies for your executable +###################################################################################### + +ADD_SUBDIRECTORY(doc) +ADD_SUBDIRECTORY(test) +ADD_SUBDIRECTORY(tutorial) + +###################################################################################### + diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/CTestConfig.cmake b/branches/ParadisEO-GPU/paradiseo-gpu/CTestConfig.cmake new file mode 100644 index 000000000..465d208d6 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/CTestConfig.cmake @@ -0,0 +1,7 @@ +set(CTEST_PROJECT_NAME "ParadisEO") +set(CTEST_NIGHTLY_START_TIME "00:00:00 EST") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "cdash.inria.fr") +set(CTEST_DROP_LOCATION "/CDash/submit.php?project=ParadisEO") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/CTestCustom.cmake b/branches/ParadisEO-GPU/paradiseo-gpu/CTestCustom.cmake new file mode 100644 index 000000000..1bb72150a --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/CTestCustom.cmake @@ -0,0 +1,8 @@ +SET(CTEST_CUSTOM_COVERAGE_EXCLUDE + ${CTEST_CUSTOM_COVERAGE_EXCLUDE} +"test/" +"paradiseo-eo/" +"paradiseo-mo/" +"paradiseo-gpu/" +"problems/" +) diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/README.txt b/branches/ParadisEO-GPU/paradiseo-gpu/README.txt new file mode 100644 index 000000000..89e4b0c55 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/README.txt @@ -0,0 +1,81 @@ + PARADISEO-GPU README FILE +======================================================================= + check latest news at http://paradiseo.gforge.inria.fr/ +======================================================================= + +Welcome to ParadisEO-GPU, the reusable design and implementation of parallel meta- +heuristics on Graphics Processing Units (GPU). +The latest news about ParadisEO-GPU can be found on the gforge repository at +http://paradiseo.gforge.inria.fr/index.php?n=Doc.API +In case of any problem, please e-mail us at +paradiseo-help@lists.gforge.inria.fr + + + +======================================================================= + BUILDING PARADISEO-PEO +======================================================================= +The basic installation procedure goes the following. + +To compile paradiseo-gpu in the default directory, +go to paradiseo-gpu/build/ and run: + > cmake .. + > make + // for an easy-use of the provided lessons + > make install + // optional (if the documentation is not already available) + > make doc + +To compile paradiseo-peo anywhere else, simply run: + > cmake $(GPU) -Dconfig= + > make + // for an easy-use of the provided lessons + > make install + // optional (if the documentation is not already available) + > make doc + +To clean everything, simply run + > make clean + + +=================================================================== + DIRECTORY STRUCTURE +=================================================================== +After unpacking the archive file, you should end up with the following +structure: + +.../ The main PARADISEO-GPU directory, created when unpacking. + | + +-- build BUILD directory that contains libraries and executable files. + | + +-- src SOURCE directory Contains most PARADISEO-GPU .h files. + | + +-- doc DOCUMENTATION directory (generated by Doxygen). + | | + | +- html HTML files - start at index.html. + | | + | +- latex latex files - use to generate Postcript doc. + | | + | +- man Unix man format documentation. + | + | + +-- tutorial APPLICATIONS + | + +-- INSTANCES The instances problem directory (QAP instances ...) + | + +-- OneMax How make One max problem with parallel evalution of neighborhood(bit flipping) with hamming distances =1 + | + +-- KswapOneMax How make One max problem with parallel evalution of neighborhood(bit flipping) with hamming distances >=1 + | + +-- PPP_GPU How make Permuted Perceptron Problem with parallel evalution of neighborhood on GPU + | + +-- QAP_GPU How make Quadratic Assignement Problem with parallel evaluation of neighborhood on GPU + | + +-- QAP_CPU How make Quadratic Assignement Problem with sequentiel evaluation of neighborhood on CPU + + +=================================================================== + NOTES +=================================================================== + +Mailing list : paradiseo-help@lists.gforge.inria.fr diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/install.cmake b/branches/ParadisEO-GPU/paradiseo-gpu/install.cmake new file mode 100644 index 000000000..763e0524a --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/install.cmake @@ -0,0 +1,18 @@ +####################################################################################### +### Paths to EO, MO, GPU, MOEO and CUDA must be specified above. +####################################################################################### + +SET(EO_SRC_DIR "${CMAKE_SOURCE_DIR}/../paradiseo-eo" CACHE PATH "ParadisEO-EO source directory" FORCE) +SET(EO_BIN_DIR "${CMAKE_BINARY_DIR}/../../paradiseo-eo/build" CACHE PATH "ParadisEO-EO binary directory" FORCE) + +SET(MO_SRC_DIR "${CMAKE_SOURCE_DIR}/../paradiseo-mo" CACHE PATH "ParadisMO-MO source directory" FORCE) +SET(MO_BIN_DIR "${CMAKE_BINARY_DIR}/../../paradiseo-mo/build" CACHE PATH "ParadisMO-MO binary directory" FORCE) + +SET(GPU_SRC_DIR "${CMAKE_SOURCE_DIR}/../paradiseo-gpu" CACHE PATH "ParadisEO-GPU source directory" FORCE) +SET(GPU_BIN_DIR "${CMAKE_BINARY_DIR}/../../paradiseo-gpu/build" CACHE PATH "ParadisEO-GPU binary directory" FORCE) + +SET(PROBLEMS_SRC_DIR "${CMAKE_SOURCE_DIR}/../problems" CACHE PATH "Problems dependant source directory" FORCE) + +SET(CUDA_DIR "/usr/local/cuda" CACHE PATH "cuda directory" FORCE) + + diff --git a/branches/ParadisEO-GPU/problems/eval/bbRoyalRoadEval.h b/branches/ParadisEO-GPU/problems/eval/bbRoyalRoadEval.h new file mode 100644 index 000000000..9d861f738 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/bbRoyalRoadEval.h @@ -0,0 +1,129 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _bbRoyalRoadEval_h +#define _bbRoyalRoadEval_h + +#include +#include + +/** + * Full evaluation Function for Building-Block Royal Road problem: + * Richard A. Watson & Thomas Jansen, "A building-block royal road where crossover is provably essential", GECCO 07. + */ +template< class EOT > +class BBRoyalRoadEval : public eoEvalFunc +{ +public: + /** + * Default constructor + * @param _b number of blocks + * @param _k size of a block + */ + BBRoyalRoadEval(unsigned int _b, unsigned int _k) : k(_k), b(_b) { } + + /** + * add a target to sub-objective functions + * + * @param target target vector of boolean (of size k) + * @param w weights of this target + */ + void addTarget(vector & target, double w) { + targets.push_back(target); + weights.push_back(w); + } + + /** + * Count the number of complete blocks in the bit string + * @param _sol the solution to evaluate + */ + void operator() (EOT& _solution) { + double sum = 0; + + unsigned int i, j, t; + unsigned int offset; + + // Hamming distance + double d; + + for(i = 0; i < b; i++) { + offset = i * k; + + for(t = 0; t < targets.size(); t++) { + d = 0; + for(j = 0; j < k; j++) + if (_solution[offset + j] != targets[t][j]) + d++; + + if (d == 0) + sum += weights[t]; + else + sum += 1.0 / ( 1.0 + d ); + } + } + + _solution.fitness(sum); + } + + /** + * get the size of a block + * @return block size + */ + unsigned int blockSize() { + return k; + } + + /** + * get the number of blocks + * @return the number of blocks + */ + unsigned int nbBlocks() { + return b; + } + + /** + * get the targets + * @return the vector of targets which is a boolean vector + */ + vector > & getTargets() { + return targets; + } + +private: + // number of blocks + unsigned int b; + + // size of a block + unsigned int k; + + vector > targets; + vector weights; +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/longKPathEval.h b/branches/ParadisEO-GPU/problems/eval/longKPathEval.h new file mode 100644 index 000000000..38cd69705 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/longKPathEval.h @@ -0,0 +1,189 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __longKPathEval_h +#define __longKPathEval_h + +#include + +/** + * Full evaluation function for long k-path problem + */ +template< class EOT > +class LongKPathEval : public eoEvalFunc +{ +private: + // parameter k of the problem + unsigned k; + + // tempory variable if the solution is in the long path + bool inPath; + + /** + * compute the number k j in solution = u1^kO^jw between i and i - k + 1 with |u1^kO^j| = i and k+j <= k + * + * @param solution the solution to evaluate + * @param l last position in the bit string + * @param n0 number of consecutive 0 + * @param n1 number of consecutive 1 + */ + void nbOnesZeros(EOT & solution, unsigned l, unsigned & n0, unsigned & n1) { + n0 = 0; + + unsigned ind = l - 1; + + while (n0 < k && solution[ind - n0] == 0) + n0++; + + n1 = 0; + + ind = ind - n0; + while (n0 + n1 < k && solution[ind - n1] == 1) + n1++; + } + + /** + * true if the solution is the last solution of the path of bitstring length l + * + * @param solution the solution to evaluate + * @param l size of the path, last position in the bit string + * @return true if the solution is the solution of the path + */ + bool final(EOT & solution, unsigned l) { + if (l == 1) + return (solution[0] == 1); + else { + int i = 0; + + while (i < l - k && solution[i] == 0) + i++; + + if (i < l - k) + return false; + else { + while (i < l && solution[i] == 1) + i++; + + return (i == l); + } + } + } + + /** + * position in the long path + * + * @param solution the solution to evaluate + * @param l size of the path, last position in the bit string + * @return position in the path + */ + unsigned rank(EOT & solution, unsigned int l) { + if (l == 1) { // long path l = 1 + inPath = true; + + if (solution[0] == 0) + return 0; + else + return 1; + } else { // long path for l>1 + unsigned n0, n1; + + // read the k last bits, and count the number of last successive 0 follow by the last successive 1 + nbOnesZeros(solution, l, n0, n1); + + if (n0 == k) // first part of the path + return rank(solution, l - k); + else + if (n1 == k) { // last part of the path + return (k+1) * (1 << ((l-1) / k)) - k - rank(solution, l - k); + } else + if (n0 + n1 == k) { + if (final(solution, l - k)) { + inPath = true; + return (k+1) * (1 << ((l-k-1) / k)) - k + n1; + } else { + inPath = false; + return 0; + } + } else { + inPath = false; + return 0; + } + } + } + + /** + * compute the number of zero of the bit string + * + * @param solution the solution to evaluate + * @return number of zero in the bit string + */ + unsigned int nbZero(EOT & solution){ + unsigned int res = 0; + + for(unsigned int i=0; i < solution.size(); i++) + if (solution[i] == 0) + res++; + + return res; + } + +public: + /** + * Default constructor + * + * @param _k parameter k of the long K-path problem + */ + LongKPathEval(unsigned _k) : k(_k) { + }; + + /** + * default destructor + */ + ~LongKPathEval(void) {} ; + + /** + * compute the fitnes of the solution + * + * @param solution the solution to evaluate + * @return fitness of the solution + */ + void operator()(EOT & solution) { + inPath = true; + + unsigned r = rank(solution, solution.size()); + + if (inPath) + solution.fitness(solution.size() + r); + else + solution.fitness(nbZero(solution)); + } + +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/maxSATeval.h b/branches/ParadisEO-GPU/problems/eval/maxSATeval.h new file mode 100644 index 000000000..87a3c4ca6 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/maxSATeval.h @@ -0,0 +1,277 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _maxSATeval_h +#define _maxSATeval_h + +#include +#include + +/** + * Full evaluation Function for max-SAT problem + */ +template< class EOT > +class MaxSATeval : public eoEvalFunc +{ +public: + + /** + * Constructor + * generate a random instance of max k-SAT problem + * + * @param _n number of variables + * @param _m number of clauses + * @param _k of litteral by clause + */ + MaxSATeval(unsigned _n, unsigned _m, unsigned _k) { + nbVar = _n; + nbClauses = _m; + nbLitteral = _k; + + // creation of the clauses + clauses = new std::vector[nbClauses]; + + // the variables are numbered from 1 to nbVar + variables = new std::vector[nbVar + 1]; + + //int var[nbVar]; + std::vector var; + var.resize(nbVar); + unsigned i, j, ind; + + // to selected nbLitteral different variables in the clauses + for(i = 0; i < nbVar; i++) + var[i] = i + 1; + + int number, tmp; + + // generation of the clauses + for(i = 0; i < nbClauses; i++) { + for(j = 0 ; j < nbLitteral; j++) { + // selection of the variable + ind = rng.random(nbVar - j); + number = var[ind]; + + // permutation for forbidd identical variables + tmp = var[ind]; + var[ind] = var[nbVar - j - 1]; + var[nbVar - j - 1] = tmp; + + // litteral = (variable) or (not variable) ? + // negative value means not variable + if (rng.flip()) + number = -number; + + // variable number belong to clause i + if (number < 0) + variables[-number].push_back(-i); + else + variables[number].push_back(i); + + // clause i has got the litteral number + clauses[i].push_back(number); + } + } + + } + + /** + * Constructor + * instance is given in the cnf format (see dimacs) + * + * @param _fileName file name of the instance in cnf format + */ + MaxSATeval(std::string & _fileName) { + std::fstream file(_fileName.c_str(), std::ios::in); + + if (!file) { + std::string str = "MaxSATeval: Could not open file [" + _fileName + "]." ; + throw std::runtime_error(str); + } + + std::string s; + + // commentaries + std::string line; + file >> s; + while (s[0] == 'c') { + getline(file,line,'\n'); + file >> s; + } + + // parameters + if (s[0] != 'p') { + std::string str = "MaxSATeval: could not read the parameters of the instance from file [" + _fileName + "]." ; + throw std::runtime_error(str); + } + file >> s; + if (s != "cnf") { + std::string str = "MaxSATeval: " + _fileName + " is not a file in cnf format."; + throw std::runtime_error(str); + } + + file >> nbVar >> nbClauses; + nbLitteral = 0; // could be different from one clause to antoher, so no value + + // creation of the clauses + clauses = new std::vector[nbClauses]; + + // the variables are numbered from 1 to nbVar + variables = new std::vector[nbVar + 1]; + + // read the clauses + int number; + for(unsigned i = 0; i < nbClauses; i++) { + do { + file >> number; + if (number != 0) { + clauses[i].push_back(number); + if (number < 0) + number = -number; + + if (number < 0) + variables[-number].push_back(-i); + else + variables[number].push_back(i); + } + } while (number != 0); + } + + file.close(); + } + + /** + * Destructor + */ + ~MaxSATeval() { + // delete the clauses + delete[] clauses; + + // delete the variables + delete[] variables; + } + + /** + * export the instance to a file in cnf format + * + * @param _fileName file name to export the instance + */ + void save(std::string & _fileName) { + std::fstream file(_fileName.c_str(), std::ios::out); + + if (!file) { + std::string str = "MaxSATeval: Could not open " + _fileName; + throw std::runtime_error(str); + } + + // write some commentaries + file << "c random max k-SAT generated by maxSATeval from paradisEO framework on sourceForge" << std::endl; + file << "c "<< std::endl; + + // write the parameters + file << "p cnf " << nbVar << " " << nbClauses << std::endl; + + // write the clauses + unsigned int i, j; + + for(i = 0; i < nbClauses; i++) { + j = 0; + while (j < clauses[i].size()) { + file << clauses[i][j] << " "; + j++; + } + file << "0" << std::endl; + } + + file.close(); + } + + /** + * evaluation the clause + * + * @param _n number of the given clause + * @param _solution the solution to evaluation + * @return true when the clause is true + */ + bool clauseEval(unsigned int _n, EOT & _solution) { + unsigned nLitteral = clauses[_n].size(); + int litteral; + + bool clause = false; + + unsigned int j = 0; + while (j < nLitteral && !clause) { + litteral = clauses[_n][j]; + clause = ((litteral > 0) && _solution[litteral - 1]) || ((litteral < 0) && !(_solution[-litteral - 1])); + + j++; + } + + return clause; + } + + /** + * fitness evaluation of the solution + * + * @param _solution the solution to evaluation + */ + virtual void operator()(EOT & _solution) { + unsigned int fit = 0; + + for(unsigned i = 0; i < nbClauses; i++) + if (clauseEval(i, _solution)) + fit++; + + _solution.fitness(fit); + } + + /** + * Public variables (used in incremental evaluation) + */ + + // number of variables + unsigned int nbVar; + // number of clauses + unsigned int nbClauses; + // number of litteral by clause (0 when the instance is read from file) + unsigned int nbLitteral; + + // list of clauses: + // each clause has the number of the variable (from 1 to nbVar) + // when the value is negative, litteral = not(variable) + std::vector * clauses; + + // list of variables: + // for each variable, the list of clauses + // when the value is negative, litteral = not(variable) in this clause + std::vector * variables; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/moPopSolEval.h b/branches/ParadisEO-GPU/problems/eval/moPopSolEval.h new file mode 100644 index 000000000..a393fd0dd --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/moPopSolEval.h @@ -0,0 +1,82 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _moPopSolEval_h +#define _moPopSolEval_h + +#include +#include +#include + +/** + * To compute the fitness of a pop-based solution + */ +template< class EOT > +class moPopSolEval : public eoEvalFunc +{ +public: + typedef typename EOT::SUBEOT SUBEOT; + + /** + * default constructor + * + * @param _eval evaluation function of the solution + * @param _p the exponent of the p-norm to compute the population based fitness + */ + moPopSolEval(eoEvalFunc& _eval, unsigned int _p): eval(_eval), p(_p){} + + /** + * to compute the fitness of a population-based solution + * which is the norm p of the fitness of solutions: ( sigma_{i} f(s_i)^p )^(1/p) + * + * re-compute the fitness of solution which are invalid + * + * @param _sol the population-based solution to evaluate + */ + void operator() (EOT& _sol) { + double fit = 0; + + for (unsigned int i = 0; i < _sol.size(); i++) { + if(_sol[i].invalid()) + eval(_sol[i]); + + fit += pow((double) _sol[i].fitness(), (int) p); + } + + fit = pow((double) fit, (double)1/p); + + _sol.fitness(fit); + } + +private: + eoEvalFunc& eval; + unsigned int p; +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/nkLandscapesEval.h b/branches/ParadisEO-GPU/problems/eval/nkLandscapesEval.h new file mode 100644 index 000000000..29fd20d5f --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/nkLandscapesEval.h @@ -0,0 +1,414 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __nkLandscapesEval_H +#define __nkLandscapesEval_H + +#include + +template< class EOT > +class nkLandscapesEval : public eoEvalFunc { +public: + // parameter N : size of the bit string + unsigned N; + + // parameter K : number of epistatic links + unsigned K; + + // Table of contributions + double ** tables; + + // Links between each bit + // links[i][0], ..., links[i][K] : the (K+1) links to the bit i + unsigned ** links; + + /** + * Empty constructor + */ + nkLandscapesEval() : N(0), K(0) + { + tables = NULL; + links = NULL; + }; + + /** + * Constructor of random instance + * + * @param _N size of the bit string + * @param _K number of the epistatic links + * @param consecutive : if true then the links are consecutive (i, i+1, i+2, ..., i+K), else the links are randomly choose from (1..N) + */ + nkLandscapesEval(int _N, int _K, bool consecutive = false) : N(_N), K(_K) + { + if (consecutive) + consecutiveTables(); + else + randomTables(); + }; + + /** + * Constructor from a file instance + * + * @param _fileName the name of the file of the instance + */ + nkLandscapesEval(const char * _fileName) + { + string fname(_fileName); + load(fname); + }; + + /** + * Default destructor of the table contribution and the links + */ + ~nkLandscapesEval() + { + deleteTables(); + }; + + /** + * Reserve the space memory for the links and the table + */ + void buildTables() + { + links = new unsigned*[N]; + tables = new double*[N]; + + for(unsigned i = 0; i < N; i++) { + tables[i] = new double[1<<(K+1)]; + links[i] = new unsigned[K+1]; + } + }; + + /** + * Free the space memory of the table contributions and the links + */ + void deleteTables() + { + if (links != NULL) { + for(int i = 0; i < N; i++) { + delete [] (links[i]); + } + delete [] links; + links = NULL; + } + + if (tables != NULL) { + for(int i = 0; i < N; i++) { + delete [] (tables[i]); + } + delete [] tables; + tables = NULL; + } + }; + + /** + * Load the instance from a file + * + * @param _fileName file name of the instance + */ + virtual void load(const string _fileName) + { + fstream file; + file.open(_fileName.c_str(), ios::in); + + if (file.is_open()) { + string s; + + // Read the commentairies + string line; + file >> s; + while (s[0] == 'c') { + getline(file,line,'\n'); + file >> s; + } + + // Read the parameters + if (s[0] != 'p') { + string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; + throw runtime_error(str); + } + + file >> s; + if (s != "NK") { + string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ; + throw runtime_error(str); + } + + // read parameters N and K + file >> N >> K; + buildTables(); + + // read the links + if (s[0] != 'p') { + string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ; + throw runtime_error(str); + } + + file >> s; + if (s == "links") { + loadLinks(file); + } else { + string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ; + throw runtime_error(str); + } + + // lecture des tables + if (s[0] != 'p') { + string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; + throw runtime_error(str); + } + + file >> s; + + if (s == "tables") { + loadTables(file); + } else { + string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; + throw runtime_error(str); + } + + file.close(); + } else { + string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw runtime_error(str); + } + + }; + + /** + * Read the links from the file + * + * @param file the file to read + */ + void loadLinks(fstream & file) { + for(int j = 0; j < K+1; j++) + for(int i = 0; i < N; i++) { + file >> links[i][j]; + } + } + + /** + * Read the tables from the file + * + * @param file the file to read + */ + void loadTables(fstream & file) { + for(int j = 0; j < (1<<(K+1)); j++) + for(int i = 0; i < N; i++) + file >> tables[i][j]; + } + + /** + * Save the current intance into a file + * + * @param _fileName the file name of instance + */ + virtual void save(const char * _fileName) { + fstream file; + file.open(_fileName, ios::out); + + if (file.is_open()) { + file << "c name of the file : " << _fileName << endl; + file << "p NK " << N << " " << K <=0; j--) + perm(tabTirage, t[j], N-1-j); + } + + /** + * To generate an instance with no-random links + * + * @param i the bit of contribution + */ + void consecutiveLinks(int i) { + for(int j = 0; j < K+1; j++) { + links[i][j] = (i + j) % N; + } + } + + /** + * To generate a contribution in the table f_i + * + */ + virtual double contribution() { + return rng.uniform(); + } + + /** + * To generate instance with random (without replacement) links + * + */ + virtual void randomTables() { + buildTables(); + + int tabTirage[N]; + initTirage(tabTirage); + + for(int i = 0; i < N; i++) { + // random links to the bit + choose(i, tabTirage); + + // table of contribution with random numbers from [0,1) + for(int j = 0; j < (1<<(K+1)); j++) + tables[i][j] = contribution(); + } + } + + /** + * To generate instance with consecutive links + * + */ + virtual void consecutiveTables() { + buildTables(); + + for(int i = 0; i < N; i++) { + // consecutive link to bit i + consecutiveLinks(i); + + // table of contribution with random numbers from [0,1) + for(int j = 0; j < (1<<(K+1)); j++) + tables[i][j] = contribution(); + } + } + +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/nkpLandscapesEval.h b/branches/ParadisEO-GPU/problems/eval/nkpLandscapesEval.h new file mode 100644 index 000000000..9be4f47e2 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/nkpLandscapesEval.h @@ -0,0 +1,213 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __nkpLandscapesEval_H +#define __nkpLandscapesEval_H + +#include + +/* + * Neutral version of NK landscapes: the 'probabilistic' NK + * see work of L. Barnett "Ruggedness and Neutrality - The NKp family of Fitness Landscapes" (1998) + */ +template< class EOT > +class nkpLandscapesEval : public nkLandscapesEval { +public: + // parameter N : size of the bit string + using nkLandscapesEval::N; + // parameter K : number of epistatic links + using nkLandscapesEval::K; + // Table of contributions + using nkLandscapesEval::tables; + // Links between each bit + using nkLandscapesEval::links; + + using nkLandscapesEval::buildTables; + using nkLandscapesEval::loadLinks; + using nkLandscapesEval::loadTables; + using nkLandscapesEval::consecutiveTables; + using nkLandscapesEval::randomTables; + + // parameter p : probability to have the contribution to zero, otherwise random number from [0,1) + double p; + + /** + * Empty constructor + */ + nkpLandscapesEval() : nkLandscapesEval(), p(0.0) { } + + /** + * Constructor of random instance + * + * @param _N size of the bit string + * @param _K number of the epistatic links + * @param _p probability to have a contribution equals to zero + * @param consecutive : if true then the links are consecutive (i, i+1, i+2, ..., i+K), else the links are randomly choose from (1..N) + */ + nkpLandscapesEval(int _N, int _K, double _p, bool consecutive = false) : nkLandscapesEval() { + N = _N; + K = _K; + p = _p; + + if (consecutive) + consecutiveTables(); + else + randomTables(); + } + + /** + * Constructor from a file instance + * + * @param _fileName the name of the file of the instance + */ + nkpLandscapesEval(const char * _fileName) : nkLandscapesEval(_fileName) { } + + /** + * Load the instance from a file + * + * @param _fileName file name of the instance + */ + virtual void load(const string _fileName) + { + fstream file; + file.open(_fileName.c_str(), ios::in); + + if (file.is_open()) { + string s; + + // Read the commentairies + string line; + file >> s; + while (s[0] == 'c') { + getline(file,line,'\n'); + file >> s; + } + + // Read the parameters + if (s[0] != 'p') { + string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; + throw runtime_error(str); + } + + file >> s; + if (s != "NKp") { + string str = "nkpLandscapesEval.load: -- NKp -- expected in [" + _fileName + "] at the begining." ; + throw runtime_error(str); + } + + // read parameters N, K and p + file >> N >> K >> p; + buildTables(); + + // read the links + if (s[0] != 'p') { + string str = "nkpLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N, K, and p." ; + throw runtime_error(str); + } + + file >> s; + if (s == "links") { + loadLinks(file); + } else { + string str = "nkpLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N, K, and q." ; + throw runtime_error(str); + } + + // lecture des tables + if (s[0] != 'p') { + string str = "nkpLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; + throw runtime_error(str); + } + + file >> s; + + if (s == "tables") { + loadTables(file); + } else { + string str = "nkpLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; + throw runtime_error(str); + } + + file.close(); + } else { + string str = "nkpLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw runtime_error(str); + } + + }; + + /** + * Save the current intance into a file + * + * @param _fileName the file name of instance + */ + virtual void save(const char * _fileName) { + fstream file; + file.open(_fileName, ios::out); + + if (file.is_open()) { + file << "c name of the file : " << _fileName << endl; + file << "p NKp " << N << " " << K << " " << p << endl; + + file << "p links" << endl; + for(int j=0; j +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __nkqLandscapesEval_H +#define __nkqLandscapesEval_H + +#include + +/* + * Neutral version of NK landscapes: the 'quantised' NK + * see work of E. J. Newman, and R. Engelhardt "Effects of Neutral Selection on the Evolution of Molecular Species" (1998) + */ +template< class EOT > +class nkqLandscapesEval : public nkLandscapesEval { +public: + // parameter N : size of the bit string + using nkLandscapesEval::N; + // parameter K : number of epistatic links + using nkLandscapesEval::K; + // Table of contributions + using nkLandscapesEval::tables; + // Links between each bit + using nkLandscapesEval::links; + + using nkLandscapesEval::buildTables; + using nkLandscapesEval::loadLinks; + using nkLandscapesEval::loadTables; + using nkLandscapesEval::consecutiveTables; + using nkLandscapesEval::randomTables; + + // parameter q : number of different integer values in the table: [0..q[ + unsigned q; + + /** + * Empty constructor + */ + nkqLandscapesEval() : nkLandscapesEval(), q(0) { } + + /** + * Constructor of random instance + * + * @param _N size of the bit string + * @param _K number of the epistatic links + * @param consecutive : if true then the links are consecutive (i, i+1, i+2, ..., i+K), else the links are randomly choose from (1..N) + */ + nkqLandscapesEval(unsigned _N, unsigned _K, unsigned _q, bool consecutive = false) : nkLandscapesEval() { + N = _N; + K = _K; + q = _q; + + if (consecutive) + consecutiveTables(); + else + randomTables(); + } + + /** + * Constructor from a file instance + * + * @param _fileName the name of the file of the instance + */ + nkqLandscapesEval(const char * _fileName) : nkLandscapesEval(_fileName) { } + + /** + * Load the instance from a file + * + * @param _fileName file name of the instance + */ + virtual void load(const string _fileName) + { + fstream file; + file.open(_fileName.c_str(), ios::in); + + if (file.is_open()) { + string s; + + // Read the commentairies + string line; + file >> s; + while (s[0] == 'c') { + getline(file,line,'\n'); + file >> s; + } + + // Read the parameters + if (s[0] != 'p') { + string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; + throw runtime_error(str); + } + + file >> s; + if (s != "NKq") { + string str = "nkqLandscapesEval.load: -- NKq -- expected in [" + _fileName + "] at the begining." ; + throw runtime_error(str); + } + + // read parameters N, K and q + file >> N >> K >> q; + buildTables(); + + // read the links + if (s[0] != 'p') { + string str = "nkqLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N, K, and q." ; + throw runtime_error(str); + } + + file >> s; + if (s == "links") { + loadLinks(file); + } else { + string str = "nkqLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N, K, and q." ; + throw runtime_error(str); + } + + // lecture des tables + if (s[0] != 'p') { + string str = "nkqLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; + throw runtime_error(str); + } + + file >> s; + + if (s == "tables") { + loadTables(file); + } else { + string str = "nkqLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; + throw runtime_error(str); + } + + file.close(); + } else { + string str = "nkqLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw runtime_error(str); + } + + }; + + /** + * Save the current intance into a file + * + * @param _fileName the file name of instance + */ + virtual void save(const char * _fileName) { + fstream file; + file.open(_fileName, ios::out); + + if (file.is_open()) { + file << "c name of the file : " << _fileName << endl; + file << "p NKq " << N << " " << K << " " << q << endl; + + file << "p links" << endl; + for(int j=0; j +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _oneMaxEval_h +#define _oneMaxEval_h + +#include + +/** + * Full evaluation Function for OneMax problem + */ +template< class EOT > +class oneMaxEval : public eoEvalFunc +{ +public: + + /** + * Count the number of 1 in a bitString + * @param _sol the solution to evaluate + */ + void operator() (EOT& _sol) { + unsigned int sum = 0; + for (unsigned int i = 0; i < _sol.size(); i++) + sum += _sol[i]; + _sol.fitness(sum); + } +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/oneMaxPopEval.h b/branches/ParadisEO-GPU/problems/eval/oneMaxPopEval.h new file mode 100644 index 000000000..ecd475ee6 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/oneMaxPopEval.h @@ -0,0 +1,63 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _oneMaxPopEval_h +#define _oneMaxPopEval_h + +#include +#include +#include + +template< class EOT > +class oneMaxPopEval : public eoEvalFunc< moPopSol > +{ +public: + + oneMaxPopEval(oneMaxEval& _eval, unsigned int _p): eval(_eval), p(_p){} + /** + * Count the number of 1 in a bitString + * @param _sol the solution to evaluate + */ + void operator() (moPopSol& _sol) { + double fit=0; + for (unsigned int i = 0; i < _sol.size(); i++){ + if(_sol[i].invalid()) + eval(_sol[i]); + fit+=pow((double) _sol[i].fitness(), (int) p); + } + fit=pow((double) fit, (double)1/p); + _sol.fitness(fit); + } + +private: + oneMaxEval& eval; + unsigned int p; +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/qapEval.h b/branches/ParadisEO-GPU/problems/eval/qapEval.h new file mode 100644 index 000000000..0915a8886 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/qapEval.h @@ -0,0 +1,151 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _qapEval_h +#define _qapEval_h + +#include + +/** + * Full evaluation Function for QAP problem + */ +template< class EOT > +class QAPeval : public eoEvalFunc +{ +public: + + /* + * Constructor from instance file + * + * @param _fileData the file name which contains the instance of QAP from QAPlib + */ + QAPeval(string & _fileData) { + fstream file(_fileData.c_str(), ios::in); + + if (!file) { + string str = "QAPeval: Could not open file [" + _fileData + "]." ; + throw runtime_error(str); + } + + unsigned i, j; + + file >> n; + A = new int *[n]; + B = new int *[n]; + + for(i = 0; i < n; i++) { + A[i] = new int[n]; + for(j = 0; j < n; j++) { + file >> A[i][j]; + } + } + + for(i = 0; i < n; i++) { + B[i] = new int[n]; + for(j = 0; j < n; j++) + file >> B[i][j]; + } + + file.close(); + } + + /* + * default destructor + */ + ~QAPeval() { + unsigned i; + + if (A != NULL) { + for(i = 0; i < n; i++) + delete[] A[i]; + delete[] A; + } + + if (B != NULL) { + for(i = 0; i < n; i++) + delete[] B[i]; + delete[] B; + } + } + + /* + * full evaluation for QAP + * + * @param _solution the solution to evaluate + */ + void operator()(EOT & _solution) { + int cost = 0; + + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + cost += A[i][j] * B[_solution[i]][_solution[j]]; + + _solution.fitness(cost); + } + + /* + * to get the matrix A + * + * @return matrix A + */ + int** getA() { + return A; + } + + /* + * to get the matrix B + * + * @return matrix B + */ + int** getB() { + return B; + } + + /* + * to get the number of objects, of variables + * + * @return number of objects + */ + int getNbVar() { + return n; + } + +private: + // number of variables + int n; + + // matrix A + int ** A; + + // matrix B + int ** B; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/queenEval.h b/branches/ParadisEO-GPU/problems/eval/queenEval.h new file mode 100644 index 000000000..da8dd9ee3 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/queenEval.h @@ -0,0 +1,57 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _queenEval_h +#define _queenEval_h + +#include + +/** + * Full evaluation function for QUEEN problem + */ +template< class EOT > +class queenEval : public eoEvalFunc +{ +public: + + /** + * Count number of threat + * @param _queen a solution + */ + void operator()(EOT& _queen){ + unsigned int fit=0; + for(unsigned int i=0; i<_queen.size()-1; i++) + for(unsigned int j=i+1; j< _queen.size(); j++) + if(((unsigned int)_queen[i]+j-i == (unsigned int)_queen[j]) || ((unsigned int)_queen[i]+i-j == (unsigned int)_queen[j])) + fit++; + _queen.fitness(fit); + } +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/royalRoadEval.h b/branches/ParadisEO-GPU/problems/eval/royalRoadEval.h new file mode 100644 index 000000000..8e866cf48 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/royalRoadEval.h @@ -0,0 +1,87 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _RoyalRoadEval_h +#define _RoyalRoadEval_h + +#include + +/** + * Full evaluation Function for Royal Road problem + */ +template< class EOT > +class RoyalRoadEval : public eoEvalFunc +{ +public: + /** + * Default constructor + * @param _k size of a block + */ + RoyalRoadEval(unsigned int _k) : k(_k) {} + + /** + * Count the number of complete blocks in the bit string + * @param _sol the solution to evaluate + */ + void operator() (EOT& _solution) { + unsigned int sum = 0; + unsigned int i, j; + unsigned int offset; + + // number of blocks + unsigned int n = _solution.size() / k; + + for (i = 0; i < n; i++) { + offset = i * k; + + j = 0; + while (j < k && _solution[offset + j]) j++; + + if (j == k) + sum++; + } + + _solution.fitness(sum); + } + + /** + * get the size of a block + * @return block size + */ + unsigned int blockSize() { + return k; + } + +private: + // size of a block + unsigned int k; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/problems/eval/ubqpEval.h b/branches/ParadisEO-GPU/problems/eval/ubqpEval.h new file mode 100644 index 000000000..b2bb4be09 --- /dev/null +++ b/branches/ParadisEO-GPU/problems/eval/ubqpEval.h @@ -0,0 +1,212 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _ubqpEval_h +#define _ubqpEval_h + +#include +#include + +/** + * Full evaluation Function + * for unconstrainted binary quadratic programming problem + */ +template< class EOT > +class UbqpEval : public eoEvalFunc +{ +public: + + /** + * Constructor + * instance is given in the ORLIB format (0) or matrix format (1): + * The format of these data files is: + * number of test problem in the serie + * for each test problem in turn: + * - Format 0: + * number of variables (n), number of non-zero elements in the q(i,j) matrix + * for each non-zero element in turn: + * i, j, q(i,j) {=q(j,i) as the matrix is symmetric} + * - Format 1: + * number of variables (n) + * for each line i + * for each columm j + * q(i,j) + * @param _fileName file name of the instance in ORLIB format + * @param format id of the file format (0 or 1) + * @param _numInstance the number of the given instance to solve + */ + UbqpEval(std::string & _fileName, unsigned format = 0, unsigned int _numInstance = 0) { + std::fstream file(_fileName.c_str(), std::ios::in); + + if (!file) { + std::string str = "UbqpEval: Could not open file [" + _fileName + "]." ; + throw std::runtime_error(str); + } + + unsigned int nbInstances; + file >> nbInstances; + + // number of non zero in the matrix + unsigned int nbNonZero = 0; + + unsigned int i, j; + int v; + + for(unsigned k = 0; k < _numInstance; k++) { + if (format == 0) { + file >> nbVar >> nbNonZero ; + + for(unsigned kk = 0; kk < nbNonZero; kk++) + file >> i >> j >> v; + } else { + file >> nbVar ; + + for(unsigned int i = 0; i < nbVar; i++) { + for(unsigned int j = 0; j < nbVar; j++) { + file >> v; + } + } + } + + } + + // the chosen instance + if (format == 0) + file >> nbVar >> nbNonZero ; + else + file >> nbVar ; + + // creation of the matrix + Q = new int*[nbVar]; + + for(unsigned int i = 0; i < nbVar; i++) { + Q[i] = new int[nbVar]; + for(unsigned int j = 0; j < nbVar; j++) + Q[i][j] = 0; + } + + // read the matrix + if (format == 0) { + for(unsigned int k = 0; k < nbNonZero; k++) { + file >> i >> j >> v; + Q[i][j] = v; + } + } else { + for(unsigned int i = 0; i < nbVar; i++) { + for(unsigned int j = 0; j < nbVar; j++) { + file >> v; + Q[i][j] = v; + } + } + } + + file.close(); + + // put the matrix in lower triangular form + for(unsigned i = 1; i < nbVar; i++) + for(unsigned int j = 0; j < i; j++) { + Q[i][j] = Q[i][j] + Q[j][i]; + Q[j][i] = 0; + } + + } + + /** + * Destructor + */ + ~UbqpEval() { + if (Q != NULL) { + for(unsigned i = 0; i < nbVar; i++) + delete[] Q[i]; + + // delete the matrix + delete[] Q; + } + } + + /** + * fitness evaluation of the solution + * + * @param _solution the solution to evaluation + */ + virtual void operator()(EOT & _solution) { + int fit = 0; + unsigned int j; + + for(unsigned i = 0; i < nbVar; i++) + if (_solution[i] == 1) + for(j = 0; j <= i; j++) + if (_solution[j] == 1) + fit += Q[i][j]; + + _solution.fitness(fit); + } + + /* + * to get the matrix Q + * + * @return matrix Q + */ + int** getQ() { + return Q; + } + + /* + * to get the number of variable (bit string length) + * + * @return bit string length + */ + int getNbVar() { + return nbVar; + } + + void print() { + std::cout << nbVar << std::endl; + for(unsigned int i = 0; i < nbVar; i++) { + for(unsigned int j = 0; j < nbVar; j++) { + std::cout << Q[i][j] << " "; + } + std::cout << std::endl; + } + } + +private: + /** + * variables (used in incremental evaluation) + */ + + // number of variable + unsigned int nbVar; + + // matrix of flux: + // the matrix is put in lower triangular form: for i