本文整理汇总了Python中state.State.generateCars方法的典型用法代码示例。如果您正苦于以下问题:Python State.generateCars方法的具体用法?Python State.generateCars怎么用?Python State.generateCars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.generateCars方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: car
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import generateCars [as 别名]
class Supervisor:
# _map includes
# method for moving a car( e.g., map.moveCar(car, from, to) )
# _cars includes the cars and it type, priority and speed
def __init__(self, _numberOfCars,_mapWidth,_mapHeight,_AIName):
self.numberOfCars = _numberOfCars
self.state = State(_mapWidth, _mapHeight)
self.state.generateCars(_numberOfCars)
self.map = self.state.getMap()
self.cars = self.state.getCars()
# AI
self.ai = AI(_numberOfCars,_AIName)
# Initializing the remain moves of cars
self.carMovesRemain = []
for carID in range(numberOfCars):
self.carMovesRemain.append(self.cars[carID].speed)
# carList : a 'list' of 'car'
# car :
# car.type : 'vehicle', 'taxi', 'ambulance'
# car.location : (x,y)
# car.start : (x,y)
# car.destination : (x,y)
# car.priority : 'high', 'medium', 'low'
# car.speed : 1, 2, 3
#
# car.getNextLocation(gameState) : return next location of the car
def setAI(self,_AIName):
self.ai = AI(self.numberOfCars,_AIName)
def start(self):
# for car in cars:
# nextAction = AI.nextStep(car.id, state)
# state = state.getStateByAction(car.id, nextAction)
# Drawer.draw(state)
# Start
currCarIdx = 0
nextAction = AI.nextStep(currCarIdx, state)
state = state.getStateByAction(currCarIdx, nextAction)
Drawer.draw(state)
while(not state.isGoal()):
nextCarIdx = self.getNextCarIdx(currCarIdx)
nextAction = AI.nextStep(currCarIdx, state)
state = state.getStateByAction(currCarIdx, nextAction)
Drawer.draw(state)
def printArrivedRatio(self,_mState):
goal_counter = 0
for carID in range(self.numberOfCars):
if(_mState.isGoalState(carID)):
goal_counter = goal_counter+1
print 'Arrived Ratio : ',goal_counter , ' / ', self.numberOfCars
def isGoal(self,_mState):
goal_counter = 0
for carID in range(self.numberOfCars):
if(_mState.isGoalState(carID)):
goal_counter = goal_counter+1
#print goal_counter
if goal_counter == self.numberOfCars:
return True
else:
return False
def getNextCarIdx(self, currCarIdx):
if(self.carMovesRemain[currCarIdx] > 0):
nextCarIdx = currCarIdx
self.carMovesRemain[nextCarIdx] = (self.carMovesRemain[nextCarIdx]
- 1)
return nextCarIdx
else:
self.carMovesRemain[currCarIdx] = self.carList[currCarIdx].speed
nextCarIdx = (currCarIdx + 1) % len(self.carList)
self.carMovesRemain[nextCarIdx] = (self.carMovesRemain[nextCarIdx]
- 1)
return nextCarIdx
def getNextCarWithPriority():
pass
def showCarsInfo(self):
if(len(self.cars) > 0):
for car in self.cars:
print '---------------'
print 'ID: ', car.id_
print 'type: ', car.type_
print 'location: ', car.location
print 'start: ', car.start
#.........这里部分代码省略.........
示例2: State
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import generateCars [as 别名]
f=True
for (v,u) in Edic:
cap=0
for (p,e) in v.p:
if p!=u: cap=cap+e-len(Edic[(v,p)])
for (p,e) in u.p:
if p!=v: cap=cap+e-len(Edic[(u,p)])
if cap<=len(Edic[(v,u)]): f=False
return f
if __name__ == '__main__':
n_car=120
w=30; h=30
a = State(30,30)
ai = AI(n_car,"KGreedyAStar")
a.generateCars(n_car)
#a.printMap()
"""
for x in range(h):
for y in range(w):
if a.currentMap[x][y]==-2:
sys.stdout.write("\219\219")
elif a.currentMap[x][y]==-1:
sys.stdout.write(" ")
elif a.currentMap[x][y]>=0:
sys.stdout.write("OO")
#sys.stdout.write( "%2d"%(int(a.currentMap[x][y])) )
sys.stdout.write("\n")
"""
(G,Vdic) = MapToGraph(a.currentMap)