refactor(util/lp): use Lean exception
This commit is contained in:
parent
8fbf66d01a
commit
d9acf90f7b
8 changed files with 235 additions and 259 deletions
|
@ -261,7 +261,7 @@ class lar_solver {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
throw "unexpected";
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ class lar_solver {
|
|||
case at_upper_bound: return upper_bound[j];
|
||||
case free_of_bounds: return zero_of_type<V>();
|
||||
default:
|
||||
throw "unexpected type";
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,10 +421,8 @@ public:
|
|||
case GE: return left_side_val >= constr.m_right_side;
|
||||
case GT: return left_side_val >= constr.m_right_side;
|
||||
case EQ: return left_side_val == constr.m_right_side;
|
||||
|
||||
default:
|
||||
throw "unexpected";
|
||||
return false;
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -833,8 +831,7 @@ public:
|
|||
return abs(left_side_val - norm_constr.m_right_side);
|
||||
|
||||
default:
|
||||
throw "unexpected";
|
||||
return numeric_traits<mpq>::zero();
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -748,7 +748,7 @@ public:
|
|||
case upper_bound:
|
||||
return at_upper_bound;
|
||||
default:
|
||||
throw "unexpected column type";
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1159,8 +1159,7 @@ public: // todo : move public lower ; it is for debug only
|
|||
slope_at_entering += delta;
|
||||
break;
|
||||
default:
|
||||
throw 1;
|
||||
lean_assert(false); // such a type does not exist
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1222,9 +1221,7 @@ public: // todo : move public lower ; it is for debug only
|
|||
return true;
|
||||
break;
|
||||
default:
|
||||
lean_assert(false);
|
||||
throw "cannot be here";
|
||||
break;
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,8 +340,7 @@ public:
|
|||
for (auto it : this->m_columns) {
|
||||
auto sol_it = solution.find(it.second->get_name());
|
||||
if (sol_it == solution.end()) {
|
||||
std::cout << "cannot find column " << it.first << " in solution " << std::endl;
|
||||
throw;
|
||||
throw exception(sstream() << "cannot find column " << it.first << " in solutio");
|
||||
}
|
||||
|
||||
if (!it.second->bounds_hold(sol_it->second)) {
|
||||
|
@ -356,8 +355,7 @@ public:
|
|||
T get_row_value(unsigned i, std::unordered_map<std::string, T> const & solution, bool print) {
|
||||
auto it = this->m_A_values.find(i);
|
||||
if (it == this->m_A_values.end()) {
|
||||
std::cout << "cannot find row " << i << std::endl;
|
||||
throw "get_row_value";
|
||||
throw exception(sstream() << "cannot find row " << i);
|
||||
}
|
||||
T ret = numeric_traits<T>::zero();
|
||||
for (auto & pair : it->second) {
|
||||
|
@ -414,8 +412,7 @@ public:
|
|||
}
|
||||
return true;;
|
||||
}
|
||||
std::cout << "throw in row_constraint_holds " << std::endl;
|
||||
throw "wrong case";
|
||||
lean_unreachable();
|
||||
}
|
||||
|
||||
bool row_constraints_hold(std::unordered_map<std::string, T> const & solution) {
|
||||
|
|
|
@ -35,7 +35,7 @@ inline std::string column_type_to_string(column_type t) {
|
|||
case free_column:
|
||||
return std::string("free_column");
|
||||
default:
|
||||
throw "unexpected";
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,7 @@ inline const char* lp_status_to_string(lp_status status) {
|
|||
case EMPTY: return "EMPTY";
|
||||
case UNSTABLE: return "UNSTABLE";
|
||||
default:
|
||||
std::cout << "throwing in lp_status_to_string " << std::endl;
|
||||
throw "lp_status_to_string";
|
||||
lean_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,8 +84,7 @@ inline lp_status lp_status_from_string(std::string status) {
|
|||
if (status == "TIME_EXHAUSTED") return lp_status::TIME_EXHAUSTED;
|
||||
if (status == "ITERATIONS_EXHAUSTED") return lp_status::ITERATIONS_EXHAUSTED;
|
||||
if (status == "EMPTY") return lp_status::EMPTY;
|
||||
std::cout << "unexpected status " << status << std::endl;
|
||||
throw "wrong status in a test file";
|
||||
lean_unreachable();
|
||||
}
|
||||
|
||||
enum non_basic_column_value_position { at_low_bound, at_upper_bound, at_fixed, free_of_bounds };
|
||||
|
|
|
@ -6,15 +6,16 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/lp/lp_settings.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "util/exception.h"
|
||||
#include "util/sstream.h"
|
||||
#include "util/lp/lp_settings.h"
|
||||
#include "util/lp/column_info.h"
|
||||
#include "util/lp/static_matrix.h"
|
||||
#include <algorithm>
|
||||
#include "util/lp/lp_core_solver_base.h"
|
||||
#include <vector>
|
||||
#include "util/lp/scaler.h"
|
||||
namespace lean {
|
||||
enum lp_relation {
|
||||
|
@ -109,8 +110,7 @@ public:
|
|||
T get_column_value_by_name(std::string name) const {
|
||||
auto it = m_names_to_columns.find(name);
|
||||
if (it == m_names_to_columns.end()) {
|
||||
std::cout << "throwing in get_column_value_by_name" << std::endl;
|
||||
throw "get_column_value_by_name";
|
||||
throw exception(sstream() << "get_column_value_by_name " << name);
|
||||
}
|
||||
return get_column_value(it -> second);
|
||||
}
|
||||
|
@ -435,11 +435,9 @@ protected:
|
|||
case lp_relation::Less_or_equal:
|
||||
return row_le_is_obsolete(row, row_index);
|
||||
}
|
||||
|
||||
throw "unexpected relation";
|
||||
lean_unreachable();
|
||||
}
|
||||
|
||||
|
||||
void remove_fixed_or_zero_columns() {
|
||||
for (auto & i_row : m_A_values) {
|
||||
remove_fixed_or_zero_columns_from_row(i_row.first, i_row.second);
|
||||
|
@ -515,8 +513,7 @@ protected:
|
|||
for (auto & row : m_A_values) {
|
||||
for (auto & col : row.second) {
|
||||
if (col.second == numeric_traits<T>::zero() || m_columns[col.first]->is_fixed()) {
|
||||
std::cout << "found fixed column " << std::endl;
|
||||
throw "map_external_columns_to_core_solver_columns";
|
||||
throw exception("found fixed column");
|
||||
}
|
||||
unsigned j = col.first;
|
||||
auto j_place = m_external_columns_to_core_solver_columns.find(j);
|
||||
|
@ -615,7 +612,7 @@ protected:
|
|||
|
||||
auto row = this->m_A_values.find(i);
|
||||
if (row == this->m_A_values.end()) {
|
||||
throw "cannot find row ";
|
||||
throw exception("cannot find row");
|
||||
}
|
||||
for (auto col : row->second) {
|
||||
ret += col.second * this->m_columns[col.first]->get_shift();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
Author: Lev Nachmanson
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
@ -19,8 +18,8 @@ namespace lean {
|
|||
struct convert_struct {
|
||||
static X convert(const Y & y){ return X(y);}
|
||||
static bool is_epsilon_small(const X & x, const double & y) { return abs(get_double(x)) < y; }
|
||||
static bool below_bound_numeric(const X &, const X &, const Y &) { throw "don't call";}
|
||||
static bool above_bound_numeric(const X &, const X &, const Y &) { throw "don't call";}
|
||||
static bool below_bound_numeric(const X &, const X &, const Y &) { lean_unreachable(); }
|
||||
static bool above_bound_numeric(const X &, const X &, const Y &) { lean_unreachable(); }
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,7 +73,7 @@ namespace lean {
|
|||
}
|
||||
|
||||
numeric_pair operator/(const numeric_pair &) const {
|
||||
throw "should not be called";
|
||||
lean_unreachable();
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,10 +82,9 @@ namespace lean {
|
|||
}
|
||||
|
||||
numeric_pair operator*(const numeric_pair & /*a*/) const {
|
||||
throw "should not be called";
|
||||
lean_unreachable();
|
||||
}
|
||||
|
||||
|
||||
numeric_pair& operator+=(const numeric_pair & a) {
|
||||
x += a.x;
|
||||
y += a.y;
|
||||
|
@ -145,7 +143,7 @@ namespace lean {
|
|||
|
||||
|
||||
// template <numeric_pair, typename T> bool precise() { return numeric_traits<T>::precise();}
|
||||
template <typename T> double get_double(const numeric_pair<T> & ) { throw "do not call"; }
|
||||
template <typename T> double get_double(const numeric_pair<T> & ) { lean_unreachable(); }
|
||||
template <typename T>
|
||||
class numeric_traits<numeric_pair<T>> {
|
||||
public:
|
||||
|
@ -153,7 +151,7 @@ namespace lean {
|
|||
static numeric_pair<T> zero() { return numeric_pair<T>(numeric_traits<T>::zero(), numeric_traits<T>::zero()); }
|
||||
static bool is_zero(const numeric_pair<T> & v) { return numeric_traits<T>::is_zero(v.x) && numeric_traits<T>::is_zero(v.y); }
|
||||
static double get_double(const numeric_pair<T> & v){ return numeric_traits<T>::get_double(v.x); } // just return the double of the first coordinate
|
||||
static double one() { throw "do not call"; }
|
||||
static double one() { lean_unreachable(); }
|
||||
};
|
||||
template <>
|
||||
struct convert_struct<double, numeric_pair<double>> {
|
||||
|
@ -171,10 +169,10 @@ namespace lean {
|
|||
return convert_struct<T, double>::is_epsilon_small(p.x, eps) && convert_struct<T, double>::is_epsilon_small(p.y, eps);
|
||||
}
|
||||
static bool below_bound_numeric(const numeric_pair<T> &, const numeric_pair<T> &, const double &) {
|
||||
throw "do not call";
|
||||
lean_unreachable();
|
||||
}
|
||||
static bool above_bound_numeric(const numeric_pair<T> &, const numeric_pair<T> &, const double &) {
|
||||
throw "do not call";
|
||||
lean_unreachable();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include "util/numerics/numeric_traits.h"
|
||||
#include "util/numerics/xnumeral.h"
|
||||
#include "util/numerics/mpq.h"
|
||||
|
@ -15,10 +18,7 @@
|
|||
#include "util/numerics/double.h"
|
||||
#include "util/numerics/float.h"
|
||||
#include "util/numerics/mpfp.h"
|
||||
#include <set>
|
||||
#include "util/lp/sparse_vector.h"
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include "util/lp/matrix_domain.h"
|
||||
#include "util/lp/indexed_vector.h"
|
||||
|
||||
|
@ -48,8 +48,6 @@ private:
|
|||
T m_value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// each assignment for this matrix should be issued only once!!!
|
||||
template <typename T, typename X>
|
||||
class static_matrix
|
||||
|
@ -461,15 +459,9 @@ public:
|
|||
virtual void set_number_of_rows(unsigned /*m*/) { }
|
||||
virtual void set_number_of_columns(unsigned /*n*/) { }
|
||||
#endif
|
||||
// const T & get_value_of_column_cell(column_cell<T> const & cc) const {
|
||||
// lean_assert(cc.m_i < m_rows.size());
|
||||
// lean_assert(cc.m_offset < m_rows[cc.m_i].size());
|
||||
// return m_rows[cc.m_i][cc.m_offset].get_val();
|
||||
// }
|
||||
|
||||
T get_max_val_in_row(unsigned i) const {
|
||||
lean_assert(false);
|
||||
throw 0;// not implemented
|
||||
lean_unreachable();
|
||||
}
|
||||
|
||||
T get_balance() const {
|
||||
|
|
Loading…
Reference in a new issue