3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-28 19:35:50 +00:00

Partial cleanup of util/lp/*

This commit is contained in:
Christoph M. Wintersteiger 2017-09-17 16:00:06 +01:00
parent 00651f8f21
commit d61b722b68
109 changed files with 3503 additions and 2023 deletions

View file

@ -1,10 +1,25 @@
/*
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 "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) {
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;
@ -27,7 +42,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::init(unsigned l
}
}
#ifdef LEAN_DEBUG
#ifdef Z3DEBUG
template <typename T, typename X> void permutation_matrix<T, X>::print(std::ostream & out) const {
out << "[";
for (unsigned i = 0; i < size(); i++) {
@ -44,13 +59,13 @@ template <typename T, typename X> void permutation_matrix<T, X>::print(std::ostr
template <typename T, typename X>
void permutation_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings & ) {
#ifdef LEAN_DEBUG
#ifdef Z3DEBUG
// dense_matrix<L, X> deb(*this);
// L * deb_w = clone_vector<L>(w, row_count());
// deb.apply_from_left(deb_w);
#endif
// std::cout << " apply_from_left " << std::endl;
lean_assert(m_X_buffer.size() == w.size());
SASSERT(m_X_buffer.size() == w.size());
unsigned i = size();
while (i-- > 0) {
m_X_buffer[i] = w[m_permutation[i]];
@ -59,8 +74,8 @@ void permutation_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings & ) {
while (i-- > 0) {
w[i] = m_X_buffer[i];
}
#ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<L>(deb_w, w, row_count()));
#ifdef Z3DEBUG
// SASSERT(vectors_are_equal<L>(deb_w, w, row_count()));
// delete [] deb_w;
#endif
}
@ -81,12 +96,12 @@ void permutation_matrix<T, X>::apply_from_left_to_T(indexed_vector<T> & w, lp_se
}
template <typename T, typename X> void permutation_matrix<T, X>::apply_from_right(vector<T> & w) {
#ifdef LEAN_DEBUG
#ifdef Z3DEBUG
// dense_matrix<T, X> deb(*this);
// T * deb_w = clone_vector<T>(w, row_count());
// deb.apply_from_right(deb_w);
#endif
lean_assert(m_T_buffer.size() == w.size());
SASSERT(m_T_buffer.size() == w.size());
for (unsigned i = 0; i < size(); i++) {
m_T_buffer[i] = w[m_rev[i]];
}
@ -94,14 +109,14 @@ template <typename T, typename X> void permutation_matrix<T, X>::apply_from_righ
for (unsigned i = 0; i < size(); i++) {
w[i] = m_T_buffer[i];
}
#ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<T>(deb_w, w, row_count()));
#ifdef Z3DEBUG
// SASSERT(vectors_are_equal<T>(deb_w, w, row_count()));
// delete [] deb_w;
#endif
}
template <typename T, typename X> void permutation_matrix<T, X>::apply_from_right(indexed_vector<T> & w) {
#ifdef LEAN_DEBUG
#ifdef Z3DEBUG
vector<T> wcopy(w.m_data);
apply_from_right(wcopy);
#endif
@ -117,9 +132,9 @@ template <typename T, typename X> void permutation_matrix<T, X>::apply_from_righ
unsigned pj = m_permutation[j];
w.set_value(buffer[i], pj);
}
lean_assert(w.is_OK());
#ifdef LEAN_DEBUG
lean_assert(vectors_are_equal(wcopy, w.m_data));
SASSERT(w.is_OK());
#ifdef Z3DEBUG
SASSERT(vectors_are_equal(wcopy, w.m_data));
#endif
}
@ -147,7 +162,7 @@ void permutation_matrix<T, X>::clear_data(indexed_vector<L> & w) {
template <typename T, typename X>template <typename L>
void permutation_matrix<T, X>::apply_reverse_from_left(indexed_vector<L> & w) {
// the result will be w = p(-1) * w
#ifdef LEAN_DEBUG
#ifdef Z3DEBUG
// dense_matrix<L, X> deb(get_reverse());
// L * deb_w = clone_vector<L>(w.m_data, row_count());
// deb.apply_from_left(deb_w);
@ -165,8 +180,8 @@ void permutation_matrix<T, X>::apply_reverse_from_left(indexed_vector<L> & w) {
w[j] = t[i];
w.m_index[i] = j;
}
#ifdef LEAN_DEBUG
// lean_assert(vectors_are_equal<L>(deb_w, w.m_data, row_count()));
#ifdef Z3DEBUG
// SASSERT(vectors_are_equal<L>(deb_w, w.m_data, row_count()));
// delete [] deb_w;
#endif
}
@ -174,7 +189,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left(indexed_vector<L> & w) {
template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_left_to_T(vector<T> & w) {
// the result will be w = p(-1) * w
lean_assert(m_T_buffer.size() == w.size());
SASSERT(m_T_buffer.size() == w.size());
unsigned i = size();
while (i-- > 0) {
m_T_buffer[m_permutation[i]] = w[i];
@ -187,7 +202,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left_to_T(vector<T> & w) {
template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_left_to_X(vector<X> & w) {
// the result will be w = p(-1) * w
lean_assert(m_X_buffer.size() == w.size());
SASSERT(m_X_buffer.size() == w.size());
unsigned i = size();
while (i-- > 0) {
m_X_buffer[m_permutation[i]] = w[i];
@ -201,7 +216,7 @@ void permutation_matrix<T, X>::apply_reverse_from_left_to_X(vector<X> & w) {
template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_right_to_T(vector<T> & w) {
// the result will be w = w * p(-1)
lean_assert(m_T_buffer.size() == w.size());
SASSERT(m_T_buffer.size() == w.size());
unsigned i = size();
while (i-- > 0) {
m_T_buffer[i] = w[m_permutation[i]];
@ -215,11 +230,11 @@ void permutation_matrix<T, X>::apply_reverse_from_right_to_T(vector<T> & w) {
template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_right_to_T(indexed_vector<T> & w) {
// the result will be w = w * p(-1)
#ifdef LEAN_DEBUG
#ifdef Z3DEBUG
// vector<T> wcopy(w.m_data);
// apply_reverse_from_right_to_T(wcopy);
#endif
lean_assert(w.is_OK());
SASSERT(w.is_OK());
vector<T> tmp;
vector<unsigned> tmp_index(w.m_index);
for (auto i : w.m_index) {
@ -232,15 +247,15 @@ void permutation_matrix<T, X>::apply_reverse_from_right_to_T(indexed_vector<T> &
w.set_value(tmp[k], m_rev[j]);
}
// lean_assert(w.is_OK());
// lean_assert(vectors_are_equal(w.m_data, wcopy));
// SASSERT(w.is_OK());
// SASSERT(vectors_are_equal(w.m_data, wcopy));
}
template <typename T, typename X>
void permutation_matrix<T, X>::apply_reverse_from_right_to_X(vector<X> & w) {
// the result will be w = w * p(-1)
lean_assert(m_X_buffer.size() == w.size());
SASSERT(m_X_buffer.size() == w.size());
unsigned i = size();
while (i-- > 0) {
m_X_buffer[i] = w[m_permutation[i]];
@ -253,7 +268,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) {
// the result will be this = (i,j)*this
lean_assert(i < size() && j < size() && i != j);
SASSERT(i < size() && j < size() && i != j);
auto pi = m_rev[i];
auto pj = m_rev[j];
set_val(pi, j);
@ -262,7 +277,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) {
// the result will be this = this * (i,j)
lean_assert(i < size() && j < size() && i != j);
SASSERT(i < size() && j < size() && i != j);
auto pi = m_permutation[i];
auto pj = m_permutation[j];
set_val(i, pj);
@ -271,7 +286,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) {
m_work_array = m_permutation;
lean_assert(p.size() == size());
SASSERT(p.size() == size());
unsigned i = size();
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
@ -281,7 +296,7 @@ template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_per
// 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) {
m_work_array = m_permutation;
lean_assert(p.size() == size());
SASSERT(p.size() == size());
unsigned i = size();
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
@ -289,7 +304,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 ?
lean_assert(q.size() == size());
SASSERT(q.size() == size());
m_work_array = m_permutation;
// the result is this = this*q(-1)
unsigned i = size();