Major overhaul of temperature logic. Behavioral change.
I think the reason the temperature logic was so confused in the old code is because the Java code has a class `Temperature` that is used for graphical display *and* two variables in `formulas` that are used for most of the actual math. But somewhere along the line, some of the code in `formulas.java` started reading from `Temperature.value` as well. So the Python code was just faithfully copying that confusion. The actual abstraction here is a very simple "temperature" object with a stored value. It can be "clamped" to 100.0 for a given period. The only complication is that one of the codelets (the rule-transformer codelet) wants to get access to the "actual value" of the temperature even when it is clamped. The Python rule-transformer codelet also had a bug: it was accidentally setting `temperature.value` on the `temperature` module instead of on the `temperature.temperature` object! This turned some of its behavior into a no-op, for whatever that's worth. Lastly, the calculation of `finalTemperature` in the main program can now report 100.0 if the answer is found while the temperature is clamped. I don't fully understand why this didn't happen in the old code. I've hacked around it with `temperature.last_unclamped_value` for now, but I should TODO FIXME.
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import logging
|
||||
|
||||
import formulas
|
||||
from temperature import temperature
|
||||
from workspaceString import WorkspaceString
|
||||
|
||||
|
||||
@ -85,19 +84,14 @@ class Workspace(object):
|
||||
self.initial.updateIntraStringUnhappiness()
|
||||
self.target.updateIntraStringUnhappiness()
|
||||
|
||||
def updateTemperature(self):
|
||||
def getUpdatedTemperature(self):
|
||||
self.assessTemperature()
|
||||
ruleWeakness = 100.0
|
||||
if self.rule:
|
||||
self.rule.updateStrength()
|
||||
ruleWeakness = 100.0 - self.rule.totalStrength
|
||||
values = ((self.totalUnhappiness, 0.8), (ruleWeakness, 0.2))
|
||||
above_actual_temperature = formulas.actualTemperature + 0.001
|
||||
formulas.actualTemperature = formulas.weightedAverage(values)
|
||||
if temperature.clamped:
|
||||
formulas.actualTemperature = 100.0
|
||||
formulas.Temperature = formulas.actualTemperature
|
||||
temperature.update(formulas.Temperature)
|
||||
return formulas.weightedAverage(values)
|
||||
|
||||
def numberOfUnrelatedObjects(self):
|
||||
"""A list of all objects in the workspace with >= 1 open bond slots"""
|
||||
|
||||
Reference in New Issue
Block a user