1 # Copyright (C) 2006-2013 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.
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")
29 def setPool(self,pool):
30 """Must be implemented to set the pool"""
34 """returns typecode of type expected as Input"""
37 def getTCForOut(self):
38 """returns typecode of type expected as Output"""
41 def startToTakeDecision(self):
42 """This method is called only once to launch the algorithm. It must first fill the
43 pool with samples to evaluate and call self.signalMasterAndWait() to block until a
44 sample has been evaluated. When returning from this method, it MUST check for an
45 eventual termination request (with the method self.isTerminationRequested()). If
46 the termination is requested, the method must perform any necessary cleanup and
47 return as soon as possible. Otherwise it can either add new samples to evaluate in
48 the pool, do nothing (wait for more samples), or empty the pool and return to
49 finish the evaluation.
52 for iter in xrange(5):
53 #push a sample in the input of the slave node
54 self.pool.pushInSample(iter,val)
55 #wait until next sample is ready
56 self.signalMasterAndWait()
57 #check error notification
58 if self.isTerminationRequested():
59 self.pool.destroyAll()
62 #get a sample from the output of the slave node
63 currentId=self.pool.getCurrentId()
64 v=self.pool.getCurrentOutSample()
65 val=val+v.getIntValue()
67 #in the end destroy the pool content
68 self.pool.destroyAll()