Skip to content

Commit

Permalink
Feature/switch to cmake (#1)
Browse files Browse the repository at this point in the history
* Switch to CMake

* Add build.yml
  • Loading branch information
fontanf committed Jul 14, 2024
1 parent 75653cf commit 5c126e4
Show file tree
Hide file tree
Showing 74 changed files with 409 additions and 960 deletions.
15 changes: 0 additions & 15 deletions .bazelrc

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build

on: [push]

jobs:

build:

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-latest]
python-version: ["3.8"]

env:
GENERALIZED_ASSIGNMENT_DATA: ${{ github.workspace }}/data/

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install nauty
run: sudo apt-get install -y libnauty2-dev
if: matrix.os == 'ubuntu-latest'
- name: Install CLP (MacOS)
run: |
brew install clp
brew install cbc
if: ${{ (matrix.os == 'macos-13') || (matrix.os == 'macos-latest') }}
- name: Build
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
- name: Run tests
run: python3 -u scripts/run_tests.py test_results
- name: Checkout main branch
run: |
git remote set-branches origin '*'
git fetch --depth 1
git checkout master
- name: Build
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
- name: Run tests
run: python3 -u scripts/run_tests.py test_results_ref
- name: Process tests
run: python3 -u ./build/_deps/optimizationtools-src/scripts/process_tests.py --ref test_results_ref --new test_results
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.15.0)

project(GeneralizedAssignmentSolver LANGUAGES CXX)

option(GENERALIZEDASSIGNMENTSOLVER_USE_CBC "Use CBC" ON)
option(GENERALIZEDASSIGNMENTSOLVER_USE_GUROBI "Use Gurobi" OFF)
option(GENERALIZEDASSIGNMENTSOLVER_USE_CPLEX "Use CPLEX" OFF)
option(GENERALIZEDASSIGNMENTSOLVER_USE_KNITRO "Use Knitro" OFF)

# Avoid FetchContent warning.
cmake_policy(SET CMP0135 NEW)

# Require C++14.
set(CMAKE_CXX_STANDARD 14)

# Enable output of compile commands during generation.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set MSVC_RUNTIME_LIBRARY.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# Add sub-directories.
add_subdirectory(extern)
add_subdirectory(src)
add_subdirectory(test)
70 changes: 5 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,16 @@ It is possible to solve the variant where not all items have to be assigned by a

## Usage (command line)

The only required dependency is Boost:
```shell
sudo apt-get install libboost-all-dev
```

Compile:
```shell
bazel build -- //...
```

However, most algorithms require additional libraries (see below).
Compile with additional libraries (or just uncomment the corresponding lines in `.bazelrc`):
```shell
bazel build \
--define coinor=true \
--define cplex=true \
--define gurobi=true \
--define gecode=true \
--define dlib=true \
--define localsolver=true \
--define knitro=true \
-- //...
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
```

Solve:
```shell
./bazel-bin/generalizedassignmentsolver/main --verbosity-level 1 --algorithm mthg --desirability "-pij/wij" --input "data/chu1997/a05100" --output "a05100_output.json" --certificate "a05100_solution.txt"
./install/bin/generalizedassignmentsolver --verbosity-level 1 --algorithm mthg --desirability "-pij/wij" --input "data/chu1997/a05100" --output "a05100_output.json" --certificate "a05100_solution.txt"
```
```
=====================================
Expand Down Expand Up @@ -141,50 +124,7 @@ Feasible: 1
Cost: 1713
```

Unit tests:
```shell
bazel test --compilation_mode=dbg -- //...
```

Checker:
```shell
./bazel-bin/generalizedassignmentsolver/checker data/chu1997/a05100 a05100_solution.txt
```

Run benchmarks:
```shell
python3 ../optimizationtools/optimizationtools/bench_run.py --algorithms "mthg -f cij" "mthg -f wij" "mthg -f cij*wij" "mthg -f -pij/wij" "mthg -f wij/ti" "mthg-regret -f cij" "mthg-regret -f wij" "mthg-regret -f cij*wij" "mthg-regret -f -pij/wij" "mthg-regret -f wij/ti" "random"
python3 ../optimizationtools/optimizationtools/bench_process.py --benchmark heuristicshort --labels "mthg -f cij" "mthg -f wij" "mthg -f cij*wij" "mthg -f -pij/wij" "mthg -f wij/ti" "mthg-regret -f cij" "mthg-regret -f wij" "mthg-regret -f cij*wij" "mthg-regret -f -pij/wij" "mthg-regret -f wij/ti" "random" --timelimit 0.1
```

![heuristicshort](img/heuristicshort.png?raw=true "heuristicshort")

## Optional dependencies

To enable a dependency, uncomment the corresponding line in the `.bazelrc` file and adapt its path in the `WORKSPACEi` file.

Here are some notes for their installations:

### COIN-OR (CLP, CBC, VOL, DIP)

Automatically installed through Bazel.

### Gecode

Download latest version: download https://www.gecode.org/download.html

Compile (more info https://www.gecode.org/doc/2.2.0/reference/PageComp.html):
```shell
./configure
make
./install/bin/generalizedassignmentsolver_checker data/chu1997/a05100 a05100_solution.txt
```

### Gurobi

After installing, execute the following commands:
```shell
cd ${GUROBI_HOME}/linux64/src/build/
make
cp libgurobi_c++.a ../../lib/
```

Loading

0 comments on commit 5c126e4

Please sign in to comment.