Skip to content

Commit

Permalink
Merge pull request #15 from jdreo/solver-init
Browse files Browse the repository at this point in the history
Solver features
  • Loading branch information
yoann-dufresne authored Oct 11, 2024
2 parents 81c43fe + 6b4b5c6 commit 506f35d
Show file tree
Hide file tree
Showing 15 changed files with 712 additions and 266 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ if(USE_LOCAL_PARADISEO)
include_directories(${PARADISEO_ROOT}/eo/src)
include_directories(${PARADISEO_ROOT}/mo/src)
include_directories(${PARADISEO_ROOT}/moeo/src)
include_directories(${PARADISEO_ROOT}/edo/src)
# FIXME supposed to be set by Paradiseo, but failed to propagate here.
find_package(Eigen3)
if(EIGEN3_FOUND)
include_directories( ${EIGEN3_INCLUDE_DIR} )
add_compile_definitions( WITH_EIGEN )
else()
message(FATAL_ERROR "\n\nERROR: Eigen3 must be installed, e.g. `sudo apt install libeigen3-dev`.\n" )
endif()

link_directories(${PARADISEO_BUILD}/lib)
else()
include_directories($ENV{PARADISEO_ROOT}/include/paradiseo/eo)
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,42 @@ To run the tests, use the following commands:
mkdir -p build && cd build && cmake -CMAKE_BUILD_TYPE=Debug .. && make && make test
```


## Command Line Interface

The `search` executable is the main interface to run the optimization solver.
It takes options of the form `--long[=<value>]` or `-s[=<value>]`.
The equal sign is mandatory, spaces between option flag and value are not supported.
A file holding a set of options can be passed using `@<filename>`.
Running the executable once produces a `search.status` file with the last setup,
and be called backed using, e.g.: `./search @search.status`.

It allows running:

- a mono-objective hill-climbing, with `--algo=HC` (the default),
- a mono-objective simulated annealing, with `--algo=SA`,
- a bi-objective evolutionary algorithm, with `--algo=NSGA2`.

Solution are encoded as a vector of indices toward a set of pre-determined
parametrized hash function operators.
The parameters domain can be set with `--shift-*` and `--mult-*` options.

One can pass an initial solution to HC and SA algorithms by using standard
input, for example:
```sh
echo "0 3 1 2 3 101" | ./search --func-len=3 --init-sol=1
```
will initialize the first solution with `𓉘r2𐙤a2𐙤l3𐙤m31𓉝`
(`m31` being added automatically to complete the forward hash).

The solution encoding reads as:
```
┌ Fitness (here a mono-objective one)
│ ┌ func-len
│ │ ┌ Operators indices
│ │ ┌─┴─┐ ┌ Total number of operators (i.e. past-the-max index)
0 3 1 2 3 101
```
Beware that you are responsible for aligning `--func-len` and the size of the
encoded solution.

22 changes: 11 additions & 11 deletions app/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ int main()
// Evaluates the hash function
// SoftAvalancheTest<myuint> soft_test{hashFunc};
// CLUTCHLOG(progress, "Run SoftAvalancheTest");
// CLUTCHLOG(note, " 1 000 000 iterations:\t" << soft_test.run(value_size * 1000000UL));
// CLUTCHLOG(note, " 10 000 000 iterations:\t" << soft_test.run(value_size * 10000000UL));
// CLUTCHLOG(note, " 100 000 000 iterations:\t" << soft_test.run(value_size * 100000000UL));
// CLUTCHLOG(note, "1 000 000 000 iterations:\t" << soft_test.run(value_size * 1000000000UL));
// CLUTCHLOG(note, " 1 000 000 iterations:\t" << soft_test(hashFunc, value_size * 1000000UL));
// CLUTCHLOG(note, " 10 000 000 iterations:\t" << soft_test(hashFunc, value_size * 10000000UL));
// CLUTCHLOG(note, " 100 000 000 iterations:\t" << soft_test(hashFunc, value_size * 100000000UL));
// CLUTCHLOG(note, "1 000 000 000 iterations:\t" << soft_test(hashFunc, value_size * 1000000000UL));

StrictAvalancheTest<myuint> strict_test{hashFunc};
StrictAvalancheTest<myuint> strict_test{hashFunc.get_value_size()};
CLUTCHLOG(progress, "Run SoftAvalancheTest");
for (size_t i = 0; i < 20; i++)
{
CLUTCHLOG(note, " 10 000 iterations:\t" << strict_test.run(value_size * 10000UL));
CLUTCHLOG(note, " 10 000 iterations:\t" << strict_test(hashFunc, value_size * 10000UL));
}
std::cout << std::endl;
for (size_t i = 0; i < 20; i++)
{
CLUTCHLOG(note, " 100 000 iterations:\t" << strict_test.run(value_size * 100000UL));
CLUTCHLOG(note, " 100 000 iterations:\t" << strict_test(hashFunc, value_size * 100000UL));
}
std::cout << std::endl;
std::cout << std::endl;
for (size_t i = 0; i < 20; i++)
{
CLUTCHLOG(note, " 1 000 000 iterations:\t" << strict_test.run(value_size * 1000000UL));
CLUTCHLOG(note, " 1 000 000 iterations:\t" << strict_test(hashFunc, value_size * 1000000UL));
}
CLUTCHLOG(note, "100 000 000 iterations:\t" << strict_test.run(value_size * 100000000UL));
CLUTCHLOG(note, "100 000 000 iterations:\t" << strict_test(hashFunc, value_size * 100000000UL));

CLUTCHLOG(note, "Invert");
// Get the inverse function
Expand All @@ -96,7 +96,7 @@ int main()
using Min = eoMinimizingFitness;
using Combi = moCombination<Min>;

eoForgeVector< EvalFull<myuint,Combi>::OpItf > forge(/*always_reinstantiate*/true);
eoForgeVector< combi::EvalFull<myuint,Combi>::OpItf > forge(/*always_reinstantiate*/true);
forge.add< Multiply <myuint> >( 9, value_size);
forge.add< XorLeftShift <myuint> >(17, value_size);
forge.add< XorLeftShift <myuint> >( 5, value_size);
Expand All @@ -119,7 +119,7 @@ int main()
CLUTCHLOG(debug, "Solution: " << sol);

CLUTCHLOG(note, "Evaluate");
EvalFull<myuint,Combi> eval(value_size, forge);
combi::EvalFull<myuint,Combi> eval(value_size, forge, strict_test);

eval(sol);

Expand Down
Loading

0 comments on commit 506f35d

Please sign in to comment.