def testSimple(): #Sometimes this backtracks global g g = NumboGraph(numble=Numble([1, 1, 1], 3)) pg(g) g.do_timestep() print() pg(g)
def get_actions_from_graph(self): '''Polls all the ActiveNodes for Actions and chooses which to do on this timestep.''' active_nodes = self.get_active_nodes() if (self.max_active_nodes is not None and len(active_nodes) > self.max_active_nodes ): active_nodes = self.choose_active_nodes(active_nodes) if ( ShowActiveNodes.is_logging() or ShowActionList.is_logging() or ShowActionsChosen.is_logging() ): print(f'{chr(10)}t={self.graph["t"]}') if ShowActiveNodes.is_logging(): print('ACTIVE NODES') pg(self, active_nodes) actions = self.collect_actions(active_nodes) if ShowActionList.is_logging(): print('ACTIONS COLLECTED') self.print_actions(actions) # Filter out actions whose weight is below their threshold #actions = [a for a in actions if a.weight(self) >= a.threshold] actions = [a for a in actions if self.urgency(a) > 0.0] if len(actions) == 0: self.consecutive_timesteps_with_no_action += 1 #HACK Crude boosting of random nodes to shake things up if self.consecutive_timesteps_with_no_action > 10: ns = list(self.nodes) for i in range(10): nodeid = choice(ns) #print('GROSS', self.nodestr(nodeid)) self.gross_boost_salience(nodeid) else: self.consecutive_timesteps_with_no_action = 0 chosen_actions = self.choose_actions(actions) if ShowActionsChosen.is_logging(): print('ACTIONS CHOSEN') self.print_actions(chosen_actions) return chosen_actions
def in_progress(seed=None, num_timesteps=None, watchers=default_watchers + [ EquationResultWatcher([2, 3], Times, 6), EquationResultWatcher([1, 1], Plus, 2), EquationResultWatcher([1, 1, 1], Plus, 3), EquationResultWatcher([1, 2], Plus, 3) ]): '''This runs whatever I'm working on right now. --BEN''' global g g = NumboGraph(numble=Numble([1, 1, 1, 1, 1], 6), seed=seed, num_timesteps=num_timesteps, watchers=watchers) two = g.make_node(Block(2)) #g.add_tag(Seek, two) three = g.make_node(Block(3)) #g.add_tag(Seek, three) pg(g) g.run()
# test at the end to appropriate source files. from equation import EquationWatcher from PortGraph import PortGraph, pg from numbonodes import * def make_numble(g, bricks, target): '''Makes a Workspace node containing numble and returns the Workspace's node id.''' ws = g.make_node(Workspace) for brick in bricks: brick_id = g.make_node(Brick(brick)) g.add_member_edge(ws, brick_id) target_id = g.make_node(Target(target)) g.add_member_edge(ws, target_id) return ws if __name__ == '__main__': g = PortGraph() ws = g.members_to_subgraph(make_numble(g, [1, 1], 2)) eqn = make_equation(g, [1, 1], Plus, 2) pg(g) print() watcher = EquationWatcher(g, eqn['equation_id']) saw = watcher.look(ws) saw[0].go(g) pg(g)
def close(): global g g = NumboGraph(numble=Numble([120, 1, 2, 3, 4, 5], 121)) pg(g) g.run()
def testInstantSuccess(): g = NumboGraph(watchers=[WantedWatcher()], numble=Numble([1, 3, 1], 3)) pg(g) g.do_timestep() print() pg(g)