3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-25 18:15:32 +00:00
delta has to be computed based on Simplex tableau not on difference graph.
This commit is contained in:
Nikolaj Bjorner 2020-04-27 17:07:12 -07:00
parent 3a63c3751e
commit 4f462925a0
7 changed files with 91 additions and 21 deletions

View file

@ -20,7 +20,50 @@ Notes:
#include "math/simplex/simplex.h"
#include "math/simplex/sparse_matrix_def.h"
#include "math/simplex/simplex_def.h"
#include "util/rational.h"
#include "util/inf_rational.h"
namespace simplex {
template class simplex<mpz_ext>;
template class simplex<mpq_ext>;
static void refine_delta(rational& delta, inf_rational const& l, inf_rational const& u) {
if (l.get_rational() < u.get_rational() && l.get_infinitesimal() > u.get_infinitesimal()) {
rational new_delta = (u.get_rational() - l.get_rational()) / (l.get_infinitesimal() - u.get_infinitesimal());
if (new_delta < delta) {
delta = new_delta;
}
}
}
void ensure_rational_solution(simplex<mpq_ext>& S) {
rational delta(1);
for (unsigned i = 0; i < S.get_num_vars(); ++i) {
auto const& _value = S.get_value(i);
inf_rational value(rational(_value.first), rational(_value.second));
if (S.lower_valid(i)) {
auto const& _bound = S.get_lower(i);
inf_rational bound(rational(_bound.first), rational(_bound.second));
refine_delta(delta, bound, value);
}
if (S.upper_valid(i)) {
auto const& _bound = S.get_upper(i);
inf_rational bound(rational(_bound.first), rational(_bound.second));
refine_delta(delta, value, bound);
}
}
unsynch_mpq_inf_manager inf_mgr;
scoped_mpq_inf q(inf_mgr);
for (unsigned i = 0; i < S.get_num_vars(); ++i) {
auto const& _value = S.get_value(i);
rational inf(_value.second);
if (!inf.is_zero()) {
rational fin = rational(_value.first) + inf * delta;
inf = 0;
inf_mgr.set(q, fin.to_mpq(), inf.to_mpq());
S.set_value(i, q);
}
}
}
};

View file

@ -133,6 +133,8 @@ namespace simplex {
void set_upper(var_t var, eps_numeral const& b);
void get_lower(var_t var, scoped_eps_numeral& b) const { b = m_vars[var].m_lower; }
void get_upper(var_t var, scoped_eps_numeral& b) const { b = m_vars[var].m_upper; }
eps_numeral const& get_lower(var_t var) const { return m_vars[var].m_lower; }
eps_numeral const& get_upper(var_t var) const { return m_vars[var].m_upper; }
bool above_lower(var_t var, eps_numeral const& b) const;
bool below_upper(var_t var, eps_numeral const& b) const;
bool below_lower(var_t v) const;
@ -198,6 +200,7 @@ namespace simplex {
bool is_feasible() const;
};
void ensure_rational_solution(simplex<mpq_ext>& s);
};
#endif

View file

@ -5,8 +5,6 @@ Module Name:
simplex_def.h
Abstract:
Author:
Nikolaj Bjorner (nbjorner) 2014-01-15