Module messages
[hide private]
[frames] | no frames]

Source Code for Module messages

  1  ################################################################################## 
  2  # Copyright (c) 2010, 2011, 2012, 2013, Daniel Urieli, Peter Stone 
  3  # University of Texas at Austin 
  4  # All right reserved 
  5  #  
  6  # Based On: 
  7  #  
  8  # Copyright (c) 2000-2003, Jelle Kok, University of Amsterdam 
  9  # All rights reserved. 
 10  #  
 11  # Redistribution and use in source and binary forms, with or without 
 12  # modification, are permitted provided that the following conditions are met: 
 13  #  
 14  # 1. Redistributions of source code must retain the above copyright notice, this 
 15  # list of conditions and the following disclaimer. 
 16  #  
 17  # 2. Redistributions in binary form must reproduce the above copyright notice, 
 18  # this list of conditions and the following disclaimer in the documentation 
 19  # and/or other materials provided with the distribution. 
 20  #  
 21  # 3. Neither the name of the University of Amsterdam nor the names of its 
 22  # contributors may be used to endorse or promote products derived from this 
 23  # software without specific prior written permission. 
 24  #  
 25  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 26  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 27  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 28  # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
 29  # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 30  # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 31  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 32  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 33  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 34  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 35  ################################################################################## 
 36   
 37   
 38   
 39   
40 -class PrimitiveMessage:
41 """ 42 A primitive message that is send from an agent to 43 other agent / other agents / the simulation environment. 44 """ 45 46 # message types 47 TYPE_VISIT = 'MSG_TYPE_VISIT' 48 TYPE_EDGE_LENGTH = 'MSG_TYPE_EDGE_LENGTH' 49 TYPE_START_PATROL = 'MSG_TYPE_START_PATROL' 50 TYPE_POSITION = 'MSG_TYPE_POSITION' 51 TYPE_PATROL_DIVISION = 'MSG_TYPE_PATROL_DIVISION' 52 TYPE_REACHED_START = 'MSG_TYPE_REACHED_START' 53 TYPE_TRACKING_POINT = 'MSG_TYPE_TRACKING_POINT' 54 TYPE_NAVIGATION_CENTRAL_POINT = 'MSG_TYPE_NAVIGATION_CENTRAL_POINT' 55 TYPE_POSITIONS_ASSIGNMENT = 'MSG_TYPE_POSITIONS_ASSIGNMENT' 56 57 # receiver options 58 TO_SIMULATOR = -1 59 TO_ALL = -2 60 # SUBSET_OF_AGENTS # TODO - need to add support for that 61
62 - def __init__(self, to, type, content):
63 self.to = to 64 self.type = type 65 self.content = content
66
67 - def __str__(self):
68 res = "PrimitiveMessage:" 69 res += " to=" + str(self.to) 70 res += " type=" + str(self.type) 71 res += " content=" + str(self.content) 72 res += "\n" 73 return res
74 75
76 -class CompositeMessage:
77 """ 78 Class for general Message that is created by an agent. 79 A CompositeMessage is just a (possibly empty) list of PrimitiveMessage. 80 """
81 - def __init__(self):
82 self.primitiveMsgs = []
83
84 - def __str__(self):
85 res = "\nCompositeMessage:\n" 86 for a in self.primitiveMsgs: 87 res += str(a) 88 res += "\n" 89 return res
90 91
92 - def appendMsg(self, msg):
93 """ 94 Adding a primitive message to the list of outgoing messages. 95 96 @type msg: PrimitiveMessage 97 @param msg: the message to be added to the list 98 """ 99 self.primitiveMsgs.append(msg)
100