def test_two_considerations_are_combined_as_expected(self): val_1 = 0.8 val_2 = 0.5 input_broker = MockInputBroker({ CONSIDERATION_1: 0.8, CONSIDERATION_2: 0.5, }) consideration_1 = Consideration( CONSIDERATION_1, curves.LinearCurve(x_offset=0.0, y_offset=0.0, slope=1.0), min_value=0.0, max_value=1.0, ) consideration_2 = Consideration( CONSIDERATION_2, curves.LinearCurve(x_offset=0.0, y_offset=0.0, slope=1.0), min_value=0.0, max_value=1.0, ) behavior = Behavior("test") behavior.considerations.append(consideration_1) behavior.considerations.append(consideration_2) f = behavior.get_compensation_factor() score = behavior.score(input_broker, Context) expected = (val_1 + val_1*f - val_1**2*f) * (val_2 + val_2*f - val_2**2*f) self.assertEqual(expected, score.final_score)
def behaviorSimple(): X, Y = np.mgrid[-100:100:40j, -100:100:40j] # Behavior 3 - patrol_circle # Behavior 1 - waypoint info1 = Behavior_info(f_type='waypoint', behavior_id='001', xa=40, ya=40, xb=0, yb=0, K=1, R=0, slowing_R=0, slowing_K=0, security='HIGH', effect_range=10) b1 = Behavior(info1) b1.projection = True U1, V1 = b1.get_field(X, Y, wind=78, theta=100) print b1.get_field(0, 0, wind=45, theta=100) plt.figure(1) plt.quiver(X, Y, U1, V1) plt.show()
def test_simple_linear_behavior_returns_input_value_as_score(self): val_1 = 0.8 input_broker = MockInputBroker({ CONSIDERATION_1: 0.8, }) consideration_1 = Consideration( CONSIDERATION_1, curves.LinearCurve(x_offset=0.0, y_offset=0.0, slope=1.0), min_value=0.0, max_value=1.0, ) behavior = Behavior("test") behavior.considerations.append(consideration_1) score = behavior.score(input_broker, Context) expected = val_1 self.assertEqual(expected, score.final_score)
def exec_scenario(scenario): #ヒアリング時のbehaviorの設定 #behav = Behavior("../dat/scene.csv") behav = Behavior(scenario) index = 0 #behaviorがあるまで実行 while (True): node = behav.get_node(index) if node is None: logging.info('end senario') break index = exec_behavior_node(node) if index == -1: logging.info('end senario') break
def __init__(self): """ init """ self.sensobs = [] self.add_sensob(Sensob(Ultrasonic())) self.add_sensob(Sensob(ReflectanceSensors())) self.add_sensob(Sensob(Camera())) self.motob = Motob() self.behaviors = [] self.add_behavior(Behavior(self, [10000, 10000, [10000, 10000, 10000]], "drive", 1)) self.add_behavior(Behavior(self, [30, 10000, [10000, 10000, 10000]], "stop", 3)) self.add_behavior(Behavior(self, [10000, 0.3, [10000, 10000, 10000]], "turnaround", 2)) self.add_behavior(Behavior(self, [10000, 10000, [210, 10000, 10000]], "turn_left", 5)) #self.add_behavior(Behavior(self, [10000, 10000, [10000, 200, 10000]], "turn_right", 4)) self.active_behaviors = [] self.arbitrator = Arbitrator()
def from_json(self, json): """Setups Config using JSON object. Returns self. """ config_json = json[ROOT_KEY][CONF_KEY] self.http_access_port = config_json[HTTP_ACCESS_PORT_KEY] self.dns_port = config_json[DNS_PORT_KEY] self.behaviors = [ Behavior().from_json(jsonBehavior) for jsonBehavior in config_json[BEHAVIORS_KEY] ] return self
def createDefaultVisibleBehaviorSet(self): ''' CREATE VISIBLE BEHAVIOR SET This func will create a set of visible output for HMM. :return: behav(list of obj) ''' # According to these sets, we instantiate a list of behavior obj. behav = [] i = 0 # for t in self.mDefaultTime: for l in self.mDefaultLocation: for m in self.mDefaultMotion: # for s in self.mDefaultSound behav.append( Behavior(motion=m, location=l # no = i, # sound = s )) i += 1 return behav
def __init__(self, myBBCON, priority): Behavior.__init__(self, myBBCON, priority)
import networkx as nx import behavior as be import events as ev import random as rdm import gathering as ga from behavior import Behavior from simulator import Simulator from node import Node from node import NodePrototype G=nx.DiGraph() G.add_path([0,1,2,3,4]) b = Behavior() #b.sendAfterReceive = True #b.includeBehavior = True #b.Process = be.BasicProcessing.UpdateAll() b.Route = be.BasicRouting.All() b.Select = be.BasicSelection.AllAtOnce(lambda:5) b.OnSignal = be.BasicSignaling.SendPeriodically(lambda:20) b.name = "first" p1 = NodePrototype() p1["health"] = 23 p1["money"] = 34 p1.DefineAttribute("love",45) p1.SetBehavior(b) p2 = NodePrototype()
def __init__(self, bbcon, priority): Behavior.__init__(self, bbcon, priority)
#!/usr/bin/env python import rospy from behavior import Behavior if __name__ == '__main__': # This is the main thread, thread #1 rospy.init_node('my_node') my_node = Behavior("b1") #my_node.loop() rospy.spin() # useless... since loop already blocks. If you have # no idle job (i.e. loop) to do outside event # handling, rospy.spin() is mandatory in order to # prevent from immediate termination of your node.
def __init__(self, manager): Behavior.__init__(self, manager)
def __init__(self, sensob, bbcon): Behavior.__init__(self, sensob, bbcon) self.weight = 0.1
#!/usr/bin/env python import rospy from behavior import Behavior if __name__ == '__main__': # This is the main thread, thread #1 rospy.init_node('my_node') my_node = Behavior("b2") #my_node.loop() rospy.spin() # useless... since loop already blocks. If you have # no idle job (i.e. loop) to do outside event # handling, rospy.spin() is mandatory in order to # prevent from immediate termination of your node.