Commit 91eff718 authored by Henrik Zimmer's avatar Henrik Zimmer
Browse files

Improved search for variables to be eliminated. Try to eliminate reals first integers last.

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@26 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent f0634972
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
/// default Constructor /// default Constructor
ConstrainedSolver() { } ConstrainedSolver() { epsilon_ = 1e-6; }
/// Destructor /// Destructor
~ConstrainedSolver() { } ~ConstrainedSolver() { }
...@@ -203,6 +203,8 @@ public: ...@@ -203,6 +203,8 @@ public:
/*@}*/ /*@}*/
/// Set numerical epsilon for valid constraint coefficient
void set_epsilon( double _epsilon) { epsilon_ = _epsilon;}
/** @name Verify the result. /** @name Verify the result.
* Functions to verify the result of the constrained solver. Are the constraints met, are the correct variables correctly rounded ... * Functions to verify the result of the constrained solver. Are the constraints met, are the correct variables correctly rounded ...
...@@ -268,6 +270,8 @@ private: ...@@ -268,6 +270,8 @@ private:
/// Assignment operator (not used) /// Assignment operator (not used)
ConstrainedSolver& operator=(const ConstrainedSolver& _rhs); ConstrainedSolver& operator=(const ConstrainedSolver& _rhs);
double epsilon_;
}; };
......
...@@ -211,6 +211,7 @@ make_constraints_independent( ...@@ -211,6 +211,7 @@ make_constraints_independent(
{ {
// get elimination variable // get elimination variable
int elim_j = -1; int elim_j = -1;
int elim_int_j = -1;
// iterate over current row, until variable found // iterate over current row, until variable found
// first search for real valued variable // first search for real valued variable
...@@ -245,28 +246,38 @@ make_constraints_independent( ...@@ -245,28 +246,38 @@ make_constraints_independent(
//break; //break;
} }
else else
// store smallest integer {
if( fabs(*row_it) < elim_val) // store integer closest to 1
if( fabs(fabs(*row_it)-1.0) < elim_val)
{ {
elim_j = cur_j; elim_int_j = cur_j;
elim_val = fabs(*row_it); elim_val = fabs(fabs(*row_it)-1.0);
} }
}
} }
} }
// first try to eliminate a valid (>epsilon_) real valued variable (safer)
if( max_elim_val > epsilon_)
{}
else // use the best found integer
elim_j = elim_int_j;
// store result // store result
_c_elim[i] = elim_j; _c_elim[i] = elim_j;
// error check result // error check result
if( elim_j == -1) if( elim_j == -1)
{ {
// redundant or incompatible? // redundant or incompatible?
if( fabs(gmm::mat_const_row(_constraints, i)[n_vars-1]) > 1e-6 ) if( fabs(gmm::mat_const_row(_constraints, i)[n_vars-1]) > epsilon_ )
std::cerr << "Warning: incompatible condition:\n"; std::cerr << "Warning: incompatible condition:\n";
else else
std::cerr << "Warning: redundant condition:\n"; std::cerr << "Warning: redundant condition:\n";
} }
else else
if(roundmap[elim_j] && fabs(elim_val-1.0) > 1e-6) if(roundmap[elim_j] && elim_val > 1e-6)
std::cerr << "Warning: eliminate non +-1 integer -> correct rounding cannot be guaranteed:\n" std::cerr << "Warning: eliminate non +-1 integer -> correct rounding cannot be guaranteed:\n"
<< gmm::mat_const_row(_constraints, i) << std::endl; << gmm::mat_const_row(_constraints, i) << std::endl;
...@@ -274,7 +285,7 @@ make_constraints_independent( ...@@ -274,7 +285,7 @@ make_constraints_independent(
if( elim_j != -1 ) if( elim_j != -1 )
{ {
// get elim variable value // get elim variable value
double elim_val = _constraints(i, elim_j); double elim_val_cur = _constraints(i, elim_j);
// copy col // copy col
CVector col = constraints_c.col(elim_j); CVector col = constraints_c.col(elim_j);
...@@ -287,7 +298,7 @@ make_constraints_independent( ...@@ -287,7 +298,7 @@ make_constraints_independent(
if( c_it.index() > i) if( c_it.index() > i)
{ {
sw.start(); sw.start();
add_row_simultaneously( c_it.index(), -(*c_it)/elim_val, gmm::mat_row(_constraints, i), _constraints, constraints_c); add_row_simultaneously( c_it.index(), -(*c_it)/elim_val_cur, gmm::mat_row(_constraints, i), _constraints, constraints_c);
// make sure the eliminated entry is 0 on all other rows and not 1e-17 // make sure the eliminated entry is 0 on all other rows and not 1e-17
_constraints( c_it.index(), elim_j) = 0; _constraints( c_it.index(), elim_j) = 0;
constraints_c(c_it.index(), elim_j) = 0; constraints_c(c_it.index(), elim_j) = 0;
......
Supports Markdown
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