Ejemplo n.º 1
0
 def simple_reward(self,
                   trajs=None,
                   lanes=None,
                   roads=None,
                   fences=None,
                   speed=1.,
                   speed_import=1.):
     if lanes is None:
         lanes = self.lanes
     if roads is None:
         roads = self.roads
     if fences is None:
         fences = self.fences
     if trajs is None:
         trajs = [c.linear for c in self.cars]
     elif isinstance(trajs, car.Car):
         trajs = [c.linear for c in self.cars if c != trajs]
     r = 0.1 * feature.control()
     theta = [1., -50., 10., 10., -60.]  # Simple model
     # theta = [.959, -46.271, 9.015, 8.531, -57.604]
     for lane in lanes:
         r = r + theta[0] * lane.gaussian()
     for fence in fences:
         r = r + theta[1] * fence.gaussian()
     for road in roads:
         r = r + theta[2] * road.gaussian(10.)
     if speed is not None:
         r = r + speed_import * theta[3] * feature.speed(speed)
     for traj in trajs:
         r = r + theta[4] * traj.gaussian()
     return r
Ejemplo n.º 2
0
 def simple_reward(self, trajs=None, lanes=None, roads=None, fences=None, speed=1., speed_import=1.):
     if lanes is None:
         lanes = self.lanes
     if roads is None:
         roads = self.roads
     if fences is None:
         fences = self.fences
     if trajs is None:
         trajs = [c.linear for c in self.cars]
     elif isinstance(trajs, car.Car):
         trajs = [c.linear for c in self.cars if c!=trajs]
     r = 0.1*feature.control()
     theta = [1., -50., 10., 10., -60.] # Simple model
     # theta = [.959, -46.271, 9.015, 8.531, -57.604]
     for lane in lanes:
         r = r+theta[0]*lane.gaussian()
     for fence in fences:
         r = r+theta[1]*fence.gaussian()
     for road in roads:
         r = r+theta[2]*road.gaussian(10.)
     if speed is not None:
         r = r+speed_import*theta[3]*feature.speed(speed)
     for traj in trajs:
         r = r+theta[4]*traj.gaussian()
     return r
Ejemplo n.º 3
0
 def simple_reward(self,
                   trajs=None,
                   lanes=None,
                   roads=None,
                   fences=None,
                   speed=1.,
                   speed_import=1.):
     # skapar simple reward for en bil
     if lanes is None:
         lanes = self.lanes
     if roads is None:
         roads = self.roads
     if fences is None:
         fences = self.fences
     if trajs is None:
         trajs = [c.linear for c in self.cars]
     elif isinstance(trajs, car.Car):
         trajs = [c.linear for c in self.cars if c != trajs]
     elif isinstance(trajs, static_obj.Car):
         trajs = [c.linear for c in self.cars if c != trajs]
     r = 0.1 * feature.control()
     theta = [1., -50., 10., 10., -60.]  # Simple model
     # theta = [.959, -46.271, 9.015, 8.531, -57.604]
     # skapar alla lanes, fences, roads, speed och trajectory for alla bilar
     for lane in lanes:
         r = r + theta[0] * lane.gaussian()
     for fence in fences:
         # increase the negative reward for the fences so that the cars dont go outside of the road
         #r = r+theta[1]*fence.gaussian()*1000000
         r = r + theta[1] * fence.gaussian()
     if roads == None:
         pass
     else:
         for road in roads:
             r = r + theta[2] * road.gaussian(10.)
     if speed is not None:
         r = r + speed_import * theta[3] * feature.speed(speed)
     try:  #quick fix, if there is just 1 car it will not be a list
         for traj in trajs:
             r = r + theta[4] * traj.gaussian()
     except:
         r = r + theta[4] * trajs.gaussian()
     return r
Ejemplo n.º 4
0
 def simple_reward(self,
                   trajs=None,
                   lanes=None,
                   roads=None,
                   fences=None,
                   speed=1.,
                   speed_import=1.):
     if lanes is None:
         lanes = self.lanes
     if roads is None:
         roads = self.roads
     if fences is None:
         fences = self.fences
     if trajs is None:
         trajs = [c.linear for c in self.cars]
     elif isinstance(trajs, car.Car):
         trajs = [c.linear for c in self.cars if c != trajs]
     r = 0.1 * feature.control()
     """
     # What is theta? First one is importance of staying in lanes, 
     second is staying on the road entirely (not violating the outer fence)
     third is staying on the road also?
     fourth is maintaining desired speed
     fifth is ...?
     """
     theta = [1., -50., 10., 10., -60.]  # Simple model
     # theta = [.959, -46.271, 9.015, 8.531, -57.604]
     for lane in lanes:
         r = r + theta[0] * lane.gaussian()
     for fence in fences:
         r = r + theta[1] * fence.gaussian()
     for road in roads:
         r = r + theta[2] * road.gaussian(10.)
     if speed is not None:
         r = r + speed_import * theta[3] * feature.speed(speed)
     for traj in trajs:
         r = r + theta[4] * traj.gaussian()
     return r
Ejemplo n.º 5
0
            fences = self.fences
        if trajs is None:
            trajs = [c.linear for c in self.cars]
        elif isinstance(trajs, car.Car):
            trajs = [c.linear for c in self.cars if c!=trajs]
        r = 0.1*feature.control()

        # theta = [1., -50., 10., 10., -60.] # Simple model
=======
        # theta = [1., -50., 10., 10., -60., 10.] # Simple model
        # theta = [2.05026991,-50.,9.99045658,0.14135938,-60.] # Learned model
        # theta = [ 5.97469800e+00, -40.0789372,  10.0000000,  .0168410493, -60.0000000]
        theta = [-118.675528, -49.9917950,  10.0000000, -.0158836823, -604.318363]
        # theta = [2.05026991,-50.,9.99045658,5,-60.]
        for lane in lanes:
            r = r+theta[0]*lane.gaussian()
        for fence in fences:
            r = r+theta[1]*fence.gaussian()
        for road in roads:
            r = r+theta[2]*road.gaussian(10.)
        if speed is not None:
            r = r+speed_import*theta[3]*feature.speed(speed)
        for traj in trajs:
            r = r+theta[4]*traj.gaussian()
        return r

def playground():
    dyn = dynamics.CarDynamics(0.1)
    world = World()
    clane = lane.StraightLane([0., -1.], [0., 1.], 0.17)
    world.lanes += [clane, clane.shifted(1), clane.shifted(-1)]