该计划完成后,将旨在使用人工智能来获得最快的时间。汽车可以以恒定的速度加速、刹车或移动。在代码中会有一些部分(代表拐角),速度必须等于或低于某个特定的值(取决于拐角有多紧),我希望程序能够决定何时是加速、刹车和以恒定速度移动的最佳时刻。
使用python可以做到这一点吗?你能创建一个逐渐变得更好的神经网络吗?如果是这样,我该如何着手做这样的事情呢?
谢谢!
import time
x = 0
def TrackSimulation(distance, speed, acceleration, loopbreak, time1):
while loopbreak == 1:
if x == 1:
acceleration = 9
elif x == 2:
acceleration = -9
elif x == 0:
acceleration = 0
else:
print("Error")
if distance >= 0 and distance < 80:
speed = (speed) + ((acceleration) * 0.1)
distance = (distance) + ((speed) * 0.1)
time1 = time1 + 0.1
print((speed), " M/s")
print((distance), "M")
time.sleep(0.1)
elif distance >= 80 and distance <= 110:
if speed >= 30:
print("Too fast!")
loopbreak = 2
break
else:
print("You are in the speed checker")
speed = (speed) + ((acceleration) * 0.1)
distance = (distance) + ((speed) * 0.1)
time1 = time1 + 0.1
print((speed), " M/s")
print((distance), "M")
time.sleep(0.1)
elif distance >= 110 and distance < 200:
speed = (speed) + ((acceleration) * 0.1)
distance = (distance) + ((speed) * 0.1)
time1 = time1 + 0.1
print((speed), " M/s")
print((distance), "M")
time.sleep(0.1)
elif distance >= 200:
print("race over")
finaltime = round((time1), 3)
print("This was your time,", (finaltime))
loopbreak = 2
break发布于 2020-07-24 22:04:45
我建议看看强化学习是如何工作的。核心思想是这样的-
强化学习是关于在特定情况下采取适当的行动来最大化奖励。
例如,在你的例子中,你有这样的赛道,你需要建立一个算法,让汽车在最短的时间内到达目标。这意味着你需要训练一个强化学习模型,以最大限度地减少达到目标所需的时间。该模型将有一些输入参数,如速度,加速度,左转向,右转向,突破等。它将通过在此输入空间中随机采取行动,并试图在保持在轨道上并最小化所需时间的同时达到最终目标。
Open AI Gym在python中提供了一组优秀的工具,用于练习和学习Q学习等强化算法。它包含用python实现的各种游戏,允许您构建自己的模型,并尝试针对奖励来训练您的演员。检查在那里实现的这个car racing game。
这是一个关于强化学习的video,用来训练马里奥-卡丁车赢得比赛。
https://stackoverflow.com/questions/63056077
复制相似问题