diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2011-02-20 23:00:18 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2011-02-20 23:00:18 -0500 |
commit | ee5dc03fbf6b75328295f5a6115f5d6a5c33455e (patch) | |
tree | db39963c35214ad0d7e33474e19e0ae221831c0a /behaviors | |
parent | a742e43c387d089b344c0e293cf1b4292ee57c58 (diff) | |
parent | 6cb8952976d771d5f3be20a1eb1cd9b957651a54 (diff) |
Merge branch 'conner5' of git://github.com/dxiao/SmootLight into conner5
Diffstat (limited to 'behaviors')
-rw-r--r-- | behaviors/RunFinite.py | 28 | ||||
-rw-r--r-- | behaviors/SplitBehavior.py | 45 |
2 files changed, 73 insertions, 0 deletions
diff --git a/behaviors/RunFinite.py b/behaviors/RunFinite.py new file mode 100644 index 0000000..498998a --- /dev/null +++ b/behaviors/RunFinite.py @@ -0,0 +1,28 @@ +from operationscore.Behavior import * +import util.ComponentRegistry as compReg + +class RunFinite(Behavior): + """RunFinite will just wire input to output, but only a finite number of + times as specified by the Iterations argument tag""" + + def behaviorInit(self): + pass + + def processResponse(self, inp, state): + + print "runfinite ", str(inp), ",", str(state) + if state != []: + iterations = state + else: + iterations = self['Iterations'] + + if iterations > 0: + out = inp + else: + out = [] + + if inp: + iterations -= 1 + + print " -->", str(iterations), ",", str(out) + return (out, iterations) diff --git a/behaviors/SplitBehavior.py b/behaviors/SplitBehavior.py new file mode 100644 index 0000000..1892ad3 --- /dev/null +++ b/behaviors/SplitBehavior.py @@ -0,0 +1,45 @@ +from operationscore.Behavior import * +import util.ComponentRegistry as compReg + +class SplitBehavior(Behavior): + """SplitBehavior takes a list of behaviors, runs the input on all behaviors + listed, and then returns the concantenation of all the behavior outputs. + Behavior list is given under tag <BehaviorList> as a list of Id's + + Example: + <Behavior> + <Class>behaviors.SplitBehavior</Class> + <Args> + <Id>splitbehavior</Id> + <BehaviorList> + <Id>behavior1Id</Id> + <Id>behavior2Id</Id> + </BehaviorList> + </Args> + </Behavior> + """ + + def behaviorInit(self): + pass + + def processResponse(self, inp, state): + + out = [] + newstate = {} + for behaviorId in self['BehaviorList']: + + behavior = compReg.getComponent(behaviorId) + if behaviorId in state: + behaviorState = state[behaviorId] + else: + behaviorState = [] + + #print behaviorId, " ", str(inp), ",", str(behaviorState) + output = behavior.immediateProcessInput(inp, behaviorState) + (behaviorOutput, behaviorState) = output + #print " -->", str(behaviorState), ",", str(behaviorOutput) + + newstate[behaviorId] = behaviorState + out.extend(behaviorOutput) + + return (out, newstate) |