ometah-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oMetah-devel] ometah/experiment metahtest.py


From: Jean-Philippe Aumasson
Subject: [oMetah-devel] ometah/experiment metahtest.py
Date: Thu, 09 Jun 2005 10:38:57 -0400

CVSROOT:        /cvsroot/ometah
Module name:    ometah
Branch:         
Changes by:     Jean-Philippe Aumasson <address@hidden> 05/06/09 14:38:57

Modified files:
        experiment     : metahtest.py 

Log message:
        * new XML parser, classes Problem and Metaheuristic, etc...

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/experiment/metahtest.py.diff?tr1=1.9&tr2=1.10&r1=text&r2=text

Patches:
Index: ometah/experiment/metahtest.py
diff -u ometah/experiment/metahtest.py:1.9 ometah/experiment/metahtest.py:1.10
--- ometah/experiment/metahtest.py:1.9  Thu Jun  9 12:43:20 2005
+++ ometah/experiment/metahtest.py      Thu Jun  9 14:38:56 2005
@@ -55,6 +55,7 @@
 récupérer infos sur le problème à partir du header XML, et instancier un 
Header à remplir selon les vars parsées
 
 plottage de distribution : distrib pour chaque iteration, et pas pour 
l'ensemble...superposition des distributions ?
+-> distrib pour optima
 
 W  modulariser le prog
 
@@ -66,7 +67,7 @@
 
 D attributs __path et __defaultfilename dans l'Interface
 
-privater les méthodes non publiques ( add __ )
+D privater les méthodes non publiques ( add __ )
 
 
 /----
@@ -118,6 +119,7 @@
 
     __currentNode__ = None
     __pointsList__ = None
+    __header__ = None
     
     def __init__(self, xmlFile, interf):
         """ constructor, xmlFile is the file object of the XML output """
@@ -128,19 +130,19 @@
         from xml.dom.minidom import parse
         self.doc = parse(self.__xmlFile)
 
-    def getRootElement(self):
+    def __getRootElement(self):
         """ returns the rool element of the XML tree """
         if self.__currentNode__ == None:
             self.__currentNode__ = self.doc.documentElement
         return self.__currentNode__
 
-    def getText(self, node):
+    def __getText(self, node):
         return node.childNodes[0].nodeValue
 
-    def getList(self, nodes):
+    def __getList(self, nodes):
         li = []
         for n in nodes:
-            li.append(self.getText(n))
+            li.append(self.__getText(n))
         return li
     
     def getPoints(self):
@@ -148,48 +150,83 @@
         if self.__pointsList__ != None:
             return self.__pointsList__
         self.__pointsList__ = []
-        for iteration in 
self.getRootElement().getElementsByTagName('iteration'):
-            if iteration.getAttribute("class") == "intensification":
-                for sample in iteration.getElementsByTagName('sample'):
-                    for point in sample.getElementsByTagName('point'):
-                        if point.nodeType == point.ELEMENT_NODE:
-                            p = Point()                            
-                            try:
-                                p.value = 
self.getText(point.getElementsByTagName('values')[0])
-                                p.coords = 
self.getList(point.getElementsByTagName('solution')) #returns a list
-                            except:
-                                self.__interface.log('ERROR : XML element 
missing')
-                            self.__pointsList__.append(p)
+    
+        optimization = 
self.__getRootElement().getElementsByTagName('optimization')[0]
+        for iteration in optimization.getElementsByTagName('iteration'):
+            for step in iteration.getElementsByTagName('step'):
+                if step.getAttribute('class') == 'intensification':
+                    for sample in step.getElementsByTagName('sample'):
+                        for point in sample.getElementsByTagName('point'):
+                            if point.nodeType == point.ELEMENT_NODE:
+                                p = Point()                            
+                                try:
+                                    p.value = 
self.__getText(point.getElementsByTagName('values')[0])
+                                    p.coords = 
self.__getList(point.getElementsByTagName('solution')) #returns a list
+                                except:
+                                    self.__interface.log('ERROR : XML element 
missing [XMLParser.getPoints]\n')
+                                self.__pointsList__.append(p)
         return self.__pointsList__
+    
+    def getHeader(self):
+        """ creates a Header object for informations in XML header """
+        if self.__header__ != None:
+            return self.__header__
+        self.__header__ = Header()
 
+        # 1 remplir problem, et l'instancier avant
 
+        # 2 idem pour metaheur
 
-class Header:
-    """ for additional informations in XML file """
     
-    __dimension = None
-    __iterations = None
-    __problemName = None
-    __metahName = None
-        
+class Problem:
+    """ descriptive informations of a problem
+    only public attributes, descriptive class..."""
+    key = None
+    name = None
+    description = None
+    formula = None
+    dimension = None
+    optimum = [] # list of Point objects
+    min_bound = [] # idem
+    max_bound = [] # idem
+    reference = None
+    
     def __init__(self):
         pass
 
-    def getProblemName(self):
-        return self.__problemName
+class Metaheuristic:
+    """ descriptive informations of a metaheuristic
+    only public attributes, descriptive class..."""
+
+    key = None
+    name = None
+    family = None
+    acronym = None
+    description = None
+    reference = None
+    
+    def __init__(self):
+        pass
 
-    def getMetahName(self):
-        return self.__metahName
 
-    def getDimension(self):
-        return self.__dimension
+class Header:
+    """ for additional informations in XML file """
 
-    def getIterations(self):
-        return self.__iterations
+    __problem = Problem()
+    __metah = Metaheuristic()
+        
+    def __init__(self):
+        pass
+
+    def getProblem(self):
+        return self.__problem
+
+    def getMetah(self):
+        return self.__metah
 
     def toString(self):
         """ to generate a file name for the interface """
-        s = self.__problemName + "_" + self.__metahName;
+        s = self.__problem.name + "_" + self.__metah.name;
         return s
 
 class Point:
@@ -202,6 +239,11 @@
         pass
 
 
+def run(n):
+    """ make n runs for the given pb, algo, etc...
+    each output has the index of its run """
+    
+
 def main():
     """ main() """
 
@@ -256,7 +298,8 @@
     pointsList = parser.getPoints()
     intfc.log('getting points list : getPoints() ...  OK\n')
 
-    intfc.setPostscriptOutput(filename = 'valuesDistribHist')    
+
+    intfc.setBitmapOutput(filename = 'valuesDistribHist')    
     intfc.plotValuesIterationsDistribHist(pointsList, __HIST_BREAKS)    
     r.dev_off()
     intfc.log('outputing results : plotValuesIterationsDistribHist(...)  ...  
OK\n')
@@ -268,24 +311,22 @@
     interface.log('outputing results : plotValues(...)  ...  OK\n')
     """
 
-    intfc.setPostscriptOutput(filename = 'valuesBoxes')
+    intfc.setBitmapOutput(filename = 'valuesBoxes')
     intfc.plotValuesIterationsBoxes(pointsList, 10)
     r.dev_off()
     intfc.log('outputing results : plotValuesIterationsBoxes(...)  ...  OK\n')
     
-    intfc.setPostscriptOutput(filename = 'valuesStD')
+    intfc.setBitmapOutput(filename = 'valuesStD')
     intfc.plotValuesIterationsStdGraph(pointsList, 10)
     r.dev_off()
     intfc.log('outputing results : plotValuesIterationsStdGraph(...)  ...  
OK\n')
-    
+     
     slog = "\n[ End at " + time.ctime() + " ] \n"
     intfc.log(slog)
 
      
     print "time :",  (time.time()-t)
 
-
-
     
 if __name__ == '__main__':
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]