mirror of
https://github.com/Z3Prover/z3
synced 2025-04-28 03:15:50 +00:00
mv util/lp to math/lp
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
b6513b8e2d
commit
33cbd29ed0
150 changed files with 524 additions and 479 deletions
61
src/math/lp/column_namer.h
Normal file
61
src/math/lp/column_namer.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#pragma once
|
||||
/*++
|
||||
Copyright (c) 2017 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
<name>
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Lev Nachmanson (levnach)
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
#include <string>
|
||||
#include "math/lp/static_matrix.h"
|
||||
namespace lp {
|
||||
class column_namer {
|
||||
public:
|
||||
virtual std::string get_variable_name(unsigned j) const = 0;
|
||||
template <typename T>
|
||||
void print_row(const row_strip<T> & row, std::ostream & out) const {
|
||||
vector<std::pair<T, unsigned>> coeff;
|
||||
for (auto & p : row) {
|
||||
coeff.push_back(std::make_pair(p.coeff(), p.var()));
|
||||
}
|
||||
print_linear_combination_of_column_indices(coeff, out);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void print_linear_combination_of_column_indices(const vector<std::pair<T, unsigned>> & coeffs, std::ostream & out) const {
|
||||
bool first = true;
|
||||
for (const auto & it : coeffs) {
|
||||
auto val = it.first;
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
if (numeric_traits<T>::is_pos(val)) {
|
||||
out << " + ";
|
||||
} else {
|
||||
out << " - ";
|
||||
val = -val;
|
||||
}
|
||||
}
|
||||
if (val == -numeric_traits<T>::one())
|
||||
out << " - ";
|
||||
else if (val != numeric_traits<T>::one())
|
||||
out << val;
|
||||
|
||||
out << get_variable_name(it.second);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue