def execute(self, action): #print('execute') run = Assembler(self.carID) self.output = run.getTensor() if self.output is None: term = True #print('is none') return self.getObservation(), term, 0 #20000 rew = Reward('ego', run.getTraffic(), self.output, run.getPrioritizedTraffic()) coll, term = rew.collision() if term is True: cost = coll return self.getObservation(), term, cost # over, term = rew.overtime() # if term is True: # cost = over # return self.getObservation(), term, cost traci.vehicle.setSpeedMode('ego', 0) num_vec = traci.vehicle.getIDList() for i in range(len(num_vec)): if num_vec[i] != 'ego': traci.vehicle.setLaneChangeMode(num_vec[i], 512) carID = 'ego' act = Action(carID) #print(action) if action == 0: act.decelerate() #print('dec') elif action == 1: act.accelerate() #print('acc') #elif action == 2: # act.emergency() else: act.remain() #print('rem') gap, term = rew.emergency_gap() #wary = rew.wary_before_intersection() #brake = rew.emergency_brake() #print(self.output[0:20]) #print(gap) cost = rew.optimum_speed_deviation() + gap #+ over traci.simulationStep() #print(self.getObservation()) #print(term) return self.getObservation(), term, cost
def execute(self, action): run = Assembler(self.carID) self.output = run.getTensor() #print(run.getTensor()) if self.output is None: term = True return self.getObservation(), term, 0 rew = Reward('ego', run.getTraffic(), self.output) coll, term = rew.collision() if term is True: cost = coll return self.getObservation(), term, cost traci.vehicle.setSpeedMode('ego', 0) num_vec = traci.vehicle.getIDList() for i in range(len(num_vec)): if num_vec[i] != 'ego': traci.vehicle.setLaneChangeMode(num_vec[i], 512) ### #if i % 2 == 0: #traci.vehicle.setSpeedMode(num_vec[i], 23) carID = 'ego' act = Action(carID) if action == 0: act.decelerate() # print('dec') elif action == 1: act.accelerate() # print('acc') else: act.remain() # print('rem') gap, term = rew.emergency_gap() wary = rew.wary_before_intersection() #win = rew.target() brake = rew.emergency_brake() cost = rew.optimum_speed_deviation() + brake + gap + wary traci.simulationStep() #print(self.output) return self.getObservation(), term, cost