4 class myalgosync(SALOMERuntime.OptimizerAlgSync):
6 SALOMERuntime.OptimizerAlgSync.__init__(self, None)
7 r=SALOMERuntime.getSALOMERuntime()
8 self.tin=r.getTypeCode("pyobj")
9 self.tout=r.getTypeCode("pyobj")
10 self.tAlgoInit=r.getTypeCode("pyobj")
11 self.tAlgoResult=r.getTypeCode("pyobj")
13 def setPool(self,pool):
14 """Must be implemented to set the pool"""
18 """return typecode of type expected as Input of the internal node """
21 def getTCForOut(self):
22 """return typecode of type expected as Output of the internal node"""
25 def getTCForAlgoInit(self):
26 """return typecode of type expected as input for initialize """
29 def getTCForAlgoResult(self):
30 """return typecode of type expected as output of the algorithm """
31 return self.tAlgoResult
33 def initialize(self,input):
34 """Optional method called on initialization.
35 The type of "input" is returned by "getTCForAlgoInit"
37 self.data=input.getPyObj()
41 """Start to fill the pool with samples to evaluate."""
42 r=SALOMERuntime.getSALOMERuntime()
45 # "range" is for a python object which is not of basic type
46 self.pool.pushInSample(self.iter, r.createAnyPyObject(range(i)))
49 def takeDecision(self):
50 """ This method is called each time a sample has been evaluated. It can
51 either add new samples to evaluate in the pool, do nothing (wait for
52 more samples), or empty the pool to finish the evaluation.
54 currentId=self.pool.getCurrentId()
55 in_value = self.pool.getCurrentInSample().getPyObj()
56 result = self.pool.getCurrentOutSample().getPyObj()
57 self.result = self.result + len(result)
60 """Optional method called when the algorithm has finished, successfully
61 or not, to perform any necessary clean up."""
62 self.pool.destroyAll()
63 self.result = 0 # the result object is destroyed
65 def getAlgoResult(self):
66 """return the result of the algorithm.
67 The object returned is of type indicated by getTCForAlgoResult.
69 r=SALOMERuntime.getSALOMERuntime()
70 # Force the creation of a python object into the result port.
71 # If a basic python type is used, it will be converted to a basic c++ type
72 # (int, double, std::string) and this is not what the result port expects as
73 # it is declared of type pyobj.
74 self.result = r.createAnyPyObject(self.result)
75 # do not return a local variable created with "createAnyPyObject" (crash)