コード例 #1
0
    def test_reset(self, pev, CS_list):

        self.path_info = []
        self.CS_list = CS_list
        self.pev = pev
        self.sim_time = self.pev.t_start
        self.path_info = rt.sim_main_first_time_check(self.pev, self.CS_list,
                                                      self.graph,
                                                      self.action_size)

        state = [self.pev.source, self.pev.curr_SOC]
        for path in self.path_info:
            cs, pev_SOC, front_path, total_d_time, waiting_time, charging_time = path
            state += [total_d_time, waiting_time, charging_time]
        state = np.reshape(state, [1, self.state_size])

        return state, source, destination
コード例 #2
0
    def reset(self):

        t_start = np.random.uniform(0, 1200)
        soc = np.random.uniform(0.3, 0.5)
        while soc <= 0.0 or soc > 1.0:
            soc = np.random.uniform(0.3, 0.5)
        self.graph.source_node_set = list(self.graph.source_node_set)
        self.graph.destination_node_set = list(self.graph.destination_node_set)

        source = self.graph.source_node_set[np.random.random_integers(
            0,
            len(self.graph.source_node_set) - 1)]
        while source in self.graph.cs_info.keys():
            source = self.graph.source_node_set[np.random.random_integers(
                0,
                len(self.graph.source_node_set) - 1)]

        destination = self.graph.source_node_set[np.random.random_integers(
            0,
            len(self.graph.source_node_set) - 1)]
        while destination in self.graph.cs_info.keys():
            destination = self.graph.source_node_set[np.random.random_integers(
                0,
                len(self.graph.source_node_set) - 1)]

        self.path_info = []
        self.pev = EV(e, t_start, soc, source, destination)
        self.sim_time = self.pev.t_start
        self.path_info = rt.sim_main_first_time_check(self.pev, self.CS_list,
                                                      self.graph,
                                                      self.action_size)

        # print('\npev soc', self.pev.SOC)
        state = [self.pev.source, self.pev.SOC]
        for path in self.path_info:
            cs, pev_SOC, front_path, total_d_time, waiting_time, charging_time = path
            state += [total_d_time, waiting_time, charging_time]
        state = np.reshape(state, [1, self.state_size])

        return state, source, destination
コード例 #3
0
    def step(self, action, done):

        cs, pev_SOC, front_path, total_d_time, waiting_time, charging_time = self.path_info[
            action]
        # print(self.sim_time, self.pev.curr_location, cs.id, pev_SOC)
        self.target = cs

        if pev_SOC <= 0.0:
            print('error soc', pev_SOC)
            done = 1
            reward = -5
            return np.zeros((1, self.state_size)), -1, reward, done

        if len(front_path) > 1:
            next_node = front_path[1]
            self.sim_time, time = rt.update_ev(self.pev, self.graph,
                                               self.pev.curr_location,
                                               next_node, self.sim_time)
            if self.sim_time == 0 and time == 0:
                print('time idx error')
                done = 1
                reward = -5
                return np.zeros((1, self.state_size)), -1, reward, done
            done = 0
            reward = -1 * (time)
            self.pev.curr_location = next_node
            self.path_info = rt.sim_main_first_time_check(
                self.pev, self.CS_list, self.graph, self.action_size)
            next_state = [self.pev.curr_location, self.pev.curr_SOC]

            for path in self.path_info:
                cs, pev_SOC, front_path, total_d_time, waiting_time, charging_time = path
                next_state += [total_d_time, waiting_time, charging_time]
            next_state = np.reshape(next_state, [1, self.state_size])

            return next_state, next_node, reward, done

        elif self.pev.curr_location == cs.id:

            self.pev.before_charging_SOC = self.pev.curr_SOC
            self.pev.cscharingenergy = self.pev.maxBCAPA * self.pev.req_SOC - self.pev.curr_SOC * self.pev.maxBCAPA
            self.pev.cschargingcost = self.pev.cscharingenergy * cs.price[int(
                self.sim_time / 5)]
            self.pev.curr_SOC = self.pev.req_SOC
            self.pev.cschargingtime = charging_time

            self.pev.cschargingwaitingtime = waiting_time
            self.pev.charged = 1
            self.pev.cs = cs

            self.sim_time += charging_time * 60
            self.sim_time += waiting_time * 60
            # print(waiting_time, waiting_time * 60)

            self.pev.csdrivingtime = self.pev.totaldrivingtime
            self.pev.csdistance = self.pev.totaldrivingdistance
            self.pev.cschargingwaitingtime = self.pev.cschargingwaitingtime
            self.pev.cschargingtime = self.pev.cschargingtime
            self.pev.cssoc = self.pev.curr_SOC

            done = 1
            reward = -1 * (waiting_time + charging_time)
            print(done, '충전소야')

            return np.zeros((1, self.state_size)), -1, reward, done
        else:
            print("???")
            input()