]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/engine/OptimizerLoop.hxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/yacs.git] / src / engine / OptimizerLoop.hxx
index f48b231ad5856d42daaef7a2e08366ff6beb4ac1..41763275045f8c631b1322f2ddbfcd02f00ab613 100644 (file)
@@ -1,57 +1,36 @@
-//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2012  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library 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
-//  Lesser General Public License for more details.
+// This library 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
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #ifndef __OPTIMIZERLOOP_HXX__
 #define __OPTIMIZERLOOP_HXX__
 
+#include "YACSlibEngineExport.hxx"
 #include "Pool.hxx"
-#include "Thread.hxx"
 #include "DynParaLoop.hxx"
 #include "DynLibLoader.hxx"
 #include "OptimizerAlg.hxx"
 #include "ElementaryNode.hxx"
-#include "DrivenCondition.hxx"
 
 namespace YACS
 {
   namespace ENGINE
   {
-    class OptimizerAlgStandardized : public OptimizerAlgSync
-    {
-    private:
-      ::YACS::BASES::Thread *_threadInCaseOfNotEvent;
-      ::YACS::BASES::DrivenCondition _condition;
-      OptimizerAlgBase *_algBehind;
-    public:
-      OptimizerAlgStandardized(Pool *pool, OptimizerAlgBase *alg);
-      ~OptimizerAlgStandardized();
-      TypeCode *getTCForIn() const;
-      TypeCode *getTCForOut() const;
-      void setAlgPointer(OptimizerAlgBaseFactory algFactory);
-      void parseFileToInit(const std::string& fileName);
-      void initialize(const Any *input) throw (Exception);
-      void takeDecision();
-      void finish();
-      void start();
-    private:
-      static void *threadFctForAsync(void* ownStack);
-    };
-
     class OptimizerLoop;
 
     class FakeNodeForOptimizerLoop : public ElementaryNode
@@ -59,10 +38,10 @@ namespace YACS
       friend class OptimizerLoop;
     private:
       OptimizerLoop *_loop;
-      unsigned _reason;
+      std::string _message;
       bool _normal;
     private:
-      FakeNodeForOptimizerLoop(OptimizerLoop *loop, bool normal, unsigned reason);
+      FakeNodeForOptimizerLoop(OptimizerLoop *loop, bool normal, std::string message);
       FakeNodeForOptimizerLoop(const FakeNodeForOptimizerLoop& other);
       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
       void exForwardFailed();
@@ -72,12 +51,9 @@ namespace YACS
       void finished();
     private:
       static const char NAME[];
-      static const unsigned char ALG_WITHOUT_START_CASES = 52;
-      static const unsigned char NO_BRANCHES = 53;
-      static const unsigned char NO_ALG_INITIALIZATION = 54;
     };
 
-    class OptimizerLoop : public DynParaLoop
+    class YACSLIBENGINE_EXPORT OptimizerLoop : public DynParaLoop
     {
       friend class FakeNodeForOptimizerLoop;
       
@@ -85,28 +61,30 @@ namespace YACS
       Pool _myPool;
       bool _algInitOnFile;
       std::string _symbol;
-      AnyInputPort _portForInitFile;
-      ::YACS::BASES::DynLibLoader _loader;
-      OptimizerAlgStandardized *_alg;
+      std::string _alglib;
+      AnyInputPort _algoInitPort;
+      ::YACS::BASES::DynLibLoader * _loader;
+      OptimizerAlgBase *_alg;
       AnyInputPort _retPortForOutPool;
       std::vector<bool> _initNodeUpdated;
       bool _convergenceReachedWithOtherCalc;
       FakeNodeForOptimizerLoop *_nodeForSpecialCases;
       std::vector<AnyInputPort *> _interceptorsForOutPool;
-      ::YACS::BASES::DrivenCondition _condForCompletenessB4Relaunch;
       //! outputports interceptors leaving current scope.
       std::map<InputPort *, std::vector<InputPort *> > _interceptors;
+      AnyOutputPort _algoResultPort;
     public:
       OptimizerLoop(const std::string& name, const std::string& algLibWthOutExt,
                     const std::string& symbolNameToOptimizerAlgBaseInstanceFactory,
-                    bool algInitOnFile) throw(Exception);
+                    bool algInitOnFile,bool initAlgo=true, Proc * procForTypes = NULL);
       OptimizerLoop(const OptimizerLoop& other, ComposedNode *father, bool editionOnly);
       ~OptimizerLoop();
       void init(bool start=true);
       void exUpdateState();
       int getNumberOfInputPorts() const;
       InputPort *edGetPortForOutPool() { return &_retPortForOutPool; }
-      InputPort *edGetPortForInitFile() { return &_portForInitFile; }
+      InputPort *edGetAlgoInitPort() { return &_algoInitPort; }
+      OutputPort *edGetAlgoResultPort() { return &_algoResultPort; }
       InputPort *getInputPort(const std::string& name) const throw(Exception);
       std::list<InputPort *> getSetOfInputPort() const;
       std::list<InputPort *> getLocalInputPorts() const;
@@ -114,7 +92,22 @@ namespace YACS
       void getReadyTasks(std::vector<Task *>& tasks);
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
       void checkNoCyclePassingThrough(Node *node) throw(Exception);
+      virtual void accept(Visitor *visitor);
+      virtual std::string getSymbol() const { return _symbol; }
+      virtual std::string getAlgLib() const ;
+      virtual void setAlgorithm(const std::string& alglib,const std::string& symbol,
+                                bool checkLinks=true, Proc * procForTypes = NULL);
+      virtual void checkBasicConsistency() const throw(Exception);
+      virtual std::string typeName() {return "YACS__ENGINE__OptimizerLoop";}
+      int getNumberOfOutputPorts() const;
+      std::list<OutputPort *> getSetOfOutputPort() const;
+      std::list<OutputPort *> getLocalOutputPorts() const;
+      OutPort *getOutPort(const std::string& name) const throw(Exception);
+      OutputPort *getOutputPort(const std::string& name) const throw(Exception);
+      YACS::Event finalize();
+
     protected:
+      virtual YACS::Event updateStateOnFailedEventFrom(Node *node);
       void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
       void checkControlDependancy(OutPort *start, InPort *end, bool cross,
@@ -131,10 +124,17 @@ namespace YACS
       void initInterceptors(unsigned nbOfBr);
       void pushValueOutOfScopeForCase(unsigned branchId);
       Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
+      virtual void loadAlgorithm();
+
+    private:
+      TypeCode * checkTypeCode(TypeCode * tc, const char * portName);
+
     protected:
       static const int NOT_RUNNING_BRANCH_ID;
-      static const char NAME_OF_FILENAME_INPUT[];
+      static const int NOT_INITIALIZED_BRANCH_ID;
+      static const char NAME_OF_ALGO_INIT_PORT[];
       static const char NAME_OF_OUT_POOL_INPUT[];
+      static const char NAME_OF_ALGO_RESULT_PORT[];
     };
   }
 }