PGA/route.py
def refresh_state(self, reset_window=True):
        """
        refresh state of this route, i.e. recalculate all punish, cost and other parameters
        if the sequence and punish parameter of this route hasn't been changed, this method shouldn't be called
        :param reset_window: if time window is reset to the last serve time after time window punish
        :return: None
        """
        self.start_time = depot_open_time
        self.cost = 0
        self.window_punish, self.capacity_punish, self.weight_punish, self.volume_punish = 0, 0, 0, 0
        self.capacity_remain = driving_range
        self.capacity_waste = 0
        self.served_w, self.served_v = 0, 0
        self.extra_t = 0
        self.travel_d = 0
        time = depot_open_time
        distance = 0
        capacity = driving_range
        weight, volume = max_weight, max_volume
        pre_node = center_id
        extra_time = []
        for node in self.sequence:
            d = self.g_map.get_distance(pre_node, node)
            t = self.g_map.get_time(pre_node, node)
            capacity -= d
            self.travel_d += d
            if node > custom_number:
                time += t + charge_tm
                distance += d
                self.cost += charge_cost + unit_trans_cost * d
                self.capacity_punish += self.punish * abs(capacity) / driving_range if capacity < 0 else 0
                self.capacity_waste = max(self.capacity_waste, capacity)
                capacity = driving_range  # recharge battery
            else:
                self.cost += unit_trans_cost * d  # regular cost
                time += t
                window = self.g_map.get_window(node)
                if time < window[0]:
                    self.cost += wait_cost * abs(window[0] - time)  # waiting cost
                    extra_time.append(window[1] - time)
                    time = window[0]
                elif time > window[1]:
                    self.window_punish += self.punish * abs(time - window[1])
                    time = window[1] if reset_window else time
                    extra_time.append(-1)
                else:
                    extra_time.append(window[1] - time)
                time += unload_time
                demand = self.g_map.get_demand(node)
                weight -= demand[0]
                volume -= demand[1]
                self.served_w += demand[0]
                self.served_v += demand[1]
                self.weight_punish += self.punish * abs(weight) if weight < 0 else 0
                self.volume_punish += self.punish * abs(volume) if volume < 0 else 0
                self.capacity_punish += self.punish * abs(capacity) / driving_range if capacity < 0 else 0
            pre_node = node
        d = self.g_map.get_distance(pre_node, center_id)
        t = self.g_map.get_time(pre_node, center_id)
        capacity -= d
        self.travel_d += d
        self.capacity_remain = capacity
        time += t
        self.cost += unit_trans_cost * d  # regular cost
        self.capacity_punish += self.punish * abs(capacity) / driving_range if capacity < 0 else 0
        if time > 24.:
            self.window_punish += self.punish * abs(time - 24.)
            extra_time.append(-1)
        else:
            extra_time.append(24. - time)
        self.extra_t = max(0, min(extra_time))
        self.cost -= len(extra_time) * self.extra_t * wait_cost  # reduce wait cost
        self.cost += self.window_punish + self.capacity_punish + self.weight_punish + self.volume_punish  # add punish
        self.start_time += self.extra_t

        refresh state of this route, i.e. recalculate all punish, cost and other parameters
        if the sequence and punish parameter of this route hasn't been changed, this method shouldn't be called
        :param reset_window: if time window is reset to the last serve time after time window punish
        :return: None
        
refresh state of this route, i.e. recalculate all punish, cost and other parameters
if the sequence and punish parameter of this route hasn't been changed, this method shouldn't be called
refresh state of this route i . e . recalculate all punish cost and other parameters if the sequence and punish parameter of this route hasn ' t been changed this method shouldn ' t be called
def refresh_state(self, reset_window=True):
        self.start_time = depot_open_time
        self.cost = 0
        self.window_punish, self.capacity_punish, self.weight_punish, self.volume_punish = 0, 0, 0, 0
        self.capacity_remain = driving_range
        self.capacity_waste = 0
        self.served_w, self.served_v = 0, 0
        self.extra_t = 0
        self.travel_d = 0
        time = depot_open_time
        distance = 0
        capacity = driving_range
        weight, volume = max_weight, max_volume
        pre_node = center_id
        extra_time = []
        for node in self.sequence:
            d = self.g_map.get_distance(pre_node, node)
            t = self.g_map.get_time(pre_node, node)
            capacity -= d
            self.travel_d += d
            if node > custom_number:
                time += t + charge_tm
                distance += d
                self.cost += charge_cost + unit_trans_cost * d
                self.capacity_punish += self.punish * abs(capacity) / driving_range if capacity < 0 else 0
                self.capacity_waste = max(self.capacity_waste, capacity)
                capacity = driving_range  
            else:
                self.cost += unit_trans_cost * d  
                time += t
                window = self.g_map.get_window(node)
                if time < window[0]:
                    self.cost += wait_cost * abs(window[0] - time)  
                    extra_time.append(window[1] - time)
                    time = window[0]
                elif time > window[1]:
                    self.window_punish += self.punish * abs(time - window[1])
                    time = window[1] if reset_window else time
                    extra_time.append(-1)
                else:
                    extra_time.append(window[1] - time)
                time += unload_time
                demand = self.g_map.get_demand(node)
                weight -= demand[0]
                volume -= demand[1]
                self.served_w += demand[0]
                self.served_v += demand[1]
                self.weight_punish += self.punish * abs(weight) if weight < 0 else 0
                self.volume_punish += self.punish * abs(volume) if volume < 0 else 0
                self.capacity_punish += self.punish * abs(capacity) / driving_range if capacity < 0 else 0
            pre_node = node
        d = self.g_map.get_distance(pre_node, center_id)
        t = self.g_map.get_time(pre_node, center_id)
        capacity -= d
        self.travel_d += d
        self.capacity_remain = capacity
        time += t
        self.cost += unit_trans_cost * d  
        self.capacity_punish += self.punish * abs(capacity) / driving_range if capacity < 0 else 0
        if time > 24.:
            self.window_punish += self.punish * abs(time - 24.)
            extra_time.append(-1)
        else:
            extra_time.append(24. - time)
        self.extra_t = max(0, min(extra_time))
        self.cost -= len(extra_time) * self.extra_t * wait_cost  
        self.cost += self.window_punish + self.capacity_punish + self.weight_punish + self.volume_punish  
        self.start_time += self.extra_t
def refresh_state ( self , reset_window = True ) : self . start_time = depot_open_time self . cost = 0 self . window_punish , self . capacity_punish , self . weight_punish , self . volume_punish = 0 , 0 , 0 , 0 self . capacity_remain = driving_range self . capacity_waste = 0 self . served_w , self . served_v = 0 , 0 self . extra_t = 0 self . travel_d = 0 time = depot_open_time distance = 0 capacity = driving_range weight , volume = max_weight , max_volume pre_node = center_id extra_time = [ ] for node in self . sequence : d = self . g_map . get_distance ( pre_node , node ) t = self . g_map . get_time ( pre_node , node ) capacity -= d self . travel_d += d if node > custom_number : time += t + charge_tm distance += d self . cost += charge_cost + unit_trans_cost * d self . capacity_punish += self . punish * abs ( capacity ) / driving_range if capacity < 0 else 0 self . capacity_waste = max ( self . capacity_waste , capacity ) capacity = driving_range else : self . cost += unit_trans_cost * d time += t window = self . g_map . get_window ( node ) if time < window [ 0 ] : self . cost += wait_cost * abs ( window [ 0 ] - time ) extra_time . append ( window [ 1 ] - time ) time = window [ 0 ] elif time > window [ 1 ] : self . window_punish += self . punish * abs ( time - window [ 1 ] ) time = window [ 1 ] if reset_window else time extra_time . append ( - 1 ) else : extra_time . append ( window [ 1 ] - time ) time += unload_time demand = self . g_map . get_demand ( node ) weight -= demand [ 0 ] volume -= demand [ 1 ] self . served_w += demand [ 0 ] self . served_v += demand [ 1 ] self . weight_punish += self . punish * abs ( weight ) if weight < 0 else 0 self . volume_punish += self . punish * abs ( volume ) if volume < 0 else 0 self . capacity_punish += self . punish * abs ( capacity ) / driving_range if capacity < 0 else 0 pre_node = node d = self . g_map . get_distance ( pre_node , center_id ) t = self . g_map . get_time ( pre_node , center_id ) capacity -= d self . travel_d += d self . capacity_remain = capacity time += t self . cost += unit_trans_cost * d self . capacity_punish += self . punish * abs ( capacity ) / driving_range if capacity < 0 else 0 if time > 24. : self . window_punish += self . punish * abs ( time - 24. ) extra_time . append ( - 1 ) else : extra_time . append ( 24. - time ) self . extra_t = max ( 0 , min ( extra_time ) ) self . cost -= len ( extra_time ) * self . extra_t * wait_cost self . cost += self . window_punish + self . capacity_punish + self . weight_punish + self . volume_punish self . start_time += self . extra_t
refresh state of this route, i.e.
refresh state of this route i . e .
"""
        refresh state of this route, i.e. recalculate all punish, cost and other parameters
        if the sequence and punish parameter of this route hasn't been changed, this method shouldn't be called
        :param reset_window: if time window is reset to the last serve time after time window punish
        :return: None
        """ # recharge battery # regular cost # waiting cost # regular cost # reduce wait cost # add punish
None
self
reset_window
if time window is reset to the last serve time after time window punish
if time window is reset to the last serve time after time window punish