throw YACS::Exception("YACSEvalPort::GetTypeOfData : Unrecognized type of data ! Must be int or double for the moment !");
}
-YACSEvalInputPort::YACSEvalInputPort(YACS::ENGINE::InputPort *ptr):_ptr(ptr),_isLocked(false),_mySeq(0)
+YACSEvalInputPort::YACSEvalInputPort(YACS::ENGINE::InputPort *ptr):_ptr(ptr),_mySeq(0),_isRandom(false),_isLocked(false),_undergroundPort(0)
{
GetTypeOfData(_ptr);
}
void YACSEvalInputPort::setSequenceOfValuesToEval(const YACSEvalSeqAny *vals)
{
- checkForNonConstMethod();
+ if(!_isRandom && _isLocked)
+ throw YACS::Exception("YACSEvalInputPort::setSequenceOfValuesToEval : trying to set a sequence on a var not declared as random !");
+ //checkForNonConstMethod not called here because it is a special non const method !
if(!vals)
throw YACS::Exception("YACSEvalInputPort::setSequenceOfValuesToEval : input is NULL !");
if(vals==_mySeq)
if(_mySeq)
delete _mySeq;
_mySeq=vals->copy();
+ _isRandom=true;
+}
+
+bool YACSEvalInputPort::hasSequenceOfValuesToEval() const
+{
+ return (_mySeq!=0);
}
-bool YACSEvalInputPort::hasSequenceOfValuesToEval(std::size_t& sz) const
+void YACSEvalInputPort::declareRandomnessStatus(bool isRandom)
{
- sz=std::numeric_limits<std::size_t>::max();
- bool ret(_mySeq!=0);
- if(ret)
- sz=_mySeq->size();
- return ret;
+ checkForNonConstMethod();
+ _isRandom=isRandom;
+ if(!_isRandom)
+ _undergroundPort=0;
}
-void YACSEvalInputPort::initializeUndergroundWithSeq(YACS::ENGINE::InputPyPort *p) const
+std::size_t YACSEvalInputPort::initializeUndergroundWithSeq() const
{
- if(!p)
- throw YACS::Exception("YACSEvalInputPort::initializeUndergroundWithSeq : p is null !");
+ if(!_undergroundPort)
+ throw YACS::Exception("YACSEvalInputPort::initializeUndergroundWithSeq : internal error ! this input has not been locked properly ! Need to be locked !");
if(!_mySeq)
throw YACS::Exception("YACSEvalInputPort::initializeUndergroundWithSeq : this is not set as a sequence !");
- _mySeq->initialize(p);
+ _mySeq->initialize(_undergroundPort);
+ return _mySeq->size();
}
YACSEvalInputPort::~YACSEvalInputPort()
delete _mySeq;
}
+void YACSEvalInputPort::setUndergroundPortToBeSet(YACS::ENGINE::InputPyPort *p) const
+{
+ if(!_isRandom)
+ throw YACS::Exception("YACSEvalInputPort::setUndergroundPortToBeSet : trying to set a non random var !");
+ _undergroundPort=p;
+}
+
YACSEvalAny *YACSEvalInputPort::convertFromInternalAnyToExternal(YACS::ENGINE::Any *data) const
{
if(!data)
YACSEVALYFX_EXPORT YACSEvalAny *getDefaultValueDefined() const;
YACSEVALYFX_EXPORT void setDefaultValue(const YACSEvalAny *parameter);
YACSEVALYFX_EXPORT void setSequenceOfValuesToEval(const YACSEvalSeqAny* vals);
- YACSEVALYFX_EXPORT bool hasSequenceOfValuesToEval(std::size_t& sz) const;
+ YACSEVALYFX_EXPORT bool hasSequenceOfValuesToEval() const;
+ YACSEVALYFX_EXPORT bool isRandomVar() const { return _isRandom; }
+ YACSEVALYFX_EXPORT void declareRandomnessStatus(bool isRandom);
//
YACSEVALYFX_EXPORT YACS::ENGINE::InputPort *getUndergroundPtr() const { return _ptr; }
- YACSEVALYFX_EXPORT void initializeUndergroundWithSeq(YACS::ENGINE::InputPyPort *p) const;
+ YACSEVALYFX_EXPORT std::size_t initializeUndergroundWithSeq() const;
//
YACSEVALYFX_EXPORT virtual ~YACSEvalInputPort();
void lock() const { _isLocked=true; }
- void unlock() const { _isLocked=false; }
+ void unlock() const { _isLocked=false; _isRandom=false; }
+ void setUndergroundPortToBeSet(YACS::ENGINE::InputPyPort *p) const;
private:
YACSEvalAny *convertFromInternalAnyToExternal(YACS::ENGINE::Any *data) const;
void checkForNonConstMethod() const;
private:
YACS::ENGINE::InputPort * _ptr;
YACSEvalSeqAny *_mySeq;
+ mutable bool _isRandom;
mutable bool _isLocked;
+ mutable YACS::ENGINE::InputPyPort *_undergroundPort;
};
class YACSEvalOutputPort : public YACSEvalPort
return _pattern->getFreeOutputPorts();
}
-void YACSEvalYFX::lockPortsForEvaluation(const std::vector< YACSEvalOutputPort * >& outputsOfInterest)
+void YACSEvalYFX::lockPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputsOfInterest, const std::vector< YACSEvalOutputPort * >& outputsOfInterest)
{
- std::size_t sz(checkPortsForEvaluation(outputsOfInterest));
- _pattern->setOutPortsOfInterestForEvaluation(sz,outputsOfInterest);
+ checkPortsForEvaluation(inputsOfInterest,outputsOfInterest);
+ _pattern->setOutPortsOfInterestForEvaluation(outputsOfInterest);
_pattern->generateGraph();
}
bool YACSEvalYFX::run(YACSEvalSession *session, int& nbOfBranches)
{
+ _pattern->assignRandomVarsInputs();
YACSEvalListOfResources *rss(giveResources());
if(!rss->isInteractive())
throw YACS::Exception("YACSEvalYFX::run : not implemented yet for non interactive !");
_pattern=YACSEvalYFXPattern::FindPatternFrom(scheme,ownScheme);
}
-std::size_t YACSEvalYFX::checkPortsForEvaluation(const std::vector< YACSEvalOutputPort * >& outputs) const
+void YACSEvalYFX::checkPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputs, const std::vector< YACSEvalOutputPort * >& outputs) const
{
+ std::set<YACSEvalInputPort * > inputs2(inputs.begin(),inputs.end());
std::vector< YACSEvalInputPort * > allInputs(getFreeInputPorts());
std::vector< YACSEvalOutputPort * > allOutputs(getFreeOutputPorts());
- std::size_t sz(std::numeric_limits<std::size_t>::max());
for(std::vector< YACSEvalInputPort * >::const_iterator it=allInputs.begin();it!=allInputs.end();it++)
{
- std::size_t mySz;
- if(!(*it)->isOKForLock() && !(*it)->hasSequenceOfValuesToEval(mySz))
+ if(inputs2.find(*it)==inputs2.end())
{
- std::ostringstream oss; oss << "YACSEvalYFX::checkPortsForEvaluation : input port with name \"" << (*it)->getName() << "\" is not set properly !";
- throw YACS::Exception(oss.str());
- }
- if((*it)->hasSequenceOfValuesToEval(mySz))
- {
- if(sz==std::numeric_limits<std::size_t>::max())
- sz=mySz;
- else
+ if(!(*it)->isOKForLock())
{
- if(sz!=mySz)
- {
- std::ostringstream oss; oss << "YACSEvalYFX::checkPortsForEvaluation : input port with name \"" << (*it)->getName() << "\" is declared as to be evaluated on array ! But size of array is not the same than the others !";
- throw YACS::Exception(oss.str());
- }
+ std::ostringstream oss; oss << "YACSEvalYFX::checkPortsForEvaluation : input port with name \"" << (*it)->getName() << "\" is not set properly !";
+ throw YACS::Exception(oss.str());
}
}
}
if(soutputs.size()!=outputs.size())
throw YACS::Exception("YACSEvalYFX::lockPortsForEvaluation : each elt in outputs must appear once !");
for(std::vector< YACSEvalInputPort * >::const_iterator it=allInputs.begin();it!=allInputs.end();it++)
- (*it)->lock();
- return sz;
+ {
+ (*it)->declareRandomnessStatus(inputs2.find(*it)!=inputs2.end());
+ (*it)->lock();
+ }
}
YACSEvalYFX::~YACSEvalYFX()
YACSEVALYFX_EXPORT static YACSEvalYFX *BuildFromScheme(YACS::ENGINE::Proc *scheme);
YACSEVALYFX_EXPORT std::vector< YACSEvalInputPort * > getFreeInputPorts() const;
YACSEVALYFX_EXPORT std::vector< YACSEvalOutputPort * > getFreeOutputPorts() const;
- YACSEVALYFX_EXPORT void lockPortsForEvaluation(const std::vector< YACSEvalOutputPort * >& outputsOfInterest);
+ YACSEVALYFX_EXPORT void lockPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputsOfInterest, const std::vector< YACSEvalOutputPort * >& outputsOfInterest);
YACSEVALYFX_EXPORT void unlockAll();
YACSEVALYFX_EXPORT bool isLocked() const;
YACSEVALYFX_EXPORT YACSEvalListOfResources *giveResources();
YACSEVALYFX_EXPORT ~YACSEvalYFX();
private:
YACSEvalYFX(YACS::ENGINE::Proc *scheme, bool ownScheme);
- std::size_t checkPortsForEvaluation(const std::vector< YACSEvalOutputPort * >& outputs) const;
+ void checkPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputs, const std::vector< YACSEvalOutputPort * >& outputs) const;
private:
YACSEvalYFXPattern *_pattern;
};
#include "ResourcesManager.hxx"
#include <map>
+#include <limits>
#include <numeric>
#include <sstream>
delete _res;
}
-YACSEvalYFXRunOnlyPattern::YACSEvalYFXRunOnlyPattern(YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode):YACSEvalYFXPattern(scheme,ownScheme),_runNode(runNode),_commonSz(0),_generatedGraph(0)
+YACSEvalYFXRunOnlyPattern::YACSEvalYFXRunOnlyPattern(YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode):YACSEvalYFXPattern(scheme,ownScheme),_runNode(runNode),_generatedGraph(0)
{
if(!_runNode)
throw YACS::Exception("YACSEvalYFXRunOnlyPattern : internal run node must be not null !");
buildOutputPorts();
}
-void YACSEvalYFXRunOnlyPattern::setOutPortsOfInterestForEvaluation(std::size_t commonSize, const std::vector<YACSEvalOutputPort *>& outputsOfInterest)
+void YACSEvalYFXRunOnlyPattern::setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest)
{
checkNonLocked();
- _commonSz=commonSize;
_outputsOfInterest=outputsOfInterest;
}
void YACSEvalYFXRunOnlyPattern::resetOutputsOfInterest()
{
checkLocked();
- _commonSz=0;
_outputsOfInterest.clear();
}
void YACSEvalYFXRunOnlyPattern::generateGraph()
{
static const char LISTPYOBJ_STR[]="list[pyobj]";
- if(_commonSz==0 || _outputsOfInterest.empty())
+ if(_outputsOfInterest.empty())
return ;
YACS::ENGINE::RuntimeSALOME::setRuntime();
YACS::ENGINE::RuntimeSALOME *r(YACS::ENGINE::getSALOMERuntime());
std::ostringstream var0;
for(std::vector< YACSEvalInputPort >::const_iterator it=_inputs.begin();it!=_inputs.end();it++)
{
- std::size_t dummy;
- if((*it).hasSequenceOfValuesToEval(dummy))
+ if((*it).isRandomVar())
{
var0 << (*it).getName() << ",";
YACS::ENGINE::TypeCode *tc(createSeqTypeCodeFrom(_generatedGraph,(*it).getTypeOfData()));
YACS::ENGINE::InputPyPort *inpc(dynamic_cast<YACS::ENGINE::InputPyPort *>(inp));
if(!inpc)
throw YACS::Exception("YACSEvalYFXRunOnlyPattern::generateGraph : internal error 1 !");
- (*it).initializeUndergroundWithSeq(inpc);
+ (*it).setUndergroundPortToBeSet(inpc);
}
}
std::ostringstream n0Script; n0Script << "sender=zip(" << var0.str() << ")\n";
std::ostringstream var1;
for(std::vector< YACSEvalInputPort >::const_iterator it=_inputs.begin();it!=_inputs.end();it++)
{
- std::size_t dummy;
- if((*it).hasSequenceOfValuesToEval(dummy))
+ if((*it).isRandomVar())
{
var1 << (*it).getName() << ",";
YACS::ENGINE::OutputPort *myOut(n100->edAddOutputPort((*it).getName(),_generatedGraph->getTypeCode((*it).getTypeOfData())));
return nbOfBranch;
}
+void YACSEvalYFXRunOnlyPattern::assignRandomVarsInputs()
+{
+ std::size_t sz(std::numeric_limits<std::size_t>::max());
+ for(std::vector< YACSEvalInputPort >::const_iterator it=_inputs.begin();it!=_inputs.end();it++)
+ if((*it).isRandomVar())
+ {
+ std::size_t locSize((*it).initializeUndergroundWithSeq());
+ if(sz==std::numeric_limits<std::size_t>::max())
+ sz=locSize;
+ else
+ if(sz!=locSize)
+ throw YACS::Exception("YACSEvalYFXRunOnlyPattern::assignRandomVarsInputs : length of sequences in random vars must be the same !");
+ }
+}
+
bool YACSEvalYFXRunOnlyPattern::isLocked() const
{
return _generatedGraph!=0;
void checkLocked() const;
void checkNonLocked() const;
static void CheckNodeIsOK(YACS::ENGINE::ComposedNode *node);
- virtual void setOutPortsOfInterestForEvaluation(std::size_t commonSize, const std::vector<YACSEvalOutputPort *>& outputs) = 0;
+ virtual void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputs) = 0;
virtual void resetOutputsOfInterest() = 0;
virtual void generateGraph() = 0;
virtual void resetGeneratedGraph() = 0;
+ virtual void assignRandomVarsInputs() = 0;
virtual int assignNbOfBranches() = 0;
virtual bool isLocked() const = 0;
virtual YACSEvalListOfResources *giveResources() = 0;
{
public:
YACSEvalYFXRunOnlyPattern(YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
- void setOutPortsOfInterestForEvaluation(std::size_t commonSize, const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
+ void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
void resetOutputsOfInterest();
void generateGraph();
void resetGeneratedGraph();
int assignNbOfBranches();
+ void assignRandomVarsInputs();
bool isLocked() const;
YACSEvalListOfResources *giveResources();
YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
void buildOutputPorts();
private:
YACS::ENGINE::ComposedNode *_runNode;
- std::size_t _commonSz;
std::vector<YACSEvalOutputPort *> _outputsOfInterest;
YACS::ENGINE::Proc *_generatedGraph;
};
std::string getName() const;
bool hasDefaultValueDefined() const;
YACSEvalAny *getDefaultValueDefined() const;
+ bool isRandomVar() const;
+ void declareRandomnessStatus(bool isRandom);
+ bool hasSequenceOfValuesToEval() const;
%extend
{
void setDefaultValue(PyObject *parameter)
self->setSequenceOfValuesToEval(valsCpp);
delete valsCpp;
}
-
- PyObject *hasSequenceOfValuesToEval() const
- {
- std::size_t ret1;
- bool ret0(self->hasSequenceOfValuesToEval(ret1));
- PyObject *ret(PyTuple_New(2));
- PyObject *ret0Py=ret0?Py_True:Py_False;
- Py_XINCREF(ret0Py);
- PyTuple_SetItem(ret,0,ret0Py);
- PyTuple_SetItem(ret,1,PyInt_FromLong(ret1));
- return ret;
- }
}
private:
YACSEvalInputPort();
YACSEvalListOfResources *giveResources();
%extend
{
- void lockPortsForEvaluation(PyObject *outputsOfInterest)
+ void lockPortsForEvaluation(PyObject *inputsOfInterest, PyObject *outputsOfInterest)
{
std::vector<YACSEvalOutputPort *> outputsOfInterestCpp;
if(PyList_Check(outputsOfInterest))
PyErr_SetString(PyExc_TypeError,"not a list");
return ;
}
- self->lockPortsForEvaluation(outputsOfInterestCpp);
+ //
+ std::vector< YACSEvalInputPort * > inputsOfInterestCpp;
+ if(PyList_Check(inputsOfInterest))
+ {
+ int size(PyList_Size(inputsOfInterest));
+ for(int i=0;i<size;i++)
+ {
+ PyObject *obj(PyList_GetItem(inputsOfInterest,i));
+ void *argp(0);
+ int status(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_YACSEvalInputPort,0|0));
+ if(!SWIG_IsOK(status))
+ {
+ std::ostringstream oss; oss << "Input elt #" << i << " in list is not a YACSEvalInputPort instance !";
+ throw YACS::Exception(oss.str());
+ }
+ inputsOfInterestCpp.push_back(reinterpret_cast<YACSEvalInputPort *>(argp));
+ }
+ }
+ else
+ {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return ;
+ }
+ self->lockPortsForEvaluation(inputsOfInterestCpp,outputsOfInterestCpp);
}
PyObject *getResults() const
# prepare for execution
inps[0].setDefaultValue(1.1)
inps[1].setSequenceOfValuesToEval([10.1,10.2,10.3])
-a,b=inps[2].hasSequenceOfValuesToEval()
+a=inps[2].hasSequenceOfValuesToEval()
inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3,40.4])
-a,b=inps[2].hasSequenceOfValuesToEval()
+a=inps[2].hasSequenceOfValuesToEval()
inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3])
-efx.lockPortsForEvaluation([outps[0],outps[2]])
+efx.lockPortsForEvaluation([inps[1],inps[2]],[outps[0],outps[2]])
#
+"""
g=efx.getUndergroundGeneratedGraph()
g.saveSchema("toto.xml")
rss=efx.giveResources()
assert(a)
assert(b==4)
assert(efx.getResults()==[[11.110000000000001, 11.22, 11.330000000000002], [93.63, 94.26, 124.89000000000001]])
+"""
#import loader
#import pilot
#l=loader.YACSLoader()
# prepare for execution
inps[0].setDefaultValue(1.1)
inps[1].setSequenceOfValuesToEval([10.1,10.2,10.3])
- self.assertRaises(ValueError,efx.lockPortsForEvaluation,[outps[0],outps[2]]) # because e is not set
- a,b=inps[2].hasSequenceOfValuesToEval()
+ self.assertRaises(ValueError,efx.lockPortsForEvaluation,[inps[1]],[outps[0],outps[2]]) # because e is not set
+ a=inps[2].hasSequenceOfValuesToEval()
self.assertTrue(not a)
inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3,40.4])
- a,b=inps[2].hasSequenceOfValuesToEval()
+ a=inps[2].hasSequenceOfValuesToEval()
self.assertTrue(a)
- self.assertEqual(b,4)
- self.assertRaises(ValueError,efx.lockPortsForEvaluation,[outps[0],outps[2]]) # because size of vals of e is not equal to size of vals of a
+ efx.lockPortsForEvaluation([inps[1],inps[2]],[outps[0],outps[2]])
inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3])
- efx.lockPortsForEvaluation([outps[0],outps[2]])
#
g=efx.getUndergroundGeneratedGraph()
g.saveSchema("toto.xml")