def __init__(self, name, model): super().__init__(name, model) self.wealth = 1 self.location = () self.direction = model.random.rand() * (2 * np.pi) self.speed = 2 self.radius = 3 self.moveable = True self.shared_content = dict() # Defining the composite behavior explore = Explore('Explore') # Setup for the behavior explore.setup(0, self, None) # This behavior is just defined to check if the composite tree # can be combined with other primite behaviors is_carrying = IsCarrying('IsCarrying') is_carrying.setup(0, self, 'Food') seq = py_trees.composites.Sequence('Seq') seq.add_children([explore, is_carrying]) # Since its root is a sequence, we can use it directly self.behaviour_tree = py_trees.trees.BehaviourTree(seq)
def __init__(self, name, model): super().__init__(name, model) self.location = () self.direction = model.random.rand() * (2 * np.pi) # self.speed = 2 self.radius = 3 self.moveable = True self.shared_content = dict() root = py_trees.composites.Sequence("Sequence") # Sensing the environemnt to find object to carry lowest = NeighbourObjects('0') lowest.setup(0, self, 'Food') # First check if the item is carrable? carryable = IsCarryable('SC_IsCarryable_1') carryable.setup(0, self, 'Food') # Then check if the item can be carried by a single agent issinglecarry = IsSingleCarry('SC_IsSingleCarry_2') issinglecarry.setup(0, self, 'Food') # Finally, carry the object singlecarry = SingleCarry('SC_SingleCarry_3') singlecarry.setup(0, self, 'Food') # Define a sequence to combine the primitive behavior sc_sequence = py_trees.composites.Sequence('SC_SEQUENCE') sc_sequence.add_children([carryable, issinglecarry, singlecarry]) # Creating composite single carry object # singlecarry = CompositeSingleCarry('SingleCarry') # singlecarry.setup(0, self, 'Food') high = Explore('Explore') high.setup(0, self) root.add_children([lowest, sc_sequence, high]) self.behaviour_tree = py_trees.trees.BehaviourTree(root)
def __init__(self, name, model): super().__init__(name, model) self.location = () self.direction = model.random.rand() * (2 * np.pi) # self.speed = 2 self.radius = 3 self.moveable = True self.shared_content = dict() self.shared_content['Hub'] = {model.hub} self.shared_content['Sites'] = {model.site} # Drop branch dseq = py_trees.composites.Sequence('DSequence') iscarrying = IsInPartialAttached('8') iscarrying.setup(0, self, 'Food') # If near hub and carrying food with other agents drop neighhub = NeighbourObjects('2') neighhub.setup(0, self, 'Hub') drop = CompositeDropPartial('4') drop.setup(0, self, 'Food') dseq.add_children([neighhub, drop]) # Carry branch cseq = py_trees.composites.Sequence('CSequence') # neighsite = NeighbourObjects('5') # neighsite.setup(0, self, 'Sites') neighhub = py_trees.meta.inverter(NeighbourObjects)('40') neighhub.setup(0, self, 'Hub') neighfood = NeighbourObjects('50') neighfood.setup(0, self, 'Food') invcarrying = py_trees.meta.inverter(IsInPartialAttached)('8') invcarrying.setup(0, self, 'Food') carry = CompositeMultipleCarry('9') carry.setup(0, self, 'Food') # Move to hub hubseq = py_trees.composites.Sequence('HubSeq') # If carrying something to go to hub gotohub = MoveTowards('10') gotohub.setup(0, self, 'Hub') hubseq.add_children([iscarrying, gotohub]) cseq.add_children([neighhub, neighfood, carry, hubseq]) # Locomotion branch # Move to site siteseq = py_trees.composites.Sequence('SiteSeq') # If site already found and not carrying anything go to site sitefound = IsVisitedBefore('7') sitefound.setup(0, self, 'Sites') gotosite = MoveTowards('9') gotosite.setup(0, self, 'Sites') siteseq.add_children([sitefound, invcarrying, gotosite]) # Do Random walk explore = Explore('12') explore.setup(0, self) randwalk = py_trees.composites.Sequence('Randwalk') randwalk.add_children([explore]) # Try to got to site and hub if not explore locoselect = py_trees.composites.Selector('Move') locoselect.add_children([iscarrying, siteseq, explore]) # First try to drop then collect or explore select = py_trees.composites.Selector('Main') select.add_children([dseq, cseq, locoselect]) self.behaviour_tree = py_trees.trees.BehaviourTree(select)
def __init__(self, name, model, xmlstring=None): super().__init__(name, model) self.location = () self.direction = model.random.rand() * (2 * np.pi) self.speed = 2 self.radius = 3 self.moveable = True self.shared_content = dict() self.carryable = False # Define a BTContruct object self.bt = BTConstruct(None, self) class DummyIndividual: def __init__(self): self.phenotype = None dummyind = DummyIndividual() self.individual = [dummyind] self.individual[0].phenotype = xmlstring # self.bt.xmlstring = xmlstring # self.bt.construct() # Drop branch dseq = py_trees.composites.Sequence('DSequence') iscarrying = IsCarrying('IsCarrying_Food') iscarrying.setup(0, self, 'Food') neighhub = NeighbourObjects('NeighbourObjects_Hub') neighhub.setup(0, self, 'Hub') notneighhub = py_trees.meta.inverter(NeighbourObjects)( 'NeighbourObjects_Hub') notneighhub.setup(0, self, 'Hub') drop = CompositeDrop('CompositeDrop_Food') drop.setup(0, self, 'Food') dseq.add_children([neighhub, drop]) # Carry branch cseq = py_trees.composites.Sequence('CSequence') neighsite = NeighbourObjects('NeighbourObjects_Sites') neighsite.setup(0, self, 'Sites') neighfood = NeighbourObjects('NeighbourObjects_Food') neighfood.setup(0, self, 'Food') invcarrying = py_trees.meta.inverter(IsCarrying)('IsCarrying_Food') invcarrying.setup(0, self, 'Food') carry = CompositeSingleCarry('CompositeSingleCarry_Food') carry.setup(0, self, 'Food') cseq.add_children([neighsite, neighfood, invcarrying, carry]) # Locomotion branch # Move to site siteseq = py_trees.composites.Sequence('SiteSeq') sitefound = IsVisitedBefore('IsVisitedBefore_Sites') sitefound.setup(0, self, 'Sites') gotosite = MoveTowards('MoveTowards_Sites') gotosite.setup(0, self, 'Sites') siteseq.add_children([sitefound, invcarrying, gotosite]) # siteseq.add_children([invcarrying]) # Move to hub hubseq = py_trees.composites.Sequence('HubSeq') gotohub = MoveTowards('MoveTowards_Hub') gotohub.setup(0, self, 'Hub') hubseq.add_children([iscarrying, gotohub]) sitenotfound = py_trees.meta.inverter(IsVisitedBefore)( 'IsVisitedBefore_Sites') sitenotfound.setup(0, self, 'Sites') explore = Explore('Explore') explore.setup(0, self) randwalk = py_trees.composites.Sequence('Randwalk') randwalk.add_children([sitenotfound, explore]) locoselect = py_trees.composites.Selector('Move') # locoselect.add_children([siteseq, hubseq, explore]) locoselect.add_children([hubseq, randwalk]) select = py_trees.composites.Selector('Main') select.add_children([dseq, cseq, locoselect]) self.behaviour_tree = py_trees.trees.BehaviourTree(select) py_trees.display.render_dot_tree(self.behaviour_tree.root, name=model.pname + '/forgehc')
def __init__(self, name, model, xmlstring=None): super().__init__(name, model) self.location = () self.direction = model.random.rand() * (2 * np.pi) self.speed = 2 self.radius = 3 self.moveable = True self.shared_content = dict() self.carryable = False # Define a BTContruct object self.bt = BTConstruct(None, self) class DummyIndividual: def __init__(self): self.phenotype = None dummyind = DummyIndividual() self.individual = [dummyind] self.individual[0].phenotype = xmlstring # self.bt.xmlstring = xmlstring # self.bt.construct() # self.shared_content['Hub'] = {model.hub} # self.shared_content['Sites'] = {model.site} # Drop branch dseq = py_trees.composites.Sequence('DSequence') iscarrying = IsInPartialAttached('IsInPartialAttached_Food') iscarrying.setup(0, self, 'Food') # If near hub and carrying food with other agents drop neighhub = NeighbourObjects('NeighbourObjects_Hub') neighhub.setup(0, self, 'Hub') drop = CompositeDropPartial('CompositeDropPartial_Food') drop.setup(0, self, 'Food') dseq.add_children([neighhub, drop]) # Carry branch cseq = py_trees.composites.Sequence('CSequence') # neighsite = NeighbourObjects('5') # neighsite.setup(0, self, 'Sites') neighhub = py_trees.meta.inverter(NeighbourObjects)( 'NeighbourObjects_Hub') neighhub.setup(0, self, 'Hub') neighfood = NeighbourObjects('NeighbourObjects_Food') neighfood.setup(0, self, 'Food') invcarrying = py_trees.meta.inverter(IsInPartialAttached)( 'IsInPartialAttached_Food') invcarrying.setup(0, self, 'Food') carry = CompositeMultipleCarry('CompositeMultipleCarry_Food') carry.setup(0, self, 'Food') # Move to hub hubseq = py_trees.composites.Sequence('HubSeq') # If carrying something to go to hub gotohub = MoveTowards('MoveTowards_Hub') gotohub.setup(0, self, 'Hub') hubseq.add_children([iscarrying, gotohub]) cseq.add_children([neighhub, neighfood, carry, hubseq]) # Locomotion branch # Move to site siteseq = py_trees.composites.Sequence('SiteSeq') # If site already found and not carrying anything go to site sitefound = IsVisitedBefore('IsVisitedBefore_Sites') sitefound.setup(0, self, 'Sites') gotosite = MoveTowards('MoveTowards_Sites') gotosite.setup(0, self, 'Sites') siteseq.add_children([sitefound, invcarrying, gotosite]) # Do Random walk explore = Explore('Explore') explore.setup(0, self) randwalk = py_trees.composites.Sequence('Randwalk') randwalk.add_children([explore]) # Try to got to site and hub if not explore locoselect = py_trees.composites.Selector('Move') locoselect.add_children([iscarrying, siteseq, explore]) # First try to drop then collect or explore select = py_trees.composites.Selector('Main') select.add_children([dseq, cseq, locoselect]) self.behaviour_tree = py_trees.trees.BehaviourTree(select) py_trees.display.render_dot_tree(self.behaviour_tree.root, name=model.pname + '/cthc')
def __init__(self, name, model): super().__init__(name, model) self.location = () self.direction = model.random.rand() * (2 * np.pi) self.speed = 2 self.radius = 3 self.moveable = True self.shared_content = dict() self.shared_content['Hub'] = {model.hub} # Drop branch dseq = py_trees.composites.Sequence('DSequence') iscarrying = IsCarrying('1') iscarrying.setup(0, self, 'Food') neighhub = NeighbourObjects('2') neighhub.setup(0, self, 'Hub') drop = CompositeDrop('4') drop.setup(0, self, 'Food') dseq.add_children([neighhub, drop]) # Carry branch cseq = py_trees.composites.Sequence('CSequence') neighsite = NeighbourObjects('5') neighsite.setup(0, self, 'Sites') neighfood = NeighbourObjects('50') neighfood.setup(0, self, 'Food') invcarrying = py_trees.meta.inverter(IsCarrying)('8') invcarrying.setup(0, self, 'Food') carry = CompositeSingleCarry('6') carry.setup(0, self, 'Food') cseq.add_children([neighsite, neighfood, invcarrying, carry]) # Locomotion branch # Move to site siteseq = py_trees.composites.Sequence('SiteSeq') sitefound = IsVisitedBefore('7') sitefound.setup(0, self, 'Sites') gotosite = MoveTowards('9') gotosite.setup(0, self, 'Sites') siteseq.add_children([sitefound, invcarrying, gotosite]) # Move to hub hubseq = py_trees.composites.Sequence('HubSeq') gotohub = MoveTowards('10') gotohub.setup(0, self, 'Hub') hubseq.add_children([iscarrying, gotohub]) sitenotfound = py_trees.meta.inverter(IsVisitedBefore)('11') sitenotfound.setup(0, self, 'Sites') explore = Explore('12') explore.setup(0, self) randwalk = py_trees.composites.Sequence('Randwalk') randwalk.add_children([explore]) locoselect = py_trees.composites.Selector('Move') locoselect.add_children([siteseq, hubseq, explore]) select = py_trees.composites.Selector('Main') select.add_children([dseq, cseq, locoselect]) self.behaviour_tree = py_trees.trees.BehaviourTree(select)
def construct_bt(self): """Construct BT.""" # Get the phenotype of the genome and store as xmlstring # self.bt.xmlstring = self.xmlstring # Drop branch # Drop branch dseq = py_trees.composites.Sequence('DSequence') iscarrying = IsCarrying('IsCarrying_Debris') iscarrying.setup(0, self, 'Debris') neighhub = NeighbourObjects('NeighbourObjects') neighhub.setup(0, self, 'Obstacles') drop = CompositeDrop('CompositeDrop_Debris') drop.setup(0, self, 'Debris') dseq.add_children([neighhub, drop]) # Carry branch cseq = py_trees.composites.Sequence('CSequence') neighsite = py_trees.meta.inverter(NeighbourObjects)( 'NeighbourObjects') neighsite.setup(0, self, 'Obstacles') neighfood = NeighbourObjects('NeighbourObjects_Debris') neighfood.setup(0, self, 'Debris') invcarrying = py_trees.meta.inverter(IsCarrying)('IsCarrying_Debris') invcarrying.setup(0, self, 'Debris') carry = CompositeSingleCarry('CompositeSingleCarry_Debris') carry.setup(0, self, 'Debris') cseq.add_children([neighsite, neighfood, invcarrying, carry]) # Locomotion branch # Move to site siteseq = py_trees.composites.Sequence('SiteSeq') sitefound = IsVisitedBefore('IsVisitedBefore') sitefound.setup(0, self, 'Obstacles') gotosite = MoveTowards('MoveTowards') gotosite.setup(0, self, 'Obstacles') siteseq.add_children([sitefound, iscarrying, gotosite]) # Move to hub hubseq = py_trees.composites.Sequence('HubSeq') gotohub = MoveTowards('MoveTowards_Hub') gotohub.setup(0, self, 'Hub') hubseq.add_children([iscarrying, gotohub]) sitenotfound = py_trees.meta.inverter(IsVisitedBefore)( 'IsVisitedBefore') sitenotfound.setup(0, self, 'Obstacles') explore = Explore('Explore') explore.setup(0, self) randwalk = py_trees.composites.Sequence('Randwalk') randwalk.add_children([explore]) locoselect = py_trees.composites.Selector('Move') locoselect.add_children([siteseq, explore]) select = py_trees.composites.Selector('Main') select.add_children([dseq, cseq, locoselect]) self.behaviour_tree = py_trees.trees.BehaviourTree(select)
def construct_bt(self): """Construct BT.""" # Get the phenotype of the genome and store as xmlstring # self.bt.xmlstring = self.xmlstring # Drop branch dseq = py_trees.composites.Sequence('DSequence') iscarrying = IsInPartialAttached('IsInPartialAttached_Food') iscarrying.setup(0, self, 'Food') # If near hub and carrying food with other agents drop neighhub = NeighbourObjects('NeighbourObjects_Hub') neighhub.setup(0, self, 'Hub') drop = CompositeDropPartial('CompositeDropPartial_Food') drop.setup(0, self, 'Food') dseq.add_children([neighhub, drop]) # Carry branch cseq = py_trees.composites.Sequence('CSequence') # neighsite = NeighbourObjects('5') # neighsite.setup(0, self, 'Sites') neighhub = py_trees.meta.inverter(NeighbourObjects)( 'NeighbourObjects_Hub') neighhub.setup(0, self, 'Hub') neighfood = NeighbourObjects('NeighbourObjects_Food') neighfood.setup(0, self, 'Food') invcarrying = py_trees.meta.inverter(IsInPartialAttached)( 'IsInPartialAttached_Food') invcarrying.setup(0, self, 'Food') carry = CompositeMultipleCarry('CompositeMultipleCarry_Food') carry.setup(0, self, 'Food') # Move to hub hubseq = py_trees.composites.Sequence('HubSeq') # If carrying something to go to hub gotohub = MoveTowards('MoveTowards_Hub') gotohub.setup(0, self, 'Hub') hubseq.add_children([iscarrying, gotohub]) cseq.add_children([neighhub, neighfood, carry, hubseq]) # Locomotion branch # Move to site siteseq = py_trees.composites.Sequence('SiteSeq') # If site already found and not carrying anything go to site sitefound = IsVisitedBefore('IsVisitedBefore_Sites') sitefound.setup(0, self, 'Sites') gotosite = MoveTowards('MoveTowards_Sites') gotosite.setup(0, self, 'Sites') siteseq.add_children([sitefound, invcarrying, gotosite]) # Do Random walk explore = Explore('Explore') explore.setup(0, self) randwalk = py_trees.composites.Sequence('Randwalk') randwalk.add_children([explore]) # Try to got to site and hub if not explore locoselect = py_trees.composites.Selector('Move') locoselect.add_children([iscarrying, siteseq, explore]) # First try to drop then collect or explore select = py_trees.composites.Selector('Main') select.add_children([dseq, cseq, locoselect]) self.behaviour_tree = py_trees.trees.BehaviourTree(select)