Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanf committed Jan 13, 2024
1 parent cd289c5 commit ca4aa6e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 26 deletions.
5 changes: 5 additions & 0 deletions setcoveringsolver/setcovering/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#include "setcoveringsolver/setcovering/reduction.hpp"

#include "optimizationtools/utils/output.hpp"
#include "optimizationtools/utils/utils.hpp"

#include <iomanip>

namespace setcoveringsolver
{
namespace setcovering
Expand Down
14 changes: 7 additions & 7 deletions setcoveringsolver/setcovering/algorithm_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,33 @@ void AlgorithmFormatter::print(
}

void AlgorithmFormatter::update_solution(
const Solution& solution_new,
const Solution& solution,
const std::string& s)
{
if (optimizationtools::is_solution_strictly_better(
objective_direction(),
output_.solution.feasible(),
output_.solution.objective_value(),
solution_new.feasible(),
solution_new.objective_value())) {
solution.feasible(),
solution.objective_value())) {
output_.time = parameters_.timer.elapsed_time();
output_.solution = solution_new;
output_.solution = solution;
print(s);
output_.json["IntermediaryOutputs"].push_back(output_.to_json());
parameters_.new_solution_callback(output_, s);
}
}

void AlgorithmFormatter::update_bound(
Cost bound_new,
Cost bound,
const std::string& s)
{
if (optimizationtools::is_bound_strictly_better(
objective_direction(),
output_.bound,
bound_new)) {
bound)) {
output_.time = parameters_.timer.elapsed_time();
output_.bound = bound_new;
output_.bound = bound;
print(s);
output_.json["IntermediaryOutputs"].push_back(output_.to_json());
parameters_.new_solution_callback(output_, s);
Expand Down
4 changes: 2 additions & 2 deletions setcoveringsolver/setcovering/algorithm_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class AlgorithmFormatter

/** Update the solution. */
void update_solution(
const Solution& solution_new,
const Solution& solution,
const std::string& s);

/** Update the bound. */
void update_bound(
Cost bound_new,
Cost bound,
const std::string& s);

/** Method to call at the end of the algorithm. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "optimizationtools/containers/indexed_set.hpp"
#include "optimizationtools/containers/indexed_binary_heap.hpp"

#include <iomanip>

using namespace setcoveringsolver::setcovering;

struct LargeNeighborhoodSearchSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include "setcoveringsolver/setcovering/algorithms/greedy.hpp"

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

#include <thread>
#include <iomanip>

using namespace setcoveringsolver::setcovering;

Expand Down
6 changes: 1 addition & 5 deletions setcoveringsolver/setcovering/instance.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include "setcoveringsolver/setcovering/instance.hpp"
#include "setcoveringsolver/setcovering/instance_builder.hpp"

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

#include <random>
#include <set>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <thread>

Expand Down
5 changes: 4 additions & 1 deletion setcoveringsolver/setcovering/instance.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once

#include "optimizationtools/utils/output.hpp"
#include <cstdint>
#include <vector>
#include <string>
#include <iostream>

namespace setcoveringsolver
{
Expand Down
2 changes: 2 additions & 0 deletions setcoveringsolver/setcovering/instance_builder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "setcoveringsolver/setcovering/instance_builder.hpp"

#include <fstream>

using namespace setcoveringsolver::setcovering;

void InstanceBuilder::add_sets(SetId number_of_sets)
Expand Down
8 changes: 7 additions & 1 deletion setcoveringsolver/setcovering/solution.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "setcoveringsolver/setcovering/solution.hpp"

#include "optimizationtools/utils/utils.hpp"

#include <fstream>
#include <iomanip>

using namespace setcoveringsolver::setcovering;

Solution::Solution(const Instance& instance):
Expand Down Expand Up @@ -33,7 +38,8 @@ Solution::Solution(
}
}

void Solution::write(std::string certificate_path) const
void Solution::write(
const std::string& certificate_path) const
{
if (certificate_path.empty())
return;
Expand Down
5 changes: 2 additions & 3 deletions setcoveringsolver/setcovering/solution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#include "optimizationtools/containers/indexed_set.hpp"
#include "optimizationtools/containers/indexed_map.hpp"
#include "optimizationtools/utils/utils.hpp"

#include <iomanip>
#include "nlohmann//json.hpp"

namespace setcoveringsolver
{
Expand Down Expand Up @@ -91,7 +90,7 @@ class Solution
*/

/** Write the solution to a file. */
void write(std::string certificate_path) const;
void write(const std::string& certificate_path) const;

/** Export solution characteristics to a JSON structure. */
nlohmann::json to_json() const;
Expand Down

0 comments on commit ca4aa6e

Please sign in to comment.