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 multiobjective #13

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b7c0732
feat(solver): adds moCombination
jdreo Aug 21, 2024
9b8f940
feat(solver): adds moCombinationNeighbor
jdreo Aug 22, 2024
9a8e6ee
feat(solver): adds moCombinationNeighborhood
jdreo Aug 22, 2024
813baf9
FIX!(HashFunction): use shared_ptr instead of unique_ptr
jdreo Aug 22, 2024
519ddcd
fix(XorRightShift): copy construct from existing member
jdreo Aug 22, 2024
6859414
feat(solver): add EvalFunc and EvalTest
jdreo Aug 22, 2024
1c2fc90
feat(solver): add a search app PoC
jdreo Aug 22, 2024
acaeed9
Merge pull request #4 from jdreo/solver
yoann-dufresne Sep 2, 2024
e55a3d4
feat(cmake): add Paradiseo and clutchlog as submodules
jdreo Sep 4, 2024
c28142f
feat(search): make_domain
jdreo Sep 4, 2024
ac2281d
feat(search): CLI arguments
jdreo Sep 4, 2024
ebc2d19
update(paradiseo)
jdreo Sep 5, 2024
a243abf
REFACTOR!(Operators): adds Operator::to_short
jdreo Sep 5, 2024
a069fed
refactor(Multiplier): use value_size for consistency
jdreo Sep 5, 2024
64291d3
fix(HashFunction): add explicit copy constructor and assignememt
jdreo Sep 5, 2024
d605fa4
refactor(EvalFunc): adds a separate function for making the hash func…
jdreo Sep 5, 2024
ac00029
fix(moCombinationNeighbor): adds explicit calls to virtual base classes
jdreo Sep 5, 2024
b2e3abd
feat(search): make use of lasts patches
jdreo Sep 5, 2024
b0f5592
Merge pull request #5 from jdreo/dev
yoann-dufresne Sep 9, 2024
56d93b9
Merge pull request #7 from jdreo/solver-domain
yoann-dufresne Sep 9, 2024
65b67d5
:bug: paradiseao update
yoann-dufresne Sep 9, 2024
550d612
Merge branch 'dev' of github.com:yoann-dufresne/rHashGen into dev
yoann-dufresne Sep 9, 2024
abe42a4
feat(github): add build/test workflow
jdreo Sep 11, 2024
8b72f1d
feat(github): add build/test workflow
jdreo Sep 11, 2024
0bd2ffa
fix(cmake): remove useless definition
jdreo Sep 10, 2024
94f210d
update(external): latest clutchlog (fix) and paradiseo (feat)
jdreo Sep 10, 2024
6b925f8
fix(search): remove EO's verbose conf + better help doc
jdreo Sep 21, 2024
b657bb5
feat(search): choose between HC or SA algo
jdreo Sep 21, 2024
6521692
fix(search): remove Masking from the search domain
jdreo Sep 21, 2024
afddc13
fix(search): raise an error if unknown algo
jdreo Sep 22, 2024
6093d44
refactor(moCombination): inherit from eoInt
jdreo Sep 26, 2024
1ee7dc4
feat(moeo): adds EvalMO
jdreo Sep 27, 2024
febf0bf
feat(search): adds a multi-objective algo
jdreo Sep 27, 2024
0d9b719
feat(search): pretty print output
jdreo Sep 27, 2024
88acaed
doc: adds missing comments & update README
jdreo Sep 27, 2024
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
49 changes: 49 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build Debug (Ubuntu)
on: [push, pull_request]

env:
# CMake build types: Release, Debug, RelWithDebInfo
BUILD_TYPE: Debug

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
strategy:
matrix:
compiler:
- g++-10
- g++-11
- g++-12
- g++-13
- clang-13
- clang-14
- clang-15
- clang-16
- clang-17
os:
- macos-latest
- ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Configure
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "external/googletest"]
path = external/googletest
url = https://github.com/google/googletest.git
[submodule "external/paradiseo"]
path = external/paradiseo
url = https://github.com/nojhan/paradiseo.git
[submodule "external/clutchlog"]
path = external/clutchlog
url = https://github.com/nojhan/clutchlog.git
65 changes: 61 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,88 @@ project(rHashGen)

# Set the C++ standard to use
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


######################################################################################
# Configurable user settings
######################################################################################

# Compilation options
option(BUILD_DOCS "Enable building of documentation" OFF)
option(BUILD_TESTING "Enable building of tests" OFF)
option(BUILD_FOR_LOCAL "Whether to make the executables dependant on the environment of the building computer (enables CMake's build with RPATH), may be necessary on HPC clusters" OFF)
option(USE_LOCAL_PARADISEO "Use a local version of Paradiseo rather than the one installed on the system" ON)

# Common
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)

if(BUILD_FOR_LOCAL)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
endif()


######################################################################################
# Dependencies
######################################################################################

# Own lib
include_directories(include)

# ParadisEO
if(USE_LOCAL_PARADISEO)
set(PARADISEO_ROOT "${PROJECT_SOURCE_DIR}/external/paradiseo" CACHE PATH "Where to find ParadisEO")
set(PARADISEO_BUILD "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "Build dir of ParadisEO")

include_directories(${PARADISEO_ROOT})
include_directories(${PARADISEO_ROOT}/eo/src)
include_directories(${PARADISEO_ROOT}/mo/src)
include_directories(${PARADISEO_ROOT}/moeo/src)
link_directories(${PARADISEO_BUILD}/lib)
else()
include_directories($ENV{PARADISEO_ROOT}/include/paradiseo/eo)
include_directories($ENV{PARADISEO_ROOT}/include/paradiseo/mo)
link_directories($ENV{PARADISEO_ROOT}/lib64)
endif()
set(PARADISEO_LIBRARIES eoutils eo)

# Single-header dependencies.
include_directories(external/clutchlog)

# Include the src directory
include_directories(${PROJECT_SOURCE_DIR}/src/include)


######################################################################################
# Start building
######################################################################################

# Add subdirectories
add_subdirectory(src)

# Google Test
add_subdirectory(external/googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

# ParadisEO
add_subdirectory(external/paradiseo)


# Find all main files in the app directory
file(GLOB APP_SOURCES ${PROJECT_SOURCE_DIR}/app/*.cpp)

# For each main file, create an executable
foreach(APP_SOURCE ${APP_SOURCES})
# Get the file name without the extension
get_filename_component(APP_NAME ${APP_SOURCE} NAME_WE)

# Add the executable
add_executable(${APP_NAME} ${APP_SOURCE})

# Link the necessary libraries
target_link_libraries(${APP_NAME} PRIVATE rHashGenLib)
target_link_libraries(${APP_NAME} PRIVATE rHashGenLib ${PARADISEO_LIBRARIES})
endforeach()

# Add the test directory
Expand Down
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,17 @@ git clone --recursive https://github.com/username/repo.git && cd repo
mkdir build && cd build
# Configure the build using CMake
cmake ..
# Compile an example binary
make example
# Compile the unit tests
make rHashGen-tests
# Compile the solver
make search
# See how to run the solver
./search --help
```

## Running the Binaries
## Run tests

To run the example and test binaries, use the following commands:
To run the tests, use the following commands:

```bash
# Run the example binary
./example

# Run the test binary
make test
mkdir -p build && cd build && cmake -CMAKE_BUILD_TYPE=Debug .. && make && make test
```


56 changes: 52 additions & 4 deletions app/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@
#include "AddShift.hpp"
#include "Masking.hpp"
#include "Multiply.hpp"
#include "moCombination.hpp"
#include "moCombinationNeighbor.hpp"
#include "moCombinationNeighborhood.hpp"
#include "EvalFunc.hpp"
#include "log.h"


int main()
{
CLUTCHLOG(progress, "Set config");
clutchlog_config(); // common config
auto& log = clutchlog::logger();
log.threshold("XDebug");

// The size of the values to manipulate is 57 bits.
size_t value_size{31};
using myuint = uint32_t;

CLUTCHLOG(progress, "Try HashFunc");
// Create an instance of HashFunction with a value size of 64 bits
HashFunction<myuint> hashFunc("hash", value_size);
HashFunction<myuint> hashFunc(value_size, "hash");

// Add shift operators
hashFunc.add_operator(std::make_unique<Multiply<myuint>>(9, value_size));
Expand All @@ -29,27 +40,64 @@ int main()
hashFunc.add_operator(std::make_unique<XorRightShift<myuint>>(3, value_size));
hashFunc.add_operator(std::make_unique<Multiply<myuint>>(9, value_size));

CLUTCHLOG(note, "Complete with masks");
// Complete with masks if necessary
hashFunc.complete_with_masks();

// Print the string representation of the hash function
std::cout << hashFunc.to_string() << std::endl;

CLUTCHLOG(note, "Invert");
// Get the inverse function
HashFunction<myuint> revHashFunc{hashFunc.invert()};

// Print the string representation of the inverted hash function
std::cout << "Inverted function:" << std::endl;
std::cout << revHashFunc.to_string() << std::endl;

CLUTCHLOG(progress, "Apply HashFunc");
// Apply the hash function to a value
myuint value {0xDADBEEF};
myuint hashed {hashFunc.apply(value)};
std::cout << hashFunc.get_name() << "(0x" << std::hex << value << ") = 0x" << hashed << std::endl;

// Apply the inverse function to the hashed value
myuint recovered {revHashFunc.apply(hashed)};
std::cout << revHashFunc.get_name() << "(0x" << std::hex << hashed << ") = 0x" << recovered << std::dec << std::endl;

CLUTCHLOG(progress, "Try solver");
using Min = eoMinimizingFitness;
using Combi = moCombination<Min>;

eoForgeVector< 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);
forge.add< AddShift <myuint> >(19, value_size);
forge.add< XorRightShift<myuint> >( 3, value_size);
forge.add< Multiply <myuint> >( 9, value_size);

CLUTCHLOG(note, "Try solutions");
Combi sol({0,1,2}, forge.size());
CLUTCHLOG(debug, "Solution: " << sol);

CLUTCHLOG(note, "Next in neighborhood");
moCombinationNeighbor<Combi> neighb;
moCombinationNeighborhood<Combi> hood;
hood.init(sol, neighb);
hood.next(sol, neighb);
CLUTCHLOG(debug, "Neighbor: " << neighb);

neighb.move(sol);
CLUTCHLOG(debug, "Solution: " << sol);

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

eval(sol);

CLUTCHLOG(progress, "Final solution:");
std::cout << sol << std::endl;

return 0;
}
}
Loading
Loading