mirror of
https://github.com/Z3Prover/z3
synced 2025-04-28 11:25:51 +00:00
add cancellations
Signed-off-by: Lev Nachmanson <levnach@hotmail.com> syntax errors Signed-off-by: Lev Nachmanson <levnach@microsoft.com> use std::vector instead of vector in cut_solver temporarily Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix in is_upper_bound, is_lower_bound Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add bound() for polynomial, needs more testing Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on resolve Signed-off-by: Lev Nachmanson <levnach@microsoft.com> implement resolve() Signed-off-by: Lev Nachmanson <levnach@microsoft.com> implement improves() Signed-off-by: Lev Nachmanson <levnach@hotmail.com> replace low_bound by lower_bound Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> better printing in cut_solver.h Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add value vector to cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on bound propagaion for cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> bound propagation for integer inequalites Signed-off-by: Lev Nachmanson <levnach@hotmail.com> bound propagation for integer inequalites Signed-off-by: Lev Nachmanson <levnach@hotmail.com> bound propagattions on integers Signed-off-by: Lev Nachmanson <levnach@hotmail.com> adding m_explanation field to cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify bound propagation in cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> calculate conflict explanation Signed-off-by: Lev Nachmanson <levnach@hotmail.com> change m_explanation type to a set Signed-off-by: Lev Nachmanson <levnach@hotmail.com> making cut_solver a member of int_solver, missing push/pop support Signed-off-by: Lev Nachmanson <levnach@hotmail.com> Nikolaj's comments Signed-off-by: Lev Nachmanson <levnach@hotmail.com> Nikolaj's comments Signed-off-by: Lev Nachmanson <levnach@hotmail.com> return explanations from cut_solver and hook up push/pop Signed-off-by: Lev Nachmanson <levnach@hotmail.com> hook up push/pop Signed-off-by: Lev Nachmanson <levnach@hotmail.com> using resize of std::vector Signed-off-by: Lev Nachmanson <levnach@hotmail.com> it is a big squashed commit Signed-off-by: Lev Nachmanson <levnach@hotmail.com> rename hpp to cpp Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fixes in push/pop of cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> return simple inequalities a part of a conflict Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on propagation and the main loop Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add file Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> init m_v[j], the var values only when j is fixed Signed-off-by: Lev Nachmanson <levnach@hotmail.com> cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> handle decide in cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> start on resolve_conflict Signed-off-by: Lev Nachmanson <levnach@hotmail.com> start on resolve_conflict Signed-off-by: Lev Nachmanson <levnach@hotmail.com> remove cut_solver_def.h Signed-off-by: Lev Nachmanson <levnach@hotmail.com> in the middle Signed-off-by: Lev Nachmanson <levnach@hotmail.com> change signature of resolve Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix the domain of the decided var Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on tightening of ineqs Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on tight ineqs Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on tightening Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on tightening Signed-off-by: Lev Nachmanson <levnach@hotmail.com> resolve conflict Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix in usage of resolve() Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on conflict resolution Signed-off-by: Lev Nachmanson <levnach@hotmail.com> cut_solver is not a template Signed-off-by: Lev Nachmanson <levnach@hotmail.com> represent var_info as a class, not a struct Signed-off-by: Lev Nachmanson <levnach@hotmail.com> make literal a class Signed-off-by: Lev Nachmanson <levnach@hotmail.com> better resolve_conflict scheme, and switch to *constraints in literals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> debug conflict resolution in cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> switch to vector Signed-off-by: Lev Nachmanson <levnach@hotmail.com> remove nondetermenistic behavior from cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> debug resolve conflict Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix backjump Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix backjump Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix backjump Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix backjump Signed-off-by: Lev Nachmanson <levnach@hotmail.com> dumb explanation Signed-off-by: Lev Nachmanson <levnach@hotmail.com> get rid of a parameter Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add lemmas origins Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use lemma_origins to provide correct explanations Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use lemma_origins to provide correct explanations Signed-off-by: Lev Nachmanson <levnach@hotmail.com> store lemmas in a separate vector Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use std::unordered_set for m_dependent_constraints Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use std::unordered_set for m_dependent_constraints Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs with lemmas Signed-off-by: Lev Nachmanson <levnach@hotmail.com> finding conflicting cores Signed-off-by: Lev Nachmanson <levnach@hotmail.com> switch from changed variables to active_set Signed-off-by: Lev Nachmanson <levnach@hotmail.com> less active constraints Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on cut_solver.h Signed-off-by: Lev Nachmanson <levnach@hotmail.com> propagate simple constraing immediately Signed-off-by: Lev Nachmanson <levnach@hotmail.com> propagate simple constraints immediately Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fixing bugs with active set Signed-off-by: Lev Nachmanson <levnach@hotmail.com> remove const_cast Signed-off-by: Lev Nachmanson <levnach@hotmail.com> towards unbounded variables Signed-off-by: Lev Nachmanson <levnach@hotmail.com> toward unbounded variables Signed-off-by: Lev Nachmanson <levnach@hotmail.com> toward unbounded variables Signed-off-by: Lev Nachmanson <levnach@hotmail.com> make lemmas_origins a set Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use correct hash and equal in m_lemma_origins Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add testing code Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add testing code Signed-off-by: Lev Nachmanson <levnach@hotmail.com> debug Signed-off-by: Lev Nachmanson <levnach@hotmail.com> debug unlimited vars Signed-off-by: Lev Nachmanson <levnach@hotmail.com> take in Nikolaj's comments and improvements Signed-off-by: Lev Nachmanson <levnach@hotmail.com> address the comments Signed-off-by: Lev Nachmanson <levnach@hotmail.com> handle unlimited vars in check_inconsistent Signed-off-by: Lev Nachmanson <levnach@hotmail.com> debug Signed-off-by: Lev Nachmanson <levnach@hotmail.com> detect trivial polynomials in resolve Signed-off-by: Lev Nachmanson <levnach@hotmail.com> Nikolaj's changes Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify handling of m_global_bound_var Signed-off-by: Lev Nachmanson <levnach@hotmail.com> decide on m_global_bound_var if it is not fixed Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify m_global_bound_var Signed-off-by: Lev Nachmanson <levnach@hotmail.com> remove m_global_bound_var, simplify the indexing of var_infos of cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> do not run cut_solver with vars without any bound Signed-off-by: Lev Nachmanson <levnach@hotmail.com> small changes Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add cancellation in cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> do not pop lemmas during a cut_solver run Signed-off-by: Lev Nachmanson <levnach@hotmail.com> treating cut_solver as an heurisitic Signed-off-by: Lev Nachmanson <levnach@hotmail.com> prepare for cut_solver returning undef Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify work with active_set in cut_solver, add stats Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify var_info literals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix a bug in fill_conflict_explanation Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix a bug in the conflict explanation Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add timeout to validate_* in theory_lra.cpp Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify cut_solver, no special treatment for simple constraints Signed-off-by: Lev Nachmanson <levnach@hotmail.com> cleanup the cancel story Signed-off-by: Lev Nachmanson <levnach@hotmail.com> cleanup cancelling Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix a bug in push/pop of cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> extract a method in int_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> some progress with the new scheme Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add testing code Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fixes in test and in literal creation Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix a bug in bound propagation in cut_solver.h Signed-off-by: Lev Nachmanson <levnach@hotmail.com> simplify cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> provide valid conflict explanation Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use a lazy push in stacked_map Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use a lazy push in stacked_map Signed-off-by: Lev Nachmanson <levnach@hotmail.com> optimize stack operations on var_info's domains Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix a bug in tightening Signed-off-by: Lev Nachmanson <levnach@hotmail.com> use the standard tactics from qflia_tactic Signed-off-by: Lev Nachmanson <levnach@hotmail.com> spread the var domain stack over literals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> spread the var domain stack over literals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> avoid cycling in cut_solver.h and fixes in push/pop Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fixes after rebase Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
58ca4518e5
commit
6202b2f2e4
103 changed files with 7035 additions and 5106 deletions
338
src/util/lp/permutation_matrix_def.h
Normal file
338
src/util/lp/permutation_matrix_def.h
Normal file
|
@ -0,0 +1,338 @@
|
|||
/*++
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename X> permutation_matrix<T, X>::permutation_matrix(unsigned length, vector<unsigned> const & values): m_permutation(length), m_rev(length) , m_T_buffer(length), m_X_buffer(length) {
|
||||
for (unsigned i = 0; i < length; i++) {
|
||||
set_val(i, values[i]);
|
||||
}
|
||||
}
|
||||
// create a unit permutation of the given length
|
||||
template <typename T, typename X> void permutation_matrix<T, X>::init(unsigned length) {
|
||||
m_permutation.resize(length);
|
||||
m_rev.resize(length);
|
||||
m_T_buffer.resize(length);
|
||||
m_X_buffer.resize(length);
|
||||
for (unsigned i = 0; i < length; i++) {
|
||||
m_permutation[i] = m_rev[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
#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++) {
|
||||
out << m_permutation[i];
|
||||
if (i < size() - 1) {
|
||||
out << ",";
|
||||
} else {
|
||||
out << "]";
|
||||
}
|
||||
}
|
||||
out << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T, typename X>
|
||||
void permutation_matrix<T, X>::apply_from_left(vector<X> & w, lp_settings & ) {
|
||||
#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;
|
||||
lp_assert(m_X_buffer.size() == w.size());
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
m_X_buffer[i] = w[m_permutation[i]];
|
||||
}
|
||||
i = size();
|
||||
while (i-- > 0) {
|
||||
w[i] = m_X_buffer[i];
|
||||
}
|
||||
#ifdef LEAN_DEBUG
|
||||
// lp_assert(vectors_are_equal<L>(deb_w, w, row_count()));
|
||||
// delete [] deb_w;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T, typename X>
|
||||
void permutation_matrix<T, X>::apply_from_left_to_T(indexed_vector<T> & w, lp_settings & ) {
|
||||
vector<T> t(w.m_index.size());
|
||||
vector<unsigned> tmp_index(w.m_index.size());
|
||||
copy_aside(t, tmp_index, w); // todo: is it too much copying
|
||||
clear_data(w);
|
||||
// set the new values
|
||||
for (unsigned i = static_cast<unsigned>(t.size()); i > 0;) {
|
||||
i--;
|
||||
unsigned j = m_rev[tmp_index[i]];
|
||||
w[j] = t[i];
|
||||
w.m_index[i] = j;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename X> void permutation_matrix<T, X>::apply_from_right(vector<T> & w) {
|
||||
#ifdef Z3DEBUG
|
||||
// dense_matrix<T, X> deb(*this);
|
||||
// T * deb_w = clone_vector<T>(w, row_count());
|
||||
// deb.apply_from_right(deb_w);
|
||||
#endif
|
||||
lp_assert(m_T_buffer.size() == w.size());
|
||||
for (unsigned i = 0; i < size(); i++) {
|
||||
m_T_buffer[i] = w[m_rev[i]];
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < size(); i++) {
|
||||
w[i] = m_T_buffer[i];
|
||||
}
|
||||
#ifdef LEAN_DEBUG
|
||||
// lp_assert(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 Z3DEBUG
|
||||
vector<T> wcopy(w.m_data);
|
||||
apply_from_right(wcopy);
|
||||
#endif
|
||||
vector<T> buffer(w.m_index.size());
|
||||
vector<unsigned> index_copy(w.m_index);
|
||||
for (unsigned i = 0; i < w.m_index.size(); i++) {
|
||||
buffer[i] = w.m_data[w.m_index[i]];
|
||||
}
|
||||
w.clear();
|
||||
|
||||
for (unsigned i = 0; i < index_copy.size(); i++) {
|
||||
unsigned j = index_copy[i];
|
||||
unsigned pj = m_permutation[j];
|
||||
w.set_value(buffer[i], pj);
|
||||
}
|
||||
lp_assert(w.is_OK());
|
||||
#ifdef LEAN_DEBUG
|
||||
lp_assert(vectors_are_equal(wcopy, w.m_data));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename X> template <typename L>
|
||||
void permutation_matrix<T, X>::copy_aside(vector<L> & t, vector<unsigned> & tmp_index, indexed_vector<L> & w) {
|
||||
for (unsigned i = static_cast<unsigned>(t.size()); i > 0;) {
|
||||
i--;
|
||||
unsigned j = w.m_index[i];
|
||||
t[i] = w[j]; // copy aside all non-zeroes
|
||||
tmp_index[i] = j; // and the indices too
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename X> template <typename L>
|
||||
void permutation_matrix<T, X>::clear_data(indexed_vector<L> & w) {
|
||||
// clear old non-zeroes
|
||||
for (unsigned i = static_cast<unsigned>(w.m_index.size()); i > 0;) {
|
||||
i--;
|
||||
unsigned j = w.m_index[i];
|
||||
w[j] = zero_of_type<L>();
|
||||
}
|
||||
}
|
||||
|
||||
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 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);
|
||||
#endif
|
||||
vector<L> t(w.m_index.size());
|
||||
vector<unsigned> tmp_index(w.m_index.size());
|
||||
|
||||
copy_aside(t, tmp_index, w);
|
||||
clear_data(w);
|
||||
|
||||
// set the new values
|
||||
for (unsigned i = static_cast<unsigned>(t.size()); i > 0;) {
|
||||
i--;
|
||||
unsigned j = m_permutation[tmp_index[i]];
|
||||
w[j] = t[i];
|
||||
w.m_index[i] = j;
|
||||
}
|
||||
#ifdef LEAN_DEBUG
|
||||
// lp_assert(vectors_are_equal<L>(deb_w, w.m_data, row_count()));
|
||||
// delete [] deb_w;
|
||||
#endif
|
||||
}
|
||||
|
||||
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
|
||||
lp_assert(m_T_buffer.size() == w.size());
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
m_T_buffer[m_permutation[i]] = w[i];
|
||||
}
|
||||
i = size();
|
||||
while (i-- > 0) {
|
||||
w[i] = m_T_buffer[i];
|
||||
}
|
||||
}
|
||||
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
|
||||
lp_assert(m_X_buffer.size() == w.size());
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
m_X_buffer[m_permutation[i]] = w[i];
|
||||
}
|
||||
i = size();
|
||||
while (i-- > 0) {
|
||||
w[i] = m_X_buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
lp_assert(m_T_buffer.size() == w.size());
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
m_T_buffer[i] = w[m_permutation[i]];
|
||||
}
|
||||
i = size();
|
||||
while (i-- > 0) {
|
||||
w[i] = m_T_buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
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 Z3DEBUG
|
||||
// vector<T> wcopy(w.m_data);
|
||||
// apply_reverse_from_right_to_T(wcopy);
|
||||
#endif
|
||||
lp_assert(w.is_OK());
|
||||
vector<T> tmp;
|
||||
vector<unsigned> tmp_index(w.m_index);
|
||||
for (auto i : w.m_index) {
|
||||
tmp.push_back(w[i]);
|
||||
}
|
||||
w.clear();
|
||||
|
||||
for (unsigned k = 0; k < tmp_index.size(); k++) {
|
||||
unsigned j = tmp_index[k];
|
||||
w.set_value(tmp[k], m_rev[j]);
|
||||
}
|
||||
|
||||
// lp_assert(w.is_OK());
|
||||
// lp_assert(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)
|
||||
lp_assert(m_X_buffer.size() == w.size());
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
m_X_buffer[i] = w[m_permutation[i]];
|
||||
}
|
||||
i = size();
|
||||
while (i-- > 0) {
|
||||
w[i] = m_X_buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
lp_assert(i < size() && j < size() && i != j);
|
||||
auto pi = m_rev[i];
|
||||
auto pj = m_rev[j];
|
||||
set_val(pi, j);
|
||||
set_val(pj, i);
|
||||
}
|
||||
|
||||
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)
|
||||
lp_assert(i < size() && j < size() && i != j);
|
||||
auto pi = m_permutation[i];
|
||||
auto pj = m_permutation[j];
|
||||
set_val(i, pj);
|
||||
set_val(j, pi);
|
||||
}
|
||||
|
||||
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;
|
||||
lp_assert(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
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
lp_assert(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
|
||||
|
||||
}
|
||||
|
||||
template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_reverse_from_right(permutation_matrix<T, X> & q){ // todo : condensed permutations ?
|
||||
lp_assert(q.size() == size());
|
||||
m_work_array = m_permutation;
|
||||
// the result is this = this*q(-1)
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
set_val(i, q.m_rev[m_work_array[i]]); // we have m(P)*m(Q) = m(QP), where m is the matrix of the permutation
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_permutation_reverse_from_left(permutation_matrix<T, X> & r){ // todo : condensed permutations?
|
||||
// the result is this = r(-1)*this
|
||||
m_work_array = m_permutation;
|
||||
// the result is this = this*q(-1)
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
set_val(i, m_work_array[r.m_rev[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename X> bool permutation_matrix<T, X>::is_identity() const {
|
||||
unsigned i = size();
|
||||
while (i-- > 0) {
|
||||
if (m_permutation[i] != i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue