145 std::vector<int> &asgn, std::vector<MatchingType> &matchings) {
146 unsigned int const nRows = this->costMatrix.size() - 1;
147 unsigned int const nCols = this->costMatrix[0].size() - 1;
149 unsigned int const min_dim = std::min(nRows, nCols);
150 bool const transpose = nRows > nCols;
153 for(
unsigned int ind = 0; ind < asgn.size(); ++ind) {
154 int const indMatrix = std::min(ind, min_dim);
155 int const i = (!transpose) ? indMatrix : asgn[ind];
156 int const j = (!transpose) ? asgn[ind] : indMatrix;
157 cost += this->costMatrix[i][j];
158 matchings.push_back(std::make_tuple(i, j, this->costMatrix[i][j]));
165 std::vector<MatchingType> &matchings) {
166 int const nRows = this->costMatrix.size() - 1;
167 int const nCols = this->costMatrix[0].size() - 1;
168 int const max_dim = std::max(nRows, nCols);
169 int const min_dim = std::min(nRows, nCols);
172 std::vector<std::vector<int>> allAsgn;
176 if(min_dim == 1 and max_dim == 1)
177 allAsgn = {{0}, {1, 0}};
178 else if(min_dim == 1 and max_dim == 2)
179 allAsgn = {{0, 1}, {2, 0, 1}, {1, 0}};
180 else if(min_dim == 1 and max_dim == 3)
181 allAsgn = {{0, 1, 2}, {3, 0, 1, 2}, {1, 0, 2}, {2, 0, 1}};
182 else if(min_dim == 1 and max_dim == 4)
183 allAsgn = {{0, 1, 2, 3},
188 else if(min_dim == 1 and max_dim == 5)
189 allAsgn = {{0, 1, 2, 3, 4}, {5, 0, 1, 2, 3, 4}, {1, 0, 2, 3, 4},
190 {2, 0, 1, 3, 4}, {3, 0, 1, 2, 4}, {4, 0, 1, 2, 3}};
191 else if(min_dim == 1 and max_dim == 6)
192 allAsgn = {{0, 1, 2, 3, 4, 5}, {6, 0, 1, 2, 3, 4, 5}, {1, 0, 2, 3, 4, 5},
193 {2, 0, 1, 3, 4, 5}, {3, 0, 1, 2, 4, 5}, {4, 0, 1, 2, 3, 5},
195 else if(min_dim == 2 and max_dim == 2)
196 allAsgn = {{0, 1}, {0, 2, 1}, {2, 1, 0}, {2, 2, 0, 1},
197 {1, 0}, {1, 2, 0}, {2, 0, 1}};
199 std::stringstream ss;
200 ss << min_dim <<
"_" << max_dim;
201 std::string
const asgnName = ss.str();
203 if(not saveAsgn or savedAsgn.find(asgnName) == savedAsgn.end()) {
206 enumerateAssignments(min_dim, max_dim, allAsgn);
208 savedAsgn[asgnName] = allAsgn;
209 std::stringstream ss2;
210 ss2 << allAsgn.size() <<
" done";
214 allAsgn = savedAsgn[asgnName];
218 dataType bestCost = std::numeric_limits<dataType>::max();
219 std::vector<MatchingType> bestMatching;
220 for(std::vector<int> &asgn : allAsgn) {
221 std::vector<MatchingType> tempMatching;
222 dataType cost = tryAssignment(asgn, tempMatching);
223 if(bestCost > cost) {
225 bestMatching = tempMatching;
228 matchings = bestMatching;