Changeset 1644

Show
Ignore:
Timestamp:
07/16/07 16:09:20 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- removed duplicated code after merging from trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/branches/hw/gaphas/constraint.py

    r1641 r1644  
    372372    """ 
    373373 
    374     def __init__(self, band=None, v=None): 
    375         super(BalanceConstraint, self).__init__(band[0], band[1], v) 
    376         self.band = band 
    377         b1, b2 = self.band 
    378         w = b2 - b1 
    379         if w != 0: 
    380             self.balance = (v - b1) / w 
    381         else: 
    382             self.balance = 0 
    383         self.v = v 
    384         print 'b', self.balance 
    385  
    386     def solve_for(self, var): 
    387         b1, b2 = self.band 
    388         w = b2 - b1 
    389         var.value = b1 + w * self.balance 
    390  
    391  
    392  
    393 class BalanceConstraint(Constraint): 
    394     """ 
    395     Ensure that a variable @v is between values specified by @band 
    396     and in distance proportional from @band[0]. 
    397  
    398     Consider 
    399     >>> from solver import Variable, WEAK 
    400     >>> a, b, c = Variable(2.0), Variable(3.0), Variable(2.3, WEAK) 
    401     >>> bc = BalanceConstraint(band=(a,b), v=c) 
    402     >>> c.value = 2.4 
    403     >>> c 
    404     Variable(2.4, 10) 
    405     >>> bc.solve_for(c) 
    406     >>> a, b, c 
    407     (Variable(2, 20), Variable(3, 20), Variable(2.3, 10)) 
    408  
    409     Band does not have to be band[0] < band[1] 
    410     >>> a, b, c = Variable(3.0), Variable(2.0), Variable(2.45, WEAK) 
    411     >>> bc = BalanceConstraint(band=(a,b), v=c) 
    412     >>> c.value = 2.50 
    413     >>> c 
    414     Variable(2.5, 10) 
    415     >>> bc.solve_for(c) 
    416     >>> a, b, c 
    417     (Variable(3, 20), Variable(2, 20), Variable(2.45, 10)) 
    418     """ 
    419  
    420374    def __init__(self, band=None, v=None, balance=None): 
    421375        super(BalanceConstraint, self).__init__(band[0], band[1], v)