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

Source Code for Module factories

  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  import random 
 40   
 41  ######################################################################## 
 42  # This file contains factory functions that are used in main.py 
 43  # to allocate objects based on cmd line options 
 44  ######################################################################## 
 45   
 46   
 47  ################################################### 
 48  # AgentStrategy Factories. 
 49  # All should have an create(self, agentIndex) function 
 50  ################################################### 
 51  #TODO: We might need to send specific data do different strategies. 
 52  #      This can be done using the **args method. 
 53  #      However, we don't do it yet as it's just an experimental mode,  
 54  #      and anyway allocation method might be changed later 
 55   
 56  import agents 
 57  import state 
58 -class CirclingStrategyFactory:
59 - def create(self, agentIndex):
60 return agents.AgentCirclingStrategy(speed=agentIndex)
61
62 -class RRTStrategyFactory:
63 - def __init__(self, paths, rulesOfTheSea):
64 self.paths = paths 65 self.rulesOfTheSea = rulesOfTheSea
66
67 - def create(self, agentIndex):
68 agentPath = self.paths[agentIndex] # assuming path of length 2 69 return agents.AgentRRTStrategy(agentIndex, agentPath[0], agentPath[1], self.rulesOfTheSea)
70
71 -class PIDStrategyFactory:
72 - def __init__(self, rulesOfTheSea):
73 self.rulesOfTheSea = rulesOfTheSea
74
75 - def create(self, agentIndex):
76 return agents.AgentPIDStrategy(agentIndex, 77 (random.randint(0,1200), random.randint(0,600)), self.rulesOfTheSea)
78 79 #class MeasureEdgeLengthsFactory: 80 # def create(self, agentIndex): 81 # #TODO: this class is a hack, find better way to allocate and combine 82 # 83 # 84 # ############## goalPos=(random.randint(0,1200), random.randint(0,600)) 85 # goalPos=(1100, 300) 86 # 87 # 88 # 89 # agentStrategy = agents.AgentPIDStrategy(agentIndex, 90 # goalPos) 91 # return agents.MeasureEdgeLengths(agentIndex, goalPos, agentStrategy) 92 93
94 -class AgentStaticPatrolStrategyFactory:
95 - def __init__(self, paths, rulesOfTheSea):
96 self.paths = paths 97 self.rulesOfTheSea = rulesOfTheSea
98
99 - def create(self, agentIndex):
100 return agents.AgentStaticPatrolStrategy(agentIndex, self.paths[agentIndex], self.rulesOfTheSea)
101
102 -class AgentCoordinatedPatrolStrategyFactory:
103 - def __init__(self, patrolPoints, edgeLengths, rulesOfTheSea):
104 self.patrolPoints = patrolPoints 105 self.edgeLengths = edgeLengths 106 self.rulesOfTheSea = rulesOfTheSea
107
108 - def create(self, agentIndex):
109 return agents.AgentCoordinatedPatrolStrategy(agentIndex, self.patrolPoints, self.edgeLengths, self.rulesOfTheSea)
110
111 -class AgentJoiningPatrolStrategyFactory:
112 - def __init__(self, patrolPoints, edgeLengths, rulesOfTheSea):
113 self.patrolPoints = patrolPoints 114 self.edgeLengths = edgeLengths 115 self.rulesOfTheSea = rulesOfTheSea
116
117 - def create(self, agentIndex):
118 return agents.AgentJoiningPatrolStrategy(agentIndex, self.patrolPoints, self.edgeLengths, self.rulesOfTheSea)
119 120
121 -class AgentTrackingPatrolStrategyFactory:
122 - def __init__(self, trackedShipIndices, trackingShipIndices, trackingDistance, 123 positionOffsets, rulesOfTheSea):
124 self.trackedShipIndices = trackedShipIndices 125 self.trackingShipIndices = trackingShipIndices 126 self.trackingDistance = trackingDistance 127 self.positionOffsets = positionOffsets 128 self.rulesOfTheSea = rulesOfTheSea
129
130 - def create(self, agentIndex):
131 return agents.AgentTrackingPatrolStrategy(agentIndex, 132 self.trackedShipIndices, self.trackingShipIndices, 133 self.trackingDistance, self.positionOffsets, self.rulesOfTheSea)
134 135 # class AgentRandomPatrolStrategyFactory: 136 # def __init__(self, patrolArea, rulesOfTheSea): 137 # self.patrolArea = patrolArea 138 # self.rulesOfTheSea = rulesOfTheSea 139 # 140 # def create(self, agentIndex): 141 # return agents.AgentRandomPatrolStrategy(agentIndex, self.patrolArea, self.rulesOfTheSea) 142 143 144 145 ################################################### 146 # AgentWorldModel Factories. 147 # All should have an create(self) function 148 ################################################### 149 import agents
150 -class CompleteWorldModelFactory:
151 - def create(self, shipIndex):
152 return agents.AgentWorldModelCompleteWorld(shipIndex)
153 154 155 156 157 ################################################### 158 # Ship Factories. 159 # All should have an create(self) function 160 ################################################### 161 import shipModels
162 -class BasicShipFactory:
163 - def create(self):
164 return shipModels.Ship()
165