1 /* 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Copyright (C) 2013 - DIGITEO - Cedric DELAMARRE 4 * 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises 6 * 7 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * This file was originally licensed under the terms of the CeCILL v2.1, 10 * and continues to be available under such terms. 11 * For more information, see the COPYING file which you should have received 12 * along with this program. 13 * 14 */ 15 16 #ifndef __OPTIMIZATIONS_HXX__ 17 #define __OPTIMIZATIONS_HXX__ 18 19 #include <vector> 20 #include <map> 21 #include "dynlib_optimization.h" 22 #include "string.hxx" 23 #include "callable.hxx" 24 25 extern "C" 26 { 27 #include "Thread_Wrapper.h" 28 } 29 30 extern "C" 31 { 32 // optim 33 void C2F(genros)(int* ind, int* n, double* x, double* f, double* g, int* ti, float* tr, double* td); 34 void C2F(topt2) (int* ind, int* n, double* x, double* f, double* g, int* ti, float* tr, double* td); 35 void C2F(icsemc)(int* ind, int* n, double* x, double* f, double* g, int* ti, float* tr, double* td); 36 void C2F(mcsec) (int* ind, int* n, double* x, double* f, double* g, int* ti, float* tr, double* td); 37 38 // fsolve 39 void C2F(fsol1) (int* n, double* x, double* v, int* iflag); 40 void C2F(fsolj1)(int* n, double* x, double* jac, int* iflag); 41 42 // lsqrsolve 43 void C2F(lsqrsol1) (int* m, int* n, double* x, double* v, int* iflag); 44 void C2F(lsqrsolj1) (int* m, int* n, double* x, double* jac, int* ldjac, int* iflag); 45 46 } 47 48 class OPTIMIZATION_IMPEXP OptimizationFunctions 49 { 50 51 public : 52 53 OptimizationFunctions(const std::wstring& callerName); 54 ~OptimizationFunctions(); 55 56 void setXRows(int); 57 void setXCols(int); 58 int getXRows(); 59 int getXCols(); 60 61 // optim 62 void setOptimCostfFunction(types::Callable*); 63 bool setOptimCostfFunction(types::String*); 64 void setCostfArgs(types::InternalType*); 65 void execCostf(int* ind, int* n, double* x, double* f, double* g, int* ti, float* tr, double* td); 66 67 // fsolve & lsqrsolve 68 void setFsolveFctFunction(types::Callable*); 69 bool setFsolveFctFunction(types::String*); 70 void setFsolveFctArgs(types::InternalType*); 71 void execFsolveFct(int* n, double* x, double* v, int* iflag); 72 void execLsqrsolveFct(int* m, int* n, double* x, double* v, int* iflag); 73 74 void setFsolveJacFunction(types::Callable*); 75 bool setFsolveJacFunction(types::String*); 76 void setFsolveJacArgs(types::InternalType*); 77 void execFsolveJac(int* n, double* x, double* v, double* jac, int* ldjac, int* iflag); 78 void execLsqrsolveJac(int* m, int* n, double* x, double* v, double* jac, int* ldjac, int* iflag); 79 80 private : 81 82 std::map<std::wstring, void*> m_staticFunctionMap; 83 std::wstring m_wstrCaller; 84 int m_iXRows; 85 int m_iXCols; 86 87 // optim 88 types::Callable* m_pCallOptimCostfFunction; 89 types::String* m_pStringOptimCostfFunctionDyn; 90 types::String* m_pStringOptimCostfFunctionStatic; 91 std::vector<types::InternalType*> m_OptimArgs; 92 void callCostfMacro(int* ind, int* n, double* x, double* f, double* g, int* ti, float* tr, double* td); 93 94 // fsolve & lsqrsolve 95 types::Callable* m_pCallFsolveFctFunction; 96 types::String* m_pStringFsolveFctFunctionDyn; 97 types::String* m_pStringFsolveFctFunctionStatic; 98 std::vector<types::InternalType*> m_fsolveFctArgs; 99 void callFsolveFctMacro(int* n, double* x, double* v, int* iflag); 100 void callLsqrsolveFctMacro(int* m, int* n, double* x, double* v, int* iflag); 101 102 types::Callable* m_pCallFsolveJacFunction; 103 types::String* m_pStringFsolveJacFunctionDyn; 104 types::String* m_pStringFsolveJacFunctionStatic; 105 std::vector<types::InternalType*> m_fsolveJacArgs; 106 void callFsolveJacMacro(int* n, double* x, double* v, double* jac, int* ldjac, int* iflag); 107 void callLsqrsolveJacMacro(int* m, int* n, double* x, double* v, double* jac, int* ldjac, int* iflag); 108 109 }; 110 111 class OPTIMIZATION_IMPEXP Optimization 112 { 113 // differential equation functions 114 private : 115 static std::vector<OptimizationFunctions*> m_OptimizationFunctions; 116 117 public : 118 static void addOptimizationFunctions(OptimizationFunctions* _opFunction); 119 static void removeOptimizationFunctions(); 120 static OptimizationFunctions* getOptimizationFunctions(); 121 122 }; 123 #endif /* !__OPTIMIZATIONS_HXX__ */ 124 125