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
예제 #2
0
    def execute(self, action):
        #traci.vehicle.setSpeedMode('ego', 0)
        #print(action)
        run = Assembler(self.carID)

        # self.output = tensor.executeTensor()
        self.output = run.getTensor()
        # print(self.output)
        if self.output is None:
            term = True
            return self.getObservation(), term, 0
        # rew = Reward('ego', self.output)
        rew = Reward('ego')

        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)
        # print(action)
        carID = 'ego'
        act = Action(carID)
        if action == 0:
            pass
            #act.decelerate()
            #print('dec')
        elif action == 1:
            pass
            #act.accelerate()
            #print('acc')
        else:
            pass
            #act.remain()
            #print('rem')
        traci.simulationStep()

        #net = sumolib.net.readNet('huge_crossing/huge_crossing.net.xml')
        #tensor = Tensor('ego', net, self.conflictory_list[0], self.connection_list[0])
        #self.output = tensor.executeTensor()
        #rew = Reward('ego', self.output)

        win = rew.target()
        cost = rew.optimum_speed_deviation() + win
        # + brake
        traci.simulationStep()

        return self.getObservation(), term, cost
예제 #3
0
    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
    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
        else:
            self.co2.append(traci.vehicle.getFuelConsumption(self.carID))

        rew = Reward('ego', run.getTraffic(), self.output,
                     run.getPrioritizedTraffic())

        coll, term = rew.collision_test()
        if term is True:
            self.setCollisionCounter()
            cost = coll
            return self.getObservation(), term, cost

        traci.vehicle.setSpeedMode('ego', 0)
        num_vec = traci.vehicle.getIDList()
        disruption = []
        for i in range(len(num_vec)):
            if num_vec[i] != 'ego':
                if traci.vehicle.getAcceleration(num_vec[i]) < 0:
                    disruption.append(traci.vehicle.getAcceleration(
                        num_vec[i]))

                traci.vehicle.setLaneChangeMode(num_vec[i], 512)

        self.disruptionIntensity.append(sum(disruption))
        ###
        #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')
        #elif action == 2:
        #   print('eme')
        #  act.emergency()
        else:
            act.remain()
            #print('rem')
        #print(traci.vehicle.getSpeed(self.carID))
        #gap, term = rew.emergency_gap_test()
        #wary = rew.wary_before_intersection()

        #win = rew.target()
        #brake = rew.emergency_brake()
        cost = rew.optimum_speed_deviation()  #+ gap #+ brake # #+ wary
        traci.simulationStep()
        #print(self.output)
        self.terminationTime.append(traci.simulation.getCurrentTime())
        #print(traci.simulation.getCurrentTime())

        return self.getObservation(), term, cost