1 # Copyright (C) 2006-2014 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
22 class myalgoasync(SALOMERuntime.OptimizerAlgASync):
24 SALOMERuntime.OptimizerAlgASync.__init__(self, None)
25 r=SALOMERuntime.getSALOMERuntime()
26 self.tin=r.getTypeCode("double")
27 self.tout=r.getTypeCode("int")
28 self.tAlgoInit=r.getTypeCode("int")
29 self.tAlgoResult=r.getTypeCode("int")
31 def setPool(self,pool):
32 """Must be implemented to set the pool"""
36 """return typecode of type expected as Input of the internal node """
39 def getTCForOut(self):
40 """return typecode of type expected as Output of the internal node"""
43 def getTCForAlgoInit(self):
44 """return typecode of type expected as input for initialize """
47 def getTCForAlgoResult(self):
48 """return typecode of type expected as output of the algorithm """
49 return self.tAlgoResult
51 def initialize(self,input):
52 """Optional method called on initialization.
53 The type of "input" is returned by "getTCForAlgoInit"
55 print "Algo initialize, input = ", input.getIntValue()
57 def startToTakeDecision(self):
58 """This method is called only once to launch the algorithm. It must
59 first fill the pool with samples to evaluate and call
60 self.signalMasterAndWait() to block until a sample has been
61 evaluated. When returning from this method, it MUST check for an
62 eventual termination request (with the method
63 self.isTerminationRequested()). If the termination is requested, the
64 method must perform any necessary cleanup and return as soon as
65 possible. Otherwise it can either add new samples to evaluate in the
66 pool, do nothing (wait for more samples), or empty the pool and
67 return to finish the evaluation.
69 print "startToTakeDecision"
70 # fill the pool with samples
72 self.pool.pushInSample(0, 0.5)
75 self.signalMasterAndWait()
76 while not self.isTerminationRequested():
77 currentId=self.pool.getCurrentId()
78 valIn = self.pool.getCurrentInSample().getDoubleValue()
79 valOut = self.pool.getCurrentOutSample().getIntValue()
80 print "Compute currentId=%s, valIn=%s, valOut=%s" % (currentId, valIn, valOut)
84 nextSample = valIn + 1
85 self.pool.pushInSample(iter, nextSample)
87 self.signalMasterAndWait()
90 """Optional method called when the algorithm has finished, successfully
91 or not, to perform any necessary clean up."""
93 self.pool.destroyAll()
95 def getAlgoResult(self):
96 """return the result of the algorithm.
97 The object returned is of type indicated by getTCForAlgoResult.