Exemplo n.º 1
0
    def Tkern(self, s):
        n, l, n_, l_ = self.n, self.l, self.n_, self.l_
        r = self.r
        rho = self.rho
        Ui = self.Ui
        Vi = self.Vi
        Ui_ = self.Ui_
        Vi_ = self.Vi_

        len_s = len(s)

        tstamp()
        U = np.tile(Ui, (len_s, 1))
        V = np.tile(Vi, (len_s, 1))
        U_ = np.tile(Ui_, (len_s, 1))
        V_ = np.tile(Vi_, (len_s, 1))
        #tstamp('Tiling in Tkerns ends')

        wig_calc = np.vectorize(fn.wig)

        ss, rr = np.meshgrid(s, r, indexing='ij')

        tstamp()
        T_s_r = (1-(-1)**(l_+l+ss))*fn.omega(l_,0)*fn.omega(l,0) \
            *wig_calc(l_,ss,l,-1,0,1)*(U_*V+V_*U-U_*U-0.5*V*V_*(l*(l+1) + \
            l_*(l_+1)-ss*(ss+1)))/rr
        #tstamp('Computing T_s_r ends')

        return T_s_r
Exemplo n.º 2
0
        gbest_tracker = 0  # tracker of num of iterations that the gbest value hasn't changed
        iteration_no = 0

        # =============================================================================
        # FULL PSO UPDATE
        #    while gbest stopping condition not met:
        #       if pbest value for any particle violates refreshing gap then update particle using PSO
        #       Update all particles using CLPS
        #       Perform local search on all particles
        #       Update and record results (increment gbest tracker, flag value update)
        #
        # =============================================================================
        start_timer = time.time()
        while gbest_tracker < sg:  #or (PSO_benchmark_NV==gbest_NV and PSO_benchmark_dist<=gbest_dist)==False or (best_benchmark_NV==gbest_NV and best_benchmark_dist<=gbest_dist)==False: #gbest_fitness>PSO_benchmark_val==True or gbest_fitness>best_benchmark_val==True:
            #        if gbest_tracker<sg:
            w = omega(w0, w1, gbest_tracker, max_gen)
            #            arr_pbest_particle = pbest_particle_pC_list(arr_pbest_results[:,fitness_col],M)
            arr_pbest_particle = pbest_particle_pC_list(M, denom, M_1)
            #            pbest_particle_position_list = pbest_particle_position_list[]

            ##            PSO
            if np.max(flag) >= rg:
                PSO_resultlist, flagged_indicies = PSO(
                    flag, rg, w, c, num_cores, num_customers_depot,
                    arr_distance_matrix, arr_customers, total_time,
                    total_capacity, gbest_position_list,
                    pbest_particle_position_list, pop_particle_position_list,
                    pop_particle_velocity_list)
                ##
                #route_routeList_list, particle_position, route_capacity_list, route_distance_list, route_time_list, total_distance, num_vehicles, particle_velocity
                flag, arr_results, arr_pbest_results, pop_particle_routeList_list, pop_particle_position_list, pop_particle_distance_list, pop_distance_list, pop_num_route_list, pop_particle_velocity_list, arr_gbest_result, gbest_velocity_list, gbest_position_list, gbest_routeList_list, gbest_distance_list, gbest_tracker, pbest_particle_routeList_list, pbest_particle_position_list, pbest_particle_distance_list, pbest_distance_list, pbest_num_route_list, pbest_particle_velocity_list = PSO_result_updater(