diff options
-rw-r--r-- | brandt.c | 41 | ||||
-rw-r--r-- | test_brandt.c | 26 |
2 files changed, 66 insertions, 1 deletions
@@ -67,6 +67,31 @@ BRANDT_bidder_start (struct BRANDT_Auction *auction, | |||
67 | atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; | 67 | atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; |
68 | outcome = auction->outcome_public ? outcome_public : outcome_private; | 68 | outcome = auction->outcome_public ? outcome_public : outcome_private; |
69 | 69 | ||
70 | if (auction_mPlusFirstPrice == atype && n <= auction->m) | ||
71 | { /* fewer bidders than items to sell. every bidder won with lowest price */ | ||
72 | struct BRANDT_Result *res; | ||
73 | if (auction->outcome_public) | ||
74 | { | ||
75 | res = GNUNET_new_array (n, struct BRANDT_Result); | ||
76 | for (uint16_t h = 0; h < n; h++) | ||
77 | { | ||
78 | res[h].bidder = h; | ||
79 | res[h].price = 0; | ||
80 | res[h].status = BRANDT_bidder_won; | ||
81 | } | ||
82 | auction->result (auction->closure, res, n); | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | res = GNUNET_new (struct BRANDT_Result); | ||
87 | res->bidder = i; | ||
88 | res->price = 0; | ||
89 | res->status = BRANDT_bidder_won; | ||
90 | auction->result (auction->closure, res, 1); | ||
91 | } | ||
92 | return; | ||
93 | } | ||
94 | |||
70 | /* On M+1st price auctions we multiply the amount of prizes by the amount of | 95 | /* On M+1st price auctions we multiply the amount of prizes by the amount of |
71 | * bidders and resctrict each bidder to his own distinct subset of the | 96 | * bidders and resctrict each bidder to his own distinct subset of the |
72 | * prices. This is done for tie breaking. An additional proof is used in the | 97 | * prices. This is done for tie breaking. An additional proof is used in the |
@@ -104,12 +129,26 @@ seller_start (void *arg) | |||
104 | 129 | ||
105 | ad->task = NULL; | 130 | ad->task = NULL; |
106 | 131 | ||
107 | if (0 == (ad->n = ad->start (ad->closure))) | 132 | ad->n = ad->start (ad->closure); |
133 | if (0 == ad->n) | ||
108 | { | 134 | { |
109 | weprintf ("no bidders registered for auction"); | 135 | weprintf ("no bidders registered for auction"); |
110 | ad->result (ad->closure, NULL, 0); | 136 | ad->result (ad->closure, NULL, 0); |
111 | return; | 137 | return; |
112 | } | 138 | } |
139 | else if (ad->n <= ad->m) | ||
140 | { | ||
141 | struct BRANDT_Result *res = GNUNET_new_array (ad->n, struct BRANDT_Result); | ||
142 | |||
143 | weprintf ("less bidders than needed, selling for lowest price"); | ||
144 | for (uint16_t i = 0; i < ad->n; i++) | ||
145 | { | ||
146 | res[i].bidder = i; | ||
147 | res[i].price = 0; | ||
148 | res[i].status = BRANDT_bidder_won; | ||
149 | } | ||
150 | ad->result (ad->closure, res, ad->n); | ||
151 | } | ||
113 | 152 | ||
114 | atype = ad->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; | 153 | atype = ad->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; |
115 | outcome = ad->outcome_public ? outcome_public : outcome_private; | 154 | outcome = ad->outcome_public ? outcome_public : outcome_private; |
diff --git a/test_brandt.c b/test_brandt.c index 1fb985c..46ec90d 100644 --- a/test_brandt.c +++ b/test_brandt.c | |||
@@ -84,6 +84,29 @@ expected_outcome (uint16_t i) | |||
84 | return ret; | 84 | return ret; |
85 | } | 85 | } |
86 | 86 | ||
87 | /* fewer bidders than needed -> everyone wins with lowest price */ | ||
88 | if (tcase.n <= tcase.m) | ||
89 | { | ||
90 | if (tcase.outcome_public || i == tcase.n) | ||
91 | { | ||
92 | ret = GNUNET_new_array (tcase.n, struct BRANDT_Result); | ||
93 | for (uint16_t h = 0; h < tcase.n; h++) | ||
94 | { | ||
95 | ret[h].bidder = h; | ||
96 | ret[h].price = 0; | ||
97 | ret[h].status = BRANDT_bidder_won; | ||
98 | } | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | ret = GNUNET_new (struct BRANDT_Result); | ||
103 | ret->bidder = i; | ||
104 | ret->price = 0; | ||
105 | ret->status = BRANDT_bidder_won; | ||
106 | } | ||
107 | return ret; | ||
108 | } | ||
109 | |||
87 | /* find M+1st highest bidder to determine selling price */ | 110 | /* find M+1st highest bidder to determine selling price */ |
88 | for (uint16_t h = 0; h < tcase.n; h++) | 111 | for (uint16_t h = 0; h < tcase.n; h++) |
89 | if (tcase.bids[h] > mpf_highest_bid) | 112 | if (tcase.bids[h] > mpf_highest_bid) |
@@ -387,6 +410,9 @@ main (int argc, char *argv[]) | |||
387 | test_auction (0, 2, NULL, 0, 1) || | 410 | test_auction (0, 2, NULL, 0, 1) || |
388 | test_auction (0, 2, NULL, 1, 0) || | 411 | test_auction (0, 2, NULL, 1, 0) || |
389 | test_auction (0, 2, NULL, 2, 0) || | 412 | test_auction (0, 2, NULL, 2, 0) || |
413 | test_auction (1, 2, (uint16_t[]) { 1 }, 1, 0) || | ||
414 | test_auction (1, 2, (uint16_t[]) { 0 }, 2, 0) || | ||
415 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 2, 0) || | ||
390 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 1, 0) || | 416 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 1, 0) || |
391 | test_auction (3, 2, (uint16_t[]) { 0, 0, 1 }, 2, 0) || | 417 | test_auction (3, 2, (uint16_t[]) { 0, 0, 1 }, 2, 0) || |
392 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 0) || | 418 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 0) || |