[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29156] branches/soc-2010-rohith291991/ intern/comiso: Everything required adapted to eigen2 except MISolver.
Rohith B V
rohith291991 at gmail.com
Wed Jun 2 14:20:13 CEST 2010
Revision: 29156
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29156
Author: rohith291991
Date: 2010-06-02 14:20:13 +0200 (Wed, 02 Jun 2010)
Log Message:
-----------
Everything required adapted to eigen2 except MISolver. Next commit will be done only after that is done and it compiles. This commit does not compile yet.
Modified Paths:
--------------
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/main.cc
branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolverT.cc
branches/soc-2010-rohith291991/intern/comiso/Solver/GMM_Tools.cc
branches/soc-2010-rohith291991/intern/comiso/Solver/MISolver.hh
branches/soc-2010-rohith291991/intern/comiso/Solver/common.h
Modified: branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/main.cc
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/main.cc 2010-06-02 11:18:19 UTC (rev 29155)
+++ branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/main.cc 2010-06-02 12:20:13 UTC (rev 29156)
@@ -48,6 +48,9 @@
// ROHITH - Modify These
#include <CoMISo/Solver/ConstrainedSolver.hh>
#include <CoMISo/Solver/MISolver.hh>
+
+
+// WILL HAVE TO BE MODIFIED COMPLETELY
#include <CoMISo/Solver/GMM_Tools.hh>
@@ -192,7 +195,7 @@
print_equations( C );
std::cout << std::endl;
- std::cout << "---------- 4) we now explicitly carry out the steps performed internally by the constrained solver and compare the two results at the end..." << std::endl;
+ std::cout << "---------- 4) we now explicitly carry out the steps performed internally by the constrained solver" << std::endl;
// copy the matrices
SparseXdc Acpy( A );
@@ -213,7 +216,7 @@
// TILL HERE
- // ROHITH - TODO
+ // ROHITH - DONE BUT WATCHOUT FOR ERRORS
cs.make_constraints_independent( C, ids_to_round, ids_to_elim);
@@ -243,7 +246,7 @@
//TILL HERE
-// ROHITH TODO
+// ROHITH ALMOST DONE but watchout for errors
cs.eliminate_constraints( Ccpy, Acpy, x, b, ids_to_round, ids_to_elim, new_idx, Acsc);
@@ -290,7 +293,7 @@
- // ROHITH TODO
+ // DONE BUT CHECK FOR ERRORS
cs.restore_eliminated_vars( Ccpy, x, ids_to_elim, new_idx);
@@ -298,24 +301,7 @@
// DONE FROM HERE
std::cout << " fullsize solution vector x is\n" << x << std::endl << std::endl;
- std::cout << "---------- ---------- 5) the same result is obtained by one call to the constrained solver, which takes care of re-indexing etc. internally..." << std::endl;
- // ids_to_round is altered by previous steps...
- ids_to_round.clear();
- ids_to_round.push_back(2);
- x.resize(A.rows());
- b.resize(A.rows());
-
-// TILL HERE
-
-
- // ROHITH TODO
- cs.solve( C, A, x, b_cpy, ids_to_round, 0.0, false, true);
-
-
-// DONE
-
- std::cout << " fullsize solution vector x is\n" << x << std::endl << std::endl;
-
+
return -1;
}
Modified: branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolverT.cc
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolverT.cc 2010-06-02 11:18:19 UTC (rev 29155)
+++ branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolverT.cc 2010-06-02 12:20:13 UTC (rev 29156)
@@ -33,7 +33,12 @@
//== INCLUDES =================================================================
#include "ConstrainedSolver.hh"
-#include <gmm/gmm.h>
+
+
+//#include <gmm/gmm.h> <-- Removed
+
+
+
#include <float.h>
#include <CoMISo/Utils/StopWatch.hh>
@@ -171,7 +176,7 @@
//-----------------------------------------------------------------------------
-//ROHITH - TODO
+//ROHITH - DONE but watch out for errors
void
ConstrainedSolver::
@@ -207,32 +212,34 @@
// get elimination variable
int elim_j = -1;
-
-
-
-
- // TODO
// 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
- typedef typename gmm::linalg_traits<RMatrixT>::const_sub_row_type CRowT;
- typedef typename gmm::linalg_traits<RMatrixT>::sub_row_type RowT;
- typedef typename gmm::linalg_traits<CRowT>::const_iterator RIter;
+ // typedef typename gmm::linalg_traits<RMatrixT>::const_sub_row_type CRowT;
+ // typedef typename gmm::linalg_traits<RMatrixT>::sub_row_type RowT;
+ //typedef typename gmm::linalg_traits<CRowT>::const_iterator RIter;
+
+//DONE but watch out for errors here
+
+
// get current condition row
- CRowT row = gmm::mat_const_row( _constraints, i);
- RIter row_it = gmm::vect_const_begin( row);
- RIter row_end = gmm::vect_const_end( row);
+ SparseVr row = SparseVr(_constraints.row(i));
+ SparseVr::InnerIterator row_it(row,0);
+
+
+ // RIter row_it = gmm::vect_const_begin( row);
+ // RIter row_end = gmm::vect_const_end( row);
double elim_val = FLT_MAX;
+//
-
- for(; row_it != row_end; ++row_it)
+ for(; row_it; ++row_it)
{
int cur_j = row_it.index();
// do not use the constant part
@@ -246,10 +253,10 @@
}
else
// store smallest integer
- if( fabs(*row_it) < elim_val)
+ if( fabs(row_it.value()) < elim_val)
{
elim_j = cur_j;
- elim_val = fabs(*row_it);
+ elim_val = fabs(row_it.value());
}
}
}
@@ -263,8 +270,8 @@
- //TODO this
- if( fabs(gmm::mat_const_row(_constraints, i)[n_vars-1]) > 1e-6 )
+ // DONE but watch out for errors
+ if( fabs(SparseVr(_constraints.row(i))[n_vars-1]) > 1e-6 )
std::cerr << "Warning: incompatible condition:\n";
else
std::cerr << "Warning: redundant condition:\n";
@@ -279,8 +286,7 @@
- // TODO
- << gmm::mat_const_row(_constraints, i) << std::endl;
+ << SparseVr(_constraints.row(i)) << std::endl;
@@ -292,19 +298,19 @@
double elim_val = _constraints(i, elim_j);
// copy col
- CVector col = constraints_c.col(elim_j);
+ SparseVc col = SparseVc(constraints_c.col(elim_j));
-
-
+
// iterate over column
- //TODO (Related to rows)
- typename gmm::linalg_traits<CVector>::const_iterator c_it = gmm::vect_const_begin(col);
- typename gmm::linalg_traits<CVector>::const_iterator c_end = gmm::vect_const_end(col);
+
+ // typename gmm::linalg_traits<CVector>::const_iterator c_it = gmm::vect_const_begin(col);
+ // typename gmm::linalg_traits<CVector>::const_iterator c_end = gmm::vect_const_end(col);
+ SparseVc::InnerIterator c_it(col,0);
- for(; c_it != c_end; ++c_it)
+ for(; c_it; ++c_it)
if( c_it.index() > i)
{
sw.start();
@@ -312,12 +318,12 @@
- // TODO THIS
- 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, _constraints.row(i), _constraints, constraints_c);
+
// make sure the eliminated entry is 0 on all other rows and not 1e-17
_constraints( c_it.index(), elim_j) = 0;
constraints_c(c_it.index(), elim_j) = 0;
@@ -330,21 +336,21 @@
//-----------------------------------------------------------------------------
-template<class SVector1T, class SVector2T, class VectorIT, class SVector3T>
+
void
ConstrainedSolver::
eliminate_constraints(
- gmm::row_matrix<SVector1T>& _constraints,
- gmm::row_matrix<SVector2T>& _B,
- VectorIT& _idx_to_round,
+ SparseXdr& _constraints,
+ SparseXdr& _B,
+ VectorXi& _idx_to_round,
std::vector<int>& _c_elim,
std::vector<int>& _new_idx,
- gmm::col_matrix<SVector3T>& _Bcol)
+ SparseXdc& _Bcol)
{
std::cerr << __FUNCTION__ << std::endl;
// copy into column matrix
- gmm::resize(_Bcol, gmm::mat_nrows(_B), gmm::mat_ncols(_B));
- gmm::copy( _B, _Bcol);
+ _Bcol.resize( _B.rows(), _B.cols());
+ _Bcol= SparseXdr(_B);
// store columns which should be eliminated
std::vector<int> elim_cols;
@@ -362,27 +368,33 @@
elim_cols.push_back(_c_elim[i]);
// copy col
- SVector3T col = _Bcol.col(cur_j);
+ SparseVc col = _Bcol.col(cur_j);
// iterate over column
- typename gmm::linalg_traits<SVector3T>::const_iterator c_it = gmm::vect_const_begin(col);
- typename gmm::linalg_traits<SVector3T>::const_iterator c_end = gmm::vect_const_end(col);
+ SparseVc::InnerIterator c_it(col,0);
+
- for(; c_it != c_end; ++c_it)
- add_row( c_it.index(), -(*c_it)/cur_val, gmm::mat_row(_constraints, i), _Bcol);
+ for(; c_it; ++c_it)
+ //DONE
+ add_row( c_it.index(), -(*c_it)/cur_val, _constraints.rows(), i), _Bcol);
}
}
// eliminate columns
+
+
+ //DONE
eliminate_columns( _Bcol, elim_cols);
// TODO FIXME Size -1 ?!?!
// init _new_idx vector
- _new_idx.resize(gmm::mat_ncols(_constraints));
+ _new_idx.resize(_constraints.cols()));
for(unsigned int i=0; i<_new_idx.size(); ++i)
_new_idx[i] = i;
// update _new_idx w.r.t. eliminated cols
+
+ //DONE but change namespace
gmm::eliminate_vars_idx( elim_cols, _new_idx, -1);
// update _idx_to_round (in place)
@@ -412,26 +424,26 @@
//-----------------------------------------------------------------------------
-template<class SVector1T, class SVector2T, class VectorIT, class CSCMatrixT>
+
void
ConstrainedSolver::
eliminate_constraints(
- gmm::row_matrix<SVector1T>& _constraints,
- gmm::col_matrix<SVector2T>& _A,
+ SparseXdr& _constraints,
+ SparseXdc& _A,
std::vector<double>& _x,
std::vector<double>& _rhs,
- VectorIT& _idx_to_round,
+ VectorXi& _idx_to_round,
std::vector<int>& _v_elim,
std::vector<int>& _new_idx,
- CSCMatrixT& _Acsc)
+ SparseXdc& _Acsc)
{
std::cerr << __FUNCTION__ << std::endl;
ACG::StopWatch sw;
sw.start();
// define iterator on matrix A and on constraints C
- typedef typename gmm::linalg_traits<SVector2T>::const_iterator AIter;
- typedef typename gmm::linalg_traits<SVector1T>::const_iterator CIter;
+ //typedef typename gmm::linalg_traits<SVector2T>::const_iterator AIter;
+ //typedef typename gmm::linalg_traits<SVector1T>::const_iterator CIter;
// store variable indices to be eliminated
std::vector<int> elim_varids;
@@ -449,20 +461,20 @@
elim_varids.push_back(_v_elim[i]);
// copy col
- SVector2T col ( _A.col( cur_j));
+ SparseVc col ( _A.col( cur_j));
// get a reference to current constraint vector
- SVector1T& constraint( _constraints.row(i));
+ SparseVr constraint( _constraints.row(i));
// add cur_j-th row multiplied with constraint[k] to each row k
// iterator of matrix column
- AIter col_it, col_end;
+ SparseVc::InnerIterator col_it(col,0);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list