def test_reset(self, pev, graph, CS_list):
        self.graph = graph
        self.path_info = []
        self.CS_list = CS_list
        self.pev = pev
        self.sim_time = self.pev.t_start
        self.timeIDX = int(self.sim_time / 5)
        self.path_info = ta.get_feature_state(self.sim_time, self.pev,
                                              self.CS_list, self.graph, NCS)
        self.pev.path.append(self.pev.curr_location)

        state = [
            self.pev.curr_location / self.graph.num_node,
            self.pev.destination / self.graph.num_node, self.pev.curr_SOC,
            self.sim_time / 288
        ]
        for path in self.path_info:
            cs, req_soc, driving_cost, fpath, rpath, fp_dist, rp_dist, fp_dt, rp_dt, fp_w, r_w, wtime, ctime, cs_char_cost, home_char_cost = path
            state += [
                wtime, ctime, driving_cost / 10, cs_char_cost / 10,
                home_char_cost / 10
            ]
        state = np.reshape(state, [1, self.state_size])

        return state, self.pev.source, self.pev.destination
    def reset(self):
        # self.graph.reset_traffic_info()
        self.CS_list = reset_CS_info(self.graph)
        t_start, soc = default_setting_random_value()
        self.graph.source_node_set = list(self.graph.source_node_set)
        source = self.graph.source_node_set[np.random.randint(
            0,
            len(self.graph.source_node_set) - 1)]
        self.graph.destination_node_set = list(self.graph.destination_node_set)
        destination = self.graph.destination_node_set[np.random.randint(
            0,
            len(self.graph.destination_node_set) - 1)]
        while source == destination or destination in self.graph.cs_info:
            destination = self.graph.destination_node_set[np.random.randint(
                0,
                len(self.graph.destination_node_set) - 1)]

        self.path_info = []
        self.pev = EV(e, t_start, soc, source, destination)
        self.pev.path.append(self.pev.curr_location)
        self.sim_time = self.pev.t_start
        self.timeIDX = int(self.sim_time / 5)
        self.path_info = ta.get_feature_state(self.sim_time, self.pev,
                                              self.CS_list, self.graph, NCS)

        # print('\npev soc', self.pev.SOC)
        state = [
            self.pev.curr_location / self.graph.num_node,
            self.pev.destination / self.graph.num_node, self.pev.curr_SOC,
            self.sim_time / 288
        ]
        for path in self.path_info:
            cs, req_soc, driving_cost, fpath, rpath, fp_dist, rp_dist, fp_dt, rp_dt, fp_w, r_w, wtime, ctime, cs_char_cost, home_char_cost = path
            state += [
                wtime, ctime, driving_cost / 10, cs_char_cost / 10,
                home_char_cost / 10
            ]

        state = np.reshape(state, [1, self.state_size])

        return state, source, destination
示例#3
0
    def step(self, action):
        cs, req_soc, driving_cost, fpath, rpath, fp_dist, rp_dist, fp_dt, rp_dt, fp_w, r_w, wtime, ctime, cs_char_cost, home_char_cost = self.path_info[
            action]
        self.pev.path.append(self.pev.curr_location)

        if len(fpath) > 1:
            next_node = fpath[1]
            chargingprice = cs.price[int(self.sim_time / 5)]
            distance_onetwo = self.graph.get_path_distance(fpath[0:2])
            velocity_onetwo = self.graph.velocity(fpath[0], fpath[1],
                                                  int(self.sim_time / 5))
            croad = self.pev.ECRate * distance_onetwo * chargingprice
            troad = UNITtimecost * distance_onetwo / velocity_onetwo
            road_cost = croad + troad

            self.sim_time, time = ta.update_ev(self.pev, self.graph,
                                               self.pev.curr_location,
                                               next_node, self.sim_time)
            if self.sim_time == 0 and time == 0:
                done = 1
                reward = -50
                return np.zeros((1, self.state_size)), -1, reward, done
            if self.pev.curr_SOC <= 0.0:
                done = 1
                reward = -50
                return np.zeros((1, self.state_size)), -1, reward, done

            done = 0
            reward = -1 * road_cost

            self.path_info = ta.get_feature_state(self.sim_time, self.pev,
                                                  self.CS_list, self.graph,
                                                  self.action_size)

            next_state = [
                self.pev.curr_location / self.graph.num_node,
                self.pev.destination / self.graph.num_node, self.pev.curr_SOC,
                self.sim_time / 288
            ]
            for path in self.path_info:
                cs, req_soc, driving_cost, fpath, rpath, fp_dist, rp_dist, fp_dt, rp_dt, fp_w, r_w, wtime, ctime, cs_char_cost, home_char_cost = path
                next_state += [
                    wtime, ctime, driving_cost / 10, cs_char_cost / 10,
                    home_char_cost / 10
                ]
            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.charged = 1
            self.pev.cs = cs
            self.pev.csid = cs.id
            self.pev.req_SOC = req_soc
            self.pev.rear_path = rpath

            self.pev.cssoc = self.pev.curr_SOC
            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.cschargingwaitingtime = cs.waittime[int(self.sim_time /
                                                             5)]
            self.pev.cschargingstarttime = self.sim_time + self.pev.cschargingwaitingtime * 60
            self.pev.cschargingprice = cs.price[int(
                self.pev.cschargingstarttime / 5)]
            self.pev.cschargingcost = self.pev.cscharingenergy * self.pev.cschargingprice

            self.pev.csdrivingtime = self.pev.totaldrivingtime
            self.pev.csdistance = self.pev.totaldrivingdistance
            self.pev.cschargingwaitingtime = self.pev.cschargingwaitingtime
            self.pev.cschargingtime = (
                self.pev.cscharingenergy /
                (cs.chargingpower * self.pev.charging_effi))

            self.pev.curr_SOC = self.pev.req_SOC
            self.sim_time += self.pev.cschargingwaitingtime * 60
            self.sim_time += self.pev.cschargingtime * 60

            self.pev.curr_time = self.sim_time

            rpath = self.pev.rear_path
            # print(rpath)
            for i in range(len(rpath) - 1):
                fnode = rpath[i]
                tnode = rpath[i + 1]
                # print(fnode, tnode, self.pev.curr_location)
                self.pev.path.append(tnode)
                self.sim_time, homedtime = ta.update_ev(
                    self.pev, self.graph, fnode, tnode, self.sim_time)
                self.pev.homedrivingtime += homedtime

            # print(self.pev.curr_location,self.pev.destination)
            if self.pev.curr_location == self.pev.destination:
                self.pev.homesoc = self.pev.curr_SOC
                self.pev.homechargingstarttime = self.sim_time
                self.pev.homechargingenergy = self.pev.maxBCAPA * self.pev.final_soc - self.pev.curr_SOC * self.pev.maxBCAPA
                self.pev.homechargingtime = (
                    self.pev.homechargingenergy /
                    (cs.homechargingpower * self.pev.charging_effi))
                self.pev.homedrivingdistance = self.graph.get_path_distance(
                    rpath)
                self.pev.homechargingprice = cs.TOU_price[int(self.sim_time /
                                                              60)]
                self.pev.homechargingcost = self.pev.homechargingenergy * self.pev.homechargingprice

                self.pev.curr_SOC = self.pev.final_soc
                self.sim_time += self.pev.homechargingtime
                self.pev.curr_time = self.sim_time

                self.pev.expense_time_part = (
                    self.pev.totaldrivingtime + self.pev.cschargingwaitingtime
                    + self.pev.cschargingtime) * UNITtimecost
                self.pev.expense_cost_part = self.pev.totaldrivingdistance * self.pev.ECRate * self.pev.cschargingprice + self.pev.cschargingcost + self.pev.homechargingcost

                self.pev.totalcost = self.pev.expense_time_part + self.pev.expense_cost_part

                done = 1
                # reward = -1 * ((self.pev.cschargingwaitingtime + self.pev.cschargingtime + rp_dt) * UNITtimecost + self.pev.homechargingcost)
                reward = -1 * self.pev.totalcost

            else:
                print('error final destination')
                input()

            return np.zeros((1, self.state_size)), -1, reward, done
        else:
            done = 1
            reward = -50
            return np.zeros((1, self.state_size)), -1, reward, done