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: Tue, 07 Jun 2005 02:51:36 -0400

CVSROOT:        /cvsroot/ometah
Module name:    ometah
Branch:         
Changes by:     Jean-Philippe Aumasson <address@hidden> 05/06/07 06:51:36

Modified files:
        experiment     : metahtest.py 

Log message:
        * parsing of XML output with expat ok
        * output histogram to png or ps

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

Patches:
Index: ometah/experiment/metahtest.py
diff -u ometah/experiment/metahtest.py:1.3 ometah/experiment/metahtest.py:1.4
--- ometah/experiment/metahtest.py:1.3  Mon Jun  6 15:37:52 2005
+++ ometah/experiment/metahtest.py      Tue Jun  7 06:51:36 2005
@@ -84,7 +84,7 @@
         self.__dimension = 1
         self.__iterations = 0
         self.__problemName = ''
-        self.__metahName = ''
+        self.__metahName = ''        
     
     def execOmetah(self, path, output):
         """ execute ometah with given arguments,
@@ -97,26 +97,15 @@
         """ set class attributes from XML parsing """
         dimension = 1
         
-    def plotDistribution(self, list):
-        """ plot from informations read in xml file """
-        # KEEP OLD CODE for the moment ... (plotted from a file)
-        """
-        f = open(self.__xmlOutput, 'r')
-        line = f.readline()
-        coord = line.split()        
-        r.plot_default(coord[0], coord[1], col='red', xlim=(0, 1), ylim=(0, 1))
-        line = f.readline()
-        while len(string.split(line, sep=","))  != 2:            
-        if len(line.split()) == 2:
-        coord = line.split()
-        a = round(float(coord[0]), 4)
-        b = round(float(coord[1]), 4)
-        print a, ", ",  b
-        r.points(a, b, col='blue')
-        else:
-        print "empty line"
-        line = f.readline()        
-        f.close() """
+    def plotDistribution(self, plist, breaks):
+        """ plot from informations read in xml file """        
+        xlist = []
+        for x in plist:
+            xlist.append(float(x.value))
+        print xlist    
+        r.hist(xlist, breaks, col='green')
+    
+    
         
     def log(self):
         """ will write log of current job in a *.log file with date,
@@ -156,6 +145,15 @@
         if self.__currentNode__ == None:
             self.__currentNode__ = self.doc.documentElement
         return self.__currentNode__
+
+    def getText(self, node):
+        return node.childNodes[0].nodeValue
+
+    def getList(self, nodes):
+        li = []
+        for n in nodes:
+            li.append(self.getText(n))
+        return li
     
     def getPoints(self):
         """ returns a list of Points """
@@ -166,18 +164,25 @@
         # pour les attributs :
         #  help(xml.dom.minidom.Element)
         #  -> ... getAttribute(self, attname) !!
-        for point in self.getRootElement().getElementsByTagName('point'):
-            if point.nodeType == point.ELEMENT_NODE:
-                p = Point()
-                try:
-                    p.value = 
self.getText(point.getElementsByTagName('values')[0])
-                    p.coords = 
self.getText(point.getElementsByTagName('solution')) # returns a list ?
-                except:
-                    print 'XML element missing'
-                self.__pointsList__.append(p)
+        #
+        #  TODO : commits itsMetaheuristic.cpp !!!
+        #
+        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:
+                                print 'XML element missing'
+                            self.__pointsList__.append(p)
         return self.__pointsList__
 
 
+
 class Header:
     """ for additional informations in XML file """
     
@@ -213,12 +218,9 @@
 
     parser = XMLParser(fd)
     parser.readXml()
-
-    # !! donner un dicionnaire en param├Ętre de plot !
-    # parser = Parser(fd)    
-    # parser.parse()
-    # list = parser.getPointList()
-    # main.plotDistribution(list)
+    pointsList = parser.getPoints()
+    
+    main.plotDistribution(pointsList, 10)
     
     r.dev_off()
     




reply via email to

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