Commit 4947a077 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

baryonyx: apply coding style

parent 342701cc
......@@ -120,7 +120,7 @@ struct numeric_cast_failure : public std::exception
* assert(not lp::is_numeric_castable<std::int8_t>(v2));
* @endcode
*/
template <typename Target, typename Source>
template<typename Target, typename Source>
inline bool
is_numeric_castable(Source arg) noexcept
{
......@@ -159,7 +159,7 @@ is_numeric_castable(Source arg) noexcept
* long int index = lp::numeric_cast<long int>(v); // No throw.
* @endcode
*/
template <typename Target, typename Source>
template<typename Target, typename Source>
inline Target
numeric_cast(Source s)
{
......@@ -716,8 +716,8 @@ struct variables
struct function_element
{
function_element(int factor_, index variable_index_) noexcept
: factor(factor_),
variable_index(variable_index_)
: factor(factor_)
, variable_index(variable_index_)
{
}
......@@ -838,8 +838,9 @@ compute_min_max_objective_function(const problem& pb) noexcept
* std::system_error.
*/
BARYONYX_API
problem make_problem(std::shared_ptr<baryonyx::context> ctx,
const std::string& filename);
problem
make_problem(std::shared_ptr<baryonyx::context> ctx,
const std::string& filename);
/**
* Read a @e lp file from the @e is stream.
......@@ -848,14 +849,16 @@ problem make_problem(std::shared_ptr<baryonyx::context> ctx,
* std::system_error.
*/
BARYONYX_API
problem make_problem(std::shared_ptr<baryonyx::context> ctx, std::istream& is);
problem
make_problem(std::shared_ptr<baryonyx::context> ctx, std::istream& is);
/**
* Write @e lp problem into a stream.
*
*/
BARYONYX_API
std::ostream& operator<<(std::ostream& os, const problem& p);
std::ostream&
operator<<(std::ostream& os, const problem& p);
/**
* @details Try to solve or find a feasible solution for the @c
......@@ -867,7 +870,8 @@ std::ostream& operator<<(std::ostream& os, const problem& p);
* @exception baryonyx::problem_definition
*/
BARYONYX_API
result solve(std::shared_ptr<baryonyx::context> ctx, problem& pb);
result
solve(std::shared_ptr<baryonyx::context> ctx, problem& pb);
/**
* @details Try to optimize the @c baryonyx::problem with a set of
......@@ -880,15 +884,16 @@ result solve(std::shared_ptr<baryonyx::context> ctx, problem& pb);
* @throw @c baryonyx::solver_error.
*/
BARYONYX_API
result optimize(std::shared_ptr<baryonyx::context> ctx, problem& pb);
result
optimize(std::shared_ptr<baryonyx::context> ctx, problem& pb);
BARYONYX_API
bool is_valid_solution(const problem& pb,
const std::vector<int>& variable_value);
bool
is_valid_solution(const problem& pb, const std::vector<int>& variable_value);
BARYONYX_API
double compute_solution(const problem& pb,
const std::vector<int>& variable_value);
double
compute_solution(const problem& pb, const std::vector<int>& variable_value);
}
#endif
......@@ -204,7 +204,7 @@ struct minimize_tag
{
};
template <typename iteratorT, typename randomT>
template<typename iteratorT, typename randomT>
void
random_shuffle_unique(iteratorT begin, iteratorT end, randomT& rng)
{
......@@ -219,7 +219,7 @@ random_shuffle_unique(iteratorT begin, iteratorT end, randomT& rng)
std::shuffle(ret, begin, rng);
}
template <typename iteratorT, typename randomT>
template<typename iteratorT, typename randomT>
void
calculator_sort(iteratorT begin, iteratorT end, randomT& rng, minimize_tag)
{
......@@ -238,7 +238,7 @@ calculator_sort(iteratorT begin, iteratorT end, randomT& rng, minimize_tag)
}
}
template <typename iteratorT, typename randomT>
template<typename iteratorT, typename randomT>
void
calculator_sort(iteratorT begin, iteratorT end, randomT& rng, maximize_tag)
{
......@@ -336,7 +336,7 @@ compute_C_size(const AP_type& ap, index k) noexcept
return C_size;
}
template <typename modeT, typename randomT>
template<typename modeT, typename randomT>
struct constraint_calculator
{
using mode_type = modeT;
......@@ -645,7 +645,7 @@ struct merged_constraint_hash
* remove the constraint and we remove all reference to this variable in all
* constraints.
*/
template <typename constraintsT>
template<typename constraintsT>
long
remove_small_constraints(constraintsT& csts) noexcept
{
......@@ -667,7 +667,7 @@ remove_small_constraints(constraintsT& csts) noexcept
* removes, second is the number of constraints removed due to the 0 factor
* removed.
*/
template <typename constraintsT>
template<typename constraintsT>
std::tuple<long, long>
remove_element_with_factor_0(constraintsT& csts) noexcept
{
......@@ -913,7 +913,7 @@ make_merged_constraints(std::shared_ptr<context> ctx,
// return ret;
}
template <typename modeT, typename randomT>
template<typename modeT, typename randomT>
struct solver
{
using mode_type = modeT;
......@@ -1102,7 +1102,7 @@ struct solver
}
};
template <typename T>
template<typename T>
std::size_t
cycle_avoidance_hash(const std::vector<T>& vec)
{
......@@ -1136,7 +1136,7 @@ cycle_avoidance_hash(const std::vector<std::pair<index, index>>& vec)
return seed;
}
template <typename T>
template<typename T>
struct no_cycle_avoidance
{
using value_type = T;
......@@ -1162,7 +1162,7 @@ struct no_cycle_avoidance
}
};
template <typename T>
template<typename T>
struct cycle_avoidance
{
using value_type = T;
......@@ -1235,7 +1235,7 @@ struct cycle_avoidance
}
};
template <typename solverT>
template<typename solverT>
std::size_t
compute_missing_constraint(solverT& solver, std::vector<index>& R)
{
......@@ -1257,7 +1257,7 @@ compute_missing_constraint(solverT& solver, std::vector<index>& R)
return R.size();
}
template <typename randomT>
template<typename randomT>
struct compute_reversing
{
std::vector<index> R;
......@@ -1267,7 +1267,7 @@ struct compute_reversing
{
}
template <typename solverT>
template<typename solverT>
std::size_t run_all(solverT& solver,
double kappa,
double delta,
......@@ -1279,7 +1279,7 @@ struct compute_reversing
return compute_missing_constraint(solver, R);
}
template <typename solverT>
template<typename solverT>
std::size_t run(solverT& solver, double kappa, double delta, double theta)
{
auto ret = compute_missing_constraint(solver, R);
......@@ -1296,7 +1296,7 @@ struct compute_reversing
}
};
template <typename randomT>
template<typename randomT>
struct compute_none
{
std::vector<index> R;
......@@ -1306,7 +1306,7 @@ struct compute_none
{
}
template <typename solverT>
template<typename solverT>
std::size_t run_all(solverT& solver,
double kappa,
double delta,
......@@ -1318,7 +1318,7 @@ struct compute_none
return compute_missing_constraint(solver, R);
}
template <typename solverT>
template<typename solverT>
std::size_t run(solverT& solver, double kappa, double delta, double theta)
{
auto ret = compute_missing_constraint(solver, R);
......@@ -1335,7 +1335,7 @@ struct compute_none
}
};
template <typename randomT>
template<typename randomT>
struct compute_random
{
using random_generator_type = randomT;
......@@ -1349,7 +1349,7 @@ struct compute_random
{
}
template <typename solverT>
template<typename solverT>
std::size_t run_all(solverT& solver,
double kappa,
double delta,
......@@ -1365,7 +1365,7 @@ struct compute_random
return compute_missing_constraint(solver, R);
}
template <typename solverT>
template<typename solverT>
std::size_t run(solverT& solver, double kappa, double delta, double theta)
{
auto ret = compute_missing_constraint(solver, R);
......@@ -1391,7 +1391,7 @@ struct compute_infeasibility_decr
{
};
template <typename randomT, typename directionT>
template<typename randomT, typename directionT>
struct compute_infeasibility
{
using random_generator_type = randomT;
......@@ -1401,7 +1401,7 @@ struct compute_infeasibility
std::vector<std::pair<index, index>> R;
no_cycle_avoidance<index> detect_infeasability_cycle;
template <typename iteratorT>
template<typename iteratorT>
void sort(iteratorT begin, iteratorT end, compute_infeasibility_incr) const
{
std::sort(begin, end, [](const auto& lhs, const auto& rhs) {
......@@ -1409,7 +1409,7 @@ struct compute_infeasibility
});
}
template <typename iteratorT>
template<typename iteratorT>
void sort(iteratorT begin, iteratorT end, compute_infeasibility_decr) const
{
std::sort(begin, end, [](const auto& lhs, const auto& rhs) {
......@@ -1422,7 +1422,7 @@ struct compute_infeasibility
{
}
template <typename solverT>
template<typename solverT>
std::size_t compute_missing_constraint(solverT& solver)
{
R.clear();
......@@ -1447,7 +1447,7 @@ struct compute_infeasibility
return R.size();
}
template <typename solverT>
template<typename solverT>
std::size_t run_all(solverT& solver,
double kappa,
double delta,
......@@ -1492,7 +1492,7 @@ struct compute_infeasibility
return compute_missing_constraint(solver);
}
template <typename solverT>
template<typename solverT>
std::size_t run(solverT& solver, double kappa, double delta, double theta)
{
auto ret = compute_missing_constraint(solver);
......@@ -1522,7 +1522,7 @@ struct compute_infeasibility
}
};
template <typename modeT, typename constraintOrderT, typename randomT>
template<typename modeT, typename constraintOrderT, typename randomT>
struct solver_functor
{
using mode_type = modeT;
......@@ -1636,7 +1636,7 @@ struct solver_functor
}
};
template <typename modeT, typename constraintOrderT, typename randomT>
template<typename modeT, typename constraintOrderT, typename randomT>
struct optimize_functor
{
using mode_type = modeT;
......@@ -1825,7 +1825,7 @@ normalize_costs(std::shared_ptr<context> ctx, const c_type& c)
return ret;
}
template <typename modeT, typename constraintOrderT, typename randomT>
template<typename modeT, typename constraintOrderT, typename randomT>
inline result
solve(std::shared_ptr<context> ctx,
problem& pb,
......@@ -1854,7 +1854,7 @@ solve(std::shared_ptr<context> ctx,
return result;
}
template <typename modeT, typename constraintOrderT, typename randomT>
template<typename modeT, typename constraintOrderT, typename randomT>
inline result
optimize(std::shared_ptr<context> ctx,
problem& pb,
......
......@@ -588,7 +588,7 @@ optimize(std::shared_ptr<baryonyx::context> ctx, problem& pb)
return mitm_optimize(ctx, pb);
}
template <typename functionT, typename variablesT>
template<typename functionT, typename variablesT>
int
compute_function(const functionT& fct, const variablesT& vars) noexcept
{
......
......@@ -43,7 +43,7 @@ namespace baryonyx {
* @tparam A_T Type of element of matrix A.
* @tparam P_T Type of element of matrix P.
*/
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
class SparseArray
{
public:
......@@ -132,7 +132,7 @@ public:
void mult_row_p(index_type row, p_type y);
template <typename InputIterator>
template<typename InputIterator>
void reserve(index_type elem,
InputIterator row_begin,
InputIterator row_end,
......@@ -160,28 +160,28 @@ private:
inline index_type binary_find(index_type row, index_type col) const;
};
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
SparseArray<A_T, P_T>::SparseArray(index_type rows, index_type cols)
: m_rows_access(rows, -1)
, m_cols_access(cols, -1)
{
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
bool
SparseArray<A_T, P_T>::empty() const noexcept
{
return m_a.empty();
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
typename SparseArray<A_T, P_T>::size_type
SparseArray<A_T, P_T>::size() const noexcept
{
return m_a.size();
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
std::tuple<typename SparseArray<A_T, P_T>::iterator,
typename SparseArray<A_T, P_T>::iterator>
SparseArray<A_T, P_T>::row(index_type row) noexcept
......@@ -197,7 +197,7 @@ SparseArray<A_T, P_T>::row(index_type row) noexcept
return std::make_tuple(begin, m_rows.end());
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
std::tuple<typename SparseArray<A_T, P_T>::iterator,
typename SparseArray<A_T, P_T>::iterator>
SparseArray<A_T, P_T>::column(index_type col) noexcept
......@@ -213,7 +213,7 @@ SparseArray<A_T, P_T>::column(index_type col) noexcept
return std::make_tuple(begin, m_cols.end());
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
std::tuple<typename SparseArray<A_T, P_T>::const_iterator,
typename SparseArray<A_T, P_T>::const_iterator>
SparseArray<A_T, P_T>::row(index_type row) const noexcept
......@@ -229,7 +229,7 @@ SparseArray<A_T, P_T>::row(index_type row) const noexcept
return std::make_tuple(begin, m_rows.end());
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
std::tuple<typename SparseArray<A_T, P_T>::const_iterator,
typename SparseArray<A_T, P_T>::const_iterator>
SparseArray<A_T, P_T>::column(index_type col) const noexcept
......@@ -245,7 +245,7 @@ SparseArray<A_T, P_T>::column(index_type col) const noexcept
return std::make_tuple(begin, m_cols.end());
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::set(index_type row, index_type col, a_type x, p_type y)
{
......@@ -276,7 +276,7 @@ SparseArray<A_T, P_T>::set(index_type row, index_type col, a_type x, p_type y)
}
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::set_p(index_type row, index_type col, p_type y)
{
......@@ -287,7 +287,7 @@ SparseArray<A_T, P_T>::set_p(index_type row, index_type col, p_type y)
m_p[it] = y;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::add_a(index_type row, index_type col, a_type x)
{
......@@ -298,7 +298,7 @@ SparseArray<A_T, P_T>::add_a(index_type row, index_type col, a_type x)
m_a[it] += x;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::add_p(index_type row, index_type col, p_type y)
{
......@@ -309,7 +309,7 @@ SparseArray<A_T, P_T>::add_p(index_type row, index_type col, p_type y)
m_p[it] += y;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::invert(index_type row, index_type col)
{
......@@ -321,7 +321,7 @@ SparseArray<A_T, P_T>::invert(index_type row, index_type col)
m_p[it] = -m_p[it];
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::mult_p(index_type row, index_type col, p_type y)
{
......@@ -332,7 +332,7 @@ SparseArray<A_T, P_T>::mult_p(index_type row, index_type col, p_type y)
m_p[it] *= y;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::mult_row_p(index_type row, p_type y)
{
......@@ -342,8 +342,8 @@ SparseArray<A_T, P_T>::mult_row_p(index_type row, p_type y)
m_p[std::get<0>(i)->value] *= y;
}
template <typename A_T, typename P_T>
template <typename InputIterator>
template<typename A_T, typename P_T>
template<typename InputIterator>
void
SparseArray<A_T, P_T>::reserve(index_type elem,
InputIterator row_begin,
......@@ -368,7 +368,7 @@ SparseArray<A_T, P_T>::reserve(index_type elem,
}
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::sort() noexcept
{
......@@ -397,7 +397,7 @@ SparseArray<A_T, P_T>::sort() noexcept
}
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
typename SparseArray<A_T, P_T>::a_type
SparseArray<A_T, P_T>::A(index_type row, index_type col) const
{
......@@ -408,7 +408,7 @@ SparseArray<A_T, P_T>::A(index_type row, index_type col) const
return m_a[it];
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
typename SparseArray<A_T, P_T>::p_type
SparseArray<A_T, P_T>::P(index_type row, index_type col) const
{
......@@ -419,35 +419,35 @@ SparseArray<A_T, P_T>::P(index_type row, index_type col) const
return m_p[it];
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
typename std::vector<typename SparseArray<A_T, P_T>::a_type>&
SparseArray<A_T, P_T>::A()
{
return m_a;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
const typename std::vector<typename SparseArray<A_T, P_T>::a_type>&
SparseArray<A_T, P_T>::A() const
{
return m_a;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
typename std::vector<typename SparseArray<A_T, P_T>::p_type>&
SparseArray<A_T, P_T>::P()
{
return m_p;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
const typename std::vector<typename SparseArray<A_T, P_T>::p_type>&
SparseArray<A_T, P_T>::P() const
{
return m_p;
}
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::swap(SparseArray& c) noexcept(
noexcept(swap(m_a, c.m_a)) && noexcept(swap(m_p, c.m_p)) &&
......@@ -461,7 +461,7 @@ SparseArray<A_T, P_T>::swap(SparseArray& c) noexcept(
}
#ifndef LP_FULL_OPTIMIZATION
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void
SparseArray<A_T, P_T>::m_check_index(index_type row, index_type col) const
noexcept
......@@ -470,14 +470,14 @@ SparseArray<A_T, P_T>::m_check_index(index_type row, index_type col) const
Expects(row >= 0, "SparseArray: bad row access");
}
#else
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
void SparseArray<A_T, P_T>::m_check_index(index_type, index_type) const
noexcept
{
}
#endif
template <typename A_T, typename P_T>
template<typename A_T, typename P_T>
typename SparseArray<A_T, P_T>::index_type
SparseArray<A_T, P_T>::binary_find(
typename SparseArray<A_T, P_T>::index_type row,
......
......@@ -63,7 +63,7 @@ get_parameters(std::shared_ptr<baryonyx::context>& ctx) noexcept
return std::make_tuple(kappa, delta, theta, limit);
}
template <typename variableT>
template<typename variableT>
bool
is_boolean_variable(const variableT& vars)
{
......@@ -74,7 +74,7 @@ is_boolean_variable(const variableT& vars)
return true;
}
template <typename constraintsT>
template<typename constraintsT>
bool
is_boolean_coefficient(const constraintsT csts)
{
......@@ -86,7 +86,7 @@ is_boolean_coefficient(const constraintsT csts)
return true;
}
template <typename variableT>
template<typename variableT>
bool
is_integer_variable(const variableT& vars)
{
......@@ -97,7 +97,7 @@ is_integer_variable(const variableT& vars)
return true;
}
template <typename constraintsT>
template<typename constraintsT>
bool
is_101_coefficient(const constraintsT csts)
{
......@@ -109,7 +109,7 @@ is_101_coefficient(const constraintsT csts)
return true;
}
template <typename functionT>
template<typename functionT>
functionT
cleanup_function_element(functionT fct, long int& nb)
{
......
......@@ -27,9 +27,11 @@
<