3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-16 05:48:44 +00:00

replace lean to lp

Signed-off-by: Lev Nachmanson <levnach@microsoft.com>
This commit is contained in:
Lev Nachmanson 2017-07-10 11:06:37 -07:00
parent f6a75600c2
commit cc32e45471
117 changed files with 1726 additions and 1726 deletions

View file

@ -17,7 +17,7 @@ Author:
#include "gparams.h" #include "gparams.h"
#include <signal.h> #include <signal.h>
static lean::lp_solver<double, double>* g_solver = 0; static lp::lp_solver<double, double>* g_solver = 0;
static void display_statistics() { static void display_statistics() {
if (g_solver && g_solver->settings().print_statistics) { if (g_solver && g_solver->settings().print_statistics) {
@ -42,7 +42,7 @@ static void on_timeout() {
} }
} }
struct front_end_resource_limit : public lean::lp_resource_limit { struct front_end_resource_limit : public lp::lp_resource_limit {
reslimit& m_reslim; reslimit& m_reslim;
front_end_resource_limit(reslimit& lim): front_end_resource_limit(reslimit& lim):
@ -64,14 +64,14 @@ void run_solver(lp_params & params, char const * mps_file_name) {
scoped_timer timer(timeout, &eh); scoped_timer timer(timeout, &eh);
std::string fn(mps_file_name); std::string fn(mps_file_name);
lean::mps_reader<double, double> reader(fn); lp::mps_reader<double, double> reader(fn);
reader.set_message_stream(&std::cout); // can be redirected reader.set_message_stream(&std::cout); // can be redirected
reader.read(); reader.read();
if (!reader.is_ok()) { if (!reader.is_ok()) {
std::cerr << "cannot process " << mps_file_name << std::endl; std::cerr << "cannot process " << mps_file_name << std::endl;
return; return;
} }
lean::lp_solver<double, double> * solver = reader.create_solver(false); // false - to create the primal solver lp::lp_solver<double, double> * solver = reader.create_solver(false); // false - to create the primal solver
solver->settings().set_resource_limit(lp_limit); solver->settings().set_resource_limit(lp_limit);
g_solver = solver; g_solver = solver;
if (params.min()) { if (params.min()) {
@ -80,11 +80,11 @@ void run_solver(lp_params & params, char const * mps_file_name) {
solver->settings().set_message_ostream(&std::cout); solver->settings().set_message_ostream(&std::cout);
solver->settings().report_frequency = params.rep_freq(); solver->settings().report_frequency = params.rep_freq();
solver->settings().print_statistics = params.print_stats(); solver->settings().print_statistics = params.print_stats();
solver->settings().simplex_strategy() = lean::simplex_strategy_enum::lu; solver->settings().simplex_strategy() = lp::simplex_strategy_enum::lu;
solver->find_maximal_solution(); solver->find_maximal_solution();
*(solver->settings().get_message_ostream()) << "status is " << lp_status_to_string(solver->get_status()) << std::endl; *(solver->settings().get_message_ostream()) << "status is " << lp_status_to_string(solver->get_status()) << std::endl;
if (solver->get_status() == lean::OPTIMAL) { if (solver->get_status() == lp::OPTIMAL) {
if (params.min()) { if (params.min()) {
solver->flip_costs(); solver->flip_costs();
} }

View file

@ -40,7 +40,7 @@ Revision History:
#include "math/polynomial/algebraic_numbers.h" #include "math/polynomial/algebraic_numbers.h"
#include "math/polynomial/polynomial.h" #include "math/polynomial/polynomial.h"
namespace lp { namespace lp_api {
enum bound_kind { lower_t, upper_t }; enum bound_kind { lower_t, upper_t };
std::ostream& operator<<(std::ostream& out, bound_kind const& k) { std::ostream& operator<<(std::ostream& out, bound_kind const& k) {
@ -118,7 +118,7 @@ namespace lp {
namespace smt { namespace smt {
typedef ptr_vector<lp::bound> lp_bounds; typedef ptr_vector<lp_api::bound> lp_bounds;
class theory_lra::imp { class theory_lra::imp {
@ -137,7 +137,7 @@ namespace smt {
delayed_atom(unsigned b, bool t): m_bv(b), m_is_true(t) {} delayed_atom(unsigned b, bool t): m_bv(b), m_is_true(t) {}
}; };
class resource_limit : public lean::lp_resource_limit { class resource_limit : public lp::lp_resource_limit {
imp& m_imp; imp& m_imp;
public: public:
resource_limit(imp& i): m_imp(i) { } resource_limit(imp& i): m_imp(i) { }
@ -202,13 +202,13 @@ namespace smt {
} }
}; };
typedef vector<std::pair<rational, lean::var_index>> var_coeffs; typedef vector<std::pair<rational, lp::var_index>> var_coeffs;
svector<lean::var_index> m_theory_var2var_index; // translate from theory variables to lar vars svector<lp::var_index> m_theory_var2var_index; // translate from theory variables to lar vars
svector<theory_var> m_var_index2theory_var; // reverse map from lp_solver variables to theory variables svector<theory_var> m_var_index2theory_var; // reverse map from lp_solver variables to theory variables
svector<theory_var> m_term_index2theory_var; // reverse map from lp_solver variables to theory variables svector<theory_var> m_term_index2theory_var; // reverse map from lp_solver variables to theory variables
var_coeffs m_left_side; // constraint left side var_coeffs m_left_side; // constraint left side
mutable std::unordered_map<lean::var_index, rational> m_variable_values; // current model mutable std::unordered_map<lp::var_index, rational> m_variable_values; // current model
enum constraint_source { enum constraint_source {
inequality_source, inequality_source,
@ -225,10 +225,10 @@ namespace smt {
expr* m_not_handled; expr* m_not_handled;
ptr_vector<app> m_underspecified; ptr_vector<app> m_underspecified;
unsigned_vector m_var_trail; unsigned_vector m_var_trail;
vector<ptr_vector<lp::bound> > m_use_list; // bounds where variables are used. vector<ptr_vector<lp_api::bound> > m_use_list; // bounds where variables are used.
// attributes for incremental version: // attributes for incremental version:
u_map<lp::bound*> m_bool_var2bound; u_map<lp_api::bound*> m_bool_var2bound;
vector<lp_bounds> m_bounds; vector<lp_bounds> m_bounds;
unsigned_vector m_unassigned_bounds; unsigned_vector m_unassigned_bounds;
unsigned_vector m_bounds_trail; unsigned_vector m_bounds_trail;
@ -247,7 +247,7 @@ namespace smt {
scoped_ptr<scoped_anum> m_a1, m_a2; scoped_ptr<scoped_anum> m_a1, m_a2;
// integer arithmetic // integer arithmetic
scoped_ptr<lean::int_solver> m_lia; scoped_ptr<lp::int_solver> m_lia;
struct var_value_eq { struct var_value_eq {
@ -268,7 +268,7 @@ namespace smt {
return m_th.is_int(v); return m_th.is_int(v);
} }
else { else {
return (unsigned)std::hash<lean::impq>()(m_th.get_ivalue(v)); return (unsigned)std::hash<lp::impq>()(m_th.get_ivalue(v));
} }
} }
}; };
@ -276,9 +276,9 @@ namespace smt {
svector<scope> m_scopes; svector<scope> m_scopes;
lp::stats m_stats; lp_api::stats m_stats;
arith_factory* m_factory; arith_factory* m_factory;
scoped_ptr<lean::lar_solver> m_solver; scoped_ptr<lp::lar_solver> m_solver;
resource_limit m_resource_limit; resource_limit m_resource_limit;
lp_bounds m_new_bounds; lp_bounds m_new_bounds;
@ -294,15 +294,15 @@ namespace smt {
void init_solver() { void init_solver() {
if (m_solver) return; if (m_solver) return;
lp_params lp(ctx().get_params()); lp_params lp(ctx().get_params());
m_solver = alloc(lean::lar_solver); m_solver = alloc(lp::lar_solver);
m_theory_var2var_index.reset(); m_theory_var2var_index.reset();
m_solver->settings().set_resource_limit(m_resource_limit); m_solver->settings().set_resource_limit(m_resource_limit);
m_solver->settings().simplex_strategy() = static_cast<lean::simplex_strategy_enum>(lp.simplex_strategy()); m_solver->settings().simplex_strategy() = static_cast<lp::simplex_strategy_enum>(lp.simplex_strategy());
reset_variable_values(); reset_variable_values();
m_solver->settings().bound_propagation() = BP_NONE != propagation_mode(); m_solver->settings().bound_propagation() = BP_NONE != propagation_mode();
m_solver->set_propagate_bounds_on_pivoted_rows_mode(lp.bprop_on_pivoted_rows()); m_solver->set_propagate_bounds_on_pivoted_rows_mode(lp.bprop_on_pivoted_rows());
//m_solver->settings().set_ostream(0); //m_solver->settings().set_ostream(0);
m_lia = alloc(lean::int_solver, m_solver.get()); m_lia = alloc(lp::int_solver, m_solver.get());
} }
void ensure_nra() { void ensure_nra() {
@ -454,7 +454,7 @@ namespace smt {
r = rational::one(); r = rational::one();
rational r1; rational r1;
v = mk_var(t); v = mk_var(t);
svector<lean::var_index> vars; svector<lp::var_index> vars;
ptr_vector<expr> todo; ptr_vector<expr> todo;
todo.push_back(t); todo.push_back(t);
while (!todo.empty()) { while (!todo.empty()) {
@ -556,8 +556,8 @@ namespace smt {
return v; return v;
} }
lean::var_index get_var_index(theory_var v) { lp::var_index get_var_index(theory_var v) {
lean::var_index result = UINT_MAX; lp::var_index result = UINT_MAX;
if (m_theory_var2var_index.size() > static_cast<unsigned>(v)) { if (m_theory_var2var_index.size() > static_cast<unsigned>(v)) {
result = m_theory_var2var_index[v]; result = m_theory_var2var_index[v];
} }
@ -606,20 +606,20 @@ namespace smt {
return true; return true;
} }
void add_eq_constraint(lean::constraint_index index, enode* n1, enode* n2) { void add_eq_constraint(lp::constraint_index index, enode* n1, enode* n2) {
m_constraint_sources.setx(index, equality_source, null_source); m_constraint_sources.setx(index, equality_source, null_source);
m_equalities.setx(index, enode_pair(n1, n2), enode_pair(0, 0)); m_equalities.setx(index, enode_pair(n1, n2), enode_pair(0, 0));
++m_stats.m_add_rows; ++m_stats.m_add_rows;
} }
void add_ineq_constraint(lean::constraint_index index, literal lit) { void add_ineq_constraint(lp::constraint_index index, literal lit) {
m_constraint_sources.setx(index, inequality_source, null_source); m_constraint_sources.setx(index, inequality_source, null_source);
m_inequalities.setx(index, lit, null_literal); m_inequalities.setx(index, lit, null_literal);
++m_stats.m_add_rows; ++m_stats.m_add_rows;
TRACE("arith", m_solver->print_constraint(index, tout); tout << "\n";); TRACE("arith", m_solver->print_constraint(index, tout); tout << "\n";);
} }
void add_def_constraint(lean::constraint_index index, theory_var v) { void add_def_constraint(lp::constraint_index index, theory_var v) {
m_constraint_sources.setx(index, definition_source, null_source); m_constraint_sources.setx(index, definition_source, null_source);
m_definitions.setx(index, v, null_theory_var); m_definitions.setx(index, v, null_theory_var);
++m_stats.m_add_rows; ++m_stats.m_add_rows;
@ -634,7 +634,7 @@ namespace smt {
st.coeffs().push_back(rational::one()); st.coeffs().push_back(rational::one());
st.coeffs().push_back(rational::minus_one()); st.coeffs().push_back(rational::minus_one());
init_left_side(st); init_left_side(st);
add_eq_constraint(m_solver->add_constraint(m_left_side, lean::EQ, rational::zero()), n1, n2); add_eq_constraint(m_solver->add_constraint(m_left_side, lp::EQ, rational::zero()), n1, n2);
TRACE("arith", TRACE("arith",
tout << "v" << v1 << " = " << "v" << v2 << ": " tout << "v" << v1 << " = " << "v" << v2 << ": "
<< mk_pp(n1->get_owner(), m) << " = " << mk_pp(n2->get_owner(), m) << "\n";); << mk_pp(n1->get_owner(), m) << " = " << mk_pp(n2->get_owner(), m) << "\n";);
@ -644,7 +644,7 @@ namespace smt {
for (unsigned i = m_bounds_trail.size(); i > old_size; ) { for (unsigned i = m_bounds_trail.size(); i > old_size; ) {
--i; --i;
unsigned v = m_bounds_trail[i]; unsigned v = m_bounds_trail[i];
lp::bound* b = m_bounds[v].back(); lp_api::bound* b = m_bounds[v].back();
// del_use_lists(b); // del_use_lists(b);
dealloc(b); dealloc(b);
m_bounds[v].pop_back(); m_bounds[v].pop_back();
@ -687,7 +687,7 @@ namespace smt {
else { else {
init_left_side(st); init_left_side(st);
theory_var v = mk_var(term); theory_var v = mk_var(term);
lean::var_index vi = m_theory_var2var_index.get(v, UINT_MAX); lp::var_index vi = m_theory_var2var_index.get(v, UINT_MAX);
if (vi == UINT_MAX) { if (vi == UINT_MAX) {
vi = m_solver->add_term(m_left_side, st.coeff()); vi = m_solver->add_term(m_left_side, st.coeff());
m_theory_var2var_index.setx(v, vi, UINT_MAX); m_theory_var2var_index.setx(v, vi, UINT_MAX);
@ -747,22 +747,22 @@ namespace smt {
ctx().set_var_theory(bv, get_id()); ctx().set_var_theory(bv, get_id());
expr* n1, *n2; expr* n1, *n2;
rational r; rational r;
lp::bound_kind k; lp_api::bound_kind k;
theory_var v = null_theory_var; theory_var v = null_theory_var;
if (a.is_le(atom, n1, n2) && is_numeral(n2, r) && is_app(n1)) { if (a.is_le(atom, n1, n2) && is_numeral(n2, r) && is_app(n1)) {
v = internalize_def(to_app(n1)); v = internalize_def(to_app(n1));
k = lp::upper_t; k = lp_api::upper_t;
} }
else if (a.is_ge(atom, n1, n2) && is_numeral(n2, r) && is_app(n1)) { else if (a.is_ge(atom, n1, n2) && is_numeral(n2, r) && is_app(n1)) {
v = internalize_def(to_app(n1)); v = internalize_def(to_app(n1));
k = lp::lower_t; k = lp_api::lower_t;
} }
else { else {
TRACE("arith", tout << "Could not internalize " << mk_pp(atom, m) << "\n";); TRACE("arith", tout << "Could not internalize " << mk_pp(atom, m) << "\n";);
found_not_handled(atom); found_not_handled(atom);
return true; return true;
} }
lp::bound* b = alloc(lp::bound, bv, v, is_int(v), r, k); lp_api::bound* b = alloc(lp_api::bound, bv, v, is_int(v), r, k);
m_bounds[v].push_back(b); m_bounds[v].push_back(b);
updt_unassigned_bounds(v, +1); updt_unassigned_bounds(v, +1);
m_bounds_trail.push_back(v); m_bounds_trail.push_back(v);
@ -836,7 +836,7 @@ namespace smt {
unsigned old_size = m_scopes.size() - num_scopes; unsigned old_size = m_scopes.size() - num_scopes;
del_bounds(m_scopes[old_size].m_bounds_lim); del_bounds(m_scopes[old_size].m_bounds_lim);
for (unsigned i = m_scopes[old_size].m_var_trail_lim; i < m_var_trail.size(); ++i) { for (unsigned i = m_scopes[old_size].m_var_trail_lim; i < m_var_trail.size(); ++i) {
lean::var_index vi = m_theory_var2var_index[m_var_trail[i]]; lp::var_index vi = m_theory_var2var_index[m_var_trail[i]];
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
unsigned ti = m_solver->adjust_term_index(vi); unsigned ti = m_solver->adjust_term_index(vi);
m_term_index2theory_var[ti] = UINT_MAX; m_term_index2theory_var[ti] = UINT_MAX;
@ -1027,14 +1027,14 @@ namespace smt {
return m_solver->var_is_registered(m_theory_var2var_index[v]); return m_solver->var_is_registered(m_theory_var2var_index[v]);
} }
lean::impq get_ivalue(theory_var v) const { lp::impq get_ivalue(theory_var v) const {
lean_assert(can_get_ivalue(v)); lp_assert(can_get_ivalue(v));
lean::var_index vi = m_theory_var2var_index[v]; lp::var_index vi = m_theory_var2var_index[v];
if (!m_solver->is_term(vi)) if (!m_solver->is_term(vi))
return m_solver->get_value(vi); return m_solver->get_value(vi);
const lean::lar_term& term = m_solver->get_term(vi); const lp::lar_term& term = m_solver->get_term(vi);
lean::impq result(term.m_v); lp::impq result(term.m_v);
for (const auto & i: term.m_coeffs) { for (const auto & i: term.m_coeffs) {
result += m_solver->get_value(i.first) * i.second; result += m_solver->get_value(i.first) * i.second;
} }
@ -1044,12 +1044,12 @@ namespace smt {
rational get_value(theory_var v) const { rational get_value(theory_var v) const {
if (!can_get_value(v)) return rational::zero(); if (!can_get_value(v)) return rational::zero();
lean::var_index vi = m_theory_var2var_index[v]; lp::var_index vi = m_theory_var2var_index[v];
if (m_variable_values.count(vi) > 0) { if (m_variable_values.count(vi) > 0) {
return m_variable_values[vi]; return m_variable_values[vi];
} }
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
const lean::lar_term& term = m_solver->get_term(vi); const lp::lar_term& term = m_solver->get_term(vi);
rational result = term.m_v; rational result = term.m_v;
for (auto i = term.m_coeffs.begin(); i != term.m_coeffs.end(); ++i) { for (auto i = term.m_coeffs.begin(); i != term.m_coeffs.end(); ++i) {
result += m_variable_values[i->first] * i->second; result += m_variable_values[i->first] * i->second;
@ -1072,7 +1072,7 @@ namespace smt {
} }
bool assume_eqs() { bool assume_eqs() {
svector<lean::var_index> vars; svector<lp::var_index> vars;
theory_var sz = static_cast<theory_var>(th.get_num_vars()); theory_var sz = static_cast<theory_var>(th.get_num_vars());
for (theory_var v = 0; v < sz; ++v) { for (theory_var v = 0; v < sz; ++v) {
if (th.is_relevant_and_shared(get_enode(v))) { if (th.is_relevant_and_shared(get_enode(v))) {
@ -1167,7 +1167,7 @@ namespace smt {
final_check_status final_check_eh() { final_check_status final_check_eh() {
m_use_nra_model = false; m_use_nra_model = false;
lbool is_sat = l_true; lbool is_sat = l_true;
if (m_solver->get_status() != lean::lp_status::OPTIMAL) { if (m_solver->get_status() != lp::lp_status::OPTIMAL) {
is_sat = make_feasible(); is_sat = make_feasible();
} }
final_check_status st = FC_DONE; final_check_status st = FC_DONE;
@ -1223,7 +1223,7 @@ namespace smt {
} }
// create a bound atom representing term <= k // create a bound atom representing term <= k
app_ref mk_bound(lean::lar_term const& term, rational const& k) { app_ref mk_bound(lp::lar_term const& term, rational const& k) {
SASSERT(k.is_int()); SASSERT(k.is_int());
app_ref t = mk_term(term, true); app_ref t = mk_term(term, true);
app_ref atom(a.mk_le(t, a.mk_numeral(k, true)), m); app_ref atom(a.mk_le(t, a.mk_numeral(k, true)), m);
@ -1238,20 +1238,20 @@ namespace smt {
lbool check_lia() { lbool check_lia() {
if (m.canceled()) return l_undef; if (m.canceled()) return l_undef;
lean::lar_term term; lp::lar_term term;
lean::mpq k; lp::mpq k;
lean::explanation ex; // TBD, this should be streamlined accross different explanations lp::explanation ex; // TBD, this should be streamlined accross different explanations
switch(m_lia->check(term, k, ex)) { switch(m_lia->check(term, k, ex)) {
case lean::lia_move::ok: case lp::lia_move::ok:
return l_true; return l_true;
case lean::lia_move::branch: { case lp::lia_move::branch: {
(void)mk_bound(term, k); (void)mk_bound(term, k);
// branch on term <= k // branch on term <= k
// at this point we have a new unassigned atom that the // at this point we have a new unassigned atom that the
// SAT core assigns a value to // SAT core assigns a value to
return l_false; return l_false;
} }
case lean::lia_move::cut: { case lp::lia_move::cut: {
// m_explanation implies term <= k // m_explanation implies term <= k
app_ref b = mk_bound(term, k); app_ref b = mk_bound(term, k);
m_eqs.reset(); m_eqs.reset();
@ -1265,12 +1265,12 @@ namespace smt {
assign(literal(ctx().get_bool_var(b), false)); assign(literal(ctx().get_bool_var(b), false));
return l_false; return l_false;
} }
case lean::lia_move::conflict: case lp::lia_move::conflict:
// ex contains unsat core // ex contains unsat core
m_explanation = ex.m_explanation; m_explanation = ex.m_explanation;
set_conflict1(); set_conflict1();
return l_false; return l_false;
case lean::lia_move::give_up: case lp::lia_move::give_up:
TRACE("arith", tout << "lia giveup\n";); TRACE("arith", tout << "lia giveup\n";);
return l_undef; return l_undef;
default: default:
@ -1375,7 +1375,7 @@ namespace smt {
#else #else
propagate_bound(bv, is_true, b); propagate_bound(bv, is_true, b);
#endif #endif
lp::bound& b = *m_bool_var2bound.find(bv); lp_api::bound& b = *m_bool_var2bound.find(bv);
assert_bound(bv, is_true, b); assert_bound(bv, is_true, b);
@ -1388,7 +1388,7 @@ namespace smt {
/*for (; qhead < m_asserted_atoms.size() && !ctx().inconsistent(); ++qhead) { /*for (; qhead < m_asserted_atoms.size() && !ctx().inconsistent(); ++qhead) {
bool_var bv = m_asserted_atoms[qhead].m_bv; bool_var bv = m_asserted_atoms[qhead].m_bv;
bool is_true = m_asserted_atoms[qhead].m_is_true; bool is_true = m_asserted_atoms[qhead].m_is_true;
lp::bound& b = *m_bool_var2bound.find(bv); lp_api::bound& b = *m_bool_var2bound.find(bv);
propagate_bound_compound(bv, is_true, b); propagate_bound_compound(bv, is_true, b);
}*/ }*/
@ -1421,7 +1421,7 @@ namespace smt {
} }
int new_num_of_p = m_solver->settings().st().m_num_of_implied_bounds; int new_num_of_p = m_solver->settings().st().m_num_of_implied_bounds;
CTRACE("arith", new_num_of_p > num_of_p, tout << "found " << new_num_of_p << " implied bounds\n";); CTRACE("arith", new_num_of_p > num_of_p, tout << "found " << new_num_of_p << " implied bounds\n";);
if (m_solver->get_status() == lean::lp_status::INFEASIBLE) { if (m_solver->get_status() == lp::lp_status::INFEASIBLE) {
set_conflict(); set_conflict();
} }
else { else {
@ -1431,7 +1431,7 @@ namespace smt {
} }
} }
bool bound_is_interesting(unsigned vi, lean::lconstraint_kind kind, const rational & bval) const { bool bound_is_interesting(unsigned vi, lp::lconstraint_kind kind, const rational & bval) const {
theory_var v; theory_var v;
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
v = m_term_index2theory_var.get(m_solver->adjust_term_index(vi), null_theory_var); v = m_term_index2theory_var.get(m_solver->adjust_term_index(vi), null_theory_var);
@ -1448,7 +1448,7 @@ namespace smt {
} }
lp_bounds const& bounds = m_bounds[v]; lp_bounds const& bounds = m_bounds[v];
for (unsigned i = 0; i < bounds.size(); ++i) { for (unsigned i = 0; i < bounds.size(); ++i) {
lp::bound* b = bounds[i]; lp_api::bound* b = bounds[i];
if (ctx().get_assignment(b->get_bv()) != l_undef) { if (ctx().get_assignment(b->get_bv()) != l_undef) {
continue; continue;
} }
@ -1461,11 +1461,11 @@ namespace smt {
return false; return false;
} }
struct local_bound_propagator: public lean::bound_propagator { struct local_bound_propagator: public lp::bound_propagator {
imp & m_imp; imp & m_imp;
local_bound_propagator(imp& i) : bound_propagator(*i.m_solver), m_imp(i) {} local_bound_propagator(imp& i) : bound_propagator(*i.m_solver), m_imp(i) {}
bool bound_is_interesting(unsigned j, lean::lconstraint_kind kind, const rational & v) { bool bound_is_interesting(unsigned j, lp::lconstraint_kind kind, const rational & v) {
return m_imp.bound_is_interesting(j, kind, v); return m_imp.bound_is_interesting(j, kind, v);
} }
@ -1475,10 +1475,10 @@ namespace smt {
}; };
void propagate_lp_solver_bound(lean::implied_bound& be) { void propagate_lp_solver_bound(lp::implied_bound& be) {
theory_var v; theory_var v;
lean::var_index vi = be.m_j; lp::var_index vi = be.m_j;
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
v = m_term_index2theory_var.get(m_solver->adjust_term_index(vi), null_theory_var); v = m_term_index2theory_var.get(m_solver->adjust_term_index(vi), null_theory_var);
} }
@ -1499,7 +1499,7 @@ namespace smt {
lp_bounds const& bounds = m_bounds[v]; lp_bounds const& bounds = m_bounds[v];
bool first = true; bool first = true;
for (unsigned i = 0; i < bounds.size(); ++i) { for (unsigned i = 0; i < bounds.size(); ++i) {
lp::bound* b = bounds[i]; lp_api::bound* b = bounds[i];
if (ctx().get_assignment(b->get_bv()) != l_undef) { if (ctx().get_assignment(b->get_bv()) != l_undef) {
continue; continue;
} }
@ -1562,28 +1562,28 @@ namespace smt {
} }
} }
literal is_bound_implied(lean::lconstraint_kind k, rational const& value, lp::bound const& b) const { literal is_bound_implied(lp::lconstraint_kind k, rational const& value, lp_api::bound const& b) const {
if ((k == lean::LE || k == lean::LT) && b.get_bound_kind() == lp::upper_t && value <= b.get_value()) { if ((k == lp::LE || k == lp::LT) && b.get_bound_kind() == lp_api::upper_t && value <= b.get_value()) {
// v <= value <= b.get_value() => v <= b.get_value() // v <= value <= b.get_value() => v <= b.get_value()
return literal(b.get_bv(), false); return literal(b.get_bv(), false);
} }
if ((k == lean::GE || k == lean::GT) && b.get_bound_kind() == lp::lower_t && b.get_value() <= value) { if ((k == lp::GE || k == lp::GT) && b.get_bound_kind() == lp_api::lower_t && b.get_value() <= value) {
// b.get_value() <= value <= v => b.get_value() <= v // b.get_value() <= value <= v => b.get_value() <= v
return literal(b.get_bv(), false); return literal(b.get_bv(), false);
} }
if (k == lean::LE && b.get_bound_kind() == lp::lower_t && value < b.get_value()) { if (k == lp::LE && b.get_bound_kind() == lp_api::lower_t && value < b.get_value()) {
// v <= value < b.get_value() => v < b.get_value() // v <= value < b.get_value() => v < b.get_value()
return literal(b.get_bv(), true); return literal(b.get_bv(), true);
} }
if (k == lean::LT && b.get_bound_kind() == lp::lower_t && value <= b.get_value()) { if (k == lp::LT && b.get_bound_kind() == lp_api::lower_t && value <= b.get_value()) {
// v < value <= b.get_value() => v < b.get_value() // v < value <= b.get_value() => v < b.get_value()
return literal(b.get_bv(), true); return literal(b.get_bv(), true);
} }
if (k == lean::GE && b.get_bound_kind() == lp::upper_t && b.get_value() < value) { if (k == lp::GE && b.get_bound_kind() == lp_api::upper_t && b.get_value() < value) {
// b.get_value() < value <= v => b.get_value() < v // b.get_value() < value <= v => b.get_value() < v
return literal(b.get_bv(), true); return literal(b.get_bv(), true);
} }
if (k == lean::GT && b.get_bound_kind() == lp::upper_t && b.get_value() <= value) { if (k == lp::GT && b.get_bound_kind() == lp_api::upper_t && b.get_value() <= value) {
// b.get_value() <= value < v => b.get_value() < v // b.get_value() <= value < v => b.get_value() < v
return literal(b.get_bv(), true); return literal(b.get_bv(), true);
} }
@ -1591,7 +1591,7 @@ namespace smt {
return null_literal; return null_literal;
} }
void mk_bound_axioms(lp::bound& b) { void mk_bound_axioms(lp_api::bound& b) {
if (!ctx().is_searching()) { if (!ctx().is_searching()) {
// //
// NB. We make an assumption that user push calls propagation // NB. We make an assumption that user push calls propagation
@ -1602,19 +1602,19 @@ namespace smt {
return; return;
} }
theory_var v = b.get_var(); theory_var v = b.get_var();
lp::bound_kind kind1 = b.get_bound_kind(); lp_api::bound_kind kind1 = b.get_bound_kind();
rational const& k1 = b.get_value(); rational const& k1 = b.get_value();
lp_bounds & bounds = m_bounds[v]; lp_bounds & bounds = m_bounds[v];
lp::bound* end = 0; lp_api::bound* end = 0;
lp::bound* lo_inf = end, *lo_sup = end; lp_api::bound* lo_inf = end, *lo_sup = end;
lp::bound* hi_inf = end, *hi_sup = end; lp_api::bound* hi_inf = end, *hi_sup = end;
for (unsigned i = 0; i < bounds.size(); ++i) { for (unsigned i = 0; i < bounds.size(); ++i) {
lp::bound& other = *bounds[i]; lp_api::bound& other = *bounds[i];
if (&other == &b) continue; if (&other == &b) continue;
if (b.get_bv() == other.get_bv()) continue; if (b.get_bv() == other.get_bv()) continue;
lp::bound_kind kind2 = other.get_bound_kind(); lp_api::bound_kind kind2 = other.get_bound_kind();
rational const& k2 = other.get_value(); rational const& k2 = other.get_value();
if (k1 == k2 && kind1 == kind2) { if (k1 == k2 && kind1 == kind2) {
// the bounds are equivalent. // the bounds are equivalent.
@ -1622,7 +1622,7 @@ namespace smt {
} }
SASSERT(k1 != k2 || kind1 != kind2); SASSERT(k1 != k2 || kind1 != kind2);
if (kind2 == lp::lower_t) { if (kind2 == lp_api::lower_t) {
if (k2 < k1) { if (k2 < k1) {
if (lo_inf == end || k2 > lo_inf->get_value()) { if (lo_inf == end || k2 > lo_inf->get_value()) {
lo_inf = &other; lo_inf = &other;
@ -1648,14 +1648,14 @@ namespace smt {
} }
void mk_bound_axiom(lp::bound& b1, lp::bound& b2) { void mk_bound_axiom(lp_api::bound& b1, lp_api::bound& b2) {
theory_var v = b1.get_var(); theory_var v = b1.get_var();
literal l1(b1.get_bv()); literal l1(b1.get_bv());
literal l2(b2.get_bv()); literal l2(b2.get_bv());
rational const& k1 = b1.get_value(); rational const& k1 = b1.get_value();
rational const& k2 = b2.get_value(); rational const& k2 = b2.get_value();
lp::bound_kind kind1 = b1.get_bound_kind(); lp_api::bound_kind kind1 = b1.get_bound_kind();
lp::bound_kind kind2 = b2.get_bound_kind(); lp_api::bound_kind kind2 = b2.get_bound_kind();
bool v_is_int = is_int(v); bool v_is_int = is_int(v);
SASSERT(v == b2.get_var()); SASSERT(v == b2.get_var());
if (k1 == k2 && kind1 == kind2) return; if (k1 == k2 && kind1 == kind2) return;
@ -1663,8 +1663,8 @@ namespace smt {
parameter coeffs[3] = { parameter(symbol("farkas")), parameter coeffs[3] = { parameter(symbol("farkas")),
parameter(rational(1)), parameter(rational(1)) }; parameter(rational(1)), parameter(rational(1)) };
if (kind1 == lp::lower_t) { if (kind1 == lp_api::lower_t) {
if (kind2 == lp::lower_t) { if (kind2 == lp_api::lower_t) {
if (k2 <= k1) { if (k2 <= k1) {
mk_clause(~l1, l2, 3, coeffs); mk_clause(~l1, l2, 3, coeffs);
} }
@ -1685,7 +1685,7 @@ namespace smt {
} }
} }
} }
else if (kind2 == lp::lower_t) { else if (kind2 == lp_api::lower_t) {
if (k1 >= k2) { if (k1 >= k2) {
// k1 >= lo_inf, k1 >= x or lo_inf <= x // k1 >= lo_inf, k1 >= x or lo_inf <= x
mk_clause(l1, l2, 3, coeffs); mk_clause(l1, l2, 3, coeffs);
@ -1743,21 +1743,21 @@ namespace smt {
iterator begin1 = occs.begin(); iterator begin1 = occs.begin();
iterator begin2 = occs.begin(); iterator begin2 = occs.begin();
iterator end = occs.end(); iterator end = occs.end();
begin1 = first(lp::lower_t, begin1, end); begin1 = first(lp_api::lower_t, begin1, end);
begin2 = first(lp::upper_t, begin2, end); begin2 = first(lp_api::upper_t, begin2, end);
iterator lo_inf = begin1, lo_sup = begin1; iterator lo_inf = begin1, lo_sup = begin1;
iterator hi_inf = begin2, hi_sup = begin2; iterator hi_inf = begin2, hi_sup = begin2;
iterator lo_inf1 = begin1, lo_sup1 = begin1; iterator lo_inf1 = begin1, lo_sup1 = begin1;
iterator hi_inf1 = begin2, hi_sup1 = begin2; iterator hi_inf1 = begin2, hi_sup1 = begin2;
bool flo_inf, fhi_inf, flo_sup, fhi_sup; bool flo_inf, fhi_inf, flo_sup, fhi_sup;
ptr_addr_hashtable<lp::bound> visited; ptr_addr_hashtable<lp_api::bound> visited;
for (unsigned i = 0; i < atoms.size(); ++i) { for (unsigned i = 0; i < atoms.size(); ++i) {
lp::bound* a1 = atoms[i]; lp_api::bound* a1 = atoms[i];
lo_inf1 = next_inf(a1, lp::lower_t, lo_inf, end, flo_inf); lo_inf1 = next_inf(a1, lp_api::lower_t, lo_inf, end, flo_inf);
hi_inf1 = next_inf(a1, lp::upper_t, hi_inf, end, fhi_inf); hi_inf1 = next_inf(a1, lp_api::upper_t, hi_inf, end, fhi_inf);
lo_sup1 = next_sup(a1, lp::lower_t, lo_sup, end, flo_sup); lo_sup1 = next_sup(a1, lp_api::lower_t, lo_sup, end, flo_sup);
hi_sup1 = next_sup(a1, lp::upper_t, hi_sup, end, fhi_sup); hi_sup1 = next_sup(a1, lp_api::upper_t, hi_sup, end, fhi_sup);
if (lo_inf1 != end) lo_inf = lo_inf1; if (lo_inf1 != end) lo_inf = lo_inf1;
if (lo_sup1 != end) lo_sup = lo_sup1; if (lo_sup1 != end) lo_sup = lo_sup1;
if (hi_inf1 != end) hi_inf = hi_inf1; if (hi_inf1 != end) hi_inf = hi_inf1;
@ -1776,24 +1776,24 @@ namespace smt {
} }
struct compare_bounds { struct compare_bounds {
bool operator()(lp::bound* a1, lp::bound* a2) const { return a1->get_value() < a2->get_value(); } bool operator()(lp_api::bound* a1, lp_api::bound* a2) const { return a1->get_value() < a2->get_value(); }
}; };
lp_bounds::iterator first( lp_bounds::iterator first(
lp::bound_kind kind, lp_api::bound_kind kind,
iterator it, iterator it,
iterator end) { iterator end) {
for (; it != end; ++it) { for (; it != end; ++it) {
lp::bound* a = *it; lp_api::bound* a = *it;
if (a->get_bound_kind() == kind) return it; if (a->get_bound_kind() == kind) return it;
} }
return end; return end;
} }
lp_bounds::iterator next_inf( lp_bounds::iterator next_inf(
lp::bound* a1, lp_api::bound* a1,
lp::bound_kind kind, lp_api::bound_kind kind,
iterator it, iterator it,
iterator end, iterator end,
bool& found_compatible) { bool& found_compatible) {
@ -1801,7 +1801,7 @@ namespace smt {
iterator result = end; iterator result = end;
found_compatible = false; found_compatible = false;
for (; it != end; ++it) { for (; it != end; ++it) {
lp::bound * a2 = *it; lp_api::bound * a2 = *it;
if (a1 == a2) continue; if (a1 == a2) continue;
if (a2->get_bound_kind() != kind) continue; if (a2->get_bound_kind() != kind) continue;
rational const & k2(a2->get_value()); rational const & k2(a2->get_value());
@ -1817,15 +1817,15 @@ namespace smt {
} }
lp_bounds::iterator next_sup( lp_bounds::iterator next_sup(
lp::bound* a1, lp_api::bound* a1,
lp::bound_kind kind, lp_api::bound_kind kind,
iterator it, iterator it,
iterator end, iterator end,
bool& found_compatible) { bool& found_compatible) {
rational const & k1(a1->get_value()); rational const & k1(a1->get_value());
found_compatible = false; found_compatible = false;
for (; it != end; ++it) { for (; it != end; ++it) {
lp::bound * a2 = *it; lp_api::bound * a2 = *it;
if (a1 == a2) continue; if (a1 == a2) continue;
if (a2->get_bound_kind() != kind) continue; if (a2->get_bound_kind() != kind) continue;
rational const & k2(a2->get_value()); rational const & k2(a2->get_value());
@ -1839,7 +1839,7 @@ namespace smt {
void propagate_basic_bounds() { void propagate_basic_bounds() {
for (auto const& bv : m_to_check) { for (auto const& bv : m_to_check) {
lp::bound& b = *m_bool_var2bound.find(bv); lp_api::bound& b = *m_bool_var2bound.find(bv);
propagate_bound(bv, ctx().get_assignment(bv) == l_true, b); propagate_bound(bv, ctx().get_assignment(bv) == l_true, b);
if (ctx().inconsistent()) break; if (ctx().inconsistent()) break;
@ -1854,11 +1854,11 @@ namespace smt {
// x <= hi -> x <= hi' // x <= hi -> x <= hi'
// x <= hi -> ~(x >= hi') // x <= hi -> ~(x >= hi')
void propagate_bound(bool_var bv, bool is_true, lp::bound& b) { void propagate_bound(bool_var bv, bool is_true, lp_api::bound& b) {
if (BP_NONE == propagation_mode()) { if (BP_NONE == propagation_mode()) {
return; return;
} }
lp::bound_kind k = b.get_bound_kind(); lp_api::bound_kind k = b.get_bound_kind();
theory_var v = b.get_var(); theory_var v = b.get_var();
inf_rational val = b.get_value(is_true); inf_rational val = b.get_value(is_true);
lp_bounds const& bounds = m_bounds[v]; lp_bounds const& bounds = m_bounds[v];
@ -1868,12 +1868,12 @@ namespace smt {
literal lit1(bv, !is_true); literal lit1(bv, !is_true);
literal lit2 = null_literal; literal lit2 = null_literal;
bool find_glb = (is_true == (k == lp::lower_t)); bool find_glb = (is_true == (k == lp_api::lower_t));
if (find_glb) { if (find_glb) {
rational glb; rational glb;
lp::bound* lb = 0; lp_api::bound* lb = 0;
for (unsigned i = 0; i < bounds.size(); ++i) { for (unsigned i = 0; i < bounds.size(); ++i) {
lp::bound* b2 = bounds[i]; lp_api::bound* b2 = bounds[i];
if (b2 == &b) continue; if (b2 == &b) continue;
rational const& val2 = b2->get_value(); rational const& val2 = b2->get_value();
if ((is_true ? val2 < val : val2 <= val) && (!lb || glb < val2)) { if ((is_true ? val2 < val : val2 <= val) && (!lb || glb < val2)) {
@ -1882,14 +1882,14 @@ namespace smt {
} }
} }
if (!lb) return; if (!lb) return;
bool sign = lb->get_bound_kind() != lp::lower_t; bool sign = lb->get_bound_kind() != lp_api::lower_t;
lit2 = literal(lb->get_bv(), sign); lit2 = literal(lb->get_bv(), sign);
} }
else { else {
rational lub; rational lub;
lp::bound* ub = 0; lp_api::bound* ub = 0;
for (unsigned i = 0; i < bounds.size(); ++i) { for (unsigned i = 0; i < bounds.size(); ++i) {
lp::bound* b2 = bounds[i]; lp_api::bound* b2 = bounds[i];
if (b2 == &b) continue; if (b2 == &b) continue;
rational const& val2 = b2->get_value(); rational const& val2 = b2->get_value();
if ((is_true ? val < val2 : val <= val2) && (!ub || val2 < lub)) { if ((is_true ? val < val2 : val <= val2) && (!ub || val2 < lub)) {
@ -1898,7 +1898,7 @@ namespace smt {
} }
} }
if (!ub) return; if (!ub) return;
bool sign = ub->get_bound_kind() != lp::upper_t; bool sign = ub->get_bound_kind() != lp_api::upper_t;
lit2 = literal(ub->get_bv(), sign); lit2 = literal(ub->get_bv(), sign);
} }
TRACE("arith", TRACE("arith",
@ -1918,27 +1918,27 @@ namespace smt {
++m_stats.m_bounds_propagations; ++m_stats.m_bounds_propagations;
} }
void add_use_lists(lp::bound* b) { void add_use_lists(lp_api::bound* b) {
theory_var v = b->get_var(); theory_var v = b->get_var();
lean::var_index vi = get_var_index(v); lp::var_index vi = get_var_index(v);
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
lean::lar_term const& term = m_solver->get_term(vi); lp::lar_term const& term = m_solver->get_term(vi);
for (auto i = term.m_coeffs.begin(); i != term.m_coeffs.end(); ++i) { for (auto i = term.m_coeffs.begin(); i != term.m_coeffs.end(); ++i) {
lean::var_index wi = i->first; lp::var_index wi = i->first;
unsigned w = m_var_index2theory_var[wi]; unsigned w = m_var_index2theory_var[wi];
m_use_list.reserve(w + 1, ptr_vector<lp::bound>()); m_use_list.reserve(w + 1, ptr_vector<lp_api::bound>());
m_use_list[w].push_back(b); m_use_list[w].push_back(b);
} }
} }
} }
void del_use_lists(lp::bound* b) { void del_use_lists(lp_api::bound* b) {
theory_var v = b->get_var(); theory_var v = b->get_var();
lean::var_index vi = m_theory_var2var_index[v]; lp::var_index vi = m_theory_var2var_index[v];
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
lean::lar_term const& term = m_solver->get_term(vi); lp::lar_term const& term = m_solver->get_term(vi);
for (auto i = term.m_coeffs.begin(); i != term.m_coeffs.end(); ++i) { for (auto i = term.m_coeffs.begin(); i != term.m_coeffs.end(); ++i) {
lean::var_index wi = i->first; lp::var_index wi = i->first;
unsigned w = m_var_index2theory_var[wi]; unsigned w = m_var_index2theory_var[wi];
SASSERT(m_use_list[w].back() == b); SASSERT(m_use_list[w].back() == b);
m_use_list[w].pop_back(); m_use_list[w].pop_back();
@ -1952,7 +1952,7 @@ namespace smt {
// have been assigned we may know the truth value of the inequality by using simple // have been assigned we may know the truth value of the inequality by using simple
// bounds propagation. // bounds propagation.
// //
void propagate_bound_compound(bool_var bv, bool is_true, lp::bound& b) { void propagate_bound_compound(bool_var bv, bool is_true, lp_api::bound& b) {
theory_var v = b.get_var(); theory_var v = b.get_var();
TRACE("arith", tout << mk_pp(get_owner(v), m) << "\n";); TRACE("arith", tout << mk_pp(get_owner(v), m) << "\n";);
if (static_cast<unsigned>(v) >= m_use_list.size()) { if (static_cast<unsigned>(v) >= m_use_list.size()) {
@ -1968,7 +1968,7 @@ namespace smt {
// x >= 0, y >= 1 -> x + y >= 1 // x >= 0, y >= 1 -> x + y >= 1
// x <= 0, y <= 2 -> x + y <= 2 // x <= 0, y <= 2 -> x + y <= 2
literal lit = null_literal; literal lit = null_literal;
if (lp::lower_t == vb->get_bound_kind()) { if (lp_api::lower_t == vb->get_bound_kind()) {
if (get_glb(*vb, r) && r >= vb->get_value()) { // vb is assigned true if (get_glb(*vb, r) && r >= vb->get_value()) { // vb is assigned true
lit = literal(vb->get_bv(), false); lit = literal(vb->get_bv(), false);
} }
@ -2002,30 +2002,30 @@ namespace smt {
} }
} }
bool get_lub(lp::bound const& b, inf_rational& lub) { bool get_lub(lp_api::bound const& b, inf_rational& lub) {
return get_bound(b, lub, true); return get_bound(b, lub, true);
} }
bool get_glb(lp::bound const& b, inf_rational& glb) { bool get_glb(lp_api::bound const& b, inf_rational& glb) {
return get_bound(b, glb, false); return get_bound(b, glb, false);
} }
std::ostream& display_bound(std::ostream& out, lp::bound const& b) { std::ostream& display_bound(std::ostream& out, lp_api::bound const& b) {
return out << mk_pp(ctx().bool_var2expr(b.get_bv()), m); return out << mk_pp(ctx().bool_var2expr(b.get_bv()), m);
} }
bool get_bound(lp::bound const& b, inf_rational& r, bool is_lub) { bool get_bound(lp_api::bound const& b, inf_rational& r, bool is_lub) {
m_core.reset(); m_core.reset();
m_eqs.reset(); m_eqs.reset();
m_params.reset(); m_params.reset();
r.reset(); r.reset();
theory_var v = b.get_var(); theory_var v = b.get_var();
lean::var_index vi = m_theory_var2var_index[v]; lp::var_index vi = m_theory_var2var_index[v];
SASSERT(m_solver->is_term(vi)); SASSERT(m_solver->is_term(vi));
lean::lar_term const& term = m_solver->get_term(vi); lp::lar_term const& term = m_solver->get_term(vi);
for (auto const coeff : term.m_coeffs) { for (auto const coeff : term.m_coeffs) {
lean::var_index wi = coeff.first; lp::var_index wi = coeff.first;
lean::constraint_index ci; lp::constraint_index ci;
rational value; rational value;
bool is_strict; bool is_strict;
if (coeff.second.is_neg() == is_lub) { if (coeff.second.is_neg() == is_lub) {
@ -2052,25 +2052,25 @@ namespace smt {
return true; return true;
} }
void assert_bound(bool_var bv, bool is_true, lp::bound& b) { void assert_bound(bool_var bv, bool is_true, lp_api::bound& b) {
if (m_solver->get_status() == lean::lp_status::INFEASIBLE) { if (m_solver->get_status() == lp::lp_status::INFEASIBLE) {
return; return;
} }
scoped_internalize_state st(*this); scoped_internalize_state st(*this);
st.vars().push_back(b.get_var()); st.vars().push_back(b.get_var());
st.coeffs().push_back(rational::one()); st.coeffs().push_back(rational::one());
init_left_side(st); init_left_side(st);
lean::lconstraint_kind k = lean::EQ; lp::lconstraint_kind k = lp::EQ;
bool is_int = b.is_int(); bool is_int = b.is_int();
switch (b.get_bound_kind()) { switch (b.get_bound_kind()) {
case lp::lower_t: case lp_api::lower_t:
k = is_true ? lean::GE : (is_int ? lean::LE : lean::LT); k = is_true ? lp::GE : (is_int ? lp::LE : lp::LT);
break; break;
case lp::upper_t: case lp_api::upper_t:
k = is_true ? lean::LE : (is_int ? lean::GE : lean::GT); k = is_true ? lp::LE : (is_int ? lp::GE : lp::GT);
break; break;
} }
if (k == lean::LT || k == lean::LE) { if (k == lp::LT || k == lp::LE) {
++m_stats.m_assert_lower; ++m_stats.m_assert_lower;
} }
else { else {
@ -2078,7 +2078,7 @@ namespace smt {
} }
auto vi = get_var_index(b.get_var()); auto vi = get_var_index(b.get_var());
rational bound = b.get_value(); rational bound = b.get_value();
lean::constraint_index ci; lp::constraint_index ci;
if (is_int && !is_true) { if (is_int && !is_true) {
rational bound = b.get_value(false).get_rational(); rational bound = b.get_value(false).get_rational();
ci = m_solver->add_var_bound(vi, k, bound); ci = m_solver->add_var_bound(vi, k, bound);
@ -2099,7 +2099,7 @@ namespace smt {
// Then the equality v1 == v2 is propagated to the core. // Then the equality v1 == v2 is propagated to the core.
// //
typedef std::pair<lean::constraint_index, rational> constraint_bound; typedef std::pair<lp::constraint_index, rational> constraint_bound;
vector<constraint_bound> m_lower_terms; vector<constraint_bound> m_lower_terms;
vector<constraint_bound> m_upper_terms; vector<constraint_bound> m_upper_terms;
typedef std::pair<rational, bool> value_sort_pair; typedef std::pair<rational, bool> value_sort_pair;
@ -2107,16 +2107,16 @@ namespace smt {
typedef map<value_sort_pair, theory_var, value_sort_pair_hash, default_eq<value_sort_pair> > value2var; typedef map<value_sort_pair, theory_var, value_sort_pair_hash, default_eq<value_sort_pair> > value2var;
value2var m_fixed_var_table; value2var m_fixed_var_table;
void propagate_eqs(lean::var_index vi, lean::constraint_index ci, lean::lconstraint_kind k, lp::bound& b) { void propagate_eqs(lp::var_index vi, lp::constraint_index ci, lp::lconstraint_kind k, lp_api::bound& b) {
if (propagate_eqs()) { if (propagate_eqs()) {
rational const& value = b.get_value(); rational const& value = b.get_value();
if (k == lean::GE) { if (k == lp::GE) {
set_lower_bound(vi, ci, value); set_lower_bound(vi, ci, value);
if (has_upper_bound(vi, ci, value)) { if (has_upper_bound(vi, ci, value)) {
fixed_var_eh(b.get_var(), value); fixed_var_eh(b.get_var(), value);
} }
} }
else if (k == lean::LE) { else if (k == lp::LE) {
set_upper_bound(vi, ci, value); set_upper_bound(vi, ci, value);
if (has_lower_bound(vi, ci, value)) { if (has_lower_bound(vi, ci, value)) {
fixed_var_eh(b.get_var(), value); fixed_var_eh(b.get_var(), value);
@ -2137,16 +2137,16 @@ namespace smt {
bool use_tableau() const { return lp_params(ctx().get_params()).simplex_strategy() < 2; } bool use_tableau() const { return lp_params(ctx().get_params()).simplex_strategy() < 2; }
void set_upper_bound(lean::var_index vi, lean::constraint_index ci, rational const& v) { set_bound(vi, ci, v, false); } void set_upper_bound(lp::var_index vi, lp::constraint_index ci, rational const& v) { set_bound(vi, ci, v, false); }
void set_lower_bound(lean::var_index vi, lean::constraint_index ci, rational const& v) { set_bound(vi, ci, v, true); } void set_lower_bound(lp::var_index vi, lp::constraint_index ci, rational const& v) { set_bound(vi, ci, v, true); }
void set_bound(lean::var_index vi, lean::constraint_index ci, rational const& v, bool is_lower) { void set_bound(lp::var_index vi, lp::constraint_index ci, rational const& v, bool is_lower) {
if (!m_solver->is_term(vi)) { if (!m_solver->is_term(vi)) {
// m_solver already tracks bounds on proper variables, but not on terms. // m_solver already tracks bounds on proper variables, but not on terms.
return; return;
} }
lean::var_index ti = m_solver->adjust_term_index(vi); lp::var_index ti = m_solver->adjust_term_index(vi);
auto& vec = is_lower ? m_lower_terms : m_upper_terms; auto& vec = is_lower ? m_lower_terms : m_upper_terms;
if (vec.size() <= ti) { if (vec.size() <= ti) {
vec.resize(ti + 1, constraint_bound(UINT_MAX, rational())); vec.resize(ti + 1, constraint_bound(UINT_MAX, rational()));
@ -2159,15 +2159,15 @@ namespace smt {
} }
} }
bool has_upper_bound(lean::var_index vi, lean::constraint_index& ci, rational const& bound) { return has_bound(vi, ci, bound, false); } bool has_upper_bound(lp::var_index vi, lp::constraint_index& ci, rational const& bound) { return has_bound(vi, ci, bound, false); }
bool has_lower_bound(lean::var_index vi, lean::constraint_index& ci, rational const& bound) { return has_bound(vi, ci, bound, true); } bool has_lower_bound(lp::var_index vi, lp::constraint_index& ci, rational const& bound) { return has_bound(vi, ci, bound, true); }
bool has_bound(lean::var_index vi, lean::constraint_index& ci, rational const& bound, bool is_lower) { bool has_bound(lp::var_index vi, lp::constraint_index& ci, rational const& bound, bool is_lower) {
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
lean::var_index ti = m_solver->adjust_term_index(vi); lp::var_index ti = m_solver->adjust_term_index(vi);
theory_var v = m_term_index2theory_var.get(ti, null_theory_var); theory_var v = m_term_index2theory_var.get(ti, null_theory_var);
rational val; rational val;
TRACE("arith", tout << vi << " " << v << "\n";); TRACE("arith", tout << vi << " " << v << "\n";);
@ -2210,7 +2210,7 @@ namespace smt {
if (static_cast<unsigned>(v2) < th.get_num_vars() && !is_equal(v1, v2)) { if (static_cast<unsigned>(v2) < th.get_num_vars() && !is_equal(v1, v2)) {
auto vi1 = get_var_index(v1); auto vi1 = get_var_index(v1);
auto vi2 = get_var_index(v2); auto vi2 = get_var_index(v2);
lean::constraint_index ci1, ci2, ci3, ci4; lp::constraint_index ci1, ci2, ci3, ci4;
TRACE("arith", tout << "fixed: " << mk_pp(get_owner(v1), m) << " " << mk_pp(get_owner(v2), m) << " " << bound << " " << has_lower_bound(vi2, ci3, bound) << "\n";); TRACE("arith", tout << "fixed: " << mk_pp(get_owner(v1), m) << " " << mk_pp(get_owner(v2), m) << " " << bound << " " << has_lower_bound(vi2, ci3, bound) << "\n";);
if (has_lower_bound(vi2, ci3, bound) && has_upper_bound(vi2, ci4, bound)) { if (has_lower_bound(vi2, ci3, bound) && has_upper_bound(vi2, ci4, bound)) {
VERIFY (has_lower_bound(vi1, ci1, bound)); VERIFY (has_lower_bound(vi1, ci1, bound));
@ -2260,13 +2260,13 @@ namespace smt {
auto status = m_solver->find_feasible_solution(); auto status = m_solver->find_feasible_solution();
TRACE("arith_verbose", display(tout);); TRACE("arith_verbose", display(tout););
switch (status) { switch (status) {
case lean::lp_status::INFEASIBLE: case lp::lp_status::INFEASIBLE:
return l_false; return l_false;
case lean::lp_status::FEASIBLE: case lp::lp_status::FEASIBLE:
case lean::lp_status::OPTIMAL: case lp::lp_status::OPTIMAL:
// SASSERT(m_solver->all_constraints_hold()); // SASSERT(m_solver->all_constraints_hold());
return l_true; return l_true;
case lean::lp_status::TIME_EXHAUSTED: case lp::lp_status::TIME_EXHAUSTED:
default: default:
TRACE("arith", tout << "status treated as inconclusive: " << status << "\n";); TRACE("arith", tout << "status treated as inconclusive: " << status << "\n";);
@ -2276,14 +2276,14 @@ namespace smt {
} }
} }
vector<std::pair<rational, lean::constraint_index>> m_explanation; vector<std::pair<rational, lp::constraint_index>> m_explanation;
literal_vector m_core; literal_vector m_core;
svector<enode_pair> m_eqs; svector<enode_pair> m_eqs;
vector<parameter> m_params; vector<parameter> m_params;
// lean::constraint_index const null_constraint_index = UINT_MAX; // not sure what a correct fix is // lp::constraint_index const null_constraint_index = UINT_MAX; // not sure what a correct fix is
void set_evidence(lean::constraint_index idx) { void set_evidence(lp::constraint_index idx) {
if (idx == UINT_MAX) { if (idx == UINT_MAX) {
return; return;
} }
@ -2371,14 +2371,14 @@ namespace smt {
nlsat::anum const& nl_value(theory_var v, scoped_anum& r) { nlsat::anum const& nl_value(theory_var v, scoped_anum& r) {
SASSERT(m_nra); SASSERT(m_nra);
SASSERT(m_use_nra_model); SASSERT(m_use_nra_model);
lean::var_index vi = m_theory_var2var_index[v]; lp::var_index vi = m_theory_var2var_index[v];
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
lean::lar_term const& term = m_solver->get_term(vi); lp::lar_term const& term = m_solver->get_term(vi);
scoped_anum r1(m_nra->am()); scoped_anum r1(m_nra->am());
m_nra->am().set(r, term.m_v.to_mpq()); m_nra->am().set(r, term.m_v.to_mpq());
for (auto const coeff : term.m_coeffs) { for (auto const coeff : term.m_coeffs) {
lean::var_index wi = coeff.first; lp::var_index wi = coeff.first;
m_nra->am().set(r1, coeff.second.to_mpq()); m_nra->am().set(r1, coeff.second.to_mpq());
m_nra->am().mul(m_nra->value(wi), r1, r1); m_nra->am().mul(m_nra->value(wi), r1, r1);
m_nra->am().add(r1, r, r); m_nra->am().add(r1, r, r);
@ -2474,16 +2474,16 @@ namespace smt {
} }
theory_lra::inf_eps value(theory_var v) { theory_lra::inf_eps value(theory_var v) {
lean::impq ival = get_ivalue(v); lp::impq ival = get_ivalue(v);
return inf_eps(0, inf_rational(ival.x, ival.y)); return inf_eps(0, inf_rational(ival.x, ival.y));
} }
theory_lra::inf_eps maximize(theory_var v, expr_ref& blocker, bool& has_shared) { theory_lra::inf_eps maximize(theory_var v, expr_ref& blocker, bool& has_shared) {
lean::var_index vi = m_theory_var2var_index.get(v, UINT_MAX); lp::var_index vi = m_theory_var2var_index.get(v, UINT_MAX);
vector<std::pair<rational, lean::var_index> > coeffs; vector<std::pair<rational, lp::var_index> > coeffs;
rational coeff; rational coeff;
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
const lean::lar_term& term = m_solver->get_term(vi); const lp::lar_term& term = m_solver->get_term(vi);
for (auto & ti : term.m_coeffs) { for (auto & ti : term.m_coeffs) {
coeffs.push_back(std::make_pair(ti.second, ti.first)); coeffs.push_back(std::make_pair(ti.second, ti.first));
} }
@ -2493,7 +2493,7 @@ namespace smt {
coeffs.push_back(std::make_pair(rational::one(), vi)); coeffs.push_back(std::make_pair(rational::one(), vi));
coeff = rational::zero(); coeff = rational::zero();
} }
lean::impq term_max; lp::impq term_max;
if (m_solver->maximize_term(coeffs, term_max)) { if (m_solver->maximize_term(coeffs, term_max)) {
blocker = mk_gt(v); blocker = mk_gt(v);
inf_rational val(term_max.x + coeff, term_max.y); inf_rational val(term_max.x + coeff, term_max.y);
@ -2508,7 +2508,7 @@ namespace smt {
} }
expr_ref mk_gt(theory_var v) { expr_ref mk_gt(theory_var v) {
lean::impq val = get_ivalue(v); lp::impq val = get_ivalue(v);
expr* obj = get_enode(v)->get_owner(); expr* obj = get_enode(v)->get_owner();
rational r = val.x; rational r = val.x;
expr_ref e(m); expr_ref e(m);
@ -2539,7 +2539,7 @@ namespace smt {
return internalize_def(term); return internalize_def(term);
} }
app_ref mk_term(lean::lar_term const& term, bool is_int) { app_ref mk_term(lp::lar_term const& term, bool is_int) {
expr_ref_vector args(m); expr_ref_vector args(m);
for (auto & ti : term.m_coeffs) { for (auto & ti : term.m_coeffs) {
theory_var w = m_var_index2theory_var[ti.first]; theory_var w = m_var_index2theory_var[ti.first];
@ -2561,7 +2561,7 @@ namespace smt {
} }
app_ref mk_obj(theory_var v) { app_ref mk_obj(theory_var v) {
lean::var_index vi = m_theory_var2var_index[v]; lp::var_index vi = m_theory_var2var_index[v];
bool is_int = a.is_int(get_enode(v)->get_owner()); bool is_int = a.is_int(get_enode(v)->get_owner());
if (m_solver->is_term(vi)) { if (m_solver->is_term(vi)) {
return mk_term(m_solver->get_term(vi), is_int); return mk_term(m_solver->get_term(vi), is_int);
@ -2588,9 +2588,9 @@ namespace smt {
bool_var bv = ctx().mk_bool_var(b); bool_var bv = ctx().mk_bool_var(b);
ctx().set_var_theory(bv, get_id()); ctx().set_var_theory(bv, get_id());
// ctx().set_enode_flag(bv, true); // ctx().set_enode_flag(bv, true);
lp::bound_kind bkind = lp::bound_kind::lower_t; lp_api::bound_kind bkind = lp_api::bound_kind::lower_t;
if (is_strict) bkind = lp::bound_kind::upper_t; if (is_strict) bkind = lp_api::bound_kind::upper_t;
lp::bound* a = alloc(lp::bound, bv, v, is_int, r, bkind); lp_api::bound* a = alloc(lp_api::bound, bv, v, is_int, r, bkind);
mk_bound_axioms(*a); mk_bound_axioms(*a);
updt_unassigned_bounds(v, +1); updt_unassigned_bounds(v, +1);
m_bounds[v].push_back(a); m_bounds[v].push_back(a);
@ -2622,7 +2622,7 @@ namespace smt {
} }
} }
void display_evidence(std::ostream& out, vector<std::pair<rational, lean::constraint_index>> const& evidence) { void display_evidence(std::ostream& out, vector<std::pair<rational, lp::constraint_index>> const& evidence) {
for (auto const& ev : evidence) { for (auto const& ev : evidence) {
expr_ref e(m); expr_ref e(m);
SASSERT(!ev.first.is_zero()); SASSERT(!ev.first.is_zero());

View file

@ -11,7 +11,7 @@ Author: Lev Nachmanson
#include <set> #include <set>
#include <iostream> #include <iostream>
namespace lean { namespace lp {
class argument_parser { class argument_parser {
std::unordered_map<std::string, std::string> m_options; std::unordered_map<std::string, std::string> m_options;
std::unordered_map<std::string, std::string> m_options_with_after_string; std::unordered_map<std::string, std::string> m_options_with_after_string;

View file

@ -31,7 +31,7 @@ Author: Lev Nachmanson
#include "util/lp/stacked_unordered_set.h" #include "util/lp/stacked_unordered_set.h"
#include "util/lp/int_set.h" #include "util/lp/int_set.h"
#include "util/stopwatch.h" #include "util/stopwatch.h"
namespace lean { namespace lp {
unsigned seed = 1; unsigned seed = 1;
random_gen g_rand; random_gen g_rand;
@ -78,7 +78,7 @@ void test_matrix(sparse_matrix<T, X> & a) {
a.set(i, j, t); a.set(i, j, t);
lean_assert(a.get(i, j) == t); lp_assert(a.get(i, j) == t);
unsigned j1; unsigned j1;
if (j < m - 1) { if (j < m - 1) {
@ -170,7 +170,7 @@ vector<int> allocate_basis_heading(unsigned count) { // the rest of initilizatio
void init_basic_part_of_basis_heading(vector<unsigned> & basis, vector<int> & basis_heading) { void init_basic_part_of_basis_heading(vector<unsigned> & basis, vector<int> & basis_heading) {
lean_assert(basis_heading.size() >= basis.size()); lp_assert(basis_heading.size() >= basis.size());
unsigned m = basis.size(); unsigned m = basis.size();
for (unsigned i = 0; i < m; i++) { for (unsigned i = 0; i < m; i++) {
unsigned column = basis[i]; unsigned column = basis[i];
@ -225,7 +225,7 @@ void test_small_lu(lp_settings & settings) {
vector<unsigned> non_basic_columns; vector<unsigned> non_basic_columns;
init_basis_heading_and_non_basic_columns_vector(basis, heading, non_basic_columns); init_basis_heading_and_non_basic_columns_vector(basis, heading, non_basic_columns);
lu<double, double> l(m, basis, settings); lu<double, double> l(m, basis, settings);
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
indexed_vector<double> w(m.row_count()); indexed_vector<double> w(m.row_count());
std::cout << "entering 2, leaving 0" << std::endl; std::cout << "entering 2, leaving 0" << std::endl;
l.prepare_entering(2, w); // to init vector w l.prepare_entering(2, w); // to init vector w
@ -235,7 +235,7 @@ void test_small_lu(lp_settings & settings) {
// std::cout << "we were factoring " << std::endl; // std::cout << "we were factoring " << std::endl;
// print_matrix(get_B(l)); // print_matrix(get_B(l));
// #endif // #endif
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
std::cout << "entering 4, leaving 3" << std::endl; std::cout << "entering 4, leaving 3" << std::endl;
l.prepare_entering(4, w); // to init vector w l.prepare_entering(4, w); // to init vector w
l.replace_column(0, w, heading[3]); l.replace_column(0, w, heading[3]);
@ -247,7 +247,7 @@ void test_small_lu(lp_settings & settings) {
print_matrix(&bl, std::cout); print_matrix(&bl, std::cout);
} }
#endif #endif
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
std::cout << "entering 5, leaving 1" << std::endl; std::cout << "entering 5, leaving 1" << std::endl;
l.prepare_entering(5, w); // to init vector w l.prepare_entering(5, w); // to init vector w
@ -260,7 +260,7 @@ void test_small_lu(lp_settings & settings) {
print_matrix(&bl, std::cout); print_matrix(&bl, std::cout);
} }
#endif #endif
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
std::cout << "entering 3, leaving 2" << std::endl; std::cout << "entering 3, leaving 2" << std::endl;
l.prepare_entering(3, w); // to init vector w l.prepare_entering(3, w); // to init vector w
l.replace_column(0, w, heading[2]); l.replace_column(0, w, heading[2]);
@ -272,7 +272,7 @@ void test_small_lu(lp_settings & settings) {
print_matrix(&bl, std::cout); print_matrix(&bl, std::cout);
} }
#endif #endif
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
m.add_row(); m.add_row();
m.add_column(); m.add_column();
@ -291,7 +291,7 @@ void test_small_lu(lp_settings & settings) {
auto columns_to_replace = l.get_set_of_columns_to_replace_for_add_last_rows(heading); auto columns_to_replace = l.get_set_of_columns_to_replace_for_add_last_rows(heading);
l.add_last_rows_to_B(heading, columns_to_replace); l.add_last_rows_to_B(heading, columns_to_replace);
std::cout << "here" << std::endl; std::cout << "here" << std::endl;
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
} }
#endif #endif
@ -373,7 +373,7 @@ void test_larger_lu_exp(lp_settings & settings) {
dense_matrix<double, double> left_side = l.get_left_side(basis); dense_matrix<double, double> left_side = l.get_left_side(basis);
dense_matrix<double, double> right_side = l.get_right_side(); dense_matrix<double, double> right_side = l.get_right_side();
lean_assert(left_side == right_side); lp_assert(left_side == right_side);
int leaving = 3; int leaving = 3;
int entering = 8; int entering = 8;
for (unsigned i = 0; i < m.row_count(); i++) { for (unsigned i = 0; i < m.row_count(); i++) {
@ -385,12 +385,12 @@ void test_larger_lu_exp(lp_settings & settings) {
l.prepare_entering(entering, w); l.prepare_entering(entering, w);
l.replace_column(0, w, heading[leaving]); l.replace_column(0, w, heading[leaving]);
change_basis(entering, leaving, basis, non_basic_columns, heading); change_basis(entering, leaving, basis, non_basic_columns, heading);
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
l.prepare_entering(11, w); // to init vector w l.prepare_entering(11, w); // to init vector w
l.replace_column(0, w, heading[0]); l.replace_column(0, w, heading[0]);
change_basis(11, 0, basis, non_basic_columns, heading); change_basis(11, 0, basis, non_basic_columns, heading);
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
} }
void test_larger_lu_with_holes(lp_settings & settings) { void test_larger_lu_with_holes(lp_settings & settings) {
@ -432,7 +432,7 @@ void test_larger_lu_with_holes(lp_settings & settings) {
l.prepare_entering(8, w); // to init vector w l.prepare_entering(8, w); // to init vector w
l.replace_column(0, w, heading[0]); l.replace_column(0, w, heading[0]);
change_basis(8, 0, basis, non_basic_columns, heading); change_basis(8, 0, basis, non_basic_columns, heading);
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
} }
@ -479,7 +479,7 @@ void test_larger_lu(lp_settings& settings) {
l.prepare_entering(9, w); // to init vector w l.prepare_entering(9, w); // to init vector w
l.replace_column(0, w, heading[0]); l.replace_column(0, w, heading[0]);
change_basis(9, 0, basis, non_basic_columns, heading); change_basis(9, 0, basis, non_basic_columns, heading);
lean_assert(l.is_correct(basis)); lp_assert(l.is_correct(basis));
} }
@ -612,7 +612,7 @@ void test_swap_rows_with_permutation(sparse_matrix<T, X>& m){
dense_matrix<double, double> original(&m); dense_matrix<double, double> original(&m);
permutation_matrix<double, double> q(dim); permutation_matrix<double, double> q(dim);
print_matrix(m, std::cout); print_matrix(m, std::cout);
lean_assert(original == q * m); lp_assert(original == q * m);
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
unsigned row1 = my_random() % dim; unsigned row1 = my_random() % dim;
unsigned row2 = my_random() % dim; unsigned row2 = my_random() % dim;
@ -620,7 +620,7 @@ void test_swap_rows_with_permutation(sparse_matrix<T, X>& m){
std::cout << "swap " << row1 << " " << row2 << std::endl; std::cout << "swap " << row1 << " " << row2 << std::endl;
m.swap_rows(row1, row2); m.swap_rows(row1, row2);
q.transpose_from_left(row1, row2); q.transpose_from_left(row1, row2);
lean_assert(original == q * m); lp_assert(original == q * m);
print_matrix(m, std::cout); print_matrix(m, std::cout);
std::cout << std::endl; std::cout << std::endl;
} }
@ -636,7 +636,7 @@ void test_swap_cols_with_permutation(sparse_matrix<T, X>& m){
dense_matrix<double, double> original(&m); dense_matrix<double, double> original(&m);
permutation_matrix<double, double> q(dim); permutation_matrix<double, double> q(dim);
print_matrix(m, std::cout); print_matrix(m, std::cout);
lean_assert(original == q * m); lp_assert(original == q * m);
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
unsigned row1 = my_random() % dim; unsigned row1 = my_random() % dim;
unsigned row2 = my_random() % dim; unsigned row2 = my_random() % dim;
@ -644,7 +644,7 @@ void test_swap_cols_with_permutation(sparse_matrix<T, X>& m){
std::cout << "swap " << row1 << " " << row2 << std::endl; std::cout << "swap " << row1 << " " << row2 << std::endl;
m.swap_rows(row1, row2); m.swap_rows(row1, row2);
q.transpose_from_right(row1, row2); q.transpose_from_right(row1, row2);
lean_assert(original == q * m); lp_assert(original == q * m);
print_matrix(m, std::cout); print_matrix(m, std::cout);
std::cout << std::endl; std::cout << std::endl;
} }
@ -663,8 +663,8 @@ void test_swap_rows(sparse_matrix<T, X>& m, unsigned i0, unsigned i1){
m.swap_rows(i0, i1); m.swap_rows(i0, i1);
for (unsigned j = 0; j < m.dimension(); j++) { for (unsigned j = 0; j < m.dimension(); j++) {
lean_assert(mcopy(i0, j) == m(i1, j)); lp_assert(mcopy(i0, j) == m(i1, j));
lean_assert(mcopy(i1, j) == m(i0, j)); lp_assert(mcopy(i1, j) == m(i0, j));
} }
} }
template <typename T, typename X> template <typename T, typename X>
@ -678,15 +678,15 @@ void test_swap_columns(sparse_matrix<T, X>& m, unsigned i0, unsigned i1){
m.swap_columns(i0, i1); m.swap_columns(i0, i1);
for (unsigned j = 0; j < m.dimension(); j++) { for (unsigned j = 0; j < m.dimension(); j++) {
lean_assert(mcopy(j, i0) == m(j, i1)); lp_assert(mcopy(j, i0) == m(j, i1));
lean_assert(mcopy(j, i1) == m(j, i0)); lp_assert(mcopy(j, i1) == m(j, i0));
} }
for (unsigned i = 0; i < m.dimension(); i++) { for (unsigned i = 0; i < m.dimension(); i++) {
if (i == i0 || i == i1) if (i == i0 || i == i1)
continue; continue;
for (unsigned j = 0; j < m.dimension(); j++) { for (unsigned j = 0; j < m.dimension(); j++) {
lean_assert(mcopy(j, i)== m(j, i)); lp_assert(mcopy(j, i)== m(j, i));
} }
} }
} }
@ -748,7 +748,7 @@ void test_pivot_like_swaps_and_pivot(){
m.pivot_row_to_row(pivot_row_0, beta, target_row, settings); m.pivot_row_to_row(pivot_row_0, beta, target_row, settings);
// print_matrix(m); // print_matrix(m);
for (unsigned j = 0; j < m.dimension(); j++) { for (unsigned j = 0; j < m.dimension(); j++) {
lean_assert(abs(row[j] - m(target_row, j)) < 0.00000001); lp_assert(abs(row[j] - m(target_row, j)) < 0.00000001);
} }
} }
@ -853,57 +853,57 @@ void sparse_matrix_with_permutaions_test() {
m.multiply_from_left(q0); m.multiply_from_left(q0);
for (unsigned i = 0; i < dim; i++) { for (unsigned i = 0; i < dim; i++) {
for (unsigned j = 0; j < dim; j++) { for (unsigned j = 0; j < dim; j++) {
lean_assert(m(i, j) == dm0.get_elem(q0[i], j)); lp_assert(m(i, j) == dm0.get_elem(q0[i], j));
} }
} }
auto q0_dm = q0 * dm; auto q0_dm = q0 * dm;
lean_assert(m == q0_dm); lp_assert(m == q0_dm);
m.multiply_from_left(q1); m.multiply_from_left(q1);
for (unsigned i = 0; i < dim; i++) { for (unsigned i = 0; i < dim; i++) {
for (unsigned j = 0; j < dim; j++) { for (unsigned j = 0; j < dim; j++) {
lean_assert(m(i, j) == dm0.get_elem(q0[q1[i]], j)); lp_assert(m(i, j) == dm0.get_elem(q0[q1[i]], j));
} }
} }
auto q1_q0_dm = q1 * q0_dm; auto q1_q0_dm = q1 * q0_dm;
lean_assert(m == q1_q0_dm); lp_assert(m == q1_q0_dm);
m.multiply_from_right(p0); m.multiply_from_right(p0);
for (unsigned i = 0; i < dim; i++) { for (unsigned i = 0; i < dim; i++) {
for (unsigned j = 0; j < dim; j++) { for (unsigned j = 0; j < dim; j++) {
lean_assert(m(i, j) == dm0.get_elem(q0[q1[i]], p0[j])); lp_assert(m(i, j) == dm0.get_elem(q0[q1[i]], p0[j]));
} }
} }
auto q1_q0_dm_p0 = q1_q0_dm * p0; auto q1_q0_dm_p0 = q1_q0_dm * p0;
lean_assert(m == q1_q0_dm_p0); lp_assert(m == q1_q0_dm_p0);
m.multiply_from_right(p1); m.multiply_from_right(p1);
for (unsigned i = 0; i < dim; i++) { for (unsigned i = 0; i < dim; i++) {
for (unsigned j = 0; j < dim; j++) { for (unsigned j = 0; j < dim; j++) {
lean_assert(m(i, j) == dm0.get_elem(q0[q1[i]], p1[p0[j]])); lp_assert(m(i, j) == dm0.get_elem(q0[q1[i]], p1[p0[j]]));
} }
} }
auto q1_q0_dm_p0_p1 = q1_q0_dm_p0 * p1; auto q1_q0_dm_p0_p1 = q1_q0_dm_p0 * p1;
lean_assert(m == q1_q0_dm_p0_p1); lp_assert(m == q1_q0_dm_p0_p1);
m.multiply_from_right(p1); m.multiply_from_right(p1);
for (unsigned i = 0; i < dim; i++) { for (unsigned i = 0; i < dim; i++) {
for (unsigned j = 0; j < dim; j++) { for (unsigned j = 0; j < dim; j++) {
lean_assert(m(i, j) == dm0.get_elem(q0[q1[i]], p1[p1[p0[j]]])); lp_assert(m(i, j) == dm0.get_elem(q0[q1[i]], p1[p1[p0[j]]]));
} }
} }
auto q1_q0_dm_p0_p1_p1 = q1_q0_dm_p0_p1 * p1; auto q1_q0_dm_p0_p1_p1 = q1_q0_dm_p0_p1 * p1;
lean_assert(m == q1_q0_dm_p0_p1_p1); lp_assert(m == q1_q0_dm_p0_p1_p1);
} }
void test_swap_columns() { void test_swap_columns() {
@ -1024,7 +1024,7 @@ void test_apply_reverse_from_right_to_perm(permutation_matrix<double, double> &
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
auto rev = l.get_inverse(); auto rev = l.get_inverse();
auto rs = pclone * rev; auto rs = pclone * rev;
lean_assert(p == rs) lp_assert(p == rs)
#endif #endif
} }
@ -1051,8 +1051,8 @@ void test_permutations() {
p.apply_reverse_from_right_to_T(v); p.apply_reverse_from_right_to_T(v);
p.apply_reverse_from_right_to_T(vi); p.apply_reverse_from_right_to_T(vi);
lean_assert(vectors_are_equal(v, vi.m_data)); lp_assert(vectors_are_equal(v, vi.m_data));
lean_assert(vi.is_OK()); lp_assert(vi.is_OK());
} }
void lp_solver_test() { void lp_solver_test() {
@ -1200,7 +1200,7 @@ void solve_mps_double(std::string file_name, bool look_for_min, unsigned max_ite
compare_solutions(reader, primal_solver, solver); compare_solutions(reader, primal_solver, solver);
print_x(reader, primal_solver); print_x(reader, primal_solver);
std::cout << "dual cost is " << cost << ", but primal cost is " << primal_cost << std::endl; std::cout << "dual cost is " << cost << ", but primal cost is " << primal_cost << std::endl;
lean_assert(false); lp_assert(false);
} }
} }
} }
@ -1210,7 +1210,7 @@ void solve_mps_double(std::string file_name, bool look_for_min, unsigned max_ite
} }
void solve_mps_rational(std::string file_name, bool look_for_min, unsigned max_iterations, unsigned time_limit, bool dual, argument_parser & args_parser) { void solve_mps_rational(std::string file_name, bool look_for_min, unsigned max_iterations, unsigned time_limit, bool dual, argument_parser & args_parser) {
mps_reader<lean::mpq, lean::mpq> reader(file_name); mps_reader<lp::mpq, lp::mpq> reader(file_name);
reader.read(); reader.read();
if (reader.is_ok()) { if (reader.is_ok()) {
auto * solver = reader.create_solver(dual); auto * solver = reader.create_solver(dual);
@ -1224,7 +1224,7 @@ void solve_mps_rational(std::string file_name, bool look_for_min, unsigned max_i
// for (auto name: reader.column_names()) { // for (auto name: reader.column_names()) {
// std::cout << name << "=" << solver->get_column_value_by_name(name) << ' '; // std::cout << name << "=" << solver->get_column_value_by_name(name) << ' ';
// } // }
lean::mpq cost = solver->get_current_cost(); lp::mpq cost = solver->get_current_cost();
if (look_for_min) { if (look_for_min) {
cost = -cost; cost = -cost;
} }
@ -1262,7 +1262,7 @@ void solve_mps(std::string file_name, argument_parser & args_parser) {
void solve_mps_in_rational(std::string file_name, bool dual, argument_parser & /*args_parser*/) { void solve_mps_in_rational(std::string file_name, bool dual, argument_parser & /*args_parser*/) {
std::cout << "solving " << file_name << std::endl; std::cout << "solving " << file_name << std::endl;
mps_reader<lean::mpq, lean::mpq> reader(file_name); mps_reader<lp::mpq, lp::mpq> reader(file_name);
reader.read(); reader.read();
if (reader.is_ok()) { if (reader.is_ok()) {
auto * solver = reader.create_solver(dual); auto * solver = reader.create_solver(dual);
@ -1274,7 +1274,7 @@ void solve_mps_in_rational(std::string file_name, bool dual, argument_parser & /
std::cout << name << "=" << solver->get_column_value_by_name(name).get_double() << ' '; std::cout << name << "=" << solver->get_column_value_by_name(name).get_double() << ' ';
} }
} }
std::cout << std::endl << "cost = " << numeric_traits<lean::mpq>::get_double(solver->get_current_cost()) << std::endl; std::cout << std::endl << "cost = " << numeric_traits<lp::mpq>::get_double(solver->get_current_cost()) << std::endl;
} }
delete solver; delete solver;
} else { } else {
@ -1318,7 +1318,7 @@ void test_binary_priority_queue() {
for (unsigned i = 0; i < 10; i++) { for (unsigned i = 0; i < 10; i++) {
unsigned de = q.dequeue(); unsigned de = q.dequeue();
lean_assert(i == de); lp_assert(i == de);
std::cout << de << std::endl; std::cout << de << std::endl;
} }
q.enqueue(2, 2); q.enqueue(2, 2);
@ -1341,7 +1341,7 @@ void test_binary_priority_queue() {
unsigned t = 0; unsigned t = 0;
while (q.size() > 0) { while (q.size() > 0) {
unsigned d =q.dequeue(); unsigned d =q.dequeue();
lean_assert(t++ == d); lp_assert(t++ == d);
std::cout << d << std::endl; std::cout << d << std::endl;
} }
#endif #endif
@ -1370,7 +1370,7 @@ void solve_mps_with_known_solution(std::string file_name, std::unordered_map<std
std::cout << "status is " << lp_status_to_string(solver->get_status()) << std::endl; std::cout << "status is " << lp_status_to_string(solver->get_status()) << std::endl;
if (status != solver->get_status()){ if (status != solver->get_status()){
std::cout << "status should be " << lp_status_to_string(status) << std::endl; std::cout << "status should be " << lp_status_to_string(status) << std::endl;
lean_assert(status == solver->get_status()); lp_assert(status == solver->get_status());
throw "status is wrong"; throw "status is wrong";
} }
if (solver->get_status() == lp_status::OPTIMAL) { if (solver->get_status() == lp_status::OPTIMAL) {
@ -1381,7 +1381,7 @@ void solve_mps_with_known_solution(std::string file_name, std::unordered_map<std
std::cout << "expected:" << it.first << "=" << std::cout << "expected:" << it.first << "=" <<
it.second <<", got " << solver->get_column_value_by_name(it.first) << std::endl; it.second <<", got " << solver->get_column_value_by_name(it.first) << std::endl;
} }
lean_assert(fabs(it.second - solver->get_column_value_by_name(it.first)) < 0.000001); lp_assert(fabs(it.second - solver->get_column_value_by_name(it.first)) < 0.000001);
} }
} }
if (reader.column_names().size() < 20) { if (reader.column_names().size() < 20) {
@ -1466,127 +1466,127 @@ void fill_file_names(vector<std::string> &file_names, std::set<std::string> & m
return; return;
} }
std::string home_dir_str(home_dir); std::string home_dir_str(home_dir);
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l0redund.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l0redund.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l1.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l1.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l2.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l2.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l3.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l3.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l4.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l4.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l4fix.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l4fix.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/plan.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/plan.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/samp2.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/samp2.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/murtagh.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/murtagh.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/l0.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/l0.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/AFIRO.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/AFIRO.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SC50B.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SC50B.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SC50A.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SC50A.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/KB2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/KB2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SC105.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SC105.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STOCFOR1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STOCFOR1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/ADLITTLE.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/ADLITTLE.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BLEND.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BLEND.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCAGR7.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCAGR7.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SC205.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SC205.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHARE2B.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHARE2B.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/RECIPELP.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/RECIPELP.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/LOTFI.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/LOTFI.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/VTP-BASE.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/VTP-BASE.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHARE1B.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHARE1B.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BOEING2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BOEING2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BORE3D.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BORE3D.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCORPION.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCORPION.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/CAPRI.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/CAPRI.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BRANDY.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BRANDY.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCAGR25.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCAGR25.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCTAP1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCTAP1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/ISRAEL.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/ISRAEL.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCFXM1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCFXM1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BANDM.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BANDM.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/E226.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/E226.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/AGG.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/AGG.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GROW7.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GROW7.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/ETAMACRO.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/ETAMACRO.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FINNIS.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FINNIS.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCSD1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCSD1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STANDATA.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STANDATA.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STANDGUB.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STANDGUB.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BEACONFD.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BEACONFD.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STAIR.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STAIR.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STANDMPS.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STANDMPS.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GFRD-PNC.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GFRD-PNC.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCRS8.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCRS8.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BOEING1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BOEING1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/MODSZK1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/MODSZK1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/DEGEN2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/DEGEN2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FORPLAN.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FORPLAN.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/AGG2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/AGG2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/AGG3.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/AGG3.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCFXM2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCFXM2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHELL.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHELL.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PILOT4.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PILOT4.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCSD6.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCSD6.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHIP04S.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHIP04S.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SEBA.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SEBA.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GROW15.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GROW15.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FFFFF800.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FFFFF800.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BNL1.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BNL1.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PEROLD.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PEROLD.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/QAP8.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/QAP8.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCFXM3.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCFXM3.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHIP04L.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHIP04L.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GANGES.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GANGES.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCTAP2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCTAP2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GROW22.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GROW22.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHIP08S.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHIP08S.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PILOT-WE.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PILOT-WE.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/MAROS.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/MAROS.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STOCFOR2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STOCFOR2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/25FV47.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/25FV47.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHIP12S.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHIP12S.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCSD8.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCSD8.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FIT1P.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FIT1P.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SCTAP3.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SCTAP3.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SIERRA.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SIERRA.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PILOTNOV.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PILOTNOV.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/CZPROB.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/CZPROB.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FIT1D.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FIT1D.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PILOT-JA.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PILOT-JA.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHIP08L.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHIP08L.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/BNL2.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/BNL2.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/NESM.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/NESM.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/CYCLE.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/CYCLE.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/acc-tight5.mps"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/acc-tight5.mps");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/SHIP12L.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/SHIP12L.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/DEGEN3.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/DEGEN3.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GREENBEA.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GREENBEA.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/GREENBEB.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/GREENBEB.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/80BAU3B.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/80BAU3B.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/TRUSS.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/TRUSS.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/D2Q06C.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/D2Q06C.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/WOODW.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/WOODW.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/QAP12.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/QAP12.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/D6CUBE.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/D6CUBE.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PILOT.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PILOT.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/DFL001.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/DFL001.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/WOOD1P.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/WOOD1P.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FIT2P.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FIT2P.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/PILOT87.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/PILOT87.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/STOCFOR3.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/STOCFOR3.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/QAP15.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/QAP15.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/FIT2D.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/FIT2D.SIF");
file_names.push_back(home_dir_str + "/projects/lean/src/tests/util/lp/test_files/netlib/MAROS-R7.SIF"); file_names.push_back(home_dir_str + "/projects/lp/src/tests/util/lp/test_files/netlib/MAROS-R7.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/FIT2P.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/FIT2P.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/DFL001.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/DFL001.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/D2Q06C.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/D2Q06C.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/80BAU3B.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/80BAU3B.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/GREENBEB.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/GREENBEB.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/GREENBEA.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/GREENBEA.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/BNL2.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/BNL2.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/SHIP08L.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/SHIP08L.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/FIT1D.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/FIT1D.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/SCTAP3.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/SCTAP3.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/SCSD8.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/SCSD8.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/SCSD6.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/SCSD6.SIF");
minimums.insert("/projects/lean/src/tests/util/lp/test_files/netlib/MAROS-R7.SIF"); minimums.insert("/projects/lp/src/tests/util/lp/test_files/netlib/MAROS-R7.SIF");
} }
void test_out_dir(std::string out_dir) { void test_out_dir(std::string out_dir) {
@ -1706,48 +1706,48 @@ void solve_some_mps(argument_parser & args_parser) {
#endif #endif
void solve_rational() { void solve_rational() {
lp_primal_simplex<lean::mpq, lean::mpq> solver; lp_primal_simplex<lp::mpq, lp::mpq> solver;
solver.add_constraint(lp_relation::Equal, lean::mpq(7), 0); solver.add_constraint(lp_relation::Equal, lp::mpq(7), 0);
solver.add_constraint(lp_relation::Equal, lean::mpq(-3), 1); solver.add_constraint(lp_relation::Equal, lp::mpq(-3), 1);
// setting the cost // setting the cost
int cost[] = {-3, -1, -1, 2, -1, 1, 1, -4}; int cost[] = {-3, -1, -1, 2, -1, 1, 1, -4};
std::string var_names[8] = {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8"}; std::string var_names[8] = {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8"};
for (unsigned i = 0; i < 8; i++) { for (unsigned i = 0; i < 8; i++) {
solver.set_cost_for_column(i, lean::mpq(cost[i])); solver.set_cost_for_column(i, lp::mpq(cost[i]));
solver.give_symbolic_name_to_column(var_names[i], i); solver.give_symbolic_name_to_column(var_names[i], i);
} }
int row0[] = {1, 0, 3, 1, -5, -2 , 4, -6}; int row0[] = {1, 0, 3, 1, -5, -2 , 4, -6};
for (unsigned i = 0; i < 8; i++) { for (unsigned i = 0; i < 8; i++) {
solver.set_row_column_coefficient(0, i, lean::mpq(row0[i])); solver.set_row_column_coefficient(0, i, lp::mpq(row0[i]));
} }
int row1[] = {0, 1, -2, -1, 4, 1, -3, 5}; int row1[] = {0, 1, -2, -1, 4, 1, -3, 5};
for (unsigned i = 0; i < 8; i++) { for (unsigned i = 0; i < 8; i++) {
solver.set_row_column_coefficient(1, i, lean::mpq(row1[i])); solver.set_row_column_coefficient(1, i, lp::mpq(row1[i]));
} }
int bounds[] = {8, 6, 4, 15, 2, 10, 10, 3}; int bounds[] = {8, 6, 4, 15, 2, 10, 10, 3};
for (unsigned i = 0; i < 8; i++) { for (unsigned i = 0; i < 8; i++) {
solver.set_low_bound(i, lean::mpq(0)); solver.set_low_bound(i, lp::mpq(0));
solver.set_upper_bound(i, lean::mpq(bounds[i])); solver.set_upper_bound(i, lp::mpq(bounds[i]));
} }
std::unordered_map<std::string, lean::mpq> expected_sol; std::unordered_map<std::string, lp::mpq> expected_sol;
expected_sol["x1"] = lean::mpq(0); expected_sol["x1"] = lp::mpq(0);
expected_sol["x2"] = lean::mpq(6); expected_sol["x2"] = lp::mpq(6);
expected_sol["x3"] = lean::mpq(0); expected_sol["x3"] = lp::mpq(0);
expected_sol["x4"] = lean::mpq(15); expected_sol["x4"] = lp::mpq(15);
expected_sol["x5"] = lean::mpq(2); expected_sol["x5"] = lp::mpq(2);
expected_sol["x6"] = lean::mpq(1); expected_sol["x6"] = lp::mpq(1);
expected_sol["x7"] = lean::mpq(1); expected_sol["x7"] = lp::mpq(1);
expected_sol["x8"] = lean::mpq(0); expected_sol["x8"] = lp::mpq(0);
solver.find_maximal_solution(); solver.find_maximal_solution();
lean_assert(solver.get_status() == OPTIMAL); lp_assert(solver.get_status() == OPTIMAL);
for (auto it : expected_sol) { for (auto it : expected_sol) {
lean_assert(it.second == solver.get_column_value_by_name(it.first)); lp_assert(it.second == solver.get_column_value_by_name(it.first));
} }
} }
@ -1805,7 +1805,7 @@ std::unordered_map<std::string, double> * get_solution_from_glpsol_output(std::s
return ret; return ret;
} }
lean_assert(split.size() > 3); lp_assert(split.size() > 3);
(*ret)[split[1]] = atof(split[3].c_str()); (*ret)[split[1]] = atof(split[3].c_str());
} while (true); } while (true);
} }
@ -1829,7 +1829,7 @@ void test_init_U() {
for (unsigned i = 0; i < 3; i++) { for (unsigned i = 0; i < 3; i++) {
for (unsigned j = 0; j < 3; j ++) { for (unsigned j = 0; j < 3; j ++) {
lean_assert(m(i, basis[j]) == u(i, j)); lp_assert(m(i, basis[j]) == u(i, j));
} }
} }
@ -1857,7 +1857,7 @@ void test_replace_column() {
for (unsigned column_to_replace = 0; column_to_replace < m.dimension(); column_to_replace ++) { for (unsigned column_to_replace = 0; column_to_replace < m.dimension(); column_to_replace ++) {
m.replace_column(column_to_replace, w, settings); m.replace_column(column_to_replace, w, settings);
for (unsigned i = 0; i < m.dimension(); i++) { for (unsigned i = 0; i < m.dimension(); i++) {
lean_assert(abs(w[i] - m(i, column_to_replace)) < 0.00000001); lp_assert(abs(w[i] - m(i, column_to_replace)) < 0.00000001);
} }
} }
} }
@ -1961,7 +1961,7 @@ void test_stacked_unsigned() {
v = 3; v = 3;
v = 4; v = 4;
v.pop(); v.pop();
lean_assert(v == 2); lp_assert(v == 2);
v ++; v ++;
v++; v++;
std::cout << "before push v=" << v << std::endl; std::cout << "before push v=" << v << std::endl;
@ -1971,7 +1971,7 @@ void test_stacked_unsigned() {
v+=1; v+=1;
std::cout << "v = " << v << std::endl; std::cout << "v = " << v << std::endl;
v.pop(2); v.pop(2);
lean_assert(v == 4); lp_assert(v == 4);
const unsigned & rr = v; const unsigned & rr = v;
std::cout << rr << std:: endl; std::cout << rr << std:: endl;
@ -2020,7 +2020,7 @@ void test_stacked_set() {
s.push(); s.push();
s.insert(4); s.insert(4);
s.pop(); s.pop();
lean_assert(s() == scopy); lp_assert(s() == scopy);
s.push(); s.push();
s.push(); s.push();
s.insert(4); s.insert(4);
@ -2028,7 +2028,7 @@ void test_stacked_set() {
s.push(); s.push();
s.insert(4); s.insert(4);
s.pop(3); s.pop(3);
lean_assert(s() == scopy); lp_assert(s() == scopy);
#endif #endif
} }
@ -2397,15 +2397,15 @@ void test_files_from_directory(std::string test_file_dir, argument_parser & args
} }
std::unordered_map<std::string, lean::mpq> get_solution_map(lp_solver<lean::mpq, lean::mpq> * lps, mps_reader<lean::mpq, lean::mpq> & reader) { std::unordered_map<std::string, lp::mpq> get_solution_map(lp_solver<lp::mpq, lp::mpq> * lps, mps_reader<lp::mpq, lp::mpq> & reader) {
std::unordered_map<std::string, lean::mpq> ret; std::unordered_map<std::string, lp::mpq> ret;
for (auto it : reader.column_names()) { for (auto it : reader.column_names()) {
ret[it] = lps->get_column_value_by_name(it); ret[it] = lps->get_column_value_by_name(it);
} }
return ret; return ret;
} }
void run_lar_solver(argument_parser & args_parser, lar_solver * solver, mps_reader<lean::mpq, lean::mpq> * reader) { void run_lar_solver(argument_parser & args_parser, lar_solver * solver, mps_reader<lp::mpq, lp::mpq> * reader) {
std::string maxng = args_parser.get_option_value("--maxng"); std::string maxng = args_parser.get_option_value("--maxng");
if (maxng.size() > 0) { if (maxng.size() > 0) {
solver->settings().max_number_of_iterations_with_no_improvements = atoi(maxng.c_str()); solver->settings().max_number_of_iterations_with_no_improvements = atoi(maxng.c_str());
@ -2425,7 +2425,7 @@ void run_lar_solver(argument_parser & args_parser, lar_solver * solver, mps_read
} }
auto * lps = reader->create_solver(false); auto * lps = reader->create_solver(false);
lps->find_maximal_solution(); lps->find_maximal_solution();
std::unordered_map<std::string, lean::mpq> sol = get_solution_map(lps, *reader); std::unordered_map<std::string, lp::mpq> sol = get_solution_map(lps, *reader);
std::cout << "status = " << lp_status_to_string(solver->get_status()) << std::endl; std::cout << "status = " << lp_status_to_string(solver->get_status()) << std::endl;
return; return;
} }
@ -2434,7 +2434,7 @@ void run_lar_solver(argument_parser & args_parser, lar_solver * solver, mps_read
lp_status status = solver->solve(); lp_status status = solver->solve();
std::cout << "status is " << lp_status_to_string(status) << ", processed for " << sw.get_current_seconds() <<" seconds, and " << solver->get_total_iterations() << " iterations" << std::endl; std::cout << "status is " << lp_status_to_string(status) << ", processed for " << sw.get_current_seconds() <<" seconds, and " << solver->get_total_iterations() << " iterations" << std::endl;
if (solver->get_status() == INFEASIBLE) { if (solver->get_status() == INFEASIBLE) {
vector<std::pair<lean::mpq, constraint_index>> evidence; vector<std::pair<lp::mpq, constraint_index>> evidence;
solver->get_infeasibility_explanation(evidence); solver->get_infeasibility_explanation(evidence);
} }
if (args_parser.option_is_used("--randomize_lar")) { if (args_parser.option_is_used("--randomize_lar")) {
@ -2467,7 +2467,7 @@ lar_solver * create_lar_solver_from_file(std::string file_name, argument_parser
} }
return reader.create_lar_solver(); return reader.create_lar_solver();
} }
mps_reader<lean::mpq, lean::mpq> reader(file_name); mps_reader<lp::mpq, lp::mpq> reader(file_name);
reader.read(); reader.read();
if (!reader.is_ok()) { if (!reader.is_ok()) {
std::cout << "cannot process " << file_name << std::endl; std::cout << "cannot process " << file_name << std::endl;
@ -2478,8 +2478,8 @@ lar_solver * create_lar_solver_from_file(std::string file_name, argument_parser
void test_lar_on_file(std::string file_name, argument_parser & args_parser) { void test_lar_on_file(std::string file_name, argument_parser & args_parser) {
lar_solver * solver = create_lar_solver_from_file(file_name, args_parser); lar_solver * solver = create_lar_solver_from_file(file_name, args_parser);
mps_reader<lean::mpq, lean::mpq> reader(file_name); mps_reader<lp::mpq, lp::mpq> reader(file_name);
mps_reader<lean::mpq, lean::mpq> * mps_reader = nullptr; mps_reader<lp::mpq, lp::mpq> * mps_reader = nullptr;
reader.read(); reader.read();
if (reader.is_ok()) { if (reader.is_ok()) {
mps_reader = & reader; mps_reader = & reader;
@ -2524,28 +2524,28 @@ void test_lar_solver(argument_parser & args_parser) {
} }
void test_numeric_pair() { void test_numeric_pair() {
numeric_pair<lean::mpq> a; numeric_pair<lp::mpq> a;
numeric_pair<lean::mpq> b(2, lean::mpq(6, 2)); numeric_pair<lp::mpq> b(2, lp::mpq(6, 2));
a = b; a = b;
numeric_pair<lean::mpq> c(0.1, 0.5); numeric_pair<lp::mpq> c(0.1, 0.5);
a += 2*c; a += 2*c;
a -= c; a -= c;
lean_assert (a == b + c); lp_assert (a == b + c);
numeric_pair<lean::mpq> d = a * 2; numeric_pair<lp::mpq> d = a * 2;
std::cout << a << std::endl; std::cout << a << std::endl;
lean_assert(b == b); lp_assert(b == b);
lean_assert(b < a); lp_assert(b < a);
lean_assert(b <= a); lp_assert(b <= a);
lean_assert(a > b); lp_assert(a > b);
lean_assert(a != b); lp_assert(a != b);
lean_assert(a >= b); lp_assert(a >= b);
lean_assert(-a < b); lp_assert(-a < b);
lean_assert(a < 2 * b); lp_assert(a < 2 * b);
lean_assert(b + b > a); lp_assert(b + b > a);
lean_assert(lean::mpq(2.1) * b + b > a); lp_assert(lp::mpq(2.1) * b + b > a);
lean_assert(-b * lean::mpq(2.1) - b < lean::mpq(0.99) * a); lp_assert(-b * lp::mpq(2.1) - b < lp::mpq(0.99) * a);
std::cout << - b * lean::mpq(2.1) - b << std::endl; std::cout << - b * lp::mpq(2.1) - b << std::endl;
lean_assert(-b *(lean::mpq(2.1) + 1) == - b * lean::mpq(2.1) - b); lp_assert(-b *(lp::mpq(2.1) + 1) == - b * lp::mpq(2.1) - b);
} }
void get_matrix_dimensions(std::ifstream & f, unsigned & m, unsigned & n) { void get_matrix_dimensions(std::ifstream & f, unsigned & m, unsigned & n) {
@ -2566,7 +2566,7 @@ void read_row_cols(unsigned i, static_matrix<double, double>& A, std::ifstream &
if (line== "row_end") if (line== "row_end")
break; break;
auto r = split_and_trim(line); auto r = split_and_trim(line);
lean_assert(r.size() == 4); lp_assert(r.size() == 4);
unsigned j = atoi(r[1].c_str()); unsigned j = atoi(r[1].c_str());
double v = atof(r[3].c_str()); double v = atof(r[3].c_str());
A.set(i, j, v); A.set(i, j, v);
@ -2594,7 +2594,7 @@ void read_basis(vector<unsigned> & basis, std::ifstream & f) {
std::cout << "reading basis" << std::endl; std::cout << "reading basis" << std::endl;
std::string line; std::string line;
getline(f, line); getline(f, line);
lean_assert(line == "basis_start"); lp_assert(line == "basis_start");
do { do {
getline(f, line); getline(f, line);
if (line == "basis_end") if (line == "basis_end")
@ -2607,7 +2607,7 @@ void read_basis(vector<unsigned> & basis, std::ifstream & f) {
void read_indexed_vector(indexed_vector<double> & v, std::ifstream & f) { void read_indexed_vector(indexed_vector<double> & v, std::ifstream & f) {
std::string line; std::string line;
getline(f, line); getline(f, line);
lean_assert(line == "vector_start"); lp_assert(line == "vector_start");
do { do {
getline(f, line); getline(f, line);
if (line == "vector_end") break; if (line == "vector_end") break;
@ -2647,7 +2647,7 @@ void check_lu_from_file(std::string lufile_name) {
A.copy_column_to_vector(entering, a); A.copy_column_to_vector(entering, a);
indexed_vector<double> cd(d); indexed_vector<double> cd(d);
B.apply_from_left(cd.m_data, settings); B.apply_from_left(cd.m_data, settings);
lean_assert(vectors_are_equal(cd.m_data , a)); lp_assert(vectors_are_equal(cd.m_data , a));
#endif #endif
} }
@ -2745,7 +2745,7 @@ void test_evidence_for_total_inf_simple(argument_parser & args_parser) {
auto status = solver.solve(); auto status = solver.solve();
std::cout << lp_status_to_string(status) << std::endl; std::cout << lp_status_to_string(status) << std::endl;
std::unordered_map<var_index, mpq> model; std::unordered_map<var_index, mpq> model;
lean_assert(solver.get_status() == INFEASIBLE); lp_assert(solver.get_status() == INFEASIBLE);
} }
void test_bound_propagation_one_small_sample1() { void test_bound_propagation_one_small_sample1() {
/* /*
@ -2941,8 +2941,8 @@ void test_total_case_l(){
ls.solve(); ls.solve();
bound_propagator bp(ls); bound_propagator bp(ls);
ls.propagate_bounds_for_touched_rows(bp); ls.propagate_bounds_for_touched_rows(bp);
lean_assert(ev.size() == 4); lp_assert(ev.size() == 4);
lean_assert(contains_j_kind(x, GE, - one_of_type<mpq>(), ev)); lp_assert(contains_j_kind(x, GE, - one_of_type<mpq>(), ev));
} }
void test_bound_propagation() { void test_bound_propagation() {
test_total_case_u(); test_total_case_u();
@ -2962,17 +2962,17 @@ void test_int_set() {
s.insert(1); s.insert(1);
s.insert(2); s.insert(2);
s.print(std::cout); s.print(std::cout);
lean_assert(s.contains(2)); lp_assert(s.contains(2));
lean_assert(s.size() == 2); lp_assert(s.size() == 2);
s.erase(2); s.erase(2);
lean_assert(s.size() == 1); lp_assert(s.size() == 1);
s.erase(2); s.erase(2);
lean_assert(s.size() == 1); lp_assert(s.size() == 1);
s.print(std::cout); s.print(std::cout);
s.insert(3); s.insert(3);
s.insert(2); s.insert(2);
s.clear(); s.clear();
lean_assert(s.size() == 0); lp_assert(s.size() == 0);
} }
@ -3226,7 +3226,7 @@ void test_lp_local(int argn, char**argv) {
ret = 0; ret = 0;
return finalize(ret); return finalize(ret);
} }
// lean::ccc = 0; // lp::ccc = 0;
return finalize(0); return finalize(0);
test_init_U(); test_init_U();
test_replace_column(); test_replace_column();
@ -3243,5 +3243,5 @@ void test_lp_local(int argn, char**argv) {
} }
} }
void tst_lp(char ** argv, int argc, int& i) { void tst_lp(char ** argv, int argc, int& i) {
lean::test_lp_local(argc - 2, argv + 2); lp::test_lp_local(argc - 2, argv + 2);
} }

View file

@ -2,12 +2,12 @@ void gparams_register_modules(){}
void mem_initialize() {} void mem_initialize() {}
void mem_finalize() {} void mem_finalize() {}
#include "util/rational.h" #include "util/rational.h"
namespace lean { namespace lp {
void test_lp_local(int argc, char**argv); void test_lp_local(int argc, char**argv);
} }
int main(int argn, char**argv){ int main(int argn, char**argv){
rational::initialize(); rational::initialize();
lean::test_lp_local(argn, argv); lp::test_lp_local(argn, argv);
rational::finalize(); rational::finalize();
return 0; return 0;
} }

View file

@ -23,7 +23,7 @@
#include "util/lp/lar_constraints.h" #include "util/lp/lar_constraints.h"
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
namespace lean { namespace lp {
template<typename T> template<typename T>
T from_string(const std::string& str) { T from_string(const std::string& str) {
@ -108,13 +108,13 @@ namespace lean {
void fill_simple_elem(lisp_elem & lm) { void fill_simple_elem(lisp_elem & lm) {
int separator = first_separator(); int separator = first_separator();
lean_assert(-1 != separator && separator != 0); lp_assert(-1 != separator && separator != 0);
lm.m_head = m_line.substr(0, separator); lm.m_head = m_line.substr(0, separator);
m_line = m_line.substr(separator); m_line = m_line.substr(separator);
} }
void fill_nested_elem(lisp_elem & lm) { void fill_nested_elem(lisp_elem & lm) {
lean_assert(m_line[0] == '('); lp_assert(m_line[0] == '(');
m_line = m_line.substr(1); m_line = m_line.substr(1);
int separator = first_separator(); int separator = first_separator();
lm.m_head = m_line.substr(0, separator); lm.m_head = m_line.substr(0, separator);
@ -181,11 +181,11 @@ namespace lean {
} }
void adjust_rigth_side(formula_constraint & /* c*/, lisp_elem & /*el*/) { void adjust_rigth_side(formula_constraint & /* c*/, lisp_elem & /*el*/) {
// lean_assert(el.m_head == "0"); // do nothing for the time being // lp_assert(el.m_head == "0"); // do nothing for the time being
} }
void set_constraint_coeffs(formula_constraint & c, lisp_elem & el) { void set_constraint_coeffs(formula_constraint & c, lisp_elem & el) {
lean_assert(el.m_elems.size() == 2); lp_assert(el.m_elems.size() == 2);
set_constraint_coeffs_on_coeff_element(c, el.m_elems[0]); set_constraint_coeffs_on_coeff_element(c, el.m_elems[0]);
adjust_rigth_side(c, el.m_elems[1]); adjust_rigth_side(c, el.m_elems[1]);
} }
@ -201,7 +201,7 @@ namespace lean {
add_mult_elem(c, el.m_elems); add_mult_elem(c, el.m_elems);
} else if (el.m_head == "~") { } else if (el.m_head == "~") {
lisp_elem & minel = el.m_elems[0]; lisp_elem & minel = el.m_elems[0];
lean_assert(minel.is_simple()); lp_assert(minel.is_simple());
c.m_right_side += mpq(str_to_int(minel.m_head)); c.m_right_side += mpq(str_to_int(minel.m_head));
} else { } else {
std::cout << "unexpected input " << el.m_head << std::endl; std::cout << "unexpected input " << el.m_head << std::endl;
@ -211,14 +211,14 @@ namespace lean {
} }
std::string get_name(lisp_elem & name) { std::string get_name(lisp_elem & name) {
lean_assert(name.is_simple()); lp_assert(name.is_simple());
lean_assert(!is_integer(name.m_head)); lp_assert(!is_integer(name.m_head));
return name.m_head; return name.m_head;
} }
void add_mult_elem(formula_constraint & c, std::vector<lisp_elem> & els) { void add_mult_elem(formula_constraint & c, std::vector<lisp_elem> & els) {
lean_assert(els.size() == 2); lp_assert(els.size() == 2);
mpq coeff = get_coeff(els[0]); mpq coeff = get_coeff(els[0]);
std::string col_name = get_name(els[1]); std::string col_name = get_name(els[1]);
c.add_pair(coeff, col_name); c.add_pair(coeff, col_name);
@ -228,16 +228,16 @@ namespace lean {
if (le.is_simple()) { if (le.is_simple()) {
return mpq(str_to_int(le.m_head)); return mpq(str_to_int(le.m_head));
} else { } else {
lean_assert(le.m_head == "~"); lp_assert(le.m_head == "~");
lean_assert(le.size() == 1); lp_assert(le.size() == 1);
lisp_elem & el = le.m_elems[0]; lisp_elem & el = le.m_elems[0];
lean_assert(el.is_simple()); lp_assert(el.is_simple());
return -mpq(str_to_int(el.m_head)); return -mpq(str_to_int(el.m_head));
} }
} }
int str_to_int(std::string & s) { int str_to_int(std::string & s) {
lean_assert(is_integer(s)); lp_assert(is_integer(s));
return atoi(s.c_str()); return atoi(s.c_str());
} }
@ -245,7 +245,7 @@ namespace lean {
if (el.size()) { if (el.size()) {
add_complex_sum_elem(c, el); add_complex_sum_elem(c, el);
} else { } else {
lean_assert(is_integer(el.m_head)); lp_assert(is_integer(el.m_head));
int v = atoi(el.m_head.c_str()); int v = atoi(el.m_head.c_str());
mpq vr(v); mpq vr(v);
c.m_right_side -= vr; c.m_right_side -= vr;
@ -263,7 +263,7 @@ namespace lean {
} else if (el.m_head == "+") { } else if (el.m_head == "+") {
add_sum(c, el.m_elems); add_sum(c, el.m_elems);
} else { } else {
lean_assert(false); // unexpected input lp_assert(false); // unexpected input
} }
} }

View file

@ -15,7 +15,7 @@ Author: Lev Nachmanson
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/lp_solver.h" #include "util/lp/lp_solver.h"
namespace lean { namespace lp {
template <typename T> template <typename T>
struct test_result { struct test_result {

View file

@ -7,7 +7,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/debug.h" #include "util/debug.h"
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
namespace lean { namespace lp {
// the elements with the smallest priority are dequeued first // the elements with the smallest priority are dequeued first
template <typename T> template <typename T>
class binary_heap_priority_queue { class binary_heap_priority_queue {
@ -60,7 +60,7 @@ public:
/// return the first element of the queue and removes it from the queue /// return the first element of the queue and removes it from the queue
unsigned dequeue(); unsigned dequeue();
unsigned peek() const { unsigned peek() const {
lean_assert(m_heap_size > 0); lp_assert(m_heap_size > 0);
return m_heap[1]; return m_heap[1];
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG

View file

@ -4,7 +4,7 @@
*/ */
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/binary_heap_priority_queue.h" #include "util/lp/binary_heap_priority_queue.h"
namespace lean { namespace lp {
// is is the child place in heap // is is the child place in heap
template <typename T> void binary_heap_priority_queue<T>::swap_with_parent(unsigned i) { template <typename T> void binary_heap_priority_queue<T>::swap_with_parent(unsigned i) {
unsigned parent = m_heap[i >> 1]; unsigned parent = m_heap[i >> 1];
@ -33,8 +33,8 @@ template <typename T> void binary_heap_priority_queue<T>::decrease_priority(unsi
template <typename T> bool binary_heap_priority_queue<T>::is_consistent() const { template <typename T> bool binary_heap_priority_queue<T>::is_consistent() const {
for (int i = 0; i < m_heap_inverse.size(); i++) { for (int i = 0; i < m_heap_inverse.size(); i++) {
int i_index = m_heap_inverse[i]; int i_index = m_heap_inverse[i];
lean_assert(i_index <= static_cast<int>(m_heap_size)); lp_assert(i_index <= static_cast<int>(m_heap_size));
lean_assert(i_index == -1 || m_heap[i_index] == i); lp_assert(i_index == -1 || m_heap[i_index] == i);
} }
for (unsigned i = 1; i < m_heap_size; i++) { for (unsigned i = 1; i < m_heap_size; i++) {
unsigned ch = i << 1; unsigned ch = i << 1;
@ -55,7 +55,7 @@ template <typename T> void binary_heap_priority_queue<T>::remove(unsigned o) {
if (o_in_heap == -1) { if (o_in_heap == -1) {
return; // nothing to do return; // nothing to do
} }
lean_assert(static_cast<unsigned>(o_in_heap) <= m_heap_size); lp_assert(static_cast<unsigned>(o_in_heap) <= m_heap_size);
if (static_cast<unsigned>(o_in_heap) < m_heap_size) { if (static_cast<unsigned>(o_in_heap) < m_heap_size) {
put_at(o_in_heap, m_heap[m_heap_size--]); put_at(o_in_heap, m_heap[m_heap_size--]);
if (m_priorities[m_heap[o_in_heap]] > priority_of_o) { if (m_priorities[m_heap[o_in_heap]] > priority_of_o) {
@ -72,11 +72,11 @@ template <typename T> void binary_heap_priority_queue<T>::remove(unsigned o) {
} }
} }
} else { } else {
lean_assert(static_cast<unsigned>(o_in_heap) == m_heap_size); lp_assert(static_cast<unsigned>(o_in_heap) == m_heap_size);
m_heap_size--; m_heap_size--;
} }
m_heap_inverse[o] = -1; m_heap_inverse[o] = -1;
// lean_assert(is_consistent()); // lp_assert(is_consistent());
} }
// n is the initial queue capacity. // n is the initial queue capacity.
// The capacity will be enlarged two times automatically if needed // The capacity will be enlarged two times automatically if needed
@ -102,7 +102,7 @@ template <typename T> void binary_heap_priority_queue<T>::put_to_heap(unsigned i
template <typename T> void binary_heap_priority_queue<T>::enqueue_new(unsigned o, const T& priority) { template <typename T> void binary_heap_priority_queue<T>::enqueue_new(unsigned o, const T& priority) {
m_heap_size++; m_heap_size++;
int i = m_heap_size; int i = m_heap_size;
lean_assert(o < m_priorities.size()); lp_assert(o < m_priorities.size());
m_priorities[o] = priority; m_priorities[o] = priority;
put_at(i, o); put_at(i, o);
while (i > 1 && m_priorities[m_heap[i >> 1]] > priority) { while (i > 1 && m_priorities[m_heap[i >> 1]] > priority) {
@ -134,7 +134,7 @@ template <typename T> void binary_heap_priority_queue<T>::change_priority_for_ex
/// return the first element of the queue and removes it from the queue /// return the first element of the queue and removes it from the queue
template <typename T> unsigned binary_heap_priority_queue<T>::dequeue_and_get_priority(T & priority) { template <typename T> unsigned binary_heap_priority_queue<T>::dequeue_and_get_priority(T & priority) {
lean_assert(m_heap_size != 0); lp_assert(m_heap_size != 0);
int ret = m_heap[1]; int ret = m_heap[1];
priority = m_priorities[ret]; priority = m_priorities[ret];
put_the_last_at_the_top_and_fix_the_heap(); put_the_last_at_the_top_and_fix_the_heap();
@ -168,7 +168,7 @@ template <typename T> void binary_heap_priority_queue<T>::put_the_last_at_the_to
} }
/// return the first element of the queue and removes it from the queue /// return the first element of the queue and removes it from the queue
template <typename T> unsigned binary_heap_priority_queue<T>::dequeue() { template <typename T> unsigned binary_heap_priority_queue<T>::dequeue() {
lean_assert(m_heap_size > 0); lp_assert(m_heap_size > 0);
int ret = m_heap[1]; int ret = m_heap[1];
put_the_last_at_the_top_and_fix_the_heap(); put_the_last_at_the_top_and_fix_the_heap();
m_heap_inverse[ret] = -1; m_heap_inverse[ret] = -1;

View file

@ -4,7 +4,7 @@
*/ */
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
#include "util/lp/binary_heap_priority_queue.hpp" #include "util/lp/binary_heap_priority_queue.hpp"
namespace lean { namespace lp {
template binary_heap_priority_queue<int>::binary_heap_priority_queue(unsigned int); template binary_heap_priority_queue<int>::binary_heap_priority_queue(unsigned int);
template unsigned binary_heap_priority_queue<int>::dequeue(); template unsigned binary_heap_priority_queue<int>::dequeue();
template void binary_heap_priority_queue<int>::enqueue(unsigned int, int const&); template void binary_heap_priority_queue<int>::enqueue(unsigned int, int const&);
@ -16,11 +16,11 @@ template unsigned binary_heap_priority_queue<double>::dequeue();
template unsigned binary_heap_priority_queue<mpq>::dequeue(); template unsigned binary_heap_priority_queue<mpq>::dequeue();
template void binary_heap_priority_queue<numeric_pair<mpq> >::enqueue(unsigned int, numeric_pair<mpq> const&); template void binary_heap_priority_queue<numeric_pair<mpq> >::enqueue(unsigned int, numeric_pair<mpq> const&);
template void binary_heap_priority_queue<numeric_pair<mpq> >::resize(unsigned int); template void binary_heap_priority_queue<numeric_pair<mpq> >::resize(unsigned int);
template void lean::binary_heap_priority_queue<double>::resize(unsigned int); template void lp::binary_heap_priority_queue<double>::resize(unsigned int);
template binary_heap_priority_queue<unsigned int>::binary_heap_priority_queue(unsigned int); template binary_heap_priority_queue<unsigned int>::binary_heap_priority_queue(unsigned int);
template void binary_heap_priority_queue<unsigned>::resize(unsigned int); template void binary_heap_priority_queue<unsigned>::resize(unsigned int);
template unsigned binary_heap_priority_queue<unsigned int>::dequeue(); template unsigned binary_heap_priority_queue<unsigned int>::dequeue();
template void binary_heap_priority_queue<unsigned int>::enqueue(unsigned int, unsigned int const&); template void binary_heap_priority_queue<unsigned int>::enqueue(unsigned int, unsigned int const&);
template void binary_heap_priority_queue<unsigned int>::remove(unsigned int); template void binary_heap_priority_queue<unsigned int>::remove(unsigned int);
template void lean::binary_heap_priority_queue<mpq>::resize(unsigned int); template void lp::binary_heap_priority_queue<mpq>::resize(unsigned int);
} }

View file

@ -15,7 +15,7 @@
typedef std::pair<unsigned, unsigned> upair; typedef std::pair<unsigned, unsigned> upair;
namespace lean { namespace lp {
template <typename T> template <typename T>
class binary_heap_upair_queue { class binary_heap_upair_queue {
binary_heap_priority_queue<T> m_q; binary_heap_priority_queue<T> m_q;

View file

@ -6,7 +6,7 @@
#include <set> #include <set>
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/binary_heap_upair_queue.h" #include "util/lp/binary_heap_upair_queue.h"
namespace lean { namespace lp {
template <typename T> binary_heap_upair_queue<T>::binary_heap_upair_queue(unsigned size) : m_q(size), m_pairs(size) { template <typename T> binary_heap_upair_queue<T>::binary_heap_upair_queue(unsigned size) : m_q(size), m_pairs(size) {
for (unsigned i = 0; i < size; i++) for (unsigned i = 0; i < size; i++)
m_available_spots.push_back(i); m_available_spots.push_back(i);
@ -14,7 +14,7 @@ template <typename T> binary_heap_upair_queue<T>::binary_heap_upair_queue(unsign
template <typename T> unsigned template <typename T> unsigned
binary_heap_upair_queue<T>::dequeue_available_spot() { binary_heap_upair_queue<T>::dequeue_available_spot() {
lean_assert(m_available_spots.empty() == false); lp_assert(m_available_spots.empty() == false);
unsigned ret = m_available_spots.back(); unsigned ret = m_available_spots.back();
m_available_spots.pop_back(); m_available_spots.pop_back();
return ret; return ret;
@ -54,7 +54,7 @@ template <typename T> void binary_heap_upair_queue<T>::enqueue(unsigned i, unsig
m_pairs.resize(new_size); m_pairs.resize(new_size);
} }
ij_index = dequeue_available_spot(); ij_index = dequeue_available_spot();
// lean_assert(ij_index<m_pairs.size() && ij_index_is_new(ij_index)); // lp_assert(ij_index<m_pairs.size() && ij_index_is_new(ij_index));
m_pairs[ij_index] = p; m_pairs[ij_index] = p;
m_pairs_to_index[p] = ij_index; m_pairs_to_index[p] = ij_index;
} else { } else {
@ -64,7 +64,7 @@ template <typename T> void binary_heap_upair_queue<T>::enqueue(unsigned i, unsig
} }
template <typename T> void binary_heap_upair_queue<T>::dequeue(unsigned & i, unsigned &j) { template <typename T> void binary_heap_upair_queue<T>::dequeue(unsigned & i, unsigned &j) {
lean_assert(!m_q.is_empty()); lp_assert(!m_q.is_empty());
unsigned ij_index = m_q.dequeue(); unsigned ij_index = m_q.dequeue();
upair & p = m_pairs[ij_index]; upair & p = m_pairs[ij_index];
i = p.first; i = p.first;

View file

@ -3,7 +3,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#include "util/lp/binary_heap_upair_queue.hpp" #include "util/lp/binary_heap_upair_queue.hpp"
namespace lean { namespace lp {
template binary_heap_upair_queue<int>::binary_heap_upair_queue(unsigned int); template binary_heap_upair_queue<int>::binary_heap_upair_queue(unsigned int);
template binary_heap_upair_queue<unsigned int>::binary_heap_upair_queue(unsigned int); template binary_heap_upair_queue<unsigned int>::binary_heap_upair_queue(unsigned int);
template unsigned binary_heap_upair_queue<int>::dequeue_available_spot(); template unsigned binary_heap_upair_queue<int>::dequeue_available_spot();

View file

@ -13,7 +13,7 @@
// We try to pin a var by pushing the total by using the variable bounds // We try to pin a var by pushing the total by using the variable bounds
// In a loop we drive the partial sum down, denoting the variables of this process by _u. // In a loop we drive the partial sum down, denoting the variables of this process by _u.
// In the same loop trying to pin variables by pushing the partial sum up, denoting the variable related to it by _l // In the same loop trying to pin variables by pushing the partial sum up, denoting the variable related to it by _l
namespace lean { namespace lp {
class bound_analyzer_on_row { class bound_analyzer_on_row {
@ -91,11 +91,11 @@ public :
} }
const impq & ub(unsigned j) const { const impq & ub(unsigned j) const {
lean_assert(upper_bound_is_available(j)); lp_assert(upper_bound_is_available(j));
return m_bp.get_upper_bound(j); return m_bp.get_upper_bound(j);
} }
const impq & lb(unsigned j) const { const impq & lb(unsigned j) const {
lean_assert(low_bound_is_available(j)); lp_assert(low_bound_is_available(j));
return m_bp.get_low_bound(j); return m_bp.get_low_bound(j);
} }
@ -153,7 +153,7 @@ public :
void limit_all_monoids_from_above() { void limit_all_monoids_from_above() {
int strict = 0; int strict = 0;
mpq total; mpq total;
lean_assert(is_zero(total)); lp_assert(is_zero(total));
m_it.reset(); m_it.reset();
mpq a; unsigned j; mpq a; unsigned j;
while (m_it.next(a, j)) { while (m_it.next(a, j)) {
@ -180,7 +180,7 @@ public :
void limit_all_monoids_from_below() { void limit_all_monoids_from_below() {
int strict = 0; int strict = 0;
mpq total; mpq total;
lean_assert(is_zero(total)); lp_assert(is_zero(total));
m_it.reset(); m_it.reset();
mpq a; unsigned j; mpq a; unsigned j;
while (m_it.next(a, j)) { while (m_it.next(a, j)) {
@ -272,7 +272,7 @@ public :
// mpq a; unsigned j; // mpq a; unsigned j;
// while (it->next(a, j)) { // while (it->next(a, j)) {
// if (be.m_j == j) continue; // if (be.m_j == j) continue;
// lean_assert(bound_is_available(j, is_neg(a) ? low_bound : !low_bound)); // lp_assert(bound_is_available(j, is_neg(a) ? low_bound : !low_bound));
// be.m_vector_of_bound_signatures.emplace_back(a, j, numeric_traits<impq>:: // be.m_vector_of_bound_signatures.emplace_back(a, j, numeric_traits<impq>::
// is_neg(a)? low_bound: !low_bound); // is_neg(a)? low_bound: !low_bound);
// } // }

View file

@ -3,7 +3,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
namespace lean { namespace lp {
bound_propagator::bound_propagator(lar_solver & ls): bound_propagator::bound_propagator(lar_solver & ls):
m_lar_solver(ls) {} m_lar_solver(ls) {}
column_type bound_propagator::get_column_type(unsigned j) const { column_type bound_propagator::get_column_type(unsigned j) const {

View file

@ -4,7 +4,7 @@
*/ */
#pragma once #pragma once
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
namespace lean { namespace lp {
class lar_solver; class lar_solver;
class bound_propagator { class bound_propagator {
std::unordered_map<unsigned, unsigned> m_improved_low_bounds; // these maps map a column index to the corresponding index in ibounds std::unordered_map<unsigned, unsigned> m_improved_low_bounds; // these maps map a column index to the corresponding index in ibounds
@ -19,7 +19,7 @@ public:
const impq & get_upper_bound(unsigned) const; const impq & get_upper_bound(unsigned) const;
void try_add_bound(const mpq & v, unsigned j, bool is_low, bool coeff_before_j_is_pos, unsigned row_or_term_index, bool strict); void try_add_bound(const mpq & v, unsigned j, bool is_low, bool coeff_before_j_is_pos, unsigned row_or_term_index, bool strict);
virtual bool bound_is_interesting(unsigned vi, virtual bool bound_is_interesting(unsigned vi,
lean::lconstraint_kind kind, lp::lconstraint_kind kind,
const rational & bval) {return true;} const rational & bval) {return true;}
unsigned number_of_found_bounds() const { return m_ibounds.size(); } unsigned number_of_found_bounds() const { return m_ibounds.size(); }
virtual void consume(mpq const& v, unsigned j) { std::cout << "doh\n"; } virtual void consume(mpq const& v, unsigned j) { std::cout << "doh\n"; }

View file

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace lean { namespace lp {
enum breakpoint_type { enum breakpoint_type {
low_break, upper_break, fixed_break low_break, upper_break, fixed_break
}; };

View file

@ -9,7 +9,7 @@
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
namespace lean { namespace lp {
inline bool is_valid(unsigned j) { return static_cast<int>(j) >= 0;} inline bool is_valid(unsigned j) { return static_cast<int>(j) >= 0;}
template <typename T> template <typename T>
@ -100,11 +100,11 @@ public:
} }
T get_low_bound() const { T get_low_bound() const {
lean_assert(m_low_bound_is_set); lp_assert(m_low_bound_is_set);
return m_low_bound; return m_low_bound;
} }
T get_upper_bound() const { T get_upper_bound() const {
lean_assert(m_upper_bound_is_set); lp_assert(m_upper_bound_is_set);
return m_upper_bound; return m_upper_bound;
} }
@ -156,7 +156,7 @@ public:
} }
T get_fixed_value() const { T get_fixed_value() const {
lean_assert(m_is_fixed); lp_assert(m_is_fixed);
return m_fixed_value; return m_fixed_value;
} }

View file

@ -5,7 +5,7 @@
*/ */
#include <string> #include <string>
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
namespace lean { namespace lp {
class column_namer { class column_namer {
public: public:
virtual std::string get_column_name(unsigned j) const = 0; virtual std::string get_column_name(unsigned j) const = 0;

View file

@ -4,7 +4,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#pragma once #pragma once
namespace lean { namespace lp {
template <typename V> template <typename V>
struct conversion_helper { struct conversion_helper {
static V get_low_bound(const column_info<mpq> & ci) { static V get_low_bound(const column_info<mpq> & ci) {

View file

@ -10,7 +10,7 @@
#include <ostream> #include <ostream>
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
#include "util/lp/indexed_vector.h" #include "util/lp/indexed_vector.h"
namespace lean { namespace lp {
template <typename T, typename X> class lp_core_solver_base; // forward definition template <typename T, typename X> class lp_core_solver_base; // forward definition
template <typename T, typename X> template <typename T, typename X>

View file

@ -9,7 +9,7 @@
#include "util/lp/lp_core_solver_base.h" #include "util/lp/lp_core_solver_base.h"
#include "util/lp/core_solver_pretty_printer.h" #include "util/lp/core_solver_pretty_printer.h"
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
@ -148,7 +148,7 @@ template <typename T, typename X> void core_solver_pretty_printer<T, X>::adjust_
case column_type::free_column: case column_type::free_column:
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
} }
@ -357,7 +357,7 @@ template <typename T, typename X> void core_solver_pretty_printer<T, X>::print_g
unsigned width = m_column_widths[col]; unsigned width = m_column_widths[col];
string s = row[col]; string s = row[col];
int number_of_blanks = width - static_cast<unsigned>(s.size()); int number_of_blanks = width - static_cast<unsigned>(s.size());
lean_assert(number_of_blanks >= 0); lp_assert(number_of_blanks >= 0);
print_blanks(number_of_blanks, m_out); print_blanks(number_of_blanks, m_out);
m_out << s << ' '; m_out << s << ' ';
if (col < row.size() - 1) { if (col < row.size() - 1) {
@ -368,7 +368,7 @@ template <typename T, typename X> void core_solver_pretty_printer<T, X>::print_g
string rs = T_to_string(rst); string rs = T_to_string(rst);
int nb = m_rs_width - static_cast<int>(rs.size()); int nb = m_rs_width - static_cast<int>(rs.size());
lean_assert(nb >= 0); lp_assert(nb >= 0);
print_blanks(nb + 1, m_out); print_blanks(nb + 1, m_out);
m_out << rs << std::endl; m_out << rs << std::endl;
} }

View file

@ -4,12 +4,12 @@
*/ */
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
#include "util/lp/core_solver_pretty_printer.hpp" #include "util/lp/core_solver_pretty_printer.hpp"
template lean::core_solver_pretty_printer<double, double>::core_solver_pretty_printer(lean::lp_core_solver_base<double, double> &, std::ostream & out); template lp::core_solver_pretty_printer<double, double>::core_solver_pretty_printer(lp::lp_core_solver_base<double, double> &, std::ostream & out);
template void lean::core_solver_pretty_printer<double, double>::print(); template void lp::core_solver_pretty_printer<double, double>::print();
template lean::core_solver_pretty_printer<double, double>::~core_solver_pretty_printer(); template lp::core_solver_pretty_printer<double, double>::~core_solver_pretty_printer();
template lean::core_solver_pretty_printer<lean::mpq, lean::mpq>::core_solver_pretty_printer(lean::lp_core_solver_base<lean::mpq, lean::mpq> &, std::ostream & out); template lp::core_solver_pretty_printer<lp::mpq, lp::mpq>::core_solver_pretty_printer(lp::lp_core_solver_base<lp::mpq, lp::mpq> &, std::ostream & out);
template void lean::core_solver_pretty_printer<lean::mpq, lean::mpq>::print(); template void lp::core_solver_pretty_printer<lp::mpq, lp::mpq>::print();
template lean::core_solver_pretty_printer<lean::mpq, lean::mpq>::~core_solver_pretty_printer(); template lp::core_solver_pretty_printer<lp::mpq, lp::mpq>::~core_solver_pretty_printer();
template lean::core_solver_pretty_printer<lean::mpq, lean::numeric_pair<lean::mpq> >::core_solver_pretty_printer(lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> > &, std::ostream & out); template lp::core_solver_pretty_printer<lp::mpq, lp::numeric_pair<lp::mpq> >::core_solver_pretty_printer(lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> > &, std::ostream & out);
template lean::core_solver_pretty_printer<lean::mpq, lean::numeric_pair<lean::mpq> >::~core_solver_pretty_printer(); template lp::core_solver_pretty_printer<lp::mpq, lp::numeric_pair<lp::mpq> >::~core_solver_pretty_printer();
template void lean::core_solver_pretty_printer<lean::mpq, lean::numeric_pair<lean::mpq> >::print(); template void lp::core_solver_pretty_printer<lp::mpq, lp::numeric_pair<lp::mpq> >::print();

View file

@ -6,7 +6,7 @@
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/matrix.h" #include "util/lp/matrix.h"
namespace lean { namespace lp {
// used for debugging purposes only // used for debugging purposes only
template <typename T, typename X> template <typename T, typename X>
class dense_matrix: public matrix<T, X> { class dense_matrix: public matrix<T, X> {
@ -31,7 +31,7 @@ public:
dense_matrix(unsigned m, unsigned n); dense_matrix(unsigned m, unsigned n);
dense_matrix operator*=(matrix<T, X> const & a) { dense_matrix operator*=(matrix<T, X> const & a) {
lean_assert(column_count() == a.row_count()); lp_assert(column_count() == a.row_count());
dense_matrix c(row_count(), a.column_count()); dense_matrix c(row_count(), a.column_count());
for (unsigned i = 0; i < row_count(); i++) { for (unsigned i = 0; i < row_count(); i++) {
for (unsigned j = 0; j < a.column_count(); j++) { for (unsigned j = 0; j < a.column_count(); j++) {

View file

@ -7,7 +7,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
#include "util/lp/dense_matrix.h" #include "util/lp/dense_matrix.h"
namespace lean { namespace lp {
template <typename T> void print_vector(const vector<T> & t, std::ostream & out); template <typename T> void print_vector(const vector<T> & t, std::ostream & out);
template <typename T, typename X> dense_matrix<T, X>::dense_matrix(unsigned m, unsigned n) : m_m(m), m_n(n), m_values(m * n, numeric_traits<T>::zero()) { template <typename T, typename X> dense_matrix<T, X>::dense_matrix(unsigned m, unsigned n) : m_m(m), m_n(n), m_values(m * n, numeric_traits<T>::zero()) {
} }
@ -170,7 +170,7 @@ template <typename T, typename X> void dense_matrix<T, X>::multiply_row_by_const
template <typename T, typename X> template <typename T, typename X>
dense_matrix<T, X> operator* (matrix<T, X> & a, matrix<T, X> & b){ dense_matrix<T, X> operator* (matrix<T, X> & a, matrix<T, X> & b){
lean_assert(a.column_count() == b.row_count()); lp_assert(a.column_count() == b.row_count());
dense_matrix<T, X> ret(a.row_count(), b.column_count()); dense_matrix<T, X> ret(a.row_count(), b.column_count());
for (unsigned i = 0; i < ret.m_m; i++) for (unsigned i = 0; i < ret.m_m; i++)
for (unsigned j = 0; j< ret.m_n; j++) { for (unsigned j = 0; j< ret.m_n; j++) {

View file

@ -6,20 +6,20 @@
#include "util/lp/dense_matrix.hpp" #include "util/lp/dense_matrix.hpp"
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
#include "util/vector.h" #include "util/vector.h"
template lean::dense_matrix<double, double> lean::operator*<double, double>(lean::matrix<double, double>&, lean::matrix<double, double>&); template lp::dense_matrix<double, double> lp::operator*<double, double>(lp::matrix<double, double>&, lp::matrix<double, double>&);
template void lean::dense_matrix<double, double>::apply_from_left(vector<double> &); template void lp::dense_matrix<double, double>::apply_from_left(vector<double> &);
template lean::dense_matrix<double, double>::dense_matrix(lean::matrix<double, double> const*); template lp::dense_matrix<double, double>::dense_matrix(lp::matrix<double, double> const*);
template lean::dense_matrix<double, double>::dense_matrix(unsigned int, unsigned int); template lp::dense_matrix<double, double>::dense_matrix(unsigned int, unsigned int);
template lean::dense_matrix<double, double>& lean::dense_matrix<double, double>::operator=(lean::dense_matrix<double, double> const&); template lp::dense_matrix<double, double>& lp::dense_matrix<double, double>::operator=(lp::dense_matrix<double, double> const&);
template lean::dense_matrix<lean::mpq, lean::mpq>::dense_matrix(unsigned int, unsigned int); template lp::dense_matrix<lp::mpq, lp::mpq>::dense_matrix(unsigned int, unsigned int);
template lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::dense_matrix(lean::matrix<lean::mpq, lean::numeric_pair<lean::mpq> > const*); template lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::dense_matrix(lp::matrix<lp::mpq, lp::numeric_pair<lp::mpq> > const*);
template void lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_from_left(vector<lean::mpq>&); template void lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_from_left(vector<lp::mpq>&);
template lean::dense_matrix<lean::mpq, lean::mpq> lean::operator*<lean::mpq, lean::mpq>(lean::matrix<lean::mpq, lean::mpq>&, lean::matrix<lean::mpq, lean::mpq>&); template lp::dense_matrix<lp::mpq, lp::mpq> lp::operator*<lp::mpq, lp::mpq>(lp::matrix<lp::mpq, lp::mpq>&, lp::matrix<lp::mpq, lp::mpq>&);
template lean::dense_matrix<lean::mpq, lean::mpq> & lean::dense_matrix<lean::mpq, lean::mpq>::operator=(lean::dense_matrix<lean::mpq, lean::mpq> const&); template lp::dense_matrix<lp::mpq, lp::mpq> & lp::dense_matrix<lp::mpq, lp::mpq>::operator=(lp::dense_matrix<lp::mpq, lp::mpq> const&);
template lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::dense_matrix(unsigned int, unsigned int); template lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::dense_matrix(unsigned int, unsigned int);
template lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >& lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::operator=(lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> > const&); template lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >& lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::operator=(lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> > const&);
template lean::dense_matrix<lean::mpq, lean::numeric_pair<lean::mpq> > lean::operator*<lean::mpq, lean::numeric_pair<lean::mpq> >(lean::matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&, lean::matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&); template lp::dense_matrix<lp::mpq, lp::numeric_pair<lp::mpq> > lp::operator*<lp::mpq, lp::numeric_pair<lp::mpq> >(lp::matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&, lp::matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&);
template void lean::dense_matrix<lean::mpq, lean::numeric_pair< lean::mpq> >::apply_from_right( vector< lean::mpq> &); template void lp::dense_matrix<lp::mpq, lp::numeric_pair< lp::mpq> >::apply_from_right( vector< lp::mpq> &);
template void lean::dense_matrix<double,double>::apply_from_right(class vector<double> &); template void lp::dense_matrix<double,double>::apply_from_right(class vector<double> &);
template void lean::dense_matrix<lean::mpq, lean::mpq>::apply_from_left(vector<lean::mpq>&); template void lp::dense_matrix<lp::mpq, lp::mpq>::apply_from_left(vector<lp::mpq>&);
#endif #endif

View file

@ -7,7 +7,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/tail_matrix.h" #include "util/lp/tail_matrix.h"
#include "util/lp/permutation_matrix.h" #include "util/lp/permutation_matrix.h"
namespace lean { namespace lp {
// This is the sum of a unit matrix and a one-column matrix // This is the sum of a unit matrix and a one-column matrix
template <typename T, typename X> template <typename T, typename X>
@ -61,7 +61,7 @@ public:
void push_back(unsigned row_index, T val ) { void push_back(unsigned row_index, T val ) {
lean_assert(row_index != m_column_index); lp_assert(row_index != m_column_index);
m_column_vector.push_back(row_index, val); m_column_vector.push_back(row_index, val);
} }

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/eta_matrix.h" #include "util/lp/eta_matrix.h"
namespace lean { namespace lp {
// This is the sum of a unit matrix and a one-column matrix // This is the sum of a unit matrix and a one-column matrix
template <typename T, typename X> template <typename T, typename X>
@ -60,7 +60,7 @@ void eta_matrix<T, X>::apply_from_right(vector<T> & w) {
} }
w[m_column_index] = t; w[m_column_index] = t;
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<T>(clone_w, w, get_number_of_rows())); // lp_assert(vectors_are_equal<T>(clone_w, w, get_number_of_rows()));
// delete clone_w; // delete clone_w;
#endif #endif
} }
@ -100,8 +100,8 @@ void eta_matrix<T, X>::apply_from_right(indexed_vector<T> & w) {
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(w.is_OK()); // lp_assert(w.is_OK());
// lean_assert(vectors_are_equal<T>(wcopy, w.m_data)); // lp_assert(vectors_are_equal<T>(wcopy, w.m_data));
#endif #endif
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
@ -130,7 +130,7 @@ void eta_matrix<T, X>::conjugate_by_permutation(permutation_matrix<T, X> & p) {
pair.first = p.get_rev(pair.first); pair.first = p.get_rev(pair.first);
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(deb == *this); // lp_assert(deb == *this);
#endif #endif
} }
} }

View file

@ -7,22 +7,22 @@
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
#include "util/lp/eta_matrix.hpp" #include "util/lp/eta_matrix.hpp"
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template double lean::eta_matrix<double, double>::get_elem(unsigned int, unsigned int) const; template double lp::eta_matrix<double, double>::get_elem(unsigned int, unsigned int) const;
template lean::mpq lean::eta_matrix<lean::mpq, lean::mpq>::get_elem(unsigned int, unsigned int) const; template lp::mpq lp::eta_matrix<lp::mpq, lp::mpq>::get_elem(unsigned int, unsigned int) const;
template lean::mpq lean::eta_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::get_elem(unsigned int, unsigned int) const; template lp::mpq lp::eta_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::get_elem(unsigned int, unsigned int) const;
#endif #endif
template void lean::eta_matrix<double, double>::apply_from_left(vector<double>&, lean::lp_settings&); template void lp::eta_matrix<double, double>::apply_from_left(vector<double>&, lp::lp_settings&);
template void lean::eta_matrix<double, double>::apply_from_right(vector<double>&); template void lp::eta_matrix<double, double>::apply_from_right(vector<double>&);
template void lean::eta_matrix<double, double>::conjugate_by_permutation(lean::permutation_matrix<double, double>&); template void lp::eta_matrix<double, double>::conjugate_by_permutation(lp::permutation_matrix<double, double>&);
template void lean::eta_matrix<lean::mpq, lean::mpq>::apply_from_left(vector<lean::mpq>&, lean::lp_settings&); template void lp::eta_matrix<lp::mpq, lp::mpq>::apply_from_left(vector<lp::mpq>&, lp::lp_settings&);
template void lean::eta_matrix<lean::mpq, lean::mpq>::apply_from_right(vector<lean::mpq>&); template void lp::eta_matrix<lp::mpq, lp::mpq>::apply_from_right(vector<lp::mpq>&);
template void lean::eta_matrix<lean::mpq, lean::mpq>::conjugate_by_permutation(lean::permutation_matrix<lean::mpq, lean::mpq>&); template void lp::eta_matrix<lp::mpq, lp::mpq>::conjugate_by_permutation(lp::permutation_matrix<lp::mpq, lp::mpq>&);
template void lean::eta_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_from_left(vector<lean::numeric_pair<lean::mpq> >&, lean::lp_settings&); template void lp::eta_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_from_left(vector<lp::numeric_pair<lp::mpq> >&, lp::lp_settings&);
template void lean::eta_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_from_right(vector<lean::mpq>&); template void lp::eta_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_from_right(vector<lp::mpq>&);
template void lean::eta_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::conjugate_by_permutation(lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&); template void lp::eta_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::conjugate_by_permutation(lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&);
template void lean::eta_matrix<double, double>::apply_from_left_local<double>(lean::indexed_vector<double>&, lean::lp_settings&); template void lp::eta_matrix<double, double>::apply_from_left_local<double>(lp::indexed_vector<double>&, lp::lp_settings&);
template void lean::eta_matrix<lean::mpq, lean::mpq>::apply_from_left_local<lean::mpq>(lean::indexed_vector<lean::mpq>&, lean::lp_settings&); template void lp::eta_matrix<lp::mpq, lp::mpq>::apply_from_left_local<lp::mpq>(lp::indexed_vector<lp::mpq>&, lp::lp_settings&);
template void lean::eta_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_from_left_local<lean::mpq>(lean::indexed_vector<lean::mpq>&, lean::lp_settings&); template void lp::eta_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_from_left_local<lp::mpq>(lp::indexed_vector<lp::mpq>&, lp::lp_settings&);
template void lean::eta_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_from_right(lean::indexed_vector<lean::mpq>&); template void lp::eta_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_from_right(lp::indexed_vector<lp::mpq>&);
template void lean::eta_matrix<lean::mpq, lean::mpq>::apply_from_right(lean::indexed_vector<lean::mpq>&); template void lp::eta_matrix<lp::mpq, lp::mpq>::apply_from_right(lp::indexed_vector<lp::mpq>&);
template void lean::eta_matrix<double, double>::apply_from_right(lean::indexed_vector<double>&); template void lp::eta_matrix<double, double>::apply_from_right(lp::indexed_vector<double>&);

View file

@ -12,8 +12,8 @@
#endif #endif
namespace std { namespace std {
template<> template<>
struct hash<lean::mpq> { struct hash<lp::mpq> {
inline size_t operator()(const lean::mpq & v) const { inline size_t operator()(const lp::mpq & v) const {
return v.hash(); return v.hash();
} }
}; };

View file

@ -5,7 +5,7 @@
#pragma once #pragma once
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
#include "util/lp/lar_constraints.h" #include "util/lp/lar_constraints.h"
namespace lean { namespace lp {
struct implied_bound { struct implied_bound {
mpq m_bound; mpq m_bound;
unsigned m_j; // the column for which the bound has been found unsigned m_j; // the column for which the bound has been found

View file

@ -4,7 +4,7 @@
*/ */
#pragma once #pragma once
namespace lean { namespace lp {
template <typename T> template <typename T>
class indexed_value { class indexed_value {
public: public:

View file

@ -11,7 +11,7 @@
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
#include <unordered_set> #include <unordered_set>
namespace lean { namespace lp {
template <typename T> void print_vector(const vector<T> & t, std::ostream & out); template <typename T> void print_vector(const vector<T> & t, std::ostream & out);
template <typename T> void print_vector(const buffer<T> & t, std::ostream & out); template <typename T> void print_vector(const buffer<T> & t, std::ostream & out);
@ -86,7 +86,7 @@ public:
return m_data[i]; return m_data[i];
} }
void clean_up() { void clp_up() {
#if 0==1 #if 0==1
for (unsigned k = 0; k < m_index.size(); k++) { for (unsigned k = 0; k < m_index.size(); k++) {
unsigned i = m_index[k]; unsigned i = m_index[k];
@ -140,7 +140,7 @@ public:
} }
} }
void restore_index_and_clean_from_data() { void restore_index_and_clp_from_data() {
m_index.resize(0); m_index.resize(0);
for (unsigned i = 0; i < m_data.size(); i++) { for (unsigned i = 0; i < m_data.size(); i++) {
T & v = m_data[i]; T & v = m_data[i];

View file

@ -5,7 +5,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/indexed_vector.h" #include "util/lp/indexed_vector.h"
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
namespace lean { namespace lp {
template <typename T> template <typename T>
void print_vector(const vector<T> & t, std::ostream & out) { void print_vector(const vector<T> & t, std::ostream & out) {
@ -41,13 +41,13 @@ template <typename T>
void indexed_vector<T>::resize(unsigned data_size) { void indexed_vector<T>::resize(unsigned data_size) {
clear(); clear();
m_data.resize(data_size, numeric_traits<T>::zero()); m_data.resize(data_size, numeric_traits<T>::zero());
lean_assert(is_OK()); lp_assert(is_OK());
} }
template <typename T> template <typename T>
void indexed_vector<T>::set_value(const T& value, unsigned index) { void indexed_vector<T>::set_value(const T& value, unsigned index) {
m_data[index] = value; m_data[index] = value;
lean_assert(std::find(m_index.begin(), m_index.end(), index) == m_index.end()); lp_assert(std::find(m_index.begin(), m_index.end(), index) == m_index.end());
m_index.push_back(index); m_index.push_back(index);
} }

View file

@ -4,7 +4,7 @@
*/ */
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/indexed_vector.hpp" #include "util/lp/indexed_vector.hpp"
namespace lean { namespace lp {
template void indexed_vector<double>::clear(); template void indexed_vector<double>::clear();
template void indexed_vector<double>::clear_all(); template void indexed_vector<double>::clear_all();
template void indexed_vector<double>::erase_from_index(unsigned int); template void indexed_vector<double>::erase_from_index(unsigned int);
@ -20,17 +20,17 @@ template void indexed_vector<unsigned>::set_value(const unsigned&, unsigned int)
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template bool indexed_vector<double>::is_OK() const; template bool indexed_vector<double>::is_OK() const;
template bool indexed_vector<mpq>::is_OK() const; template bool indexed_vector<mpq>::is_OK() const;
template bool indexed_vector<lean::numeric_pair<mpq> >::is_OK() const; template bool indexed_vector<lp::numeric_pair<mpq> >::is_OK() const;
template void lean::indexed_vector< lean::mpq>::print(std::basic_ostream<char,struct std::char_traits<char> > &); template void lp::indexed_vector< lp::mpq>::print(std::basic_ostream<char,struct std::char_traits<char> > &);
template void lean::indexed_vector<double>::print(std::basic_ostream<char,struct std::char_traits<char> > &); template void lp::indexed_vector<double>::print(std::basic_ostream<char,struct std::char_traits<char> > &);
template void lean::indexed_vector<lean::numeric_pair<lean::mpq> >::print(std::ostream&); template void lp::indexed_vector<lp::numeric_pair<lp::mpq> >::print(std::ostream&);
#endif #endif
} }
template void lean::print_vector<double>(vector<double> const&, std::ostream&); template void lp::print_vector<double>(vector<double> const&, std::ostream&);
template void lean::print_vector<unsigned int>(vector<unsigned int> const&, std::ostream&); template void lp::print_vector<unsigned int>(vector<unsigned int> const&, std::ostream&);
template void lean::print_vector<std::string>(vector<std::string> const&, std::ostream&); template void lp::print_vector<std::string>(vector<std::string> const&, std::ostream&);
template void lean::print_vector<lean::numeric_pair<lean::mpq> >(vector<lean::numeric_pair<lean::mpq>> const&, std::ostream&); template void lp::print_vector<lp::numeric_pair<lp::mpq> >(vector<lp::numeric_pair<lp::mpq>> const&, std::ostream&);
template void lean::indexed_vector<double>::resize(unsigned int); template void lp::indexed_vector<double>::resize(unsigned int);
template void lean::print_vector< lean::mpq>(vector< lean::mpq> const &, std::basic_ostream<char, std::char_traits<char> > &); template void lp::print_vector< lp::mpq>(vector< lp::mpq> const &, std::basic_ostream<char, std::char_traits<char> > &);
template void lean::print_vector<std::pair<lean::mpq, unsigned int> >(vector<std::pair<lean::mpq, unsigned int>> const&, std::ostream&); template void lp::print_vector<std::pair<lp::mpq, unsigned int> >(vector<std::pair<lp::mpq, unsigned int>> const&, std::ostream&);
template void lean::indexed_vector<lean::numeric_pair<lean::mpq> >::erase_from_index(unsigned int); template void lp::indexed_vector<lp::numeric_pair<lp::mpq> >::erase_from_index(unsigned int);

View file

@ -6,7 +6,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/indexed_vector.h" #include "util/lp/indexed_vector.h"
#include <ostream> #include <ostream>
namespace lean { namespace lp {
// serves at a set of non-negative integers smaller than the set size // serves at a set of non-negative integers smaller than the set size
class int_set { class int_set {
vector<int> m_data; vector<int> m_data;
@ -20,7 +20,7 @@ public:
return m_data[j] >= 0; return m_data[j] >= 0;
} }
void insert(unsigned j) { void insert(unsigned j) {
lean_assert(j < m_data.size()); lp_assert(j < m_data.size());
if (contains(j)) return; if (contains(j)) return;
m_data[j] = m_index.size(); m_data[j] = m_index.size();
m_index.push_back(j); m_index.push_back(j);

View file

@ -5,10 +5,10 @@
#include "util/lp/int_solver.h" #include "util/lp/int_solver.h"
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
namespace lean { namespace lp {
void int_solver::fix_non_base_columns() { void int_solver::fix_non_base_columns() {
lean_assert(is_feasible() && inf_int_set_is_correct()); lp_assert(is_feasible() && inf_int_set_is_correct());
auto & lcs = m_lar_solver->m_mpq_lar_core_solver; auto & lcs = m_lar_solver->m_mpq_lar_core_solver;
bool change = false; bool change = false;
for (unsigned j : lcs.m_r_nbasis) { for (unsigned j : lcs.m_r_nbasis) {
@ -22,7 +22,7 @@ void int_solver::fix_non_base_columns() {
if (m_lar_solver->find_feasible_solution() == INFEASIBLE) if (m_lar_solver->find_feasible_solution() == INFEASIBLE)
failed(); failed();
init_inf_int_set(); init_inf_int_set();
lean_assert(is_feasible() && inf_int_set_is_correct()); lp_assert(is_feasible() && inf_int_set_is_correct());
} }
void int_solver::failed() { void int_solver::failed() {
@ -30,11 +30,11 @@ void int_solver::failed() {
for (unsigned j : m_old_values_set.m_index) { for (unsigned j : m_old_values_set.m_index) {
lcs.m_r_x[j] = m_old_values_data[j]; lcs.m_r_x[j] = m_old_values_data[j];
lean_assert(lcs.m_r_solver.column_is_feasible(j)); lp_assert(lcs.m_r_solver.column_is_feasible(j));
lcs.m_r_solver.remove_column_from_inf_set(j); lcs.m_r_solver.remove_column_from_inf_set(j);
} }
lean_assert(lcs.m_r_solver.calc_current_x_is_feasible_include_non_basis()); lp_assert(lcs.m_r_solver.calc_current_x_is_feasible_include_non_basis());
lean_assert(lcs.m_r_solver.current_x_is_feasible()); lp_assert(lcs.m_r_solver.current_x_is_feasible());
m_old_values_set.clear(); m_old_values_set.clear();
} }
@ -78,7 +78,7 @@ int int_solver::find_inf_int_boxed_base_column_with_smallest_range() {
lar_core_solver & lcs = m_lar_solver->m_mpq_lar_core_solver; lar_core_solver & lcs = m_lar_solver->m_mpq_lar_core_solver;
for (int j : m_inf_int_set.m_index) { for (int j : m_inf_int_set.m_index) {
lean_assert(is_base(j) && column_is_int_inf(j)); lp_assert(is_base(j) && column_is_int_inf(j));
if (!is_boxed(j)) if (!is_boxed(j))
continue; continue;
new_range = lcs.m_r_upper_bounds()[j].x - lcs.m_r_low_bounds()[j].x; new_range = lcs.m_r_upper_bounds()[j].x - lcs.m_r_low_bounds()[j].x;
@ -109,7 +109,7 @@ int int_solver::find_inf_int_boxed_base_column_with_smallest_range() {
} }
bool int_solver::mk_gomory_cut(unsigned row_index, explanation & ex) { bool int_solver::mk_gomory_cut(unsigned row_index, explanation & ex) {
lean_assert(false); lp_assert(false);
return true; return true;
/* /*
const auto & row = m_lar_solver->A_r().m_rows[row_index]; const auto & row = m_lar_solver->A_r().m_rows[row_index];
@ -297,10 +297,10 @@ void int_solver::init_check_data() {
} }
lia_move int_solver::check(lar_term& t, mpq& k, explanation& ex) { lia_move int_solver::check(lar_term& t, mpq& k, explanation& ex) {
lean_assert(m_lar_solver->m_mpq_lar_core_solver.r_basis_is_OK()); lp_assert(m_lar_solver->m_mpq_lar_core_solver.r_basis_is_OK());
lean_assert(is_feasible()); lp_assert(is_feasible());
init_check_data(); init_check_data();
lean_assert(inf_int_set_is_correct()); lp_assert(inf_int_set_is_correct());
// currently it is a reimplementation of // currently it is a reimplementation of
// final_check_status theory_arith<Ext>::check_int_feasibility() // final_check_status theory_arith<Ext>::check_int_feasibility()
// from theory_arith_int.h // from theory_arith_int.h
@ -344,7 +344,7 @@ lia_move int_solver::check(lar_term& t, mpq& k, explanation& ex) {
if (j != -1) { if (j != -1) {
TRACE("arith_int", tout << "j" << j << " does not have an integer assignment: " << get_value(j) << "\n";); TRACE("arith_int", tout << "j" << j << " does not have an integer assignment: " << get_value(j) << "\n";);
lean_assert(t.is_empty()); lp_assert(t.is_empty());
t.add_to_map(j, mpq(1)); t.add_to_map(j, mpq(1));
k = floor(get_value(j)); k = floor(get_value(j));
TRACE("arith_int", tout << "branching v" << j << " = " << get_value(j) << "\n"; TRACE("arith_int", tout << "branching v" << j << " = " << get_value(j) << "\n";
@ -354,7 +354,7 @@ lia_move int_solver::check(lar_term& t, mpq& k, explanation& ex) {
return lia_move::branch; return lia_move::branch;
} }
} }
lean_assert(m_lar_solver->m_mpq_lar_core_solver.r_basis_is_OK()); lp_assert(m_lar_solver->m_mpq_lar_core_solver.r_basis_is_OK());
// return true; // return true;
return lia_move::give_up; return lia_move::give_up;
} }
@ -387,7 +387,7 @@ void int_solver::move_non_base_vars_to_bounds() {
void int_solver::set_value_for_nbasic_column(unsigned j, const impq & new_val) { void int_solver::set_value_for_nbasic_column(unsigned j, const impq & new_val) {
lean_assert(!is_base(j)); lp_assert(!is_base(j));
auto & x = m_lar_solver->m_mpq_lar_core_solver.m_r_x[j]; auto & x = m_lar_solver->m_mpq_lar_core_solver.m_r_x[j];
if (!m_old_values_set.contains(j)) { if (!m_old_values_set.contains(j)) {
m_old_values_set.insert(j); m_old_values_set.insert(j);
@ -450,7 +450,7 @@ void int_solver::patch_int_infeasible_columns() {
TRACE("patch_int", TRACE("patch_int",
tout << "patching with 0\n";); tout << "patching with 0\n";);
} }
lean_assert(is_feasible() && inf_int_set_is_correct()); lp_assert(is_feasible() && inf_int_set_is_correct());
} }
} }
@ -621,7 +621,7 @@ linear_combination_iterator<mpq> * int_solver::get_column_iterator(unsigned j) {
int_solver::int_solver(lar_solver* lar_slv) : int_solver::int_solver(lar_solver* lar_slv) :
m_lar_solver(lar_slv), m_lar_solver(lar_slv),
m_branch_cut_counter(0) { m_branch_cut_counter(0) {
lean_assert(m_old_values_set.size() == 0); lp_assert(m_old_values_set.size() == 0);
m_old_values_set.resize(lar_slv->A_r().column_count()); m_old_values_set.resize(lar_slv->A_r().column_count());
m_old_values_data.resize(lar_slv->A_r().column_count(), zero_of_type<impq>()); m_old_values_data.resize(lar_slv->A_r().column_count(), zero_of_type<impq>());
} }
@ -740,8 +740,8 @@ bool int_solver::get_freedom_interval_for_column(unsigned x_j, bool & inf_l, imp
tout << "]\n"; tout << "]\n";
tout << "val = " << get_value(x_j) << "\n"; tout << "val = " << get_value(x_j) << "\n";
); );
lean_assert(inf_l || l <= get_value(x_j)); lp_assert(inf_l || l <= get_value(x_j));
lean_assert(inf_u || u >= get_value(x_j)); lp_assert(inf_u || u >= get_value(x_j));
return true; return true;
} }
@ -758,7 +758,7 @@ bool int_solver::value_is_int(unsigned j) const {
bool int_solver::is_feasible() const { bool int_solver::is_feasible() const {
auto & lcs = m_lar_solver->m_mpq_lar_core_solver; auto & lcs = m_lar_solver->m_mpq_lar_core_solver;
lean_assert( lp_assert(
lcs.m_r_solver.calc_current_x_is_feasible_include_non_basis() == lcs.m_r_solver.calc_current_x_is_feasible_include_non_basis() ==
lcs.m_r_solver.current_x_is_feasible()); lcs.m_r_solver.current_x_is_feasible());
return lcs.m_r_solver.current_x_is_feasible(); return lcs.m_r_solver.current_x_is_feasible();

View file

@ -9,7 +9,7 @@
#include "util/lp/int_set.h" #include "util/lp/int_set.h"
#include "util/lp/lar_term.h" #include "util/lp/lar_term.h"
namespace lean { namespace lp {
class lar_solver; class lar_solver;
template <typename T, typename X> template <typename T, typename X>
struct lp_constraint; struct lp_constraint;

View file

@ -6,7 +6,7 @@
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
#include "util/lp/static_matrix.h" #include "util/lp/static_matrix.h"
#include "util/lp/lar_term.h" #include "util/lp/lar_term.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
struct iterator_on_column:linear_combination_iterator<T> { struct iterator_on_column:linear_combination_iterator<T> {
const vector<column_cell>& m_column; // the offset in term coeffs const vector<column_cell>& m_column; // the offset in term coeffs

View file

@ -4,7 +4,7 @@
*/ */
#pragma once #pragma once
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
namespace lean { namespace lp {
template <typename T> template <typename T>
struct iterator_on_indexed_vector:linear_combination_iterator<T> { struct iterator_on_indexed_vector:linear_combination_iterator<T> {
const indexed_vector<T> & m_v; const indexed_vector<T> & m_v;

View file

@ -4,7 +4,7 @@
*/ */
#pragma once #pragma once
#include "util/lp/iterator_on_indexed_vector.h" #include "util/lp/iterator_on_indexed_vector.h"
namespace lean { namespace lp {
template <typename T> template <typename T>
struct iterator_on_pivot_row:linear_combination_iterator<T> { struct iterator_on_pivot_row:linear_combination_iterator<T> {
bool m_basis_returned; bool m_basis_returned;

View file

@ -4,7 +4,7 @@
*/ */
#pragma once #pragma once
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
namespace lean { namespace lp {
template <typename T> template <typename T>
struct iterator_on_row:linear_combination_iterator<T> { struct iterator_on_row:linear_combination_iterator<T> {
const vector<row_cell<T>> & m_row; const vector<row_cell<T>> & m_row;

View file

@ -6,7 +6,7 @@
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
#include "util/lp/lar_term.h" #include "util/lp/lar_term.h"
namespace lean { namespace lp {
struct iterator_on_term_with_basis_var:linear_combination_iterator<mpq> { struct iterator_on_term_with_basis_var:linear_combination_iterator<mpq> {
const lar_term & m_term; const lar_term & m_term;
std::unordered_map<unsigned, mpq>::const_iterator m_i; // the offset in term coeffs std::unordered_map<unsigned, mpq>::const_iterator m_i; // the offset in term coeffs

View file

@ -12,7 +12,7 @@
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/ul_pair.h" #include "util/lp/ul_pair.h"
#include "util/lp/lar_term.h" #include "util/lp/lar_term.h"
namespace lean { namespace lp {
inline lconstraint_kind flip_kind(lconstraint_kind t) { inline lconstraint_kind flip_kind(lconstraint_kind t) {
return static_cast<lconstraint_kind>( - static_cast<int>(t)); return static_cast<lconstraint_kind>( - static_cast<int>(t));
} }
@ -25,7 +25,7 @@ inline std::string lconstraint_kind_string(lconstraint_kind t) {
case GT: return std::string(">"); case GT: return std::string(">");
case EQ: return std::string("="); case EQ: return std::string("=");
} }
lean_unreachable(); lp_unreachable();
return std::string(); // it is unreachable return std::string(); // it is unreachable
} }
@ -74,7 +74,7 @@ public:
: lar_base_constraint(kind, right_side), m_coeffs(left_side) {} : lar_base_constraint(kind, right_side), m_coeffs(left_side) {}
lar_constraint(const lar_base_constraint & c) { lar_constraint(const lar_base_constraint & c) {
lean_assert(false); // should not be called : todo! lp_assert(false); // should not be called : todo!
} }
unsigned size() const { unsigned size() const {

View file

@ -18,7 +18,7 @@
#include "util/lp/iterator_on_column.h" #include "util/lp/iterator_on_column.h"
#include "util/lp/iterator_on_indexed_vector.h" #include "util/lp/iterator_on_indexed_vector.h"
#include "util/lp/stacked_value.h" #include "util/lp/stacked_value.h"
namespace lean { namespace lp {
class lar_core_solver { class lar_core_solver {
// m_sign_of_entering is set to 1 if the entering variable needs // m_sign_of_entering is set to 1 if the entering variable needs
@ -168,9 +168,9 @@ public:
} }
void push() { void push() {
lean_assert(m_r_solver.basis_heading_is_correct()); lp_assert(m_r_solver.basis_heading_is_correct());
lean_assert(!need_to_presolve_with_double_solver() || m_d_solver.basis_heading_is_correct()); lp_assert(!need_to_presolve_with_double_solver() || m_d_solver.basis_heading_is_correct());
lean_assert(m_column_types.size() == m_r_A.column_count()); lp_assert(m_column_types.size() == m_r_A.column_count());
m_stacked_simplex_strategy = settings().simplex_strategy(); m_stacked_simplex_strategy = settings().simplex_strategy();
m_stacked_simplex_strategy.push(); m_stacked_simplex_strategy.push();
m_column_types.push(); m_column_types.push();
@ -192,7 +192,7 @@ public:
template <typename K> template <typename K>
void push_vector(stacked_vector<K> & pushed_vector, const vector<K> & vector) { void push_vector(stacked_vector<K> & pushed_vector, const vector<K> & vector) {
lean_assert(pushed_vector.size() <= vector.size()); lp_assert(pushed_vector.size() <= vector.size());
for (unsigned i = 0; i < vector.size();i++) { for (unsigned i = 0; i < vector.size();i++) {
if (i == pushed_vector.size()) { if (i == pushed_vector.size()) {
pushed_vector.push_back(vector[i]); pushed_vector.push_back(vector[i]);
@ -242,8 +242,8 @@ public:
pop_basis(k); pop_basis(k);
m_stacked_simplex_strategy.pop(k); m_stacked_simplex_strategy.pop(k);
settings().simplex_strategy() = m_stacked_simplex_strategy; settings().simplex_strategy() = m_stacked_simplex_strategy;
lean_assert(m_r_solver.basis_heading_is_correct()); lp_assert(m_r_solver.basis_heading_is_correct());
lean_assert(!need_to_presolve_with_double_solver() || m_d_solver.basis_heading_is_correct()); lp_assert(!need_to_presolve_with_double_solver() || m_d_solver.basis_heading_is_correct());
} }
bool need_to_presolve_with_double_solver() const { bool need_to_presolve_with_double_solver() const {
@ -304,11 +304,11 @@ public:
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
m_r_solver.remove_column_from_inf_set(j); m_r_solver.remove_column_from_inf_set(j);
return true; return true;
@ -317,7 +317,7 @@ public:
void prepare_solver_x_with_signature_tableau(const lar_solution_signature & signature) { void prepare_solver_x_with_signature_tableau(const lar_solution_signature & signature) {
lean_assert(m_r_solver.inf_set_is_correct()); lp_assert(m_r_solver.inf_set_is_correct());
for (auto &t : signature) { for (auto &t : signature) {
unsigned j = t.first; unsigned j = t.first;
if (m_r_heading[j] >= 0) if (m_r_heading[j] >= 0)
@ -332,9 +332,9 @@ public:
m_r_solver.m_x[jb] -= delta * m_r_solver.m_A.get_val(cc); m_r_solver.m_x[jb] -= delta * m_r_solver.m_A.get_val(cc);
m_r_solver.update_column_in_inf_set(jb); m_r_solver.update_column_in_inf_set(jb);
} }
lean_assert(m_r_solver.A_mult_x_is_off() == false); lp_assert(m_r_solver.A_mult_x_is_off() == false);
} }
lean_assert(m_r_solver.inf_set_is_correct()); lp_assert(m_r_solver.inf_set_is_correct());
} }
@ -342,7 +342,7 @@ public:
void prepare_solver_x_with_signature(const lar_solution_signature & signature, lp_primal_core_solver<L,K> & s) { void prepare_solver_x_with_signature(const lar_solution_signature & signature, lp_primal_core_solver<L,K> & s) {
for (auto &t : signature) { for (auto &t : signature) {
unsigned j = t.first; unsigned j = t.first;
lean_assert(m_r_heading[j] < 0); lp_assert(m_r_heading[j] < 0);
auto pos_type = t.second; auto pos_type = t.second;
switch (pos_type) { switch (pos_type) {
case at_low_bound: case at_low_bound:
@ -359,7 +359,7 @@ public:
case not_at_bound: case not_at_bound:
switch (m_column_types[j]) { switch (m_column_types[j]) {
case column_type::free_column: case column_type::free_column:
lean_assert(false); // unreachable lp_assert(false); // unreachable
case column_type::upper_bound: case column_type::upper_bound:
s.m_x[j] = s.m_upper_bounds[j]; s.m_x[j] = s.m_upper_bounds[j];
break; break;
@ -377,15 +377,15 @@ public:
s.m_x[j] = s.m_low_bounds[j]; s.m_x[j] = s.m_low_bounds[j];
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
lean_assert(is_zero_vector(s.m_b)); lp_assert(is_zero_vector(s.m_b));
s.solve_Ax_eq_b(); s.solve_Ax_eq_b();
} }
@ -418,7 +418,7 @@ public:
// the queues of delayed indices // the queues of delayed indices
std::queue<unsigned> entr_q, leav_q; std::queue<unsigned> entr_q, leav_q;
auto * l = cs.m_factorization; auto * l = cs.m_factorization;
lean_assert(l->get_status() == LU_status::OK); lp_assert(l->get_status() == LU_status::OK);
for (unsigned i = 0; i < trace_of_basis_change.size(); i+= 2) { for (unsigned i = 0; i < trace_of_basis_change.size(); i+= 2) {
unsigned entering = trace_of_basis_change[i]; unsigned entering = trace_of_basis_change[i];
unsigned leaving = trace_of_basis_change[i+1]; unsigned leaving = trace_of_basis_change[i+1];
@ -446,8 +446,8 @@ public:
continue; continue;
} }
} }
lean_assert(cs.m_basis_heading[entering] < 0); lp_assert(cs.m_basis_heading[entering] < 0);
lean_assert(cs.m_basis_heading[leaving] >= 0); lp_assert(cs.m_basis_heading[leaving] >= 0);
if (l->get_status() == LU_status::OK) { if (l->get_status() == LU_status::OK) {
l->prepare_entering(entering, w); // to init vector w l->prepare_entering(entering, w); // to init vector w
l->replace_column(zero_of_type<L>(), w, cs.m_basis_heading[leaving]); l->replace_column(zero_of_type<L>(), w, cs.m_basis_heading[leaving]);
@ -471,7 +471,7 @@ public:
void solve_on_signature_tableau(const lar_solution_signature & signature, const vector<unsigned> & changes_of_basis) { void solve_on_signature_tableau(const lar_solution_signature & signature, const vector<unsigned> & changes_of_basis) {
r_basis_is_OK(); r_basis_is_OK();
lean_assert(settings().use_tableau()); lp_assert(settings().use_tableau());
bool r = catch_up_in_lu_tableau(changes_of_basis, m_d_solver.m_basis_heading); bool r = catch_up_in_lu_tableau(changes_of_basis, m_d_solver.m_basis_heading);
if (!r) { // it is the case where m_d_solver gives a degenerated basis if (!r) { // it is the case where m_d_solver gives a degenerated basis
@ -490,10 +490,10 @@ public:
return; return;
m_r_solver.stop_tracing_basis_changes(); m_r_solver.stop_tracing_basis_changes();
// and now catch up in the double solver // and now catch up in the double solver
lean_assert(m_r_solver.total_iterations() >= m_r_solver.m_trace_of_basis_change_vector.size() /2); lp_assert(m_r_solver.total_iterations() >= m_r_solver.m_trace_of_basis_change_vector.size() /2);
catch_up_in_lu(m_r_solver.m_trace_of_basis_change_vector, m_r_solver.m_basis_heading, m_d_solver); catch_up_in_lu(m_r_solver.m_trace_of_basis_change_vector, m_r_solver.m_basis_heading, m_d_solver);
} }
lean_assert(r_basis_is_OK()); lp_assert(r_basis_is_OK());
} }
bool adjust_x_of_column(unsigned j) { bool adjust_x_of_column(unsigned j) {
@ -507,16 +507,16 @@ public:
} }
m_r_solver.snap_column_to_bound_tableau(j); m_r_solver.snap_column_to_bound_tableau(j);
lean_assert(m_r_solver.column_is_feasible(j)); lp_assert(m_r_solver.column_is_feasible(j));
m_r_solver.m_inf_set.erase(j); m_r_solver.m_inf_set.erase(j);
*/ */
lean_assert(false); lp_assert(false);
return true; return true;
} }
bool catch_up_in_lu_tableau(const vector<unsigned> & trace_of_basis_change, const vector<int> & basis_heading) { bool catch_up_in_lu_tableau(const vector<unsigned> & trace_of_basis_change, const vector<int> & basis_heading) {
lean_assert(r_basis_is_OK()); lp_assert(r_basis_is_OK());
// the queues of delayed indices // the queues of delayed indices
std::queue<unsigned> entr_q, leav_q; std::queue<unsigned> entr_q, leav_q;
for (unsigned i = 0; i < trace_of_basis_change.size(); i+= 2) { for (unsigned i = 0; i < trace_of_basis_change.size(); i+= 2) {
@ -546,8 +546,8 @@ public:
continue; continue;
} }
} }
lean_assert(m_r_solver.m_basis_heading[entering] < 0); lp_assert(m_r_solver.m_basis_heading[entering] < 0);
lean_assert(m_r_solver.m_basis_heading[leaving] >= 0); lp_assert(m_r_solver.m_basis_heading[leaving] >= 0);
m_r_solver.change_basis_unconditionally(entering, leaving); m_r_solver.change_basis_unconditionally(entering, leaving);
if(!m_r_solver.pivot_column_tableau(entering, m_r_solver.m_basis_heading[entering])) { if(!m_r_solver.pivot_column_tableau(entering, m_r_solver.m_basis_heading[entering])) {
// unroll the last step // unroll the last step
@ -557,12 +557,12 @@ public:
#endif #endif
m_r_solver.pivot_column_tableau(leaving, m_r_solver.m_basis_heading[leaving]); m_r_solver.pivot_column_tableau(leaving, m_r_solver.m_basis_heading[leaving]);
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
lean_assert(t); lp_assert(t);
#endif #endif
return false; return false;
} }
} }
lean_assert(r_basis_is_OK()); lp_assert(r_basis_is_OK());
return true; return true;
} }
@ -572,21 +572,21 @@ public:
if (!m_r_solver.m_settings.use_tableau()) if (!m_r_solver.m_settings.use_tableau())
return true; return true;
for (unsigned j : m_r_solver.m_basis) { for (unsigned j : m_r_solver.m_basis) {
lean_assert(m_r_solver.m_A.m_columns[j].size() == 1); lp_assert(m_r_solver.m_A.m_columns[j].size() == 1);
lean_assert(m_r_solver.m_A.get_val(m_r_solver.m_A.m_columns[j][0]) == one_of_type<mpq>()); lp_assert(m_r_solver.m_A.get_val(m_r_solver.m_A.m_columns[j][0]) == one_of_type<mpq>());
} }
for (unsigned j =0; j < m_r_solver.m_basis_heading.size(); j++) { for (unsigned j =0; j < m_r_solver.m_basis_heading.size(); j++) {
if (m_r_solver.m_basis_heading[j] >= 0) continue; if (m_r_solver.m_basis_heading[j] >= 0) continue;
if (m_r_solver.m_column_types[j] == column_type::fixed) continue; if (m_r_solver.m_column_types[j] == column_type::fixed) continue;
lean_assert(static_cast<unsigned>(- m_r_solver.m_basis_heading[j] - 1) < m_r_solver.m_column_types.size()); lp_assert(static_cast<unsigned>(- m_r_solver.m_basis_heading[j] - 1) < m_r_solver.m_column_types.size());
lean_assert( m_r_solver.m_basis_heading[j] <= -1); lp_assert( m_r_solver.m_basis_heading[j] <= -1);
} }
#endif #endif
return true; return true;
} }
void solve_on_signature(const lar_solution_signature & signature, const vector<unsigned> & changes_of_basis) { void solve_on_signature(const lar_solution_signature & signature, const vector<unsigned> & changes_of_basis) {
lean_assert(!settings().use_tableau()); lp_assert(!settings().use_tableau());
if (m_r_solver.m_factorization == nullptr) { if (m_r_solver.m_factorization == nullptr) {
for (unsigned j = 0; j < changes_of_basis.size(); j+=2) { for (unsigned j = 0; j < changes_of_basis.size(); j+=2) {
unsigned entering = changes_of_basis[j]; unsigned entering = changes_of_basis[j];
@ -615,7 +615,7 @@ public:
return; return;
m_r_solver.stop_tracing_basis_changes(); m_r_solver.stop_tracing_basis_changes();
// and now catch up in the double solver // and now catch up in the double solver
lean_assert(m_r_solver.total_iterations() >= m_r_solver.m_trace_of_basis_change_vector.size() /2); lp_assert(m_r_solver.total_iterations() >= m_r_solver.m_trace_of_basis_change_vector.size() /2);
catch_up_in_lu(m_r_solver.m_trace_of_basis_change_vector, m_r_solver.m_basis_heading, m_d_solver); catch_up_in_lu(m_r_solver.m_trace_of_basis_change_vector, m_r_solver.m_basis_heading, m_d_solver);
} }
} }
@ -641,7 +641,7 @@ public:
template <typename L, typename K> template <typename L, typename K>
void extract_signature_from_lp_core_solver(const lp_primal_core_solver<L, K> & solver, lar_solution_signature & signature) { void extract_signature_from_lp_core_solver(const lp_primal_core_solver<L, K> & solver, lar_solution_signature & signature) {
signature.clear(); signature.clear();
lean_assert(signature.size() == 0); lp_assert(signature.size() == 0);
for (unsigned j = 0; j < solver.m_basis_heading.size(); j++) { for (unsigned j = 0; j < solver.m_basis_heading.size(); j++) {
if (solver.m_basis_heading[j] < 0) { if (solver.m_basis_heading[j] < 0) {
signature[j] = solver.get_non_basic_column_value_position(j); signature[j] = solver.get_non_basic_column_value_position(j);
@ -664,7 +664,7 @@ public:
if (upper_bound_is_set(j)) { if (upper_bound_is_set(j)) {
const auto & ub = m_r_solver.m_upper_bounds[j]; const auto & ub = m_r_solver.m_upper_bounds[j];
m_d_upper_bounds[j] = ub.x.get_double() + delta * ub.y.get_double(); m_d_upper_bounds[j] = ub.x.get_double() + delta * ub.y.get_double();
lean_assert(!low_bound_is_set(j) || (m_d_upper_bounds[j] >= m_d_low_bounds[j])); lp_assert(!low_bound_is_set(j) || (m_d_upper_bounds[j] >= m_d_low_bounds[j]));
} }
} }
} }
@ -729,7 +729,7 @@ public:
case column_type::fixed: case column_type::fixed:
return true; return true;
default: default:
lean_assert(false); lp_assert(false);
} }
return false; return false;
} }
@ -744,20 +744,20 @@ public:
case column_type::fixed: case column_type::fixed:
return true; return true;
default: default:
lean_assert(false); lp_assert(false);
} }
return false; return false;
} }
void update_delta(mpq& delta, numeric_pair<mpq> const& l, numeric_pair<mpq> const& u) const { void update_delta(mpq& delta, numeric_pair<mpq> const& l, numeric_pair<mpq> const& u) const {
lean_assert(l <= u); lp_assert(l <= u);
if (l.x < u.x && l.y > u.y) { if (l.x < u.x && l.y > u.y) {
mpq delta1 = (u.x - l.x) / (l.y - u.y); mpq delta1 = (u.x - l.x) / (l.y - u.y);
if (delta1 < delta) { if (delta1 < delta) {
delta = delta1; delta = delta1;
} }
} }
lean_assert(l.x + delta * l.y <= u.x + delta * u.y); lp_assert(l.x + delta * l.y <= u.x + delta * u.y);
} }
@ -804,14 +804,14 @@ public:
} }
const impq & low_bound(unsigned j) const { const impq & low_bound(unsigned j) const {
lean_assert(m_column_types()[j] == column_type::fixed || lp_assert(m_column_types()[j] == column_type::fixed ||
m_column_types()[j] == column_type::boxed || m_column_types()[j] == column_type::boxed ||
m_column_types()[j] == column_type::low_bound); m_column_types()[j] == column_type::low_bound);
return m_r_low_bounds[j]; return m_r_low_bounds[j];
} }
const impq & upper_bound(unsigned j) const { const impq & upper_bound(unsigned j) const {
lean_assert(m_column_types()[j] == column_type::fixed || lp_assert(m_column_types()[j] == column_type::fixed ||
m_column_types()[j] == column_type::boxed || m_column_types()[j] == column_type::boxed ||
m_column_types()[j] == column_type::upper_bound); m_column_types()[j] == column_type::upper_bound);
return m_r_upper_bounds[j]; return m_r_upper_bounds[j];

View file

@ -10,7 +10,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lar_core_solver.h" #include "util/lp/lar_core_solver.h"
#include "util/lp/lar_solution_signature.h" #include "util/lp/lar_solution_signature.h"
namespace lean { namespace lp {
lar_core_solver::lar_core_solver( lar_core_solver::lar_core_solver(
lp_settings & settings, lp_settings & settings,
const column_namer & column_names const column_namer & column_names
@ -42,9 +42,9 @@ lar_core_solver::lar_core_solver(
column_names){} column_names){}
void lar_core_solver::init_costs(bool first_time) { void lar_core_solver::init_costs(bool first_time) {
lean_assert(false); // should not be called lp_assert(false); // should not be called
// lean_assert(this->m_x.size() >= this->m_n()); // lp_assert(this->m_x.size() >= this->m_n());
// lean_assert(this->m_column_types.size() >= this->m_n()); // lp_assert(this->m_column_types.size() >= this->m_n());
// if (first_time) // if (first_time)
// this->m_costs.resize(this->m_n()); // this->m_costs.resize(this->m_n());
// X inf = this->m_infeasibility; // X inf = this->m_infeasibility;
@ -54,7 +54,7 @@ void lar_core_solver::init_costs(bool first_time) {
// if (!(first_time || inf >= this->m_infeasibility)) { // if (!(first_time || inf >= this->m_infeasibility)) {
// LP_OUT(this->m_settings, "iter = " << this->total_iterations() << std::endl); // LP_OUT(this->m_settings, "iter = " << this->total_iterations() << std::endl);
// LP_OUT(this->m_settings, "inf was " << T_to_string(inf) << " and now " << T_to_string(this->m_infeasibility) << std::endl); // LP_OUT(this->m_settings, "inf was " << T_to_string(inf) << " and now " << T_to_string(this->m_infeasibility) << std::endl);
// lean_assert(false); // lp_assert(false);
// } // }
// if (inf == this->m_infeasibility) // if (inf == this->m_infeasibility)
// this->m_iters_with_no_cost_growing++; // this->m_iters_with_no_cost_growing++;
@ -105,7 +105,7 @@ void lar_core_solver::init_cost_for_column(unsigned j) {
this->m_costs[j] = numeric_traits<T>::zero(); this->m_costs[j] = numeric_traits<T>::zero();
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
}*/ }*/
} }
@ -138,7 +138,7 @@ int lar_core_solver::column_is_out_of_bounds(unsigned j) {
return 0; return 0;
break; break;
}*/ }*/
lean_assert(false); lp_assert(false);
return true; return true;
} }
@ -192,7 +192,7 @@ void lar_core_solver::calculate_pivot_row(unsigned i) {
} }
void lar_core_solver::fill_not_improvable_zero_sum_from_inf_row() { void lar_core_solver::fill_not_improvable_zero_sum_from_inf_row() {
lean_assert(m_r_solver.A_mult_x_is_off() == false); lp_assert(m_r_solver.A_mult_x_is_off() == false);
unsigned bj = m_r_basis[m_r_solver.m_inf_row_index_for_tableau]; unsigned bj = m_r_basis[m_r_solver.m_inf_row_index_for_tableau];
m_infeasible_sum_sign = m_r_solver.inf_sign_of_column(bj); m_infeasible_sum_sign = m_r_solver.inf_sign_of_column(bj);
m_infeasible_linear_combination.clear(); m_infeasible_linear_combination.clear();
@ -227,15 +227,15 @@ void lar_core_solver::fill_not_improvable_zero_sum() {
void lar_core_solver::solve() { void lar_core_solver::solve() {
lean_assert(m_r_solver.non_basic_columns_are_set_correctly()); lp_assert(m_r_solver.non_basic_columns_are_set_correctly());
lean_assert(m_r_solver.inf_set_is_correct()); lp_assert(m_r_solver.inf_set_is_correct());
if (m_r_solver.current_x_is_feasible() && m_r_solver.m_look_for_feasible_solution_only) { if (m_r_solver.current_x_is_feasible() && m_r_solver.m_look_for_feasible_solution_only) {
m_r_solver.set_status(OPTIMAL); m_r_solver.set_status(OPTIMAL);
return; return;
} }
++settings().st().m_need_to_solve_inf; ++settings().st().m_need_to_solve_inf;
lean_assert(!m_r_solver.A_mult_x_is_off()); lp_assert(!m_r_solver.A_mult_x_is_off());
lean_assert((!settings().use_tableau()) || r_basis_is_OK()); lp_assert((!settings().use_tableau()) || r_basis_is_OK());
if (need_to_presolve_with_double_solver()) { if (need_to_presolve_with_double_solver()) {
prefix_d(); prefix_d();
lar_solution_signature solution_signature; lar_solution_signature solution_signature;
@ -248,11 +248,11 @@ void lar_core_solver::solve() {
solve_on_signature_tableau(solution_signature, changes_of_basis); solve_on_signature_tableau(solution_signature, changes_of_basis);
else else
solve_on_signature(solution_signature, changes_of_basis); solve_on_signature(solution_signature, changes_of_basis);
lean_assert(!settings().use_tableau() || r_basis_is_OK()); lp_assert(!settings().use_tableau() || r_basis_is_OK());
} else { } else {
if (!settings().use_tableau()) { if (!settings().use_tableau()) {
bool snapped = m_r_solver.snap_non_basic_x_to_bound(); bool snapped = m_r_solver.snap_non_basic_x_to_bound();
lean_assert(m_r_solver.non_basic_columns_are_set_correctly()); lp_assert(m_r_solver.non_basic_columns_are_set_correctly());
if (snapped) if (snapped)
m_r_solver.solve_Ax_eq_b(); m_r_solver.solve_Ax_eq_b();
} }
@ -260,16 +260,16 @@ void lar_core_solver::solve() {
m_r_solver.find_feasible_solution(); m_r_solver.find_feasible_solution();
else else
m_r_solver.solve(); m_r_solver.solve();
lean_assert(!settings().use_tableau() || r_basis_is_OK()); lp_assert(!settings().use_tableau() || r_basis_is_OK());
} }
if (m_r_solver.get_status() == INFEASIBLE) { if (m_r_solver.get_status() == INFEASIBLE) {
fill_not_improvable_zero_sum(); fill_not_improvable_zero_sum();
} else if (m_r_solver.get_status() != UNBOUNDED) { } else if (m_r_solver.get_status() != UNBOUNDED) {
m_r_solver.set_status(OPTIMAL); m_r_solver.set_status(OPTIMAL);
} }
lean_assert(r_basis_is_OK()); lp_assert(r_basis_is_OK());
lean_assert(m_r_solver.non_basic_columns_are_set_correctly()); lp_assert(m_r_solver.non_basic_columns_are_set_correctly());
lean_assert(m_r_solver.inf_set_is_correct()); lp_assert(m_r_solver.inf_set_is_correct());
} }

View file

@ -8,6 +8,6 @@
#include "util/debug.h" #include "util/debug.h"
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
#include <unordered_map> #include <unordered_map>
namespace lean { namespace lp {
typedef std::unordered_map<unsigned, non_basic_column_value_position> lar_solution_signature; typedef std::unordered_map<unsigned, non_basic_column_value_position> lar_solution_signature;
} }

View file

@ -4,7 +4,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
namespace lean { namespace lp {
unsigned lar_solver::constraint_count() const { unsigned lar_solver::constraint_count() const {
return m_constraints.size(); return m_constraints.size();
@ -23,7 +23,7 @@ lp_settings & lar_solver::settings() { return m_settings;}
lp_settings const & lar_solver::settings() const { return m_settings;} lp_settings const & lar_solver::settings() const { return m_settings;}
void clear() {lean_assert(false); // not implemented void clear() {lp_assert(false); // not implemented
} }
@ -52,7 +52,7 @@ bool lar_solver::is_term(var_index j) const {
} }
unsigned lar_solver::adjust_term_index(unsigned j) const { unsigned lar_solver::adjust_term_index(unsigned j) const {
lean_assert(is_term(j)); lp_assert(is_term(j));
return j - m_terms_start_index; return j - m_terms_start_index;
} }
@ -60,10 +60,10 @@ unsigned lar_solver::adjust_term_index(unsigned j) const {
bool lar_solver::use_lu() const { return m_settings.simplex_strategy() == simplex_strategy_enum::lu; } bool lar_solver::use_lu() const { return m_settings.simplex_strategy() == simplex_strategy_enum::lu; }
bool lar_solver::sizes_are_correct() const { bool lar_solver::sizes_are_correct() const {
lean_assert(strategy_is_undecided() || !m_mpq_lar_core_solver.need_to_presolve_with_double_solver() || A_r().column_count() == A_d().column_count()); lp_assert(strategy_is_undecided() || !m_mpq_lar_core_solver.need_to_presolve_with_double_solver() || A_r().column_count() == A_d().column_count());
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_column_types.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_column_types.size());
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size());
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_x.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_x.size());
return true; return true;
} }
@ -105,7 +105,7 @@ bool lar_solver::implied_bound_is_correctly_explained(implied_bound const & be,
else if (kind == LE || kind == LT) n_of_L++; else if (kind == LE || kind == LT) n_of_L++;
rs_of_evidence += coeff*constr.m_right_side; rs_of_evidence += coeff*constr.m_right_side;
} }
lean_assert(n_of_G == 0 || n_of_L == 0); lp_assert(n_of_G == 0 || n_of_L == 0);
lconstraint_kind kind = n_of_G ? GE : (n_of_L ? LE : EQ); lconstraint_kind kind = n_of_G ? GE : (n_of_L ? LE : EQ);
if (strict) if (strict)
kind = static_cast<lconstraint_kind>((static_cast<int>(kind) / 2)); kind = static_cast<lconstraint_kind>((static_cast<int>(kind) / 2));
@ -149,7 +149,7 @@ bool lar_solver::implied_bound_is_correctly_explained(implied_bound const & be,
void lar_solver::analyze_new_bounds_on_row( void lar_solver::analyze_new_bounds_on_row(
unsigned row_index, unsigned row_index,
bound_propagator & bp) { bound_propagator & bp) {
lean_assert(!use_tableau()); lp_assert(!use_tableau());
iterator_on_pivot_row<mpq> it(m_mpq_lar_core_solver.get_pivot_row(), m_mpq_lar_core_solver.m_r_basis[row_index]); iterator_on_pivot_row<mpq> it(m_mpq_lar_core_solver.get_pivot_row(), m_mpq_lar_core_solver.m_r_basis[row_index]);
bound_analyzer_on_row ra_pos(it, bound_analyzer_on_row ra_pos(it,
@ -168,7 +168,7 @@ void lar_solver::analyze_new_bounds_on_row_tableau(
if (A_r().m_rows[row_index].size() > settings().max_row_length_for_bound_propagation) if (A_r().m_rows[row_index].size() > settings().max_row_length_for_bound_propagation)
return; return;
iterator_on_row<mpq> it(A_r().m_rows[row_index]); iterator_on_row<mpq> it(A_r().m_rows[row_index]);
lean_assert(use_tableau()); lp_assert(use_tableau());
bound_analyzer_on_row::analyze_row(it, bound_analyzer_on_row::analyze_row(it,
zero_of_type<numeric_pair<mpq>>(), zero_of_type<numeric_pair<mpq>>(),
row_index, row_index,
@ -201,7 +201,7 @@ void lar_solver::calculate_implied_bounds_for_row(unsigned i, bound_propagator &
linear_combination_iterator<mpq> * lar_solver::create_new_iter_from_term(unsigned term_index) const { linear_combination_iterator<mpq> * lar_solver::create_new_iter_from_term(unsigned term_index) const {
lean_assert(false); // not implemented lp_assert(false); // not implemented
return nullptr; return nullptr;
// new linear_combination_iterator_on_vector<mpq>(m_terms[adjust_term_index(term_index)]->coeffs_as_vector()); // new linear_combination_iterator_on_vector<mpq>(m_terms[adjust_term_index(term_index)]->coeffs_as_vector());
} }
@ -212,7 +212,7 @@ unsigned lar_solver::adjust_column_index_to_term_index(unsigned j) const {
} }
void lar_solver::propagate_bounds_on_a_term(const lar_term& t, bound_propagator & bp, unsigned term_offset) { void lar_solver::propagate_bounds_on_a_term(const lar_term& t, bound_propagator & bp, unsigned term_offset) {
lean_assert(false); // not implemented lp_assert(false); // not implemented
} }
@ -223,7 +223,7 @@ void lar_solver::explain_implied_bound(implied_bound & ib, bound_propagator & bp
unsigned m_j = ib.m_j; unsigned m_j = ib.m_j;
if (is_term(m_j)) { if (is_term(m_j)) {
auto it = m_ext_vars_to_columns.find(m_j); auto it = m_ext_vars_to_columns.find(m_j);
lean_assert(it != m_ext_vars_to_columns.end()); lp_assert(it != m_ext_vars_to_columns.end());
m_j = it->second.ext_j(); m_j = it->second.ext_j();
} }
for (auto const& r : A_r().m_rows[i]) { for (auto const& r : A_r().m_rows[i]) {
@ -232,22 +232,22 @@ void lar_solver::explain_implied_bound(implied_bound & ib, bound_propagator & bp
if (j == m_j) continue; if (j == m_j) continue;
if (is_term(j)) { if (is_term(j)) {
auto it = m_ext_vars_to_columns.find(j); auto it = m_ext_vars_to_columns.find(j);
lean_assert(it != m_ext_vars_to_columns.end()); lp_assert(it != m_ext_vars_to_columns.end());
j = it->second.ext_j(); j = it->second.ext_j();
} }
int a_sign = is_pos(a)? 1: -1; int a_sign = is_pos(a)? 1: -1;
int sign = j_sign * a_sign; int sign = j_sign * a_sign;
const ul_pair & ul = m_vars_to_ul_pairs[j]; const ul_pair & ul = m_vars_to_ul_pairs[j];
auto witness = sign > 0? ul.upper_bound_witness(): ul.low_bound_witness(); auto witness = sign > 0? ul.upper_bound_witness(): ul.low_bound_witness();
lean_assert(is_valid(witness)); lp_assert(is_valid(witness));
bp.consume(a, witness); bp.consume(a, witness);
} }
// lean_assert(implied_bound_is_correctly_explained(ib, explanation)); // lp_assert(implied_bound_is_correctly_explained(ib, explanation));
} }
bool lar_solver::term_is_used_as_row(unsigned term) const { bool lar_solver::term_is_used_as_row(unsigned term) const {
lean_assert(is_term(term)); lp_assert(is_term(term));
return contains(m_ext_vars_to_columns, term); return contains(m_ext_vars_to_columns, term);
} }
@ -338,7 +338,7 @@ void lar_solver::push() {
m_constraint_count.push(); m_constraint_count.push();
} }
void lar_solver::clean_large_elements_after_pop(unsigned n, int_set& set) { void lar_solver::clp_large_elements_after_pop(unsigned n, int_set& set) {
vector<int> to_remove; vector<int> to_remove;
for (unsigned j: set.m_index) for (unsigned j: set.m_index)
if (j >= n) if (j >= n)
@ -348,7 +348,7 @@ void lar_solver::clean_large_elements_after_pop(unsigned n, int_set& set) {
} }
void lar_solver::shrink_inf_set_after_pop(unsigned n, int_set & set) { void lar_solver::shrink_inf_set_after_pop(unsigned n, int_set & set) {
clean_large_elements_after_pop(n, set); clp_large_elements_after_pop(n, set);
set.resize(n); set.resize(n);
} }
@ -367,16 +367,16 @@ void lar_solver::pop(unsigned k) {
m_vars_to_ul_pairs.pop(k); m_vars_to_ul_pairs.pop(k);
m_mpq_lar_core_solver.pop(k); m_mpq_lar_core_solver.pop(k);
clean_large_elements_after_pop(n, m_columns_with_changed_bound); clp_large_elements_after_pop(n, m_columns_with_changed_bound);
unsigned m = A_r().row_count(); unsigned m = A_r().row_count();
clean_large_elements_after_pop(m, m_rows_with_changed_bounds); clp_large_elements_after_pop(m, m_rows_with_changed_bounds);
clean_inf_set_of_r_solver_after_pop(); clp_inf_set_of_r_solver_after_pop();
lean_assert(m_settings.simplex_strategy() == simplex_strategy_enum::undecided || lp_assert(m_settings.simplex_strategy() == simplex_strategy_enum::undecided ||
(!use_tableau()) || m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau()); (!use_tableau()) || m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau());
lean_assert(ax_is_correct()); lp_assert(ax_is_correct());
lean_assert(m_mpq_lar_core_solver.m_r_solver.inf_set_is_correct()); lp_assert(m_mpq_lar_core_solver.m_r_solver.inf_set_is_correct());
m_constraint_count.pop(k); m_constraint_count.pop(k);
for (unsigned i = m_constraint_count; i < m_constraints.size(); i++) for (unsigned i = m_constraint_count; i < m_constraints.size(); i++)
delete m_constraints[i]; delete m_constraints[i];
@ -389,8 +389,8 @@ void lar_solver::pop(unsigned k) {
m_terms.resize(m_term_count); m_terms.resize(m_term_count);
m_simplex_strategy.pop(k); m_simplex_strategy.pop(k);
m_settings.simplex_strategy() = m_simplex_strategy; m_settings.simplex_strategy() = m_simplex_strategy;
lean_assert(sizes_are_correct()); lp_assert(sizes_are_correct());
lean_assert((!m_settings.use_tableau()) || m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau()); lp_assert((!m_settings.use_tableau()) || m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau());
} }
vector<constraint_index> lar_solver::get_all_constraint_indices() const { vector<constraint_index> lar_solver::get_all_constraint_indices() const {
@ -419,13 +419,13 @@ bool lar_solver::maximize_term_on_tableau(const vector<std::pair<mpq, var_index>
bool lar_solver::costs_are_zeros_for_r_solver() const { bool lar_solver::costs_are_zeros_for_r_solver() const {
for (unsigned j = 0; j < m_mpq_lar_core_solver.m_r_solver.m_costs.size(); j++) { for (unsigned j = 0; j < m_mpq_lar_core_solver.m_r_solver.m_costs.size(); j++) {
lean_assert(is_zero(m_mpq_lar_core_solver.m_r_solver.m_costs[j])); lp_assert(is_zero(m_mpq_lar_core_solver.m_r_solver.m_costs[j]));
} }
return true; return true;
} }
bool lar_solver::reduced_costs_are_zeroes_for_r_solver() const { bool lar_solver::reduced_costs_are_zeroes_for_r_solver() const {
for (unsigned j = 0; j < m_mpq_lar_core_solver.m_r_solver.m_d.size(); j++) { for (unsigned j = 0; j < m_mpq_lar_core_solver.m_r_solver.m_d.size(); j++) {
lean_assert(is_zero(m_mpq_lar_core_solver.m_r_solver.m_d[j])); lp_assert(is_zero(m_mpq_lar_core_solver.m_r_solver.m_d[j]));
} }
return true; return true;
} }
@ -433,7 +433,7 @@ bool lar_solver::reduced_costs_are_zeroes_for_r_solver() const {
void lar_solver::set_costs_to_zero(const vector<std::pair<mpq, var_index>> & term) { void lar_solver::set_costs_to_zero(const vector<std::pair<mpq, var_index>> & term) {
auto & rslv = m_mpq_lar_core_solver.m_r_solver; auto & rslv = m_mpq_lar_core_solver.m_r_solver;
auto & jset = m_mpq_lar_core_solver.m_r_solver.m_inf_set; // hijack this set that should be empty right now auto & jset = m_mpq_lar_core_solver.m_r_solver.m_inf_set; // hijack this set that should be empty right now
lean_assert(jset.m_index.size()==0); lp_assert(jset.m_index.size()==0);
for (auto & p : term) { for (auto & p : term) {
unsigned j = p.second; unsigned j = p.second;
@ -452,16 +452,16 @@ void lar_solver::set_costs_to_zero(const vector<std::pair<mpq, var_index>> & ter
jset.clear(); jset.clear();
lean_assert(reduced_costs_are_zeroes_for_r_solver()); lp_assert(reduced_costs_are_zeroes_for_r_solver());
lean_assert(costs_are_zeros_for_r_solver()); lp_assert(costs_are_zeros_for_r_solver());
} }
void lar_solver::prepare_costs_for_r_solver(const vector<std::pair<mpq, var_index>> & term) { void lar_solver::prepare_costs_for_r_solver(const vector<std::pair<mpq, var_index>> & term) {
auto & rslv = m_mpq_lar_core_solver.m_r_solver; auto & rslv = m_mpq_lar_core_solver.m_r_solver;
rslv.m_using_infeas_costs = false; rslv.m_using_infeas_costs = false;
lean_assert(costs_are_zeros_for_r_solver()); lp_assert(costs_are_zeros_for_r_solver());
lean_assert(reduced_costs_are_zeroes_for_r_solver()); lp_assert(reduced_costs_are_zeroes_for_r_solver());
rslv.m_costs.resize(A_r().column_count(), zero_of_type<mpq>()); rslv.m_costs.resize(A_r().column_count(), zero_of_type<mpq>());
for (auto & p : term) { for (auto & p : term) {
unsigned j = p.second; unsigned j = p.second;
@ -471,7 +471,7 @@ void lar_solver::prepare_costs_for_r_solver(const vector<std::pair<mpq, var_inde
else else
rslv.update_reduced_cost_for_basic_column_cost_change(- p.first, j); rslv.update_reduced_cost_for_basic_column_cost_change(- p.first, j);
} }
lean_assert(rslv.reduced_costs_are_correct_tableau()); lp_assert(rslv.reduced_costs_are_correct_tableau());
} }
bool lar_solver::maximize_term_on_corrected_r_solver(const vector<std::pair<mpq, var_index>> & term, bool lar_solver::maximize_term_on_corrected_r_solver(const vector<std::pair<mpq, var_index>> & term,
@ -498,10 +498,10 @@ bool lar_solver::maximize_term_on_corrected_r_solver(const vector<std::pair<mpq,
} }
case simplex_strategy_enum::lu: case simplex_strategy_enum::lu:
lean_assert(false); // not implemented lp_assert(false); // not implemented
return false; return false;
default: default:
lean_unreachable(); // wrong mode lp_unreachable(); // wrong mode
} }
return false; return false;
} }
@ -509,7 +509,7 @@ bool lar_solver::maximize_term_on_corrected_r_solver(const vector<std::pair<mpq,
// return true if found and false if unbounded // return true if found and false if unbounded
bool lar_solver::maximize_term(const vector<std::pair<mpq, var_index>> & term, bool lar_solver::maximize_term(const vector<std::pair<mpq, var_index>> & term,
impq &term_max) { impq &term_max) {
lean_assert(m_mpq_lar_core_solver.m_r_solver.current_x_is_feasible()); lp_assert(m_mpq_lar_core_solver.m_r_solver.current_x_is_feasible());
m_mpq_lar_core_solver.m_r_solver.m_look_for_feasible_solution_only = false; m_mpq_lar_core_solver.m_r_solver.m_look_for_feasible_solution_only = false;
return maximize_term_on_corrected_r_solver(term, term_max); return maximize_term_on_corrected_r_solver(term, term_max);
} }
@ -517,7 +517,7 @@ bool lar_solver::maximize_term(const vector<std::pair<mpq, var_index>> & term,
const lar_term & lar_solver::get_term(unsigned j) const { const lar_term & lar_solver::get_term(unsigned j) const {
lean_assert(j >= m_terms_start_index); lp_assert(j >= m_terms_start_index);
return *m_terms[j - m_terms_start_index]; return *m_terms[j - m_terms_start_index];
} }
@ -579,7 +579,7 @@ void lar_solver::detect_rows_of_bound_change_column_for_nbasic_column(unsigned j
m_column_buffer.resize(A_r().row_count()); m_column_buffer.resize(A_r().row_count());
else else
m_column_buffer.clear(); m_column_buffer.clear();
lean_assert(m_column_buffer.size() == 0 && m_column_buffer.is_OK()); lp_assert(m_column_buffer.size() == 0 && m_column_buffer.is_OK());
m_mpq_lar_core_solver.m_r_solver.solve_Bd(j, m_column_buffer); m_mpq_lar_core_solver.m_r_solver.solve_Bd(j, m_column_buffer);
for (unsigned i : m_column_buffer.m_index) for (unsigned i : m_column_buffer.m_index)
@ -613,7 +613,7 @@ void lar_solver::detect_rows_of_column_with_bound_change(unsigned j) {
} }
void lar_solver::adjust_x_of_column(unsigned j) { void lar_solver::adjust_x_of_column(unsigned j) {
lean_assert(false); lp_assert(false);
} }
bool lar_solver::row_is_correct(unsigned i) const { bool lar_solver::row_is_correct(unsigned i) const {
@ -706,14 +706,14 @@ void lar_solver::update_x_and_inf_costs_for_columns_with_changed_bounds() {
} }
void lar_solver::update_x_and_inf_costs_for_columns_with_changed_bounds_tableau() { void lar_solver::update_x_and_inf_costs_for_columns_with_changed_bounds_tableau() {
lean_assert(ax_is_correct()); lp_assert(ax_is_correct());
for (auto j : m_columns_with_changed_bound.m_index) for (auto j : m_columns_with_changed_bound.m_index)
update_x_and_inf_costs_for_column_with_changed_bounds(j); update_x_and_inf_costs_for_column_with_changed_bounds(j);
if (tableau_with_costs()) { if (tableau_with_costs()) {
for (unsigned j : m_basic_columns_with_changed_cost.m_index) for (unsigned j : m_basic_columns_with_changed_cost.m_index)
m_mpq_lar_core_solver.m_r_solver.update_inf_cost_for_column_tableau(j); m_mpq_lar_core_solver.m_r_solver.update_inf_cost_for_column_tableau(j);
lean_assert(m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau()); lp_assert(m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau());
} }
} }
@ -735,7 +735,7 @@ void lar_solver::solve_with_core_solver() {
update_x_and_inf_costs_for_columns_with_changed_bounds(); update_x_and_inf_costs_for_columns_with_changed_bounds();
m_mpq_lar_core_solver.solve(); m_mpq_lar_core_solver.solve();
set_status(m_mpq_lar_core_solver.m_r_solver.get_status()); set_status(m_mpq_lar_core_solver.m_r_solver.get_status());
lean_assert(m_status != OPTIMAL || all_constraints_hold()); lp_assert(m_status != OPTIMAL || all_constraints_hold());
} }
@ -760,7 +760,7 @@ numeric_pair<mpq> lar_solver::get_basic_var_value_from_row(unsigned i) {
numeric_pair<mpq> r = zero_of_type<numeric_pair<mpq>>(); numeric_pair<mpq> r = zero_of_type<numeric_pair<mpq>>();
m_mpq_lar_core_solver.calculate_pivot_row(i); m_mpq_lar_core_solver.calculate_pivot_row(i);
for (unsigned j : m_mpq_lar_core_solver.m_r_solver.m_pivot_row.m_index) { for (unsigned j : m_mpq_lar_core_solver.m_r_solver.m_pivot_row.m_index) {
lean_assert(m_mpq_lar_core_solver.m_r_solver.m_basis_heading[j] < 0); lp_assert(m_mpq_lar_core_solver.m_r_solver.m_basis_heading[j] < 0);
r -= m_mpq_lar_core_solver.m_r_solver.m_pivot_row.m_data[j] * m_mpq_lar_core_solver.m_r_x[j]; r -= m_mpq_lar_core_solver.m_r_solver.m_pivot_row.m_data[j] * m_mpq_lar_core_solver.m_r_x[j];
} }
return r; return r;
@ -824,12 +824,12 @@ unsigned lar_solver::constraint_stack_size() const {
} }
void lar_solver::fill_last_row_of_A_r(static_matrix<mpq, numeric_pair<mpq>> & A, const lar_term * ls) { void lar_solver::fill_last_row_of_A_r(static_matrix<mpq, numeric_pair<mpq>> & A, const lar_term * ls) {
lean_assert(A.row_count() > 0); lp_assert(A.row_count() > 0);
lean_assert(A.column_count() > 0); lp_assert(A.column_count() > 0);
unsigned last_row = A.row_count() - 1; unsigned last_row = A.row_count() - 1;
lean_assert(A.m_rows[last_row].size() == 0); lp_assert(A.m_rows[last_row].size() == 0);
for (auto & t : ls->m_coeffs) { for (auto & t : ls->m_coeffs) {
lean_assert(!is_zero(t.second)); lp_assert(!is_zero(t.second));
var_index j = t.first; var_index j = t.first;
A.set(last_row, j, - t.second); A.set(last_row, j, - t.second);
} }
@ -839,7 +839,7 @@ void lar_solver::fill_last_row_of_A_r(static_matrix<mpq, numeric_pair<mpq>> & A,
template <typename U, typename V> template <typename U, typename V>
void lar_solver::create_matrix_A(static_matrix<U, V> & matr) { void lar_solver::create_matrix_A(static_matrix<U, V> & matr) {
lean_assert(false); // not implemented lp_assert(false); // not implemented
/* /*
unsigned m = number_or_nontrivial_left_sides(); unsigned m = number_or_nontrivial_left_sides();
unsigned n = m_vec_of_canonic_left_sides.size(); unsigned n = m_vec_of_canonic_left_sides.size();
@ -920,7 +920,7 @@ bool lar_solver::constraint_holds(const lar_base_constraint & constr, std::unord
case GT: 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; case EQ: return left_side_val == constr.m_right_side;
default: default:
lean_unreachable(); lp_unreachable();
} }
return false; // it is unreachable return false; // it is unreachable
} }
@ -965,7 +965,7 @@ bool lar_solver::the_left_sides_sum_to_zero(const vector<std::pair<mpq, unsigned
for (auto & it : evidence) { for (auto & it : evidence) {
mpq coeff = it.first; mpq coeff = it.first;
constraint_index con_ind = it.second; constraint_index con_ind = it.second;
lean_assert(con_ind < m_constraints.size()); lp_assert(con_ind < m_constraints.size());
register_in_map(coeff_map, *m_constraints[con_ind], coeff); register_in_map(coeff_map, *m_constraints[con_ind], coeff);
} }
@ -988,7 +988,7 @@ bool lar_solver::the_right_sides_do_not_sum_to_zero(const vector<std::pair<mpq,
for (auto & it : evidence) { for (auto & it : evidence) {
mpq coeff = it.first; mpq coeff = it.first;
constraint_index con_ind = it.second; constraint_index con_ind = it.second;
lean_assert(con_ind < m_constraints.size()); lp_assert(con_ind < m_constraints.size());
const lar_constraint & constr = *m_constraints[con_ind]; const lar_constraint & constr = *m_constraints[con_ind];
ret += constr.m_right_side * coeff; ret += constr.m_right_side * coeff;
} }
@ -998,22 +998,22 @@ bool lar_solver::the_right_sides_do_not_sum_to_zero(const vector<std::pair<mpq,
bool lar_solver::explanation_is_correct(const vector<std::pair<mpq, unsigned>>& explanation) const { bool lar_solver::explanation_is_correct(const vector<std::pair<mpq, unsigned>>& explanation) const {
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
lconstraint_kind kind; lconstraint_kind kind;
lean_assert(the_relations_are_of_same_type(explanation, kind)); lp_assert(the_relations_are_of_same_type(explanation, kind));
lean_assert(the_left_sides_sum_to_zero(explanation)); lp_assert(the_left_sides_sum_to_zero(explanation));
mpq rs = sum_of_right_sides_of_explanation(explanation); mpq rs = sum_of_right_sides_of_explanation(explanation);
switch (kind) { switch (kind) {
case LE: lean_assert(rs < zero_of_type<mpq>()); case LE: lp_assert(rs < zero_of_type<mpq>());
break; break;
case LT: lean_assert(rs <= zero_of_type<mpq>()); case LT: lp_assert(rs <= zero_of_type<mpq>());
break; break;
case GE: lean_assert(rs > zero_of_type<mpq>()); case GE: lp_assert(rs > zero_of_type<mpq>());
break; break;
case GT: lean_assert(rs >= zero_of_type<mpq>()); case GT: lp_assert(rs >= zero_of_type<mpq>());
break; break;
case EQ: lean_assert(rs != zero_of_type<mpq>()); case EQ: lp_assert(rs != zero_of_type<mpq>());
break; break;
default: default:
lean_assert(false); lp_assert(false);
return false; return false;
} }
#endif #endif
@ -1034,7 +1034,7 @@ mpq lar_solver::sum_of_right_sides_of_explanation(const vector<std::pair<mpq, un
for (auto & it : explanation) { for (auto & it : explanation) {
mpq coeff = it.first; mpq coeff = it.first;
constraint_index con_ind = it.second; constraint_index con_ind = it.second;
lean_assert(con_ind < m_constraints.size()); lp_assert(con_ind < m_constraints.size());
ret += (m_constraints[con_ind]->m_right_side - m_constraints[con_ind]->get_free_coeff_of_left_side()) * coeff; ret += (m_constraints[con_ind]->m_right_side - m_constraints[con_ind]->get_free_coeff_of_left_side()) * coeff;
} }
return ret; return ret;
@ -1091,7 +1091,7 @@ void lar_solver::get_infeasibility_explanation(vector<std::pair<mpq, constraint_
int inf_sign; int inf_sign;
auto inf_row = m_mpq_lar_core_solver.get_infeasibility_info(inf_sign); auto inf_row = m_mpq_lar_core_solver.get_infeasibility_info(inf_sign);
get_infeasibility_explanation_for_inf_sign(explanation, inf_row, inf_sign); get_infeasibility_explanation_for_inf_sign(explanation, inf_row, inf_sign);
lean_assert(explanation_is_correct(explanation)); lp_assert(explanation_is_correct(explanation));
} }
@ -1109,14 +1109,14 @@ void lar_solver::get_infeasibility_explanation_for_inf_sign(
const ul_pair & ul = m_vars_to_ul_pairs[j]; const ul_pair & ul = m_vars_to_ul_pairs[j];
constraint_index bound_constr_i = adj_sign < 0 ? ul.upper_bound_witness() : ul.low_bound_witness(); constraint_index bound_constr_i = adj_sign < 0 ? ul.upper_bound_witness() : ul.low_bound_witness();
lean_assert(bound_constr_i < m_constraints.size()); lp_assert(bound_constr_i < m_constraints.size());
explanation.push_back(std::make_pair(coeff, bound_constr_i)); explanation.push_back(std::make_pair(coeff, bound_constr_i));
} }
} }
void lar_solver::get_model(std::unordered_map<var_index, mpq> & variable_values) const { void lar_solver::get_model(std::unordered_map<var_index, mpq> & variable_values) const {
mpq delta = mpq(1, 2); // start from 0.5 to have less clashes mpq delta = mpq(1, 2); // start from 0.5 to have less clashes
lean_assert(m_status == OPTIMAL); lp_assert(m_status == OPTIMAL);
unsigned i; unsigned i;
do { do {
@ -1188,7 +1188,7 @@ mpq lar_solver::get_left_side_val(const lar_base_constraint & cns, const std::u
for (auto & it : cns.get_left_side_coefficients()) { for (auto & it : cns.get_left_side_coefficients()) {
var_index j = it.second; var_index j = it.second;
auto vi = var_map.find(j); auto vi = var_map.find(j);
lean_assert(vi != var_map.end()); lp_assert(vi != var_map.end());
ret += it.first * vi->second; ret += it.first * vi->second;
} }
return ret; return ret;
@ -1234,7 +1234,7 @@ bool lar_solver::column_represents_row_in_tableau(unsigned j) {
void lar_solver::make_sure_that_the_bottom_right_elem_not_zero_in_tableau(unsigned i, unsigned j) { void lar_solver::make_sure_that_the_bottom_right_elem_not_zero_in_tableau(unsigned i, unsigned j) {
// i, j - is the indices of the bottom-right element of the tableau // i, j - is the indices of the bottom-right element of the tableau
lean_assert(A_r().row_count() == i + 1 && A_r().column_count() == j + 1); lp_assert(A_r().row_count() == i + 1 && A_r().column_count() == j + 1);
auto & last_column = A_r().m_columns[j]; auto & last_column = A_r().m_columns[j];
int non_zero_column_cell_index = -1; int non_zero_column_cell_index = -1;
for (unsigned k = last_column.size(); k-- > 0;){ for (unsigned k = last_column.size(); k-- > 0;){
@ -1244,13 +1244,13 @@ void lar_solver::make_sure_that_the_bottom_right_elem_not_zero_in_tableau(unsign
non_zero_column_cell_index = k; non_zero_column_cell_index = k;
} }
lean_assert(non_zero_column_cell_index != -1); lp_assert(non_zero_column_cell_index != -1);
lean_assert(static_cast<unsigned>(non_zero_column_cell_index) != i); lp_assert(static_cast<unsigned>(non_zero_column_cell_index) != i);
m_mpq_lar_core_solver.m_r_solver.transpose_rows_tableau(last_column[non_zero_column_cell_index].m_i, i); m_mpq_lar_core_solver.m_r_solver.transpose_rows_tableau(last_column[non_zero_column_cell_index].m_i, i);
} }
void lar_solver::remove_last_row_and_column_from_tableau(unsigned j) { void lar_solver::remove_last_row_and_column_from_tableau(unsigned j) {
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size());
auto & slv = m_mpq_lar_core_solver.m_r_solver; auto & slv = m_mpq_lar_core_solver.m_r_solver;
unsigned i = A_r().row_count() - 1; //last row index unsigned i = A_r().row_count() - 1; //last row index
make_sure_that_the_bottom_right_elem_not_zero_in_tableau(i, j); make_sure_that_the_bottom_right_elem_not_zero_in_tableau(i, j);
@ -1269,17 +1269,17 @@ void lar_solver::remove_last_row_and_column_from_tableau(unsigned j) {
A_r().remove_element(last_row, rc); A_r().remove_element(last_row, rc);
} }
lean_assert(last_row.size() == 0); lp_assert(last_row.size() == 0);
lean_assert(A_r().m_columns[j].size() == 0); lp_assert(A_r().m_columns[j].size() == 0);
A_r().m_rows.pop_back(); A_r().m_rows.pop_back();
A_r().m_columns.pop_back(); A_r().m_columns.pop_back();
slv.m_b.pop_back(); slv.m_b.pop_back();
} }
void lar_solver::remove_last_column_from_tableau(unsigned j) { void lar_solver::remove_last_column_from_tableau(unsigned j) {
lean_assert(j == A_r().column_count() - 1); lp_assert(j == A_r().column_count() - 1);
// the last column has to be empty // the last column has to be empty
lean_assert(A_r().m_columns[j].size() == 0); lp_assert(A_r().m_columns[j].size() == 0);
A_r().m_columns.pop_back(); A_r().m_columns.pop_back();
} }
@ -1288,7 +1288,7 @@ void lar_solver::remove_last_column_from_basis_tableau(unsigned j) {
int i = rslv.m_basis_heading[j]; int i = rslv.m_basis_heading[j];
if (i >= 0) { // j is a basic var if (i >= 0) { // j is a basic var
int last_pos = static_cast<int>(rslv.m_basis.size()) - 1; int last_pos = static_cast<int>(rslv.m_basis.size()) - 1;
lean_assert(last_pos >= 0); lp_assert(last_pos >= 0);
if (i != last_pos) { if (i != last_pos) {
unsigned j_at_last_pos = rslv.m_basis[last_pos]; unsigned j_at_last_pos = rslv.m_basis[last_pos];
rslv.m_basis[i] = j_at_last_pos; rslv.m_basis[i] = j_at_last_pos;
@ -1297,7 +1297,7 @@ void lar_solver::remove_last_column_from_basis_tableau(unsigned j) {
rslv.m_basis.pop_back(); // remove j from the basis rslv.m_basis.pop_back(); // remove j from the basis
} else { } else {
int last_pos = static_cast<int>(rslv.m_nbasis.size()) - 1; int last_pos = static_cast<int>(rslv.m_nbasis.size()) - 1;
lean_assert(last_pos >= 0); lp_assert(last_pos >= 0);
i = - 1 - i; i = - 1 - i;
if (i != last_pos) { if (i != last_pos) {
unsigned j_at_last_pos = rslv.m_nbasis[last_pos]; unsigned j_at_last_pos = rslv.m_nbasis[last_pos];
@ -1307,14 +1307,14 @@ void lar_solver::remove_last_column_from_basis_tableau(unsigned j) {
rslv.m_nbasis.pop_back(); // remove j from the basis rslv.m_nbasis.pop_back(); // remove j from the basis
} }
rslv.m_basis_heading.pop_back(); rslv.m_basis_heading.pop_back();
lean_assert(rslv.m_basis.size() == A_r().row_count()); lp_assert(rslv.m_basis.size() == A_r().row_count());
lean_assert(rslv.basis_heading_is_correct()); lp_assert(rslv.basis_heading_is_correct());
} }
void lar_solver::remove_column_from_tableau(unsigned j) { void lar_solver::remove_column_from_tableau(unsigned j) {
auto& rslv = m_mpq_lar_core_solver.m_r_solver; auto& rslv = m_mpq_lar_core_solver.m_r_solver;
lean_assert(j == A_r().column_count() - 1); lp_assert(j == A_r().column_count() - 1);
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size());
if (column_represents_row_in_tableau(j)) { if (column_represents_row_in_tableau(j)) {
remove_last_row_and_column_from_tableau(j); remove_last_row_and_column_from_tableau(j);
if (rslv.m_basis_heading[j] < 0) if (rslv.m_basis_heading[j] < 0)
@ -1328,27 +1328,27 @@ void lar_solver::remove_column_from_tableau(unsigned j) {
rslv.m_costs.pop_back(); rslv.m_costs.pop_back();
remove_last_column_from_basis_tableau(j); remove_last_column_from_basis_tableau(j);
lean_assert(m_mpq_lar_core_solver.r_basis_is_OK()); lp_assert(m_mpq_lar_core_solver.r_basis_is_OK());
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size());
} }
void lar_solver::pop_tableau() { void lar_solver::pop_tableau() {
lean_assert(m_mpq_lar_core_solver.m_r_solver.m_costs.size() == A_r().column_count()); lp_assert(m_mpq_lar_core_solver.m_r_solver.m_costs.size() == A_r().column_count());
lean_assert(m_mpq_lar_core_solver.m_r_solver.m_basis.size() == A_r().row_count()); lp_assert(m_mpq_lar_core_solver.m_r_solver.m_basis.size() == A_r().row_count());
lean_assert(m_mpq_lar_core_solver.m_r_solver.basis_heading_is_correct()); lp_assert(m_mpq_lar_core_solver.m_r_solver.basis_heading_is_correct());
// We remove last variables starting from m_column_names.size() to m_vec_of_canonic_left_sides.size(). // We remove last variables starting from m_column_names.size() to m_vec_of_canonic_left_sides.size().
// At this moment m_column_names is already popped // At this moment m_column_names is already popped
for (unsigned j = A_r().column_count(); j-- > m_columns_to_ext_vars_or_term_indices.size();) for (unsigned j = A_r().column_count(); j-- > m_columns_to_ext_vars_or_term_indices.size();)
remove_column_from_tableau(j); remove_column_from_tableau(j);
lean_assert(m_mpq_lar_core_solver.m_r_solver.m_costs.size() == A_r().column_count()); lp_assert(m_mpq_lar_core_solver.m_r_solver.m_costs.size() == A_r().column_count());
lean_assert(m_mpq_lar_core_solver.m_r_solver.m_basis.size() == A_r().row_count()); lp_assert(m_mpq_lar_core_solver.m_r_solver.m_basis.size() == A_r().row_count());
lean_assert(m_mpq_lar_core_solver.m_r_solver.basis_heading_is_correct()); lp_assert(m_mpq_lar_core_solver.m_r_solver.basis_heading_is_correct());
} }
void lar_solver::clean_inf_set_of_r_solver_after_pop() { void lar_solver::clp_inf_set_of_r_solver_after_pop() {
vector<unsigned> became_feas; vector<unsigned> became_feas;
clean_large_elements_after_pop(A_r().column_count(), m_mpq_lar_core_solver.m_r_solver.m_inf_set); clp_large_elements_after_pop(A_r().column_count(), m_mpq_lar_core_solver.m_r_solver.m_inf_set);
std::unordered_set<unsigned> basic_columns_with_changed_cost; std::unordered_set<unsigned> basic_columns_with_changed_cost;
auto inf_index_copy = m_mpq_lar_core_solver.m_r_solver.m_inf_set.m_index; auto inf_index_copy = m_mpq_lar_core_solver.m_r_solver.m_inf_set.m_index;
for (auto j: inf_index_copy) { for (auto j: inf_index_copy) {
@ -1363,14 +1363,14 @@ void lar_solver::clean_inf_set_of_r_solver_after_pop() {
} }
for (unsigned j : became_feas) { for (unsigned j : became_feas) {
lean_assert(m_mpq_lar_core_solver.m_r_solver.m_basis_heading[j] < 0); lp_assert(m_mpq_lar_core_solver.m_r_solver.m_basis_heading[j] < 0);
m_mpq_lar_core_solver.m_r_solver.m_d[j] -= m_mpq_lar_core_solver.m_r_solver.m_costs[j]; m_mpq_lar_core_solver.m_r_solver.m_d[j] -= m_mpq_lar_core_solver.m_r_solver.m_costs[j];
m_mpq_lar_core_solver.m_r_solver.m_costs[j] = zero_of_type<mpq>(); m_mpq_lar_core_solver.m_r_solver.m_costs[j] = zero_of_type<mpq>();
m_mpq_lar_core_solver.m_r_solver.m_inf_set.erase(j); m_mpq_lar_core_solver.m_r_solver.m_inf_set.erase(j);
} }
became_feas.clear(); became_feas.clear();
for (unsigned j : m_mpq_lar_core_solver.m_r_solver.m_inf_set.m_index) { for (unsigned j : m_mpq_lar_core_solver.m_r_solver.m_inf_set.m_index) {
lean_assert(m_mpq_lar_core_solver.m_r_heading[j] >= 0); lp_assert(m_mpq_lar_core_solver.m_r_heading[j] >= 0);
if (m_mpq_lar_core_solver.m_r_solver.column_is_feasible(j)) if (m_mpq_lar_core_solver.m_r_solver.column_is_feasible(j))
became_feas.push_back(j); became_feas.push_back(j);
} }
@ -1383,14 +1383,14 @@ void lar_solver::clean_inf_set_of_r_solver_after_pop() {
m_mpq_lar_core_solver.m_r_solver.update_inf_cost_for_column_tableau(j); m_mpq_lar_core_solver.m_r_solver.update_inf_cost_for_column_tableau(j);
for (unsigned j : basic_columns_with_changed_cost) for (unsigned j : basic_columns_with_changed_cost)
m_mpq_lar_core_solver.m_r_solver.update_inf_cost_for_column_tableau(j); m_mpq_lar_core_solver.m_r_solver.update_inf_cost_for_column_tableau(j);
lean_assert(m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau()); lp_assert(m_mpq_lar_core_solver.m_r_solver.reduced_costs_are_correct_tableau());
} }
} }
void lar_solver::shrink_explanation_to_minimum(vector<std::pair<mpq, constraint_index>> & explanation) const { void lar_solver::shrink_explanation_to_minimum(vector<std::pair<mpq, constraint_index>> & explanation) const {
// implementing quickXplain // implementing quickXplain
quick_xplain::run(explanation, *this); quick_xplain::run(explanation, *this);
lean_assert(this->explanation_is_correct(explanation)); lp_assert(this->explanation_is_correct(explanation));
} }
bool lar_solver::model_is_int_feasible() const { bool lar_solver::model_is_int_feasible() const {
@ -1421,7 +1421,7 @@ bool lar_solver::var_is_int(var_index v) const {
bool lar_solver::column_is_int(unsigned j) const { bool lar_solver::column_is_int(unsigned j) const {
unsigned ext_var = m_columns_to_ext_vars_or_term_indices[j]; unsigned ext_var = m_columns_to_ext_vars_or_term_indices[j];
lean_assert(contains(m_ext_vars_to_columns, ext_var)); lp_assert(contains(m_ext_vars_to_columns, ext_var));
return m_ext_vars_to_columns.find(ext_var)->second.is_integer(); return m_ext_vars_to_columns.find(ext_var)->second.is_integer();
} }
@ -1432,7 +1432,7 @@ bool lar_solver::column_is_fixed(unsigned j) const {
bool lar_solver::ext_var_is_int(var_index ext_var) const { bool lar_solver::ext_var_is_int(var_index ext_var) const {
auto it = m_ext_vars_to_columns.find(ext_var); auto it = m_ext_vars_to_columns.find(ext_var);
lean_assert(it != m_ext_vars_to_columns.end()); lp_assert(it != m_ext_vars_to_columns.end());
return it == m_ext_vars_to_columns.end() || it->second.is_integer(); return it == m_ext_vars_to_columns.end() || it->second.is_integer();
} }
@ -1445,7 +1445,7 @@ bool lar_solver::strategy_is_undecided() const {
var_index lar_solver::add_var(unsigned ext_j, bool is_int) { var_index lar_solver::add_var(unsigned ext_j, bool is_int) {
TRACE("add_var", tout << "adding var " << ext_j << (is_int? " int" : " nonint") << std::endl;); TRACE("add_var", tout << "adding var " << ext_j << (is_int? " int" : " nonint") << std::endl;);
var_index i; var_index i;
lean_assert(ext_j < m_terms_start_index); lp_assert(ext_j < m_terms_start_index);
if (ext_j >= m_terms_start_index) if (ext_j >= m_terms_start_index)
throw 0; // todo : what is the right way to exit? throw 0; // todo : what is the right way to exit?
@ -1453,19 +1453,19 @@ var_index lar_solver::add_var(unsigned ext_j, bool is_int) {
if (it != m_ext_vars_to_columns.end()) { if (it != m_ext_vars_to_columns.end()) {
return it->second.ext_j(); return it->second.ext_j();
} }
lean_assert(m_vars_to_ul_pairs.size() == A_r().column_count()); lp_assert(m_vars_to_ul_pairs.size() == A_r().column_count());
i = A_r().column_count(); i = A_r().column_count();
m_vars_to_ul_pairs.push_back(ul_pair(static_cast<unsigned>(-1))); m_vars_to_ul_pairs.push_back(ul_pair(static_cast<unsigned>(-1)));
add_non_basic_var_to_core_fields(ext_j, is_int); add_non_basic_var_to_core_fields(ext_j, is_int);
lean_assert(sizes_are_correct()); lp_assert(sizes_are_correct());
return i; return i;
} }
void lar_solver::register_new_ext_var_index(unsigned ext_v, bool is_int) { void lar_solver::register_new_ext_var_index(unsigned ext_v, bool is_int) {
lean_assert(!contains(m_ext_vars_to_columns, ext_v)); lp_assert(!contains(m_ext_vars_to_columns, ext_v));
unsigned j = static_cast<unsigned>(m_ext_vars_to_columns.size()); unsigned j = static_cast<unsigned>(m_ext_vars_to_columns.size());
m_ext_vars_to_columns.insert(std::make_pair(ext_v, ext_var_info(j, is_int))); m_ext_vars_to_columns.insert(std::make_pair(ext_v, ext_var_info(j, is_int)));
lean_assert(m_columns_to_ext_vars_or_term_indices.size() == j); lp_assert(m_columns_to_ext_vars_or_term_indices.size() == j);
m_columns_to_ext_vars_or_term_indices.push_back(ext_v); m_columns_to_ext_vars_or_term_indices.push_back(ext_v);
} }
@ -1481,12 +1481,12 @@ void lar_solver::add_non_basic_var_to_core_fields(unsigned ext_j, bool is_int) {
void lar_solver::add_new_var_to_core_fields_for_doubles(bool register_in_basis) { void lar_solver::add_new_var_to_core_fields_for_doubles(bool register_in_basis) {
unsigned j = A_d().column_count(); unsigned j = A_d().column_count();
A_d().add_column(); A_d().add_column();
lean_assert(m_mpq_lar_core_solver.m_d_x.size() == j); lp_assert(m_mpq_lar_core_solver.m_d_x.size() == j);
// lean_assert(m_mpq_lar_core_solver.m_d_low_bounds.size() == j && m_mpq_lar_core_solver.m_d_upper_bounds.size() == j); // restore later // lp_assert(m_mpq_lar_core_solver.m_d_low_bounds.size() == j && m_mpq_lar_core_solver.m_d_upper_bounds.size() == j); // restore later
m_mpq_lar_core_solver.m_d_x.resize(j + 1); m_mpq_lar_core_solver.m_d_x.resize(j + 1);
m_mpq_lar_core_solver.m_d_low_bounds.resize(j + 1); m_mpq_lar_core_solver.m_d_low_bounds.resize(j + 1);
m_mpq_lar_core_solver.m_d_upper_bounds.resize(j + 1); m_mpq_lar_core_solver.m_d_upper_bounds.resize(j + 1);
lean_assert(m_mpq_lar_core_solver.m_d_heading.size() == j); // as A().column_count() on the entry to the method lp_assert(m_mpq_lar_core_solver.m_d_heading.size() == j); // as A().column_count() on the entry to the method
if (register_in_basis) { if (register_in_basis) {
A_d().add_row(); A_d().add_row();
m_mpq_lar_core_solver.m_d_heading.push_back(m_mpq_lar_core_solver.m_d_basis.size()); m_mpq_lar_core_solver.m_d_heading.push_back(m_mpq_lar_core_solver.m_d_basis.size());
@ -1501,15 +1501,15 @@ void lar_solver::add_new_var_to_core_fields_for_doubles(bool register_in_basis)
void lar_solver::add_new_var_to_core_fields_for_mpq(bool register_in_basis) { void lar_solver::add_new_var_to_core_fields_for_mpq(bool register_in_basis) {
unsigned j = A_r().column_count(); unsigned j = A_r().column_count();
A_r().add_column(); A_r().add_column();
lean_assert(m_mpq_lar_core_solver.m_r_x.size() == j); lp_assert(m_mpq_lar_core_solver.m_r_x.size() == j);
// lean_assert(m_mpq_lar_core_solver.m_r_low_bounds.size() == j && m_mpq_lar_core_solver.m_r_upper_bounds.size() == j); // restore later // lp_assert(m_mpq_lar_core_solver.m_r_low_bounds.size() == j && m_mpq_lar_core_solver.m_r_upper_bounds.size() == j); // restore later
m_mpq_lar_core_solver.m_r_x.resize(j + 1); m_mpq_lar_core_solver.m_r_x.resize(j + 1);
m_mpq_lar_core_solver.m_r_low_bounds.increase_size_by_one(); m_mpq_lar_core_solver.m_r_low_bounds.increase_size_by_one();
m_mpq_lar_core_solver.m_r_upper_bounds.increase_size_by_one(); m_mpq_lar_core_solver.m_r_upper_bounds.increase_size_by_one();
m_mpq_lar_core_solver.m_r_solver.m_inf_set.increase_size_by_one(); m_mpq_lar_core_solver.m_r_solver.m_inf_set.increase_size_by_one();
m_mpq_lar_core_solver.m_r_solver.m_costs.resize(j + 1); m_mpq_lar_core_solver.m_r_solver.m_costs.resize(j + 1);
m_mpq_lar_core_solver.m_r_solver.m_d.resize(j + 1); m_mpq_lar_core_solver.m_r_solver.m_d.resize(j + 1);
lean_assert(m_mpq_lar_core_solver.m_r_heading.size() == j); // as A().column_count() on the entry to the method lp_assert(m_mpq_lar_core_solver.m_r_heading.size() == j); // as A().column_count() on the entry to the method
if (register_in_basis) { if (register_in_basis) {
A_r().add_row(); A_r().add_row();
m_mpq_lar_core_solver.m_r_heading.push_back(m_mpq_lar_core_solver.m_r_basis.size()); m_mpq_lar_core_solver.m_r_heading.push_back(m_mpq_lar_core_solver.m_r_basis.size());
@ -1544,14 +1544,14 @@ var_index lar_solver::add_term(const vector<std::pair<mpq, var_index>> & coeffs,
if (m_settings.bound_propagation()) if (m_settings.bound_propagation())
m_rows_with_changed_bounds.insert(A_r().row_count() - 1); m_rows_with_changed_bounds.insert(A_r().row_count() - 1);
} }
lean_assert(m_ext_vars_to_columns.size() == A_r().column_count()); lp_assert(m_ext_vars_to_columns.size() == A_r().column_count());
return ret; return ret;
} }
void lar_solver::add_row_for_term(const lar_term * term, unsigned term_ext_index) { void lar_solver::add_row_for_term(const lar_term * term, unsigned term_ext_index) {
lean_assert(sizes_are_correct()); lp_assert(sizes_are_correct());
add_row_from_term_no_constraint(term, term_ext_index); add_row_from_term_no_constraint(term, term_ext_index);
lean_assert(sizes_are_correct()); lp_assert(sizes_are_correct());
} }
void lar_solver::add_row_from_term_no_constraint(const lar_term * term, unsigned term_ext_index) { void lar_solver::add_row_from_term_no_constraint(const lar_term * term, unsigned term_ext_index) {
@ -1577,7 +1577,7 @@ void lar_solver::add_row_from_term_no_constraint(const lar_term * term, unsigned
void lar_solver::add_basic_var_to_core_fields() { void lar_solver::add_basic_var_to_core_fields() {
bool use_lu = m_mpq_lar_core_solver.need_to_presolve_with_double_solver(); bool use_lu = m_mpq_lar_core_solver.need_to_presolve_with_double_solver();
lean_assert(!use_lu || A_r().column_count() == A_d().column_count()); lp_assert(!use_lu || A_r().column_count() == A_d().column_count());
m_mpq_lar_core_solver.m_column_types.push_back(column_type::free_column); m_mpq_lar_core_solver.m_column_types.push_back(column_type::free_column);
m_columns_with_changed_bound.increase_size_by_one(); m_columns_with_changed_bound.increase_size_by_one();
m_rows_with_changed_bounds.increase_size_by_one(); m_rows_with_changed_bounds.increase_size_by_one();
@ -1595,7 +1595,7 @@ bool lar_solver::bound_is_integer_if_needed(unsigned j, const mpq & right_side)
constraint_index lar_solver::add_var_bound(var_index j, lconstraint_kind kind, const mpq & right_side) { constraint_index lar_solver::add_var_bound(var_index j, lconstraint_kind kind, const mpq & right_side) {
constraint_index ci = m_constraints.size(); constraint_index ci = m_constraints.size();
if (!is_term(j)) { // j is a var if (!is_term(j)) { // j is a var
lean_assert(bound_is_integer_if_needed(j, right_side)); lp_assert(bound_is_integer_if_needed(j, right_side));
auto vc = new lar_var_constraint(j, kind, right_side); auto vc = new lar_var_constraint(j, kind, right_side);
m_constraints.push_back(vc); m_constraints.push_back(vc);
update_column_type_and_bound(j, kind, right_side, ci); update_column_type_and_bound(j, kind, right_side, ci);
@ -1603,7 +1603,7 @@ constraint_index lar_solver::add_var_bound(var_index j, lconstraint_kind kind, c
else { else {
add_var_bound_on_constraint_for_term(j, kind, right_side, ci); add_var_bound_on_constraint_for_term(j, kind, right_side, ci);
} }
lean_assert(sizes_are_correct()); lp_assert(sizes_are_correct());
return ci; return ci;
} }
@ -1625,14 +1625,14 @@ void lar_solver::update_column_type_and_bound(var_index j, lconstraint_kind kind
update_fixed_column_type_and_bound(j, kind, right_side, constr_index); update_fixed_column_type_and_bound(j, kind, right_side, constr_index);
break; break;
default: default:
lean_assert(false); // cannot be here lp_assert(false); // cannot be here
} }
} }
void lar_solver::add_var_bound_on_constraint_for_term(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) { void lar_solver::add_var_bound_on_constraint_for_term(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) {
lean_assert(is_term(j)); lp_assert(is_term(j));
unsigned adjusted_term_index = adjust_term_index(j); unsigned adjusted_term_index = adjust_term_index(j);
lean_assert(!term_is_int(m_terms[adjusted_term_index]) || right_side.is_int()); lp_assert(!term_is_int(m_terms[adjusted_term_index]) || right_side.is_int());
auto it = m_ext_vars_to_columns.find(j); auto it = m_ext_vars_to_columns.find(j);
if (it != m_ext_vars_to_columns.end()) { if (it != m_ext_vars_to_columns.end()) {
unsigned term_j = it->second.ext_j(); unsigned term_j = it->second.ext_j();
@ -1662,11 +1662,11 @@ void lar_solver::add_constraint_from_term_and_create_new_column_row(unsigned ter
unsigned j = A_r().column_count() - 1; unsigned j = A_r().column_count() - 1;
update_column_type_and_bound(j, kind, right_side - term->m_v, m_constraints.size()); update_column_type_and_bound(j, kind, right_side - term->m_v, m_constraints.size());
m_constraints.push_back(new lar_term_constraint(term, kind, right_side)); m_constraints.push_back(new lar_term_constraint(term, kind, right_side));
lean_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size()); lp_assert(A_r().column_count() == m_mpq_lar_core_solver.m_r_solver.m_costs.size());
} }
void lar_solver::decide_on_strategy_and_adjust_initial_state() { void lar_solver::decide_on_strategy_and_adjust_initial_state() {
lean_assert(strategy_is_undecided()); lp_assert(strategy_is_undecided());
if (m_vars_to_ul_pairs.size() > m_settings.column_number_threshold_for_using_lu_in_lar_solver) { if (m_vars_to_ul_pairs.size() > m_settings.column_number_threshold_for_using_lu_in_lar_solver) {
m_settings.simplex_strategy() = simplex_strategy_enum::lu; m_settings.simplex_strategy() = simplex_strategy_enum::lu;
} }
@ -1685,7 +1685,7 @@ void lar_solver::adjust_initial_state() {
adjust_initial_state_for_tableau_rows(); adjust_initial_state_for_tableau_rows();
break; break;
case simplex_strategy_enum::tableau_costs: case simplex_strategy_enum::tableau_costs:
lean_assert(false); // not implemented lp_assert(false); // not implemented
case simplex_strategy_enum::undecided: case simplex_strategy_enum::undecided:
adjust_initial_state_for_tableau_rows(); adjust_initial_state_for_tableau_rows();
break; break;
@ -1704,12 +1704,12 @@ void lar_solver::adjust_initial_state_for_lu() {
/* /*
unsigned j = A_d().column_count(); unsigned j = A_d().column_count();
A_d().add_column(); A_d().add_column();
lean_assert(m_mpq_lar_core_solver.m_d_x.size() == j); lp_assert(m_mpq_lar_core_solver.m_d_x.size() == j);
// lean_assert(m_mpq_lar_core_solver.m_d_low_bounds.size() == j && m_mpq_lar_core_solver.m_d_upper_bounds.size() == j); // restore later // lp_assert(m_mpq_lar_core_solver.m_d_low_bounds.size() == j && m_mpq_lar_core_solver.m_d_upper_bounds.size() == j); // restore later
m_mpq_lar_core_solver.m_d_x.resize(j + 1 ); m_mpq_lar_core_solver.m_d_x.resize(j + 1 );
m_mpq_lar_core_solver.m_d_low_bounds.resize(j + 1); m_mpq_lar_core_solver.m_d_low_bounds.resize(j + 1);
m_mpq_lar_core_solver.m_d_upper_bounds.resize(j + 1); m_mpq_lar_core_solver.m_d_upper_bounds.resize(j + 1);
lean_assert(m_mpq_lar_core_solver.m_d_heading.size() == j); // as A().column_count() on the entry to the method lp_assert(m_mpq_lar_core_solver.m_d_heading.size() == j); // as A().column_count() on the entry to the method
if (register_in_basis) { if (register_in_basis) {
A_d().add_row(); A_d().add_row();
m_mpq_lar_core_solver.m_d_heading.push_back(m_mpq_lar_core_solver.m_d_basis.size()); m_mpq_lar_core_solver.m_d_heading.push_back(m_mpq_lar_core_solver.m_d_basis.size());
@ -1730,13 +1730,13 @@ void lar_solver::adjust_initial_state_for_tableau_rows() {
// this fills the last row of A_d and sets the basis column: -1 in the last column of the row // this fills the last row of A_d and sets the basis column: -1 in the last column of the row
void lar_solver::fill_last_row_of_A_d(static_matrix<double, double> & A, const lar_term* ls) { void lar_solver::fill_last_row_of_A_d(static_matrix<double, double> & A, const lar_term* ls) {
lean_assert(A.row_count() > 0); lp_assert(A.row_count() > 0);
lean_assert(A.column_count() > 0); lp_assert(A.column_count() > 0);
unsigned last_row = A.row_count() - 1; unsigned last_row = A.row_count() - 1;
lean_assert(A.m_rows[last_row].empty()); lp_assert(A.m_rows[last_row].empty());
for (auto & t : ls->m_coeffs) { for (auto & t : ls->m_coeffs) {
lean_assert(!is_zero(t.second)); lp_assert(!is_zero(t.second));
var_index j = t.first; var_index j = t.first;
A.set(last_row, j, -t.second.get_double()); A.set(last_row, j, -t.second.get_double());
} }
@ -1752,8 +1752,8 @@ void lar_solver::update_free_column_type_and_bound(var_index j, lconstraint_kind
y_of_bound = -1; y_of_bound = -1;
case LE: case LE:
m_mpq_lar_core_solver.m_column_types[j] = column_type::upper_bound; m_mpq_lar_core_solver.m_column_types[j] = column_type::upper_bound;
lean_assert(m_mpq_lar_core_solver.m_column_types()[j] == column_type::upper_bound); lp_assert(m_mpq_lar_core_solver.m_column_types()[j] == column_type::upper_bound);
lean_assert(m_mpq_lar_core_solver.m_r_upper_bounds.size() > j); lp_assert(m_mpq_lar_core_solver.m_r_upper_bounds.size() > j);
{ {
auto up = numeric_pair<mpq>(right_side, y_of_bound); auto up = numeric_pair<mpq>(right_side, y_of_bound);
m_mpq_lar_core_solver.m_r_upper_bounds[j] = up; m_mpq_lar_core_solver.m_r_upper_bounds[j] = up;
@ -1764,7 +1764,7 @@ void lar_solver::update_free_column_type_and_bound(var_index j, lconstraint_kind
y_of_bound = 1; y_of_bound = 1;
case GE: case GE:
m_mpq_lar_core_solver.m_column_types[j] = column_type::low_bound; m_mpq_lar_core_solver.m_column_types[j] = column_type::low_bound;
lean_assert(m_mpq_lar_core_solver.m_r_upper_bounds.size() > j); lp_assert(m_mpq_lar_core_solver.m_r_upper_bounds.size() > j);
{ {
auto low = numeric_pair<mpq>(right_side, y_of_bound); auto low = numeric_pair<mpq>(right_side, y_of_bound);
m_mpq_lar_core_solver.m_r_low_bounds[j] = low; m_mpq_lar_core_solver.m_r_low_bounds[j] = low;
@ -1779,14 +1779,14 @@ void lar_solver::update_free_column_type_and_bound(var_index j, lconstraint_kind
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
m_columns_with_changed_bound.insert(j); m_columns_with_changed_bound.insert(j);
} }
void lar_solver::update_upper_bound_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) { void lar_solver::update_upper_bound_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) {
lean_assert(m_mpq_lar_core_solver.m_column_types()[j] == column_type::upper_bound); lp_assert(m_mpq_lar_core_solver.m_column_types()[j] == column_type::upper_bound);
mpq y_of_bound(0); mpq y_of_bound(0);
switch (kind) { switch (kind) {
case LT: case LT:
@ -1839,13 +1839,13 @@ void lar_solver::update_upper_bound_column_type_and_bound(var_index j, lconstrai
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
void lar_solver::update_boxed_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) { void lar_solver::update_boxed_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) {
lean_assert(m_status == INFEASIBLE || (m_mpq_lar_core_solver.m_column_types()[j] == column_type::boxed && m_mpq_lar_core_solver.m_r_low_bounds()[j] < m_mpq_lar_core_solver.m_r_upper_bounds()[j])); lp_assert(m_status == INFEASIBLE || (m_mpq_lar_core_solver.m_column_types()[j] == column_type::boxed && m_mpq_lar_core_solver.m_r_low_bounds()[j] < m_mpq_lar_core_solver.m_r_upper_bounds()[j]));
mpq y_of_bound(0); mpq y_of_bound(0);
switch (kind) { switch (kind) {
case LT: case LT:
@ -1861,7 +1861,7 @@ void lar_solver::update_boxed_column_type_and_bound(var_index j, lconstraint_kin
if (up < m_mpq_lar_core_solver.m_r_low_bounds[j]) { if (up < m_mpq_lar_core_solver.m_r_low_bounds[j]) {
m_status = INFEASIBLE; m_status = INFEASIBLE;
lean_assert(false); lp_assert(false);
m_infeasible_column_index = j; m_infeasible_column_index = j;
} }
else { else {
@ -1914,12 +1914,12 @@ void lar_solver::update_boxed_column_type_and_bound(var_index j, lconstraint_kin
} }
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
void lar_solver::update_low_bound_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) { void lar_solver::update_low_bound_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) {
lean_assert(m_mpq_lar_core_solver.m_column_types()[j] == column_type::low_bound); lp_assert(m_mpq_lar_core_solver.m_column_types()[j] == column_type::low_bound);
mpq y_of_bound(0); mpq y_of_bound(0);
switch (kind) { switch (kind) {
case LT: case LT:
@ -1971,14 +1971,14 @@ void lar_solver::update_low_bound_column_type_and_bound(var_index j, lconstraint
} }
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
void lar_solver::update_fixed_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) { void lar_solver::update_fixed_column_type_and_bound(var_index j, lconstraint_kind kind, const mpq & right_side, constraint_index ci) {
lean_assert(m_status == INFEASIBLE || (m_mpq_lar_core_solver.m_column_types()[j] == column_type::fixed && m_mpq_lar_core_solver.m_r_low_bounds()[j] == m_mpq_lar_core_solver.m_r_upper_bounds()[j])); lp_assert(m_status == INFEASIBLE || (m_mpq_lar_core_solver.m_column_types()[j] == column_type::fixed && m_mpq_lar_core_solver.m_r_low_bounds()[j] == m_mpq_lar_core_solver.m_r_upper_bounds()[j]));
lean_assert(m_status == INFEASIBLE || (m_mpq_lar_core_solver.m_r_low_bounds()[j].y.is_zero() && m_mpq_lar_core_solver.m_r_upper_bounds()[j].y.is_zero())); lp_assert(m_status == INFEASIBLE || (m_mpq_lar_core_solver.m_r_low_bounds()[j].y.is_zero() && m_mpq_lar_core_solver.m_r_upper_bounds()[j].y.is_zero()));
auto v = numeric_pair<mpq>(right_side, mpq(0)); auto v = numeric_pair<mpq>(right_side, mpq(0));
mpq y_of_bound(0); mpq y_of_bound(0);
@ -2033,12 +2033,12 @@ void lar_solver::update_fixed_column_type_and_bound(var_index j, lconstraint_kin
} }
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
} // namespace lean } // namespace lp

View file

@ -33,7 +33,7 @@
#include "util/lp/int_solver.h" #include "util/lp/int_solver.h"
#include "util/lp/nra_solver.h" #include "util/lp/nra_solver.h"
namespace lean { namespace lp {
class lar_solver : public column_namer { class lar_solver : public column_namer {
@ -222,7 +222,7 @@ public:
vector<unsigned> get_list_of_all_var_indices() const; vector<unsigned> get_list_of_all_var_indices() const;
void push(); void push();
static void clean_large_elements_after_pop(unsigned n, int_set& set); static void clp_large_elements_after_pop(unsigned n, int_set& set);
static void shrink_inf_set_after_pop(unsigned n, int_set & set); static void shrink_inf_set_after_pop(unsigned n, int_set & set);
@ -403,7 +403,7 @@ public:
void remove_last_column_from_basis_tableau(unsigned j); void remove_last_column_from_basis_tableau(unsigned j);
void remove_column_from_tableau(unsigned j); void remove_column_from_tableau(unsigned j);
void pop_tableau(); void pop_tableau();
void clean_inf_set_of_r_solver_after_pop(); void clp_inf_set_of_r_solver_after_pop();
void shrink_explanation_to_minimum(vector<std::pair<mpq, constraint_index>> & explanation) const; void shrink_explanation_to_minimum(vector<std::pair<mpq, constraint_index>> & explanation) const;

View file

@ -5,7 +5,7 @@
#include "util/lp/lar_solver.cpp" #include "util/lp/lar_solver.cpp"
template void lean::lar_solver::copy_from_mpq_matrix<double,double>(class lean::static_matrix<double,double> &); template void lp::lar_solver::copy_from_mpq_matrix<double,double>(class lp::static_matrix<double,double> &);

View file

@ -4,7 +4,7 @@
*/ */
#pragma once #pragma once
#include "util/lp/indexed_vector.h" #include "util/lp/indexed_vector.h"
namespace lean { namespace lp {
struct lar_term { struct lar_term {
// the term evaluates to sum of m_coeffs + m_v // the term evaluates to sum of m_coeffs + m_v
std::unordered_map<unsigned, mpq> m_coeffs; std::unordered_map<unsigned, mpq> m_coeffs;

View file

@ -3,7 +3,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#pragma once #pragma once
namespace lean { namespace lp {
template <typename T> template <typename T>
struct linear_combination_iterator { struct linear_combination_iterator {
virtual bool next(T & a, unsigned & i) = 0; virtual bool next(T & a, unsigned & i) = 0;

View file

@ -16,7 +16,7 @@
#include "util/lp/iterator_on_row.h" #include "util/lp/iterator_on_row.h"
#include "util/lp/iterator_on_pivot_row.h" #include "util/lp/iterator_on_pivot_row.h"
namespace lean { namespace lp {
template <typename T, typename X> // X represents the type of the x variable and the bounds template <typename T, typename X> // X represents the type of the x variable and the bounds
class lp_core_solver_base { class lp_core_solver_base {
@ -185,11 +185,11 @@ public:
bool need_to_pivot_to_basis_tableau() const { bool need_to_pivot_to_basis_tableau() const {
lean_assert(m_A.is_correct()); lp_assert(m_A.is_correct());
unsigned m = m_A.row_count(); unsigned m = m_A.row_count();
for (unsigned i = 0; i < m; i++) { for (unsigned i = 0; i < m; i++) {
unsigned bj = m_basis[i]; unsigned bj = m_basis[i];
lean_assert(m_A.m_columns[bj].size() > 0); lp_assert(m_A.m_columns[bj].size() > 0);
if (m_A.m_columns[bj].size() > 1 || m_A.get_val(m_A.m_columns[bj][0]) != one_of_type<mpq>()) return true; if (m_A.m_columns[bj].size() > 1 || m_A.get_val(m_A.m_columns[bj][0]) != one_of_type<mpq>()) return true;
} }
return false; return false;
@ -198,7 +198,7 @@ public:
bool reduced_costs_are_correct_tableau() const { bool reduced_costs_are_correct_tableau() const {
if (m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows) if (m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows)
return true; return true;
lean_assert(m_A.is_correct()); lp_assert(m_A.is_correct());
if (m_using_infeas_costs) { if (m_using_infeas_costs) {
if (infeasibility_costs_are_correct() == false) { if (infeasibility_costs_are_correct() == false) {
std::cout << "infeasibility_costs_are_correct() does not hold" << std::endl; std::cout << "infeasibility_costs_are_correct() does not hold" << std::endl;
@ -373,11 +373,11 @@ public:
} }
bool make_column_feasible(unsigned j, numeric_pair<mpq> & delta) { bool make_column_feasible(unsigned j, numeric_pair<mpq> & delta) {
lean_assert(m_basis_heading[j] < 0); lp_assert(m_basis_heading[j] < 0);
auto & x = m_x[j]; auto & x = m_x[j];
switch (m_column_types[j]) { switch (m_column_types[j]) {
case column_type::fixed: case column_type::fixed:
lean_assert(m_low_bounds[j] == m_upper_bounds[j]); lp_assert(m_low_bounds[j] == m_upper_bounds[j]);
if (x != m_low_bounds[j]) { if (x != m_low_bounds[j]) {
delta = m_low_bounds[j] - x; delta = m_low_bounds[j] - x;
x = m_low_bounds[j]; x = m_low_bounds[j];
@ -413,7 +413,7 @@ public:
case column_type::free_column: case column_type::free_column:
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
return false; return false;
@ -462,7 +462,7 @@ public:
} }
void change_basis_unconditionally(unsigned entering, unsigned leaving) { void change_basis_unconditionally(unsigned entering, unsigned leaving) {
lean_assert(m_basis_heading[entering] < 0); lp_assert(m_basis_heading[entering] < 0);
int place_in_non_basis = -1 - m_basis_heading[entering]; int place_in_non_basis = -1 - m_basis_heading[entering];
if (static_cast<unsigned>(place_in_non_basis) >= m_nbasis.size()) { if (static_cast<unsigned>(place_in_non_basis) >= m_nbasis.size()) {
// entering variable in not in m_nbasis, we need to put it back; // entering variable in not in m_nbasis, we need to put it back;
@ -481,8 +481,8 @@ public:
} }
void change_basis(unsigned entering, unsigned leaving) { void change_basis(unsigned entering, unsigned leaving) {
lean_assert(m_basis_heading[entering] < 0); lp_assert(m_basis_heading[entering] < 0);
lean_assert(m_basis_heading[leaving] >= 0); lp_assert(m_basis_heading[leaving] >= 0);
int place_in_basis = m_basis_heading[leaving]; int place_in_basis = m_basis_heading[leaving];
int place_in_non_basis = - m_basis_heading[entering] - 1; int place_in_non_basis = - m_basis_heading[entering] - 1;
@ -523,7 +523,7 @@ public:
case column_type::free_column: case column_type::free_column:
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
return true; return true;
@ -571,7 +571,7 @@ public:
case column_type::free_column: case column_type::free_column:
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
out << "basis heading = " << m_basis_heading[j] << std::endl; out << "basis heading = " << m_basis_heading[j] << std::endl;
out << "x = " << m_x[j] << std::endl; out << "x = " << m_x[j] << std::endl;
@ -670,17 +670,17 @@ public:
} }
void insert_column_into_inf_set(unsigned j) { void insert_column_into_inf_set(unsigned j) {
m_inf_set.insert(j); m_inf_set.insert(j);
lean_assert(!column_is_feasible(j)); lp_assert(!column_is_feasible(j));
} }
void remove_column_from_inf_set(unsigned j) { void remove_column_from_inf_set(unsigned j) {
m_inf_set.erase(j); m_inf_set.erase(j);
lean_assert(column_is_feasible(j)); lp_assert(column_is_feasible(j));
} }
bool costs_on_nbasis_are_zeros() const { bool costs_on_nbasis_are_zeros() const {
lean_assert(this->basis_heading_is_correct()); lp_assert(this->basis_heading_is_correct());
for (unsigned j = 0; j < this->m_n(); j++) { for (unsigned j = 0; j < this->m_n(); j++) {
if (this->m_basis_heading[j] < 0) if (this->m_basis_heading[j] < 0)
lean_assert(is_zero(this->m_costs[j])); lp_assert(is_zero(this->m_costs[j]));
} }
return true; return true;
} }

View file

@ -7,7 +7,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/lp_core_solver_base.h" #include "util/lp/lp_core_solver_base.h"
namespace lean { namespace lp {
template <typename T, typename X> lp_core_solver_base<T, X>:: template <typename T, typename X> lp_core_solver_base<T, X>::
lp_core_solver_base(static_matrix<T, X> & A, lp_core_solver_base(static_matrix<T, X> & A,
@ -53,7 +53,7 @@ lp_core_solver_base(static_matrix<T, X> & A,
m_tracing_basis_changes(false), m_tracing_basis_changes(false),
m_pivoted_rows(nullptr), m_pivoted_rows(nullptr),
m_look_for_feasible_solution_only(false) { m_look_for_feasible_solution_only(false) {
lean_assert(bounds_for_boxed_are_set_correctly()); lp_assert(bounds_for_boxed_are_set_correctly());
init(); init();
init_basis_heading_and_non_basic_columns_vector(); init_basis_heading_and_non_basic_columns_vector();
} }
@ -61,7 +61,7 @@ lp_core_solver_base(static_matrix<T, X> & A,
template <typename T, typename X> void lp_core_solver_base<T, X>:: template <typename T, typename X> void lp_core_solver_base<T, X>::
allocate_basis_heading() { // the rest of initilization will be handled by the factorization class allocate_basis_heading() { // the rest of initilization will be handled by the factorization class
init_basis_heading_and_non_basic_columns_vector(); init_basis_heading_and_non_basic_columns_vector();
lean_assert(basis_heading_is_correct()); lp_assert(basis_heading_is_correct());
} }
template <typename T, typename X> void lp_core_solver_base<T, X>:: template <typename T, typename X> void lp_core_solver_base<T, X>::
init() { init() {
@ -127,7 +127,7 @@ solve_yB(vector<T> & y) {
// } // }
// } // }
template <typename T, typename X> void lp_core_solver_base<T, X>::solve_Bd(unsigned entering, indexed_vector<T> & column) { template <typename T, typename X> void lp_core_solver_base<T, X>::solve_Bd(unsigned entering, indexed_vector<T> & column) {
lean_assert(!m_settings.use_tableau()); lp_assert(!m_settings.use_tableau());
if (m_factorization == nullptr) { if (m_factorization == nullptr) {
init_factorization(m_factorization, m_A, m_basis, m_settings); init_factorization(m_factorization, m_A, m_basis, m_settings);
} }
@ -137,19 +137,19 @@ template <typename T, typename X> void lp_core_solver_base<T, X>::solve_Bd(unsig
template <typename T, typename X> void lp_core_solver_base<T, X>:: template <typename T, typename X> void lp_core_solver_base<T, X>::
solve_Bd(unsigned entering) { solve_Bd(unsigned entering) {
lean_assert(m_ed.is_OK()); lp_assert(m_ed.is_OK());
m_factorization->solve_Bd(entering, m_ed, m_w); m_factorization->solve_Bd(entering, m_ed, m_w);
if (this->precise()) if (this->precise())
m_columns_nz[entering] = m_ed.m_index.size(); m_columns_nz[entering] = m_ed.m_index.size();
lean_assert(m_ed.is_OK()); lp_assert(m_ed.is_OK());
lean_assert(m_w.is_OK()); lp_assert(m_w.is_OK());
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// auto B = get_B(*m_factorization, m_basis); // auto B = get_B(*m_factorization, m_basis);
// vector<T> a(m_m()); // vector<T> a(m_m());
// m_A.copy_column_to_vector(entering, a); // m_A.copy_column_to_vector(entering, a);
// vector<T> cd(m_ed.m_data); // vector<T> cd(m_ed.m_data);
// B.apply_from_left(cd, m_settings); // B.apply_from_left(cd, m_settings);
// lean_assert(vectors_are_equal(cd , a)); // lp_assert(vectors_are_equal(cd , a));
#endif #endif
} }
@ -208,7 +208,7 @@ restore_m_ed(T * buffer) {
template <typename T, typename X> bool lp_core_solver_base<T, X>:: template <typename T, typename X> bool lp_core_solver_base<T, X>::
A_mult_x_is_off() const { A_mult_x_is_off() const {
lean_assert(m_x.size() == m_A.column_count()); lp_assert(m_x.size() == m_A.column_count());
if (numeric_traits<T>::precise()) { if (numeric_traits<T>::precise()) {
for (unsigned i = 0; i < m_m(); i++) { for (unsigned i = 0; i < m_m(); i++) {
X delta = m_b[i] - m_A.dot_product_with_row(i, m_x); X delta = m_b[i] - m_A.dot_product_with_row(i, m_x);
@ -244,7 +244,7 @@ A_mult_x_is_off() const {
} }
template <typename T, typename X> bool lp_core_solver_base<T, X>:: template <typename T, typename X> bool lp_core_solver_base<T, X>::
A_mult_x_is_off_on_index(const vector<unsigned> & index) const { A_mult_x_is_off_on_index(const vector<unsigned> & index) const {
lean_assert(m_x.size() == m_A.column_count()); lp_assert(m_x.size() == m_A.column_count());
if (numeric_traits<T>::precise()) return false; if (numeric_traits<T>::precise()) return false;
#if RUN_A_MULT_X_IS_OFF_FOR_PRECESE #if RUN_A_MULT_X_IS_OFF_FOR_PRECESE
for (unsigned i : index) { for (unsigned i : index) {
@ -284,13 +284,13 @@ A_mult_x_is_off_on_index(const vector<unsigned> & index) const {
// from page 182 of Istvan Maros's book // from page 182 of Istvan Maros's book
template <typename T, typename X> void lp_core_solver_base<T, X>:: template <typename T, typename X> void lp_core_solver_base<T, X>::
calculate_pivot_row_of_B_1(unsigned pivot_row) { calculate_pivot_row_of_B_1(unsigned pivot_row) {
lean_assert(! use_tableau()); lp_assert(! use_tableau());
lean_assert(m_pivot_row_of_B_1.is_OK()); lp_assert(m_pivot_row_of_B_1.is_OK());
m_pivot_row_of_B_1.clear(); m_pivot_row_of_B_1.clear();
m_pivot_row_of_B_1.set_value(numeric_traits<T>::one(), pivot_row); m_pivot_row_of_B_1.set_value(numeric_traits<T>::one(), pivot_row);
lean_assert(m_pivot_row_of_B_1.is_OK()); lp_assert(m_pivot_row_of_B_1.is_OK());
m_factorization->solve_yB_with_error_check_indexed(m_pivot_row_of_B_1, m_basis_heading, m_basis, m_settings); m_factorization->solve_yB_with_error_check_indexed(m_pivot_row_of_B_1, m_basis_heading, m_basis, m_settings);
lean_assert(m_pivot_row_of_B_1.is_OK()); lp_assert(m_pivot_row_of_B_1.is_OK());
} }
@ -380,11 +380,11 @@ set_non_basic_x_to_correct_bounds() {
break; break;
case column_type::low_bound: case column_type::low_bound:
m_x[j] = m_low_bounds[j]; m_x[j] = m_low_bounds[j];
lean_assert(column_is_dual_feasible(j)); lp_assert(column_is_dual_feasible(j));
break; break;
case column_type::upper_bound: case column_type::upper_bound:
m_x[j] = m_upper_bounds[j]; m_x[j] = m_upper_bounds[j];
lean_assert(column_is_dual_feasible(j)); lp_assert(column_is_dual_feasible(j));
break; break;
default: default:
break; break;
@ -402,15 +402,15 @@ column_is_dual_feasible(unsigned j) const {
return x_is_at_low_bound(j) && d_is_not_negative(j); return x_is_at_low_bound(j) && d_is_not_negative(j);
case column_type::upper_bound: case column_type::upper_bound:
LP_OUT(m_settings, "upper_bound type should be switched to low_bound" << std::endl); LP_OUT(m_settings, "upper_bound type should be switched to low_bound" << std::endl);
lean_assert(false); // impossible case lp_assert(false); // impossible case
case column_type::free_column: case column_type::free_column:
return numeric_traits<X>::is_zero(m_d[j]); return numeric_traits<X>::is_zero(m_d[j]);
default: default:
LP_OUT(m_settings, "column = " << j << std::endl); LP_OUT(m_settings, "column = " << j << std::endl);
LP_OUT(m_settings, "unexpected column type = " << column_type_to_string(m_column_types[j]) << std::endl); LP_OUT(m_settings, "unexpected column type = " << column_type_to_string(m_column_types[j]) << std::endl);
lean_unreachable(); lp_unreachable();
} }
lean_unreachable(); lp_unreachable();
return false; return false;
} }
template <typename T, typename X> bool lp_core_solver_base<T, X>:: template <typename T, typename X> bool lp_core_solver_base<T, X>::
@ -493,7 +493,7 @@ template <typename T, typename X> bool lp_core_solver_base<T, X>::column_is_feas
return true; return true;
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
return false; // it is unreachable return false; // it is unreachable
} }
@ -575,7 +575,7 @@ update_basis_and_x(int entering, int leaving, X const & tt) {
restore_x_and_refactor(entering, leaving, tt); restore_x_and_refactor(entering, leaving, tt);
if (m_status == FLOATING_POINT_ERROR) if (m_status == FLOATING_POINT_ERROR)
return false; return false;
lean_assert(!A_mult_x_is_off()); lp_assert(!A_mult_x_is_off());
m_iters_with_no_cost_growing++; m_iters_with_no_cost_growing++;
// LP_OUT(m_settings, "rolled back after failing of init_factorization()" << std::endl); // LP_OUT(m_settings, "rolled back after failing of init_factorization()" << std::endl);
m_status = UNSTABLE; m_status = UNSTABLE;
@ -587,7 +587,7 @@ update_basis_and_x(int entering, int leaving, X const & tt) {
template <typename T, typename X> bool lp_core_solver_base<T, X>:: template <typename T, typename X> bool lp_core_solver_base<T, X>::
divide_row_by_pivot(unsigned pivot_row, unsigned pivot_col) { divide_row_by_pivot(unsigned pivot_row, unsigned pivot_col) {
lean_assert(numeric_traits<T>::precise()); lp_assert(numeric_traits<T>::precise());
int pivot_index = -1; int pivot_index = -1;
auto & row = m_A.m_rows[pivot_row]; auto & row = m_A.m_rows[pivot_row];
unsigned size = row.size(); unsigned size = row.size();
@ -628,7 +628,7 @@ pivot_column_tableau(unsigned j, unsigned piv_row_index) {
return false; return false;
if (pivot_col_cell_index != 0) { if (pivot_col_cell_index != 0) {
lean_assert(column.size() > 1); lp_assert(column.size() > 1);
// swap the pivot column cell with the head cell // swap the pivot column cell with the head cell
auto c = column[0]; auto c = column[0];
column[0] = column[pivot_col_cell_index]; column[0] = column[pivot_col_cell_index];
@ -639,7 +639,7 @@ pivot_column_tableau(unsigned j, unsigned piv_row_index) {
} }
while (column.size() > 1) { while (column.size() > 1) {
auto & c = column.back(); auto & c = column.back();
lean_assert(c.m_i != piv_row_index); lp_assert(c.m_i != piv_row_index);
if(! m_A.pivot_row_to_row_given_cell(piv_row_index, c, j)) { if(! m_A.pivot_row_to_row_given_cell(piv_row_index, c, j)) {
return false; return false;
} }
@ -687,7 +687,7 @@ non_basis_is_correctly_represented_in_heading() const {
} }
for (unsigned j = 0; j < m_A.column_count(); j++) { for (unsigned j = 0; j < m_A.column_count(); j++) {
if (m_basis_heading[j] >= 0) { if (m_basis_heading[j] >= 0) {
lean_assert(static_cast<unsigned>(m_basis_heading[j]) < m_A.row_count() && m_basis[m_basis_heading[j]] == j); lp_assert(static_cast<unsigned>(m_basis_heading[j]) < m_A.row_count() && m_basis[m_basis_heading[j]] == j);
} }
} }
return true; return true;
@ -695,9 +695,9 @@ non_basis_is_correctly_represented_in_heading() const {
template <typename T, typename X> bool lp_core_solver_base<T, X>:: template <typename T, typename X> bool lp_core_solver_base<T, X>::
basis_heading_is_correct() const { basis_heading_is_correct() const {
lean_assert(m_basis_heading.size() == m_A.column_count()); lp_assert(m_basis_heading.size() == m_A.column_count());
lean_assert(m_basis.size() == m_A.row_count()); lp_assert(m_basis.size() == m_A.row_count());
lean_assert(m_nbasis.size() <= m_A.column_count() - m_A.row_count()); // for the dual the size of non basis can be smaller lp_assert(m_nbasis.size() <= m_A.column_count() - m_A.row_count()); // for the dual the size of non basis can be smaller
if (!basis_has_no_doubles()) { if (!basis_has_no_doubles()) {
// std::cout << "basis_has_no_doubles" << std::endl; // std::cout << "basis_has_no_doubles" << std::endl;
return false; return false;
@ -841,7 +841,7 @@ solve_Ax_eq_b() {
template <typename T, typename X> void lp_core_solver_base<T, X>:: template <typename T, typename X> void lp_core_solver_base<T, X>::
snap_non_basic_x_to_bound_and_free_to_zeroes() { snap_non_basic_x_to_bound_and_free_to_zeroes() {
for (unsigned j : non_basis()) { for (unsigned j : non_basis()) {
lean_assert(j < m_x.size()); lp_assert(j < m_x.size());
switch (m_column_types[j]) { switch (m_column_types[j]) {
case column_type::fixed: case column_type::fixed:
case column_type::boxed: case column_type::boxed:
@ -892,9 +892,9 @@ get_non_basic_column_value_position(unsigned j) const {
case column_type::upper_bound: case column_type::upper_bound:
return x_is_at_upper_bound(j)? at_upper_bound : not_at_bound; return x_is_at_upper_bound(j)? at_upper_bound : not_at_bound;
default: default:
lean_unreachable(); lp_unreachable();
} }
lean_unreachable(); lp_unreachable();
return at_low_bound; return at_low_bound;
} }
@ -925,8 +925,8 @@ template <typename T, typename X> void lp_core_solver_base<T, X>::transpose_row
} }
// j is the new basic column, j_basic - the leaving column // j is the new basic column, j_basic - the leaving column
template <typename T, typename X> bool lp_core_solver_base<T, X>::pivot_column_general(unsigned j, unsigned j_basic, indexed_vector<T> & w) { template <typename T, typename X> bool lp_core_solver_base<T, X>::pivot_column_general(unsigned j, unsigned j_basic, indexed_vector<T> & w) {
lean_assert(m_basis_heading[j] < 0); lp_assert(m_basis_heading[j] < 0);
lean_assert(m_basis_heading[j_basic] >= 0); lp_assert(m_basis_heading[j_basic] >= 0);
unsigned row_index = m_basis_heading[j_basic]; unsigned row_index = m_basis_heading[j_basic];
if (m_settings.m_simplex_strategy == simplex_strategy_enum::lu) { if (m_settings.m_simplex_strategy == simplex_strategy_enum::lu) {
if (m_factorization->need_to_refactor()) { if (m_factorization->need_to_refactor()) {
@ -980,7 +980,7 @@ template <typename T, typename X> bool
lp_core_solver_base<T, X>::infeasibility_costs_are_correct() const { lp_core_solver_base<T, X>::infeasibility_costs_are_correct() const {
if (! this->m_using_infeas_costs) if (! this->m_using_infeas_costs)
return true; return true;
lean_assert(costs_on_nbasis_are_zeros()); lp_assert(costs_on_nbasis_are_zeros());
for (unsigned j :this->m_basis) { for (unsigned j :this->m_basis) {
if (!infeasibility_cost_is_correct_for_column(j)) { if (!infeasibility_cost_is_correct_for_column(j)) {
std::cout << "infeasibility_cost_is_correct_for_column does not hold\n"; std::cout << "infeasibility_cost_is_correct_for_column does not hold\n";
@ -1025,15 +1025,15 @@ lp_core_solver_base<T, X>::infeasibility_cost_is_correct_for_column(unsigned j)
case column_type::free_column: case column_type::free_column:
return is_zero(this->m_costs[j]); return is_zero(this->m_costs[j]);
default: default:
lean_assert(false); lp_assert(false);
return true; return true;
} }
} }
template <typename T, typename X> template <typename T, typename X>
void lp_core_solver_base<T, X>::calculate_pivot_row(unsigned i) { void lp_core_solver_base<T, X>::calculate_pivot_row(unsigned i) {
lean_assert(!use_tableau()); lp_assert(!use_tableau());
lean_assert(m_pivot_row.is_OK()); lp_assert(m_pivot_row.is_OK());
m_pivot_row_of_B_1.clear(); m_pivot_row_of_B_1.clear();
m_pivot_row_of_B_1.resize(m_m()); m_pivot_row_of_B_1.resize(m_m());
m_pivot_row.clear(); m_pivot_row.clear();

View file

@ -8,125 +8,125 @@
#include "util/vector.h" #include "util/vector.h"
#include <functional> #include <functional>
#include "util/lp/lp_core_solver_base.hpp" #include "util/lp/lp_core_solver_base.hpp"
template bool lean::lp_core_solver_base<double, double>::A_mult_x_is_off() const; template bool lp::lp_core_solver_base<double, double>::A_mult_x_is_off() const;
template bool lean::lp_core_solver_base<double, double>::A_mult_x_is_off_on_index(const vector<unsigned> &) const; template bool lp::lp_core_solver_base<double, double>::A_mult_x_is_off_on_index(const vector<unsigned> &) const;
template bool lean::lp_core_solver_base<double, double>::basis_heading_is_correct() const; template bool lp::lp_core_solver_base<double, double>::basis_heading_is_correct() const;
template void lean::lp_core_solver_base<double, double>::calculate_pivot_row_of_B_1(unsigned int); template void lp::lp_core_solver_base<double, double>::calculate_pivot_row_of_B_1(unsigned int);
template void lean::lp_core_solver_base<double, double>::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned); template void lp::lp_core_solver_base<double, double>::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned);
template bool lean::lp_core_solver_base<double, double>::column_is_dual_feasible(unsigned int) const; template bool lp::lp_core_solver_base<double, double>::column_is_dual_feasible(unsigned int) const;
template void lean::lp_core_solver_base<double, double>::fill_reduced_costs_from_m_y_by_rows(); template void lp::lp_core_solver_base<double, double>::fill_reduced_costs_from_m_y_by_rows();
template bool lean::lp_core_solver_base<double, double>::find_x_by_solving(); template bool lp::lp_core_solver_base<double, double>::find_x_by_solving();
template lean::non_basic_column_value_position lean::lp_core_solver_base<double, double>::get_non_basic_column_value_position(unsigned int) const; template lp::non_basic_column_value_position lp::lp_core_solver_base<double, double>::get_non_basic_column_value_position(unsigned int) const;
template lean::non_basic_column_value_position lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::get_non_basic_column_value_position(unsigned int) const; template lp::non_basic_column_value_position lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::get_non_basic_column_value_position(unsigned int) const;
template lean::non_basic_column_value_position lean::lp_core_solver_base<lean::mpq, lean::mpq>::get_non_basic_column_value_position(unsigned int) const; template lp::non_basic_column_value_position lp::lp_core_solver_base<lp::mpq, lp::mpq>::get_non_basic_column_value_position(unsigned int) const;
template void lean::lp_core_solver_base<double, double>::init_reduced_costs_for_one_iteration(); template void lp::lp_core_solver_base<double, double>::init_reduced_costs_for_one_iteration();
template lean::lp_core_solver_base<double, double>::lp_core_solver_base( template lp::lp_core_solver_base<double, double>::lp_core_solver_base(
lean::static_matrix<double, double>&, vector<double>&, lp::static_matrix<double, double>&, vector<double>&,
vector<unsigned int >&, vector<unsigned int >&,
vector<unsigned> &, vector<int> &, vector<unsigned> &, vector<int> &,
vector<double >&, vector<double >&,
vector<double >&, vector<double >&,
lean::lp_settings&, const column_namer&, const vector<lean::column_type >&, lp::lp_settings&, const column_namer&, const vector<lp::column_type >&,
const vector<double >&, const vector<double >&,
const vector<double >&); const vector<double >&);
template bool lean::lp_core_solver_base<double, double>::print_statistics_with_iterations_and_nonzeroes_and_cost_and_check_that_the_time_is_over(char const*, std::ostream &); template bool lp::lp_core_solver_base<double, double>::print_statistics_with_iterations_and_nonzeroes_and_cost_and_check_that_the_time_is_over(char const*, std::ostream &);
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::print_statistics_with_iterations_and_nonzeroes_and_cost_and_check_that_the_time_is_over(char const*, std::ostream &); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::print_statistics_with_iterations_and_nonzeroes_and_cost_and_check_that_the_time_is_over(char const*, std::ostream &);
template void lean::lp_core_solver_base<double, double>::restore_x(unsigned int, double const&); template void lp::lp_core_solver_base<double, double>::restore_x(unsigned int, double const&);
template void lean::lp_core_solver_base<double, double>::set_non_basic_x_to_correct_bounds(); template void lp::lp_core_solver_base<double, double>::set_non_basic_x_to_correct_bounds();
template void lean::lp_core_solver_base<double, double>::snap_xN_to_bounds_and_free_columns_to_zeroes(); template void lp::lp_core_solver_base<double, double>::snap_xN_to_bounds_and_free_columns_to_zeroes();
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::snap_xN_to_bounds_and_free_columns_to_zeroes(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::snap_xN_to_bounds_and_free_columns_to_zeroes();
template void lean::lp_core_solver_base<double, double>::solve_Ax_eq_b(); template void lp::lp_core_solver_base<double, double>::solve_Ax_eq_b();
template void lean::lp_core_solver_base<double, double>::solve_Bd(unsigned int); template void lp::lp_core_solver_base<double, double>::solve_Bd(unsigned int);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq>>::solve_Bd(unsigned int, indexed_vector<lean::mpq>&); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq>>::solve_Bd(unsigned int, indexed_vector<lp::mpq>&);
template void lean::lp_core_solver_base<double, double>::solve_yB(vector<double >&); template void lp::lp_core_solver_base<double, double>::solve_yB(vector<double >&);
template bool lean::lp_core_solver_base<double, double>::update_basis_and_x(int, int, double const&); template bool lp::lp_core_solver_base<double, double>::update_basis_and_x(int, int, double const&);
template void lean::lp_core_solver_base<double, double>::update_x(unsigned int, const double&); template void lp::lp_core_solver_base<double, double>::update_x(unsigned int, const double&);
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::A_mult_x_is_off() const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::A_mult_x_is_off() const;
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::A_mult_x_is_off_on_index(const vector<unsigned> &) const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::A_mult_x_is_off_on_index(const vector<unsigned> &) const;
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::basis_heading_is_correct() const ; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::basis_heading_is_correct() const ;
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::calculate_pivot_row_of_B_1(unsigned int); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::calculate_pivot_row_of_B_1(unsigned int);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned);
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::column_is_dual_feasible(unsigned int) const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::column_is_dual_feasible(unsigned int) const;
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::fill_reduced_costs_from_m_y_by_rows(); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::fill_reduced_costs_from_m_y_by_rows();
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::find_x_by_solving(); template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::find_x_by_solving();
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::init_reduced_costs_for_one_iteration(); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::init_reduced_costs_for_one_iteration();
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::print_statistics_with_iterations_and_nonzeroes_and_cost_and_check_that_the_time_is_over(char const*, std::ostream &); template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::print_statistics_with_iterations_and_nonzeroes_and_cost_and_check_that_the_time_is_over(char const*, std::ostream &);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::restore_x(unsigned int, lean::mpq const&); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::restore_x(unsigned int, lp::mpq const&);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::set_non_basic_x_to_correct_bounds(); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::set_non_basic_x_to_correct_bounds();
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::solve_Ax_eq_b(); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::solve_Ax_eq_b();
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::solve_Bd(unsigned int); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::solve_Bd(unsigned int);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::solve_yB(vector<lean::mpq>&); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::solve_yB(vector<lp::mpq>&);
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::update_basis_and_x(int, int, lean::mpq const&); template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::update_basis_and_x(int, int, lp::mpq const&);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::update_x(unsigned int, const lean::mpq&); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::update_x(unsigned int, const lp::mpq&);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::calculate_pivot_row_of_B_1(unsigned int); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::calculate_pivot_row_of_B_1(unsigned int);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::calculate_pivot_row_when_pivot_row_of_B1_is_ready(unsigned);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::init(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::init();
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::init_basis_heading_and_non_basic_columns_vector(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::init_basis_heading_and_non_basic_columns_vector();
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::init_reduced_costs_for_one_iteration(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::init_reduced_costs_for_one_iteration();
template lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::lp_core_solver_base(lean::static_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&, vector<lean::numeric_pair<lean::mpq> >&, vector<unsigned int >&, vector<unsigned> &, vector<int> &, vector<lean::numeric_pair<lean::mpq> >&, vector<lean::mpq>&, lean::lp_settings&, const column_namer&, const vector<lean::column_type >&, template lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::lp_core_solver_base(lp::static_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&, vector<lp::numeric_pair<lp::mpq> >&, vector<unsigned int >&, vector<unsigned> &, vector<int> &, vector<lp::numeric_pair<lp::mpq> >&, vector<lp::mpq>&, lp::lp_settings&, const column_namer&, const vector<lp::column_type >&,
const vector<lean::numeric_pair<lean::mpq> >&, const vector<lp::numeric_pair<lp::mpq> >&,
const vector<lean::numeric_pair<lean::mpq> >&); const vector<lp::numeric_pair<lp::mpq> >&);
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::print_statistics_with_cost_and_check_that_the_time_is_over(lean::numeric_pair<lean::mpq>, std::ostream&); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::print_statistics_with_cost_and_check_that_the_time_is_over(lp::numeric_pair<lp::mpq>, std::ostream&);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::snap_xN_to_bounds_and_fill_xB(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::snap_xN_to_bounds_and_fill_xB();
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_Bd(unsigned int); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_Bd(unsigned int);
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::update_basis_and_x(int, int, lean::numeric_pair<lean::mpq> const&); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::update_basis_and_x(int, int, lp::numeric_pair<lp::mpq> const&);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::update_x(unsigned int, const lean::numeric_pair<lean::mpq>&); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::update_x(unsigned int, const lp::numeric_pair<lp::mpq>&);
template lean::lp_core_solver_base<lean::mpq, lean::mpq>::lp_core_solver_base( template lp::lp_core_solver_base<lp::mpq, lp::mpq>::lp_core_solver_base(
lean::static_matrix<lean::mpq, lean::mpq>&, lp::static_matrix<lp::mpq, lp::mpq>&,
vector<lean::mpq>&, vector<lp::mpq>&,
vector<unsigned int >&, vector<unsigned int >&,
vector<unsigned> &, vector<int> &, vector<unsigned> &, vector<int> &,
vector<lean::mpq>&, vector<lp::mpq>&,
vector<lean::mpq>&, vector<lp::mpq>&,
lean::lp_settings&, lp::lp_settings&,
const column_namer&, const column_namer&,
const vector<lean::column_type >&, const vector<lp::column_type >&,
const vector<lean::mpq>&, const vector<lp::mpq>&,
const vector<lean::mpq>&); const vector<lp::mpq>&);
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::print_statistics_with_iterations_and_check_that_the_time_is_over(std::ostream &); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::print_statistics_with_iterations_and_check_that_the_time_is_over(std::ostream &);
template std::string lean::lp_core_solver_base<double, double>::column_name(unsigned int) const; template std::string lp::lp_core_solver_base<double, double>::column_name(unsigned int) const;
template void lean::lp_core_solver_base<double, double>::pretty_print(std::ostream & out); template void lp::lp_core_solver_base<double, double>::pretty_print(std::ostream & out);
template void lean::lp_core_solver_base<double, double>::restore_state(double*, double*); template void lp::lp_core_solver_base<double, double>::restore_state(double*, double*);
template void lean::lp_core_solver_base<double, double>::save_state(double*, double*); template void lp::lp_core_solver_base<double, double>::save_state(double*, double*);
template std::string lean::lp_core_solver_base<lean::mpq, lean::mpq>::column_name(unsigned int) const; template std::string lp::lp_core_solver_base<lp::mpq, lp::mpq>::column_name(unsigned int) const;
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::pretty_print(std::ostream & out); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::pretty_print(std::ostream & out);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::restore_state(lean::mpq*, lean::mpq*); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::restore_state(lp::mpq*, lp::mpq*);
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::save_state(lean::mpq*, lean::mpq*); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::save_state(lp::mpq*, lp::mpq*);
template std::string lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::column_name(unsigned int) const; template std::string lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::column_name(unsigned int) const;
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::pretty_print(std::ostream & out); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::pretty_print(std::ostream & out);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::restore_state(lean::mpq*, lean::mpq*); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::restore_state(lp::mpq*, lp::mpq*);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::save_state(lean::mpq*, lean::mpq*); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::save_state(lp::mpq*, lp::mpq*);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_yB(vector<lean::mpq>&); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_yB(vector<lp::mpq>&);
template void lean::lp_core_solver_base<double, double>::init_lu(); template void lp::lp_core_solver_base<double, double>::init_lu();
template void lean::lp_core_solver_base<lean::mpq, lean::mpq>::init_lu(); template void lp::lp_core_solver_base<lp::mpq, lp::mpq>::init_lu();
template int lean::lp_core_solver_base<double, double>::pivots_in_column_and_row_are_different(int, int) const; template int lp::lp_core_solver_base<double, double>::pivots_in_column_and_row_are_different(int, int) const;
template int lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::pivots_in_column_and_row_are_different(int, int) const; template int lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::pivots_in_column_and_row_are_different(int, int) const;
template int lean::lp_core_solver_base<lean::mpq, lean::mpq>::pivots_in_column_and_row_are_different(int, int) const; template int lp::lp_core_solver_base<lp::mpq, lp::mpq>::pivots_in_column_and_row_are_different(int, int) const;
template bool lean::lp_core_solver_base<double, double>::calc_current_x_is_feasible_include_non_basis(void)const; template bool lp::lp_core_solver_base<double, double>::calc_current_x_is_feasible_include_non_basis(void)const;
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::calc_current_x_is_feasible_include_non_basis(void)const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::calc_current_x_is_feasible_include_non_basis(void)const;
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::calc_current_x_is_feasible_include_non_basis() const; template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::calc_current_x_is_feasible_include_non_basis() const;
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::pivot_fixed_vars_from_basis(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::pivot_fixed_vars_from_basis();
template bool lean::lp_core_solver_base<double, double>::column_is_feasible(unsigned int) const; template bool lp::lp_core_solver_base<double, double>::column_is_feasible(unsigned int) const;
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::column_is_feasible(unsigned int) const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::column_is_feasible(unsigned int) const;
// template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::print_linear_combination_of_column_indices(vector<std::pair<lean::mpq, unsigned int>, std::allocator<std::pair<lean::mpq, unsigned int> > > const&, std::ostream&) const; // template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::print_linear_combination_of_column_indices(vector<std::pair<lp::mpq, unsigned int>, std::allocator<std::pair<lp::mpq, unsigned int> > > const&, std::ostream&) const;
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::column_is_feasible(unsigned int) const; template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::column_is_feasible(unsigned int) const;
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::snap_non_basic_x_to_bound(); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::snap_non_basic_x_to_bound();
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::init_lu(); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::init_lu();
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::A_mult_x_is_off_on_index(vector<unsigned int> const&) const; template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::A_mult_x_is_off_on_index(vector<unsigned int> const&) const;
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::find_x_by_solving(); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::find_x_by_solving();
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::restore_x(unsigned int, lean::numeric_pair<lean::mpq> const&); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::restore_x(unsigned int, lp::numeric_pair<lp::mpq> const&);
template bool lean::lp_core_solver_base<double, double>::pivot_for_tableau_on_basis(); template bool lp::lp_core_solver_base<double, double>::pivot_for_tableau_on_basis();
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::pivot_for_tableau_on_basis(); template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::pivot_for_tableau_on_basis();
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq>>::pivot_for_tableau_on_basis(); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq>>::pivot_for_tableau_on_basis();
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq>>::pivot_column_tableau(unsigned int, unsigned int); template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq>>::pivot_column_tableau(unsigned int, unsigned int);
template bool lean::lp_core_solver_base<double, double>::pivot_column_tableau(unsigned int, unsigned int); template bool lp::lp_core_solver_base<double, double>::pivot_column_tableau(unsigned int, unsigned int);
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::pivot_column_tableau(unsigned int, unsigned int); template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::pivot_column_tableau(unsigned int, unsigned int);
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::transpose_rows_tableau(unsigned int, unsigned int); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::transpose_rows_tableau(unsigned int, unsigned int);
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::inf_set_is_correct() const; template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::inf_set_is_correct() const;
template bool lean::lp_core_solver_base<double, double>::inf_set_is_correct() const; template bool lp::lp_core_solver_base<double, double>::inf_set_is_correct() const;
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq>::inf_set_is_correct() const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq>::inf_set_is_correct() const;
template bool lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::infeasibility_costs_are_correct() const; template bool lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::infeasibility_costs_are_correct() const;
template bool lean::lp_core_solver_base<lean::mpq, lean::mpq >::infeasibility_costs_are_correct() const; template bool lp::lp_core_solver_base<lp::mpq, lp::mpq >::infeasibility_costs_are_correct() const;
template bool lean::lp_core_solver_base<double, double >::infeasibility_costs_are_correct() const; template bool lp::lp_core_solver_base<double, double >::infeasibility_costs_are_correct() const;
template void lean::lp_core_solver_base<lean::mpq, lean::numeric_pair<lean::mpq> >::calculate_pivot_row(unsigned int); template void lp::lp_core_solver_base<lp::mpq, lp::numeric_pair<lp::mpq> >::calculate_pivot_row(unsigned int);

View file

@ -11,7 +11,7 @@
#include <algorithm> #include <algorithm>
#include "util/vector.h" #include "util/vector.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
class lp_dual_core_solver:public lp_core_solver_base<T, X> { class lp_dual_core_solver:public lp_core_solver_base<T, X> {
public: public:

View file

@ -7,7 +7,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lp_dual_core_solver.h" #include "util/lp/lp_dual_core_solver.h"
namespace lean { namespace lp {
template <typename T, typename X> void lp_dual_core_solver<T, X>::init_a_wave_by_zeros() { template <typename T, typename X> void lp_dual_core_solver<T, X>::init_a_wave_by_zeros() {
unsigned j = this->m_m(); unsigned j = this->m_m();
@ -23,7 +23,7 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::restore_non_ba
while (j--) { while (j--) {
if (this->m_basis_heading[j] >= 0 ) continue; if (this->m_basis_heading[j] >= 0 ) continue;
if (m_can_enter_basis[j]) { if (m_can_enter_basis[j]) {
lean_assert(std::find(nb.begin(), nb.end(), j) == nb.end()); lp_assert(std::find(nb.begin(), nb.end(), j) == nb.end());
nb.push_back(j); nb.push_back(j);
this->m_basis_heading[j] = - static_cast<int>(nb.size()); this->m_basis_heading[j] = - static_cast<int>(nb.size());
} }
@ -93,14 +93,14 @@ template <typename T, typename X> bool lp_dual_core_solver<T, X>::done() {
} }
template <typename T, typename X> T lp_dual_core_solver<T, X>::get_edge_steepness_for_low_bound(unsigned p) { template <typename T, typename X> T lp_dual_core_solver<T, X>::get_edge_steepness_for_low_bound(unsigned p) {
lean_assert(this->m_basis_heading[p] >= 0 && static_cast<unsigned>(this->m_basis_heading[p]) < this->m_m()); lp_assert(this->m_basis_heading[p] >= 0 && static_cast<unsigned>(this->m_basis_heading[p]) < this->m_m());
T del = this->m_x[p] - this->m_low_bounds[p]; T del = this->m_x[p] - this->m_low_bounds[p];
del *= del; del *= del;
return del / this->m_betas[this->m_basis_heading[p]]; return del / this->m_betas[this->m_basis_heading[p]];
} }
template <typename T, typename X> T lp_dual_core_solver<T, X>::get_edge_steepness_for_upper_bound(unsigned p) { template <typename T, typename X> T lp_dual_core_solver<T, X>::get_edge_steepness_for_upper_bound(unsigned p) {
lean_assert(this->m_basis_heading[p] >= 0 && static_cast<unsigned>(this->m_basis_heading[p]) < this->m_m()); lp_assert(this->m_basis_heading[p] >= 0 && static_cast<unsigned>(this->m_basis_heading[p]) < this->m_m());
T del = this->m_x[p] - this->m_upper_bounds[p]; T del = this->m_x[p] - this->m_upper_bounds[p];
del *= del; del *= del;
return del / this->m_betas[this->m_basis_heading[p]]; return del / this->m_betas[this->m_basis_heading[p]];
@ -135,12 +135,12 @@ template <typename T, typename X> T lp_dual_core_solver<T, X>::pricing_for_row(u
return numeric_traits<T>::zero(); return numeric_traits<T>::zero();
break; break;
case column_type::free_column: case column_type::free_column:
lean_assert(numeric_traits<T>::is_zero(this->m_d[p])); lp_assert(numeric_traits<T>::is_zero(this->m_d[p]));
return numeric_traits<T>::zero(); return numeric_traits<T>::zero();
default: default:
lean_unreachable(); lp_unreachable();
} }
lean_unreachable(); lp_unreachable();
return numeric_traits<T>::zero(); return numeric_traits<T>::zero();
} }
@ -209,9 +209,9 @@ template <typename T, typename X> bool lp_dual_core_solver<T, X>::advance_on_kno
int pivot_compare_result = this->pivots_in_column_and_row_are_different(m_q, m_p); int pivot_compare_result = this->pivots_in_column_and_row_are_different(m_q, m_p);
if (!pivot_compare_result){;} if (!pivot_compare_result){;}
else if (pivot_compare_result == 2) { // the sign is changed, cannot continue else if (pivot_compare_result == 2) { // the sign is changed, cannot continue
lean_unreachable(); // not implemented yet lp_unreachable(); // not implemented yet
} else { } else {
lean_assert(pivot_compare_result == 1); lp_assert(pivot_compare_result == 1);
this->init_lu(); this->init_lu();
} }
DSE_FTran(); DSE_FTran();
@ -228,21 +228,21 @@ template <typename T, typename X> int lp_dual_core_solver<T, X>::define_sign_of_
if (this->x_above_upper_bound(m_p)) { if (this->x_above_upper_bound(m_p)) {
return 1; return 1;
} }
lean_unreachable(); lp_unreachable();
case column_type::low_bound: case column_type::low_bound:
if (this->x_below_low_bound(m_p)) { if (this->x_below_low_bound(m_p)) {
return -1; return -1;
} }
lean_unreachable(); lp_unreachable();
case column_type::upper_bound: case column_type::upper_bound:
if (this->x_above_upper_bound(m_p)) { if (this->x_above_upper_bound(m_p)) {
return 1; return 1;
} }
lean_unreachable(); lp_unreachable();
default: default:
lean_unreachable(); lp_unreachable();
} }
lean_unreachable(); lp_unreachable();
return 0; return 0;
} }
@ -250,10 +250,10 @@ template <typename T, typename X> bool lp_dual_core_solver<T, X>::can_be_breakpo
if (this->pivot_row_element_is_too_small_for_ratio_test(j)) return false; if (this->pivot_row_element_is_too_small_for_ratio_test(j)) return false;
switch (this->m_column_types[j]) { switch (this->m_column_types[j]) {
case column_type::low_bound: case column_type::low_bound:
lean_assert(this->m_settings.abs_val_is_smaller_than_harris_tolerance(this->m_x[j] - this->m_low_bounds[j])); lp_assert(this->m_settings.abs_val_is_smaller_than_harris_tolerance(this->m_x[j] - this->m_low_bounds[j]));
return m_sign_of_alpha_r * this->m_pivot_row[j] > 0; return m_sign_of_alpha_r * this->m_pivot_row[j] > 0;
case column_type::upper_bound: case column_type::upper_bound:
lean_assert(this->m_settings.abs_val_is_smaller_than_harris_tolerance(this->m_x[j] - this->m_upper_bounds[j])); lp_assert(this->m_settings.abs_val_is_smaller_than_harris_tolerance(this->m_x[j] - this->m_upper_bounds[j]));
return m_sign_of_alpha_r * this->m_pivot_row[j] < 0; return m_sign_of_alpha_r * this->m_pivot_row[j] < 0;
case column_type::boxed: case column_type::boxed:
{ {
@ -292,23 +292,23 @@ template <typename T, typename X> T lp_dual_core_solver<T, X>::get_delta() {
if (this->x_above_upper_bound(m_p)) { if (this->x_above_upper_bound(m_p)) {
return this->m_x[m_p] - this->m_upper_bounds[m_p]; return this->m_x[m_p] - this->m_upper_bounds[m_p];
} }
lean_unreachable(); lp_unreachable();
case column_type::low_bound: case column_type::low_bound:
if (this->x_below_low_bound(m_p)) { if (this->x_below_low_bound(m_p)) {
return this->m_x[m_p] - this->m_low_bounds[m_p]; return this->m_x[m_p] - this->m_low_bounds[m_p];
} }
lean_unreachable(); lp_unreachable();
case column_type::upper_bound: case column_type::upper_bound:
if (this->x_above_upper_bound(m_p)) { if (this->x_above_upper_bound(m_p)) {
return get_edge_steepness_for_upper_bound(m_p); return get_edge_steepness_for_upper_bound(m_p);
} }
lean_unreachable(); lp_unreachable();
case column_type::fixed: case column_type::fixed:
return this->m_x[m_p] - this->m_upper_bounds[m_p]; return this->m_x[m_p] - this->m_upper_bounds[m_p];
default: default:
lean_unreachable(); lp_unreachable();
} }
lean_unreachable(); lp_unreachable();
return zero_of_type<T>(); return zero_of_type<T>();
} }
@ -355,7 +355,7 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::update_betas()
template <typename T, typename X> void lp_dual_core_solver<T, X>::apply_flips() { template <typename T, typename X> void lp_dual_core_solver<T, X>::apply_flips() {
for (unsigned j : m_flipped_boxed) { for (unsigned j : m_flipped_boxed) {
lean_assert(this->x_is_at_bound(j)); lp_assert(this->x_is_at_bound(j));
if (this->x_is_at_low_bound(j)) { if (this->x_is_at_low_bound(j)) {
this->m_x[j] = this->m_upper_bounds[j]; this->m_x[j] = this->m_upper_bounds[j];
} else { } else {
@ -385,7 +385,7 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::snap_xN_column
case column_type::free_column: case column_type::free_column:
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
@ -441,7 +441,7 @@ template <typename T, typename X> bool lp_dual_core_solver<T, X>::basis_change_a
return false; return false;
} }
lean_assert(d_is_correct()); lp_assert(d_is_correct());
return true; return true;
} }
@ -457,7 +457,7 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::recover_leavin
case free_of_bounds: case free_of_bounds:
this->m_x[m_q] = zero_of_type<X>(); this->m_x[m_q] = zero_of_type<X>();
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
@ -584,7 +584,7 @@ template <typename T, typename X> bool lp_dual_core_solver<T, X>::tight_breakpoi
template <typename T, typename X> T lp_dual_core_solver<T, X>::calculate_harris_delta_on_breakpoint_set() { template <typename T, typename X> T lp_dual_core_solver<T, X>::calculate_harris_delta_on_breakpoint_set() {
bool first_time = true; bool first_time = true;
T ret = zero_of_type<T>(); T ret = zero_of_type<T>();
lean_assert(m_breakpoint_set.size() > 0); lp_assert(m_breakpoint_set.size() > 0);
for (auto j : m_breakpoint_set) { for (auto j : m_breakpoint_set) {
T t; T t;
if (this->x_is_at_low_bound(j)) { if (this->x_is_at_low_bound(j)) {
@ -633,7 +633,7 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::find_q_on_tigh
} }
} }
m_tight_set.erase(m_q); m_tight_set.erase(m_q);
lean_assert(m_q != -1); lp_assert(m_q != -1);
} }
template <typename T, typename X> void lp_dual_core_solver<T, X>::find_q_and_tight_set() { template <typename T, typename X> void lp_dual_core_solver<T, X>::find_q_and_tight_set() {
@ -722,13 +722,13 @@ template <typename T, typename X> void lp_dual_core_solver<T, X>::one_iteration(
this->set_status(FEASIBLE); this->set_status(FEASIBLE);
} }
pricing_loop(number_of_rows_to_try, offset_in_rows); pricing_loop(number_of_rows_to_try, offset_in_rows);
lean_assert(problem_is_dual_feasible()); lp_assert(problem_is_dual_feasible());
} }
template <typename T, typename X> void lp_dual_core_solver<T, X>::solve() { // see the page 35 template <typename T, typename X> void lp_dual_core_solver<T, X>::solve() { // see the page 35
lean_assert(d_is_correct()); lp_assert(d_is_correct());
lean_assert(problem_is_dual_feasible()); lp_assert(problem_is_dual_feasible());
lean_assert(this->basis_heading_is_correct()); lp_assert(this->basis_heading_is_correct());
this->set_total_iterations(0); this->set_total_iterations(0);
this->iters_with_no_cost_growing() = 0; this->iters_with_no_cost_growing() = 0;
do { do {

View file

@ -8,22 +8,22 @@
#include "util/vector.h" #include "util/vector.h"
#include <functional> #include <functional>
#include "util/lp/lp_dual_core_solver.hpp" #include "util/lp/lp_dual_core_solver.hpp"
template void lean::lp_dual_core_solver<lean::mpq, lean::mpq>::start_with_initial_basis_and_make_it_dual_feasible(); template void lp::lp_dual_core_solver<lp::mpq, lp::mpq>::start_with_initial_basis_and_make_it_dual_feasible();
template void lean::lp_dual_core_solver<lean::mpq, lean::mpq>::solve(); template void lp::lp_dual_core_solver<lp::mpq, lp::mpq>::solve();
template lean::lp_dual_core_solver<double, double>::lp_dual_core_solver(lean::static_matrix<double, double>&, vector<bool>&, template lp::lp_dual_core_solver<double, double>::lp_dual_core_solver(lp::static_matrix<double, double>&, vector<bool>&,
vector<double>&, vector<double>&,
vector<double>&, vector<double>&,
vector<unsigned int>&, vector<unsigned int>&,
vector<unsigned> &, vector<unsigned> &,
vector<int> &, vector<int> &,
vector<double>&, vector<double>&,
vector<lean::column_type>&, vector<lp::column_type>&,
vector<double>&, vector<double>&,
vector<double>&, vector<double>&,
lean::lp_settings&, const lean::column_namer&); lp::lp_settings&, const lp::column_namer&);
template void lean::lp_dual_core_solver<double, double>::start_with_initial_basis_and_make_it_dual_feasible(); template void lp::lp_dual_core_solver<double, double>::start_with_initial_basis_and_make_it_dual_feasible();
template void lean::lp_dual_core_solver<double, double>::solve(); template void lp::lp_dual_core_solver<double, double>::solve();
template void lean::lp_dual_core_solver<lean::mpq, lean::mpq>::restore_non_basis(); template void lp::lp_dual_core_solver<lp::mpq, lp::mpq>::restore_non_basis();
template void lean::lp_dual_core_solver<double, double>::restore_non_basis(); template void lp::lp_dual_core_solver<double, double>::restore_non_basis();
template void lean::lp_dual_core_solver<double, double>::revert_to_previous_basis(); template void lp::lp_dual_core_solver<double, double>::revert_to_previous_basis();
template void lean::lp_dual_core_solver<lean::mpq, lean::mpq>::revert_to_previous_basis(); template void lp::lp_dual_core_solver<lp::mpq, lp::mpq>::revert_to_previous_basis();

View file

@ -7,7 +7,7 @@
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/lp_solver.h" #include "util/lp/lp_solver.h"
#include "util/lp/lp_dual_core_solver.h" #include "util/lp/lp_dual_core_solver.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
class lp_dual_simplex: public lp_solver<T, X> { class lp_dual_simplex: public lp_solver<T, X> {

View file

@ -3,7 +3,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#include "util/lp/lp_dual_simplex.h" #include "util/lp/lp_dual_simplex.h"
namespace lean{ namespace lp{
template <typename T, typename X> void lp_dual_simplex<T, X>::decide_on_status_after_stage1() { template <typename T, typename X> void lp_dual_simplex<T, X>::decide_on_status_after_stage1() {
switch (m_core_solver->get_status()) { switch (m_core_solver->get_status()) {
@ -15,7 +15,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::decide_on_status_a
} }
break; break;
case DUAL_UNBOUNDED: case DUAL_UNBOUNDED:
lean_unreachable(); lp_unreachable();
case ITERATIONS_EXHAUSTED: case ITERATIONS_EXHAUSTED:
this->m_status = ITERATIONS_EXHAUSTED; this->m_status = ITERATIONS_EXHAUSTED;
break; break;
@ -26,12 +26,12 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::decide_on_status_a
this->m_status = FLOATING_POINT_ERROR; this->m_status = FLOATING_POINT_ERROR;
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
template <typename T, typename X> void lp_dual_simplex<T, X>::fix_logical_for_stage2(unsigned j) { template <typename T, typename X> void lp_dual_simplex<T, X>::fix_logical_for_stage2(unsigned j) {
lean_assert(j >= this->number_of_core_structurals()); lp_assert(j >= this->number_of_core_structurals());
switch (m_column_types_of_logicals[j - this->number_of_core_structurals()]) { switch (m_column_types_of_logicals[j - this->number_of_core_structurals()]) {
case column_type::low_bound: case column_type::low_bound:
m_low_bounds[j] = numeric_traits<T>::zero(); m_low_bounds[j] = numeric_traits<T>::zero();
@ -44,7 +44,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fix_logical_for_st
m_can_enter_basis[j] = false; m_can_enter_basis[j] = false;
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
@ -58,7 +58,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fix_structural_for
break; break;
case column_type::fixed: case column_type::fixed:
case column_type::upper_bound: case column_type::upper_bound:
lean_unreachable(); lp_unreachable();
case column_type::boxed: case column_type::boxed:
this->m_upper_bounds[j] = ci->get_adjusted_upper_bound() / this->m_column_scale[j]; this->m_upper_bounds[j] = ci->get_adjusted_upper_bound() / this->m_column_scale[j];
m_low_bounds[j] = numeric_traits<T>::zero(); m_low_bounds[j] = numeric_traits<T>::zero();
@ -70,7 +70,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fix_structural_for
m_column_types_of_core_solver[j] = column_type::free_column; m_column_types_of_core_solver[j] = column_type::free_column;
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
// T cost_was = this->m_costs[j]; // T cost_was = this->m_costs[j];
this->set_scaled_cost(j); this->set_scaled_cost(j);
@ -115,7 +115,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::solve_for_stage2()
this->m_status = FLOATING_POINT_ERROR; this->m_status = FLOATING_POINT_ERROR;
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
this->m_second_stage_iterations = m_core_solver->total_iterations(); this->m_second_stage_iterations = m_core_solver->total_iterations();
this->m_total_iterations = (this->m_first_stage_iterations + this->m_second_stage_iterations); this->m_total_iterations = (this->m_first_stage_iterations + this->m_second_stage_iterations);
@ -129,7 +129,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fill_x_with_zeros(
} }
template <typename T, typename X> void lp_dual_simplex<T, X>::stage1() { template <typename T, typename X> void lp_dual_simplex<T, X>::stage1() {
lean_assert(m_core_solver == nullptr); lp_assert(m_core_solver == nullptr);
this->m_x.resize(this->m_A->column_count(), numeric_traits<T>::zero()); this->m_x.resize(this->m_A->column_count(), numeric_traits<T>::zero());
if (this->m_settings.get_message_ostream() != nullptr) if (this->m_settings.get_message_ostream() != nullptr)
this->print_statistics_on_A(*this->m_settings.get_message_ostream()); this->print_statistics_on_A(*this->m_settings.get_message_ostream());
@ -177,7 +177,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fill_first_stage_s
} }
template <typename T, typename X> column_type lp_dual_simplex<T, X>::get_column_type(unsigned j) { template <typename T, typename X> column_type lp_dual_simplex<T, X>::get_column_type(unsigned j) {
lean_assert(j < this->m_A->column_count()); lp_assert(j < this->m_A->column_count());
if (j >= this->number_of_core_structurals()) { if (j >= this->number_of_core_structurals()) {
return m_column_types_of_logicals[j - this->number_of_core_structurals()]; return m_column_types_of_logicals[j - this->number_of_core_structurals()];
} }
@ -186,12 +186,12 @@ template <typename T, typename X> column_type lp_dual_simplex<T, X>::get_column_
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_structural_column(unsigned j) { template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_structural_column(unsigned j) {
// see 4.7 in the dissertation of Achim Koberstein // see 4.7 in the dissertation of Achim Koberstein
lean_assert(this->m_core_solver_columns_to_external_columns.find(j) != lp_assert(this->m_core_solver_columns_to_external_columns.find(j) !=
this->m_core_solver_columns_to_external_columns.end()); this->m_core_solver_columns_to_external_columns.end());
T free_bound = T(1e4); // see 4.8 T free_bound = T(1e4); // see 4.8
unsigned jj = this->m_core_solver_columns_to_external_columns[j]; unsigned jj = this->m_core_solver_columns_to_external_columns[j];
lean_assert(this->m_map_from_var_index_to_column_info.find(jj) != this->m_map_from_var_index_to_column_info.end()); lp_assert(this->m_map_from_var_index_to_column_info.find(jj) != this->m_map_from_var_index_to_column_info.end());
column_info<T> * ci = this->m_map_from_var_index_to_column_info[jj]; column_info<T> * ci = this->m_map_from_var_index_to_column_info[jj];
switch (ci->get_column_type()) { switch (ci->get_column_type()) {
case column_type::upper_bound: { case column_type::upper_bound: {
@ -221,14 +221,14 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_
this->m_upper_bounds[j] = this->m_low_bounds[j] = numeric_traits<T>::zero(); // is it needed? this->m_upper_bounds[j] = this->m_low_bounds[j] = numeric_traits<T>::zero(); // is it needed?
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
m_column_types_of_core_solver[j] = column_type::boxed; m_column_types_of_core_solver[j] = column_type::boxed;
} }
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_logical_column(unsigned j) { template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_logical_column(unsigned j) {
this->m_costs[j] = 0; this->m_costs[j] = 0;
lean_assert(get_column_type(j) != column_type::upper_bound); lp_assert(get_column_type(j) != column_type::upper_bound);
if ((m_can_enter_basis[j] = (get_column_type(j) == column_type::low_bound))) { if ((m_can_enter_basis[j] = (get_column_type(j) == column_type::low_bound))) {
m_column_types_of_core_solver[j] = column_type::boxed; m_column_types_of_core_solver[j] = column_type::boxed;
this->m_low_bounds[j] = numeric_traits<T>::zero(); this->m_low_bounds[j] = numeric_traits<T>::zero();
@ -254,7 +254,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_and_bou
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_first_stage_solver_fields_for_row_slack_and_artificial(unsigned row, template <typename T, typename X> void lp_dual_simplex<T, X>::fill_first_stage_solver_fields_for_row_slack_and_artificial(unsigned row,
unsigned & slack_var, unsigned & slack_var,
unsigned & artificial) { unsigned & artificial) {
lean_assert(row < this->row_count()); lp_assert(row < this->row_count());
auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[row]]; auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[row]];
// we need to bring the program to the form Ax = b // we need to bring the program to the form Ax = b
T rs = this->m_b[row]; T rs = this->m_b[row];
@ -335,7 +335,7 @@ template <typename T, typename X> void lp_dual_simplex<T, X>::find_maximal_solut
this->flip_costs(); // do it for now, todo ( remove the flipping) this->flip_costs(); // do it for now, todo ( remove the flipping)
this->cleanup(); this->clpup();
if (this->m_status == INFEASIBLE) { if (this->m_status == INFEASIBLE) {
return; return;
} }

View file

@ -3,7 +3,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#include "util/lp/lp_dual_simplex.hpp" #include "util/lp/lp_dual_simplex.hpp"
template lean::mpq lean::lp_dual_simplex<lean::mpq, lean::mpq>::get_current_cost() const; template lp::mpq lp::lp_dual_simplex<lp::mpq, lp::mpq>::get_current_cost() const;
template void lean::lp_dual_simplex<lean::mpq, lean::mpq>::find_maximal_solution(); template void lp::lp_dual_simplex<lp::mpq, lp::mpq>::find_maximal_solution();
template double lean::lp_dual_simplex<double, double>::get_current_cost() const; template double lp::lp_dual_simplex<double, double>::get_current_cost() const;
template void lean::lp_dual_simplex<double, double>::find_maximal_solution(); template void lp::lp_dual_simplex<double, double>::find_maximal_solution();

View file

@ -23,7 +23,7 @@
#include "util/lp/binary_heap_priority_queue.h" #include "util/lp/binary_heap_priority_queue.h"
#include "util/lp/int_set.h" #include "util/lp/int_set.h"
#include "util/lp/iterator_on_row.h" #include "util/lp/iterator_on_row.h"
namespace lean { namespace lp {
// This core solver solves (Ax=b, low_bound_values \leq x \leq upper_bound_values, maximize costs*x ) // This core solver solves (Ax=b, low_bound_values \leq x \leq upper_bound_values, maximize costs*x )
// The right side b is given implicitly by x and the basis // The right side b is given implicitly by x and the basis
@ -70,7 +70,7 @@ public:
// unsigned len = 100000000; // unsigned len = 100000000;
// for (unsigned j : this->m_inf_set.m_index) { // for (unsigned j : this->m_inf_set.m_index) {
// int i = this->m_basis_heading[j]; // int i = this->m_basis_heading[j];
// lean_assert(i >= 0); // lp_assert(i >= 0);
// unsigned row_len = this->m_A.m_rows[i].size(); // unsigned row_len = this->m_A.m_rows[i].size();
// if (row_len < len) { // if (row_len < len) {
// choices.clear(); // choices.clear();
@ -98,8 +98,8 @@ public:
bool column_is_benefitial_for_entering_basis_on_sign_row_strategy(unsigned j, int sign) const { bool column_is_benefitial_for_entering_basis_on_sign_row_strategy(unsigned j, int sign) const {
// sign = 1 means the x of the basis column of the row has to grow to become feasible, when the coeff before j is neg, or x - has to diminish when the coeff is pos // sign = 1 means the x of the basis column of the row has to grow to become feasible, when the coeff before j is neg, or x - has to diminish when the coeff is pos
// we have xbj = -aj * xj // we have xbj = -aj * xj
lean_assert(this->m_basis_heading[j] < 0); lp_assert(this->m_basis_heading[j] < 0);
lean_assert(this->column_is_feasible(j)); lp_assert(this->column_is_feasible(j));
switch (this->m_column_types[j]) { switch (this->m_column_types[j]) {
case column_type::free_column: return true; case column_type::free_column: return true;
case column_type::fixed: return false; case column_type::fixed: return false;
@ -117,13 +117,13 @@ public:
return !this->x_is_at_upper_bound(j); return !this->x_is_at_upper_bound(j);
} }
lean_assert(false); // cannot be here lp_assert(false); // cannot be here
return false; return false;
} }
bool needs_to_grow(unsigned bj) const { bool needs_to_grow(unsigned bj) const {
lean_assert(!this->column_is_feasible(bj)); lp_assert(!this->column_is_feasible(bj));
switch(this->m_column_types[bj]) { switch(this->m_column_types[bj]) {
case column_type::free_column: case column_type::free_column:
return false; return false;
@ -134,12 +134,12 @@ public:
default: default:
return false; return false;
} }
lean_assert(false); // unreachable lp_assert(false); // unreachable
return false; return false;
} }
int inf_sign_of_column(unsigned bj) const { int inf_sign_of_column(unsigned bj) const {
lean_assert(!this->column_is_feasible(bj)); lp_assert(!this->column_is_feasible(bj));
switch(this->m_column_types[bj]) { switch(this->m_column_types[bj]) {
case column_type::free_column: case column_type::free_column:
return 0; return 0;
@ -151,7 +151,7 @@ public:
default: default:
return -1; return -1;
} }
lean_assert(false); // unreachable lp_assert(false); // unreachable
return 0; return 0;
} }
@ -159,7 +159,7 @@ public:
bool monoid_can_decrease(const row_cell<T> & rc) const { bool monoid_can_decrease(const row_cell<T> & rc) const {
unsigned j = rc.m_j; unsigned j = rc.m_j;
lean_assert(this->column_is_feasible(j)); lp_assert(this->column_is_feasible(j));
switch (this->m_column_types[j]) { switch (this->m_column_types[j]) {
case column_type::free_column: case column_type::free_column:
return true; return true;
@ -186,13 +186,13 @@ public:
default: default:
return false; return false;
} }
lean_assert(false); // unreachable lp_assert(false); // unreachable
return false; return false;
} }
bool monoid_can_increase(const row_cell<T> & rc) const { bool monoid_can_increase(const row_cell<T> & rc) const {
unsigned j = rc.m_j; unsigned j = rc.m_j;
lean_assert(this->column_is_feasible(j)); lp_assert(this->column_is_feasible(j));
switch (this->m_column_types[j]) { switch (this->m_column_types[j]) {
case column_type::free_column: case column_type::free_column:
return true; return true;
@ -219,7 +219,7 @@ public:
default: default:
return false; return false;
} }
lean_assert(false); // unreachable lp_assert(false); // unreachable
return false; return false;
} }
@ -329,24 +329,24 @@ public:
} }
void limit_theta_on_basis_column_for_inf_case_m_neg_upper_bound(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_inf_case_m_neg_upper_bound(unsigned j, const T & m, X & theta, bool & unlimited) {
lean_assert(m < 0 && this->m_column_types[j] == column_type::upper_bound); lp_assert(m < 0 && this->m_column_types[j] == column_type::upper_bound);
limit_inf_on_upper_bound_m_neg(m, this->m_x[j], this->m_upper_bounds[j], theta, unlimited); limit_inf_on_upper_bound_m_neg(m, this->m_x[j], this->m_upper_bounds[j], theta, unlimited);
} }
void limit_theta_on_basis_column_for_inf_case_m_neg_low_bound(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_inf_case_m_neg_low_bound(unsigned j, const T & m, X & theta, bool & unlimited) {
lean_assert(m < 0 && this->m_column_types[j] == column_type::low_bound); lp_assert(m < 0 && this->m_column_types[j] == column_type::low_bound);
limit_inf_on_bound_m_neg(m, this->m_x[j], this->m_low_bounds[j], theta, unlimited); limit_inf_on_bound_m_neg(m, this->m_x[j], this->m_low_bounds[j], theta, unlimited);
} }
void limit_theta_on_basis_column_for_inf_case_m_pos_low_bound(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_inf_case_m_pos_low_bound(unsigned j, const T & m, X & theta, bool & unlimited) {
lean_assert(m > 0 && this->m_column_types[j] == column_type::low_bound); lp_assert(m > 0 && this->m_column_types[j] == column_type::low_bound);
limit_inf_on_low_bound_m_pos(m, this->m_x[j], this->m_low_bounds[j], theta, unlimited); limit_inf_on_low_bound_m_pos(m, this->m_x[j], this->m_low_bounds[j], theta, unlimited);
} }
void limit_theta_on_basis_column_for_inf_case_m_pos_upper_bound(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_inf_case_m_pos_upper_bound(unsigned j, const T & m, X & theta, bool & unlimited) {
lean_assert(m > 0 && this->m_column_types[j] == column_type::upper_bound); lp_assert(m > 0 && this->m_column_types[j] == column_type::upper_bound);
limit_inf_on_bound_m_pos(m, this->m_x[j], this->m_upper_bounds[j], theta, unlimited); limit_inf_on_bound_m_pos(m, this->m_x[j], this->m_upper_bounds[j], theta, unlimited);
}; };
@ -388,7 +388,7 @@ public:
bool need_to_switch_costs() const { bool need_to_switch_costs() const {
if (this->m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows) if (this->m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows)
return false; return false;
// lean_assert(calc_current_x_is_feasible() == current_x_is_feasible()); // lp_assert(calc_current_x_is_feasible() == current_x_is_feasible());
return this->current_x_is_feasible() == this->m_using_infeas_costs; return this->current_x_is_feasible() == this->m_using_infeas_costs;
} }
@ -443,7 +443,7 @@ public:
if (j == -1) if (j == -1)
return -1; return -1;
lean_assert(!this->column_is_feasible(j)); lp_assert(!this->column_is_feasible(j));
switch (this->m_column_types[j]) { switch (this->m_column_types[j]) {
case column_type::fixed: case column_type::fixed:
case column_type::upper_bound: case column_type::upper_bound:
@ -459,7 +459,7 @@ public:
new_val_for_leaving = this->m_low_bounds[j]; new_val_for_leaving = this->m_low_bounds[j];
break; break;
default: default:
lean_assert(false); lp_assert(false);
new_val_for_leaving = numeric_traits<T>::zero(); // does not matter new_val_for_leaving = numeric_traits<T>::zero(); // does not matter
} }
return j; return j;
@ -490,7 +490,7 @@ public:
} }
X theta = (this->m_x[leaving] - new_val_for_leaving) / a_ent; X theta = (this->m_x[leaving] - new_val_for_leaving) / a_ent;
advance_on_entering_and_leaving_tableau_rows(entering, leaving, theta ); advance_on_entering_and_leaving_tableau_rows(entering, leaving, theta );
lean_assert(this->m_x[leaving] == new_val_for_leaving); lp_assert(this->m_x[leaving] == new_val_for_leaving);
if (this->current_x_is_feasible()) if (this->current_x_is_feasible())
this->set_status(OPTIMAL); this->set_status(OPTIMAL);
} }
@ -507,13 +507,13 @@ public:
void update_basis_and_x_with_comparison(unsigned entering, unsigned leaving, X delta); void update_basis_and_x_with_comparison(unsigned entering, unsigned leaving, X delta);
void decide_on_status_when_cannot_find_entering() { void decide_on_status_when_cannot_find_entering() {
lean_assert(!need_to_switch_costs()); lp_assert(!need_to_switch_costs());
this->set_status(this->current_x_is_feasible()? OPTIMAL: INFEASIBLE); this->set_status(this->current_x_is_feasible()? OPTIMAL: INFEASIBLE);
} }
// void limit_theta_on_basis_column_for_feas_case_m_neg(unsigned j, const T & m, X & theta) { // void limit_theta_on_basis_column_for_feas_case_m_neg(unsigned j, const T & m, X & theta) {
// lean_assert(m < 0); // lp_assert(m < 0);
// lean_assert(this->m_column_type[j] == low_bound || this->m_column_type[j] == boxed); // lp_assert(this->m_column_type[j] == low_bound || this->m_column_type[j] == boxed);
// const X & eps = harris_eps_for_bound(this->m_low_bounds[j]); // const X & eps = harris_eps_for_bound(this->m_low_bounds[j]);
// if (this->above_bound(this->m_x[j], this->m_low_bounds[j])) { // if (this->above_bound(this->m_x[j], this->m_low_bounds[j])) {
// theta = std::min((this->m_low_bounds[j] -this->m_x[j] - eps) / m, theta); // theta = std::min((this->m_low_bounds[j] -this->m_x[j] - eps) / m, theta);
@ -522,7 +522,7 @@ public:
// } // }
void limit_theta_on_basis_column_for_feas_case_m_neg_no_check(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_feas_case_m_neg_no_check(unsigned j, const T & m, X & theta, bool & unlimited) {
lean_assert(m < 0); lp_assert(m < 0);
const X& eps = harris_eps_for_bound(this->m_low_bounds[j]); const X& eps = harris_eps_for_bound(this->m_low_bounds[j]);
limit_theta((this->m_low_bounds[j] - this->m_x[j] - eps) / m, theta, unlimited); limit_theta((this->m_low_bounds[j] - this->m_x[j] - eps) / m, theta, unlimited);
if (theta < zero_of_type<X>()) theta = zero_of_type<X>(); if (theta < zero_of_type<X>()) theta = zero_of_type<X>();
@ -530,7 +530,7 @@ public:
bool limit_inf_on_bound_m_neg(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) { bool limit_inf_on_bound_m_neg(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) {
// x gets smaller // x gets smaller
lean_assert(m < 0); lp_assert(m < 0);
if (numeric_traits<T>::precise()) { if (numeric_traits<T>::precise()) {
if (this->below_bound(x, bound)) return false; if (this->below_bound(x, bound)) return false;
if (this->above_bound(x, bound)) { if (this->above_bound(x, bound)) {
@ -554,7 +554,7 @@ public:
bool limit_inf_on_bound_m_pos(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) { bool limit_inf_on_bound_m_pos(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) {
// x gets larger // x gets larger
lean_assert(m > 0); lp_assert(m > 0);
if (numeric_traits<T>::precise()) { if (numeric_traits<T>::precise()) {
if (this->above_bound(x, bound)) return false; if (this->above_bound(x, bound)) return false;
if (this->below_bound(x, bound)) { if (this->below_bound(x, bound)) {
@ -579,14 +579,14 @@ public:
void limit_inf_on_low_bound_m_pos(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) { void limit_inf_on_low_bound_m_pos(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) {
if (numeric_traits<T>::precise()) { if (numeric_traits<T>::precise()) {
// x gets larger // x gets larger
lean_assert(m > 0); lp_assert(m > 0);
if (this->below_bound(x, bound)) { if (this->below_bound(x, bound)) {
limit_theta((bound - x) / m, theta, unlimited); limit_theta((bound - x) / m, theta, unlimited);
} }
} }
else { else {
// x gets larger // x gets larger
lean_assert(m > 0); lp_assert(m > 0);
const X& eps = harris_eps_for_bound(bound); const X& eps = harris_eps_for_bound(bound);
if (this->below_bound(x, bound)) { if (this->below_bound(x, bound)) {
limit_theta((bound - x + eps) / m, theta, unlimited); limit_theta((bound - x + eps) / m, theta, unlimited);
@ -596,7 +596,7 @@ public:
void limit_inf_on_upper_bound_m_neg(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) { void limit_inf_on_upper_bound_m_neg(const T & m, const X & x, const X & bound, X & theta, bool & unlimited) {
// x gets smaller // x gets smaller
lean_assert(m < 0); lp_assert(m < 0);
const X& eps = harris_eps_for_bound(bound); const X& eps = harris_eps_for_bound(bound);
if (this->above_bound(x, bound)) { if (this->above_bound(x, bound)) {
limit_theta((bound - x - eps) / m, theta, unlimited); limit_theta((bound - x - eps) / m, theta, unlimited);
@ -604,7 +604,7 @@ public:
} }
void limit_theta_on_basis_column_for_inf_case_m_pos_boxed(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_inf_case_m_pos_boxed(unsigned j, const T & m, X & theta, bool & unlimited) {
// lean_assert(m > 0 && this->m_column_type[j] == column_type::boxed); // lp_assert(m > 0 && this->m_column_type[j] == column_type::boxed);
const X & x = this->m_x[j]; const X & x = this->m_x[j];
const X & lbound = this->m_low_bounds[j]; const X & lbound = this->m_low_bounds[j];
@ -624,7 +624,7 @@ public:
} }
void limit_theta_on_basis_column_for_inf_case_m_neg_boxed(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_inf_case_m_neg_boxed(unsigned j, const T & m, X & theta, bool & unlimited) {
// lean_assert(m < 0 && this->m_column_type[j] == column_type::boxed); // lp_assert(m < 0 && this->m_column_type[j] == column_type::boxed);
const X & x = this->m_x[j]; const X & x = this->m_x[j];
const X & ubound = this->m_upper_bounds[j]; const X & ubound = this->m_upper_bounds[j];
if (this->above_bound(x, ubound)) { if (this->above_bound(x, ubound)) {
@ -642,7 +642,7 @@ public:
} }
} }
void limit_theta_on_basis_column_for_feas_case_m_pos(unsigned j, const T & m, X & theta, bool & unlimited) { void limit_theta_on_basis_column_for_feas_case_m_pos(unsigned j, const T & m, X & theta, bool & unlimited) {
lean_assert(m > 0); lp_assert(m > 0);
const T& eps = harris_eps_for_bound(this->m_upper_bounds[j]); const T& eps = harris_eps_for_bound(this->m_upper_bounds[j]);
if (this->below_bound(this->m_x[j], this->m_upper_bounds[j])) { if (this->below_bound(this->m_x[j], this->m_upper_bounds[j])) {
limit_theta((this->m_upper_bounds[j] - this->m_x[j] + eps) / m, theta, unlimited); limit_theta((this->m_upper_bounds[j] - this->m_x[j] + eps) / m, theta, unlimited);
@ -654,7 +654,7 @@ public:
} }
void limit_theta_on_basis_column_for_feas_case_m_pos_no_check(unsigned j, const T & m, X & theta, bool & unlimited ) { void limit_theta_on_basis_column_for_feas_case_m_pos_no_check(unsigned j, const T & m, X & theta, bool & unlimited ) {
lean_assert(m > 0); lp_assert(m > 0);
const X& eps = harris_eps_for_bound(this->m_upper_bounds[j]); const X& eps = harris_eps_for_bound(this->m_upper_bounds[j]);
limit_theta( (this->m_upper_bounds[j] - this->m_x[j] + eps) / m, theta, unlimited); limit_theta( (this->m_upper_bounds[j] - this->m_x[j] + eps) / m, theta, unlimited);
if (theta < zero_of_type<X>()) { if (theta < zero_of_type<X>()) {
@ -720,7 +720,7 @@ public:
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
if (!unlimited && theta < zero_of_type<X>()) { if (!unlimited && theta < zero_of_type<X>()) {
theta = zero_of_type<X>(); theta = zero_of_type<X>();
@ -803,7 +803,7 @@ public:
case column_type::free_column: case column_type::free_column:
return 0; return 0;
default: default:
lean_assert(false); lp_assert(false);
} }
return 0; return 0;
} }
@ -838,7 +838,7 @@ public:
return -1; return -1;
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
return 0; return 0;
@ -864,7 +864,7 @@ public:
// the delta is between the old and the new cost (old - new) // the delta is between the old and the new cost (old - new)
void update_reduced_cost_for_basic_column_cost_change(const T & delta, unsigned j) { void update_reduced_cost_for_basic_column_cost_change(const T & delta, unsigned j) {
lean_assert(this->m_basis_heading[j] >= 0); lp_assert(this->m_basis_heading[j] >= 0);
unsigned i = static_cast<unsigned>(this->m_basis_heading[j]); unsigned i = static_cast<unsigned>(this->m_basis_heading[j]);
for (const row_cell<T> & rc : this->m_A.m_rows[i]) { for (const row_cell<T> & rc : this->m_A.m_rows[i]) {
unsigned k = rc.m_j; unsigned k = rc.m_j;
@ -943,7 +943,7 @@ public:
upper_bound_values), upper_bound_values),
m_beta(A.row_count()), m_beta(A.row_count()),
m_converted_harris_eps(convert_struct<T, double>::convert(this->m_settings.harris_feasibility_tolerance)) { m_converted_harris_eps(convert_struct<T, double>::convert(this->m_settings.harris_feasibility_tolerance)) {
lean_assert(initial_x_is_correct()); lp_assert(initial_x_is_correct());
m_low_bounds_dummy.resize(A.column_count(), zero_of_type<T>()); m_low_bounds_dummy.resize(A.column_count(), zero_of_type<T>());
m_enter_price_eps = numeric_traits<T>::precise() ? numeric_traits<T>::zero() : T(1e-5); m_enter_price_eps = numeric_traits<T>::precise() ? numeric_traits<T>::zero() : T(1e-5);
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG

View file

@ -9,13 +9,13 @@
#include <set> #include <set>
#include <string> #include <string>
#include "util/lp/lp_primal_core_solver.h" #include "util/lp/lp_primal_core_solver.h"
namespace lean { namespace lp {
// This core solver solves (Ax=b, low_bound_values \leq x \leq upper_bound_values, maximize costs*x ) // This core solver solves (Ax=b, low_bound_values \leq x \leq upper_bound_values, maximize costs*x )
// The right side b is given implicitly by x and the basis // The right side b is given implicitly by x and the basis
template <typename T, typename X> template <typename T, typename X>
void lp_primal_core_solver<T, X>::sort_non_basis_rational() { void lp_primal_core_solver<T, X>::sort_non_basis_rational() {
lean_assert(numeric_traits<T>::precise()); lp_assert(numeric_traits<T>::precise());
if (this->m_settings.use_tableau()) { if (this->m_settings.use_tableau()) {
std::sort(this->m_nbasis.begin(), this->m_nbasis.end(), [this](unsigned a, unsigned b) { std::sort(this->m_nbasis.begin(), this->m_nbasis.end(), [this](unsigned a, unsigned b) {
unsigned ca = this->m_A.number_of_non_zeroes_in_column(a); unsigned ca = this->m_A.number_of_non_zeroes_in_column(a);
@ -70,11 +70,11 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_on_breakpoin
const T & d = this->m_d[j]; const T & d = this->m_d[j];
switch (this->m_column_types[j]) { switch (this->m_column_types[j]) {
case column_type::low_bound: case column_type::low_bound:
lean_assert(this->x_is_at_low_bound(j)); lp_assert(this->x_is_at_low_bound(j));
ret = d < -m_epsilon_of_reduced_cost; ret = d < -m_epsilon_of_reduced_cost;
break; break;
case column_type::upper_bound: case column_type::upper_bound:
lean_assert(this->x_is_at_upper_bound(j)); lp_assert(this->x_is_at_upper_bound(j));
ret = d > m_epsilon_of_reduced_cost; ret = d > m_epsilon_of_reduced_cost;
break; break;
case column_type::fixed: case column_type::fixed:
@ -83,7 +83,7 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_on_breakpoin
case column_type::boxed: case column_type::boxed:
{ {
bool low_bound = this->x_is_at_low_bound(j); bool low_bound = this->x_is_at_low_bound(j);
lean_assert(low_bound || this->x_is_at_upper_bound(j)); lp_assert(low_bound || this->x_is_at_upper_bound(j));
ret = (low_bound && d < -m_epsilon_of_reduced_cost) || ((!low_bound) && d > m_epsilon_of_reduced_cost); ret = (low_bound && d < -m_epsilon_of_reduced_cost) || ((!low_bound) && d > m_epsilon_of_reduced_cost);
} }
break; break;
@ -91,7 +91,7 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_on_breakpoin
ret = d > m_epsilon_of_reduced_cost || d < - m_epsilon_of_reduced_cost; ret = d > m_epsilon_of_reduced_cost || d < - m_epsilon_of_reduced_cost;
break; break;
default: default:
lean_unreachable(); lp_unreachable();
ret = false; ret = false;
break; break;
} }
@ -127,14 +127,14 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis(unsign
} }
break; break;
default: default:
lean_unreachable(); lp_unreachable();
break; break;
} }
return false; return false;
} }
template <typename T, typename X> template <typename T, typename X>
bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis_precise(unsigned j) const { bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis_precise(unsigned j) const {
lean_assert (numeric_traits<T>::precise()); lp_assert (numeric_traits<T>::precise());
if (this->m_using_infeas_costs && this->m_settings.use_breakpoints_in_feasibility_search) if (this->m_using_infeas_costs && this->m_settings.use_breakpoints_in_feasibility_search)
return column_is_benefitial_for_entering_on_breakpoints(j); return column_is_benefitial_for_entering_on_breakpoints(j);
const T& dj = this->m_d[j]; const T& dj = this->m_d[j];
@ -167,7 +167,7 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis_precis
} }
break; break;
default: default:
lean_unreachable(); lp_unreachable();
break; break;
} }
return false; return false;
@ -175,7 +175,7 @@ bool lp_primal_core_solver<T, X>::column_is_benefitial_for_entering_basis_precis
template <typename T, typename X> template <typename T, typename X>
int lp_primal_core_solver<T, X>::choose_entering_column_presize(unsigned number_of_benefitial_columns_to_go_over) { // at this moment m_y = cB * B(-1) int lp_primal_core_solver<T, X>::choose_entering_column_presize(unsigned number_of_benefitial_columns_to_go_over) { // at this moment m_y = cB * B(-1)
lean_assert(numeric_traits<T>::precise()); lp_assert(numeric_traits<T>::precise());
if (number_of_benefitial_columns_to_go_over == 0) if (number_of_benefitial_columns_to_go_over == 0)
return -1; return -1;
if (this->m_basis_sort_counter == 0) { if (this->m_basis_sort_counter == 0) {
@ -259,7 +259,7 @@ int lp_primal_core_solver<T, X>::choose_entering_column(unsigned number_of_benef
template <typename T, typename X> int lp_primal_core_solver<T, X>::advance_on_sorted_breakpoints(unsigned entering, X &t) { template <typename T, typename X> int lp_primal_core_solver<T, X>::advance_on_sorted_breakpoints(unsigned entering, X &t) {
T slope_at_entering = this->m_d[entering]; T slope_at_entering = this->m_d[entering];
breakpoint<X> * last_bp = nullptr; breakpoint<X> * last_bp = nullptr;
lean_assert(m_breakpoint_indices_queue.is_empty()==false); lp_assert(m_breakpoint_indices_queue.is_empty()==false);
while (m_breakpoint_indices_queue.is_empty() == false) { while (m_breakpoint_indices_queue.is_empty() == false) {
unsigned bi = m_breakpoint_indices_queue.dequeue(); unsigned bi = m_breakpoint_indices_queue.dequeue();
breakpoint<X> *b = &m_breakpoints[bi]; breakpoint<X> *b = &m_breakpoints[bi];
@ -274,7 +274,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::advance_on_so
} }
} }
} }
lean_assert (last_bp != nullptr); lp_assert (last_bp != nullptr);
t = last_bp->m_delta; t = last_bp->m_delta;
return last_bp->m_j; return last_bp->m_j;
} }
@ -282,13 +282,13 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::advance_on_so
template <typename T, typename X> int template <typename T, typename X> int
lp_primal_core_solver<T, X>::find_leaving_and_t_with_breakpoints(unsigned entering, X & t){ lp_primal_core_solver<T, X>::find_leaving_and_t_with_breakpoints(unsigned entering, X & t){
lean_assert(this->precise() == false); lp_assert(this->precise() == false);
fill_breakpoints_array(entering); fill_breakpoints_array(entering);
return advance_on_sorted_breakpoints(entering, t); return advance_on_sorted_breakpoints(entering, t);
} }
template <typename T, typename X> bool lp_primal_core_solver<T, X>::get_harris_theta(X & theta) { template <typename T, typename X> bool lp_primal_core_solver<T, X>::get_harris_theta(X & theta) {
lean_assert(this->m_ed.is_OK()); lp_assert(this->m_ed.is_OK());
bool unlimited = true; bool unlimited = true;
for (unsigned i : this->m_ed.m_index) { for (unsigned i : this->m_ed.m_index) {
if (this->m_settings.abs_val_is_smaller_than_pivot_tolerance(this->m_ed[i])) continue; if (this->m_settings.abs_val_is_smaller_than_pivot_tolerance(this->m_ed[i])) continue;
@ -345,13 +345,13 @@ template <typename T, typename X> bool lp_primal_core_solver<T, X>::try_jump_to_
if (m_sign_of_entering_delta > 0) { if (m_sign_of_entering_delta > 0) {
t = this->m_upper_bounds[entering] - this->m_x[entering]; t = this->m_upper_bounds[entering] - this->m_x[entering];
if (unlimited || t <= theta){ if (unlimited || t <= theta){
lean_assert(t >= zero_of_type<X>()); lp_assert(t >= zero_of_type<X>());
return true; return true;
} }
} else { // m_sign_of_entering_delta == -1 } else { // m_sign_of_entering_delta == -1
t = this->m_x[entering] - this->m_low_bounds[entering]; t = this->m_x[entering] - this->m_low_bounds[entering];
if (unlimited || t <= theta) { if (unlimited || t <= theta) {
lean_assert(t >= zero_of_type<X>()); lp_assert(t >= zero_of_type<X>());
return true; return true;
} }
} }
@ -360,7 +360,7 @@ template <typename T, typename X> bool lp_primal_core_solver<T, X>::try_jump_to_
if (m_sign_of_entering_delta > 0) { if (m_sign_of_entering_delta > 0) {
t = this->m_upper_bounds[entering] - this->m_x[entering]; t = this->m_upper_bounds[entering] - this->m_x[entering];
if (unlimited || t <= theta){ if (unlimited || t <= theta){
lean_assert(t >= zero_of_type<X>()); lp_assert(t >= zero_of_type<X>());
return true; return true;
} }
} }
@ -369,7 +369,7 @@ template <typename T, typename X> bool lp_primal_core_solver<T, X>::try_jump_to_
if (m_sign_of_entering_delta < 0) { if (m_sign_of_entering_delta < 0) {
t = this->m_x[entering] - this->m_low_bounds[entering]; t = this->m_x[entering] - this->m_low_bounds[entering];
if (unlimited || t <= theta) { if (unlimited || t <= theta) {
lean_assert(t >= zero_of_type<X>()); lp_assert(t >= zero_of_type<X>());
return true; return true;
} }
} }
@ -405,7 +405,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
do { do {
unsigned i = this->m_ed.m_index[k]; unsigned i = this->m_ed.m_index[k];
const T & ed = this->m_ed[i]; const T & ed = this->m_ed[i];
lean_assert(!numeric_traits<T>::is_zero(ed)); lp_assert(!numeric_traits<T>::is_zero(ed));
unsigned j = this->m_basis[i]; unsigned j = this->m_basis[i];
limit_theta_on_basis_column(j, - ed * m_sign_of_entering_delta, t, unlimited); limit_theta_on_basis_column(j, - ed * m_sign_of_entering_delta, t, unlimited);
if (!unlimited) { if (!unlimited) {
@ -424,7 +424,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
while (k != initial_k) { while (k != initial_k) {
unsigned i = this->m_ed.m_index[k]; unsigned i = this->m_ed.m_index[k];
const T & ed = this->m_ed[i]; const T & ed = this->m_ed[i];
lean_assert(!numeric_traits<T>::is_zero(ed)); lp_assert(!numeric_traits<T>::is_zero(ed));
unsigned j = this->m_basis[i]; unsigned j = this->m_basis[i];
unlimited = true; unlimited = true;
limit_theta_on_basis_column(j, -ed * m_sign_of_entering_delta, ratio, unlimited); limit_theta_on_basis_column(j, -ed * m_sign_of_entering_delta, ratio, unlimited);
@ -464,7 +464,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leavi
return find_leaving_and_t_with_breakpoints(entering, t); return find_leaving_and_t_with_breakpoints(entering, t);
X theta; X theta;
bool unlimited = get_harris_theta(theta); bool unlimited = get_harris_theta(theta);
lean_assert(unlimited || theta >= zero_of_type<X>()); lp_assert(unlimited || theta >= zero_of_type<X>());
if (try_jump_to_another_bound_on_entering(entering, theta, t, unlimited)) return entering; if (try_jump_to_another_bound_on_entering(entering, theta, t, unlimited)) return entering;
if (unlimited) if (unlimited)
return -1; return -1;
@ -533,7 +533,7 @@ template <typename T, typename X> X lp_primal_core_solver<T, X>::get_max_boun
template <typename T, typename X> void lp_primal_core_solver<T, X>::check_Ax_equal_b() { template <typename T, typename X> void lp_primal_core_solver<T, X>::check_Ax_equal_b() {
dense_matrix<T, X> d(this->m_A); dense_matrix<T, X> d(this->m_A);
T * ls = d.apply_from_left_with_different_dims(this->m_x); T * ls = d.apply_from_left_with_different_dims(this->m_x);
lean_assert(vectors_are_equal<T>(ls, this->m_b, this->m_m())); lp_assert(vectors_are_equal<T>(ls, this->m_b, this->m_m()));
delete [] ls; delete [] ls;
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::check_the_bounds() { template <typename T, typename X> void lp_primal_core_solver<T, X>::check_the_bounds() {
@ -543,8 +543,8 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::check_the
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::check_bound(unsigned i) { template <typename T, typename X> void lp_primal_core_solver<T, X>::check_bound(unsigned i) {
lean_assert (!(this->column_has_low_bound(i) && (numeric_traits<T>::zero() > this->m_x[i]))); lp_assert (!(this->column_has_low_bound(i) && (numeric_traits<T>::zero() > this->m_x[i])));
lean_assert (!(this->column_has_upper_bound(i) && (this->m_upper_bounds[i] < this->m_x[i]))); lp_assert (!(this->column_has_upper_bound(i) && (this->m_upper_bounds[i] < this->m_x[i])));
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::check_correctness() { template <typename T, typename X> void lp_primal_core_solver<T, X>::check_correctness() {
@ -560,8 +560,8 @@ void lp_primal_core_solver<T, X>::update_reduced_costs_from_pivot_row(unsigned e
// the basis heading has changed already // the basis heading has changed already
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
auto & basis_heading = this->m_basis_heading; auto & basis_heading = this->m_basis_heading;
lean_assert(basis_heading[entering] >= 0 && static_cast<unsigned>(basis_heading[entering]) < this->m_m()); lp_assert(basis_heading[entering] >= 0 && static_cast<unsigned>(basis_heading[entering]) < this->m_m());
lean_assert(basis_heading[leaving] < 0); lp_assert(basis_heading[leaving] < 0);
#endif #endif
T pivot = this->m_pivot_row[entering]; T pivot = this->m_pivot_row[entering];
T dq = this->m_d[entering]/pivot; T dq = this->m_d[entering]/pivot;
@ -584,7 +584,7 @@ void lp_primal_core_solver<T, X>::update_reduced_costs_from_pivot_row(unsigned e
template <typename T, typename X> int lp_primal_core_solver<T, X>::refresh_reduced_cost_at_entering_and_check_that_it_is_off(unsigned entering) { template <typename T, typename X> int lp_primal_core_solver<T, X>::refresh_reduced_cost_at_entering_and_check_that_it_is_off(unsigned entering) {
if (numeric_traits<T>::precise()) return 0; if (numeric_traits<T>::precise()) return 0;
T reduced_at_entering_was = this->m_d[entering]; // can benefit from going over non-zeros of m_ed T reduced_at_entering_was = this->m_d[entering]; // can benefit from going over non-zeros of m_ed
lean_assert(abs(reduced_at_entering_was) > m_epsilon_of_reduced_cost); lp_assert(abs(reduced_at_entering_was) > m_epsilon_of_reduced_cost);
T refreshed_cost = this->m_costs[entering]; T refreshed_cost = this->m_costs[entering];
unsigned i = this->m_m(); unsigned i = this->m_m();
while (i--) refreshed_cost -= this->m_costs[this->m_basis[i]] * this->m_ed[i]; while (i--) refreshed_cost -= this->m_costs[this->m_basis[i]] * this->m_ed[i];
@ -619,7 +619,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::backup_an
m_costs_backup = this->m_costs; m_costs_backup = this->m_costs;
} else { } else {
T cost_max = std::max(max_abs_in_vector(this->m_costs), T(1)); T cost_max = std::max(max_abs_in_vector(this->m_costs), T(1));
lean_assert(m_costs_backup.size() == 0); lp_assert(m_costs_backup.size() == 0);
for (unsigned j = 0; j < this->m_costs.size(); j++) for (unsigned j = 0; j < this->m_costs.size(); j++)
m_costs_backup.push_back(this->m_costs[j] /= cost_max); m_costs_backup.push_back(this->m_costs[j] /= cost_max);
} }
@ -649,16 +649,16 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::init_run(
template <typename T, typename X> void lp_primal_core_solver<T, X>::calc_working_vector_beta_for_column_norms(){ template <typename T, typename X> void lp_primal_core_solver<T, X>::calc_working_vector_beta_for_column_norms(){
lean_assert(numeric_traits<T>::precise() == false); lp_assert(numeric_traits<T>::precise() == false);
lean_assert(this->m_ed.is_OK()); lp_assert(this->m_ed.is_OK());
lean_assert(m_beta.is_OK()); lp_assert(m_beta.is_OK());
m_beta = this->m_ed; m_beta = this->m_ed;
this->m_factorization->solve_yB_with_error_check_indexed(m_beta, this->m_basis_heading, this->m_basis, this->m_settings); this->m_factorization->solve_yB_with_error_check_indexed(m_beta, this->m_basis_heading, this->m_basis, this->m_settings);
} }
template <typename T, typename X> template <typename T, typename X>
void lp_primal_core_solver<T, X>::advance_on_entering_equal_leaving(int entering, X & t) { void lp_primal_core_solver<T, X>::advance_on_entering_equal_leaving(int entering, X & t) {
lean_assert(!this->A_mult_x_is_off() ); lp_assert(!this->A_mult_x_is_off() );
this->update_x(entering, t * m_sign_of_entering_delta); this->update_x(entering, t * m_sign_of_entering_delta);
if (this->A_mult_x_is_off_on_index(this->m_ed.m_index) && !this->find_x_by_solving()) { if (this->A_mult_x_is_off_on_index(this->m_ed.m_index) && !this->find_x_by_solving()) {
this->init_lu(); this->init_lu();
@ -670,7 +670,7 @@ void lp_primal_core_solver<T, X>::advance_on_entering_equal_leaving(int entering
} }
} }
if (this->m_using_infeas_costs) { if (this->m_using_infeas_costs) {
lean_assert(is_zero(this->m_costs[entering])); lp_assert(is_zero(this->m_costs[entering]));
init_infeasibility_costs_for_changed_basis_only(); init_infeasibility_costs_for_changed_basis_only();
} }
if (this->m_look_for_feasible_solution_only && this->current_x_is_feasible()) if (this->m_look_for_feasible_solution_only && this->current_x_is_feasible())
@ -683,10 +683,10 @@ void lp_primal_core_solver<T, X>::advance_on_entering_equal_leaving(int entering
} }
template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_entering_and_leaving(int entering, int leaving, X & t) { template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_entering_and_leaving(int entering, int leaving, X & t) {
lean_assert(entering >= 0 && m_non_basis_list.back() == static_cast<unsigned>(entering)); lp_assert(entering >= 0 && m_non_basis_list.back() == static_cast<unsigned>(entering));
lean_assert(this->m_using_infeas_costs || t >= zero_of_type<X>()); lp_assert(this->m_using_infeas_costs || t >= zero_of_type<X>());
lean_assert(leaving >= 0 && entering >= 0); lp_assert(leaving >= 0 && entering >= 0);
lean_assert(entering != leaving || !is_zero(t)); // otherwise nothing changes lp_assert(entering != leaving || !is_zero(t)); // otherwise nothing changes
if (entering == leaving) { if (entering == leaving) {
advance_on_entering_equal_leaving(entering, t); advance_on_entering_equal_leaving(entering, t);
return; return;
@ -702,7 +702,7 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_en
this->iters_with_no_cost_growing()++; this->iters_with_no_cost_growing()++;
return; return;
} else { } else {
lean_assert(pivot_compare_result == 1); lp_assert(pivot_compare_result == 1);
this->init_lu(); this->init_lu();
if (this->m_factorization == nullptr || this->m_factorization->get_status() != LU_status::OK) { if (this->m_factorization == nullptr || this->m_factorization->get_status() != LU_status::OK) {
this->set_status(UNSTABLE); this->set_status(UNSTABLE);
@ -746,7 +746,7 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_en
} else { } else {
update_reduced_costs_from_pivot_row(entering, leaving); update_reduced_costs_from_pivot_row(entering, leaving);
} }
lean_assert(!need_to_switch_costs()); lp_assert(!need_to_switch_costs());
std::list<unsigned>::iterator it = m_non_basis_list.end(); std::list<unsigned>::iterator it = m_non_basis_list.end();
it--; it--;
* it = static_cast<unsigned>(leaving); * it = static_cast<unsigned>(leaving);
@ -754,8 +754,8 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_en
template <typename T, typename X> void lp_primal_core_solver<T, X>::advance_on_entering_precise(int entering) { template <typename T, typename X> void lp_primal_core_solver<T, X>::advance_on_entering_precise(int entering) {
lean_assert(numeric_traits<T>::precise()); lp_assert(numeric_traits<T>::precise());
lean_assert(entering > -1); lp_assert(entering > -1);
this->solve_Bd(entering); this->solve_Bd(entering);
X t; X t;
int leaving = find_leaving_and_t_precise(entering, t); int leaving = find_leaving_and_t_precise(entering, t);
@ -771,7 +771,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::advance_on_e
advance_on_entering_precise(entering); advance_on_entering_precise(entering);
return; return;
} }
lean_assert(entering > -1); lp_assert(entering > -1);
this->solve_Bd(entering); this->solve_Bd(entering);
int refresh_result = refresh_reduced_cost_at_entering_and_check_that_it_is_off(entering); int refresh_result = refresh_reduced_cost_at_entering_and_check_that_it_is_off(entering);
if (refresh_result) { if (refresh_result) {
@ -791,7 +791,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::advance_on_e
int leaving = find_leaving_and_t(entering, t); int leaving = find_leaving_and_t(entering, t);
if (leaving == -1){ if (leaving == -1){
if (!this->current_x_is_feasible()) { if (!this->current_x_is_feasible()) {
lean_assert(!numeric_traits<T>::precise()); // we cannot have unbounded with inf costs lp_assert(!numeric_traits<T>::precise()); // we cannot have unbounded with inf costs
// if (m_look_for_feasible_solution_only) { // if (m_look_for_feasible_solution_only) {
// this->m_status = INFEASIBLE; // this->m_status = INFEASIBLE;
@ -865,7 +865,7 @@ template <typename T, typename X> unsigned lp_primal_core_solver<T, X>::solve()
return this->total_iterations(); return this->total_iterations();
} }
one_iteration(); one_iteration();
lean_assert(!this->m_using_infeas_costs || this->costs_on_nbasis_are_zeros()); lp_assert(!this->m_using_infeas_costs || this->costs_on_nbasis_are_zeros());
switch (this->get_status()) { switch (this->get_status()) {
case OPTIMAL: // double check that we are at optimum case OPTIMAL: // double check that we are at optimum
case INFEASIBLE: case INFEASIBLE:
@ -914,7 +914,7 @@ template <typename T, typename X> unsigned lp_primal_core_solver<T, X>::solve()
break; break;
case UNSTABLE: case UNSTABLE:
lean_assert(! (numeric_traits<T>::precise())); lp_assert(! (numeric_traits<T>::precise()));
this->init_lu(); this->init_lu();
if (this->m_factorization->get_status() != LU_status::OK) { if (this->m_factorization->get_status() != LU_status::OK) {
this->set_status(FLOATING_POINT_ERROR); this->set_status(FLOATING_POINT_ERROR);
@ -940,7 +940,7 @@ template <typename T, typename X> unsigned lp_primal_core_solver<T, X>::solve()
&& &&
!(this->current_x_is_feasible() && this->m_look_for_feasible_solution_only)); !(this->current_x_is_feasible() && this->m_look_for_feasible_solution_only));
lean_assert(this->get_status() == FLOATING_POINT_ERROR lp_assert(this->get_status() == FLOATING_POINT_ERROR
|| ||
this->current_x_is_feasible() == false this->current_x_is_feasible() == false
|| ||
@ -957,7 +957,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::delete_fa
// according to Swietanowski, " A new steepest edge approximation for the simplex method for linear programming" // according to Swietanowski, " A new steepest edge approximation for the simplex method for linear programming"
template <typename T, typename X> void lp_primal_core_solver<T, X>::init_column_norms() { template <typename T, typename X> void lp_primal_core_solver<T, X>::init_column_norms() {
lean_assert(numeric_traits<T>::precise() == false); lp_assert(numeric_traits<T>::precise() == false);
for (unsigned j = 0; j < this->m_n(); j++) { for (unsigned j = 0; j < this->m_n(); j++) {
this->m_column_norms[j] = T(static_cast<int>(this->m_A.m_columns[j].size() + 1)) this->m_column_norms[j] = T(static_cast<int>(this->m_A.m_columns[j].size() + 1))
@ -967,7 +967,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::init_column_
// debug only // debug only
template <typename T, typename X> T lp_primal_core_solver<T, X>::calculate_column_norm_exactly(unsigned j) { template <typename T, typename X> T lp_primal_core_solver<T, X>::calculate_column_norm_exactly(unsigned j) {
lean_assert(numeric_traits<T>::precise() == false); lp_assert(numeric_traits<T>::precise() == false);
indexed_vector<T> w(this->m_m()); indexed_vector<T> w(this->m_m());
this->m_A.copy_column_to_vector(j, w); this->m_A.copy_column_to_vector(j, w);
vector<T> d(this->m_m()); vector<T> d(this->m_m());
@ -979,8 +979,8 @@ template <typename T, typename X> T lp_primal_core_solver<T, X>::calculate_colum
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::update_or_init_column_norms(unsigned entering, unsigned leaving) { template <typename T, typename X> void lp_primal_core_solver<T, X>::update_or_init_column_norms(unsigned entering, unsigned leaving) {
lean_assert(numeric_traits<T>::precise() == false); lp_assert(numeric_traits<T>::precise() == false);
lean_assert(m_column_norm_update_counter <= this->m_settings.column_norms_update_frequency); lp_assert(m_column_norm_update_counter <= this->m_settings.column_norms_update_frequency);
if (m_column_norm_update_counter == this->m_settings.column_norms_update_frequency) { if (m_column_norm_update_counter == this->m_settings.column_norms_update_frequency) {
m_column_norm_update_counter = 0; m_column_norm_update_counter = 0;
init_column_norms(); init_column_norms();
@ -992,7 +992,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::update_or
// following Swietanowski - A new steepest ... // following Swietanowski - A new steepest ...
template <typename T, typename X> void lp_primal_core_solver<T, X>::update_column_norms(unsigned entering, unsigned leaving) { template <typename T, typename X> void lp_primal_core_solver<T, X>::update_column_norms(unsigned entering, unsigned leaving) {
lean_assert(numeric_traits<T>::precise() == false); lp_assert(numeric_traits<T>::precise() == false);
T pivot = this->m_pivot_row[entering]; T pivot = this->m_pivot_row[entering];
T g_ent = calculate_norm_of_entering_exactly() / pivot / pivot; T g_ent = calculate_norm_of_entering_exactly() / pivot / pivot;
if (!numeric_traits<T>::precise()) { if (!numeric_traits<T>::precise()) {
@ -1027,7 +1027,7 @@ template <typename T, typename X> T lp_primal_core_solver<T, X>::calculate_no
// calling it stage1 is too cryptic // calling it stage1 is too cryptic
template <typename T, typename X> void lp_primal_core_solver<T, X>::find_feasible_solution() { template <typename T, typename X> void lp_primal_core_solver<T, X>::find_feasible_solution() {
this->m_look_for_feasible_solution_only = true; this->m_look_for_feasible_solution_only = true;
lean_assert(this->non_basic_columns_are_set_correctly()); lp_assert(this->non_basic_columns_are_set_correctly());
this->set_status(UNKNOWN); this->set_status(UNKNOWN);
solve(); solve();
} }
@ -1095,8 +1095,8 @@ void lp_primal_core_solver<T, X>::init_infeasibility_costs_for_changed_basis_onl
template <typename T, typename X> template <typename T, typename X>
void lp_primal_core_solver<T, X>::init_infeasibility_costs() { void lp_primal_core_solver<T, X>::init_infeasibility_costs() {
lean_assert(this->m_x.size() >= this->m_n()); lp_assert(this->m_x.size() >= this->m_n());
lean_assert(this->m_column_types.size() >= this->m_n()); lp_assert(this->m_column_types.size() >= this->m_n());
for (unsigned j = this->m_n(); j--;) for (unsigned j = this->m_n(); j--;)
init_infeasibility_cost_for_column(j); init_infeasibility_cost_for_column(j);
this->m_using_infeas_costs = true; this->m_using_infeas_costs = true;
@ -1138,7 +1138,7 @@ lp_primal_core_solver<T, X>::get_infeasibility_cost_for_column(unsigned j) const
ret = numeric_traits<T>::zero(); ret = numeric_traits<T>::zero();
break; break;
default: default:
lean_assert(false); lp_assert(false);
ret = numeric_traits<T>::zero(); // does not matter ret = numeric_traits<T>::zero(); // does not matter
break; break;
} }
@ -1192,7 +1192,7 @@ lp_primal_core_solver<T, X>::init_infeasibility_cost_for_column(unsigned j) {
this->m_costs[j] = numeric_traits<T>::zero(); this->m_costs[j] = numeric_traits<T>::zero();
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
@ -1223,7 +1223,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::print_column
case column_type::free_column: case column_type::free_column:
out << "( _" << this->m_x[j] << "_)" << std::endl; out << "( _" << this->m_x[j] << "_)" << std::endl;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
@ -1262,7 +1262,7 @@ template <typename T, typename X> std::string lp_primal_core_solver<T, X>::break
case upper_break: return "upper_break"; case upper_break: return "upper_break";
case fixed_break: return "fixed_break"; case fixed_break: return "fixed_break";
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
return "type is not found"; return "type is not found";
@ -1275,7 +1275,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::print_breakp
template <typename T, typename X> template <typename T, typename X>
void lp_primal_core_solver<T, X>::init_reduced_costs() { void lp_primal_core_solver<T, X>::init_reduced_costs() {
lean_assert(!this->use_tableau()); lp_assert(!this->use_tableau());
if (this->current_x_is_infeasible() && !this->m_using_infeas_costs) { if (this->current_x_is_infeasible() && !this->m_using_infeas_costs) {
init_infeasibility_costs(); init_infeasibility_costs();
} else if (this->current_x_is_feasible() && this->m_using_infeas_costs) { } else if (this->current_x_is_feasible() && this->m_using_infeas_costs) {
@ -1290,12 +1290,12 @@ void lp_primal_core_solver<T, X>::init_reduced_costs() {
template <typename T, typename X> void lp_primal_core_solver<T, X>::change_slope_on_breakpoint(unsigned entering, breakpoint<X> * b, T & slope_at_entering) { template <typename T, typename X> void lp_primal_core_solver<T, X>::change_slope_on_breakpoint(unsigned entering, breakpoint<X> * b, T & slope_at_entering) {
if (b->m_j == entering) { if (b->m_j == entering) {
lean_assert(b->m_type != fixed_break && (!is_zero(b->m_delta))); lp_assert(b->m_type != fixed_break && (!is_zero(b->m_delta)));
slope_at_entering += m_sign_of_entering_delta; slope_at_entering += m_sign_of_entering_delta;
return; return;
} }
lean_assert(this->m_basis_heading[b->m_j] >= 0); lp_assert(this->m_basis_heading[b->m_j] >= 0);
unsigned i_row = this->m_basis_heading[b->m_j]; unsigned i_row = this->m_basis_heading[b->m_j];
const T & d = - this->m_ed[i_row]; const T & d = - this->m_ed[i_row];
if (numeric_traits<T>::is_zero(d)) return; if (numeric_traits<T>::is_zero(d)) return;
@ -1314,13 +1314,13 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::change_sl
slope_at_entering += delta; slope_at_entering += delta;
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::try_add_breakpoint_in_row(unsigned i) { template <typename T, typename X> void lp_primal_core_solver<T, X>::try_add_breakpoint_in_row(unsigned i) {
lean_assert(i < this->m_m()); lp_assert(i < this->m_m());
const T & d = this->m_ed[i]; // the coefficient before m_entering in the i-th row const T & d = this->m_ed[i]; // the coefficient before m_entering in the i-th row
if (d == 0) return; // the change of x[m_entering] will not change the corresponding basis x if (d == 0) return; // the change of x[m_entering] will not change the corresponding basis x
unsigned j = this->m_basis[i]; unsigned j = this->m_basis[i];
@ -1342,7 +1342,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::try_add_b
case column_type::free_column: case column_type::free_column:
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
} }
@ -1366,7 +1366,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::print_bound_
out << "inf, inf" << std::endl; out << "inf, inf" << std::endl;
break; break;
default: default:
lean_assert(false); lp_assert(false);
break; break;
} }
} }

View file

@ -10,18 +10,18 @@
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
#include "util/lp/lp_primal_core_solver.hpp" #include "util/lp/lp_primal_core_solver.hpp"
#include "util/lp/lp_primal_core_solver_tableau.hpp" #include "util/lp/lp_primal_core_solver_tableau.hpp"
namespace lean { namespace lp {
template void lp_primal_core_solver<double, double>::find_feasible_solution(); template void lp_primal_core_solver<double, double>::find_feasible_solution();
template void lean::lp_primal_core_solver<lean::mpq, lean::numeric_pair<lean::mpq> >::find_feasible_solution(); template void lp::lp_primal_core_solver<lp::mpq, lp::numeric_pair<lp::mpq> >::find_feasible_solution();
template unsigned lp_primal_core_solver<double, double>::solve(); template unsigned lp_primal_core_solver<double, double>::solve();
template unsigned lp_primal_core_solver<double, double>::solve_with_tableau(); template unsigned lp_primal_core_solver<double, double>::solve_with_tableau();
template unsigned lp_primal_core_solver<mpq, mpq>::solve(); template unsigned lp_primal_core_solver<mpq, mpq>::solve();
template unsigned lp_primal_core_solver<mpq, numeric_pair<mpq> >::solve(); template unsigned lp_primal_core_solver<mpq, numeric_pair<mpq> >::solve();
template void lean::lp_primal_core_solver<double, double>::clear_breakpoints(); template void lp::lp_primal_core_solver<double, double>::clear_breakpoints();
template bool lean::lp_primal_core_solver<lean::mpq, lean::mpq>::update_basis_and_x_tableau(int, int, lean::mpq const&); template bool lp::lp_primal_core_solver<lp::mpq, lp::mpq>::update_basis_and_x_tableau(int, int, lp::mpq const&);
template bool lean::lp_primal_core_solver<double, double>::update_basis_and_x_tableau(int, int, double const&); template bool lp::lp_primal_core_solver<double, double>::update_basis_and_x_tableau(int, int, double const&);
template bool lean::lp_primal_core_solver<lean::mpq, lean::numeric_pair<lean::mpq> >::update_basis_and_x_tableau(int, int, lean::numeric_pair<lean::mpq> const&); template bool lp::lp_primal_core_solver<lp::mpq, lp::numeric_pair<lp::mpq> >::update_basis_and_x_tableau(int, int, lp::numeric_pair<lp::mpq> const&);
} }

View file

@ -4,7 +4,7 @@
*/ */
// this is a part of lp_primal_core_solver that deals with the tableau // this is a part of lp_primal_core_solver that deals with the tableau
#include "util/lp/lp_primal_core_solver.h" #include "util/lp/lp_primal_core_solver.h"
namespace lean { namespace lp {
template <typename T, typename X> void lp_primal_core_solver<T, X>::one_iteration_tableau() { template <typename T, typename X> void lp_primal_core_solver<T, X>::one_iteration_tableau() {
int entering = choose_entering_column_tableau(); int entering = choose_entering_column_tableau();
if (entering == -1) { if (entering == -1) {
@ -13,7 +13,7 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::one_iteratio
else { else {
advance_on_entering_tableau(entering); advance_on_entering_tableau(entering);
} }
lean_assert(this->inf_set_is_correct()); lp_assert(this->inf_set_is_correct());
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::advance_on_entering_tableau(int entering) { template <typename T, typename X> void lp_primal_core_solver<T, X>::advance_on_entering_tableau(int entering) {
@ -37,7 +37,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::choose_enteri
//this moment m_y = cB * B(-1) //this moment m_y = cB * B(-1)
unsigned number_of_benefitial_columns_to_go_over = get_number_of_non_basic_column_to_try_for_enter(); unsigned number_of_benefitial_columns_to_go_over = get_number_of_non_basic_column_to_try_for_enter();
lean_assert(numeric_traits<T>::precise()); lp_assert(numeric_traits<T>::precise());
if (number_of_benefitial_columns_to_go_over == 0) if (number_of_benefitial_columns_to_go_over == 0)
return -1; return -1;
if (this->m_basis_sort_counter == 0) { if (this->m_basis_sort_counter == 0) {
@ -149,7 +149,7 @@ unsigned lp_primal_core_solver<T, X>::solve_with_tableau() {
break; break;
case UNSTABLE: case UNSTABLE:
lean_assert(! (numeric_traits<T>::precise())); lp_assert(! (numeric_traits<T>::precise()));
this->init_lu(); this->init_lu();
if (this->m_factorization->get_status() != LU_status::OK) { if (this->m_factorization->get_status() != LU_status::OK) {
this->set_status(FLOATING_POINT_ERROR); this->set_status(FLOATING_POINT_ERROR);
@ -175,7 +175,7 @@ unsigned lp_primal_core_solver<T, X>::solve_with_tableau() {
&& &&
!(this->current_x_is_feasible() && this->m_look_for_feasible_solution_only)); !(this->current_x_is_feasible() && this->m_look_for_feasible_solution_only));
lean_assert(this->get_status() == FLOATING_POINT_ERROR lp_assert(this->get_status() == FLOATING_POINT_ERROR
|| ||
this->current_x_is_feasible() == false this->current_x_is_feasible() == false
|| ||
@ -184,13 +184,13 @@ unsigned lp_primal_core_solver<T, X>::solve_with_tableau() {
} }
template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_entering_and_leaving_tableau(int entering, int leaving, X & t) { template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_entering_and_leaving_tableau(int entering, int leaving, X & t) {
lean_assert(this->A_mult_x_is_off() == false); lp_assert(this->A_mult_x_is_off() == false);
lean_assert(leaving >= 0 && entering >= 0); lp_assert(leaving >= 0 && entering >= 0);
lean_assert((this->m_settings.simplex_strategy() == lp_assert((this->m_settings.simplex_strategy() ==
simplex_strategy_enum::tableau_rows) || simplex_strategy_enum::tableau_rows) ||
m_non_basis_list.back() == static_cast<unsigned>(entering)); m_non_basis_list.back() == static_cast<unsigned>(entering));
lean_assert(this->m_using_infeas_costs || !is_neg(t)); lp_assert(this->m_using_infeas_costs || !is_neg(t));
lean_assert(entering != leaving || !is_zero(t)); // otherwise nothing changes lp_assert(entering != leaving || !is_zero(t)); // otherwise nothing changes
if (entering == leaving) { if (entering == leaving) {
advance_on_entering_equal_leaving_tableau(entering, t); advance_on_entering_equal_leaving_tableau(entering, t);
return; return;
@ -201,7 +201,7 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_en
t = -t; t = -t;
} }
this->update_basis_and_x_tableau(entering, leaving, t); this->update_basis_and_x_tableau(entering, leaving, t);
lean_assert(this->A_mult_x_is_off() == false); lp_assert(this->A_mult_x_is_off() == false);
this->iters_with_no_cost_growing() = 0; this->iters_with_no_cost_growing() = 0;
} else { } else {
this->pivot_column_tableau(entering, this->m_basis_heading[leaving]); this->pivot_column_tableau(entering, this->m_basis_heading[leaving]);
@ -216,7 +216,7 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_en
this->init_reduced_costs_tableau(); this->init_reduced_costs_tableau();
} }
lean_assert(!need_to_switch_costs()); lp_assert(!need_to_switch_costs());
std::list<unsigned>::iterator it = m_non_basis_list.end(); std::list<unsigned>::iterator it = m_non_basis_list.end();
it--; it--;
* it = static_cast<unsigned>(leaving); * it = static_cast<unsigned>(leaving);
@ -225,7 +225,7 @@ template <typename T, typename X>void lp_primal_core_solver<T, X>::advance_on_en
template <typename T, typename X> template <typename T, typename X>
void lp_primal_core_solver<T, X>::advance_on_entering_equal_leaving_tableau(int entering, X & t) { void lp_primal_core_solver<T, X>::advance_on_entering_equal_leaving_tableau(int entering, X & t) {
lean_assert(!this->A_mult_x_is_off() ); lp_assert(!this->A_mult_x_is_off() );
this->update_x_tableau(entering, t * m_sign_of_entering_delta); this->update_x_tableau(entering, t * m_sign_of_entering_delta);
if (this->m_look_for_feasible_solution_only && this->current_x_is_feasible()) if (this->m_look_for_feasible_solution_only && this->current_x_is_feasible())
return; return;
@ -246,7 +246,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
const column_cell & c = col[k]; const column_cell & c = col[k];
unsigned i = c.m_i; unsigned i = c.m_i;
const T & ed = this->m_A.get_val(c); const T & ed = this->m_A.get_val(c);
lean_assert(!numeric_traits<T>::is_zero(ed)); lp_assert(!numeric_traits<T>::is_zero(ed));
unsigned j = this->m_basis[i]; unsigned j = this->m_basis[i];
limit_theta_on_basis_column(j, - ed * m_sign_of_entering_delta, t, unlimited); limit_theta_on_basis_column(j, - ed * m_sign_of_entering_delta, t, unlimited);
if (!unlimited) { if (!unlimited) {
@ -265,7 +265,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
const column_cell & c = col[k]; const column_cell & c = col[k];
unsigned i = c.m_i; unsigned i = c.m_i;
const T & ed = this->m_A.get_val(c); const T & ed = this->m_A.get_val(c);
lean_assert(!numeric_traits<T>::is_zero(ed)); lp_assert(!numeric_traits<T>::is_zero(ed));
unsigned j = this->m_basis[i]; unsigned j = this->m_basis[i];
unlimited = true; unlimited = true;
limit_theta_on_basis_column(j, -ed * m_sign_of_entering_delta, ratio, unlimited); limit_theta_on_basis_column(j, -ed * m_sign_of_entering_delta, ratio, unlimited);
@ -298,12 +298,12 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>::init_run_tableau() { template <typename T, typename X> void lp_primal_core_solver<T, X>::init_run_tableau() {
// print_matrix(&(this->m_A), std::cout); // print_matrix(&(this->m_A), std::cout);
lean_assert(this->A_mult_x_is_off() == false); lp_assert(this->A_mult_x_is_off() == false);
lean_assert(basis_columns_are_set_correctly()); lp_assert(basis_columns_are_set_correctly());
this->m_basis_sort_counter = 0; // to initiate the sort of the basis this->m_basis_sort_counter = 0; // to initiate the sort of the basis
this->set_total_iterations(0); this->set_total_iterations(0);
this->iters_with_no_cost_growing() = 0; this->iters_with_no_cost_growing() = 0;
lean_assert(this->inf_set_is_correct()); lp_assert(this->inf_set_is_correct());
if (this->current_x_is_feasible() && this->m_look_for_feasible_solution_only) if (this->current_x_is_feasible() && this->m_look_for_feasible_solution_only)
return; return;
if (this->m_settings.backup_costs) if (this->m_settings.backup_costs)
@ -317,13 +317,13 @@ template <typename T, typename X> void lp_primal_core_solver<T, X>::init_run_tab
} }
if (this->m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows) if (this->m_settings.simplex_strategy() == simplex_strategy_enum::tableau_rows)
init_tableau_rows(); init_tableau_rows();
lean_assert(this->reduced_costs_are_correct_tableau()); lp_assert(this->reduced_costs_are_correct_tableau());
lean_assert(!this->need_to_pivot_to_basis_tableau()); lp_assert(!this->need_to_pivot_to_basis_tableau());
} }
template <typename T, typename X> bool lp_primal_core_solver<T, X>:: template <typename T, typename X> bool lp_primal_core_solver<T, X>::
update_basis_and_x_tableau(int entering, int leaving, X const & tt) { update_basis_and_x_tableau(int entering, int leaving, X const & tt) {
lean_assert(this->use_tableau()); lp_assert(this->use_tableau());
update_x_tableau(entering, tt); update_x_tableau(entering, tt);
this->pivot_column_tableau(entering, this->m_basis_heading[leaving]); this->pivot_column_tableau(entering, this->m_basis_heading[leaving]);
this->change_basis(entering, leaving); this->change_basis(entering, leaving);
@ -340,8 +340,8 @@ update_x_tableau(unsigned entering, const X& delta) {
} }
} else { // m_using_infeas_costs == true } else { // m_using_infeas_costs == true
this->m_x[entering] += delta; this->m_x[entering] += delta;
lean_assert(this->column_is_feasible(entering)); lp_assert(this->column_is_feasible(entering));
lean_assert(this->m_costs[entering] == zero_of_type<T>()); lp_assert(this->m_costs[entering] == zero_of_type<T>());
// m_d[entering] can change because of the cost change for basic columns. // m_d[entering] can change because of the cost change for basic columns.
for (const auto & c : this->m_A.m_columns[entering]) { for (const auto & c : this->m_A.m_columns[entering]) {
unsigned i = c.m_i; unsigned i = c.m_i;
@ -354,13 +354,13 @@ update_x_tableau(unsigned entering, const X& delta) {
this->m_inf_set.insert(j); this->m_inf_set.insert(j);
} }
} }
lean_assert(this->A_mult_x_is_off() == false); lp_assert(this->A_mult_x_is_off() == false);
} }
template <typename T, typename X> void lp_primal_core_solver<T, X>:: template <typename T, typename X> void lp_primal_core_solver<T, X>::
update_inf_cost_for_column_tableau(unsigned j) { update_inf_cost_for_column_tableau(unsigned j) {
lean_assert(this->m_settings.simplex_strategy() != simplex_strategy_enum::tableau_rows); lp_assert(this->m_settings.simplex_strategy() != simplex_strategy_enum::tableau_rows);
lean_assert(this->m_using_infeas_costs); lp_assert(this->m_using_infeas_costs);
T new_cost = get_infeasibility_cost_for_column(j); T new_cost = get_infeasibility_cost_for_column(j);
T delta = this->m_costs[j] - new_cost; T delta = this->m_costs[j] - new_cost;
if (is_zero(delta)) if (is_zero(delta))

View file

@ -12,7 +12,7 @@
#include "util/lp/lp_primal_core_solver.h" #include "util/lp/lp_primal_core_solver.h"
#include "util/lp/lp_solver.h" #include "util/lp/lp_solver.h"
#include "util/lp/iterator_on_row.h" #include "util/lp/iterator_on_row.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
class lp_primal_simplex: public lp_solver<T, X> { class lp_primal_simplex: public lp_solver<T, X> {
lp_primal_core_solver<T, X> * m_core_solver; lp_primal_core_solver<T, X> * m_core_solver;

View file

@ -6,7 +6,7 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lp_primal_simplex.h" #include "util/lp/lp_primal_simplex.h"
namespace lean { namespace lp {
template <typename T, typename X> void lp_primal_simplex<T, X>::fill_costs_and_x_for_first_stage_solver(unsigned original_number_of_columns) { template <typename T, typename X> void lp_primal_simplex<T, X>::fill_costs_and_x_for_first_stage_solver(unsigned original_number_of_columns) {
unsigned slack_var = original_number_of_columns; unsigned slack_var = original_number_of_columns;
unsigned artificial = original_number_of_columns + this->m_slacks; unsigned artificial = original_number_of_columns + this->m_slacks;
@ -61,7 +61,7 @@ template <typename T, typename X> void lp_primal_simplex<T, X>::fill_costs_and_x
int row, int row,
unsigned & slack_var, unsigned & slack_var,
unsigned & artificial) { unsigned & artificial) {
lean_assert(row >= 0 && row < this->row_count()); lp_assert(row >= 0 && row < this->row_count());
auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[row]]; auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[row]];
// we need to bring the program to the form Ax = b // we need to bring the program to the form Ax = b
T rs = this->m_b[row]; T rs = this->m_b[row];
@ -86,7 +86,7 @@ template <typename T, typename X> void lp_primal_simplex<T, X>::fill_costs_and_x
(*this->m_A)(row, slack_var) = - numeric_traits<T>::one(); (*this->m_A)(row, slack_var) = - numeric_traits<T>::one();
if (rs > 0) { if (rs > 0) {
lean_assert(numeric_traits<T>::is_zero(this->m_x[slack_var])); lp_assert(numeric_traits<T>::is_zero(this->m_x[slack_var]));
// adding one artificial // adding one artificial
this->m_column_types[artificial] = column_type::low_bound; this->m_column_types[artificial] = column_type::low_bound;
(*this->m_A)(row, artificial) = numeric_traits<T>::one(); (*this->m_A)(row, artificial) = numeric_traits<T>::one();
@ -108,7 +108,7 @@ template <typename T, typename X> void lp_primal_simplex<T, X>::fill_costs_and_x
if (rs < 0) { if (rs < 0) {
// adding one artificial // adding one artificial
lean_assert(numeric_traits<T>::is_zero(this->m_x[slack_var])); lp_assert(numeric_traits<T>::is_zero(this->m_x[slack_var]));
this->m_column_types[artificial] = column_type::low_bound; this->m_column_types[artificial] = column_type::low_bound;
(*this->m_A)(row, artificial) = - numeric_traits<T>::one(); (*this->m_A)(row, artificial) = - numeric_traits<T>::one();
this->m_costs[artificial] = artificial_cost; this->m_costs[artificial] = artificial_cost;
@ -157,7 +157,7 @@ template <typename T, typename X> void lp_primal_simplex<T, X>::find_maximal_sol
return; return;
} }
this->cleanup(); this->clpup();
this->fill_matrix_A_and_init_right_side(); this->fill_matrix_A_and_init_right_side();
if (this->m_status == lp_status::INFEASIBLE) { if (this->m_status == lp_status::INFEASIBLE) {
return; return;
@ -177,12 +177,12 @@ template <typename T, typename X> void lp_primal_simplex<T, X>::fill_A_x_and_bas
} }
template <typename T, typename X> void lp_primal_simplex<T, X>::fill_A_x_and_basis_for_stage_one_total_inf_for_row(unsigned row) { template <typename T, typename X> void lp_primal_simplex<T, X>::fill_A_x_and_basis_for_stage_one_total_inf_for_row(unsigned row) {
lean_assert(row < this->row_count()); lp_assert(row < this->row_count());
auto ext_row_it = this->m_core_solver_rows_to_external_rows.find(row); auto ext_row_it = this->m_core_solver_rows_to_external_rows.find(row);
lean_assert(ext_row_it != this->m_core_solver_rows_to_external_rows.end()); lp_assert(ext_row_it != this->m_core_solver_rows_to_external_rows.end());
unsigned ext_row = ext_row_it->second; unsigned ext_row = ext_row_it->second;
auto constr_it = this->m_constraints.find(ext_row); auto constr_it = this->m_constraints.find(ext_row);
lean_assert(constr_it != this->m_constraints.end()); lp_assert(constr_it != this->m_constraints.end());
auto & constraint = constr_it->second; auto & constraint = constr_it->second;
unsigned j = this->m_A->column_count(); // j is a slack variable unsigned j = this->m_A->column_count(); // j is a slack variable
this->m_A->add_column(); this->m_A->add_column();
@ -209,7 +209,7 @@ template <typename T, typename X> void lp_primal_simplex<T, X>::fill_A_x_and_bas
this->m_upper_bounds[j] = m_low_bounds[j] = zero_of_type<X>(); this->m_upper_bounds[j] = m_low_bounds[j] = zero_of_type<X>();
break; break;
default: default:
lean_unreachable(); lp_unreachable();
} }
} }
@ -281,10 +281,10 @@ template <typename T, typename X> T lp_primal_simplex<T, X>::get_row_value(unsig
T ret = numeric_traits<T>::zero(); T ret = numeric_traits<T>::zero();
for (auto & pair : it->second) { for (auto & pair : it->second) {
auto cit = this->m_map_from_var_index_to_column_info.find(pair.first); auto cit = this->m_map_from_var_index_to_column_info.find(pair.first);
lean_assert(cit != this->m_map_from_var_index_to_column_info.end()); lp_assert(cit != this->m_map_from_var_index_to_column_info.end());
column_info<T> * ci = cit->second; column_info<T> * ci = cit->second;
auto sol_it = solution.find(ci->get_name()); auto sol_it = solution.find(ci->get_name());
lean_assert(sol_it != solution.end()); lp_assert(sol_it != solution.end());
T column_val = sol_it->second; T column_val = sol_it->second;
if (out != nullptr) { if (out != nullptr) {
(*out) << pair.second << "(" << ci->get_name() << "=" << column_val << ") "; (*out) << pair.second << "(" << ci->get_name() << "=" << column_val << ") ";
@ -329,7 +329,7 @@ template <typename T, typename X> bool lp_primal_simplex<T, X>::row_constraint_h
} }
return true;; return true;;
} }
lean_unreachable(); lp_unreachable();
return false; // it is unreachable return false; // it is unreachable
} }

View file

@ -8,13 +8,13 @@
#include "util/vector.h" #include "util/vector.h"
#include <functional> #include <functional>
#include "util/lp/lp_primal_simplex.hpp" #include "util/lp/lp_primal_simplex.hpp"
template bool lean::lp_primal_simplex<double, double>::bounds_hold(std::unordered_map<std::string, double, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, double> > > const&); template bool lp::lp_primal_simplex<double, double>::bounds_hold(std::unordered_map<std::string, double, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, double> > > const&);
template bool lean::lp_primal_simplex<double, double>::row_constraints_hold(std::unordered_map<std::string, double, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, double> > > const&); template bool lp::lp_primal_simplex<double, double>::row_constraints_hold(std::unordered_map<std::string, double, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, double> > > const&);
template double lean::lp_primal_simplex<double, double>::get_current_cost() const; template double lp::lp_primal_simplex<double, double>::get_current_cost() const;
template double lean::lp_primal_simplex<double, double>::get_column_value(unsigned int) const; template double lp::lp_primal_simplex<double, double>::get_column_value(unsigned int) const;
template lean::lp_primal_simplex<double, double>::~lp_primal_simplex(); template lp::lp_primal_simplex<double, double>::~lp_primal_simplex();
template lean::lp_primal_simplex<lean::mpq, lean::mpq>::~lp_primal_simplex(); template lp::lp_primal_simplex<lp::mpq, lp::mpq>::~lp_primal_simplex();
template lean::mpq lean::lp_primal_simplex<lean::mpq, lean::mpq>::get_current_cost() const; template lp::mpq lp::lp_primal_simplex<lp::mpq, lp::mpq>::get_current_cost() const;
template lean::mpq lean::lp_primal_simplex<lean::mpq, lean::mpq>::get_column_value(unsigned int) const; template lp::mpq lp::lp_primal_simplex<lp::mpq, lp::mpq>::get_column_value(unsigned int) const;
template void lean::lp_primal_simplex<double, double>::find_maximal_solution(); template void lp::lp_primal_simplex<double, double>::find_maximal_solution();
template void lean::lp_primal_simplex<lean::mpq, lean::mpq>::find_maximal_solution(); template void lp::lp_primal_simplex<lp::mpq, lp::mpq>::find_maximal_solution();

View file

@ -12,7 +12,7 @@
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/stopwatch.h" #include "util/stopwatch.h"
namespace lean { namespace lp {
typedef unsigned var_index; typedef unsigned var_index;
typedef unsigned constraint_index; typedef unsigned constraint_index;
typedef unsigned row_index; typedef unsigned row_index;
@ -374,7 +374,7 @@ inline void print_blanks(int n, std::ostream & out) {
// after a push of the last element we ensure that the vector increases // after a push of the last element we ensure that the vector increases
// we also suppose that before the last push the vector was increasing // we also suppose that before the last push the vector was increasing
inline void ensure_increasing(vector<unsigned> & v) { inline void ensure_increasing(vector<unsigned> & v) {
lean_assert(v.size() > 0); lp_assert(v.size() > 0);
unsigned j = v.size() - 1; unsigned j = v.size() - 1;
for (; j > 0; j-- ) for (; j > 0; j-- )
if (v[j] <= v[j - 1]) { if (v[j] <= v[j - 1]) {

View file

@ -6,7 +6,7 @@
#include <string> #include <string>
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
namespace lean { namespace lp {
std::string column_type_to_string(column_type t) { std::string column_type_to_string(column_type t) {
switch (t) { switch (t) {
case column_type::fixed: return "fixed"; case column_type::fixed: return "fixed";
@ -14,7 +14,7 @@ std::string column_type_to_string(column_type t) {
case column_type::low_bound: return "low_bound"; case column_type::low_bound: return "low_bound";
case column_type::upper_bound: return "upper_bound"; case column_type::upper_bound: return "upper_bound";
case column_type::free_column: return "free_column"; case column_type::free_column: return "free_column";
default: lean_unreachable(); default: lp_unreachable();
} }
return "unknown"; // it is unreachable return "unknown"; // it is unreachable
} }
@ -34,7 +34,7 @@ const char* lp_status_to_string(lp_status status) {
case EMPTY: return "EMPTY"; case EMPTY: return "EMPTY";
case UNSTABLE: return "UNSTABLE"; case UNSTABLE: return "UNSTABLE";
default: default:
lean_unreachable(); lp_unreachable();
} }
return "UNKNOWN"; // it is unreachable return "UNKNOWN"; // it is unreachable
} }
@ -49,7 +49,7 @@ lp_status lp_status_from_string(std::string status) {
if (status == "TIME_EXHAUSTED") return lp_status::TIME_EXHAUSTED; if (status == "TIME_EXHAUSTED") return lp_status::TIME_EXHAUSTED;
if (status == "ITERATIONS_EXHAUSTED") return lp_status::ITERATIONS_EXHAUSTED; if (status == "ITERATIONS_EXHAUSTED") return lp_status::ITERATIONS_EXHAUSTED;
if (status == "EMPTY") return lp_status::EMPTY; if (status == "EMPTY") return lp_status::EMPTY;
lean_unreachable(); lp_unreachable();
return lp_status::UNKNOWN; // it is unreachable return lp_status::UNKNOWN; // it is unreachable
} }

View file

@ -5,6 +5,6 @@
#include <memory> #include <memory>
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lp_settings.hpp" #include "util/lp/lp_settings.hpp"
template bool lean::vectors_are_equal<double>(vector<double> const&, vector<double> const&); template bool lp::vectors_are_equal<double>(vector<double> const&, vector<double> const&);
template bool lean::vectors_are_equal<lean::mpq>(vector<lean::mpq > const&, vector<lean::mpq> const&); template bool lp::vectors_are_equal<lp::mpq>(vector<lp::mpq > const&, vector<lp::mpq> const&);

View file

@ -15,7 +15,7 @@
#include "util/lp/scaler.h" #include "util/lp/scaler.h"
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
#include "util/lp/bound_analyzer_on_row.h" #include "util/lp/bound_analyzer_on_row.h"
namespace lean { namespace lp {
enum lp_relation { enum lp_relation {
Less_or_equal, Less_or_equal,
Equal, Equal,
@ -205,7 +205,7 @@ protected:
unsigned try_to_remove_some_rows(); unsigned try_to_remove_some_rows();
void cleanup(); void clpup();
void map_external_rows_to_core_solver_rows(); void map_external_rows_to_core_solver_rows();

View file

@ -6,7 +6,7 @@
#include <algorithm> #include <algorithm>
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/lp_solver.h" #include "util/lp/lp_solver.h"
namespace lean { namespace lp {
template <typename T, typename X> column_info<T> * lp_solver<T, X>::get_or_create_column_info(unsigned column) { template <typename T, typename X> column_info<T> * lp_solver<T, X>::get_or_create_column_info(unsigned column) {
auto it = m_map_from_var_index_to_column_info.find(column); auto it = m_map_from_var_index_to_column_info.find(column);
return (it == m_map_from_var_index_to_column_info.end())? (m_map_from_var_index_to_column_info[column] = new column_info<T>(static_cast<unsigned>(-1))) : it->second; return (it == m_map_from_var_index_to_column_info.end())? (m_map_from_var_index_to_column_info[column] = new column_info<T>(static_cast<unsigned>(-1))) : it->second;
@ -32,7 +32,7 @@ template <typename T, typename X> T lp_solver<T, X>::get_column_cost_value(unsig
return ci->get_cost() * get_column_value(j); return ci->get_cost() * get_column_value(j);
} }
template <typename T, typename X> void lp_solver<T, X>::add_constraint(lp_relation relation, T right_side, unsigned row_index) { template <typename T, typename X> void lp_solver<T, X>::add_constraint(lp_relation relation, T right_side, unsigned row_index) {
lean_assert(m_constraints.find(row_index) == m_constraints.end()); lp_assert(m_constraints.find(row_index) == m_constraints.end());
lp_constraint<T, X> cs(right_side, relation); lp_constraint<T, X> cs(right_side, relation);
m_constraints[row_index] = cs; m_constraints[row_index] = cs;
} }
@ -158,10 +158,10 @@ template <typename T, typename X> void lp_solver<T, X>::pin_vars_on_row_with_sig
column_info<T> * ci = m_map_from_var_index_to_column_info[j]; column_info<T> * ci = m_map_from_var_index_to_column_info[j];
T a = t.second; T a = t.second;
if (a * sign > numeric_traits<T>::zero()) { if (a * sign > numeric_traits<T>::zero()) {
lean_assert(ci->upper_bound_is_set()); lp_assert(ci->upper_bound_is_set());
ci->set_fixed_value(ci->get_upper_bound()); ci->set_fixed_value(ci->get_upper_bound());
} else { } else {
lean_assert(ci->low_bound_is_set()); lp_assert(ci->low_bound_is_set());
ci->set_fixed_value(ci->get_low_bound()); ci->set_fixed_value(ci->get_low_bound());
} }
} }
@ -328,7 +328,7 @@ template <typename T, typename X> bool lp_solver<T, X>::row_is_obsolete(std::
case lp_relation::Less_or_equal: case lp_relation::Less_or_equal:
return row_le_is_obsolete(row, row_index); return row_le_is_obsolete(row, row_index);
} }
lean_unreachable(); lp_unreachable();
return false; // it is unreachable return false; // it is unreachable
} }
@ -343,7 +343,7 @@ template <typename T, typename X> void lp_solver<T, X>::remove_fixed_or_zero_col
vector<unsigned> removed; vector<unsigned> removed;
for (auto & col : row) { for (auto & col : row) {
unsigned j = col.first; unsigned j = col.first;
lean_assert(m_map_from_var_index_to_column_info.find(j) != m_map_from_var_index_to_column_info.end()); lp_assert(m_map_from_var_index_to_column_info.find(j) != m_map_from_var_index_to_column_info.end());
column_info<T> * ci = m_map_from_var_index_to_column_info[j]; column_info<T> * ci = m_map_from_var_index_to_column_info[j];
if (ci->is_fixed()) { if (ci->is_fixed()) {
removed.push_back(j); removed.push_back(j);
@ -381,7 +381,7 @@ template <typename T, typename X> unsigned lp_solver<T, X>::try_to_remove_some_r
return static_cast<unsigned>(rows_to_delete.size()); return static_cast<unsigned>(rows_to_delete.size());
} }
template <typename T, typename X> void lp_solver<T, X>::cleanup() { template <typename T, typename X> void lp_solver<T, X>::clpup() {
int n = 0; // number of deleted rows int n = 0; // number of deleted rows
int d; int d;
while ((d = try_to_remove_some_rows() > 0)) while ((d = try_to_remove_some_rows() > 0))
@ -412,7 +412,7 @@ template <typename T, typename X> void lp_solver<T, X>::map_external_columns_to_
} }
unsigned j = col.first; unsigned j = col.first;
auto column_info_it = m_map_from_var_index_to_column_info.find(j); auto column_info_it = m_map_from_var_index_to_column_info.find(j);
lean_assert(column_info_it != m_map_from_var_index_to_column_info.end()); lp_assert(column_info_it != m_map_from_var_index_to_column_info.end());
auto j_column = column_info_it->second->get_column_index(); auto j_column = column_info_it->second->get_column_index();
if (!is_valid(j_column)) { // j is a newcomer if (!is_valid(j_column)) { // j is a newcomer
@ -435,14 +435,14 @@ template <typename T, typename X> void lp_solver<T, X>::fill_A_from_A_values() {
m_A = new static_matrix<T, X>(static_cast<unsigned>(m_A_values.size()), number_of_core_structurals()); m_A = new static_matrix<T, X>(static_cast<unsigned>(m_A_values.size()), number_of_core_structurals());
for (auto & t : m_A_values) { for (auto & t : m_A_values) {
auto row_it = m_external_rows_to_core_solver_rows.find(t.first); auto row_it = m_external_rows_to_core_solver_rows.find(t.first);
lean_assert(row_it != m_external_rows_to_core_solver_rows.end()); lp_assert(row_it != m_external_rows_to_core_solver_rows.end());
unsigned row = row_it->second; unsigned row = row_it->second;
for (auto k : t.second) { for (auto k : t.second) {
auto column_info_it = m_map_from_var_index_to_column_info.find(k.first); auto column_info_it = m_map_from_var_index_to_column_info.find(k.first);
lean_assert(column_info_it != m_map_from_var_index_to_column_info.end()); lp_assert(column_info_it != m_map_from_var_index_to_column_info.end());
column_info<T> *ci = column_info_it->second; column_info<T> *ci = column_info_it->second;
unsigned col = ci->get_column_index(); unsigned col = ci->get_column_index();
lean_assert(is_valid(col)); lp_assert(is_valid(col));
bool col_is_flipped = m_map_from_var_index_to_column_info[k.first]->is_flipped(); bool col_is_flipped = m_map_from_var_index_to_column_info[k.first]->is_flipped();
if (!col_is_flipped) { if (!col_is_flipped) {
(*m_A)(row, col) = k.second; (*m_A)(row, col) = k.second;
@ -456,7 +456,7 @@ template <typename T, typename X> void lp_solver<T, X>::fill_A_from_A_values() {
template <typename T, typename X> void lp_solver<T, X>::fill_matrix_A_and_init_right_side() { template <typename T, typename X> void lp_solver<T, X>::fill_matrix_A_and_init_right_side() {
map_external_rows_to_core_solver_rows(); map_external_rows_to_core_solver_rows();
map_external_columns_to_core_solver_columns(); map_external_columns_to_core_solver_columns();
lean_assert(m_A == nullptr); lp_assert(m_A == nullptr);
fill_A_from_A_values(); fill_A_from_A_values();
m_b.resize(m_A->row_count()); m_b.resize(m_A->row_count());
} }
@ -468,7 +468,7 @@ template <typename T, typename X> void lp_solver<T, X>::count_slacks_and_artific
} }
template <typename T, typename X> void lp_solver<T, X>::count_slacks_and_artificials_for_row(unsigned i) { template <typename T, typename X> void lp_solver<T, X>::count_slacks_and_artificials_for_row(unsigned i) {
lean_assert(this->m_constraints.find(this->m_core_solver_rows_to_external_rows[i]) != this->m_constraints.end()); lp_assert(this->m_constraints.find(this->m_core_solver_rows_to_external_rows[i]) != this->m_constraints.end());
auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[i]]; auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[i]];
switch (constraint.m_relation) { switch (constraint.m_relation) {
case Equal: case Equal:
@ -504,7 +504,7 @@ template <typename T, typename X> T lp_solver<T, X>::low_bound_shift_for_row(
template <typename T, typename X> void lp_solver<T, X>::fill_m_b() { template <typename T, typename X> void lp_solver<T, X>::fill_m_b() {
for (int i = this->row_count() - 1; i >= 0; i--) { for (int i = this->row_count() - 1; i >= 0; i--) {
lean_assert(this->m_constraints.find(this->m_core_solver_rows_to_external_rows[i]) != this->m_constraints.end()); lp_assert(this->m_constraints.find(this->m_core_solver_rows_to_external_rows[i]) != this->m_constraints.end());
unsigned external_i = this->m_core_solver_rows_to_external_rows[i]; unsigned external_i = this->m_core_solver_rows_to_external_rows[i];
auto & constraint = this->m_constraints[external_i]; auto & constraint = this->m_constraints[external_i];
this->m_b[i] = constraint.m_rs - low_bound_shift_for_row(external_i); this->m_b[i] = constraint.m_rs - low_bound_shift_for_row(external_i);
@ -542,13 +542,13 @@ template <typename T, typename X> T lp_solver<T, X>::get_column_value_with_core_
template <typename T, typename X> void lp_solver<T, X>::set_scaled_cost(unsigned j) { template <typename T, typename X> void lp_solver<T, X>::set_scaled_cost(unsigned j) {
// grab original costs but modify it with the column scales // grab original costs but modify it with the column scales
lean_assert(j < this->m_column_scale.size()); lp_assert(j < this->m_column_scale.size());
column_info<T> * ci = this->m_map_from_var_index_to_column_info[this->m_core_solver_columns_to_external_columns[j]]; column_info<T> * ci = this->m_map_from_var_index_to_column_info[this->m_core_solver_columns_to_external_columns[j]];
T cost = ci->get_cost(); T cost = ci->get_cost();
if (ci->is_flipped()){ if (ci->is_flipped()){
cost *= -1; cost *= -1;
} }
lean_assert(ci->is_fixed() == false); lp_assert(ci->is_fixed() == false);
this->m_costs[j] = cost * this->m_column_scale[j]; this->m_costs[j] = cost * this->m_column_scale[j];
} }
} }

View file

@ -4,37 +4,37 @@
*/ */
#include <string> #include <string>
#include "util/lp/lp_solver.hpp" #include "util/lp/lp_solver.hpp"
template void lean::lp_solver<double, double>::add_constraint(lean::lp_relation, double, unsigned int); template void lp::lp_solver<double, double>::add_constraint(lp::lp_relation, double, unsigned int);
template void lean::lp_solver<double, double>::cleanup(); template void lp::lp_solver<double, double>::clpup();
template void lean::lp_solver<double, double>::count_slacks_and_artificials(); template void lp::lp_solver<double, double>::count_slacks_and_artificials();
template void lean::lp_solver<double, double>::fill_m_b(); template void lp::lp_solver<double, double>::fill_m_b();
template void lean::lp_solver<double, double>::fill_matrix_A_and_init_right_side(); template void lp::lp_solver<double, double>::fill_matrix_A_and_init_right_side();
template void lean::lp_solver<double, double>::flip_costs(); template void lp::lp_solver<double, double>::flip_costs();
template double lean::lp_solver<double, double>::get_column_cost_value(unsigned int, lean::column_info<double>*) const; template double lp::lp_solver<double, double>::get_column_cost_value(unsigned int, lp::column_info<double>*) const;
template int lean::lp_solver<double, double>::get_column_index_by_name(std::string) const; template int lp::lp_solver<double, double>::get_column_index_by_name(std::string) const;
template double lean::lp_solver<double, double>::get_column_value_with_core_solver(unsigned int, lean::lp_core_solver_base<double, double>*) const; template double lp::lp_solver<double, double>::get_column_value_with_core_solver(unsigned int, lp::lp_core_solver_base<double, double>*) const;
template lean::column_info<double>* lean::lp_solver<double, double>::get_or_create_column_info(unsigned int); template lp::column_info<double>* lp::lp_solver<double, double>::get_or_create_column_info(unsigned int);
template void lean::lp_solver<double, double>::give_symbolic_name_to_column(std::string, unsigned int); template void lp::lp_solver<double, double>::give_symbolic_name_to_column(std::string, unsigned int);
template void lean::lp_solver<double, double>::print_statistics_on_A(std::ostream & out); template void lp::lp_solver<double, double>::print_statistics_on_A(std::ostream & out);
template bool lean::lp_solver<double, double>::problem_is_empty(); template bool lp::lp_solver<double, double>::problem_is_empty();
template void lean::lp_solver<double, double>::scale(); template void lp::lp_solver<double, double>::scale();
template void lean::lp_solver<double, double>::set_scaled_cost(unsigned int); template void lp::lp_solver<double, double>::set_scaled_cost(unsigned int);
template lean::lp_solver<double, double>::~lp_solver(); template lp::lp_solver<double, double>::~lp_solver();
template void lean::lp_solver<lean::mpq, lean::mpq>::add_constraint(lean::lp_relation, lean::mpq, unsigned int); template void lp::lp_solver<lp::mpq, lp::mpq>::add_constraint(lp::lp_relation, lp::mpq, unsigned int);
template void lean::lp_solver<lean::mpq, lean::mpq>::cleanup(); template void lp::lp_solver<lp::mpq, lp::mpq>::clpup();
template void lean::lp_solver<lean::mpq, lean::mpq>::count_slacks_and_artificials(); template void lp::lp_solver<lp::mpq, lp::mpq>::count_slacks_and_artificials();
template void lean::lp_solver<lean::mpq, lean::mpq>::fill_m_b(); template void lp::lp_solver<lp::mpq, lp::mpq>::fill_m_b();
template void lean::lp_solver<lean::mpq, lean::mpq>::fill_matrix_A_and_init_right_side(); template void lp::lp_solver<lp::mpq, lp::mpq>::fill_matrix_A_and_init_right_side();
template void lean::lp_solver<lean::mpq, lean::mpq>::flip_costs(); template void lp::lp_solver<lp::mpq, lp::mpq>::flip_costs();
template lean::mpq lean::lp_solver<lean::mpq, lean::mpq>::get_column_cost_value(unsigned int, lean::column_info<lean::mpq>*) const; template lp::mpq lp::lp_solver<lp::mpq, lp::mpq>::get_column_cost_value(unsigned int, lp::column_info<lp::mpq>*) const;
template int lean::lp_solver<lean::mpq, lean::mpq>::get_column_index_by_name(std::string) const; template int lp::lp_solver<lp::mpq, lp::mpq>::get_column_index_by_name(std::string) const;
template lean::mpq lean::lp_solver<lean::mpq, lean::mpq>::get_column_value_by_name(std::string) const; template lp::mpq lp::lp_solver<lp::mpq, lp::mpq>::get_column_value_by_name(std::string) const;
template lean::mpq lean::lp_solver<lean::mpq, lean::mpq>::get_column_value_with_core_solver(unsigned int, lean::lp_core_solver_base<lean::mpq, lean::mpq>*) const; template lp::mpq lp::lp_solver<lp::mpq, lp::mpq>::get_column_value_with_core_solver(unsigned int, lp::lp_core_solver_base<lp::mpq, lp::mpq>*) const;
template lean::column_info<lean::mpq>* lean::lp_solver<lean::mpq, lean::mpq>::get_or_create_column_info(unsigned int); template lp::column_info<lp::mpq>* lp::lp_solver<lp::mpq, lp::mpq>::get_or_create_column_info(unsigned int);
template void lean::lp_solver<lean::mpq, lean::mpq>::give_symbolic_name_to_column(std::string, unsigned int); template void lp::lp_solver<lp::mpq, lp::mpq>::give_symbolic_name_to_column(std::string, unsigned int);
template void lean::lp_solver<lean::mpq, lean::mpq>::print_statistics_on_A(std::ostream & out); template void lp::lp_solver<lp::mpq, lp::mpq>::print_statistics_on_A(std::ostream & out);
template bool lean::lp_solver<lean::mpq, lean::mpq>::problem_is_empty(); template bool lp::lp_solver<lp::mpq, lp::mpq>::problem_is_empty();
template void lean::lp_solver<lean::mpq, lean::mpq>::scale(); template void lp::lp_solver<lp::mpq, lp::mpq>::scale();
template void lean::lp_solver<lean::mpq, lean::mpq>::set_scaled_cost(unsigned int); template void lp::lp_solver<lp::mpq, lp::mpq>::set_scaled_cost(unsigned int);
template lean::lp_solver<lean::mpq, lean::mpq>::~lp_solver(); template lp::lp_solver<lp::mpq, lp::mpq>::~lp_solver();
template double lean::lp_solver<double, double>::get_column_value_by_name(std::string) const; template double lp::lp_solver<double, double>::get_column_value_by_name(std::string) const;

View file

@ -4,7 +4,7 @@
*/ */
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#ifdef lp_for_z3 #ifdef lp_for_z3
namespace lean { namespace lp {
double numeric_traits<double>::g_zero = 0.0; double numeric_traits<double>::g_zero = 0.0;
double numeric_traits<double>::g_one = 1.0; double numeric_traits<double>::g_one = 1.0;
} }

View file

@ -27,14 +27,14 @@ bool contains(const std::unordered_map<A, B> & map, const A& key) {
#define LEAN_DEBUG 1 #define LEAN_DEBUG 1
#endif #endif
namespace lean { namespace lp {
inline void throw_exception(const std::string & str) { inline void throw_exception(const std::string & str) {
throw default_exception(str); throw default_exception(str);
} }
typedef z3_exception exception; typedef z3_exception exception;
#define lean_assert(_x_) { SASSERT(_x_); } #define lp_assert(_x_) { SASSERT(_x_); }
inline void lean_unreachable() { lean_assert(false); } inline void lp_unreachable() { lp_assert(false); }
template <typename X> inline X zero_of_type() { return numeric_traits<X>::zero(); } template <typename X> inline X zero_of_type() { return numeric_traits<X>::zero(); }
template <typename X> inline X one_of_type() { return numeric_traits<X>::one(); } template <typename X> inline X one_of_type() { return numeric_traits<X>::one(); }
template <typename X> inline bool is_zero(const X & v) { return numeric_traits<X>::is_zero(v); } template <typename X> inline bool is_zero(const X & v) { return numeric_traits<X>::is_zero(v); }
@ -68,8 +68,8 @@ template<typename S, typename T> struct hash<pair<S, T>> {
}; };
template<> template<>
struct hash<lean::numeric_pair<lean::mpq>> { struct hash<lp::numeric_pair<lp::mpq>> {
inline size_t operator()(const lean::numeric_pair<lean::mpq> & v) const { inline size_t operator()(const lp::numeric_pair<lp::mpq> & v) const {
size_t seed = 0; size_t seed = 0;
hash_combine(seed, v.x); hash_combine(seed, v.x);
hash_combine(seed, v.y); hash_combine(seed, v.y);
@ -91,26 +91,26 @@ struct hash<lean::numeric_pair<lean::mpq>> {
#endif #endif
namespace std { namespace std {
template<> template<>
struct hash<lean::mpq> { struct hash<lp::mpq> {
inline size_t operator()(const lean::mpq & v) const { inline size_t operator()(const lp::mpq & v) const {
return v.hash(); return v.hash();
} }
}; };
} }
namespace lean { namespace lp {
template <typename X> inline bool precise() { return numeric_traits<X>::precise();} template <typename X> inline bool precise() { return numeric_traits<X>::precise();}
template <typename X> inline X one_of_type() { return numeric_traits<X>::one(); } template <typename X> inline X one_of_type() { return numeric_traits<X>::one(); }
template <typename X> inline bool is_zero(const X & v) { return numeric_traits<X>::is_zero(v); } template <typename X> inline bool is_zero(const X & v) { return numeric_traits<X>::is_zero(v); }
template <typename X> inline double get_double(const X & v) { return numeric_traits<X>::get_double(v); } template <typename X> inline double get_double(const X & v) { return numeric_traits<X>::get_double(v); }
template <typename T> inline T zero_of_type() {return numeric_traits<T>::zero();} template <typename T> inline T zero_of_type() {return numeric_traits<T>::zero();}
inline void throw_exception(std::string str) { throw exception(str); } inline void throw_exception(std::string str) { throw exception(str); }
template <typename T> inline T from_string(std::string const & ) { lean_unreachable();} template <typename T> inline T from_string(std::string const & ) { lp_unreachable();}
template <> double inline from_string<double>(std::string const & str) { return atof(str.c_str());} template <> double inline from_string<double>(std::string const & str) { return atof(str.c_str());}
template <> mpq inline from_string<mpq>(std::string const & str) { template <> mpq inline from_string<mpq>(std::string const & str) {
return mpq(atof(str.c_str())); return mpq(atof(str.c_str()));
} }
} // closing lean } // closing lp
template <class T> template <class T>
inline void hash_combine(std::size_t & seed, const T & v) { inline void hash_combine(std::size_t & seed, const T & v) {
seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
@ -126,8 +126,8 @@ template<typename S, typename T> struct hash<pair<S, T>> {
} }
}; };
template<> template<>
struct hash<lean::numeric_pair<lean::mpq>> { struct hash<lp::numeric_pair<lp::mpq>> {
inline size_t operator()(const lean::numeric_pair<lean::mpq> & v) const { inline size_t operator()(const lp::numeric_pair<lp::mpq> & v) const {
size_t seed = 0; size_t seed = 0;
hash_combine(seed, v.x); hash_combine(seed, v.x);
hash_combine(seed, v.y); hash_combine(seed, v.y);

View file

@ -18,7 +18,7 @@
#include "util/lp/row_eta_matrix.h" #include "util/lp/row_eta_matrix.h"
#include "util/lp/square_dense_submatrix.h" #include "util/lp/square_dense_submatrix.h"
#include "util/lp/dense_matrix.h" #include "util/lp/dense_matrix.h"
namespace lean { namespace lp {
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template <typename T, typename X> // print the nr x nc submatrix at the top left corner template <typename T, typename X> // print the nr x nc submatrix at the top left corner
void print_submatrix(sparse_matrix<T, X> & m, unsigned mr, unsigned nc); void print_submatrix(sparse_matrix<T, X> & m, unsigned mr, unsigned nc);
@ -32,7 +32,7 @@ void print_matrix(sparse_matrix<T, X>& m, std::ostream & out);
template <typename T, typename X> template <typename T, typename X>
X dot_product(const vector<T> & a, const vector<X> & b) { X dot_product(const vector<T> & a, const vector<X> & b) {
lean_assert(a.size() == b.size()); lp_assert(a.size() == b.size());
auto r = zero_of_type<X>(); auto r = zero_of_type<X>();
for (unsigned i = 0; i < a.size(); i++) { for (unsigned i = 0; i < a.size(); i++) {
r += a[i] * b[i]; r += a[i] * b[i];
@ -99,7 +99,7 @@ public:
m_i = p.apply_reverse(m_i); m_i = p.apply_reverse(m_i);
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(*this == deb); // lp_assert(*this == deb);
#endif #endif
} }
}; // end of one_elem_on_diag }; // end of one_elem_on_diag
@ -291,7 +291,7 @@ public:
bool need_to_refactor() { return m_refactor_counter >= 200; } bool need_to_refactor() { return m_refactor_counter >= 200; }
void adjust_dimension_with_matrix_A() { void adjust_dimension_with_matrix_A() {
lean_assert(m_A.row_count() >= m_dim); lp_assert(m_A.row_count() >= m_dim);
m_dim = m_A.row_count(); m_dim = m_A.row_count();
m_U.resize(m_dim); m_U.resize(m_dim);
m_Q.resize(m_dim); m_Q.resize(m_dim);
@ -305,7 +305,7 @@ public:
unsigned m = m_A.row_count(); unsigned m = m_A.row_count();
unsigned m_prev = m_U.dimension(); unsigned m_prev = m_U.dimension();
lean_assert(m_A.column_count() == heading.size()); lp_assert(m_A.column_count() == heading.size());
for (unsigned i = m_prev; i < m; i++) { for (unsigned i = m_prev; i < m; i++) {
for (const row_cell<T> & c : m_A.m_rows[i]) { for (const row_cell<T> & c : m_A.m_rows[i]) {
@ -321,14 +321,14 @@ public:
void add_last_rows_to_B(const vector<int> & heading, const std::unordered_set<unsigned> & columns_to_replace) { void add_last_rows_to_B(const vector<int> & heading, const std::unordered_set<unsigned> & columns_to_replace) {
unsigned m = m_A.row_count(); unsigned m = m_A.row_count();
lean_assert(m_A.column_count() == heading.size()); lp_assert(m_A.column_count() == heading.size());
adjust_dimension_with_matrix_A(); adjust_dimension_with_matrix_A();
m_w_for_extension.resize(m); m_w_for_extension.resize(m);
// At this moment the LU is correct // At this moment the LU is correct
// for B extended by only by ones at the diagonal in the lower right corner // for B extended by only by ones at the diagonal in the lower right corner
for (unsigned j :columns_to_replace) { for (unsigned j :columns_to_replace) {
lean_assert(heading[j] >= 0); lp_assert(heading[j] >= 0);
replace_column_with_only_change_at_last_rows(j, heading[j]); replace_column_with_only_change_at_last_rows(j, heading[j]);
if (get_status() == LU_status::Degenerated) if (get_status() == LU_status::Degenerated)
break; break;

View file

@ -9,7 +9,7 @@
#include <utility> #include <utility>
#include "util/debug.h" #include "util/debug.h"
#include "util/lp/lu.h" #include "util/lp/lu.h"
namespace lean { namespace lp {
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template <typename T, typename X> // print the nr x nc submatrix at the top left corner template <typename T, typename X> // print the nr x nc submatrix at the top left corner
void print_submatrix(sparse_matrix<T, X> & m, unsigned mr, unsigned nc, std::ostream & out) { void print_submatrix(sparse_matrix<T, X> & m, unsigned mr, unsigned nc, std::ostream & out) {
@ -122,29 +122,29 @@ lu<T, X>::lu(static_matrix<T, X> const & A,
m_failure(false), m_failure(false),
m_row_eta_work_vector(A.row_count()), m_row_eta_work_vector(A.row_count()),
m_refactor_counter(0) { m_refactor_counter(0) {
lean_assert(!(numeric_traits<T>::precise() && settings.use_tableau())); lp_assert(!(numeric_traits<T>::precise() && settings.use_tableau()));
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
debug_test_of_basis(A, basis); debug_test_of_basis(A, basis);
#endif #endif
++m_settings.st().m_num_factorizations; ++m_settings.st().m_num_factorizations;
create_initial_factorization(); create_initial_factorization();
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(check_correctness()); // lp_assert(check_correctness());
#endif #endif
} }
template <typename T, typename X> template <typename T, typename X>
void lu<T, X>::debug_test_of_basis(static_matrix<T, X> const & A, vector<unsigned> & basis) { void lu<T, X>::debug_test_of_basis(static_matrix<T, X> const & A, vector<unsigned> & basis) {
std::set<unsigned> set; std::set<unsigned> set;
for (unsigned i = 0; i < A.row_count(); i++) { for (unsigned i = 0; i < A.row_count(); i++) {
lean_assert(basis[i]< A.column_count()); lp_assert(basis[i]< A.column_count());
set.insert(basis[i]); set.insert(basis[i]);
} }
lean_assert(set.size() == A.row_count()); lp_assert(set.size() == A.row_count());
} }
template <typename T, typename X> template <typename T, typename X>
void lu<T, X>::solve_By(indexed_vector<X> & y) { void lu<T, X>::solve_By(indexed_vector<X> & y) {
lean_assert(false); // not implemented lp_assert(false); // not implemented
// init_vector_y(y); // init_vector_y(y);
// solve_By_when_y_is_ready(y); // solve_By_when_y_is_ready(y);
} }
@ -277,20 +277,20 @@ void lu<T, X>::solve_yB(vector<T>& y) {
template <typename T, typename X> template <typename T, typename X>
void lu<T, X>::solve_yB_indexed(indexed_vector<T>& y) { void lu<T, X>::solve_yB_indexed(indexed_vector<T>& y) {
lean_assert(y.is_OK()); lp_assert(y.is_OK());
// first solve yU = cb*R(-1) // first solve yU = cb*R(-1)
m_R.apply_reverse_from_right_to_T(y); // got y = cb*R(-1) m_R.apply_reverse_from_right_to_T(y); // got y = cb*R(-1)
lean_assert(y.is_OK()); lp_assert(y.is_OK());
m_U.solve_y_U_indexed(y, m_settings); // got y*U=cb*R(-1) m_U.solve_y_U_indexed(y, m_settings); // got y*U=cb*R(-1)
lean_assert(y.is_OK()); lp_assert(y.is_OK());
m_Q.apply_reverse_from_right_to_T(y); m_Q.apply_reverse_from_right_to_T(y);
lean_assert(y.is_OK()); lp_assert(y.is_OK());
for (auto e = m_tail.rbegin(); e != m_tail.rend(); ++e) { for (auto e = m_tail.rbegin(); e != m_tail.rend(); ++e) {
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
(*e)->set_number_of_columns(m_dim); (*e)->set_number_of_columns(m_dim);
#endif #endif
(*e)->apply_from_right(y); (*e)->apply_from_right(y);
lean_assert(y.is_OK()); lp_assert(y.is_OK());
} }
} }
@ -304,8 +304,8 @@ void lu<T, X>::add_delta_to_solution(const vector<T>& yc, vector<T>& y){
template <typename T, typename X> template <typename T, typename X>
void lu<T, X>::add_delta_to_solution_indexed(indexed_vector<T>& y) { void lu<T, X>::add_delta_to_solution_indexed(indexed_vector<T>& y) {
// the delta sits in m_y_copy, put result into y // the delta sits in m_y_copy, put result into y
lean_assert(y.is_OK()); lp_assert(y.is_OK());
lean_assert(m_y_copy.is_OK()); lp_assert(m_y_copy.is_OK());
m_ii.clear(); m_ii.clear();
m_ii.resize(y.data_size()); m_ii.resize(y.data_size());
for (unsigned i : y.m_index) for (unsigned i : y.m_index)
@ -315,7 +315,7 @@ void lu<T, X>::add_delta_to_solution_indexed(indexed_vector<T>& y) {
if (m_ii[i] == 0) if (m_ii[i] == 0)
m_ii.set_value(1, i); m_ii.set_value(1, i);
} }
lean_assert(m_ii.is_OK()); lp_assert(m_ii.is_OK());
y.m_index.clear(); y.m_index.clear();
for (unsigned i : m_ii.m_index) { for (unsigned i : m_ii.m_index) {
@ -326,7 +326,7 @@ void lu<T, X>::add_delta_to_solution_indexed(indexed_vector<T>& y) {
v = zero_of_type<T>(); v = zero_of_type<T>();
} }
lean_assert(y.is_OK()); lp_assert(y.is_OK());
} }
template <typename T, typename X> template <typename T, typename X>
@ -343,7 +343,7 @@ void lu<T, X>::find_error_of_yB_indexed(const indexed_vector<T>& y, const vector
// it is a non efficient version // it is a non efficient version
indexed_vector<T> yc = m_y_copy; indexed_vector<T> yc = m_y_copy;
yc.m_index.clear(); yc.m_index.clear();
lean_assert(!numeric_traits<T>::precise()); lp_assert(!numeric_traits<T>::precise());
{ {
vector<unsigned> d_basis(y.m_data.size()); vector<unsigned> d_basis(y.m_data.size());
@ -364,10 +364,10 @@ void lu<T, X>::find_error_of_yB_indexed(const indexed_vector<T>& y, const vector
} }
} }
#endif #endif
lean_assert(m_ii.is_OK()); lp_assert(m_ii.is_OK());
m_ii.clear(); m_ii.clear();
m_ii.resize(y.data_size()); m_ii.resize(y.data_size());
lean_assert(m_y_copy.is_OK()); lp_assert(m_y_copy.is_OK());
// put the error into m_y_copy // put the error into m_y_copy
for (auto k : y.m_index) { for (auto k : y.m_index) {
auto & row = m_A.m_rows[k]; auto & row = m_A.m_rows[k];
@ -399,7 +399,7 @@ void lu<T, X>::find_error_of_yB_indexed(const indexed_vector<T>& y, const vector
m_y_copy.set_value(v, k); m_y_copy.set_value(v, k);
} }
} }
lean_assert(m_y_copy.is_OK()); lp_assert(m_y_copy.is_OK());
} }
@ -415,31 +415,31 @@ void lu<T, X>::solve_yB_with_error_check_indexed(indexed_vector<T> & y, const ve
solve_yB_indexed(y); solve_yB_indexed(y);
} else { } else {
solve_yB(y.m_data); solve_yB(y.m_data);
y.restore_index_and_clean_from_data(); y.restore_index_and_clp_from_data();
} }
return; return;
} }
lean_assert(m_y_copy.is_OK()); lp_assert(m_y_copy.is_OK());
lean_assert(y.is_OK()); lp_assert(y.is_OK());
if (y.m_index.size() * ratio_of_index_size_to_all_size<T>() < m_A.column_count()) { if (y.m_index.size() * ratio_of_index_size_to_all_size<T>() < m_A.column_count()) {
m_y_copy = y; m_y_copy = y;
solve_yB_indexed(y); solve_yB_indexed(y);
lean_assert(y.is_OK()); lp_assert(y.is_OK());
if (y.m_index.size() * ratio_of_index_size_to_all_size<T>() >= m_A.column_count()) { if (y.m_index.size() * ratio_of_index_size_to_all_size<T>() >= m_A.column_count()) {
find_error_of_yB(m_y_copy.m_data, y.m_data, basis); find_error_of_yB(m_y_copy.m_data, y.m_data, basis);
solve_yB(m_y_copy.m_data); solve_yB(m_y_copy.m_data);
add_delta_to_solution(m_y_copy.m_data, y.m_data); add_delta_to_solution(m_y_copy.m_data, y.m_data);
y.restore_index_and_clean_from_data(); y.restore_index_and_clp_from_data();
m_y_copy.clear_all(); m_y_copy.clear_all();
} else { } else {
find_error_of_yB_indexed(y, heading, settings); // this works with m_y_copy find_error_of_yB_indexed(y, heading, settings); // this works with m_y_copy
solve_yB_indexed(m_y_copy); solve_yB_indexed(m_y_copy);
add_delta_to_solution_indexed(y); add_delta_to_solution_indexed(y);
} }
lean_assert(m_y_copy.is_OK()); lp_assert(m_y_copy.is_OK());
} else { } else {
solve_yB_with_error_check(y.m_data, basis); solve_yB_with_error_check(y.m_data, basis);
y.restore_index_and_clean_from_data(); y.restore_index_and_clp_from_data();
} }
} }
@ -489,7 +489,7 @@ template <typename T, typename X>
void lu<T, X>::perform_transformations_on_w(indexed_vector<T>& w) { void lu<T, X>::perform_transformations_on_w(indexed_vector<T>& w) {
apply_lp_list_to_w(w); apply_lp_list_to_w(w);
m_Q.apply_reverse_from_left(w); m_Q.apply_reverse_from_left(w);
// TBD does not compile: lean_assert(numeric_traits<T>::precise() || check_vector_for_small_values(w, m_settings)); // TBD does not compile: lp_assert(numeric_traits<T>::precise() || check_vector_for_small_values(w, m_settings));
} }
// see Chvatal 24.3 // see Chvatal 24.3
@ -503,7 +503,7 @@ template <typename T, typename X>
void lu<T, X>::apply_lp_list_to_w(indexed_vector<T> & w) { void lu<T, X>::apply_lp_list_to_w(indexed_vector<T> & w) {
for (unsigned i = 0; i < m_tail.size(); i++) { for (unsigned i = 0; i < m_tail.size(); i++) {
m_tail[i]->apply_from_left_to_T(w, m_settings); m_tail[i]->apply_from_left_to_T(w, m_settings);
// TBD does not compile: lean_assert(check_vector_for_small_values(w, m_settings)); // TBD does not compile: lp_assert(check_vector_for_small_values(w, m_settings));
} }
} }
template <typename T, typename X> template <typename T, typename X>
@ -595,7 +595,7 @@ void lu<T, X>::check_apply_lp_lists_to_w(T * w) {
permutation_matrix<T, X> qr = m_Q.get_reverse(); permutation_matrix<T, X> qr = m_Q.get_reverse();
apply_to_vector(qr, w); apply_to_vector(qr, w);
for (int i = m_dim - 1; i >= 0; i--) { for (int i = m_dim - 1; i >= 0; i--) {
lean_assert(abs(w[i] - w[i]) < 0.0000001); lp_assert(abs(w[i] - w[i]) < 0.0000001);
} }
} }
@ -640,7 +640,7 @@ bool lu<T, X>::is_correct(const vector<unsigned>& basis) {
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template <typename T, typename X> template <typename T, typename X>
dense_matrix<T, X> lu<T, X>::tail_product() { dense_matrix<T, X> lu<T, X>::tail_product() {
lean_assert(tail_size() > 0); lp_assert(tail_size() > 0);
dense_matrix<T, X> left_side = permutation_matrix<T, X>(m_dim); dense_matrix<T, X> left_side = permutation_matrix<T, X>(m_dim);
for (unsigned i = 0; i < tail_size(); i++) { for (unsigned i = 0; i < tail_size(); i++) {
matrix<T, X>* lp = get_lp_matrix(i); matrix<T, X>* lp = get_lp_matrix(i);
@ -690,8 +690,8 @@ template <typename T, typename X>
bool lu<T, X>::all_columns_and_rows_are_active() { bool lu<T, X>::all_columns_and_rows_are_active() {
unsigned i = m_dim; unsigned i = m_dim;
while (i--) { while (i--) {
lean_assert(m_U.col_is_active(i)); lp_assert(m_U.col_is_active(i));
lean_assert(m_U.row_is_active(i)); lp_assert(m_U.row_is_active(i));
} }
return true; return true;
} }
@ -733,9 +733,9 @@ void lu<T, X>::create_initial_factorization(){
} }
} }
if (j == m_dim) { if (j == m_dim) {
// TBD does not compile: lean_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings)); // TBD does not compile: lp_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings));
// lean_assert(is_correct()); // lp_assert(is_correct());
// lean_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings)); // lp_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings));
return; return;
} }
j++; j++;
@ -748,12 +748,12 @@ void lu<T, X>::create_initial_factorization(){
} }
} }
m_dense_LU->update_parent_matrix(m_settings); m_dense_LU->update_parent_matrix(m_settings);
lean_assert(m_dense_LU->is_L_matrix()); lp_assert(m_dense_LU->is_L_matrix());
m_dense_LU->conjugate_by_permutation(m_Q); m_dense_LU->conjugate_by_permutation(m_Q);
push_matrix_to_tail(m_dense_LU); push_matrix_to_tail(m_dense_LU);
m_refactor_counter = 0; m_refactor_counter = 0;
// lean_assert(is_correct()); // lp_assert(is_correct());
// lean_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings)); // lp_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings));
} }
template <typename T, typename X> template <typename T, typename X>
@ -780,7 +780,7 @@ void lu<T, X>::scan_last_row_to_work_vector(unsigned lowest_row_of_the_bump) {
vector<indexed_value<T>> & last_row_vec = m_U.get_row_values(m_U.adjust_row(lowest_row_of_the_bump)); vector<indexed_value<T>> & last_row_vec = m_U.get_row_values(m_U.adjust_row(lowest_row_of_the_bump));
for (auto & iv : last_row_vec) { for (auto & iv : last_row_vec) {
if (is_zero(iv.m_value)) continue; if (is_zero(iv.m_value)) continue;
lean_assert(!m_settings.abs_val_is_smaller_than_drop_tolerance(iv.m_value)); lp_assert(!m_settings.abs_val_is_smaller_than_drop_tolerance(iv.m_value));
unsigned adjusted_col = m_U.adjust_column_inverse(iv.m_index); unsigned adjusted_col = m_U.adjust_column_inverse(iv.m_index);
if (adjusted_col < lowest_row_of_the_bump) { if (adjusted_col < lowest_row_of_the_bump) {
m_row_eta_work_vector.set_value(-iv.m_value, adjusted_col); m_row_eta_work_vector.set_value(-iv.m_value, adjusted_col);
@ -801,14 +801,14 @@ void lu<T, X>::pivot_and_solve_the_system(unsigned replaced_column, unsigned low
vector<indexed_value<T>> & row = m_U.get_row_values(aj); vector<indexed_value<T>> & row = m_U.get_row_values(aj);
for (auto & iv : row) { for (auto & iv : row) {
unsigned col = m_U.adjust_column_inverse(iv.m_index); unsigned col = m_U.adjust_column_inverse(iv.m_index);
lean_assert(col >= j || numeric_traits<T>::is_zero(iv.m_value)); lp_assert(col >= j || numeric_traits<T>::is_zero(iv.m_value));
if (col == j) continue; if (col == j) continue;
if (numeric_traits<T>::is_zero(iv.m_value)) { if (numeric_traits<T>::is_zero(iv.m_value)) {
continue; continue;
} }
// the -v is for solving the system ( to zero the last row), and +v is for pivoting // the -v is for solving the system ( to zero the last row), and +v is for pivoting
T delta = col < lowest_row_of_the_bump? -v * iv.m_value: v * iv.m_value; T delta = col < lowest_row_of_the_bump? -v * iv.m_value: v * iv.m_value;
lean_assert(numeric_traits<T>::is_zero(delta) == false); lp_assert(numeric_traits<T>::is_zero(delta) == false);
@ -885,16 +885,16 @@ void lu<T, X>::replace_column(T pivot_elem_for_checking, indexed_vector<T> & w,
push_matrix_to_tail(row_eta); push_matrix_to_tail(row_eta);
} }
calculate_Lwave_Pwave_for_bump(replaced_column, lowest_row_of_the_bump); calculate_Lwave_Pwave_for_bump(replaced_column, lowest_row_of_the_bump);
// lean_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings)); // lp_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings));
// lean_assert(w.is_OK() && m_row_eta_work_vector.is_OK()); // lp_assert(w.is_OK() && m_row_eta_work_vector.is_OK());
} }
template <typename T, typename X> template <typename T, typename X>
void lu<T, X>::calculate_Lwave_Pwave_for_bump(unsigned replaced_column, unsigned lowest_row_of_the_bump){ void lu<T, X>::calculate_Lwave_Pwave_for_bump(unsigned replaced_column, unsigned lowest_row_of_the_bump){
T diagonal_elem; T diagonal_elem;
if (replaced_column < lowest_row_of_the_bump) { if (replaced_column < lowest_row_of_the_bump) {
diagonal_elem = m_row_eta_work_vector[lowest_row_of_the_bump]; diagonal_elem = m_row_eta_work_vector[lowest_row_of_the_bump];
// lean_assert(m_row_eta_work_vector.is_OK()); // lp_assert(m_row_eta_work_vector.is_OK());
m_U.set_row_from_work_vector_and_clean_work_vector_not_adjusted(m_U.adjust_row(lowest_row_of_the_bump), m_row_eta_work_vector, m_settings); m_U.set_row_from_work_vector_and_clp_work_vector_not_adjusted(m_U.adjust_row(lowest_row_of_the_bump), m_row_eta_work_vector, m_settings);
} else { } else {
diagonal_elem = m_U(lowest_row_of_the_bump, lowest_row_of_the_bump); // todo - get it more efficiently diagonal_elem = m_U(lowest_row_of_the_bump, lowest_row_of_the_bump); // todo - get it more efficiently
} }
@ -904,7 +904,7 @@ void lu<T, X>::calculate_Lwave_Pwave_for_bump(unsigned replaced_column, unsigned
} }
calculate_Lwave_Pwave_for_last_row(lowest_row_of_the_bump, diagonal_elem); calculate_Lwave_Pwave_for_last_row(lowest_row_of_the_bump, diagonal_elem);
// lean_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings)); // lp_assert(m_U.is_upper_triangular_and_maximums_are_set_correctly_in_rows(m_settings));
} }
template <typename T, typename X> template <typename T, typename X>
@ -930,8 +930,8 @@ void init_factorization(lu<T, X>* & factorization, static_matrix<T, X> & m_A, ve
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template <typename T, typename X> template <typename T, typename X>
dense_matrix<T, X> get_B(lu<T, X>& f, const vector<unsigned>& basis) { dense_matrix<T, X> get_B(lu<T, X>& f, const vector<unsigned>& basis) {
lean_assert(basis.size() == f.dimension()); lp_assert(basis.size() == f.dimension());
lean_assert(basis.size() == f.m_U.dimension()); lp_assert(basis.size() == f.m_U.dimension());
dense_matrix<T, X> B(f.dimension(), f.dimension()); dense_matrix<T, X> B(f.dimension(), f.dimension());
for (unsigned i = 0; i < f.dimension(); i++) for (unsigned i = 0; i < f.dimension(); i++)
for (unsigned j = 0; j < f.dimension(); j++) for (unsigned j = 0; j < f.dimension(); j++)

View file

@ -8,56 +8,56 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/debug.h" #include "util/debug.h"
#include "util/lp/lu.hpp" #include "util/lp/lu.hpp"
template double lean::dot_product<double, double>(vector<double> const&, vector<double> const&); template double lp::dot_product<double, double>(vector<double> const&, vector<double> const&);
template lean::lu<double, double>::lu(lean::static_matrix<double, double> const&, vector<unsigned int>&, lean::lp_settings&); template lp::lu<double, double>::lu(lp::static_matrix<double, double> const&, vector<unsigned int>&, lp::lp_settings&);
template void lean::lu<double, double>::push_matrix_to_tail(lean::tail_matrix<double, double>*); template void lp::lu<double, double>::push_matrix_to_tail(lp::tail_matrix<double, double>*);
template void lean::lu<double, double>::replace_column(double, lean::indexed_vector<double>&, unsigned); template void lp::lu<double, double>::replace_column(double, lp::indexed_vector<double>&, unsigned);
template void lean::lu<double, double>::solve_Bd(unsigned int, lean::indexed_vector<double>&, lean::indexed_vector<double>&); template void lp::lu<double, double>::solve_Bd(unsigned int, lp::indexed_vector<double>&, lp::indexed_vector<double>&);
template lean::lu<double, double>::~lu(); template lp::lu<double, double>::~lu();
template void lean::lu<lean::mpq, lean::mpq>::push_matrix_to_tail(lean::tail_matrix<lean::mpq, lean::mpq>*); template void lp::lu<lp::mpq, lp::mpq>::push_matrix_to_tail(lp::tail_matrix<lp::mpq, lp::mpq>*);
template void lean::lu<lean::mpq, lean::mpq>::solve_Bd(unsigned int, lean::indexed_vector<lean::mpq>&, lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::mpq>::solve_Bd(unsigned int, lp::indexed_vector<lp::mpq>&, lp::indexed_vector<lp::mpq>&);
template lean::lu<lean::mpq, lean::mpq>::~lu(); template lp::lu<lp::mpq, lp::mpq>::~lu();
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::push_matrix_to_tail(lean::tail_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >*); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::push_matrix_to_tail(lp::tail_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >*);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_Bd(unsigned int, lean::indexed_vector<lean::mpq>&, lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_Bd(unsigned int, lp::indexed_vector<lp::mpq>&, lp::indexed_vector<lp::mpq>&);
template lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::~lu(); template lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::~lu();
template lean::mpq lean::dot_product<lean::mpq, lean::mpq>(vector<lean::mpq > const&, vector<lean::mpq > const&); template lp::mpq lp::dot_product<lp::mpq, lp::mpq>(vector<lp::mpq > const&, vector<lp::mpq > const&);
template void lean::init_factorization<double, double>(lean::lu<double, double>*&, lean::static_matrix<double, double>&, vector<unsigned int>&, lean::lp_settings&); template void lp::init_factorization<double, double>(lp::lu<double, double>*&, lp::static_matrix<double, double>&, vector<unsigned int>&, lp::lp_settings&);
template void lean::init_factorization<lean::mpq, lean::mpq>(lean::lu<lean::mpq, lean::mpq>*&, lean::static_matrix<lean::mpq, lean::mpq>&, vector<unsigned int>&, lean::lp_settings&); template void lp::init_factorization<lp::mpq, lp::mpq>(lp::lu<lp::mpq, lp::mpq>*&, lp::static_matrix<lp::mpq, lp::mpq>&, vector<unsigned int>&, lp::lp_settings&);
template void lean::init_factorization<lean::mpq, lean::numeric_pair<lean::mpq> >(lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >*&, lean::static_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&, vector<unsigned int>&, lean::lp_settings&); template void lp::init_factorization<lp::mpq, lp::numeric_pair<lp::mpq> >(lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >*&, lp::static_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&, vector<unsigned int>&, lp::lp_settings&);
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
template void lean::print_matrix<double, double>(lean::sparse_matrix<double, double>&, std::ostream & out); template void lp::print_matrix<double, double>(lp::sparse_matrix<double, double>&, std::ostream & out);
template void lean::print_matrix<lean::mpq, lean::mpq>(lean::static_matrix<lean::mpq, lean::mpq>&, std::ostream&); template void lp::print_matrix<lp::mpq, lp::mpq>(lp::static_matrix<lp::mpq, lp::mpq>&, std::ostream&);
template void lean::print_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >(lean::static_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&, std::ostream&); template void lp::print_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >(lp::static_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&, std::ostream&);
template void lean::print_matrix<double, double>(lean::static_matrix<double, double>&, std::ostream & out); template void lp::print_matrix<double, double>(lp::static_matrix<double, double>&, std::ostream & out);
template bool lean::lu<double, double>::is_correct(const vector<unsigned>& basis); template bool lp::lu<double, double>::is_correct(const vector<unsigned>& basis);
template bool lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::is_correct( vector<unsigned int> const &); template bool lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::is_correct( vector<unsigned int> const &);
template lean::dense_matrix<double, double> lean::get_B<double, double>(lean::lu<double, double>&, const vector<unsigned>& basis); template lp::dense_matrix<double, double> lp::get_B<double, double>(lp::lu<double, double>&, const vector<unsigned>& basis);
template lean::dense_matrix<lean::mpq, lean::mpq> lean::get_B<lean::mpq, lean::mpq>(lean::lu<lean::mpq, lean::mpq>&, vector<unsigned int> const&); template lp::dense_matrix<lp::mpq, lp::mpq> lp::get_B<lp::mpq, lp::mpq>(lp::lu<lp::mpq, lp::mpq>&, vector<unsigned int> const&);
#endif #endif
template bool lean::lu<double, double>::pivot_the_row(int); // NOLINT template bool lp::lu<double, double>::pivot_the_row(int); // NOLINT
template void lean::lu<double, double>::init_vector_w(unsigned int, lean::indexed_vector<double>&); template void lp::lu<double, double>::init_vector_w(unsigned int, lp::indexed_vector<double>&);
template void lean::lu<double, double>::solve_By(vector<double>&); template void lp::lu<double, double>::solve_By(vector<double>&);
template void lean::lu<double, double>::solve_By_when_y_is_ready_for_X(vector<double>&); template void lp::lu<double, double>::solve_By_when_y_is_ready_for_X(vector<double>&);
template void lean::lu<double, double>::solve_yB_with_error_check(vector<double>&, const vector<unsigned>& basis); template void lp::lu<double, double>::solve_yB_with_error_check(vector<double>&, const vector<unsigned>& basis);
template void lean::lu<double, double>::solve_yB_with_error_check_indexed(lean::indexed_vector<double>&, vector<int> const&, const vector<unsigned> & basis, const lp_settings&); template void lp::lu<double, double>::solve_yB_with_error_check_indexed(lp::indexed_vector<double>&, vector<int> const&, const vector<unsigned> & basis, const lp_settings&);
template void lean::lu<lean::mpq, lean::mpq>::replace_column(lean::mpq, lean::indexed_vector<lean::mpq>&, unsigned); template void lp::lu<lp::mpq, lp::mpq>::replace_column(lp::mpq, lp::indexed_vector<lp::mpq>&, unsigned);
template void lean::lu<lean::mpq, lean::mpq>::solve_By(vector<lean::mpq >&); template void lp::lu<lp::mpq, lp::mpq>::solve_By(vector<lp::mpq >&);
template void lean::lu<lean::mpq, lean::mpq>::solve_By_when_y_is_ready_for_X(vector<lean::mpq >&); template void lp::lu<lp::mpq, lp::mpq>::solve_By_when_y_is_ready_for_X(vector<lp::mpq >&);
template void lean::lu<lean::mpq, lean::mpq>::solve_yB_with_error_check(vector<lean::mpq >&, const vector<unsigned>& basis); template void lp::lu<lp::mpq, lp::mpq>::solve_yB_with_error_check(vector<lp::mpq >&, const vector<unsigned>& basis);
template void lean::lu<lean::mpq, lean::mpq>::solve_yB_with_error_check_indexed(lean::indexed_vector<lean::mpq>&, vector< int > const&, const vector<unsigned> & basis, const lp_settings&); template void lp::lu<lp::mpq, lp::mpq>::solve_yB_with_error_check_indexed(lp::indexed_vector<lp::mpq>&, vector< int > const&, const vector<unsigned> & basis, const lp_settings&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_yB_with_error_check_indexed(lean::indexed_vector<lean::mpq>&, vector< int > const&, const vector<unsigned> & basis, const lp_settings&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_yB_with_error_check_indexed(lp::indexed_vector<lp::mpq>&, vector< int > const&, const vector<unsigned> & basis, const lp_settings&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::init_vector_w(unsigned int, lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::init_vector_w(unsigned int, lp::indexed_vector<lp::mpq>&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::replace_column(lean::mpq, lean::indexed_vector<lean::mpq>&, unsigned); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::replace_column(lp::mpq, lp::indexed_vector<lp::mpq>&, unsigned);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_Bd_faster(unsigned int, lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_Bd_faster(unsigned int, lp::indexed_vector<lp::mpq>&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_By(vector<lean::numeric_pair<lean::mpq> >&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_By(vector<lp::numeric_pair<lp::mpq> >&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_By_when_y_is_ready_for_X(vector<lean::numeric_pair<lean::mpq> >&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_By_when_y_is_ready_for_X(vector<lp::numeric_pair<lp::mpq> >&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_yB_with_error_check(vector<lean::mpq >&, const vector<unsigned>& basis); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_yB_with_error_check(vector<lp::mpq >&, const vector<unsigned>& basis);
template void lean::lu<lean::mpq, lean::mpq>::solve_By(lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::mpq>::solve_By(lp::indexed_vector<lp::mpq>&);
template void lean::lu<double, double>::solve_By(lean::indexed_vector<double>&); template void lp::lu<double, double>::solve_By(lp::indexed_vector<double>&);
template void lean::lu<double, double>::solve_yB_indexed(lean::indexed_vector<double>&); template void lp::lu<double, double>::solve_yB_indexed(lp::indexed_vector<double>&);
template void lean::lu<lean::mpq, lean::mpq>::solve_yB_indexed(lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::mpq>::solve_yB_indexed(lp::indexed_vector<lp::mpq>&);
template void lean::lu<lean::mpq, lean::numeric_pair<lean::mpq> >::solve_yB_indexed(lean::indexed_vector<lean::mpq>&); template void lp::lu<lp::mpq, lp::numeric_pair<lp::mpq> >::solve_yB_indexed(lp::indexed_vector<lp::mpq>&);
template void lean::lu<lean::mpq, lean::mpq>::solve_By_for_T_indexed_only(lean::indexed_vector<lean::mpq>&, lean::lp_settings const&); template void lp::lu<lp::mpq, lp::mpq>::solve_By_for_T_indexed_only(lp::indexed_vector<lp::mpq>&, lp::lp_settings const&);
template void lean::lu<double, double>::solve_By_for_T_indexed_only(lean::indexed_vector<double>&, lean::lp_settings const&); template void lp::lu<double, double>::solve_By_for_T_indexed_only(lp::indexed_vector<double>&, lp::lp_settings const&);

View file

@ -8,7 +8,7 @@
#include "util/vector.h" #include "util/vector.h"
#include <string> #include <string>
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
namespace lean { namespace lp {
// used for debugging purposes only // used for debugging purposes only
template <typename T, typename X> template <typename T, typename X>
class matrix { class matrix {

View file

@ -7,7 +7,7 @@
#include <cmath> #include <cmath>
#include <string> #include <string>
#include "util/lp/matrix.h" #include "util/lp/matrix.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
bool matrix<T, X>::is_equal(const matrix<T, X>& other) { bool matrix<T, X>::is_equal(const matrix<T, X>& other) {
if (other.row_count() != row_count() || other.column_count() != column_count()) if (other.row_count() != row_count() || other.column_count() != column_count())

View file

@ -7,10 +7,10 @@
#include "util/lp/matrix.hpp" #include "util/lp/matrix.hpp"
#include "util/lp/static_matrix.h" #include "util/lp/static_matrix.h"
#include <string> #include <string>
template void lean::print_matrix<double, double>(lean::matrix<double, double> const*, std::ostream & out); template void lp::print_matrix<double, double>(lp::matrix<double, double> const*, std::ostream & out);
template bool lean::matrix<double, double>::is_equal(lean::matrix<double, double> const&); template bool lp::matrix<double, double>::is_equal(lp::matrix<double, double> const&);
template void lean::print_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >(lean::matrix<lean::mpq, lean::numeric_pair<lean::mpq> > const *, std::basic_ostream<char, std::char_traits<char> > &); template void lp::print_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >(lp::matrix<lp::mpq, lp::numeric_pair<lp::mpq> > const *, std::basic_ostream<char, std::char_traits<char> > &);
template void lean::print_matrix<lean::mpq, lean::mpq>(lean::matrix<lean::mpq, lean::mpq> const*, std::ostream&); template void lp::print_matrix<lp::mpq, lp::mpq>(lp::matrix<lp::mpq, lp::mpq> const*, std::ostream&);
template bool lean::matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::is_equal(lean::matrix<lean::mpq, lean::numeric_pair<lean::mpq> > const&); template bool lp::matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::is_equal(lp::matrix<lp::mpq, lp::numeric_pair<lp::mpq> > const&);
template bool lean::matrix<lean::mpq, lean::mpq>::is_equal(lean::matrix<lean::mpq, lean::mpq> const&); template bool lp::matrix<lp::mpq, lp::mpq>::is_equal(lp::matrix<lp::mpq, lp::mpq> const&);
#endif #endif

View file

@ -19,7 +19,7 @@
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/lp_solver.h" #include "util/lp/lp_solver.h"
namespace lean { namespace lp {
inline bool my_white_space(const char & a) { inline bool my_white_space(const char & a) {
return a == ' ' || a == '\t'; return a == ' ' || a == '\t';
} }
@ -160,9 +160,9 @@ class mps_reader {
if (m_line[i] == ' ') if (m_line[i] == ' ')
break; break;
} }
lean_assert(m_line.size() >= offset); lp_assert(m_line.size() >= offset);
lean_assert(m_line.size() >> i); lp_assert(m_line.size() >> i);
lean_assert(i >= offset); lp_assert(i >= offset);
return m_line.substr(offset, i - offset); return m_line.substr(offset, i - offset);
} }
@ -497,7 +497,7 @@ class mps_reader {
void create_or_update_bound() { void create_or_update_bound() {
const unsigned name_offset = 14; const unsigned name_offset = 14;
lean_assert(m_line.size() >= 14); lp_assert(m_line.size() >= 14);
vector<std::string> bound_string = split_and_trim(m_line.substr(name_offset, m_line.size())); vector<std::string> bound_string = split_and_trim(m_line.substr(name_offset, m_line.size()));
if (bound_string.size() == 0) { if (bound_string.size() == 0) {
@ -603,7 +603,7 @@ class mps_reader {
} }
for (auto s : row_with_range->m_row_columns) { for (auto s : row_with_range->m_row_columns) {
lean_assert(m_columns.find(s.first) != m_columns.end()); lp_assert(m_columns.find(s.first) != m_columns.end());
other_bound_range_row->m_row_columns[s.first] = s.second; other_bound_range_row->m_row_columns[s.first] = s.second;
} }
} }
@ -679,7 +679,7 @@ class mps_reader {
if (row->m_name != m_cost_row_name) { if (row->m_name != m_cost_row_name) {
solver->add_constraint(get_relation_from_row(row->m_type), row->m_right_side, row->m_index); solver->add_constraint(get_relation_from_row(row->m_type), row->m_right_side, row->m_index);
for (auto s : row->m_row_columns) { for (auto s : row->m_row_columns) {
lean_assert(m_columns.find(s.first) != m_columns.end()); lp_assert(m_columns.find(s.first) != m_columns.end());
solver->set_row_column_coefficient(row->m_index, m_columns[s.first]->m_index, s.second); solver->set_row_column_coefficient(row->m_index, m_columns[s.first]->m_index, s.second);
} }
} else { } else {
@ -714,7 +714,7 @@ class mps_reader {
void set_solver_cost(row * row, lp_solver<T, X> *solver) { void set_solver_cost(row * row, lp_solver<T, X> *solver) {
for (auto s : row->m_row_columns) { for (auto s : row->m_row_columns) {
std::string name = s.first; std::string name = s.first;
lean_assert(m_columns.find(name) != m_columns.end()); lp_assert(m_columns.find(name) != m_columns.end());
mps_reader::column * col = m_columns[name]; mps_reader::column * col = m_columns[name];
solver->set_cost_for_column(col->m_index, s.second); solver->set_cost_for_column(col->m_index, s.second);
} }
@ -723,7 +723,7 @@ class mps_reader {
public: public:
void set_message_stream(std::ostream * o) { void set_message_stream(std::ostream * o) {
lean_assert(o != nullptr); lp_assert(o != nullptr);
m_message_stream = o; m_message_stream = o;
} }
vector<std::string> column_names() { vector<std::string> column_names() {

View file

@ -14,23 +14,23 @@
namespace nra { namespace nra {
struct mon_eq { struct mon_eq {
mon_eq(lean::var_index v, unsigned sz, lean::var_index const* vs): mon_eq(lp::var_index v, unsigned sz, lp::var_index const* vs):
m_v(v), m_vs(sz, vs) {} m_v(v), m_vs(sz, vs) {}
lean::var_index m_v; lp::var_index m_v;
svector<lean::var_index> m_vs; svector<lp::var_index> m_vs;
}; };
struct solver::imp { struct solver::imp {
lean::lar_solver& s; lp::lar_solver& s;
reslimit& m_limit; reslimit& m_limit;
params_ref m_params; params_ref m_params;
u_map<polynomial::var> m_lp2nl; // map from lar_solver variables to nlsat::solver variables u_map<polynomial::var> m_lp2nl; // map from lar_solver variables to nlsat::solver variables
scoped_ptr<nlsat::solver> m_nlsat; scoped_ptr<nlsat::solver> m_nlsat;
vector<mon_eq> m_monomials; vector<mon_eq> m_monomials;
unsigned_vector m_monomials_lim; unsigned_vector m_monomials_lim;
mutable std::unordered_map<lean::var_index, rational> m_variable_values; // current model mutable std::unordered_map<lp::var_index, rational> m_variable_values; // current model
imp(lean::lar_solver& s, reslimit& lim, params_ref const& p): imp(lp::lar_solver& s, reslimit& lim, params_ref const& p):
s(s), s(s),
m_limit(lim), m_limit(lim),
m_params(p) { m_params(p) {
@ -40,7 +40,7 @@ namespace nra {
return !m_monomials.empty() && !check_assignments(); return !m_monomials.empty() && !check_assignments();
} }
void add(lean::var_index v, unsigned sz, lean::var_index const* vs) { void add(lp::var_index v, unsigned sz, lp::var_index const* vs) {
m_monomials.push_back(mon_eq(v, sz, vs)); m_monomials.push_back(mon_eq(v, sz, vs));
} }
@ -87,7 +87,7 @@ namespace nra {
TBD: use partial model from lra_solver to prime the state of nlsat_solver. TBD: use partial model from lra_solver to prime the state of nlsat_solver.
TBD: explore more incremental ways of applying nlsat (using assumptions) TBD: explore more incremental ways of applying nlsat (using assumptions)
*/ */
lbool check(lean::explanation_t& ex) { lbool check(lp::explanation_t& ex) {
SASSERT(need_check()); SASSERT(need_check());
m_nlsat = alloc(nlsat::solver, m_limit, m_params); m_nlsat = alloc(nlsat::solver, m_limit, m_params);
m_lp2nl.reset(); m_lp2nl.reset();
@ -168,31 +168,31 @@ namespace nra {
nlsat::literal lit; nlsat::literal lit;
nlsat::assumption a = this + idx; nlsat::assumption a = this + idx;
switch (k) { switch (k) {
case lean::lconstraint_kind::LE: case lp::lconstraint_kind::LE:
lit = ~m_nlsat->mk_ineq_literal(nlsat::atom::kind::GT, 1, ps, is_even); lit = ~m_nlsat->mk_ineq_literal(nlsat::atom::kind::GT, 1, ps, is_even);
break; break;
case lean::lconstraint_kind::GE: case lp::lconstraint_kind::GE:
lit = ~m_nlsat->mk_ineq_literal(nlsat::atom::kind::LT, 1, ps, is_even); lit = ~m_nlsat->mk_ineq_literal(nlsat::atom::kind::LT, 1, ps, is_even);
break; break;
case lean::lconstraint_kind::LT: case lp::lconstraint_kind::LT:
lit = m_nlsat->mk_ineq_literal(nlsat::atom::kind::LT, 1, ps, is_even); lit = m_nlsat->mk_ineq_literal(nlsat::atom::kind::LT, 1, ps, is_even);
break; break;
case lean::lconstraint_kind::GT: case lp::lconstraint_kind::GT:
lit = m_nlsat->mk_ineq_literal(nlsat::atom::kind::GT, 1, ps, is_even); lit = m_nlsat->mk_ineq_literal(nlsat::atom::kind::GT, 1, ps, is_even);
break; break;
case lean::lconstraint_kind::EQ: case lp::lconstraint_kind::EQ:
lit = m_nlsat->mk_ineq_literal(nlsat::atom::kind::EQ, 1, ps, is_even); lit = m_nlsat->mk_ineq_literal(nlsat::atom::kind::EQ, 1, ps, is_even);
break; break;
} }
m_nlsat->mk_clause(1, &lit, a); m_nlsat->mk_clause(1, &lit, a);
} }
bool is_int(lean::var_index v) { bool is_int(lp::var_index v) {
return s.var_is_int(v); return s.var_is_int(v);
} }
polynomial::var lp2nl(lean::var_index v) { polynomial::var lp2nl(lp::var_index v) {
polynomial::var r; polynomial::var r;
if (!m_lp2nl.find(v, r)) { if (!m_lp2nl.find(v, r)) {
r = m_nlsat->mk_var(is_int(v)); r = m_nlsat->mk_var(is_int(v));
@ -201,7 +201,7 @@ namespace nra {
return r; return r;
} }
nlsat::anum const& value(lean::var_index v) const { nlsat::anum const& value(lp::var_index v) const {
return m_nlsat->value(m_lp2nl.find(v)); return m_nlsat->value(m_lp2nl.find(v));
} }
@ -221,7 +221,7 @@ namespace nra {
} }
}; };
solver::solver(lean::lar_solver& s, reslimit& lim, params_ref const& p) { solver::solver(lp::lar_solver& s, reslimit& lim, params_ref const& p) {
m_imp = alloc(imp, s, lim, p); m_imp = alloc(imp, s, lim, p);
} }
@ -229,11 +229,11 @@ namespace nra {
dealloc(m_imp); dealloc(m_imp);
} }
void solver::add_monomial(lean::var_index v, unsigned sz, lean::var_index const* vs) { void solver::add_monomial(lp::var_index v, unsigned sz, lp::var_index const* vs) {
m_imp->add(v, sz, vs); m_imp->add(v, sz, vs);
} }
lbool solver::check(lean::explanation_t& ex) { lbool solver::check(lp::explanation_t& ex) {
return m_imp->check(ex); return m_imp->check(ex);
} }
@ -253,7 +253,7 @@ namespace nra {
return m_imp->display(out); return m_imp->display(out);
} }
nlsat::anum const& solver::value(lean::var_index v) const { nlsat::anum const& solver::value(lp::var_index v) const {
return m_imp->value(v); return m_imp->value(v);
} }

View file

@ -10,7 +10,7 @@
#include "util/params.h" #include "util/params.h"
#include "nlsat/nlsat_solver.h" #include "nlsat/nlsat_solver.h"
namespace lean { namespace lp {
class lar_solver; class lar_solver;
} }
@ -25,7 +25,7 @@ namespace nra {
public: public:
solver(lean::lar_solver& s, reslimit& lim, params_ref const& p = params_ref()); solver(lp::lar_solver& s, reslimit& lim, params_ref const& p = params_ref());
~solver(); ~solver();
@ -33,13 +33,13 @@ namespace nra {
\brief Add a definition v = vs[0]*vs[1]*...*vs[sz-1] \brief Add a definition v = vs[0]*vs[1]*...*vs[sz-1]
The variable v is equal to the product of variables vs. The variable v is equal to the product of variables vs.
*/ */
void add_monomial(lean::var_index v, unsigned sz, lean::var_index const* vs); void add_monomial(lp::var_index v, unsigned sz, lp::var_index const* vs);
/* /*
\brief Check feasiblity of linear constraints augmented by polynomial definitions \brief Check feasiblity of linear constraints augmented by polynomial definitions
that are added. that are added.
*/ */
lbool check(lean::explanation_t& ex); lbool check(lp::explanation_t& ex);
/* /*
\brief determine whether nra check is needed. \brief determine whether nra check is needed.
@ -49,7 +49,7 @@ namespace nra {
/* /*
\brief Access model. \brief Access model.
*/ */
nlsat::anum const& value(lean::var_index v) const; nlsat::anum const& value(lp::var_index v) const;
nlsat::anum_manager& am(); nlsat::anum_manager& am();

View file

@ -17,11 +17,11 @@
// include "util/numerics/mpq.h" // include "util/numerics/mpq.h"
// include "util/numerics/numeric_traits.h" // include "util/numerics/numeric_traits.h"
#endif #endif
namespace lean { namespace lp {
#ifdef lp_for_z3 // rename rationals #ifdef lp_for_z3 // rename rationals
typedef rational mpq; typedef rational mpq;
#else #else
typedef lean::mpq mpq; typedef lp::mpq mpq;
#endif #endif
@ -73,8 +73,8 @@ template <typename X, typename Y>
struct convert_struct { struct convert_struct {
static X convert(const Y & y){ return X(y);} static X convert(const Y & y){ return X(y);}
static bool is_epsilon_small(const X & x, const double & y) { return std::abs(numeric_traits<X>::get_double(x)) < y; } static bool is_epsilon_small(const X & x, const double & y) { return std::abs(numeric_traits<X>::get_double(x)) < y; }
static bool below_bound_numeric(const X &, const X &, const Y &) { /*lean_unreachable();*/ return false;} static bool below_bound_numeric(const X &, const X &, const Y &) { /*lp_unreachable();*/ return false;}
static bool above_bound_numeric(const X &, const X &, const Y &) { /*lean_unreachable();*/ return false; } static bool above_bound_numeric(const X &, const X &, const Y &) { /*lp_unreachable();*/ return false; }
}; };
@ -144,7 +144,7 @@ struct numeric_pair {
} }
numeric_pair operator/(const numeric_pair &) const { numeric_pair operator/(const numeric_pair &) const {
// lean_unreachable(); // lp_unreachable();
} }
@ -153,7 +153,7 @@ struct numeric_pair {
} }
numeric_pair operator*(const numeric_pair & /*a*/) const { numeric_pair operator*(const numeric_pair & /*a*/) const {
// lean_unreachable(); // lp_unreachable();
} }
numeric_pair& operator+=(const numeric_pair & a) { numeric_pair& operator+=(const numeric_pair & a) {
@ -188,7 +188,7 @@ struct numeric_pair {
return numeric_pair(-x, -y); return numeric_pair(-x, -y);
} }
static bool precize() { return lean::numeric_traits<T>::precize();} static bool precize() { return lp::numeric_traits<T>::precize();}
bool is_zero() const { return x.is_zero() && y.is_zero(); } bool is_zero() const { return x.is_zero() && y.is_zero(); }
@ -230,15 +230,15 @@ numeric_pair<T> operator/(const numeric_pair<T> & r, const X & a) {
} }
// template <numeric_pair, typename T> bool precise() { return numeric_traits<T>::precise();} // template <numeric_pair, typename T> bool precise() { return numeric_traits<T>::precise();}
template <typename T> double get_double(const lean::numeric_pair<T> & ) { /* lean_unreachable(); */ return 0;} template <typename T> double get_double(const lp::numeric_pair<T> & ) { /* lp_unreachable(); */ return 0;}
template <typename T> template <typename T>
class numeric_traits<lean::numeric_pair<T>> { class numeric_traits<lp::numeric_pair<T>> {
public: public:
static bool precise() { return numeric_traits<T>::precise();} static bool precise() { return numeric_traits<T>::precise();}
static lean::numeric_pair<T> zero() { return lean::numeric_pair<T>(numeric_traits<T>::zero(), numeric_traits<T>::zero()); } static lp::numeric_pair<T> zero() { return lp::numeric_pair<T>(numeric_traits<T>::zero(), numeric_traits<T>::zero()); }
static bool is_zero(const lean::numeric_pair<T> & v) { return numeric_traits<T>::is_zero(v.x) && numeric_traits<T>::is_zero(v.y); } static bool is_zero(const lp::numeric_pair<T> & v) { return numeric_traits<T>::is_zero(v.x) && numeric_traits<T>::is_zero(v.y); }
static double get_double(const lean::numeric_pair<T> & v){ return numeric_traits<T>::get_double(v.x); } // just return the double of the first coordinate static double get_double(const lp::numeric_pair<T> & v){ return numeric_traits<T>::get_double(v.x); } // just return the double of the first coordinate
static double one() { /*lean_unreachable();*/ return 0;} static double one() { /*lp_unreachable();*/ return 0;}
static bool is_pos(const numeric_pair<T> &p) { static bool is_pos(const numeric_pair<T> &p) {
return numeric_traits<T>::is_pos(p.x) || return numeric_traits<T>::is_pos(p.x) ||
(numeric_traits<T>::is_zero(p.x) && numeric_traits<T>::is_pos(p.y)); (numeric_traits<T>::is_zero(p.x) && numeric_traits<T>::is_pos(p.y));
@ -268,11 +268,11 @@ struct convert_struct<numeric_pair<T>, double> {
return convert_struct<T, double>::is_epsilon_small(p.x, eps) && convert_struct<T, double>::is_epsilon_small(p.y, eps); 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 &) { static bool below_bound_numeric(const numeric_pair<T> &, const numeric_pair<T> &, const double &) {
// lean_unreachable(); // lp_unreachable();
return false; return false;
} }
static bool above_bound_numeric(const numeric_pair<T> &, const numeric_pair<T> &, const double &) { static bool above_bound_numeric(const numeric_pair<T> &, const numeric_pair<T> &, const double &) {
// lean_unreachable(); // lp_unreachable();
return false; return false;
} }
}; };

View file

@ -12,7 +12,7 @@
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
#include "util/lp/matrix.h" #include "util/lp/matrix.h"
#include "util/lp/tail_matrix.h" #include "util/lp/tail_matrix.h"
namespace lean { namespace lp {
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
inline bool is_even(int k) { return (k/2)*2 == k; } inline bool is_even(int k) { return (k/2)*2 == k; }
#endif #endif
@ -86,7 +86,7 @@ class permutation_matrix : public tail_matrix<T, X> {
void apply_reverse_from_right_to_X(vector<X> & w); void apply_reverse_from_right_to_X(vector<X> & w);
void set_val(unsigned i, unsigned pi) { void set_val(unsigned i, unsigned pi) {
lean_assert(i < size() && pi < size()); m_permutation[i] = pi; m_rev[pi] = i; } lp_assert(i < size() && pi < size()); m_permutation[i] = pi; m_rev[pi] = i; }
void transpose_from_left(unsigned i, unsigned j); void transpose_from_left(unsigned i, unsigned j);

View file

@ -4,7 +4,7 @@
*/ */
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/permutation_matrix.h" #include "util/lp/permutation_matrix.h"
namespace lean { namespace lp {
template <typename T, typename X> permutation_matrix<T, X>::permutation_matrix(unsigned length): m_permutation(length), m_rev(length), m_T_buffer(length), m_X_buffer(length) { template <typename T, typename X> permutation_matrix<T, X>::permutation_matrix(unsigned length): m_permutation(length), m_rev(length), m_T_buffer(length), m_X_buffer(length) {
for (unsigned i = 0; i < length; i++) { // do not change the direction of the loop because of the vectorization bug in clang3.3 for (unsigned i = 0; i < length; i++) { // do not change the direction of the loop because of the vectorization bug in clang3.3
m_permutation[i] = m_rev[i] = i; m_permutation[i] = m_rev[i] = i;
@ -50,7 +50,7 @@ void permutation_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings & ) {
// deb.apply_from_left(deb_w); // deb.apply_from_left(deb_w);
#endif #endif
// std::cout << " apply_from_left " << std::endl; // std::cout << " apply_from_left " << std::endl;
lean_assert(m_X_buffer.size() == w.size()); lp_assert(m_X_buffer.size() == w.size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) { while (i-- > 0) {
m_X_buffer[i] = w[m_permutation[i]]; m_X_buffer[i] = w[m_permutation[i]];
@ -60,7 +60,7 @@ void permutation_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings & ) {
w[i] = m_X_buffer[i]; w[i] = m_X_buffer[i];
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<L>(deb_w, w, row_count())); // lp_assert(vectors_are_equal<L>(deb_w, w, row_count()));
// delete [] deb_w; // delete [] deb_w;
#endif #endif
} }
@ -86,7 +86,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::apply_from_righ
// T * deb_w = clone_vector<T>(w, row_count()); // T * deb_w = clone_vector<T>(w, row_count());
// deb.apply_from_right(deb_w); // deb.apply_from_right(deb_w);
#endif #endif
lean_assert(m_T_buffer.size() == w.size()); lp_assert(m_T_buffer.size() == w.size());
for (unsigned i = 0; i < size(); i++) { for (unsigned i = 0; i < size(); i++) {
m_T_buffer[i] = w[m_rev[i]]; m_T_buffer[i] = w[m_rev[i]];
} }
@ -95,7 +95,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::apply_from_righ
w[i] = m_T_buffer[i]; w[i] = m_T_buffer[i];
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<T>(deb_w, w, row_count())); // lp_assert(vectors_are_equal<T>(deb_w, w, row_count()));
// delete [] deb_w; // delete [] deb_w;
#endif #endif
} }
@ -117,9 +117,9 @@ template <typename T, typename X> void permutation_matrix<T, X>::apply_from_righ
unsigned pj = m_permutation[j]; unsigned pj = m_permutation[j];
w.set_value(buffer[i], pj); w.set_value(buffer[i], pj);
} }
lean_assert(w.is_OK()); lp_assert(w.is_OK());
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
lean_assert(vectors_are_equal(wcopy, w.m_data)); lp_assert(vectors_are_equal(wcopy, w.m_data));
#endif #endif
} }
@ -166,7 +166,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left(indexed_vector<L> & w) {
w.m_index[i] = j; w.m_index[i] = j;
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<L>(deb_w, w.m_data, row_count())); // lp_assert(vectors_are_equal<L>(deb_w, w.m_data, row_count()));
// delete [] deb_w; // delete [] deb_w;
#endif #endif
} }
@ -174,7 +174,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left(indexed_vector<L> & w) {
template <typename T, typename X> template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_left_to_T(vector<T> & w) { void permutation_matrix<T, X>::apply_reverse_from_left_to_T(vector<T> & w) {
// the result will be w = p(-1) * w // the result will be w = p(-1) * w
lean_assert(m_T_buffer.size() == w.size()); lp_assert(m_T_buffer.size() == w.size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) { while (i-- > 0) {
m_T_buffer[m_permutation[i]] = w[i]; m_T_buffer[m_permutation[i]] = w[i];
@ -187,7 +187,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left_to_T(vector<T> & w) {
template <typename T, typename X> template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_left_to_X(vector<X> & w) { void permutation_matrix<T, X>::apply_reverse_from_left_to_X(vector<X> & w) {
// the result will be w = p(-1) * w // the result will be w = p(-1) * w
lean_assert(m_X_buffer.size() == w.size()); lp_assert(m_X_buffer.size() == w.size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) { while (i-- > 0) {
m_X_buffer[m_permutation[i]] = w[i]; m_X_buffer[m_permutation[i]] = w[i];
@ -201,7 +201,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left_to_X(vector<X> & w) {
template <typename T, typename X> template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_right_to_T(vector<T> & w) { void permutation_matrix<T, X>::apply_reverse_from_right_to_T(vector<T> & w) {
// the result will be w = w * p(-1) // the result will be w = w * p(-1)
lean_assert(m_T_buffer.size() == w.size()); lp_assert(m_T_buffer.size() == w.size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) { while (i-- > 0) {
m_T_buffer[i] = w[m_permutation[i]]; m_T_buffer[i] = w[m_permutation[i]];
@ -219,7 +219,7 @@ void permutation_matrix<T, X>::apply_reverse_from_right_to_T(indexed_vector<T> &
// vector<T> wcopy(w.m_data); // vector<T> wcopy(w.m_data);
// apply_reverse_from_right_to_T(wcopy); // apply_reverse_from_right_to_T(wcopy);
#endif #endif
lean_assert(w.is_OK()); lp_assert(w.is_OK());
vector<T> tmp; vector<T> tmp;
vector<unsigned> tmp_index(w.m_index); vector<unsigned> tmp_index(w.m_index);
for (auto i : w.m_index) { for (auto i : w.m_index) {
@ -232,15 +232,15 @@ void permutation_matrix<T, X>::apply_reverse_from_right_to_T(indexed_vector<T> &
w.set_value(tmp[k], m_rev[j]); w.set_value(tmp[k], m_rev[j]);
} }
// lean_assert(w.is_OK()); // lp_assert(w.is_OK());
// lean_assert(vectors_are_equal(w.m_data, wcopy)); // lp_assert(vectors_are_equal(w.m_data, wcopy));
} }
template <typename T, typename X> template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_right_to_X(vector<X> & w) { void permutation_matrix<T, X>::apply_reverse_from_right_to_X(vector<X> & w) {
// the result will be w = w * p(-1) // the result will be w = w * p(-1)
lean_assert(m_X_buffer.size() == w.size()); lp_assert(m_X_buffer.size() == w.size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) { while (i-- > 0) {
m_X_buffer[i] = w[m_permutation[i]]; m_X_buffer[i] = w[m_permutation[i]];
@ -253,7 +253,7 @@ void permutation_matrix<T, X>::apply_reverse_from_right_to_X(vector<X> & w) {
template <typename T, typename X> void permutation_matrix<T, X>::transpose_from_left(unsigned i, unsigned j) { template <typename T, typename X> void permutation_matrix<T, X>::transpose_from_left(unsigned i, unsigned j) {
// the result will be this = (i,j)*this // the result will be this = (i,j)*this
lean_assert(i < size() && j < size() && i != j); lp_assert(i < size() && j < size() && i != j);
auto pi = m_rev[i]; auto pi = m_rev[i];
auto pj = m_rev[j]; auto pj = m_rev[j];
set_val(pi, j); set_val(pi, j);
@ -262,7 +262,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::transpose_from_
template <typename T, typename X> void permutation_matrix<T, X>::transpose_from_right(unsigned i, unsigned j) { template <typename T, typename X> void permutation_matrix<T, X>::transpose_from_right(unsigned i, unsigned j) {
// the result will be this = this * (i,j) // the result will be this = this * (i,j)
lean_assert(i < size() && j < size() && i != j); lp_assert(i < size() && j < size() && i != j);
auto pi = m_permutation[i]; auto pi = m_permutation[i];
auto pj = m_permutation[j]; auto pj = m_permutation[j];
set_val(i, pj); set_val(i, pj);
@ -271,7 +271,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::transpose_from_
template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_permutation_from_left(permutation_matrix<T, X> & p) { template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_permutation_from_left(permutation_matrix<T, X> & p) {
m_work_array = m_permutation; m_work_array = m_permutation;
lean_assert(p.size() == size()); lp_assert(p.size() == size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) { while (i-- > 0) {
set_val(i, m_work_array[p[i]]); // we have m(P)*m(Q) = m(QP), where m is the matrix of the permutation set_val(i, m_work_array[p[i]]); // we have m(P)*m(Q) = m(QP), where m is the matrix of the permutation
@ -281,7 +281,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_per
// this is multiplication in the matrix sense // this is multiplication in the matrix sense
template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_permutation_from_right(permutation_matrix<T, X> & p) { template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_permutation_from_right(permutation_matrix<T, X> & p) {
m_work_array = m_permutation; m_work_array = m_permutation;
lean_assert(p.size() == size()); lp_assert(p.size() == size());
unsigned i = size(); unsigned i = size();
while (i-- > 0) while (i-- > 0)
set_val(i, p[m_work_array[i]]); // we have m(P)*m(Q) = m(QP), where m is the matrix of the permutation set_val(i, p[m_work_array[i]]); // we have m(P)*m(Q) = m(QP), where m is the matrix of the permutation
@ -289,7 +289,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_per
} }
template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_reverse_from_right(permutation_matrix<T, X> & q){ // todo : condensed permutations ? template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_reverse_from_right(permutation_matrix<T, X> & q){ // todo : condensed permutations ?
lean_assert(q.size() == size()); lp_assert(q.size() == size());
m_work_array = m_permutation; m_work_array = m_permutation;
// the result is this = this*q(-1) // the result is this = this*q(-1)
unsigned i = size(); unsigned i = size();

View file

@ -6,50 +6,50 @@
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/permutation_matrix.hpp" #include "util/lp/permutation_matrix.hpp"
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
template void lean::permutation_matrix<double, double>::apply_from_right(vector<double>&); template void lp::permutation_matrix<double, double>::apply_from_right(vector<double>&);
template void lean::permutation_matrix<double, double>::init(unsigned int); template void lp::permutation_matrix<double, double>::init(unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::init(unsigned int); template void lp::permutation_matrix<lp::mpq, lp::mpq>::init(unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq>>::init(unsigned int); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq>>::init(unsigned int);
template bool lean::permutation_matrix<double, double>::is_identity() const; template bool lp::permutation_matrix<double, double>::is_identity() const;
template void lean::permutation_matrix<double, double>::multiply_by_permutation_from_left(lean::permutation_matrix<double, double>&); template void lp::permutation_matrix<double, double>::multiply_by_permutation_from_left(lp::permutation_matrix<double, double>&);
template void lean::permutation_matrix<double, double>::multiply_by_permutation_reverse_from_left(lean::permutation_matrix<double, double>&); template void lp::permutation_matrix<double, double>::multiply_by_permutation_reverse_from_left(lp::permutation_matrix<double, double>&);
template void lean::permutation_matrix<double, double>::multiply_by_reverse_from_right(lean::permutation_matrix<double, double>&); template void lp::permutation_matrix<double, double>::multiply_by_reverse_from_right(lp::permutation_matrix<double, double>&);
template lean::permutation_matrix<double, double>::permutation_matrix(unsigned int, vector<unsigned int> const&); template lp::permutation_matrix<double, double>::permutation_matrix(unsigned int, vector<unsigned int> const&);
template void lean::permutation_matrix<double, double>::transpose_from_left(unsigned int, unsigned int); template void lp::permutation_matrix<double, double>::transpose_from_left(unsigned int, unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::apply_from_right(vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::apply_from_right(vector<lp::mpq>&);
template bool lean::permutation_matrix<lean::mpq, lean::mpq>::is_identity() const; template bool lp::permutation_matrix<lp::mpq, lp::mpq>::is_identity() const;
template void lean::permutation_matrix<lean::mpq, lean::mpq>::multiply_by_permutation_from_left(lean::permutation_matrix<lean::mpq, lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::multiply_by_permutation_from_left(lp::permutation_matrix<lp::mpq, lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::multiply_by_permutation_from_right(lean::permutation_matrix<lean::mpq, lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::multiply_by_permutation_from_right(lp::permutation_matrix<lp::mpq, lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::multiply_by_permutation_reverse_from_left(lean::permutation_matrix<lean::mpq, lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::multiply_by_permutation_reverse_from_left(lp::permutation_matrix<lp::mpq, lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::multiply_by_reverse_from_right(lean::permutation_matrix<lean::mpq, lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::multiply_by_reverse_from_right(lp::permutation_matrix<lp::mpq, lp::mpq>&);
template lean::permutation_matrix<lean::mpq, lean::mpq>::permutation_matrix(unsigned int); template lp::permutation_matrix<lp::mpq, lp::mpq>::permutation_matrix(unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::transpose_from_left(unsigned int, unsigned int); template void lp::permutation_matrix<lp::mpq, lp::mpq>::transpose_from_left(unsigned int, unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::transpose_from_right(unsigned int, unsigned int); template void lp::permutation_matrix<lp::mpq, lp::mpq>::transpose_from_right(unsigned int, unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_from_right(vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_from_right(vector<lp::mpq>&);
template bool lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::is_identity() const; template bool lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::is_identity() const;
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::multiply_by_permutation_from_left(lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::multiply_by_permutation_from_left(lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::multiply_by_permutation_from_right(lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::multiply_by_permutation_from_right(lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::multiply_by_permutation_reverse_from_left(lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::multiply_by_permutation_reverse_from_left(lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::multiply_by_reverse_from_right(lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::multiply_by_reverse_from_right(lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >&);
template lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::permutation_matrix(unsigned int); template lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::permutation_matrix(unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::transpose_from_left(unsigned int, unsigned int); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::transpose_from_left(unsigned int, unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::transpose_from_right(unsigned int, unsigned int); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::transpose_from_right(unsigned int, unsigned int);
template void lean::permutation_matrix<double, double>::apply_reverse_from_left<double>(lean::indexed_vector<double>&); template void lp::permutation_matrix<double, double>::apply_reverse_from_left<double>(lp::indexed_vector<double>&);
template void lean::permutation_matrix<double, double>::apply_reverse_from_left_to_T(vector<double>&); template void lp::permutation_matrix<double, double>::apply_reverse_from_left_to_T(vector<double>&);
template void lean::permutation_matrix<double, double>::apply_reverse_from_right_to_T(vector<double>&); template void lp::permutation_matrix<double, double>::apply_reverse_from_right_to_T(vector<double>&);
template void lean::permutation_matrix<double, double>::transpose_from_right(unsigned int, unsigned int); template void lp::permutation_matrix<double, double>::transpose_from_right(unsigned int, unsigned int);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::apply_reverse_from_left<lean::mpq>(lean::indexed_vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::apply_reverse_from_left<lp::mpq>(lp::indexed_vector<lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::apply_reverse_from_left_to_T(vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::apply_reverse_from_left_to_T(vector<lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::apply_reverse_from_right_to_T(vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::apply_reverse_from_right_to_T(vector<lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_reverse_from_left<lean::mpq>(lean::indexed_vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_reverse_from_left<lp::mpq>(lp::indexed_vector<lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_reverse_from_left_to_T(vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_reverse_from_left_to_T(vector<lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_reverse_from_right_to_T(vector<lean::mpq >&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_reverse_from_right_to_T(vector<lp::mpq >&);
template void lean::permutation_matrix<double, double>::multiply_by_permutation_from_right(lean::permutation_matrix<double, double>&); template void lp::permutation_matrix<double, double>::multiply_by_permutation_from_right(lp::permutation_matrix<double, double>&);
template lean::permutation_matrix<double, double>::permutation_matrix(unsigned int); template lp::permutation_matrix<double, double>::permutation_matrix(unsigned int);
template void lean::permutation_matrix<double, double>::apply_reverse_from_left_to_X(vector<double> &); template void lp::permutation_matrix<double, double>::apply_reverse_from_left_to_X(vector<double> &);
template void lean::permutation_matrix< lean::mpq, lean::mpq>::apply_reverse_from_left_to_X(vector<lean::mpq> &); template void lp::permutation_matrix< lp::mpq, lp::mpq>::apply_reverse_from_left_to_X(vector<lp::mpq> &);
template void lean::permutation_matrix< lean::mpq, lean::numeric_pair< lean::mpq> >::apply_reverse_from_left_to_X(vector<lean::numeric_pair< lean::mpq>> &); template void lp::permutation_matrix< lp::mpq, lp::numeric_pair< lp::mpq> >::apply_reverse_from_left_to_X(vector<lp::numeric_pair< lp::mpq>> &);
template void lean::permutation_matrix<double, double>::apply_reverse_from_right_to_T(lean::indexed_vector<double>&); template void lp::permutation_matrix<double, double>::apply_reverse_from_right_to_T(lp::indexed_vector<double>&);
template void lean::permutation_matrix<lean::mpq, lean::mpq>::apply_reverse_from_right_to_T(lean::indexed_vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::mpq>::apply_reverse_from_right_to_T(lp::indexed_vector<lp::mpq>&);
template void lean::permutation_matrix<lean::mpq, lean::numeric_pair<lean::mpq> >::apply_reverse_from_right_to_T(lean::indexed_vector<lean::mpq>&); template void lp::permutation_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::apply_reverse_from_right_to_T(lp::indexed_vector<lp::mpq>&);

View file

@ -3,7 +3,7 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
namespace lean { namespace lp {
quick_xplain::quick_xplain(vector<std::pair<mpq, constraint_index>> & explanation, const lar_solver & ls, lar_solver & qsol) : quick_xplain::quick_xplain(vector<std::pair<mpq, constraint_index>> & explanation, const lar_solver & ls, lar_solver & qsol) :
m_explanation(explanation), m_explanation(explanation),
m_parent_solver(ls), m_parent_solver(ls),
@ -56,7 +56,7 @@ void quick_xplain::minimize(const vector<unsigned>& u) {
} }
} }
if (m > 0) { if (m > 0) {
lean_assert(m_qsol.constraint_stack_size() >= initial_stack_size); lp_assert(m_qsol.constraint_stack_size() >= initial_stack_size);
m_qsol.pop(m_qsol.constraint_stack_size() - initial_stack_size); m_qsol.pop(m_qsol.constraint_stack_size() - initial_stack_size);
for (auto j : m_x) for (auto j : m_x)
add_constraint_to_qsol(j); add_constraint_to_qsol(j);
@ -73,7 +73,7 @@ void quick_xplain::minimize(const vector<unsigned>& u) {
void quick_xplain::run(vector<std::pair<mpq, constraint_index>> & explanation, const lar_solver & ls){ void quick_xplain::run(vector<std::pair<mpq, constraint_index>> & explanation, const lar_solver & ls){
if (explanation.size() <= 2) return; if (explanation.size() <= 2) return;
lar_solver qsol; lar_solver qsol;
lean_assert(ls.explanation_is_correct(explanation)); lp_assert(ls.explanation_is_correct(explanation));
quick_xplain q(explanation, ls, qsol); quick_xplain q(explanation, ls, qsol);
q.solve(); q.solve();
} }
@ -109,7 +109,7 @@ bool quick_xplain::x_is_minimal() const {
x.push_back(j); x.push_back(j);
for (unsigned k = 0; k < x.size(); k++) { for (unsigned k = 0; k < x.size(); k++) {
lean_assert(is_feasible(x, x[k])); lp_assert(is_feasible(x, x[k]));
} }
return true; return true;
} }
@ -117,7 +117,7 @@ bool quick_xplain::x_is_minimal() const {
void quick_xplain::solve() { void quick_xplain::solve() {
copy_constraints_to_local_constraints(); copy_constraints_to_local_constraints();
m_qsol.push(); m_qsol.push();
lean_assert(m_qsol.constraint_count() == 0) lp_assert(m_qsol.constraint_count() == 0)
vector<unsigned> u; vector<unsigned> u;
for (unsigned k = 0; k < m_constraints_in_local_vars.size(); k++) for (unsigned k = 0; k < m_constraints_in_local_vars.size(); k++)
u.push_back(k); u.push_back(k);
@ -127,10 +127,10 @@ void quick_xplain::solve() {
for (unsigned i : m_x) for (unsigned i : m_x)
add_constraint_to_qsol(i); add_constraint_to_qsol(i);
m_qsol.solve(); m_qsol.solve();
lean_assert(m_qsol.get_status() == INFEASIBLE); lp_assert(m_qsol.get_status() == INFEASIBLE);
m_qsol.get_infeasibility_explanation(m_explanation); m_qsol.get_infeasibility_explanation(m_explanation);
lean_assert(m_qsol.explanation_is_correct(m_explanation)); lp_assert(m_qsol.explanation_is_correct(m_explanation));
lean_assert(x_is_minimal()); lp_assert(x_is_minimal());
for (auto & p : m_explanation) { for (auto & p : m_explanation) {
p.second = this->m_local_constraint_offset_to_external_ci[m_local_ci_to_constraint_offsets[p.second]]; p.second = this->m_local_constraint_offset_to_external_ci[m_local_ci_to_constraint_offsets[p.second]];
} }

View file

@ -7,7 +7,7 @@ Author: Lev Nachmanson
#include "util/vector.h" #include "util/vector.h"
#include <unordered_set> #include <unordered_set>
namespace lean { namespace lp {
class lar_solver; // forward definition class lar_solver; // forward definition
class quick_xplain { class quick_xplain {

View file

@ -12,7 +12,7 @@ Author: Lev Nachmanson
#include "util/lp/linear_combination_iterator.h" #include "util/lp/linear_combination_iterator.h"
// see http://research.microsoft.com/projects/z3/smt07.pdf // see http://research.microsoft.com/projects/z3/smt07.pdf
// The class searches for a feasible solution with as many different values of variables as it can find // The class searches for a feasible solution with as many different values of variables as it can find
namespace lean { namespace lp {
template <typename T> struct numeric_pair; // forward definition template <typename T> struct numeric_pair; // forward definition
class lar_core_solver; // forward definition class lar_core_solver; // forward definition
class random_updater { class random_updater {

View file

@ -6,7 +6,7 @@
#include "util/lp/static_matrix.h" #include "util/lp/static_matrix.h"
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
#include "util/vector.h" #include "util/vector.h"
namespace lean { namespace lp {
@ -36,7 +36,7 @@ random_updater::interval random_updater::get_interval_of_non_basic_var(unsigned
ret.set_upper_bound(m_core_solver.m_r_upper_bounds[j]); ret.set_upper_bound(m_core_solver.m_r_upper_bounds[j]);
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
return ret; return ret;
} }
@ -44,15 +44,15 @@ random_updater::interval random_updater::get_interval_of_non_basic_var(unsigned
void random_updater::diminish_interval_for_basic_var(numeric_pair<mpq>& nb_x, unsigned j, void random_updater::diminish_interval_for_basic_var(numeric_pair<mpq>& nb_x, unsigned j,
mpq & a, mpq & a,
interval & r) { interval & r) {
lean_assert(m_core_solver.m_r_heading[j] >= 0); lp_assert(m_core_solver.m_r_heading[j] >= 0);
numeric_pair<mpq> delta; numeric_pair<mpq> delta;
lean_assert(a != zero_of_type<mpq>()); lp_assert(a != zero_of_type<mpq>());
switch (m_core_solver.get_column_type(j)) { switch (m_core_solver.get_column_type(j)) {
case column_type::free_column: case column_type::free_column:
break; break;
case column_type::low_bound: case column_type::low_bound:
delta = m_core_solver.m_r_x[j] - m_core_solver.m_r_low_bounds[j]; delta = m_core_solver.m_r_x[j] - m_core_solver.m_r_low_bounds[j];
lean_assert(delta >= zero_of_type<numeric_pair<mpq>>()); lp_assert(delta >= zero_of_type<numeric_pair<mpq>>());
if (a > 0) { if (a > 0) {
r.set_upper_bound(nb_x + delta / a); r.set_upper_bound(nb_x + delta / a);
} else { } else {
@ -61,7 +61,7 @@ void random_updater::diminish_interval_for_basic_var(numeric_pair<mpq>& nb_x, un
break; break;
case column_type::upper_bound: case column_type::upper_bound:
delta = m_core_solver.m_r_upper_bounds()[j] - m_core_solver.m_r_x[j]; delta = m_core_solver.m_r_upper_bounds()[j] - m_core_solver.m_r_x[j];
lean_assert(delta >= zero_of_type<numeric_pair<mpq>>()); lp_assert(delta >= zero_of_type<numeric_pair<mpq>>());
if (a > 0) { if (a > 0) {
r.set_low_bound(nb_x - delta / a); r.set_low_bound(nb_x - delta / a);
} else { } else {
@ -71,17 +71,17 @@ void random_updater::diminish_interval_for_basic_var(numeric_pair<mpq>& nb_x, un
case column_type::boxed: case column_type::boxed:
if (a > 0) { if (a > 0) {
delta = m_core_solver.m_r_x[j] - m_core_solver.m_r_low_bounds[j]; delta = m_core_solver.m_r_x[j] - m_core_solver.m_r_low_bounds[j];
lean_assert(delta >= zero_of_type<numeric_pair<mpq>>()); lp_assert(delta >= zero_of_type<numeric_pair<mpq>>());
r.set_upper_bound(nb_x + delta / a); r.set_upper_bound(nb_x + delta / a);
delta = m_core_solver.m_r_upper_bounds()[j] - m_core_solver.m_r_x[j]; delta = m_core_solver.m_r_upper_bounds()[j] - m_core_solver.m_r_x[j];
lean_assert(delta >= zero_of_type<numeric_pair<mpq>>()); lp_assert(delta >= zero_of_type<numeric_pair<mpq>>());
r.set_low_bound(nb_x - delta / a); r.set_low_bound(nb_x - delta / a);
} else { // a < 0 } else { // a < 0
delta = m_core_solver.m_r_upper_bounds()[j] - m_core_solver.m_r_x[j]; delta = m_core_solver.m_r_upper_bounds()[j] - m_core_solver.m_r_x[j];
lean_assert(delta >= zero_of_type<numeric_pair<mpq>>()); lp_assert(delta >= zero_of_type<numeric_pair<mpq>>());
r.set_upper_bound(nb_x - delta / a); r.set_upper_bound(nb_x - delta / a);
delta = m_core_solver.m_r_x[j] - m_core_solver.m_r_low_bounds[j]; delta = m_core_solver.m_r_x[j] - m_core_solver.m_r_low_bounds[j];
lean_assert(delta >= zero_of_type<numeric_pair<mpq>>()); lp_assert(delta >= zero_of_type<numeric_pair<mpq>>());
r.set_low_bound(nb_x + delta / a); r.set_low_bound(nb_x + delta / a);
} }
break; break;
@ -90,7 +90,7 @@ void random_updater::diminish_interval_for_basic_var(numeric_pair<mpq>& nb_x, un
r.set_upper_bound(nb_x); r.set_upper_bound(nb_x);
break; break;
default: default:
lean_assert(false); lp_assert(false);
} }
} }
@ -113,15 +113,15 @@ random_updater::interval random_updater::find_shift_interval(unsigned j) {
} }
void random_updater::shift_var(unsigned j, interval & r) { void random_updater::shift_var(unsigned j, interval & r) {
lean_assert(r.contains(m_core_solver.m_r_x[j])); lp_assert(r.contains(m_core_solver.m_r_x[j]));
lean_assert(m_core_solver.m_r_solver.column_is_feasible(j)); lp_assert(m_core_solver.m_r_solver.column_is_feasible(j));
auto old_x = m_core_solver.m_r_x[j]; auto old_x = m_core_solver.m_r_x[j];
remove_value(old_x); remove_value(old_x);
auto new_val = m_core_solver.m_r_x[j] = get_random_from_interval(r); auto new_val = m_core_solver.m_r_x[j] = get_random_from_interval(r);
add_value(new_val); add_value(new_val);
lean_assert(r.contains(m_core_solver.m_r_x[j])); lp_assert(r.contains(m_core_solver.m_r_x[j]));
lean_assert(m_core_solver.m_r_solver.column_is_feasible(j)); lp_assert(m_core_solver.m_r_solver.column_is_feasible(j));
auto delta = m_core_solver.m_r_x[j] - old_x; auto delta = m_core_solver.m_r_x[j] - old_x;
unsigned i; unsigned i;
@ -130,9 +130,9 @@ void random_updater::shift_var(unsigned j, interval & r) {
while(m_column_j->next(a, i)) { while(m_column_j->next(a, i)) {
unsigned bj = m_core_solver.m_r_basis[i]; unsigned bj = m_core_solver.m_r_basis[i];
m_core_solver.m_r_x[bj] -= a * delta; m_core_solver.m_r_x[bj] -= a * delta;
lean_assert(m_core_solver.m_r_solver.column_is_feasible(bj)); lp_assert(m_core_solver.m_r_solver.column_is_feasible(bj));
} }
lean_assert(m_core_solver.m_r_solver.A_mult_x_is_off() == false); lp_assert(m_core_solver.m_r_solver.A_mult_x_is_off() == false);
} }
numeric_pair<mpq> random_updater::get_random_from_interval(interval & r) { numeric_pair<mpq> random_updater::get_random_from_interval(interval & r) {
@ -143,7 +143,7 @@ numeric_pair<mpq> random_updater::get_random_from_interval(interval & r) {
return r.low_bound + numeric_pair<mpq>(rand % range, 0); return r.low_bound + numeric_pair<mpq>(rand % range, 0);
if ((!r.low_bound_is_set) && r.upper_bound_is_set) if ((!r.low_bound_is_set) && r.upper_bound_is_set)
return r.upper_bound - numeric_pair<mpq>(rand % range, 0); return r.upper_bound - numeric_pair<mpq>(rand % range, 0);
lean_assert(r.low_bound_is_set && r.upper_bound_is_set); lp_assert(r.low_bound_is_set && r.upper_bound_is_set);
return r.low_bound + (rand % range) * (r.upper_bound - r.low_bound)/ range; return r.low_bound + (rand % range) * (r.upper_bound - r.low_bound)/ range;
} }
@ -183,7 +183,7 @@ void random_updater::add_value(numeric_pair<mpq>& v) {
void random_updater::remove_value(numeric_pair<mpq>& v) { void random_updater::remove_value(numeric_pair<mpq>& v) {
std::unordered_map<numeric_pair<mpq>, unsigned>::iterator it = m_values.find(v); std::unordered_map<numeric_pair<mpq>, unsigned>::iterator it = m_values.find(v);
lean_assert(it != m_values.end()); lp_assert(it != m_values.end());
it->second--; it->second--;
if (it->second == 0) if (it->second == 0)
m_values.erase((std::unordered_map<numeric_pair<mpq>, unsigned>::const_iterator)it); m_values.erase((std::unordered_map<numeric_pair<mpq>, unsigned>::const_iterator)it);

View file

@ -10,7 +10,7 @@
#include "util/lp/sparse_vector.h" #include "util/lp/sparse_vector.h"
#include "util/lp/indexed_vector.h" #include "util/lp/indexed_vector.h"
#include "util/lp/permutation_matrix.h" #include "util/lp/permutation_matrix.h"
namespace lean { namespace lp {
// This is the sum of a unit matrix and a lower triangular matrix // This is the sum of a unit matrix and a lower triangular matrix
// with non-zero elements only in one row // with non-zero elements only in one row
template <typename T, typename X> template <typename T, typename X>
@ -55,7 +55,7 @@ public:
} }
void push_back(unsigned row_index, T val ) { void push_back(unsigned row_index, T val ) {
lean_assert(row_index != m_row); lp_assert(row_index != m_row);
m_row_vector.push_back(row_index, val); m_row_vector.push_back(row_index, val);
} }

View file

@ -4,7 +4,7 @@
*/ */
#include "util/vector.h" #include "util/vector.h"
#include "util/lp/row_eta_matrix.h" #include "util/lp/row_eta_matrix.h"
namespace lean { namespace lp {
template <typename T, typename X> template <typename T, typename X>
void row_eta_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings &) { void row_eta_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings &) {
// #ifdef LEAN_DEBUG // #ifdef LEAN_DEBUG
@ -19,7 +19,7 @@ void row_eta_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings &) {
} }
// w[m_row] = w_at_row; // w[m_row] = w_at_row;
// #ifdef LEAN_DEBUG // #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<T>(clone_w, w, m_dimension)); // lp_assert(vectors_are_equal<T>(clone_w, w, m_dimension));
// delete [] clone_w; // delete [] clone_w;
// #endif // #endif
} }
@ -43,7 +43,7 @@ void row_eta_matrix<T, X>::apply_from_left_local_to_T(indexed_vector<T> & w, lp_
auto it = std::find(w.m_index.begin(), w.m_index.end(), m_row); auto it = std::find(w.m_index.begin(), w.m_index.end(), m_row);
w.m_index.erase(it); w.m_index.erase(it);
} }
// TBD: lean_assert(check_vector_for_small_values(w, settings)); // TBD: lp_assert(check_vector_for_small_values(w, settings));
} }
template <typename T, typename X> template <typename T, typename X>
@ -65,7 +65,7 @@ void row_eta_matrix<T, X>::apply_from_left_local_to_X(indexed_vector<X> & w, lp_
auto it = std::find(w.m_index.begin(), w.m_index.end(), m_row); auto it = std::find(w.m_index.begin(), w.m_index.end(), m_row);
w.m_index.erase(it); w.m_index.erase(it);
} }
// TBD: does not compile lean_assert(check_vector_for_small_values(w, settings)); // TBD: does not compile lp_assert(check_vector_for_small_values(w, settings));
} }
template <typename T, typename X> template <typename T, typename X>
@ -81,14 +81,14 @@ void row_eta_matrix<T, X>::apply_from_right(vector<T> & w) {
w[it.first] += w_row * it.second; w[it.first] += w_row * it.second;
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<T>(clone_w, w, m_dimension)); // lp_assert(vectors_are_equal<T>(clone_w, w, m_dimension));
// delete clone_w; // delete clone_w;
#endif #endif
} }
template <typename T, typename X> template <typename T, typename X>
void row_eta_matrix<T, X>::apply_from_right(indexed_vector<T> & w) { void row_eta_matrix<T, X>::apply_from_right(indexed_vector<T> & w) {
lean_assert(w.is_OK()); lp_assert(w.is_OK());
const T & w_row = w[m_row]; const T & w_row = w[m_row];
if (numeric_traits<T>::is_zero(w_row)) return; if (numeric_traits<T>::is_zero(w_row)) return;
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
@ -130,7 +130,7 @@ void row_eta_matrix<T, X>::apply_from_right(indexed_vector<T> & w) {
} }
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal(wcopy, w.m_data)); // lp_assert(vectors_are_equal(wcopy, w.m_data));
#endif #endif
} }
@ -151,7 +151,7 @@ void row_eta_matrix<T, X>::conjugate_by_permutation(permutation_matrix<T, X> & p
for (unsigned i = static_cast<unsigned>(columns.size()); i-- > 0;) for (unsigned i = static_cast<unsigned>(columns.size()); i-- > 0;)
m_row_vector.m_data[i].first = p.get_rev(columns[i]); m_row_vector.m_data[i].first = p.get_rev(columns[i]);
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG
// lean_assert(deb == *this); // lp_assert(deb == *this);
#endif #endif
} }
#ifdef LEAN_DEBUG #ifdef LEAN_DEBUG

View file

@ -6,7 +6,7 @@
#include <memory> #include <memory>
#include "util/lp/row_eta_matrix.hpp" #include "util/lp/row_eta_matrix.hpp"
#include "util/lp/lu.h" #include "util/lp/lu.h"
namespace lean { namespace lp {
template void row_eta_matrix<double, double>::conjugate_by_permutation(permutation_matrix<double, double>&); template void row_eta_matrix<double, double>::conjugate_by_permutation(permutation_matrix<double, double>&);
template void row_eta_matrix<mpq, numeric_pair<mpq> >::conjugate_by_permutation(permutation_matrix<mpq, numeric_pair<mpq> >&); template void row_eta_matrix<mpq, numeric_pair<mpq> >::conjugate_by_permutation(permutation_matrix<mpq, numeric_pair<mpq> >&);
template void row_eta_matrix<mpq, mpq>::conjugate_by_permutation(permutation_matrix<mpq, mpq>&); template void row_eta_matrix<mpq, mpq>::conjugate_by_permutation(permutation_matrix<mpq, mpq>&);

View file

@ -11,7 +11,7 @@
#include <stdlib.h> /* exit, EXIT_FAILURE */ #include <stdlib.h> /* exit, EXIT_FAILURE */
#include "util/lp/lp_utils.h" #include "util/lp/lp_utils.h"
#include "util/lp/static_matrix.h" #include "util/lp/static_matrix.h"
namespace lean { namespace lp {
// for scaling an LP // for scaling an LP
template <typename T, typename X> template <typename T, typename X>
class scaler { class scaler {
@ -31,7 +31,7 @@ public:
m_scaling_maximum(scaling_maximum), m_scaling_maximum(scaling_maximum),
m_column_scale(column_scale), m_column_scale(column_scale),
m_settings(settings) { m_settings(settings) {
lean_assert(m_column_scale.size() == 0); lp_assert(m_column_scale.size() == 0);
m_column_scale.resize(m_A.column_count(), numeric_traits<T>::one()); m_column_scale.resize(m_A.column_count(), numeric_traits<T>::one());
} }

View file

@ -5,7 +5,7 @@
#include <algorithm> #include <algorithm>
#include "util/lp/scaler.h" #include "util/lp/scaler.h"
#include "util/lp/numeric_pair.h" #include "util/lp/numeric_pair.h"
namespace lean { namespace lp {
// for scaling an LP // for scaling an LP
template <typename T, typename X> T scaler<T, X>::right_side_balance() { template <typename T, typename X> T scaler<T, X>::right_side_balance() {
T ret = zero_of_type<T>(); T ret = zero_of_type<T>();
@ -41,7 +41,7 @@ template <typename T, typename X> T scaler<T, X>::A_max() const {
template <typename T, typename X> T scaler<T, X>::get_A_ratio() const { template <typename T, typename X> T scaler<T, X>::get_A_ratio() const {
T min = A_min(); T min = A_min();
T max = A_max(); T max = A_max();
lean_assert(!m_settings.abs_val_is_smaller_than_zero_tolerance(min)); lp_assert(!m_settings.abs_val_is_smaller_than_zero_tolerance(min));
T ratio = max / min; T ratio = max / min;
return ratio; return ratio;
} }
@ -51,7 +51,7 @@ template <typename T, typename X> T scaler<T, X>::get_max_ratio_on_rows() con
unsigned i = m_A.row_count(); unsigned i = m_A.row_count();
while (i--) { while (i--) {
T den = m_A.get_min_abs_in_row(i); T den = m_A.get_min_abs_in_row(i);
lean_assert(!m_settings.abs_val_is_smaller_than_zero_tolerance(den)); lp_assert(!m_settings.abs_val_is_smaller_than_zero_tolerance(den));
T t = m_A.get_max_abs_in_row(i)/ den; T t = m_A.get_max_abs_in_row(i)/ den;
if (t > ret) if (t > ret)
ret = t; ret = t;
@ -78,7 +78,7 @@ template <typename T, typename X> void scaler<T, X>::scale_rows_with_geometri
while (i--) { while (i--) {
T max = m_A.get_max_abs_in_row(i); T max = m_A.get_max_abs_in_row(i);
T min = m_A.get_min_abs_in_row(i); T min = m_A.get_min_abs_in_row(i);
lean_assert(max > zero_of_type<T>() && min > zero_of_type<T>()); lp_assert(max > zero_of_type<T>() && min > zero_of_type<T>());
if (is_zero(max) || is_zero(min)) if (is_zero(max) || is_zero(min))
continue; continue;
T gm = T(sqrt(numeric_traits<T>::get_double(max*min))); T gm = T(sqrt(numeric_traits<T>::get_double(max*min)));

View file

@ -3,5 +3,5 @@
Author: Lev Nachmanson Author: Lev Nachmanson
*/ */
#include "util/lp/scaler.hpp" #include "util/lp/scaler.hpp"
template bool lean::scaler<double, double>::scale(); template bool lp::scaler<double, double>::scale();
template bool lean::scaler<lean::mpq, lean::mpq>::scale(); template bool lp::scaler<lp::mpq, lp::mpq>::scale();

View file

@ -5,7 +5,7 @@
#pragma once #pragma once
#include "util/lp/lp_settings.h" #include "util/lp/lp_settings.h"
#include "util/lp/lar_constraints.h" #include "util/lp/lar_constraints.h"
namespace lean { namespace lp {
struct bound_signature { struct bound_signature {
unsigned m_i; unsigned m_i;
bool m_at_low; bool m_at_low;

Some files were not shown because too many files have changed in this diff Show more