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

Source Code for Module factories

  1  ################################################################################## 
  2  # Copyright (c) 2011, 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, I don't do it yet as it's just an experimental mode,  
 54  #      and anyway allocation method might be changed later 
 55  import agents 
 56  import state 
57 -class CirclingStrategyFactory:
58 - def create(self, agentIndex):
59 return agents.AgentCirclingStrategy(speed=agentIndex)
60
61 -class RRTStrategyFactory:
62 - def __init__(self, paths, rulesOfTheSea):
63 self.paths = paths 64 self.rulesOfTheSea = rulesOfTheSea
65
66 - def create(self, agentIndex):
67 agentPath = self.paths[agentIndex] # assuming path of length 2 68 return agents.AgentRRTStrategy(agentIndex, agentPath[0], agentPath[1], self.rulesOfTheSea)
69
70 -class PIDStrategyFactory:
71 - def __init__(self, rulesOfTheSea):
72 self.rulesOfTheSea = rulesOfTheSea
73
74 - def create(self, agentIndex):
75 return agents.AgentPIDStrategy(agentIndex, 76 (random.randint(0,1200), random.randint(0,600)), self.rulesOfTheSea)
77
78 -class MeasureEdgeLengthsFactory:
79 - def create(self, agentIndex):
80 #TODO: this class is completely a hack, find better way to allocate and combine 81 82 83 ############## goalPos=(random.randint(0,1200), random.randint(0,600)) 84 goalPos=(1100, 300) 85 86 87 88 agentStrategy = agents.AgentPIDStrategy(agentIndex, 89 goalPos) 90 return agents.MeasureEdgeLengths(agentIndex, goalPos, agentStrategy)
91 92
93 -class AgentBasicPatrolStrategyFactory:
94 - def __init__(self, paths, rulesOfTheSea):
95 self.paths = paths 96 self.rulesOfTheSea = rulesOfTheSea
97
98 - def create(self, agentIndex):
99 return agents.AgentBasicPatrolStrategy(agentIndex, self.paths[agentIndex], self.rulesOfTheSea)
100 101 ################################################### 102 # AgentWorldModel Factories. 103 # All should have an create(self) function 104 ################################################### 105 import agents
106 -class CompleteWorldModelFactory:
107 - def create(self, shipIndex):
108 return agents.AgentWorldModelCompleteWorld(shipIndex)
109 110 111 112 113 ################################################### 114 # Ship Factories. 115 # All should have an create(self) function 116 ################################################### 117 import shipModels
118 -class BasicShipFactory:
119 - def create(self):
120 return shipModels.Ship()
121