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