[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29192] branches/soc-2010-rohith291991/ intern/comiso: MI Solver Updated.

Rohith B V rohith291991 at gmail.com
Thu Jun 3 19:48:35 CEST 2010


Revision: 29192
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29192
Author:   rohith291991
Date:     2010-06-03 19:48:34 +0200 (Thu, 03 Jun 2010)

Log Message:
-----------
MI Solver Updated. Does not Compile. May contain some unneeded code.

Modified Paths:
--------------
    branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/main.cc
    branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolver.cc
    branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolverT.cc

Added Paths:
-----------
    branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/CoMISoDefines.h
    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/MISolverT.cc
    branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/StopWatch.h
    branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/common.h
    branches/soc-2010-rohith291991/intern/comiso/Solver/ConstrainedSolver.h
    branches/soc-2010-rohith291991/intern/comiso/Solver/MatTools.cc
    branches/soc-2010-rohith291991/intern/comiso/Solver/MatTools.hh

Added: branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/CoMISoDefines.h
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/CoMISoDefines.h	                        (rev 0)
+++ branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/CoMISoDefines.h	2010-06-03 17:48:34 UTC (rev 29192)
@@ -0,0 +1,48 @@
+/*===========================================================================*\
+ *                                                                           *
+ *                               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/>.          *
+ *                                                                           *
+\*===========================================================================*/ 
+
+#ifndef COMISODLLEXPORT
+	#ifdef WIN32
+		#ifdef COMISOMDLL
+			#ifdef USECOMISO
+				#define COMISODLLEXPORT __declspec(dllimport)
+				#define COMISODLLEXPORTONLY 
+			#else
+				#define COMISODLLEXPORT __declspec(dllexport)
+				#define COMISODLLEXPORTONLY __declspec(dllexport)
+			#endif
+		#else		
+			#define COMISODLLEXPORT	
+			#define COMISODLLEXPORTONLY
+		#endif
+	#else
+		#define COMISODLLEXPORT
+		#define COMISODLLEXPORTONLY
+	#endif
+#endif
+
+#undef min
+#undef max
+
+

Added: branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc	                        (rev 0)
+++ branches/soc-2010-rohith291991/intern/comiso/Examples/quadratic_solver/ConstrainedSolver.cc	2010-06-03 17:48:34 UTC (rev 29192)
@@ -0,0 +1,369 @@
+/*===========================================================================*\
+ *                                                                           *
+ *                               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"
+
+
+template<class IntegerT, class IntegerT2>
+void ConstrainedSolver::eliminate_vars_idx( const std::vector<IntegerT >&     _evar,
+                         std::vector<IntegerT2>&     _idx,
+                         IntegerT2                   _dummy )
+{
+   // sort input
+   std::vector<IntegerT> evar( _evar );
+   std::sort( evar.begin(), evar.end() );
+
+   // precompute update
+   std::vector<int> update_map( _idx.size() );
+
+   typename std::vector<IntegerT>::iterator cur_var = evar.begin();
+   unsigned int deleted_between = 0;
+
+   for ( unsigned int i=0; i<update_map.size(); ++i )
+   {
+     if ( cur_var != evar.end() && (IntegerT)i == *cur_var )
+      {
+         // mark as deleted
+         update_map[i] = _dummy;
+
+         ++deleted_between;
+         ++cur_var;
+      }
+      else
+      {
+         update_map[i] = i-deleted_between;
+      }
+   }
+
+   for ( unsigned int i=0; i<_idx.size(); ++i )
+   {
+     if ( (IntegerT2)_idx[i] != _dummy )
+      {
+         _idx[i] = update_map[_idx[i]];
+      }
+   }
+}
+
+
+void eliminate_csc_vars2(
+    const std::vector<int>&     _evar,
+    const std::vector<double>&      _eval,
+    SparseXdc&  _A,
+    std::vector<double>&                          _x,
+    std::vector<double>&                          _rhs )
+{
+ /* typedef unsigned int uint;
+ // typedef typename gmm::csc_matrix<RealT> MatrixT;
+
+  unsigned int nc = _A.cols(); // check 
+  unsigned int nr = _A.rows();//
+
+  unsigned int n_new = nc - _evar.size();
+
+  // modify rhs
+  for ( unsigned int k=0; k<_evar.size(); ++k )
+  {
+    int i = _evar[k];
+
+    // number of elements in this column
+    //    uint n_elem = _A.jc[i+1]-_A.jc[i];
+    uint r_idx  = 0;
+    double entry = 0.0;
+    for( uint i_elem = _A.jc[i]; i_elem < _A.jc[i+1]; ++i_elem)
+    {
+      r_idx = _A.ir[i_elem];
+      entry = _A.pr[i_elem];
+      _rhs[r_idx] -= _eval[k]*( entry );
+    }
+  }
+
+  // sort vector
+  std::vector<int> evar( _evar );
+  std::sort( evar.begin(), evar.end() );
+  evar.push_back( std::numeric_limits<int>::max() );
+
+  // build subindex set and update rhs
+  std::vector<size_t> si( n_new );
+  int cur_evar_idx=0;
+  for ( unsigned int i=0; i<nc; ++i )
+  {
+
+    unsigned int next_i = evar[cur_evar_idx];
+
+    if ( i != next_i )
+    {
+
+      _rhs[i-cur_evar_idx] = _rhs[i];
+      _x  [i-cur_evar_idx] = _x  [i];
+      si  [i-cur_evar_idx] = i;
+
+    }
+    else
+    {
+      ++cur_evar_idx;
+    }
+  }
+
+  // delete last elements
+  _rhs.resize( n_new );
+  _x.resize( n_new );
+
+  std::vector< int > new_row_idx_map( nr, -1);
+  // build re-indexing map
+  // -1 means deleted
+  {
+    int next_evar_idx(0);
+    int offset(0);
+    for( int i = 0; i < (int)nr; ++i)
+    {
+      if( i == (int)evar[next_evar_idx])
+      {
+        ++next_evar_idx;
+        ++offset;
+      }
+      else
+      {
+        new_row_idx_map[i] = i-offset;
+      }
+    }
+  }
+
+  // csc erasing rows and columns
+  int read(0), write(0), evar_col(0), last_jc(0);
+  for( unsigned int c = 0; c < nc; ++c)
+  {
+    if( c == (unsigned int)evar[evar_col] )
+    {
+      ++evar_col;
+      read += _A.jc[c+1]-last_jc;
+    }
+    else
+    {
+      while( read < (int)_A.jc[c+1] )
+      {
+        int new_idx = new_row_idx_map[_A.ir[read]];
+        if( new_idx != -1)
+        {
+          _A.pr[write] = _A.pr[read];
+          _A.ir[write] = new_idx;
+          ++write;
+        }
+        ++read;
+      }
+   }
+    last_jc = _A.jc[c+1];
+
+    _A.jc[c+1-evar_col] = write;
+  }
+
+  _A.nc = nc - evar.size()+1;
+  _A.nr = nr - evar.size()+1;*/
+}
+
+
+
+
+
+void 
+ConstrainedSolver::
+restore_eliminated_vars( MatrixXd&         _constraints,
+			 VectorXd&          _x,
+			 std::vector<int>& _c_elim,
+			 std::vector<int>& _new_idx)
+{
+  // restore original ordering of _x
+  _x.resize(_new_idx.size());
+  // last variable is the constant term 1.0
+
+  //CHECK
+  _x[_new_idx.size()-1] = 1.0;
+
+  // reverse iterate from prelast element
+  for(int i=_new_idx.size()-2; i>= 0; --i)
+  {
+    if( _new_idx[i] != -1)
+    {
+      // error handling
+      if( i < _new_idx[i]) std::cerr << "Warning: UNSAFE Ordering!!!\n";
+
+      _x[i] = _x[_new_idx[i]];
+    }
+  }
+
+  // reverse iterate
+  for(int i=_c_elim.size()-1; i>=0; --i)
+  {
+    int cur_var = _c_elim[i];
+
+    if( cur_var != -1)
+    {
+      // get variable value and set to zero
+      double cur_val = _constraints(i, cur_var);
+      _constraints(i, cur_var) = 0.0;
+
+
+	  //CHECK
+      _x[cur_var] = _x.dot(_constraints.row(i))/cur_val;
+    }
+  }
+
+  // resize
+  _x.resize(_x.size()-1);
+}
+
+
+void 
+ConstrainedSolver::
+eliminate_constraints(
+    MatrixXd& _constraints,
+    SparseXdc& _A, 
+    std::vector<double>&        _x, 
+    std::vector<double>&        _rhs, 
+    std::vector<int>&                   _idx_to_round,
+    std::vector<int>&           _v_elim,
+    std::vector<int>&           _new_idx,
+    SparseXdc&                 _Acsc)
+{
+  std::cerr << __FUNCTION__ << std::endl;
+
+ ACG::StopWatch sw;
+  sw.start();
+
+  // store variable indices to be eliminated
+  std::vector<int> elim_varids;
+  elim_varids.reserve( _v_elim.size());
+
+  for( unsigned int i=0; i < _v_elim.size(); ++i)
+  {
+    int cur_j = _v_elim[i];
+
+    if( cur_j != -1)
+    {
+      double cur_val = _constraints(i, cur_j);
+
+      // store index
+      elim_varids.push_back(_v_elim[i]);
+
+      // copy col

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list