32 int run(std::vector<MatchingType> &matchings)
override;
48 goodPrices.resize(this->
colSize, 0);
54 numberOfRounds = noRounds;
70 epsilonDiviserMultiplier = div;
74 goodPrices.resize(prices.size(), 0);
75 for(
unsigned int i = 0; i < prices.size(); ++i)
76 goodPrices[i] = prices[i];
84 int numberOfRounds = -1;
87 double epsilonDiviserMultiplier = 0;
88 double delta_lim = 0.01;
90 dataType lowerBoundCostWeight = 1 + delta_lim;
93 std::vector<int> bidderAssignments{1, -1}, bestBidderAssignments;
94 std::vector<int> goodAssignments{};
95 std::vector<double> goodPrices{};
96 dataType lowerBoundCost;
107 unsigned int const nRows = matrix.size();
108 unsigned int const nCols = matrix[0].size();
109 dataType maxValue = std::numeric_limits<dataType>::lowest();
110 for(
unsigned int i = 0; i < nRows; ++i) {
111 for(
unsigned int j = 0; j < nCols; ++j) {
112 if(not balancedAsgn and i == nRows - 1 and j == nCols - 1)
114 maxValue = (matrix[i][j] > maxValue) ? matrix[i][j] : maxValue;
161 std::vector<std::vector<dataType>> &matrix) {
162 unsigned int const nRows = matrix.size();
163 unsigned int const nCols = matrix[0].size();
164 matrix[nRows - 1][nCols - 1] = 0;
167 for(
unsigned int i = 0; i < nCols - 2; ++i) {
168 std::vector<dataType>
const newLine(matrix[nRows - 1]);
169 matrix.push_back(newLine);
172 for(
unsigned int i = 0; i < (nRows - 1) + (nCols - 1); ++i) {
173 for(
unsigned int j = 0; j < nRows - 2; ++j) {
174 matrix[i].push_back(matrix[i][nCols - 1]);
184 std::vector<std::vector<dataType>> &cMatrix) {
185 std::queue<int> unassignedBidders{};
186 for(
unsigned int i = 0; i < bidderAssignments.size(); ++i)
187 unassignedBidders.push(i);
189 while(!unassignedBidders.empty()) {
190 int const bidderId = unassignedBidders.front();
191 unassignedBidders.pop();
194 dataType bestValue = std::numeric_limits<dataType>::lowest();
195 dataType bestSecondValue = std::numeric_limits<dataType>::lowest();
197 for(
unsigned int goodId = 0; goodId < goodPrices.size(); ++goodId) {
198 if(cMatrix[bidderId][goodId] ==
static_cast<dataType
>(-1))
200 dataType goodPrice = goodPrices[goodId];
201 dataType value = -cMatrix[bidderId][goodId] - goodPrice;
202 if(value > bestValue) {
203 bestSecondValue = bestValue;
206 }
else if(value > bestSecondValue)
207 bestSecondValue = value;
211 bidderAssignments[bidderId] = bestGoodId;
212 if(goodAssignments[bestGoodId] != -1)
213 unassignedBidders.push(goodAssignments[bestGoodId]);
214 goodAssignments[bestGoodId] = bidderId;
217 if(bestSecondValue == std::numeric_limits<dataType>::lowest())
218 bestSecondValue = bestValue;
221 double const delta = abs<dataType>(bestValue - bestSecondValue) + epsilon;
222 double newPrice = goodPrices[bestGoodId] + delta;
223 if(newPrice > std::numeric_limits<double>::max() / 2) {
225 newPrice = goodPrices[bestGoodId] + epsilon;
227 goodPrices[bestGoodId] = newPrice;
233 std::vector<dataType> minCol(
234 costMatrix[0].size(), std::numeric_limits<dataType>::max()),
235 minRow(costMatrix.size(), std::numeric_limits<dataType>::max());
236 for(
unsigned int i = 0; i < costMatrix.size(); ++i) {
237 for(
unsigned int j = 0; j < costMatrix[i].size(); ++j) {
238 if(costMatrix[i][j] < minCol[j])
239 minCol[j] = costMatrix[i][j];
240 if(costMatrix[i][j] < minRow[i])
241 minRow[i] = costMatrix[i][j];
244 dataType minColCost = 0, minRowCost = 0;
245 for(
unsigned int i = 0; i < minCol.size(); ++i)
246 minColCost += minCol[i];
247 for(
unsigned int i = 0; i < minRow.size(); ++i)
248 minRowCost += minRow[i];
249 dataType lowerBoundCost = std::max(minColCost, minRowCost);
251 return lowerBoundCost;
257 dataType bestCost = std::numeric_limits<dataType>::max();
260 double const tempPrice
261 = *std::max_element(goodPrices.begin(), goodPrices.end());
262 std::vector<double> savedPrices;
263 for(
unsigned int i = 0; i < goodPrices.size(); ++i) {
264 auto old = goodPrices[i];
266 = goodPrices[i] * epsilon / ((tempPrice == 0) ? 1 : tempPrice);
267 auto t = old - goodPrices[i];
268 savedPrices.push_back(t);
286 if(cost < bestCost) {
288 bestBidderAssignments = bidderAssignments;
294 if(numberOfRounds != -1 and iter >= numberOfRounds)
297 bidderAssignments = bestBidderAssignments;
300 for(
unsigned int bidderId = 0; bidderId < bidderAssignments.size();
302 int const i = bidderId;
303 int const j = bidderAssignments[bidderId];
304 if(this->balancedAssignment
305 or (not this->balancedAssignment
307 matchings.push_back(std::make_tuple(i, j, this->
costMatrix[i][j]));
312 for(
unsigned int i = 0; i < goodPrices.size(); ++i)
313 goodPrices[i] += savedPrices[i];