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

Clean code #5

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ python3 scripts/download_data.py --data gecco2020
Run:

```shell
./bazel-bin/setcoveringsolver/setcovering/main -v 1 -i data/wedelin1995/sasd9imp2.dat -f wedelin1995 -a milp-cbc
./bazel-bin/setcoveringsolver/main -v 1 -i data/wedelin1995/sasd9imp2.dat -f wedelin1995 -a milp-cbc
```
```
=====================================
Expand Down Expand Up @@ -130,7 +130,7 @@ Cost: 5262040
```

```shell
./bazel-bin/setcoveringsolver/setcovering/main -v 1 -i data/beasley1990/scpnrh5.txt -f orlibrary -a large-neighborhood-search -t 0.3
./bazel-bin/setcoveringsolver/main -v 1 -i data/beasley1990/scpnrh5.txt -f orlibrary -a large-neighborhood-search -t 0.3
```
```
=====================================
Expand Down Expand Up @@ -212,7 +212,7 @@ Cost: 55
```

```shell
./bazel-bin/setcoveringsolver/setcovering/main -v 1 -i data/faster1994/rail582.txt -f faster --unicost -a local-search-row-weighting-1 -c solution.txt -t 2
./bazel-bin/setcoveringsolver/main -v 1 -i data/faster1994/rail582.txt -f faster --unicost -a local-search-row-weighting-1 -c solution.txt -t 2
```
```
=====================================
Expand Down Expand Up @@ -312,7 +312,7 @@ Cost: 130
```

```shell
./bazel-bin/setcoveringsolver/setcovering/main -v 1 -i data/gecco2020/AC_15_cover.txt -f gecco2020 --unicost -a local-search-row-weighting-2 -t 10 -c solution.txt
./bazel-bin/setcoveringsolver/main -v 1 -i data/gecco2020/AC_15_cover.txt -f gecco2020 --unicost -a local-search-row-weighting-2 -t 10 -c solution.txt
```
```
=====================================
Expand Down
1 change: 0 additions & 1 deletion scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
main = os.path.join(
"bazel-bin",
"setcoveringsolver",
"setcovering",
"main")


Expand Down
50 changes: 50 additions & 0 deletions setcoveringsolver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,53 @@ config_setting(
values = {"define": "gurobi=true"},
visibility = ["//visibility:public"],
)

load("//setcoveringsolver:variables.bzl", "STDCPP",
"CBC_COPTS", "CBC_DEP",
"CPLEX_COPTS", "CPLEX_DEP",
"GUROBI_COPTS", "GUROBI_DEP")

cc_library(
name = "data",
hdrs = [
"instance.hpp",
"instance_builder.hpp",
"solution.hpp",
"reduction.hpp",
"algorithm.hpp",
"algorithm_formatter.hpp",
],
srcs = [
"instance.cpp",
"instance_builder.cpp",
"solution.cpp",
"reduction.cpp",
"algorithm.cpp",
"algorithm_formatter.cpp",
],
deps = [
"@optimizationtools//optimizationtools/utils:utils",
"@optimizationtools//optimizationtools/containers:containers",
],
copts = STDCPP,
visibility = ["//visibility:public"],
)

cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [
"//setcoveringsolver/algorithms:greedy",
"//setcoveringsolver/algorithms:milp_cbc",
"//setcoveringsolver/algorithms:milp_gurobi",
"//setcoveringsolver/algorithms:local_search_row_weighting",
"//setcoveringsolver/algorithms:large_neighborhood_search",
"@boost//:program_options",
] + CBC_DEP + GUROBI_DEP,
copts = CBC_COPTS + GUROBI_COPTS,
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": ["-lpthread"],
}),
)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "setcoveringsolver/setcovering/reduction.hpp"
#include "setcoveringsolver/reduction.hpp"

#include "optimizationtools/utils/output.hpp"
#include "optimizationtools/utils/utils.hpp"
Expand All @@ -9,8 +9,6 @@

namespace setcoveringsolver
{
namespace setcovering
{

inline optimizationtools::ObjectiveDirection objective_direction()
{
Expand Down Expand Up @@ -127,4 +125,3 @@ struct Parameters: optimizationtools::Parameters
};

}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "setcoveringsolver/setcovering/algorithm_formatter.hpp"
#include "setcoveringsolver/algorithm_formatter.hpp"

#include "optimizationtools/utils/utils.hpp"

#include <iomanip>

using namespace setcoveringsolver::setcovering;
using namespace setcoveringsolver;

void AlgorithmFormatter::start(
const std::string& algorithm_name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include "setcoveringsolver/setcovering/algorithm.hpp"
#include "setcoveringsolver/algorithm.hpp"

namespace setcoveringsolver
{
namespace setcovering
{

class AlgorithmFormatter
{
Expand Down Expand Up @@ -108,4 +106,3 @@ inline const AlgorithmOutput solve_reduced_instance(
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cc_library(
name = "greedy",
hdrs = ["greedy.hpp"],
srcs = ["greedy.cpp"],
deps = ["//setcoveringsolver/setcovering:data"],
deps = ["//setcoveringsolver:data"],
visibility = ["//visibility:public"],
)

Expand All @@ -16,7 +16,7 @@ cc_library(
hdrs = ["milp_cbc.hpp"],
srcs = ["milp_cbc.cpp"],
deps = [
"//setcoveringsolver/setcovering:data",
"//setcoveringsolver:data",
] + CBC_DEP,
copts = CBC_COPTS,
visibility = ["//visibility:public"],
Expand All @@ -27,7 +27,7 @@ cc_library(
hdrs = ["milp_gurobi.hpp"],
srcs = ["milp_gurobi.cpp"],
deps = [
"//setcoveringsolver/setcovering:data",
"//setcoveringsolver:data",
] + GUROBI_DEP,
copts = GUROBI_COPTS,
visibility = ["//visibility:public"],
Expand All @@ -39,7 +39,7 @@ cc_library(
srcs = ["local_search_row_weighting.cpp"],
deps = [
":greedy",
"//setcoveringsolver/setcovering:data",
"//setcoveringsolver:data",
],
visibility = ["//visibility:public"],
)
Expand All @@ -50,7 +50,7 @@ cc_library(
srcs = ["large_neighborhood_search.cpp"],
deps = [
":greedy",
"//setcoveringsolver/setcovering:data",
"//setcoveringsolver:data",
],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "setcoveringsolver/setcovering/algorithms/greedy.hpp"
#include "setcoveringsolver/algorithms/greedy.hpp"

#include "setcoveringsolver/setcovering/algorithm_formatter.hpp"
#include "setcoveringsolver/algorithm_formatter.hpp"

#include "optimizationtools/containers/indexed_binary_heap.hpp"

using namespace setcoveringsolver::setcovering;
using namespace setcoveringsolver;

const Output setcoveringsolver::setcovering::greedy(
const Output setcoveringsolver::greedy(
const Instance& instance,
const Parameters& parameters)
{
Expand Down Expand Up @@ -67,7 +67,7 @@ const Output setcoveringsolver::setcovering::greedy(
return output;
}

const Output setcoveringsolver::setcovering::greedy_lin(
const Output setcoveringsolver::greedy_lin(
const Instance& instance,
const Parameters& parameters)
{
Expand Down Expand Up @@ -126,7 +126,7 @@ const Output setcoveringsolver::setcovering::greedy_lin(
return output;
}

const Output setcoveringsolver::setcovering::greedy_dual(
const Output setcoveringsolver::greedy_dual(
const Instance& instance,
const Parameters& parameters)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include "setcoveringsolver/setcovering/algorithm.hpp"
#include "setcoveringsolver/algorithm.hpp"

namespace setcoveringsolver
{
namespace setcovering
{

const Output greedy(
const Instance& instance,
Expand All @@ -20,5 +18,3 @@ const Output greedy_dual(
const Parameters& parameters = {});

}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "setcoveringsolver/setcovering/algorithms/large_neighborhood_search.hpp"
#include "setcoveringsolver/algorithms/large_neighborhood_search.hpp"

#include "setcoveringsolver/setcovering/algorithm_formatter.hpp"
#include "setcoveringsolver/setcovering/algorithms/greedy.hpp"
#include "setcoveringsolver/algorithm_formatter.hpp"
#include "setcoveringsolver/algorithms/greedy.hpp"

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

using namespace setcoveringsolver::setcovering;
using namespace setcoveringsolver;

struct LargeNeighborhoodSearchSet
{
Expand All @@ -17,7 +17,7 @@ struct LargeNeighborhoodSearchSet
Cost score = 0;
};

const LargeNeighborhoodSearchOutput setcoveringsolver::setcovering::large_neighborhood_search(
const LargeNeighborhoodSearchOutput setcoveringsolver::large_neighborhood_search(
const Instance& instance,
const LargeNeighborhoodSearchParameters& parameters)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include "setcoveringsolver/setcovering/algorithm.hpp"
#include "setcoveringsolver/algorithm.hpp"

namespace setcoveringsolver
{
namespace setcovering
{

struct LargeNeighborhoodSearchParameters: Parameters
{
Expand Down Expand Up @@ -77,5 +75,3 @@ const LargeNeighborhoodSearchOutput large_neighborhood_search(
const LargeNeighborhoodSearchParameters& parameters = {});

}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "setcoveringsolver/setcovering/algorithms/local_search_row_weighting.hpp"
#include "setcoveringsolver/algorithms/local_search_row_weighting.hpp"

#include "setcoveringsolver/setcovering/algorithm_formatter.hpp"
#include "setcoveringsolver/setcovering/algorithms/greedy.hpp"
#include "setcoveringsolver/algorithm_formatter.hpp"
#include "setcoveringsolver/algorithms/greedy.hpp"

#include "optimizationtools/containers/indexed_set.hpp"

using namespace setcoveringsolver::setcovering;
using namespace setcoveringsolver;

struct LocalSearchRowWeightingComponent
{
Expand Down Expand Up @@ -45,7 +45,7 @@ struct LocalSearchRowWeightingSet
Cost score = 0;
};

const LocalSearchRowWeighting2Output setcoveringsolver::setcovering::local_search_row_weighting_2(
const LocalSearchRowWeighting2Output setcoveringsolver::local_search_row_weighting_2(
const Instance& instance,
std::mt19937_64& generator,
const LocalSearchRowWeighting2Parameters& parameters)
Expand Down Expand Up @@ -566,7 +566,7 @@ struct LocalSearchRowWeighting1Set
Cost score = 0;
};

const LocalSearchRowWeighting1Output setcoveringsolver::setcovering::local_search_row_weighting_1(
const LocalSearchRowWeighting1Output setcoveringsolver::local_search_row_weighting_1(
const Instance& instance,
std::mt19937_64& generator,
const LocalSearchRowWeighting1Parameters& parameters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include "setcoveringsolver/setcovering/algorithm.hpp"
#include "setcoveringsolver/algorithm.hpp"

namespace setcoveringsolver
{
namespace setcovering
{

struct LocalSearchRowWeighting1Parameters: Parameters
{
Expand Down Expand Up @@ -207,5 +205,3 @@ const LocalSearchRowWeighting2Output local_search_row_weighting_2(
const LocalSearchRowWeighting2Parameters& parameters = {});

}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#if CBC_FOUND

#include "setcoveringsolver/setcovering/algorithms/milp_cbc.hpp"
#include "setcoveringsolver/algorithms/milp_cbc.hpp"

#include "setcoveringsolver/setcovering/algorithm_formatter.hpp"
#include "setcoveringsolver/algorithm_formatter.hpp"

using namespace setcoveringsolver::setcovering;
using namespace setcoveringsolver;

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// Callback ///////////////////////////////////
Expand Down Expand Up @@ -164,7 +164,7 @@ CoinLP::CoinLP(const Instance& instance)
number_of_elements_in_rows.data());
}

const Output setcoveringsolver::setcovering::milp_cbc(
const Output setcoveringsolver::milp_cbc(
const Instance& instance,
const MilpCbcParameters& parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

#if CBC_FOUND

#include "setcoveringsolver/setcovering/algorithm.hpp"
#include "setcoveringsolver/algorithm.hpp"

#include <CbcModel.hpp>
#include <OsiCbcSolverInterface.hpp>

namespace setcoveringsolver
{
namespace setcovering
{

struct MilpCbcParameters: Parameters
{
Expand All @@ -23,7 +21,6 @@ const Output milp_cbc(
const MilpCbcParameters& parameters = {});

}
}

#endif

Loading
Loading