mirror of
https://github.com/Z3Prover/z3
synced 2025-05-03 22:05:45 +00:00
Partial cleanup of util/lp/*
This commit is contained in:
parent
00651f8f21
commit
d61b722b68
109 changed files with 3503 additions and 2023 deletions
|
@ -1,16 +1,31 @@
|
|||
/*
|
||||
Copyright (c) 2017 Microsoft Corporation
|
||||
Author: Lev Nachmanson
|
||||
*/
|
||||
/*++
|
||||
Copyright (c) 2017 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
<name>
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Lev Nachmanson (levnach)
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
#include "util/vector.h"
|
||||
#include <utility>
|
||||
#include <set>
|
||||
#include "util/lp/static_matrix.h"
|
||||
namespace lean {
|
||||
namespace lp {
|
||||
// each assignment for this matrix should be issued only once!!!
|
||||
template <typename T, typename X>
|
||||
void static_matrix<T, X>::init_row_columns(unsigned m, unsigned n) {
|
||||
lean_assert(m_rows.size() == 0 && m_columns.size() == 0);
|
||||
SASSERT(m_rows.size() == 0 && m_columns.size() == 0);
|
||||
for (unsigned i = 0; i < m; i++){
|
||||
m_rows.push_back(row_strip());
|
||||
}
|
||||
|
@ -30,23 +45,23 @@ template <typename T, typename X> void static_matrix<T, X>::scan_row_ii_to_offse
|
|||
|
||||
template <typename T, typename X> bool static_matrix<T, X>::pivot_row_to_row_given_cell(unsigned i, column_cell & c, unsigned pivot_col) {
|
||||
unsigned ii = c.m_i;
|
||||
lean_assert(i < row_count() && ii < column_count());
|
||||
lean_assert(i != ii);
|
||||
SASSERT(i < row_count() && ii < column_count());
|
||||
SASSERT(i != ii);
|
||||
|
||||
m_became_zeros.reset();
|
||||
T alpha = -get_val(c);
|
||||
lean_assert(!is_zero(alpha));
|
||||
SASSERT(!is_zero(alpha));
|
||||
auto & ii_row_vals = m_rows[ii];
|
||||
remove_element(ii_row_vals, ii_row_vals[c.m_offset]);
|
||||
scan_row_ii_to_offset_vector(ii);
|
||||
lean_assert(!is_zero(alpha));
|
||||
SASSERT(!is_zero(alpha));
|
||||
unsigned prev_size_ii = ii_row_vals.size();
|
||||
// run over the pivot row and update row ii
|
||||
for (const auto & iv : m_rows[i]) {
|
||||
unsigned j = iv.m_j;
|
||||
if (j == pivot_col) continue;
|
||||
T alv = alpha * iv.m_value;
|
||||
lean_assert(!is_zero(iv.m_value));
|
||||
SASSERT(!is_zero(iv.m_value));
|
||||
int j_offs = m_vector_of_row_offsets[j];
|
||||
if (j_offs == -1) { // it is a new element
|
||||
add_new_element(ii, j, alv);
|
||||
|
@ -104,9 +119,9 @@ template <typename T, typename X> void static_matrix<T, X>::init_empty_matrix
|
|||
}
|
||||
|
||||
template <typename T, typename X> unsigned static_matrix<T, X>::lowest_row_in_column(unsigned col) {
|
||||
lean_assert(col < column_count());
|
||||
SASSERT(col < column_count());
|
||||
column_strip & colstrip = m_columns[col];
|
||||
lean_assert(colstrip.size() > 0);
|
||||
SASSERT(colstrip.size() > 0);
|
||||
unsigned ret = 0;
|
||||
for (auto & t : colstrip) {
|
||||
if (t.m_i > ret) {
|
||||
|
@ -122,7 +137,7 @@ template <typename T, typename X> void static_matrix<T, X>::add_columns_at_th
|
|||
}
|
||||
|
||||
template <typename T, typename X> void static_matrix<T, X>::forget_last_columns(unsigned how_many_to_forget) {
|
||||
lean_assert(m_columns.size() >= how_many_to_forget);
|
||||
SASSERT(m_columns.size() >= how_many_to_forget);
|
||||
unsigned j = column_count() - 1;
|
||||
for (; how_many_to_forget > 0; how_many_to_forget--) {
|
||||
remove_last_column(j --);
|
||||
|
@ -151,7 +166,7 @@ template <typename T, typename X> void static_matrix<T, X>::remove_last_column(u
|
|||
|
||||
template <typename T, typename X> void static_matrix<T, X>::set(unsigned row, unsigned col, T const & val) {
|
||||
if (numeric_traits<T>::is_zero(val)) return;
|
||||
lean_assert(row < row_count() && col < column_count());
|
||||
SASSERT(row < row_count() && col < column_count());
|
||||
auto & r = m_rows[row];
|
||||
unsigned offs_in_cols = static_cast<unsigned>(m_columns[col].size());
|
||||
m_columns[col].push_back(make_column_cell(row, static_cast<unsigned>(r.size())));
|
||||
|
@ -171,7 +186,7 @@ std::set<std::pair<unsigned, unsigned>> static_matrix<T, X>::get_domain() {
|
|||
|
||||
|
||||
template <typename T, typename X> void static_matrix<T, X>::copy_column_to_indexed_vector (unsigned j, indexed_vector<T> & v) const {
|
||||
lean_assert(j < m_columns.size());
|
||||
SASSERT(j < m_columns.size());
|
||||
for (auto & it : m_columns[j]) {
|
||||
const T& val = get_val(it);
|
||||
if (!is_zero(val))
|
||||
|
@ -234,13 +249,13 @@ template <typename T, typename X> T static_matrix<T, X>::get_min_abs_in_colu
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef LEAN_DEBUG
|
||||
#ifdef Z3DEBUG
|
||||
template <typename T, typename X> void static_matrix<T, X>::check_consistency() {
|
||||
std::unordered_map<std::pair<unsigned, unsigned>, T> by_rows;
|
||||
for (int i = 0; i < m_rows.size(); i++){
|
||||
for (auto & t : m_rows[i]) {
|
||||
std::pair<unsigned, unsigned> p(i, t.m_j);
|
||||
lean_assert(by_rows.find(p) == by_rows.end());
|
||||
SASSERT(by_rows.find(p) == by_rows.end());
|
||||
by_rows[p] = t.get_val();
|
||||
}
|
||||
}
|
||||
|
@ -248,11 +263,11 @@ template <typename T, typename X> void static_matrix<T, X>::check_consistency
|
|||
for (int i = 0; i < m_columns.size(); i++){
|
||||
for (auto & t : m_columns[i]) {
|
||||
std::pair<unsigned, unsigned> p(t.m_i, i);
|
||||
lean_assert(by_cols.find(p) == by_cols.end());
|
||||
SASSERT(by_cols.find(p) == by_cols.end());
|
||||
by_cols[p] = get_val(t);
|
||||
}
|
||||
}
|
||||
lean_assert(by_rows.size() == by_cols.size());
|
||||
SASSERT(by_rows.size() == by_cols.size());
|
||||
|
||||
for (auto & t : by_rows) {
|
||||
auto ic = by_cols.find(t.first);
|
||||
|
@ -260,21 +275,21 @@ template <typename T, typename X> void static_matrix<T, X>::check_consistency
|
|||
//std::cout << "rows have pair (" << t.first.first <<"," << t.first.second
|
||||
// << "), but columns don't " << std::endl;
|
||||
}
|
||||
lean_assert(ic != by_cols.end());
|
||||
lean_assert(t.second == ic->second);
|
||||
SASSERT(ic != by_cols.end());
|
||||
SASSERT(t.second == ic->second);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
template <typename T, typename X> void static_matrix<T, X>::cross_out_row(unsigned k) {
|
||||
#ifdef LEAN_DEBUG
|
||||
#ifdef Z3DEBUG
|
||||
check_consistency();
|
||||
#endif
|
||||
cross_out_row_from_columns(k, m_rows[k]);
|
||||
fix_row_indices_in_each_column_for_crossed_row(k);
|
||||
m_rows.erase(m_rows.begin() + k);
|
||||
#ifdef LEAN_DEBUG
|
||||
#ifdef Z3DEBUG
|
||||
regen_domain();
|
||||
check_consistency();
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue