23 #ifdef _POSIX_C_SOURCE
24 #undef _POSIX_C_SOURCE
48 const std::string& symbolNameToOptimizerAlgBaseInstanceFactory,
49 bool algInitOnFile,
bool initAlgo,
Proc * procForTypes):
50 OptimizerLoop(name,algLibWthOutExt,symbolNameToOptimizerAlgBaseInstanceFactory,algInitOnFile,false)
56 setAlgorithm(algLibWthOutExt, symbolNameToOptimizerAlgBaseInstanceFactory,
true, procForTypes);
80 if (procForTypes == NULL) {
82 procForTypes =
const_cast<Proc *
>(origProc);
101 PyGILState_STATE gstate=PyGILState_Ensure();
103 PyObject* mainmod = PyImport_AddModule(
"__main__");
104 PyObject* globals = PyModule_GetDict(mainmod);
106 std::string pyscript;
107 pyscript=
"import sys\n"
108 "import SALOMERuntime\n"
111 pyscript=pyscript+
"import os\n"
113 "rep,mod=os.path.split(os.path.splitext(filename)[0])\n"
115 " sys.path.insert(0,rep)\n"
116 "algomodule=__import__(mod)\n"
119 "algoclass= getattr(algomodule,entry)\n"
120 "algo= algoclass()\n"
121 "swigalgo= algo.this\n"
124 PyObject* res=PyRun_String(pyscript.c_str(), Py_file_input, globals, globals );
131 PySys_SetObject((
char*)
"stderr", new_stderr);
133 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
134 Py_DECREF(new_stderr);
136 PyGILState_Release(gstate);
151 PyObject *
_pyAlgo = PyDict_GetItemString(globals,
"algo");
153 SwigPyObject* pyalgo = (SwigPyObject*)PyDict_GetItemString(globals,
"swigalgo");
157 PyGILState_Release(gstate);
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Base class for all composed nodes.
Base class for all nodes.
virtual void modified()
Sets Node in modified state and its father if it exists.
std::string _errorDetails
Base class factorizing common methods for all algorithms interfaces.
virtual void setPool(Pool *pool)
class to build optimization loops
virtual void setAlgorithm(const std::string &alglib, const std::string &symbol, bool checkLinks=true, Proc *procForTypes=NULL)
Set the algorithm library name and factory name (symbol in library) to create the algorithm and chang...
virtual void loadAlgorithm()
Load the algorithm from the dynamic library.
Base class for all schema objects.
class to build optimization loops
SalomeOptimizerLoop(const std::string &name, const std::string &algLibWthOutExt, const std::string &symbolNameToOptimizerAlgBaseInstanceFactory, bool algInitOnFile, bool initAlgo=true, Proc *procForTypes=NULL)
Node * simpleClone(ComposedNode *father, bool editionOnly) const
virtual void loadAlgorithm()
Load the algorithm object from a Python module or a dynamic library.
PyObject * newPyStdOut(std::string &out)