Give WorkspaceString a self.ctx. Demagic all WorkspaceObjects. NFC.

This commit is contained in:
Arthur O'Dwyer
2017-04-17 20:13:22 -07:00
parent bd4790a3f1
commit 7581a328f7
4 changed files with 10 additions and 11 deletions

View File

@ -11,7 +11,7 @@ from context import context
context.slipnet = Slipnet() context.slipnet = Slipnet()
context.temperature = Temperature() context.temperature = Temperature()
context.coderack = Coderack(context) context.coderack = Coderack(context)
context.workspace = Workspace() context.workspace = Workspace(context)
def run(initial, modified, target, iterations): def run(initial, modified, target, iterations):

View File

@ -12,8 +12,9 @@ def __adjustUnhappiness(values):
class Workspace(object): class Workspace(object):
def __init__(self): def __init__(self, ctx):
#logging.debug('workspace.__init__()') #logging.debug('workspace.__init__()')
self.ctx = ctx
self.setStrings('', '', '') self.setStrings('', '', '')
self.reset() self.reset()
self.totalUnhappiness = 0.0 self.totalUnhappiness = 0.0
@ -36,9 +37,9 @@ class Workspace(object):
self.objects = [] self.objects = []
self.structures = [] self.structures = []
self.rule = None self.rule = None
self.initial = WorkspaceString(self.initialString) self.initial = WorkspaceString(self.ctx, self.initialString)
self.modified = WorkspaceString(self.modifiedString) self.modified = WorkspaceString(self.ctx, self.modifiedString)
self.target = WorkspaceString(self.targetString) self.target = WorkspaceString(self.ctx, self.targetString)
def assessUnhappiness(self): def assessUnhappiness(self):
self.intraStringUnhappiness = __adjustUnhappiness( self.intraStringUnhappiness = __adjustUnhappiness(

View File

@ -8,8 +8,7 @@ from workspaceStructure import WorkspaceStructure
class WorkspaceObject(WorkspaceStructure): class WorkspaceObject(WorkspaceStructure):
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
def __init__(self, workspaceString): def __init__(self, workspaceString):
from context import context as ctx WorkspaceStructure.__init__(self, workspaceString.ctx)
WorkspaceStructure.__init__(self, ctx)
self.string = workspaceString self.string = workspaceString
self.descriptions = [] self.descriptions = []
self.extrinsicDescriptions = [] self.extrinsicDescriptions = []

View File

@ -1,12 +1,13 @@
import logging import logging
from group import Group
from letter import Letter from letter import Letter
class WorkspaceString(object): class WorkspaceString(object):
def __init__(self, s): def __init__(self, ctx, s):
from context import context as ctx
slipnet = ctx.slipnet slipnet = ctx.slipnet
workspace = ctx.workspace workspace = ctx.workspace
self.ctx = ctx
self.string = s self.string = s
self.bonds = [] self.bonds = []
self.objects = [] self.objects = []
@ -76,8 +77,6 @@ class WorkspaceString(object):
self.intraStringUnhappiness = total / len(self.objects) self.intraStringUnhappiness = total / len(self.objects)
def equivalentGroup(self, sought): def equivalentGroup(self, sought):
from group import Group
for objekt in self.objects: for objekt in self.objects:
if isinstance(objekt, Group): if isinstance(objekt, Group):
if objekt.sameGroup(sought): if objekt.sameGroup(sought):