Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanf committed Apr 23, 2022
1 parent 5a749bf commit a8a75be
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 41 deletions.
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bazel build -- //...
Examples:

```shell
./bazel-bin/stablesolver/main -v -i "data/dimacs1992/brock200_1.clq" --format dimacs1992 -a "localsearch_rowweighting_2" -t 1 -c solution.txt
./bazel-bin/stablesolver/main -v -i "data/dimacs1992/brock200_1.clq" --format dimacs1992 -a "localsearch_rowweighting_2 --iterations 3000" -c solution.txt
```
```
=====================================
Expand All @@ -77,17 +77,16 @@ Algorithm
---------
Row Weighting Local Search 1
T (s) LB UB GAP GAP (%) Comment
----- -- -- --- ------- -------
0.0001 0 200 200 100
0.0001 15 200 185 92.5 initial solution
0.0002 16 200 184 92 iteration 2
0.0073 17 200 183 91.5 iteration 2
0.0082 18 200 182 91 iteration 2
0.0084 19 200 181 90.5 iteration 3
0.0137 20 200 180 90 iteration 1162
0.0199 21 200 179 89.5 iteration 2440
T (s) LB UB GAP GAP (%) Comment
----- -- -- --- ------- -------
0.000 0 200 200 100.00
0.000 15 200 185 92.50 initial solution
0.000 16 200 184 92.00 iteration 2
0.007 17 200 183 91.50 iteration 2
0.007 18 200 182 91.00 iteration 2
0.007 19 200 181 90.50 iteration 3
0.008 20 200 180 90.00 iteration 1162
0.010 21 200 179 89.50 iteration 2440
Final statistics
----------------
Expand All @@ -97,8 +96,8 @@ Vertex cover Value: 179
Bound: 200
Gap: 179
Gap (%): 89.5
Time (s): 1
Number of iterations: 1177617
Time (s): 0.0103
Number of iterations: 3000
```

```shell
Expand Down Expand Up @@ -138,12 +137,12 @@ Parameters
Maximum number of iterations: 300000
Maximum number of iterations without improvement: -1
T (s) LB UB GAP GAP (%) Comment
----- -- -- --- ------- -------
0.4206 0 118393 118393 100
0.4367 117029 118393 1364 1.1521 initial solution
0.8126 117146 118393 1247 1.05327 iteration 100000
1.2 117150 118393 1243 1.04989 iteration 200000
T (s) LB UB GAP GAP (%) Comment
----- -- -- --- ------- -------
0.425 0 118393 118393 100.00
0.441 117029 118393 1364 1.15 initial solution
0.815 117146 118393 1247 1.05 iteration 100000
1.207 117150 118393 1243 1.05 iteration 200000
Final statistics
----------------
Expand All @@ -153,6 +152,6 @@ Vertex cover Value: 75094
Bound: 118393
Gap: 1243
Gap (%): 1.04989
Time (s): 1.5649
Time (s): 1.5777
Number of iterations: 300000
```
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ cc_library(
git_repository(
name = "optimizationtools",
remote = "https://github.com/fontanf/optimizationtools.git",
commit = "d0cceac58c50da5850aa3447d1b545b36debe54c",
shallow_since = "1650081766 +0200",
commit = "592ba85b762fce7333542335a4fcad0e88582492",
shallow_since = "1650692671 +0200",
)

local_repository(
Expand Down
7 changes: 4 additions & 3 deletions cliquesolver/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ void Output::print(
double gap = (upper_bound == 0)?
std::numeric_limits<double>::infinity():
(double)(upper_bound - lower_bound()) / upper_bound * 100;
double t = round(info.elapsed_time() * 10000) / 10000;
double t = info.elapsed_time();
std::streamsize precision = std::cout.precision();

FFOT_VER(info,
std::setw(12) << t
std::setw(12) << std::fixed << std::setprecision(3) << t << std::defaultfloat << std::setprecision(precision)
<< std::setw(12) << lower_bound()
<< std::setw(12) << upper_bound
<< std::setw(12) << upper_bound - lower_bound()
<< std::setw(12) << gap
<< std::setw(12) << std::fixed << std::setprecision(2) << gap << std::defaultfloat << std::setprecision(precision)
<< std::setw(24) << s.str()
<< std::endl);

Expand Down
3 changes: 2 additions & 1 deletion stablesolver/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ using namespace stablesolver;
Instance::Instance(std::string instance_path, std::string format)
{
std::ifstream file(instance_path);
if (!file.good())
if (!file.good()) {
throw std::runtime_error(
"Unable to open file \"" + instance_path + "\".");
}

if (format == "dimacs1992") {
read_dimacs1992(file);
Expand Down
18 changes: 9 additions & 9 deletions stablesolver/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
namespace stablesolver
{

typedef int32_t VertexId; // v
typedef int32_t VertexPos; // v_pos
typedef int64_t EdgeId; // e
typedef int64_t EdgePos; // e_pos
typedef int64_t Weight; // w
typedef int64_t ComponentId; // c
typedef int16_t Penalty;
typedef int64_t Counter;
typedef int64_t Seed;
using VertexId = int32_t; // v
using VertexPos = int32_t; // v_pos
using EdgeId = int64_t; // e
using EdgePos = int64_t; // e_pos
using Weight = int64_t; // w
using ComponentId = int64_t; // c
using Penalty = int16_t;
using Counter = int64_t;
using Seed = int64_t;

class Solution;

Expand Down
11 changes: 6 additions & 5 deletions stablesolver/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ Output::Output(const Instance& instance, optimizationtools::Info& info):
<< std::setw(16) << "LB"
<< std::setw(16) << "UB"
<< std::setw(16) << "GAP"
<< std::setw(16) << "GAP (%)"
<< std::setw(12) << "GAP (%)"
<< std::setw(24) << "Comment"
<< std::endl
<< std::setw(12) << "-----"
<< std::setw(16) << "--"
<< std::setw(16) << "--"
<< std::setw(16) << "---"
<< std::setw(16) << "-------"
<< std::setw(12) << "-------"
<< std::setw(24) << "-------"
<< std::endl);
print(info, std::stringstream(""));
Expand All @@ -169,14 +169,15 @@ void Output::print(
double gap = (upper_bound == 0)?
std::numeric_limits<double>::infinity():
(double)(upper_bound - lower_bound()) / upper_bound * 100;
double t = round(info.elapsed_time() * 10000) / 10000;
double t = info.elapsed_time();
std::streamsize precision = std::cout.precision();

FFOT_VER(info,
std::setw(12) << t
std::setw(12) << std::fixed << std::setprecision(3) << t << std::defaultfloat << std::setprecision(precision)
<< std::setw(16) << lower_bound()
<< std::setw(16) << upper_bound
<< std::setw(16) << upper_bound - lower_bound()
<< std::setw(16) << gap
<< std::setw(12) << std::fixed << std::setprecision(2) << gap << std::defaultfloat << std::setprecision(precision)
<< std::setw(24) << s.str()
<< std::endl);

Expand Down

0 comments on commit a8a75be

Please sign in to comment.