Commit 644323fa by Adam P. Goucher

### Functionality to swap layers in tree

parent 85318ed0
Pipeline #49749597 passed with stages
in 7 minutes and 34 seconds
 ... ... @@ -64,24 +64,32 @@ class RuleTree: self.cache[nddr] = r return r def _recreate(self,oseq,nddr,lev): def _recreate(self,oseq,nddr,lev, swap_at): if lev == 0: return nddr if nddr in self.cache: return self.cache[nddr] # each node entry is the node index retrieved from a recursive call to the next level down node = tuple( [lev] + [ self._recreate(oseq,oseq[nddr][i+1],lev-1) for i in range(self.numStates) ] ) if lev == swap_at: nodes = [lev] for j in range(self.numStates): node = tuple( [lev-1] + [ self._recreate(oseq, oseq[oseq[nddr][i+1]][j+1],lev-2,swap_at) for i in range(self.numStates) ] ) r = self._getNode(node) nodes.append(r) node = tuple(nodes) else: # each node entry is the node index retrieved from a recursive call to the next level down node = tuple( [lev] + [ self._recreate(oseq,oseq[nddr][i+1],lev-1,swap_at) for i in range(self.numStates) ] ) r = self._getNode(node) self.cache[nddr] = r return r def _shrink(self): def _shrink(self, swap_at=-1): self.world = {} oseq = self.seq self.seq = [] self.cache = {} self.nodeSeq = 0 ; self.curndd = self._recreate(oseq, self.curndd, self.numInputs) self.curndd = self._recreate(oseq, self.curndd, self.numInputs, swap_at) self.shrinksize = len(self.seq) * 2 def add_rule(self,inputs,output): ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!