def run(text, nodes, repeat, steps): """ Runs the simulation and collects the nodes into a collector, a convenience class that can average the values that it collects. """ coll = util.Collector() for i in xrange(repeat): engine = Model(mode='async', text=text) engine.RULE_GETVALUE = new_getvalue # minimalist initial conditions, missing nodes set to false engine.initialize(missing=util.false) engine.iterate(steps=steps) coll.collect(states=engine.states, nodes=nodes) print '- completed' avgs = coll.get_averages(normalize=True) return avgs
def run( text, nodes, repeat, steps ): """ Runs the simulation and collects the nodes into a collector, a convenience class that can average the values that it collects. """ coll = util.Collector() for i in xrange( repeat ): engine = Model( mode='async', text=text ) engine.RULE_GETVALUE = new_getvalue # minimalist initial conditions, missing nodes set to false engine.initialize( missing=util.false ) engine.iterate( steps=steps) coll.collect( states=engine.states, nodes=nodes ) print '- completed' avgs = coll.get_averages( normalize=True ) return avgs
# pick at random from True, False and original value value = random.choice([True, False, value]) return util.default_set_value(state, name, value, p) def new_getvalue(state, name, p): """ Called every time a node value is used in an expression. It will override the value for the current step only. """ value = util.default_get_value(state, name, p) if name == 'B': # pick at random from True, False and original value return random.choice([True, False, value]) else: return value model = Model(mode='sync', text='demo-rules.txt') # assign the new rules to the engine model.RULE_SETVALUE = new_setvalue model.RULE_GETVALUE = new_getvalue model.initialize() model.iterate(steps=5) for state in model.states: print state
""" if name == 'A': # pick at random from True, False and original value value = random.choice( [True, False, value] ) return util.default_set_value( state, name, value, p ) def new_getvalue( state, name, p): """ Called every time a node value is used in an expression. It will override the value for the current step only. """ value = util.default_get_value( state, name, p ) if name == 'B': # pick at random from True, False and original value return random.choice( [True, False, value] ) else: return value model = Model( mode='sync', text='demo-rules.txt' ) # assign the new rules to the engine model.RULE_SETVALUE = new_setvalue model.RULE_GETVALUE = new_getvalue model.initialize() model.iterate( steps=5 ) for state in model.states: print(state)