Пример #1
0
def SW1(tasks, providers, capacity_unit, capacity_range): #simple greedy approach

    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
        W_requesters, req_threshold = auctioneer.WinningRequesterSelection(tasks)
        W_providers, pro_threshold = auctioneer.WinningProviderSelection(providers)

        #trimming process: make the # of selected requesters and providers equal
        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)

        #calculate the payment to providers which guarantees truthfulness of providers
        payment = auctioneer.WPS_payment(W_providers, pro_threshold) #unit payment
        payment = payment*task_size #effective payment

        #calculate the fee for requesters which guarantees their truthfulness
        fee = auctioneer.WRS_payment(W_requesters, req_threshold)

        #mere social welfare: simple summation of task values without considering task depreciation after deadline
        mere_SW = MereSW(W_requesters) - cost

        #expected social welfare: summation of task values considering task depreciation after deadline
        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) #without consideration to alpha, mu and preference

        end_time = time.process_time()

        running_time = end_time - start_time

        #budget balance check
        if pre_budget < 0: #budget balance not met. Note that we can only check the budget balance before providers' actual submission
            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])

    return np.array(result)
Пример #2
0
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 SW3(tasks, providers, capacity):

    start_time = time.process_time()
    #create profit matrix which would be input into hungarian algorithm
    '''THIS PROCESS CAN TAKE SIGNIFICANT AMOUNT OF TIME'''
    profit_matrix = CreateProfitMatrix(tasks, providers)

    #select the optimal requester-provider pairs which maximize the expected social welfare
    sorted_SW, requesters_idx, providers_idx = HungarianSelection(profit_matrix)

    #re-arrange requesters and providers
    sorted_requesters, sorted_providers = tasks[requesters_idx], providers[providers_idx]

    #create a platform
    auctioneer = Platform(capacity)

    #slice the winners according to platform capacity
    if len(requesters_idx) > capacity:
        req_threshold, pro_threshold = sorted_requesters[capacity], sorted_providers[capacity]
        W_requesters, W_providers = sorted_requesters[:capacity], sorted_providers[:capacity]

    elif len(requesters_idx) == capacity:
        req_threshold, pro_threshold = sorted_requesters[capacity-1], sorted_providers[capacity-1]
        W_requesters, W_providers = sorted_requesters[:capacity-1], sorted_providers[:capacity-1]

    else:
        req_threshold, pro_threshold = sorted_requesters[-1], sorted_providers[-1]
        W_requesters, W_providers = sorted_requesters[:-1], sorted_providers[:-1]


    #return the list of task size which will be used in the fee calculation
    task_size = TaskSizer(W_requesters)

    #return the cost incurred to providers
    cost = CostCalculator(W_providers, task_size)

    #calculate the payment to providers which guarantees truthfulness of providers
    payment = auctioneer.WPS_payment(W_providers, pro_threshold) #unit payment
    payment = payment*task_size #effective payment

    #calculate the fee for requesters which guarantees their truthfulness
    fee = auctioneer.WRS_payment(W_requesters, req_threshold)

    #mere social welfare: simple summation of task values without considering task depreciation after deadline
    mere_SW = MereSW(W_requesters) - cost

    #expected social welfare
    expected_SW = np.sum(sorted_SW[:len(W_requesters)])

    #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) #without consideration to alpha, mu and preference

    end_time = time.process_time()
    running_time = end_time - start_time

    #budget balance check
    if pre_budget < 0: #budget balance not met. Note that we can only check the budget balance before providers' actual submission
        return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, running_time] #return all zeros
    else: #budget balance met
        return [mere_SW, expected_SW, realized_SW, pre_budget, post_budget, payment.sum(), fee.sum(), changed_payment.sum(), changed_fee.sum(), cost, running_time]