More Pythonicisms. NFC.
This commit is contained in:
@ -136,12 +136,14 @@ class Bond(WorkspaceStructure):
|
||||
self.externalStrength = strength
|
||||
|
||||
def numberOfLocalSupportingBonds(self):
|
||||
return len([b for b in self.string.bonds if
|
||||
b.string == self.source.string and
|
||||
self.leftObject.letterDistance(b.leftObject) != 0 and
|
||||
self.rightObject.letterDistance(b.rightObject) != 0 and
|
||||
self.category == b.category and
|
||||
self.directionCategory == b.directionCategory])
|
||||
return sum(
|
||||
1 for b in self.string.bonds if
|
||||
b.string == self.source.string and
|
||||
self.leftObject.letterDistance(b.leftObject) != 0 and
|
||||
self.rightObject.letterDistance(b.rightObject) != 0 and
|
||||
self.category == b.category and
|
||||
self.directionCategory == b.directionCategory
|
||||
)
|
||||
|
||||
def sameCategories(self, other):
|
||||
return (self.category == other.category and
|
||||
|
||||
@ -347,11 +347,7 @@ def replacement_finder(ctx, codelet):
|
||||
# choose random letter in initial string
|
||||
letters = [o for o in workspace.initial.objects if isinstance(o, Letter)]
|
||||
letterOfInitialString = random.choice(letters)
|
||||
logging.info('selected letter in initial string = %s',
|
||||
letterOfInitialString)
|
||||
if letterOfInitialString.replacement:
|
||||
logging.info("Replacement already found for %s, so fizzling",
|
||||
letterOfInitialString)
|
||||
return
|
||||
position = letterOfInitialString.leftIndex
|
||||
moreLetters = [o for o in workspace.modified.objects
|
||||
@ -369,16 +365,13 @@ def replacement_finder(ctx, codelet):
|
||||
1: slipnet.predecessor
|
||||
}
|
||||
relation = relations[diff]
|
||||
logging.info('Relation found: %s', relation.name)
|
||||
else:
|
||||
relation = None
|
||||
logging.info('no relation found')
|
||||
letterOfInitialString.replacement = Replacement(ctx,
|
||||
letterOfInitialString, letterOfModifiedString, relation)
|
||||
if relation != slipnet.sameness:
|
||||
letterOfInitialString.changed = True
|
||||
workspace.changedObject = letterOfInitialString
|
||||
logging.info('building replacement')
|
||||
|
||||
|
||||
@codelet('top-down-bond-scout--category')
|
||||
|
||||
@ -51,11 +51,6 @@ class Workspace(object):
|
||||
o.relativeImportance * o.totalUnhappiness
|
||||
for o in self.objects)
|
||||
|
||||
def assessTemperature(self):
|
||||
self.calculateIntraStringUnhappiness()
|
||||
self.calculateInterStringUnhappiness()
|
||||
self.calculateTotalUnhappiness()
|
||||
|
||||
def calculateIntraStringUnhappiness(self):
|
||||
value = sum(
|
||||
o.relativeImportance * o.intraStringUnhappiness
|
||||
@ -88,13 +83,18 @@ class Workspace(object):
|
||||
self.target.updateIntraStringUnhappiness()
|
||||
|
||||
def getUpdatedTemperature(self):
|
||||
self.assessTemperature()
|
||||
ruleWeakness = 100.0
|
||||
self.calculateIntraStringUnhappiness()
|
||||
self.calculateInterStringUnhappiness()
|
||||
self.calculateTotalUnhappiness()
|
||||
if self.rule:
|
||||
self.rule.updateStrength()
|
||||
ruleWeakness = 100.0 - self.rule.totalStrength
|
||||
values = ((self.totalUnhappiness, 0.8), (ruleWeakness, 0.2))
|
||||
return formulas.weightedAverage(values)
|
||||
else:
|
||||
ruleWeakness = 100.0
|
||||
return formulas.weightedAverage((
|
||||
(self.totalUnhappiness, 0.8),
|
||||
(ruleWeakness, 0.2)
|
||||
))
|
||||
|
||||
def numberOfUnrelatedObjects(self):
|
||||
"""A list of all objects in the workspace with >= 1 open bond slots"""
|
||||
@ -130,7 +130,7 @@ class Workspace(object):
|
||||
|
||||
def numberOfBonds(self):
|
||||
"""The number of bonds in the workspace"""
|
||||
return len([o for o in self.structures if isinstance(o, Bond)])
|
||||
return sum(1 for o in self.structures if isinstance(o, Bond))
|
||||
|
||||
def correspondences(self):
|
||||
return [s for s in self.structures if isinstance(s, Correspondence)]
|
||||
|
||||
Reference in New Issue
Block a user