Skip to content

Commit e99745b

Browse files
committed
Update MILP models
1 parent 3c374c7 commit e99745b

File tree

20 files changed

+1038
-976
lines changed

20 files changed

+1038
-976
lines changed

CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ cmake_minimum_required(VERSION 3.28)
22

33
project(StableSolver LANGUAGES CXX)
44

5-
option(STABLESOLVER_USE_CBC "Use CPLEX" ON)
6-
option(STABLESOLVER_USE_CPLEX "Use CPLEX" OFF)
5+
option(STABLESOLVER_BUILD_MAIN "Build main" ON)
6+
option(STABLESOLVER_BUILD_TEST "Build the unit tests" ON)
7+
8+
option(STABLESOLVER_USE_CBC "Use Cbc" OFF)
9+
option(STABLESOLVER_USE_HIGHS "Use HiGHS" ON)
10+
option(STABLESOLVER_USE_XPRESS "Use FICO Xpress" OFF)
711

812
# Avoid FetchContent warning.
913
cmake_policy(SET CMP0135 NEW)
1014

11-
# Require C++11.
12-
set(CMAKE_CXX_STANDARD 11)
15+
# Require C++14.
16+
set(CMAKE_CXX_STANDARD 14)
1317

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

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The stable solver can also be used to solve the Minimum (Weight) Vertex Cover Pr
2121
- `-a greedy-strong`
2222

2323
- Mixed-Integer Linear Programs
24-
- Model 1, `|E|` constraints `-a milp-1-cbc` (Cbc) `-a milp-1-cplex` (CPLEX)
25-
- Model 2, `|V|` constraints, see "A multi-KP modeling for the maximum-clique problem" (Della Croce et Tadei, 1994) [DOI](https://doi.org/10.1016/0377-2217(94)90252-6) `-a milp-2-cplex` (CPLEX)
26-
- Model 3, clique constraints, see "A Branch-and-Bound Algorithm for the Knapsack Problem with Conflict Graph" (Bettinelli et al., 2017) [DOI](https://doi.org/10.1287/ijoc.2016.0742) (seems useless since solvers already detect and merge clique constraints) `-a milp-3-cplex` (CPLEX)
24+
- Model 1, `|E|` constraints `-a milp-1`
25+
- Model 2, `|V|` constraints, see "A multi-KP modeling for the maximum-clique problem" (Della Croce et Tadei, 1994) [DOI](https://doi.org/10.1016/0377-2217(94)90252-6) `-a milp-2`
26+
- Model 3, clique constraints, see "A Branch-and-Bound Algorithm for the Knapsack Problem with Conflict Graph" (Bettinelli et al., 2017) [DOI](https://doi.org/10.1287/ijoc.2016.0742) (seems useless since solvers already detect and merge clique constraints) `-a milp-3`
2727

2828
- Local search algorithm implemented with [fontanf/localsearchsolver](https://github.com/fontanf/localsearchsolver) `-a "local-search --threads 3"`
2929

@@ -39,7 +39,7 @@ The stable solver can also be used to solve the Minimum (Weight) Vertex Cover Pr
3939
- `-a greedy-gwmin`, adapted from the stable version, same complexity
4040
- `-a greedy-strong`
4141

42-
- Mixed-Integer Linear Program (implemented with CPLEX), see "Worst-case analysis of clique MIPs" (Naderi et al., 2021) [DOI](https://doi.org/10.1007/s10107-021-01706-2) `-a milp-cplex`
42+
- Mixed-Integer Linear Program from "Worst-case analysis of clique MIPs" (Naderi et al., 2021) [DOI](https://doi.org/10.1007/s10107-021-01706-2) `-a milp`
4343

4444
- Local search algorithm implemented with [fontanf/localsearchsolver](https://github.com/fontanf/localsearchsolver) `-a "local-search"`
4545

@@ -55,9 +55,11 @@ cmake --build build --config Release --parallel
5555
cmake --install build --config Release --prefix install
5656
```
5757

58-
To enable algorithms using CPLEX, replace the first step by:
59-
```
60-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTABLESOLVER_USE_CBC=OFF -DSTABLESOLVER_USE_CPLEX=ON
58+
Setup Python environment to use the Python scripts:
59+
```shell
60+
python3 -m venv .venv
61+
source .venv/bin/activate
62+
pip install -r requirements.txt
6163
```
6264

6365
Download data:

extern/CMakeLists.txt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,48 @@ FetchContent_Declare(
1111
EXCLUDE_FROM_ALL)
1212
FetchContent_MakeAvailable(Boost)
1313

14+
# Fetch googletest.
15+
if(STABLESOLVER_BUILD_TEST)
16+
FetchContent_Declare(
17+
googletest
18+
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip)
19+
# For Windows: Prevent overriding the parent project's compiler/linker settings
20+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
21+
set(INSTALL_GTEST OFF)
22+
FetchContent_MakeAvailable(googletest)
23+
endif()
24+
1425
# Fetch fontanf/optimizationtools.
26+
set(OPTIMIZATIONTOOLS_BUILD_TEST OFF)
1527
FetchContent_Declare(
1628
optimizationtools
1729
GIT_REPOSITORY https://github.com/fontanf/optimizationtools.git
18-
GIT_TAG 65c8e11224aac1cf6e6e33c040b6b895341ad156
19-
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../optimizationtools/"
20-
EXCLUDE_FROM_ALL)
30+
GIT_TAG e086ec4cfcc9a885cd63f579a99ea5e8f4737005)
31+
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../optimizationtools/")
2132
FetchContent_MakeAvailable(optimizationtools)
2233

23-
# Fetch fontanf/localsearchsolver.
24-
FetchContent_Declare(
25-
localsearchsolver
26-
GIT_REPOSITORY https://github.com/fontanf/localsearchsolver.git
27-
GIT_TAG f7110fdd15fa1b9001006bfbf7a8ab53f925016d
28-
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../localsearchsolver/"
29-
EXCLUDE_FROM_ALL)
30-
FetchContent_MakeAvailable(localsearchsolver)
31-
3234
# Fetch fontanf/mathoptsolverscmake.
33-
if(STABLESOLVER_USE_CBC)
34-
set(MATHOPTSOLVERSCMAKE_USE_CBC ON)
35+
set(MATHOPTSOLVERSCMAKE_USE_CLP ON)
36+
set(MATHOPTSOLVERSCMAKE_USE_CBC ON)
37+
if(STABLESOLVER_USE_HIGHS)
38+
set(MATHOPTSOLVERSCMAKE_USE_HIGHS ON)
3539
endif()
36-
if(STABLESOLVER_USE_CPLEX)
37-
set(MATHOPTSOLVERSCMAKE_USE_CPLEX ON)
40+
if(STABLESOLVER_USE_XPRESS)
41+
set(MATHOPTSOLVERSCMAKE_USE_XPRESS ON)
3842
endif()
3943
FetchContent_Declare(
4044
mathoptsolverscmake
4145
GIT_REPOSITORY https://github.com/fontanf/mathoptsolverscmake.git
42-
GIT_TAG 4472814a28a40f4d861ccd757e140835c3a31bd0
46+
GIT_TAG 59fd908038906df649e121f42652a0e8f99cbc67
4347
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../mathoptsolverscmake/"
4448
EXCLUDE_FROM_ALL)
4549
FetchContent_MakeAvailable(mathoptsolverscmake)
50+
51+
# Fetch fontanf/localsearchsolver.
52+
FetchContent_Declare(
53+
localsearchsolver
54+
GIT_REPOSITORY https://github.com/fontanf/localsearchsolver.git
55+
GIT_TAG f7110fdd15fa1b9001006bfbf7a8ab53f925016d
56+
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../localsearchsolver/"
57+
EXCLUDE_FROM_ALL)
58+
FetchContent_MakeAvailable(localsearchsolver)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include "stablesolver/clique/solution.hpp"
4+
5+
#include "mathoptsolverscmake/milp.hpp"
6+
7+
namespace stablesolver
8+
{
9+
namespace clique
10+
{
11+
12+
struct MilpParameters: Parameters
13+
{
14+
mathoptsolverscmake::SolverName solver = mathoptsolverscmake::SolverName::Highs;
15+
16+
17+
virtual int format_width() const override { return 37; }
18+
19+
virtual void format(std::ostream& os) const override
20+
{
21+
Parameters::format(os);
22+
int width = format_width();
23+
os
24+
<< std::setw(width) << std::left << "Solver: " << solver << std::endl
25+
;
26+
}
27+
28+
virtual nlohmann::json to_json() const override
29+
{
30+
nlohmann::json json = Parameters::to_json();
31+
json.merge_patch({
32+
//{"Solver", solver},
33+
});
34+
return json;
35+
}
36+
};
37+
38+
const Output milp(
39+
const Instance& instance,
40+
const MilpParameters& parameters = {});
41+
42+
}
43+
}

include/stablesolver/clique/algorithms/milp_cplex.hpp

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
#include "stablesolver/stable/algorithm.hpp"
4+
5+
#include "mathoptsolverscmake/milp.hpp"
6+
7+
namespace stablesolver
8+
{
9+
namespace stable
10+
{
11+
12+
struct MilpParameters: Parameters
13+
{
14+
mathoptsolverscmake::SolverName solver = mathoptsolverscmake::SolverName::Highs;
15+
16+
17+
virtual int format_width() const override { return 37; }
18+
19+
virtual void format(std::ostream& os) const override
20+
{
21+
Parameters::format(os);
22+
int width = format_width();
23+
os
24+
<< std::setw(width) << std::left << "Solver: " << solver << std::endl
25+
;
26+
}
27+
28+
virtual nlohmann::json to_json() const override
29+
{
30+
nlohmann::json json = Parameters::to_json();
31+
json.merge_patch({
32+
//{"Solver", solver},
33+
});
34+
return json;
35+
}
36+
};
37+
38+
const Output milp_1(
39+
const Instance& instance,
40+
const MilpParameters& parameters = {});
41+
42+
const Output milp_2(
43+
const Instance& instance,
44+
const MilpParameters& parameters = {});
45+
46+
const Output milp_3(
47+
const Instance& instance,
48+
const MilpParameters& parameters = {});
49+
50+
}
51+
}

include/stablesolver/stable/algorithms/milp_cbc.hpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

include/stablesolver/stable/algorithms/milp_cplex.hpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
gdown
2+
py7zr
3+
numpy
4+
plotly
5+
matplotlib
6+
streamlit

src/clique/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ target_sources(StableSolver_clique_main PRIVATE
1818
main.cpp)
1919
target_link_libraries(StableSolver_clique_main PUBLIC
2020
StableSolver_clique_greedy
21+
StableSolver_clique_milp
2122
StableSolver_clique_local_search
2223
Boost::program_options)
23-
if(STABLESOLVER_USE_CPLEX)
24-
target_compile_definitions(StableSolver_clique_main PUBLIC
25-
CPLEX_FOUND=1)
26-
target_link_libraries(StableSolver_clique_main PUBLIC
27-
StableSolver_clique_milp_cplex)
28-
endif()
2924
set_target_properties(StableSolver_clique_main PROPERTIES OUTPUT_NAME "stablesolver_clique")
3025
install(TARGETS StableSolver_clique_main)

0 commit comments

Comments
 (0)