[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29223] branches/soc-2010-rohith291991: Finally got the code working.
Rohith B V
rohith291991 at gmail.com
Fri Jun 4 21:52:57 CEST 2010
Revision: 29223
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29223
Author: rohith291991
Date: 2010-06-04 21:52:57 +0200 (Fri, 04 Jun 2010)
Log Message:
-----------
Finally got the code working. Now its a matter of a few more commits.
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/common.h
Added Paths:
-----------
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/comiso.cc
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/comiso.h
Removed Paths:
-------------
branches/soc-2010-rohith291991/extern/Eigen2/common.h
branches/soc-2010-rohith291991/extern/Eigen2/constraint.cc
branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/main.cc
branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolver.hh
branches/soc-2010-rohith291991/intern/comiso/Solver/GMM_Tools.cc
branches/soc-2010-rohith291991/intern/comiso/Solver/GMM_Tools.hh
Deleted: branches/soc-2010-rohith291991/extern/Eigen2/common.h
===================================================================
--- branches/soc-2010-rohith291991/extern/Eigen2/common.h 2010-06-04 19:31:14 UTC (rev 29222)
+++ branches/soc-2010-rohith291991/extern/Eigen2/common.h 2010-06-04 19:52:57 UTC (rev 29223)
@@ -1,12 +0,0 @@
-#include "Eigen/Core"
-#include "Eigen/Sparse"
-
-using namespace Eigen;
-
-// ----- Space for other typedefs as needed -----
-
-typedef SparseMatrix<double,ColMajor> SparseXdc;
-typedef SparseMatrix<double,RowMajor> SparseXdr;
-
-bool choleskySolve(SparseXd A, VectorXd b, VectorXd& x);
-bool MISolve(SparseXd A, VectorXd b, VectorXd& x, SparseXd constraints,std::vector<int> roundIndices,int maxIter=10000, double precision=1e-7);
Deleted: branches/soc-2010-rohith291991/extern/Eigen2/constraint.cc
===================================================================
--- branches/soc-2010-rohith291991/extern/Eigen2/constraint.cc 2010-06-04 19:31:14 UTC (rev 29222)
+++ branches/soc-2010-rohith291991/extern/Eigen2/constraint.cc 2010-06-04 19:52:57 UTC (rev 29223)
@@ -1,912 +0,0 @@
-/*===========================================================================*\
- * *
- * 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/>. *
- * *
-\*===========================================================================*/
-
-#define ACG_CONSTRAINEDSOLVER_C
-//== INCLUDES =================================================================
-
-#include <float.h>
-#include "StopWatch.hh"
-#include "common.h"
-
-
-//== IMPLEMENTATION ==========================================================
-
-
-namespace ACG{
-
-void solve(SparseXd& _constraints, SparseXd& _B, VectorXd _x ,VectorXd _idx_to_round,
- double _reg_factor,
- bool _show_miso_settings,
- bool _show_timings )
-{
- int nrows = B.rows();
- int ncols = B.cols()
- int ncons = constraints.rows();
-
-
- if( _show_timings) std::cerr << __FUNCTION__ << "\n Initial dimension: " << nrows << " x " << ncols << ", number of constraints: " << ncons << std::endl;
-
- // StopWatch for Timings
- ACG::StopWatch sw, sw2; sw.start(); sw2.start();
-
- // c_elim[i] = index of variable which is eliminated in condition i
- // or -1 if condition is invalid
- std::vector<int> c_elim( ncons);
-
- // apply sparse gauss elimination to make subsequent _constraints independent
-
- //TODO
- make_constraints_independent( _constraints, _idx_to_round, c_elim);
- double time_gauss = sw.stop()/1000.0; sw.start();
-
- // eliminate conditions and return column matrix Bcol
- SparseXd Bcol( nrows, ncols);
-
- // reindexing vector
- std::vector<int> new_idx;
-
-
- //TODO
- eliminate_constraints( _constraints, _B, _idx_to_round, c_elim, new_idx, Bcol);
-
- double time_eliminate = sw.stop()/1000.0; sw.start();
-
- if( _show_timings) std::cerr << "Eliminated dimension: " << Bcol.rows() << " x " << Bcol.cols() << std::endl;
-
- // setup and solve system
- //TODO
- double time_setup = setup_and_solve_system( Bcol, _x, _idx_to_round, _reg_factor, _show_miso_settings);
-
- // double time_setup_solve = sw.stop()/1000.0; sw.start();
-
- // restore eliminated vars to fulfill the given conditions
- //TODO
- restore_eliminated_vars( _constraints, _x, c_elim, new_idx);
-
- double time_resubstitute = sw.stop()/1000.0; sw.start();
-
- // double time_total = sw2.stop()/1000.0;
-
- if( _show_timings) std::cerr << "Timings: \n\t" <<
- "Gauss Elimination " << time_gauss << " s\n\t" <<
- "System Elimination " << time_eliminate << " s\n\t" <<
- "Setup " << time_setup << " s\n\t" <<
- // "Setup + Mi-Solver " << time_setup_solve << " s\n\t" <<
- "Resubstitution " << time_resubstitute << " s\n\t" << std::endl << std::endl;
- //"Total " << time_total << std::endl;
-}
-
-
-//-----------------------------------------------------------------------------
-
-
-
-void solve(
- SparseXd& _constraints,
- SparseXd& _A,
- VectorXd& _x,
- VectorXd& _rhs,
- VectorXi& _idx_to_round,
- double _reg_factor,
- bool _show_miso_settings,
- bool _show_timings )
-{
- int nrows = _A.rows();
- int ncols = _A.cols();
- int ncons = _constraints.rows();
-
- if( _show_timings) std::cerr << __FUNCTION__ << "\n Initital dimension: " << nrows << " x " << ncols << ", number of constraints: " << ncons << std::endl;
-
- // StopWatch for Timings
- ACG::StopWatch sw, sw2; sw.start(); sw2.start();
-
- // c_elim[i] = index of variable which is eliminated in condition i
- // or -1 if condition is invalid
- std::vector<int> c_elim( ncons);
-
- // apply sparse gauss elimination to make subsequent _conditions independent
- //TODO
- make_constraints_independent( _constraints, _idx_to_round, c_elim);
-
- double time_gauss = sw.stop()/1000.0; sw.start();
-
- // re-indexing vector
- std::vector<int> new_idx;
-
- gmm::csc_matrix< double > Acsc;
-
- //TODO
- eliminate_constraints( _constraints, _A, _x, _rhs, _idx_to_round, c_elim, new_idx, Acsc);
-
- double time_eliminate = sw.stop()/1000.0;
-
- if( _show_timings) std::cerr << "Eliminated dimension: " << Acsc.nr << " x " << Acsc.nc << std::endl;
-
- // create MISO solver
- ACG::MISolver miso;
- // show options dialog
- if( _show_miso_settings)
- miso.show_options_dialog();
-
- sw.start();
- miso.solve( Acsc, _x, _rhs, _idx_to_round);
- double time_miso = sw.stop()/1000.0; sw.start();
-
- // restore eliminated vars to fulfill the given conditions
- //TODO
- restore_eliminated_vars( _constraints, _x, c_elim, new_idx);
-
- double time_resubstitute = sw.stop()/1000.0; sw.start();
- double time_total = time_gauss + time_eliminate + time_miso + time_resubstitute;
- if( _show_timings) std::cerr << "Timings: \n\t" <<
- "\tGauss Elimination " << time_gauss << " s\n\t" <<
- "\tSystem Elimination " << time_eliminate << " s\n\t" <<
- "\tMi-Solver " << time_miso << " s\n\t" <<
- "\tResubstitution " << time_resubstitute << " s\n\t" <<
- "\tTotal " << time_total << std::endl << std::endl;
-}
-
-
-//-----------------------------------------------------------------------------
-
-
-void
-make_constraints_independent(
- SparseXd& _constraints,
- VectorXi& _idx_to_round,
- std::vector<int>& _c_elim)
-{
- ACG::StopWatch sw;
- // number of variables
- int n_vars = _constraints.cols();
-
- // TODO Check: HZ added 14.08.09
- _c_elim.clear();
- _c_elim.resize( gmm::mat_nrows(_constraints), -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;
-
- // copy constraints into column matrix (for faster update via iterators)
- //---------------XXXX Changes XXXX
- //typedef gmm::wsvector <double> CVector;
- //typedef gmm::col_matrix< CVector > CMatrix;
-
- SparseXd constraints_c;
-
- //half modified
- gmm::resize(constraints_c, _constraints.rows(), _constraints.cols());
- gmm::copy(_constraints, 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
-
-
- //------------ TODO: change this part later---------------
- 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;
-
- // 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);
- double elim_val = FLT_MAX;
-
- for(; row_it != row_end; ++row_it)
- {
- int cur_j = row_it.index();
- // do not use the constant part
- if( cur_j != n_vars - 1 )
- {
- // found real valued var? -> finished
- if( !roundmap[ cur_j ])
- {
- elim_j = cur_j;
- break;
- }
- else
- // store smallest integer
- if( fabs(*row_it) < elim_val)
- {
- elim_j = cur_j;
- elim_val = fabs(*row_it);
- }
- }
- }
-
- // store result
- _c_elim[i] = elim_j;
- // error check result
- if( elim_j == -1)
- {
- // redundant or incompatible?
- if( fabs(gmm::mat_const_row(_constraints, i)[n_vars-1]) > 1e-6 )
- std::cerr << "Warning: incompatible condition:\n";
- else
- std::cerr << "Warning: redundant condition:\n";
- }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list