[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29273] branches/soc-2010-rohith291991/ intern/comiso/Examples/quadratic_solver: Some cleanup.
Rohith B V
rohith291991 at gmail.com
Sun Jun 6 16:47:52 CEST 2010
Revision: 29273
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29273
Author: rohith291991
Date: 2010-06-06 16:47:51 +0200 (Sun, 06 Jun 2010)
Log Message:
-----------
Some cleanup. Same functionality as last commit.
Modified Paths:
--------------
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.h
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/MISolver.cc
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/MISolver.h
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/StopWatch.h
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/comiso.cc
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/common.cc
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/common.h
Modified: branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc 2010-06-06 13:32:58 UTC (rev 29272)
+++ branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc 2010-06-06 14:47:51 UTC (rev 29273)
@@ -1,413 +1,378 @@
/*===========================================================================*\
- * *
- * CoMISo *
- * Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen *
- * www.rwth-graphics.de *
- * *
- *---------------------------------------------------------------------------*
- * This file is part of CoMISo. *
- * *
- * CoMISo is free software: you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * CoMISo is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with CoMISo. If not, see <http://www.gnu.org/licenses/>. *
- * *
+* *
+* CoMISo *
+* Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen *
+* www.rwth-graphics.de *
+* *
+*---------------------------------------------------------------------------*
+* This file is part of CoMISo. *
+* *
+* CoMISo is free software: you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation, either version 3 of the License, or *
+* (at your option) any later version. *
+* *
+* CoMISo is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with CoMISo. If not, see <http://www.gnu.org/licenses/>. *
+* *
\*===========================================================================*/
#include "ConstrainedSolver.h"
-
void
ConstrainedSolver::
add_row_simultaneously( int _row_i,
- double _coeff,
- MatrixXd _row,
- MatrixXd& _rmat,
- MatrixXd& _cmat )
-{
-
- //SparseVr row = SparseVr(_constraints.row(i));
- int n=_row.cols();
+ double _coeff,
+ MatrixXd _row,
+ MatrixXd& _rmat,
+ MatrixXd& _cmat )
+ {
- for(int i=0; i<n; i++)
- {
+ int n=_row.cols();
- _rmat(_row_i, i) += _coeff*(_row(0,i));
- _cmat(_row_i, i) += _coeff*(_row(0,i));
+ for(int i=0; i<n; i++)
+ {
- }
-}
+ _rmat(_row_i, i) += _coeff*(_row(0,i));
+ _cmat(_row_i, i) += _coeff*(_row(0,i));
+ }
+ }
+
void
ConstrainedSolver::
make_constraints_independent(
- MatrixXd& _constraints,
- std::vector<int>& _idx_to_round,
- std::vector<int>& _c_elim)
-{
- ACG::StopWatch sw;
- // number of variables
- int n_vars = _constraints.cols();
+ MatrixXd& _constraints,
+ std::vector<int>& _idx_to_round,
+ std::vector<int>& _c_elim)
+ {
+ ACG::StopWatch sw;
+ // number of variables
+ int n_vars = _constraints.cols();
- // NOT MINE TODO Check: HZ added 14.08.09
- _c_elim.clear();
- _c_elim.resize( _constraints.cols(), -1);
+ //TODO Check: HZ added 14.08.09
+ _c_elim.clear();
+ _c_elim.resize( _constraints.cols(), -1);
-
- // build round map
- std::vector<bool> roundmap( n_vars, false);
- for(unsigned int i=0; i<_idx_to_round.size(); ++i)
- roundmap[_idx_to_round[i]] = true;
+ // build round map
+ std::vector<bool> roundmap( n_vars, false);
+ for(unsigned int i=0; i<_idx_to_round.size(); ++i)
+ roundmap[_idx_to_round[i]] = true;
- // copy constraints into column matrix (for faster update via iterators)
- // ---> REMOVED typedef gmm::wsvector<double> CVector;
- // ---> REMOVED typedef gmm::col_matrix< CVector > CMatrix;
- MatrixXd constraints_c;
+ // copy constraints into column matrix (for faster update via iterators)
- constraints_c.resize(_constraints.rows(), _constraints.cols());
- constraints_c=MatrixXd(_constraints);
+ MatrixXd constraints_c;
- // for all conditions
- for(unsigned int i=0; i<_constraints.rows(); ++i)
- {
- // get elimination variable
- int elim_j = -1;
-
- // iterate over current row, until variable found
- // first search for real valued variable
- // if not found for integers with value +-1
- // and finally take the smallest integer variable
-//DONE but watch out for errors here
+ constraints_c.resize(_constraints.rows(), _constraints.cols());
+ constraints_c=MatrixXd(_constraints);
+ // for all conditions
+ for(unsigned int i=0; i<_constraints.rows(); ++i)
+ {
+ // get elimination variable
+ int elim_j = -1;
- // get current condition row
-int nr=_constraints.rows();
+ // iterate over current row, until variable found
+ // first search for real valued variable
+ // if not found for integers with value +-1
+ // and finally take the smallest integer variable
+ // get current condition row
+ int nr=_constraints.rows();
- // RIter row_it = gmm::vect_const_begin( row);
- // RIter row_end = gmm::vect_const_end( row);
- double elim_val = FLT_MAX;
+ double elim_val = FLT_MAX;
-
- for(int j=0;j<n_vars-1;j++)
- // do not use the constant part
- if( _constraints(i,j)!=0 )
- {
- // found real valued var? -> finished
- if( !roundmap[ j ])
- {
- elim_j = j;
- break;
- }
- else
- // store smallest integer
- if( fabs(_constraints(i,j)) < elim_val)
- {
- elim_j = j;
- elim_val = fabs(_constraints(i,j));
- }
- }
-
-
+ for(int j=0;j<n_vars-1;j++)
+ // do not use the constant part
+ if( _constraints(i,j)!=0 )
+ {
+ // found real valued var? -> finished
+ if( !roundmap[ j ])
+ {
+ elim_j = j;
+ break;
+ }
+ else
+ // store smallest integer
+ if( fabs(_constraints(i,j)) < elim_val)
+ {
+ elim_j = j;
+ elim_val = fabs(_constraints(i,j));
+ }
+ }
- // store result
- _c_elim[i] = elim_j;
- // error check result
- if( elim_j == -1)
- {
- // redundant or incompatible?
- // DONE but watch out for errors
+ // store result
+ _c_elim[i] = elim_j;
+ // error check result
+ if( elim_j == -1)
+ {
+ // redundant or incompatible?
- //VectorXd cons=SparseVr(_constraints.row(i)).toDense();
- if( fabs(_constraints(i,n_vars-1) )> 1e-6 )
- std::cerr << "Warning: incompatible condition:\n";
- else
- std::cerr << "Warning: redundant condition:\n";
+ if( fabs(_constraints(i,n_vars-1) )> 1e-6 )
+ std::cerr << "Warning: incompatible condition:\n";
+ else
+ std::cerr << "Warning: redundant condition:\n";
- }
- else
- if(roundmap[elim_j] && fabs(elim_val-1.0) > 1e-6)
- std::cerr << "Warning: eliminate non +-1 integer -> correct rounding cannot be guaranteed:\n"
-
- << (_constraints.row(i)) << std::endl;
+ }
+ else
+ if(roundmap[elim_j] && fabs(elim_val-1.0) > 1e-6)
+ std::cerr << "Warning: eliminate non +-1 integer -> correct rounding cannot be guaranteed:\n"
- // is this condition dependent?
- if( elim_j != -1 )
- {
- // get elim variable value
+ << (_constraints.row(i)) << std::endl;
-
- double elim_val = _constraints(i, elim_j);
+ // is this condition dependent?
+ if( elim_j != -1 )
+ {
+ // get elim variable value
-int nr=constraints_c.rows();
-int nc=constraints_c.cols();
- // copy col
-
-int l;
-
+ double elim_val = _constraints(i, elim_j);
- for(l=i+1 ;l<nr;l++)
- if( constraints_c(l,elim_j)!=0 )
- {
-
-
- sw.start();
+ int nr=constraints_c.rows();
+ int nc=constraints_c.cols();
+ // copy col
-
- add_row_simultaneously( l, -(constraints_c(l,elim_j))/elim_val, _constraints.row(i), _constraints, constraints_c);
+ int l;
- // make sure the eliminated entry is 0 on all other rows and not 1e-17
- _constraints( l, elim_j) = 0;
- constraints_c( l, elim_j) = 0;
-
+
+ for(l=i+1 ;l<nr;l++)
+ if( constraints_c(l,elim_j)!=0 )
+ {
+
+
+ sw.start();
+
+
+ add_row_simultaneously( l, -(constraints_c(l,elim_j))/elim_val, _constraints.row(i), _constraints, constraints_c);
+
+ // make sure the eliminated entry is 0 on all other rows and not 1e-17
+ _constraints( l, elim_j) = 0;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list