AdditionalIceUtils.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "optimization/AdditionalIceUtils.h"
  2. //#include "vectort.h" // ICE
  3. // #include "ludecomp.h" //ICE
  4. // #include "mateigen.h" //ICE
  5. #include <cassert>
  6. #include <core/algebra/LUDecomposition.h>
  7. #include <core/algebra/EigValues.h>
  8. using namespace opt;
  9. //using namespace ice;
  10. matrix_type & MatrixAddVal ( matrix_type & mat, double val )
  11. {
  12. for(int i=0; i< mat.rows(); ++i)
  13. {
  14. for(int j =0; j<mat.cols(); ++j)
  15. {
  16. mat(i,j) += val;
  17. }
  18. }
  19. return mat;
  20. }
  21. double MatrixSum(const matrix_type &mat)
  22. {
  23. double sum=0.0;
  24. for(int i=0; i< mat.rows(); ++i)
  25. {
  26. for(int j =0; j<mat.cols(); ++j)
  27. {
  28. sum += mat(i,j);
  29. }
  30. }
  31. return sum;
  32. }
  33. void linSolve(const OPTIMIZATION::matrix_type &A, OPTIMIZATION::matrix_type &x, const OPTIMIZATION::matrix_type b)
  34. {
  35. int n=A.cols();
  36. assert(x.rows() == n && b.rows() == n );
  37. matrix_type LU;
  38. NICE::VectorT<int> indx;
  39. NICE::Vector xv(n);
  40. NICE::Vector iv(n);
  41. for(int i=0; i < n;++i)
  42. {
  43. iv[i] = b(i,0);
  44. }
  45. // LU-Zerlegung mit Pivotisierung
  46. NICE::LUDecomposition luDecomp;
  47. luDecomp.decomposePacked(A, LU, indx, true);
  48. // Lösung M*x1=i1
  49. xv = luDecomp.solve(LU,indx,iv);
  50. x=matrix_type(n,1);
  51. for(int i=0; i < n;++i)
  52. {
  53. x(i,0) = xv[i];
  54. }
  55. }
  56. void getEig(const OPTIMIZATION::matrix_type &A, OPTIMIZATION::matrix_type &L, OPTIMIZATION::matrix_type &V)
  57. {
  58. std::cerr << "This feature is not supported currently" << std::endl;
  59. // int n= A.cols();
  60. // L = matrix_type(n,1);
  61. // V = matrix_type(n,n);
  62. //
  63. // NICE::Vector l(n);
  64. //
  65. // NICE::EVArnoldi eig;
  66. // eig.getEigenvalues (A, l, V, n);
  67. // for(int i=0; i < n;++i)
  68. // {
  69. // L(i,0) = l[i];
  70. // }
  71. }