def SW2(tasks, providers, capacity_unit, capacity_range, power4requester, power4provider): result = [] for idx in range(1, capacity_range + 1): #create an auctioneer capacity = capacity_unit*idx auctioneer = Platform(capacity) start_time = time.process_time() #winner selection process with consideration to alpha and mu W_requesters, req_threshold = auctioneer.New_WinningRequesterSelection(tasks, power4requester) W_providers, pro_threshold = auctioneer.New_WinningProviderSelection(providers, power4provider) #trimming process W_requesters, W_providers, req_threshold, pro_threshold = auctioneer.Trimming(W_requesters, W_providers, req_threshold, pro_threshold) #cost calculation task_size = TaskSizer(W_requesters) cost = CostCalculator(W_providers, task_size) #payment calculation payment = auctioneer.New_WPS_payment(W_providers, pro_threshold, power4provider) payment = payment*task_size #fee calculation fee = auctioneer.New_WRS_payment(W_requesters, req_threshold, power4requester) #mere social welfare mere_SW = MereSW(W_requesters) - cost #expected social welfare expected_SW = ExpectedSW(W_requesters, W_providers) - cost #actually realized social welfare realized_SW, t_sub = PostSW(W_requesters, W_providers) realized_SW = realized_SW - cost #budget balance check before submission pre_budget = BudgetBalanceCheck(fee, payment) #budget balance after submission changed_fee, changed_payment = TimeVariantMoney(t_sub, W_requesters, W_providers, fee, payment) post_budget = BudgetBalanceCheck(changed_fee, changed_payment) end_time = time.process_time() running_time = end_time - start_time #budget balance check if pre_budget < 0: #budget balance not met result.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, running_time]) #return all zeros else: #budget balance met result.append([mere_SW, expected_SW, realized_SW, pre_budget, post_budget, payment.sum(), fee.sum(), changed_payment.sum(), changed_fee.sum(), cost, running_time])#proposed heuristic approach return np.array(result)
def SW(time_unit, task_n, provider_n, max_value, max_deadline, max_alpha, max_task_size, max_provider_bid, max_provider_skill, max_mu, task_columns, provider_columns, iteration, capacity, output): #mere social welfare mere1 = [] mere2 = [] #expected social welfare expected1 = [] expected2 = [] expected3 = [] #real social welfare real1 = [] real2 = [] real3 = [] #budget before submission before1 = [] before2 = [] before3 = [] #budget after submission after1 = [] after2 = [] after3 = [] #payment before submission p_before1 = [] p_before2 = [] #fee before submission f_before1 = [] f_before2 = [] #payment after submission p_after1 = [] p_after2 = [] p_after3 = [] #fee after submission f_after1 = [] f_after2 = [] f_after3 = [] #cost cost1 = [] cost2 = [] for _ in range(iteration): #participants creation 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) #winner selection #without consideration to alpha and mu 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) c1 = cost_calculator(W_providers) c2 = cost_calculator(New_W_providers) #payment #temporary payment without consideration to alpha, mu payment1 = auctioneer.WPS_payment(W_providers, pro_threshold) #temporary fee fee1 = auctioneer.WRS_payment(W_requesters, req_threshold) #temporary payment with consideration to alpha, mu payment2 = auctioneer.New_WPS_payment(New_W_providers, New_pro_threshold) #temporary fee fee2 = auctioneer.New_WRS_payment(New_W_requesters, New_req_threshold) #1. preference ordering #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) New_r_pdf, New_r_cdf = bench_distribution(New_r_rank) New_p_pdf, New_p_cdf = bench_distribution(New_p_rank) #Run Stable Marriage Algorithm: In match, requester: keys, providers: values match = auctioneer.SMA(New_requester_preference_ordering, New_provider_preference_ordering) #mere social welfare--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- result = mere_social_welfare(W_requesters) #without consideration to alpha, mu result1 = mere_social_welfare(New_W_requesters) #with consideration to alpha, mu #print('mere social welfare 1: %f' %result) #print('mere social welfare 2: %f' %result1) #expected social welfare--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- social_welfare1 = SystemExpectedSocialwelfare(W_requesters, W_providers, time_unit) #without consideration to preference & alpha, mu social_welfare2 = SystemExpectedSocialwelfare(New_W_requesters, New_W_providers, time_unit) #with consideration to alpha, mu but without preference social_welfare3 = SocialWelfare(New_W_requesters, New_W_providers, time_unit, match) #With consideration to preference & alpha, mu #print('expected social welfare 1: %f' %social_welfare1) #print('expected social welfare 2: %f' %social_welfare2) #print('expected social welfare 3: %f' %social_welfare3) #print('D 1:%f' %(result-social_welfare1)) #print('D 2:%f' %(result1-social_welfare2)) #print('D 3:%f' %(result1-social_welfare3)) #real social welfare with submission time--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- post_social_welfare1, t_sub1 = Existing_SocialWelfare(W_requesters, W_providers, time_unit) #without consideration to preference, alpha, mu post_social_welfare2, t_sub2 = Existing_SocialWelfare(New_W_requesters, New_W_providers, time_unit) #with consideration to alpha, mu post_social_welfare3, t_sub3 = Proposed_SocialWelfare(New_W_requesters, New_W_providers, time_unit, match) #with consideration to preference & alpha, mu #print('real social welfare 1:%f' %post_social_welfare1) #print('real social welfare 2:%f' %post_social_welfare2) #print('real social welfare 3:%f' %post_social_welfare3) #difference between expected social welfare and real social welfare #print('difference 1: %f' %(social_welfare1-post_social_welfare1)) #print('difference 2: %f' %(social_welfare2-post_social_welfare2)) #print('difference 3: %f' %(social_welfare3-post_social_welfare3)) #budget balance check before submission--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- net_budget1 = budget_balance_check(fee1, payment1) #without consideration to alpha, mu net_budget2 = budget_balance_check(fee2, payment2) #with consideration to alpha, mu net_budget3 = budget_balance_check(fee2, payment2) #with consideration to alpha, mu and preference #print('budget before submission(without alpha, mu, preference): %f' %net_budget1) #print('budget before submission(with alpha and mu): %f' %net_budget2) #print('budget before submission(with alpha, mu and preference): %f' %net_budget3) #budget balance after submission--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- changed_fee1, changed_payment1 = bench_time_variant_money(t_sub1, W_requesters, W_providers, fee1, payment1, time_unit) changed_fee2, changed_payment2 = bench_time_variant_money(t_sub2, New_W_requesters, New_W_providers, fee2, payment2, time_unit) changed_fee3, changed_payment3 = time_variant_money(t_sub3, New_W_requesters, New_W_providers, fee2, payment2, match, time_unit) changed_budget1 = budget_balance_check(changed_fee1, changed_payment1) #without consideration to alpha, mu and preference changed_budget2 = budget_balance_check(changed_fee2, changed_payment2) #with consideration to alpha, mu changed_budget3 = budget_balance_check(changed_fee3, changed_payment3) #with consideration to alpha, mu and preference #print('budget after submission(without alpha,mu, preference): %f' %changed_budget1) #print('budget after submission(with alpha,mu): %f' %changed_budget2) #print('budget after submission(with alpha,mu, preference): %f' %changed_budget3) #print('iteration: %f, capacity: %f' %(it, unit*(ran+1))) #budget balance check if net_budget1 < 0: result = 0 social_welfare1 = 0 post_social_welfare1 = 0 net_budget1 = 0 changed_budget1 = 0 payment1 = 0 fee1 = 0 changed_payment1 = 0 changed_fee1 = 0 c1 = 0 if net_budget2 < 0: result1 = 0 social_welfare2 = 0; social_welfare3 = 0 post_social_welfare2 = 0; post_social_welfare3 = 0 net_budget2 = 0; net_budget3 = 0 changed_budget2 = 0; changed_budget3 = 0 payment2 = 0; fee2 = 0 changed_payment2 = 0; changed_payment3 = 0 changed_fee2 = 0; changed_fee3 = 0 c2 = 0 #mere social welfare mere1.append(result) mere2.append(result1) #expected social welfare expected1.append(social_welfare1) expected2.append(social_welfare2) expected3.append(social_welfare3) #real social welfare real1.append(post_social_welfare1) real2.append(post_social_welfare2) real3.append(post_social_welfare3) #budget before submission before1.append(net_budget1) before2.append(net_budget2) before3.append(net_budget3) #budget after submission after1.append(changed_budget1) after2.append(changed_budget2) after3.append(changed_budget3) #payment before submission p_before1.append(np.sum(payment1)) p_before2.append(np.sum(payment2)) #fee before submission f_before1.append(np.sum(fee1)) f_before2.append(np.sum(fee2)) #payment after submission p_after1.append(np.sum(changed_payment1)) p_after2.append(np.sum(changed_payment2)) p_after3.append(np.sum(changed_payment3)) #fee after submission f_after1.append(np.sum(changed_fee1)) f_after2.append(np.sum(changed_fee2)) f_after3.append(np.sum(changed_fee3)) #cost cost1.append(c1) cost2.append(c2) #mere social welfare mere1 = [x for x in mere1 if x != 0] mere2 = [x for x in mere2 if x != 0]# if len(mere2) == 0: mere2 = 0 #expected social welfare expected1 = [x for x in expected1 if x != 0] expected2 = [x for x in expected2 if x != 0]# expected3 = [x for x in expected3 if x != 0]# if len(expected2) == 0: expected2 = 0 if len(expected3) == 0: expected3 = 0 #real social welfare real1 = [x for x in real1 if x != 0] real2 = [x for x in real2 if x != 0]# real3 = [x for x in real3 if x != 0]# if len(real2) == 0: real2 = 0 if len(real3) == 0: real3 = 0 #budget before submission before1 = [x for x in before1 if x != 0] before2 = [x for x in before2 if x != 0]# before3 = [x for x in before3 if x != 0]# if len(before2) == 0: before2 = 0 if len(before3) == 0: before3 = 0 #budget after submission after1 = [x for x in after1 if x != 0] after2 = [x for x in after2 if x != 0]# after3 = [x for x in after3 if x != 0]# if len(after2) == 0: after2 = 0 if len(after3) == 0: after3 = 0 #payment before submission p_before1 = [x for x in p_before1 if x != 0] p_before2 = [x for x in p_before2 if x != 0]# if len(p_before2) == 0: p_before2 = 0 #fee before submission f_before1 = [x for x in f_before1 if x != 0] f_before2 = [x for x in f_before2 if x != 0]# if len(f_before2) == 0: f_before2 = 0 #payment after submission p_after1 = [x for x in p_after1 if x != 0] p_after2 = [x for x in p_after2 if x != 0]# p_after3 = [x for x in p_after3 if x != 0]# if len(p_after3) == 0: p_after3 = 0 if len(p_after2) == 0: p_after2 = 0 #fee after submission f_after1 = [x for x in f_after1 if x != 0] f_after2 = [x for x in f_after2 if x != 0]# f_after3 = [x for x in f_after3 if x != 0]# if len(f_after3) == 0: f_after3 = 0 if len(f_after2) == 0: f_after2 = 0 #cost cost1 = [x for x in cost1 if x != 0] cost2 = [x for x in cost2 if x != 0]# if len(cost2) == 0: cost2 = 0 #output.put((mere1,mere2,expected1,expected2,expected3,real1,real2,real3,before1,before2, before3, after1, after2, after3, p_before1, p_before2, f_before1, f_before2, p_after1, p_after2, p_after3, #f_after1, f_after2, f_after3, cost1, cost2)) output.put((np.mean(mere1), np.mean(mere2), np.mean(expected1), np.mean(expected2), np.mean(expected3), np.mean(real1), np.mean(real2), np.mean(real3), np.mean(before1), np.mean(before2), np.mean(before3), np.mean(after1), np.mean(after2), np.mean(after3), np.mean(p_before1), np.mean(p_before2), np.mean(f_before1), np.mean(f_before2), np.mean(p_after1), np.mean(p_after2), np.mean(p_after3), np.mean(f_after1), np.mean(f_after2), np.mean(f_after3), np.mean(cost1), np.mean(cost2)))
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))