Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanf committed Nov 1, 2023
1 parent b31b130 commit 1755305
Show file tree
Hide file tree
Showing 48 changed files with 1,582 additions and 186 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To solve a stable (resp. clique) problem, it is possible to use a clique (resp.

The stable solver can also be used to solve the Minimum (Weight) Vertex Cover Problem by just considering the vertices outside of the solution.

### Stable Solver
### Stable

- Greedy algorithms, see "A note on greedy algorithms for the maximum weighted independent set problem" (Sakai et al., 2001) [DOI](https://doi.org/10.1016/S0166-218X(02)00205-6)
- `-a greedy-gwmin`
Expand All @@ -33,7 +33,7 @@ The stable solver can also be used to solve the Minimum (Weight) Vertex Cover Pr

- Large neighborhoodsearch based on "NuMWVC: A novel local search for minimum weighted vertex cover problem" (Li et al., 2020) [DOI](https://doi.org/10.1080/01605682.2019.1621218) `-a "large-neighborhood-search"`

### Clique Solver
### Clique

- Greedy algorithms:
- `-a greedy-gwmin`, adapted from the stable version, same complexity
Expand Down
126 changes: 119 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,127 @@ local_repository(
path = "../localsearchsolver/",
)

new_local_repository(
name = "coinor",
path = "/home/florian/Programmes/coinbrew/",
http_archive(
name = "osi_linux",
urls = ["https://github.com/coin-or/Osi/releases/download/releases%2F0.108.8/Osi-releases.0.108.8-x86_64-ubuntu20-gcc940-static.tar.gz"],
sha256 = "bd5a5bf1e6b6a28d13d41ab1554becd9f3992afe775785e51a88c9405cf2853e",
build_file_content = """
cc_library(
name = "osi",
hdrs = glob(["include/coin/Osi*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin/",
srcs = ["lib/libOsi.a", "lib/libOsiCommonTests.a"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "osi_windows",
urls = ["https://github.com/coin-or/Osi/releases/download/releases%2F0.108.8/Osi-releases.0.108.8-w64-msvc16-md.zip"],
sha256 = "a61fc462cb598139d205cd2323522581a01900575d0d6bccf660b6c7e1b0b71c",
build_file_content = """
cc_library(
name = "osi",
hdrs = glob(["include/coin/Osi*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin/",
visibility = ["//visibility:public"],
srcs = ["lib/libOsi.lib", "lib/libOsiCommonTests.lib"],
)
""",
)

http_archive(
name = "coinutils_linux",
urls = ["https://github.com/coin-or/CoinUtils/releases/download/releases%2F2.11.9/CoinUtils-releases.2.11.9-x86_64-ubuntu20-gcc940-static.tar.gz"],
sha256 = "14d07de1b7961f68e037da6f0c57844fd67d4cc1a4b125642f42cd134b228094",
build_file_content = """
cc_library(
name = "coinutils",
hdrs = glob(["include/coin/Coin*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin/",
srcs = ["lib/libCoinUtils.a"],
linkopts = ["-llapack", "-lblas", "-lbz2", "-lz"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "coinutils_windows",
urls = ["https://github.com/coin-or/CoinUtils/releases/download/releases%2F2.11.9/CoinUtils-releases.2.11.9-w64-msvc16-md.zip"],
sha256 = "2bc64f0afd80113571697e949b2663e9047272decf90d5f62e452c2628d33ca6",
build_file_content = """
cc_library(
name = "coinutils",
hdrs = glob(["include/coin/Coin*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin/",
srcs = ["lib/libCoinUtils.lib"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "clp_linux",
urls = ["https://github.com/coin-or/Clp/releases/download/releases%2F1.17.8/Clp-releases.1.17.8-x86_64-ubuntu20-gcc940-static.tar.gz"],
sha256 = "d569b04d19c25876e55d2557a1d9739df8eb50ec8ca11a98ad387fd8b90212c9",
build_file_content = """
cc_library(
name = "clp",
hdrs = glob(["include/coin/*Clp*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin",
srcs = ["lib/libClp.a", "lib/libOsiClp.a"],
deps = ["@osi_linux//:osi", "@coinutils_linux//:coinutils"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "clp_windows",
urls = ["https://github.com/coin-or/Clp/releases/download/releases%2F1.17.8/Clp-releases.1.17.8-w64-msvc16-md.zip"],
sha256 = "e37c834aea5c31dfd8620b7d2432cb31fc16ecb0c6ffb398e8f07c9c82dd5028",
build_file_content = """
cc_library(
name = "clp",
hdrs = glob(["include/coin/*Clp*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin",
srcs = ["lib/libClp.lib", "lib/libOsiClp.lib"],
deps = ["@osi_windows//:osi", "@coinutils_windows//:coinutils"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "cbc_linux",
urls = ["https://github.com/coin-or/Cbc/releases/download/releases%2F2.10.10/Cbc-releases.2.10.10-x86_64-ubuntu20-gcc940-static.tar.gz"],
sha256 = "872c78bfcdd1566f134d2f7757b76b2a2479a5b1ade065cdd1d4b303ed6f8006",
build_file_content = """
cc_library(
name = "cbc",
hdrs = glob(["include/coin/*Cbc*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin",
srcs = ["lib/libCbc.a", "lib/libOsiCbc.a", "lib/libCgl.a"],
deps = ["@clp_linux//:clp"],
linkopts = ["-lnauty"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "cbc_windows",
urls = ["https://github.com/coin-or/Cbc/releases/download/releases%2F2.10.10/Cbc-releases.2.10.10-w64-msvc16-md.zip"],
sha256 = "94a951904eb80c2f351785fc9340216e88970a716634bc1ccd8b4fc5024af37c",
build_file_content = """
cc_library(
name = "coinor",
hdrs = glob(["dist/include/**/*.h*"], exclude_directories = 0),
strip_include_prefix = "dist/include/",
srcs = glob(["dist/lib/**/*.so"], exclude_directories = 0),
name = "cbc",
hdrs = glob(["include/coin/*Cbc*.h*"], exclude_directories = 0),
strip_include_prefix = "include/coin",
srcs = ["lib/libCbc.lib", "lib/libOsiCbc.lib", "lib/libCgl.lib"],
deps = ["@clp_windows//:clp"],
visibility = ["//visibility:public"],
)
""",
Expand Down
19 changes: 0 additions & 19 deletions cliquesolver/algorithms/algorithms.hpp

This file was deleted.

56 changes: 25 additions & 31 deletions stablesolver/BUILD
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
config_setting(name = "coinor_build", values = {"define": "coinor=true"}, visibility = ["//visibility:public"])
config_setting(name = "cplex_build", values = {"define": "cplex=true"}, visibility = ["//visibility:public"])
load("@bazel_skylib//lib:selects.bzl", "selects")

load("//stablesolver:variables.bzl", "STDCPP")
config_setting(
name = "cbc_build",
values = {"define": "cbc=true"},
visibility = ["//visibility:public"],
)

selects.config_setting_group(
name = "cbc_linux",
match_all = [":cbc_build", "@bazel_tools//src/conditions:linux"],
)

cc_library(
name = "stablesolver",
hdrs = [
"instance.hpp",
"instance_builder.hpp",
"solution.hpp",
],
srcs = [
"instance.cpp",
"instance_builder.cpp",
"solution.cpp",
],
deps = [
"@optimizationtools//optimizationtools/utils:info",
"@optimizationtools//optimizationtools/utils:utils",
"@optimizationtools//optimizationtools/containers:containers",
],
visibility = ["//visibility:public"],
selects.config_setting_group(
name = "cbc_windows",
match_all = [":cbc_build", "@bazel_tools//src/conditions:windows"],
)

cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [
"//stablesolver/algorithms:algorithms",
],
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": ["-lpthread"],
}),
config_setting(
name = "cplex_build",
values = {"define": "cplex=true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "xpress_build",
values = {"define": "xpress=true"},
visibility = ["//visibility:public"]
)

load("//stablesolver:variables.bzl", "STDCPP")
22 changes: 0 additions & 22 deletions stablesolver/algorithms/algorithms.hpp

This file was deleted.

6 changes: 2 additions & 4 deletions cliquesolver/BUILD → stablesolver/clique/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
config_setting(name = "cplex_build", values = {"define": "cplex=true"}, visibility = ["//visibility:public"])

load("//stablesolver:variables.bzl", "STDCPP")

cc_library(
name = "cliquesolver",
name = "clique",
hdrs = [
"instance.hpp",
"solution.hpp",
Expand All @@ -25,7 +23,7 @@ cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [
"//cliquesolver/algorithms:algorithms",
"//stablesolver/clique/algorithms:algorithms",
],
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("//stablesolver:variables.bzl", "STDCPP",
"CPLEX_COPTS", "CPLEX_DEP", "CPOPTIMIZER_DEP")
"CPLEX_COPTS", "CPLEX_DEP")

cc_library(
name = "greedy",
hdrs = ["greedy.hpp"],
srcs = ["greedy.cpp"],
deps = ["//cliquesolver:cliquesolver"],
deps = ["//stablesolver/clique:clique"],
visibility = ["//visibility:public"],
)

Expand All @@ -14,7 +14,7 @@ cc_library(
hdrs = ["milp_cplex.hpp"],
srcs = ["milp_cplex.cpp"],
deps = [
"//cliquesolver:cliquesolver",
"//stablesolver/clique:clique",
] + CPLEX_DEP,
copts = CPLEX_COPTS,
visibility = ["//visibility:public"],
Expand All @@ -25,7 +25,7 @@ cc_library(
hdrs = ["local_search.hpp"],
srcs = ["local_search.cpp"],
deps = [
"//cliquesolver:cliquesolver",
"//stablesolver/clique:clique",
":greedy",
"@localsearchsolver//localsearchsolver:localsearchsolver",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "cliquesolver/algorithms/algorithms.hpp"
#include "stablesolver/clique/algorithms/algorithms.hpp"

#include <boost/program_options.hpp>

using namespace cliquesolver;
using namespace stablesolver::clique;
namespace po = boost::program_options;

LocalSearchOptionalParameters read_local_search_args(const std::vector<char*>& argv)
Expand All @@ -23,7 +23,7 @@ LocalSearchOptionalParameters read_local_search_args(const std::vector<char*>& a
return parameters;
}

Output cliquesolver::run(
Output stablesolver::clique::run(
std::string algorithm,
const Instance& instance,
std::mt19937_64& generator,
Expand Down
22 changes: 22 additions & 0 deletions stablesolver/clique/algorithms/algorithms.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "stablesolver/clique/solution.hpp"

#include "stablesolver/clique/algorithms/greedy.hpp"
#include "stablesolver/clique/algorithms/milp_cplex.hpp"
#include "stablesolver/clique/algorithms/local_search.hpp"

namespace stablesolver
{
namespace clique
{

Output run(
std::string algorithm,
const Instance& instance,
std::mt19937_64& generator,
optimizationtools::Info info);

}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "cliquesolver/algorithms/greedy.hpp"
#include "stablesolver/clique/algorithms/greedy.hpp"

#include "optimizationtools/containers/indexed_binary_heap.hpp"
#include "optimizationtools/containers/doubly_indexed_map.hpp"

using namespace cliquesolver;
using namespace stablesolver::clique;

Output cliquesolver::greedy_gwmin(
Output stablesolver::clique::greedy_gwmin(
const Instance& instance,
optimizationtools::Info info)
{
cliquesolver::init_display(instance, info);
stablesolver::clique::init_display(instance, info);
info.os()
<< "Algorithm" << std::endl
<< "---------" << std::endl
Expand Down Expand Up @@ -52,11 +52,11 @@ Output cliquesolver::greedy_gwmin(
return output.algorithm_end(info);
}

Output cliquesolver::greedy_strong(
Output stablesolver::clique::greedy_strong(
const Instance& instance,
optimizationtools::Info info)
{
cliquesolver::init_display(instance, info);
stablesolver::clique::init_display(instance, info);
info.os()
<< "Algorithm" << std::endl
<< "---------" << std::endl
Expand Down
Loading

0 comments on commit 1755305

Please sign in to comment.