+void OptimizerLoop::accept(Visitor *visitor)
+{
+ visitor->visitOptimizerLoop(this);
+}
+
+//! Set the algorithm library name and factory name (symbol in library) to create the algorithm and change it if the node is not connected
+/*!
+ * throw an exception if the node is connected
+ */
+void OptimizerLoop::setAlgorithm(const std::string& alglib, const std::string& symbol,
+ bool checkLinks, Proc * procForTypes)
+{
+ if(checkLinks)
+ {
+ if (_splittedPort.edGetNumberOfOutLinks() != 0 ||
+ _retPortForOutPool.edGetNumberOfLinks() != 0 ||
+ _algoInitPort.edGetNumberOfLinks() != 0 ||
+ _algoResultPort.edGetNumberOfOutLinks() != 0)
+ throw Exception("The OptimizerLoop node must be disconnected before setting the algorithm");
+ }
+
+ _symbol = symbol;
+ _alglib = alglib;
+
+ if (_alg) {
+ _alg->decrRef();
+ _alg = NULL;
+ }
+
+ loadAlgorithm();
+
+ if(_alg)
+ {
+ _alg->setProc((procForTypes == NULL) ? getProc() : procForTypes);
+
+ // Delete the values in the input ports if they were initialized
+ _retPortForOutPool.put((Any *)NULL);
+ _algoInitPort.put((Any *)NULL);
+
+ // Change the type of the ports
+ _splittedPort.edSetType(checkTypeCode(_alg->getTCForInProxy(), NAME_OF_SPLITTED_SEQ_OUT));
+ _retPortForOutPool.edSetType(checkTypeCode(_alg->getTCForOutProxy(), NAME_OF_OUT_POOL_INPUT));
+ _algoInitPort.edSetType(checkTypeCode(_alg->getTCForAlgoInitProxy(), NAME_OF_ALGO_INIT_PORT));
+ _algoResultPort.edSetType(checkTypeCode(_alg->getTCForAlgoResultProxy(), NAME_OF_ALGO_RESULT_PORT));
+ }
+
+ modified();
+}
+
+TypeCode * OptimizerLoop::checkTypeCode(TypeCode * tc, const char * portName)
+{
+ if (tc == NULL) {
+ ostringstream errorMsg;
+ errorMsg << "The algorithm specified for OptimizerLoop node \"" << getName() <<
+ "\" provided an invalid type for port \"" << portName << "\"";
+ throw Exception(errorMsg.str());
+ }
+ return tc;
+}
+
+//! Load the algorithm from the dynamic library
+/*!
+ *
+ */
+void OptimizerLoop::loadAlgorithm()
+{
+ YASSERT(_alg == NULL)
+
+ if (_loader != NULL) {
+ delete _loader;
+ _loader = NULL;
+ }
+ _loader = new YACS::BASES::DynLibLoader(_alglib);
+ OptimizerAlgBaseFactory algFactory = NULL;
+
+ if (_alglib != "" && _symbol != "")
+ {
+ try
+ {
+ _errorDetails = "";
+ algFactory = (OptimizerAlgBaseFactory)_loader->getHandleOnSymbolWithName(_symbol);
+ }
+ catch (YACS::Exception& e)
+ {
+ _errorDetails = e.what();
+ modified();
+ throw;
+ }
+ }
+
+ if (algFactory != NULL)
+ _alg = algFactory(&_myPool);
+}
+
+//! Return the name of the algorithm library
+/*!
+ *
+ */
+std::string OptimizerLoop::getAlgLib() const
+{
+ return _alglib;
+}
+
+//! Check validity for the node.
+/*!
+ * Throw an exception if the node is not valid
+ */
+void OptimizerLoop::checkBasicConsistency() const throw(YACS::Exception)
+{
+ DEBTRACE("OptimizerLoop::checkBasicConsistency");
+ if (_alglib == "")
+ throw Exception("No library specified for the OptimizerLoop control algorithm");
+ if (_symbol == "")
+ throw Exception("No symbol specified for the OptimizerLoop control algorithm");
+ if(_alg == NULL)
+ throw YACS::Exception("Problem during library loading: "+_errorDetails);
+
+ DynParaLoop::checkBasicConsistency();
+}
+
+int OptimizerLoop::getNumberOfOutputPorts() const
+{
+ return DynParaLoop::getNumberOfOutputPorts() + 1;
+}
+
+std::list<OutputPort *> OptimizerLoop::getSetOfOutputPort() const
+{
+ list<OutputPort *> ret = DynParaLoop::getSetOfOutputPort();
+ ret.push_back((OutputPort *)&_algoResultPort);
+ return ret;
+}
+
+std::list<OutputPort *> OptimizerLoop::getLocalOutputPorts() const
+{
+ list<OutputPort *> ret = DynParaLoop::getLocalOutputPorts();
+ ret.push_front((OutputPort *)&_algoResultPort);
+ return ret;
+}
+
+OutPort * OptimizerLoop::getOutPort(const std::string& name) const throw(YACS::Exception)
+{
+ return (name == NAME_OF_ALGO_RESULT_PORT) ? (OutPort *)&_algoResultPort :
+ DynParaLoop::getOutPort(name);
+}
+
+
+OutputPort * OptimizerLoop::getOutputPort(const std::string& name) const throw(YACS::Exception)
+{
+ return (name == NAME_OF_ALGO_RESULT_PORT) ? (OutputPort *)&_algoResultPort :
+ DynParaLoop::getOutputPort(name);
+}