Commit d3a3b0fa authored by Max Lyon's avatar Max Lyon
Browse files

allow setting largest exponent from the outside

parent 20123f2f
......@@ -9,6 +9,8 @@
namespace COMISO {
ExactConstraintSatisfaction::ExactConstraintSatisfaction()
:
largest_exponent_(std::numeric_limits<int>::min())
{
}
......@@ -110,16 +112,23 @@ void ExactConstraintSatisfaction::print_vector(Eigen::VectorXi b)
std::cout << std::endl;
}
int ExactConstraintSatisfaction::largest_exponent(const Eigen::VectorXd& x)
void ExactConstraintSatisfaction::largest_exponent(const Eigen::VectorXd& x)
{
// only compute largest component if it was not set from the outside
if (largest_exponent_ == std::numeric_limits<int>::min())
set_largest_exponent(std::max(compute_largest_exponent(x)+2, -65));
}
int expo = -65;
for(int i = 0; i < x.size(); i++)
{
expo = std::max(expo, static_cast<int>(std::ceil(std::log2(std::abs(x.coeffRef(i)))) + 2));
}
largest_exponent_ = expo;
delta_ = std::pow(2, expo);
void ExactConstraintSatisfaction::set_largest_exponent(int _exponent)
{
largest_exponent_ = _exponent;
delta_ = std::pow(2, largest_exponent_);
}
int ExactConstraintSatisfaction::compute_largest_exponent(const Eigen::VectorXd& x)
{
double max_elem = std::max(x.maxCoeff(), -x.minCoeff());
auto expo = static_cast<int>(std::ceil(std::log2(max_elem)));
return expo;
}
......
......@@ -33,7 +33,9 @@ public:
void swap_rows(SP_Matrix_R& mat, int row1, int row2);
void eliminate_row(SP_Matrix_R& mat, Eigen::VectorXi& b, int row1, int row2, int pivot_column);
int largest_exponent(const Eigen::VectorXd& x);
void largest_exponent(const Eigen::VectorXd& x);
void set_largest_exponent(int _exponent);
static int compute_largest_exponent(const Eigen::VectorXd& x);
int index_pivot(const sparseVec& row);
double F_delta(double x);
double get_delta();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment