[Avida-cvs] [Avida2-svn] r151 - trunk/source/python/AvidaGui2

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Fri Apr 15 04:01:10 PDT 2005


Author: kaben
Date: 2005-04-15 07:01:10 -0400 (Fri, 15 Apr 2005)
New Revision: 151

Modified:
   trunk/source/python/AvidaGui2/pyMapProfile.py
   trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
   trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
Log:

* Avida-ED fixes:
- Map population depiction was wrong. Organisms were missing.
- Map colors remain valid when switching to fitness mode during update.



Modified: trunk/source/python/AvidaGui2/pyMapProfile.py
===================================================================
--- trunk/source/python/AvidaGui2/pyMapProfile.py	2005-04-15 10:59:28 UTC (rev 150)
+++ trunk/source/python/AvidaGui2/pyMapProfile.py	2005-04-15 11:01:10 UTC (rev 151)
@@ -1,9 +1,10 @@
 
-from qt import QColor
+from qt import PYSIGNAL, QColor, QObject
 from math import exp
 
 class pyMapProfile:
-  def __init__(self):
+  def __init__(self, session_mdl):
+    self.m_session_mdl = session_mdl
     self.m_color_cache_size = 201
 
     def continuousIndexer(idx_functor):
@@ -32,8 +33,8 @@
 
 
     class gradualLinScaleUpdater:
-      def __init__(self, rng_functor):
-        self.m_rng_functor = rng_functor
+      def __init__(self, range):
+        self.m_range = range
         self.m_inf = 0.0
         self.m_sup = 0.0
         self.m_target_inf = 0.0
@@ -55,7 +56,7 @@
         return self.m_inf, self.m_sup
 
       def resetRange(self, population):
-        (inf, sup) = population and self.m_rng_functor(population) or (0.0, 0.0)
+        (inf, sup) = self.m_range.getRange()
         (self.m_target_inf, self.m_target_sup) = (self.m_inf, self.m_sup) = (inf, sup)
         self.m_inf_rescale_rate = self.m_sup_rescale_rate = 0
 
@@ -65,7 +66,7 @@
         if self.m_should_reset:
           return self.resetRange(population)
 
-        (inf, sup) = population and self.m_rng_functor(population) or (0.0, 0.0)
+        (inf, sup) = self.m_range.getRange()
         if (sup < (1 - self.m_sup_tol_coef) * self.m_target_sup) or (self.m_target_sup < sup):
           new_target_sup = sup * (1 + self.m_sup_tol_coef)
           self.m_sup_rescale_rate = float(new_target_sup - self.m_sup) / self.m_updates_to_rescale
@@ -79,7 +80,31 @@
 
         return self.getRange()
 
-    # Range functors
+    class RangeReport(QObject):
+      def __init__(self, range_functor, session_mdl):
+        self.m_range_functor = range_functor
+        self.m_session_mdl = session_mdl
+        self.connect(self.m_session_mdl.m_session_mdtr, PYSIGNAL("setAvidaSig"), self.setAvidaSlot)
+        self.m_avida = None
+        self.m_range = (0, 0)
+      def setAvidaSlot(self, avida):
+        old_avida = self.m_avida
+        self.m_avida = avida
+        if(old_avida):
+          self.disconnect(
+            self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
+            self.avidaUpdatedSlot)
+          del old_avida
+        if(self.m_avida):
+          self.connect(
+            self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
+            self.avidaUpdatedSlot)
+      def avidaUpdatedSlot(self):
+        if self.m_avida and self.m_avida.m_population:
+          self.m_range = self.m_range_functor(self.m_avida.m_population)
+      def getRange(self):
+        return self.m_range
+
     NullRng = lambda p: (0, 0)
     MeritRng = lambda p: (0, p.GetStats().GetMaxMerit())
     FitnessRng = lambda p: (0, p.GetStats().GetMaxFitness())
@@ -112,27 +137,27 @@
     #  Mode Name,        Indexer
       ('None',
         continuousIndexer(NullIdx),
-        gradualLinScaleUpdater(NullRng),
+        gradualLinScaleUpdater(RangeReport(NullRng, self.m_session_mdl)),
         None
         ),
       ('Merit',
         continuousIndexer(MeritIdx),
-        gradualLinScaleUpdater(MeritRng),
+        gradualLinScaleUpdater(RangeReport(MeritRng, self.m_session_mdl)),
         sigmoidColorLookup
         ),
       ('Fitness',
         continuousIndexer(FitnessIdx),
-        gradualLinScaleUpdater(FitnessRng),
+        gradualLinScaleUpdater(RangeReport(FitnessRng, self.m_session_mdl)),
         sigmoidColorLookup
         ),
       ('Gestation Time',
         continuousIndexer(GestationTimeIdx),
-        gradualLinScaleUpdater(GestationTimeRng),
+        gradualLinScaleUpdater(RangeReport(GestationTimeRng, self.m_session_mdl)),
         sigmoidColorLookup
         ),
       ('Size',
         continuousIndexer(SizeIdx),
-        gradualLinScaleUpdater(SizeRng),
+        gradualLinScaleUpdater(RangeReport(SizeRng, self.m_session_mdl)),
         sigmoidColorLookup
         ),
       #('Genotype',       GenotypeIdx,),

Modified: trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py	2005-04-15 10:59:28 UTC (rev 150)
+++ trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py	2005-04-15 11:01:10 UTC (rev 151)
@@ -31,7 +31,7 @@
 
     self.m_mode_combobox.clear()
     self.m_mode_combobox.setInsertionPolicy(QComboBox.AtBottom)
-    self.m_map_profile = pyMapProfile()
+    self.m_map_profile = pyMapProfile(self.m_session_mdl)
     for i in range(self.m_map_profile.getSize()):
       self.m_mode_combobox.insertItem(self.m_map_profile.getModeName(i))
 

Modified: trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriDishCtrl.py	2005-04-15 10:59:28 UTC (rev 150)
+++ trunk/source/python/AvidaGui2/pyPetriDishCtrl.py	2005-04-15 11:01:10 UTC (rev 151)
@@ -112,23 +112,29 @@
   def setIndexer(self, indexer):
     self.m_indexer = indexer
 
+  def updateCellItem(self, cell_id):
+    if self.m_cell_info[cell_id] is None:
+      self.m_cell_info[cell_id] = self.createNewCellItem(cell_id)
+    cell_info_item = self.m_cell_info[cell_id]
+    self.m_indexer(cell_info_item, self.m_cs_min_value, self.m_cs_value_range)
+    cell_info_item.updateColorUsingFunctor(self.m_color_lookup_functor)
+
   def updateCellItems(self, should_update_all = False):
-    def updateCellItem(cell_id):
-      if self.m_cell_info[cell_id] is None:
-        self.m_cell_info[cell_id] = self.createNewCellItem(cell_id)
-      cell_info_item = self.m_cell_info[cell_id]
-      self.m_indexer(cell_info_item, self.m_cs_min_value, self.m_cs_value_range)
-      cell_info_item.updateColorUsingFunctor(self.m_color_lookup_functor)
+    if self.m_cell_info:
 
-    if should_update_all and self.m_cell_info:
-      for cell_id in self.m_occupied_cells_ids:
-        updateCellItem(cell_id)
-    elif self.m_change_list and self.m_cell_info:
-      for index in range(self.m_change_list.GetChangeCount()):
-        updateCellItem(self.m_change_list[index])
+      self.m_avida and self.m_avida.m_avida_threaded_driver.m_lock.acquire()
+      if self.m_change_list:
+        for index in range(self.m_change_list.GetChangeCount()):
+          self.updateCellItem(self.m_change_list[index])
+        self.m_change_list.Reset()
+      self.m_avida and self.m_avida.m_avida_threaded_driver.m_lock.release()
 
-    if self.m_canvas: self.m_canvas.update()
+      if should_update_all:
+        for cell_id in self.m_occupied_cells_ids:
+          self.updateCellItem(cell_id)
 
+      if self.m_canvas: self.m_canvas.update()
+
   def extractPopulationSlot(self):
     population_dict = {}
     for x in range(self.m_world_w):




More information about the Avida-cvs mailing list