1 # Copyright (C) 2015-2021 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 class myalgosync(SALOMERuntime.OptimizerAlgSync):
23 SALOMERuntime.OptimizerAlgSync.__init__(self, None)
24 r=SALOMERuntime.getSALOMERuntime()
25 self.tin=r.getTypeCode("int")
26 self.tout=r.getTypeCode("int")
27 self.tAlgoInit=r.getTypeCode("int")
28 self.tAlgoResult=r.getTypeCode("int")
30 def setPool(self,pool):
31 """Must be implemented to set the pool"""
35 """return typecode of type expected as Input the internal node """
38 def getTCForOut(self):
39 """return typecode of type expected as Output the internal node"""
42 def getTCForAlgoInit(self):
43 """return typecode of type expected as input for initialize """
46 def getTCForAlgoResult(self):
47 """return typecode of type expected as output of the algorithm """
48 return self.tAlgoResult
50 def initialize(self,input):
51 """Optional method called on initialization.
52 The type of "input" is returned by "getTCForAlgoInit"
54 print("Algo initialize, input = ", input.getIntValue())
57 """Start to fill the pool with samples to evaluate."""
60 # pushInSample(id, value)
61 self.pool.pushInSample(self.iter, 1)
63 def takeDecision(self):
64 """ This method is called each time a sample has been evaluated. It can
65 either add new samples to evaluate in the pool, do nothing (wait for
66 more samples), or empty the pool to finish the evaluation.
68 currentId=self.pool.getCurrentId()
69 valIn = self.pool.getCurrentInSample().getIntValue()
70 valOut = self.pool.getCurrentOutSample().getIntValue()
71 print("Algo takeDecision currentId=%s, valIn=%s, valOut=%s" % (currentId, valIn, valOut))
76 nextSample = valIn + 1
77 self.pool.pushInSample(self.iter, nextSample)
80 """Optional method called when the algorithm has finished, successfully
81 or not, to perform any necessary clean up."""
83 self.pool.destroyAll()
85 def getAlgoResult(self):
86 """return the result of the algorithm.
87 The object returned is of type indicated by getTCForAlgoResult.