def Plot_Social_Welfare(task_n, provider_n, max_value, max_alpha, max_deadline, max_task_size, max_mu, max_provider_bid, max_provider_skill, task_columns, provider_columns): tasks = TaskCreator(task_n, max_value, max_alpha, max_deadline, max_task_size) providers = ProviderCreator(provider_n, max_mu, max_provider_bid, max_provider_skill) pro_exp_social = [] exp_social = [] pro_real_social = [] real_social = [] for i in range(1,11): capacity = 20*i auctioneer = Platform(capacity) #platform에서 winners를 선택한다. W_requesters, req_threshold = auctioneer.WinningRequesterSelection(tasks) W_providers, pro_threshold = auctioneer.WinningProviderSelection(providers) #혹시 모르니깐 requesters와 providers의 숫자를 맞춘다. W_requesters, W_providers = auctioneer.Trimming(W_requesters, W_providers) #requesters와 providers의 preference ordering을 만든다. requester_preference_ordering = auctioneer.ordering_matrix(W_providers,provider_columns) provider_preference_ordering = auctioneer.ordering_matrix(W_requesters,task_columns) b_rank, b_mean_rank = benchmark_satisfaction_level(requester_preference_ordering) b_pdf, b_cdf = bench_distribution(b_rank) match = auctioneer.SMA(requester_preference_ordering, provider_preference_ordering) #In match, requester: keys, providers: values #expected social welfare comparison social_welfare = SocialWelfare(W_requesters, W_providers, 0.01, match) benchmark = SystemExpectedSocialwelfare(W_requesters, W_providers, 0.01) pro_exp_social.append(social_welfare) exp_social.append(benchmark) rank, mean_rank = auctioneer.satisfaction_level(match, requester_preference_ordering) pdf, cdf = auctioneer.satisfaction_distribution(rank) #real social welfare welfare, t_sub = Proposed_SocialWelfare(W_requesters, W_providers, 0.01, match) bench_welfare = Existing_SocialWelfare(W_requesters, W_providers, 0.01) pro_real_social.append(welfare) real_social.append(bench_welfare) x_axis = np.array(range(1,11))*20 bar_width = 10 fig, ax = plt.subplots(nrows = 1, ncols = 2) ax[0].bar(x_axis, pro_exp_social, width = bar_width, label = 'proposed exp.SW', color = 'b') ax[0].bar(x_axis+bar_width, exp_social, width = bar_width, label = 'benchmark exp.SW', color = 'r') ax[0].legend(loc = 'best') ax[1].bar(x_axis, pro_real_social, width = bar_width, label = 'proposed real.SW', color = 'b') ax[1].bar(x_axis+bar_width, real_social, width = bar_width, label = 'benchmark real.SW', color = 'r') ax[1].legend(loc = 'best') plt.show()
def preference_cdf(time_unit, task_n, provider_n, capacity, max_value, max_deadline, max_alpha, max_task_size, max_provider_bid, max_provider_skill, max_mu, task_columns, provider_columns, iteration, output): r_distribution1 = [] r_distribution2 = [] r_distribution3 = [] r_cumulative1 = [] r_cumulative2 = [] r_cumulative3 = [] p_distribution1 = [] p_distribution2 = [] p_distribution3 = [] p_cumulative1 = [] p_cumulative2 = [] p_cumulative3 = [] r_mean1=[] r_mean2=[] r_mean3=[] p_mean1=[] p_mean2=[] p_mean3=[] for _ in range(iteration): tasks = TaskCreator(task_n, max_value, max_alpha, max_deadline, max_task_size) providers = ProviderCreator(provider_n, max_mu, max_provider_bid, max_provider_skill) auctioneer = Platform(capacity) #without consideration to alpha and mu '''winner selection''' W_requesters, req_threshold = auctioneer.WinningRequesterSelection(tasks) W_providers, pro_threshold = auctioneer.WinningProviderSelection(providers) #with consideration to alpha and mu New_W_requesters, New_req_threshold = auctioneer.New_WinningRequesterSelection(tasks) New_W_providers, New_pro_threshold = auctioneer.New_WinningProviderSelection(providers) #trimming process W_requesters, W_providers = auctioneer.Trimming(W_requesters, W_providers) New_W_requesters, New_W_providers = auctioneer.Trimming(New_W_requesters, New_W_providers) #1. preference ordering #satisfaction level without consideration of preference, alpha and mu: 1 requester_preference_ordering = auctioneer.ordering_matrix(W_providers,provider_columns) provider_preference_ordering = auctioneer.ordering_matrix(W_requesters,task_columns) r_rank, r_mean_rank = benchmark_satisfaction_level(requester_preference_ordering) p_rank, p_mean_rank = benchmark_satisfaction_level(provider_preference_ordering) r_pdf1, r_cdf1 = bench_distribution(r_rank) p_pdf1, p_cdf1 = bench_distribution(p_rank) r_distribution1.append(r_pdf1) r_cumulative1.append(r_cdf1) p_distribution1.append(p_pdf1) p_cumulative1.append(p_cdf1) r_mean1.append(r_mean_rank) p_mean1.append(p_mean_rank) #satisfaction level without consideration of preference but with alpha, mu: 2 New_requester_preference_ordering = auctioneer.ordering_matrix(New_W_providers,provider_columns) New_provider_preference_ordering = auctioneer.ordering_matrix(New_W_requesters,task_columns) New_r_rank, New_r_mean_rank = benchmark_satisfaction_level(New_requester_preference_ordering) New_p_rank, New_p_mean_rank = benchmark_satisfaction_level(New_provider_preference_ordering) r_pdf2, r_cdf2 = bench_distribution(New_r_rank) p_pdf2, p_cdf2 = bench_distribution(New_p_rank) r_distribution2.append(r_pdf2) p_distribution2.append(p_pdf2) r_cumulative2.append(r_cdf2) p_cumulative2.append(p_cdf2) r_mean2.append(New_r_mean_rank) p_mean2.append(New_p_mean_rank) #Run Stable Marriage Algorithm: In match, requester: keys, providers: values match = auctioneer.SMA(New_requester_preference_ordering, New_provider_preference_ordering) #satisfaction with consideration to preference, alpha, mu:3 #requesters r_rank3, r_mean_rank3 = auctioneer.satisfaction_level(match, New_requester_preference_ordering) #providers p_rank3, p_mean_rank3 = auctioneer.satisfaction_level(match, New_provider_preference_ordering) r_pdf3, r_cdf3 = auctioneer.satisfaction_distribution(r_rank3) p_pdf3, p_cdf3 = auctioneer.satisfaction_distribution(p_rank3) r_distribution3.append(r_pdf3) p_distribution3.append(p_pdf3) r_cumulative3.append(r_cdf3) p_cumulative3.append(p_cdf3) r_mean3.append(r_mean_rank3) p_mean3.append(p_mean_rank3) r_distribution1 = np.array(r_distribution1).mean(axis = 0) r_distribution2 = np.array(r_distribution2).mean(axis = 0) r_distribution3 = np.array(r_distribution3).mean(axis = 0) r_cumulative1 = np.array(r_cumulative1).mean(axis = 0) r_cumulative2 = np.array(r_cumulative2).mean(axis = 0) r_cumulative3 = np.array(r_cumulative3).mean(axis = 0) p_distribution1 = np.array(p_distribution1).mean(axis = 0) p_distribution2 = np.array(p_distribution2).mean(axis = 0) p_distribution3 = np.array(p_distribution3).mean(axis = 0) p_cumulative1 = np.array(p_cumulative1).mean(axis = 0) p_cumulative2 = np.array(p_cumulative2).mean(axis = 0) p_cumulative3 = np.array(p_cumulative3).mean(axis = 0) r_mean1= np.array(r_mean1).mean() r_mean2= np.array(r_mean2).mean() r_mean3= np.array(r_mean3).mean() p_mean1= np.array(p_mean1).mean() p_mean2= np.array(p_mean2).mean() p_mean3= np.array(p_mean3).mean() output.put((r_distribution1, r_distribution2, r_distribution3, r_cumulative1, r_cumulative2, r_cumulative3, p_distribution1, p_distribution2, p_distribution3, p_cumulative1, p_cumulative2, p_cumulative3, r_mean1, r_mean2, r_mean3, p_mean1, p_mean2, p_mean3))