/[ascend]/trunk/pygtk/diagnose.py
ViewVC logotype

Diff of /trunk/pygtk/diagnose.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 735 by johnpye, Wed Jul 5 02:42:19 2006 UTC revision 2042 by jpye, Sat Jun 13 08:57:47 2009 UTC
# Line 10  import config Line 10  import config
10  from infodialog import *  from infodialog import *
11    
12  ZOOM_RE = re.compile(r"([0-9]+)\s*%?")  ZOOM_RE = re.compile(r"([0-9]+)\s*%?")
13  MAX_ZOOM_SIZE = 2000  MAX_ZOOM_SIZE = float(2000) # float
14  MAX_ZOOM_RATIO = 16  MAX_ZOOM_RATIO = float(16) # float
15  AT_BOUND_TOL = 0.0001;  AT_BOUND_TOL = 0.0001;
16    
17  class DiagnoseWindow:  class DiagnoseWindow:
# Line 38  class DiagnoseWindow: Line 38  class DiagnoseWindow:
38          self.blockentry = _xml.get_widget("blockentry")          self.blockentry = _xml.get_widget("blockentry")
39          self.zoomentry = _xml.get_widget("zoomentry")          self.zoomentry = _xml.get_widget("zoomentry")
40    
41          self.varname = _xml.get_widget("varname");          self.var = None; self.rel = None
42          self.varval = _xml.get_widget("varval");          self.varname = _xml.get_widget("varname1")
43          self.varinfobutton = _xml.get_widget("varinfobutton");          self.varval = _xml.get_widget("varval")
44          self.relname = _xml.get_widget("relname");          self.varinfobutton = _xml.get_widget("varinfobutton")
45          self.relresid = _xml.get_widget("relresid");          self.relname = _xml.get_widget("relname1")
46            self.relresid = _xml.get_widget("relresid")
47          self.relinfobutton = _xml.get_widget("relinfobutton")          self.relinfobutton = _xml.get_widget("relinfobutton")
48    
49          self.varview = _xml.get_widget("varview")          self.varview = _xml.get_widget("varview")
# Line 88  class DiagnoseWindow: Line 89  class DiagnoseWindow:
89      def fill_values(self, block):      def fill_values(self, block):
90                    
91          try:          try:
92                if self.im.getNumBlocks()==0:
93                    print "NO BLOCKS!"
94                    self.image.set_from_stock(gtk.STOCK_DIALOG_ERROR
95                        ,gtk.ICON_SIZE_DIALOG
96                    )
97                    self.browser.reporter.reportError(
98                        "Can't 'Diagnose blocks' until solver has been used."
99                    )
100                    return;
101              rl,cl,rh,ch = self.im.getBlockLocation(block)              rl,cl,rh,ch = self.im.getBlockLocation(block)
102          except IndexError:          except IndexError:
103              if block >= self.im.getNumBlocks():              if block >= self.im.getNumBlocks():
# Line 209  class DiagnoseWindow: Line 219  class DiagnoseWindow:
219              #print "SCALE TO FIX, w=%d, h=%d" % (w,h)              #print "SCALE TO FIX, w=%d, h=%d" % (w,h)
220              if self.nc/self.nr > w/h:              if self.nc/self.nr > w/h:
221                  # a 'wide' image                      # a 'wide' image    
222                  self.zoom = w / self.nc                  self.zoom = float(w) / self.nc
223              else:              else:
224                  self.zoom = h / self.nr                  self.zoom = float(h) / self.nr
225    
226            #self.browser.reporter.reportNote("Diagnose window: preliminary calculated zoom = %f (nr = %d, nc = %d)" % (self.zoom, self.nr, self.nc))
227            
228    
229          if self.zoom > MAX_ZOOM_RATIO:          if self.zoom > MAX_ZOOM_RATIO:
230              self.zoom = MAX_ZOOM_RATIO              self.zoom = MAX_ZOOM_RATIO
231    
232          if self.zoom * self.nc > MAX_ZOOM_SIZE or self.zoom * self.nr > MAX_ZOOM_SIZE:          if self.zoom * self.nc > MAX_ZOOM_SIZE or self.zoom * self.nr > MAX_ZOOM_SIZE:
233                self.browser.reporter.reportNode("image is too big, reducing to MAX_ZOOM_SIZE = %f" % MAX_ZOOM_SIZE);
234              self.zoom = MAX_ZOOM_SIZE / max(self.nc,self.nr)              self.zoom = MAX_ZOOM_SIZE / max(self.nc,self.nr)
235    
236            #self.browser.reporter.reportNote("Diagnose window: matrix zoom = %f" % self.zoom)
237          w = int(self.zoom * self.nc);          w = int(self.zoom * self.nc);
238          h = int(self.zoom * self.nr);          h = int(self.zoom * self.nr);
239                            
# Line 236  class DiagnoseWindow: Line 251  class DiagnoseWindow:
251    
252          names = [str(i) for i in self.im.getBlockVars(self.block)]          names = [str(i) for i in self.im.getBlockVars(self.block)]
253    
254          print "NAMES:",names          #print "NAMES:",names
255    
256          if self.varcollapsed.get_active():          if self.varcollapsed.get_active():
257              res = reduce(names)              res = reduce(names)
# Line 263  class DiagnoseWindow: Line 278  class DiagnoseWindow:
278    
279          names = [str(i) for i in rels]          names = [str(i) for i in rels]
280    
281          print "NAMES =",names          #print "NAMES =",names
282    
283          if self.relcollapsed.get_active():          if self.relcollapsed.get_active():
284              res = reduce(names)              res = reduce(names)
# Line 322  class DiagnoseWindow: Line 337  class DiagnoseWindow:
337      def on_varinfobutton_clicked(self,*args):      def on_varinfobutton_clicked(self,*args):
338          title = "Variable '%s'" % self.var          title = "Variable '%s'" % self.var
339          text = "%s\n%s\n" % (title,"(from the solver's view)")          text = "%s\n%s\n" % (title,"(from the solver's view)")
340          text += "\n%-30s%15f" % ("Value", self.var.getValue())  
341          text += "\n%-30s%15f" % ("Nominal", self.var.getNominal())          _rows = {
342          text += "\n%-30s%15f" % ("Lower bound", self.var.getLowerBound())              "Value": self.var.getValue()
343          text += "\n%-30s%15f" % ("Upper bound", self.var.getUpperBound())              ,"Nominal": self.var.getNominal()
344                ,"Lower bound": self.var.getLowerBound()
345                ,"Upper bound": self.var.getUpperBound()
346            }
347            for k,v in _rows.iteritems():
348                text += "\n  %s\t%s" % (k,value_human(v))
349                    
350          text += "\n\nIncidence with %d relations:" % self.var.getNumIncidentRelations()          text += "\n\nIncident with %d relations:" % self.var.getNumIncidentRelations()
351          for r in self.var.getIncidentRelations():          for r in self.var.getIncidentRelations():
352              text += "\n%s" % r.getName()              text += "\n  %s" % r.getName()
353    
354          _dialog = InfoDialog(self.browser,self.window,text,title)          _dialog = InfoDialog(self.browser,self.window,text,title,tabs=(150,300))
355          _dialog.run()          _dialog.run()
356    
357      def on_relinfobutton_clicked(self,*args):      def on_relinfobutton_clicked(self,*args):
358          title = "Relation '%s'" % self.rel          title = "Relation '%s'" % self.rel
359          text = "%s\n%s\n" % (title,"(from the solver's view)")          text = "%s\n%s\n" % (title,"(from the solver's view)")
360          text += "\n%-30s%15f" % ("Residual", self.rel.getResidual())          text += "\n  %s\t%15f" % ("Residual", self.rel.getResidual())
361    
362            text += "\n\nRelation expression:\n"
363            text += self.rel.getRelationAsString()
364    
365          _dialog = InfoDialog(self.browser,self.window,text,title)          text += "\n\nIncident with %d variables:" % self.rel.getNumIncidentVariables()
366            for v in self.rel.getIncidentVariables():
367                text += "\n  %s\t= %s" % ( v.getName(),value_human(v.getValue()) )
368    
369            _dialog = InfoDialog(self.browser,self.window,text,title,tabs=(150,300))
370          _dialog.run()          _dialog.run()
371                    
372    
# Line 409  class DiagnoseWindow: Line 436  class DiagnoseWindow:
436          self.show_cursor(event.x, event.y)          self.show_cursor(event.x, event.y)
437    
438    
439  # The following is from  def value_human(v):
440        if v==0 or abs( math.log10(abs(v)) )<8:
441            return "%f" % v
442        return "%e" % v
443    
444    #---------------------------------------
445    # Procedures to 'fold' a list of items from a hierarchy
446  # http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_21719649.html  # http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_21719649.html
447  # it's still buggy.  # It's still buggy, I think
448    
449  def fold(data):  def fold(data):
450      """ fold sorted numeric sequence data into ranged representation:      """ fold sorted numeric sequence data into ranged representation:
# Line 442  def reduce(names): Line 475  def reduce(names):
475      for k, g in groupby(data, lambda x: len(x)):      for k, g in groupby(data, lambda x: len(x)):
476          if k == 1:          if k == 1:
477              indexed = {}              indexed = {}
478              seq = set(get(indexed, item) for item in g)              seq = set([get(indexed, item) for item in g])
479              res['[global]'] = [ i+fold(indexed.get(i, [])) for i in sorted(seq) ]              res['[global]'] = [ i+fold(indexed.get(i, [])) for i in sorted(seq) ]
480          else:          else:
481              for key, g1 in groupby(g, lambda x: '.'.join(x[:-1])):              for key, g1 in groupby(g, lambda x: '.'.join(x[:-1])):
# Line 457  def get(indexed, item): Line 490  def get(indexed, item):
490          item, idx = item[:-1].split('[')          item, idx = item[:-1].split('[')
491          indexed.setdefault(item, []).append(int(idx))          indexed.setdefault(item, []).append(int(idx))
492      return item      return item
493    

Legend:
Removed from v.735  
changed lines
  Added in v.2042

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22