Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solver algo #11

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ add_compile_options(-Wall -Wextra -pedantic)
# Clang
#add_compile_options( -Wno-c++98-compat-pedantic -Wno-old-style-cast -Wno-padded -Wno-extra-semi-stmt -Wno-weak-vtables)

add_compile_definitions(-DWITH_CLUTCHLOG)

if(BUILD_FOR_LOCAL)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
endif()
Expand Down
49 changes: 37 additions & 12 deletions app/search.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <iostream>
#include <cstdint>
#include <memory>
#include <map>
#include <iostream>

#include <mo>

Expand All @@ -10,7 +12,6 @@
#include "XorRightShift.hpp"
#include "Multiply.hpp"
#include "AddShift.hpp"
#include "Masking.hpp"
#include "Multiply.hpp"
#include "moCombination.hpp"
#include "moCombinationNeighbor.hpp"
Expand Down Expand Up @@ -71,9 +72,6 @@ void make_domain(eoForgeVector< EvalFull<myuint,Combi>::OpItf >& forge, size_t v

forge.add< AddShift<myuint> >(i, value_size);
CLUTCHLOG(xdebug, "AddShift << " << i);

forge.add< Masking<myuint> >(i);
CLUTCHLOG(xdebug, "Masking & " << i);
}

#ifndef NDEBUG
Expand All @@ -99,19 +97,19 @@ int main(int argc, char* argv[])
/***** Classical arguments *****/

const std::string log_level = argparser.createParam<std::string>("Progress", "log-level",
"Maximum depth level of logging (Critical<Error<Warning<Progress<Note<Info<Debug<XDebug, default=Progress)", 'l', "Logging").value();
"Maximum depth level of logging (Critical<Error<Warning<Progress<Note<Info<Debug<XDebug)", 'l', "Logging").value();

const std::string log_file = argparser.createParam<std::string>(".*", "log-file",
"Regexp indicating which source file is allowed logging (default=all)", 'f', "Logging").value();
"Regexp indicating which source file is allowed logging (use '.*' to allow all)", 'f', "Logging").value();

const std::string log_func = argparser.createParam<std::string>(".*", "log-func",
"Regexp indicating which function is allowed logging (default=all)", 'F', "Logging").value();
"Regexp indicating which function is allowed logging (use '.*' to allow all)", 'F', "Logging").value();

const size_t log_depth = argparser.createParam<size_t>(9999, "log-depth",
"Maximum stack depth above which logging is not allowed (default=no limit)", 'D', "Logging").value();
const size_t log_depth = argparser.createParam<size_t>(std::numeric_limits<size_t>::max(), "log-depth",
"Maximum stack depth above which logging is not allowed (the larger, the more is displayed)", 'D', "Logging").value();

unsigned long long seed = argparser.createParam<long>(0, "seed",
"Seed of the pseudo-random generator (0 = Epoch)", 's', "Parameters").value();
"Seed of the pseudo-random generator (0 = use number of seconds since The Epoch)", 's', "Parameters").value();

/***** Search domain arguments *****/

Expand All @@ -137,7 +135,20 @@ int main(int argc, char* argv[])
"Increment step for multipliers (note: only odd multipliers will be allowed)", 'u', "Search domain").value();
Range mult_range(mult_min, mult_max, mult_step);

make_verbose(argparser);
/***** Search domain arguments *****/

std::map<std::string,std::string> algorithms;
algorithms["HC"] = "Hill-Climbing";
algorithms["SA"] = "Simulated-Annealing";
std::ostringstream msg; msg << " (";
for(auto& kv : algorithms) {
msg << kv.first << ":" << kv.second << ", ";
}
msg << ")";
const std::string algo = argparser.createParam<std::string>("HC", "algo",
"Search metaheuristic"+msg.str(), 'a', "Algorithm").value();

// make_verbose(argparser);
make_help(argparser);

clutchlog_config(); // common config
Expand All @@ -151,6 +162,7 @@ int main(int argc, char* argv[])
if(seed == 0) {
seed = std::time(nullptr); // Epoch
}

CLUTCHLOG(info, "seed = " << seed);
CLUTCHLOG(info, "log-level = " << log_level);
CLUTCHLOG(info, "log-file = " << log_file);
Expand Down Expand Up @@ -201,7 +213,20 @@ int main(int argc, char* argv[])
check.add(best); // Update the best state.

// Hill climber, selecting a random solution among the equal-best ones.
moRandomBestHC<Nb> search(neighborhood, feval, peval, check);
std::unique_ptr< moLocalSearch<Nb> > palgo;
if( algo == "HC" ) {
palgo = std::make_unique< moRandomBestHC<Nb> >(neighborhood, feval, peval, check);
} else if( algo == "SA" ) {
palgo = std::make_unique< moSA<Nb> >(neighborhood, feval, peval, check);
} else {
std::ostringstream msg;
msg << "Unknown algorithm: " << algo << ", valid candidates are";
for( auto& kv : algorithms) {
msg << ", " << kv.first << " (" << kv.second << ")";
}
EXIT_ON_ERROR( Invalid_Argument, msg.str() );
}
moLocalSearch<Nb>& search = *palgo;
CLUTCHLOG(note, "OK");

CLUTCHLOG(progress, "Pick a random solution...");
Expand Down
2 changes: 1 addition & 1 deletion external/clutchlog
Submodule clutchlog updated 216 files
2 changes: 1 addition & 1 deletion external/paradiseo
Loading