Salome HOME
Merge branch 'V8_3_BR' into ngr/python3_dev
[modules/yacs.git] / src / yacsloader_swig / Test / optim_plugin.py
1 import SALOMERuntime
2
3 class myalgosync(SALOMERuntime.OptimizerAlgSync):
4   def __init__(self):
5     SALOMERuntime.OptimizerAlgSync.__init__(self, None)
6     r=SALOMERuntime.getSALOMERuntime()
7     self.tin=r.getTypeCode("int")
8     self.tout=r.getTypeCode("int")
9     self.tAlgoInit=r.getTypeCode("int")
10     self.tAlgoResult=r.getTypeCode("int")
11
12   def setPool(self,pool):
13     """Must be implemented to set the pool"""
14     self.pool=pool
15
16   def getTCForIn(self):
17     """return typecode of type expected as Input the internal node """
18     return self.tin
19
20   def getTCForOut(self):
21     """return typecode of type expected as Output the internal node"""
22     return self.tout
23
24   def getTCForAlgoInit(self):
25     """return typecode of type expected as input for initialize """
26     return self.tAlgoInit
27
28   def getTCForAlgoResult(self):
29     """return typecode of type expected as output of the algorithm """
30     return self.tAlgoResult
31
32   def initialize(self,input):
33     """Optional method called on initialization.
34        The type of "input" is returned by "getTCForAlgoInit"
35     """
36     print("Algo initialize, input = ", input.getIntValue())
37
38   def start(self):
39     """Start to fill the pool with samples to evaluate."""
40     print("Algo start ")
41     self.iter=0
42     # pushInSample(id, value)
43     self.pool.pushInSample(self.iter, 1)
44
45   def takeDecision(self):
46     """ This method is called each time a sample has been evaluated. It can
47         either add new samples to evaluate in the pool, do nothing (wait for
48         more samples), or empty the pool to finish the evaluation.
49     """
50     currentId=self.pool.getCurrentId()
51     valIn = self.pool.getCurrentInSample().getIntValue()
52     valOut = self.pool.getCurrentOutSample().getIntValue()
53     print("Algo takeDecision currentId=%s, valIn=%s, valOut=%s" % (currentId, valIn, valOut))
54
55     self.iter=self.iter+1
56     if self.iter < 3:
57       # continue
58       nextSample = valIn + 1
59       self.pool.pushInSample(self.iter, nextSample)
60
61   def finish(self):
62     """Optional method called when the algorithm has finished, successfully
63        or not, to perform any necessary clean up."""
64     print("Algo finish")
65     self.pool.destroyAll()
66
67   def getAlgoResult(self):
68     """return the result of the algorithm.
69        The object returned is of type indicated by getTCForAlgoResult.
70     """
71     return 42
72
73