У меня есть карта пар map<pair<int, int>, int> counts
.Я перебираю это и вычисляю некоторые числа с плавающей запятой, если значение карты больше 2. Теперь я хочу сохранить числа с плавающей запятой в векторе, который равен числу аналогичных значений в моем первом элементемоя параПример значений на моей карте:
1 1 4
1 2 5
1 3 5
1 7 5
1 29 2 .. теперь первый ключизменяется таким образом, чтобы размер был 4 (не 5, потому что одно значение <3) <br>2 10 1
2 20 4 ...
Я попытался сделать минимальный пример,что объясняет это немного лучше:
int main(int argc, char** argv)
{
// Create some values - both vectors have the same size
vector<pair<int, int>> pairs;
pairs.push_back(make_pair(1, 1));
pairs.push_back(make_pair(1, 2));
pairs.push_back(make_pair(1, 4));
pairs.push_back(make_pair(2, 7));
pairs.push_back(make_pair(2, 4));
pairs.push_back(make_pair(3, 5));
pairs.push_back(make_pair(3, 7));
pairs.push_back(make_pair(3, 8));
vector<float> value;
value.push_back(4);
value.push_back(5);
value.push_back(8);
value.push_back(2);
value.push_back(5);
value.push_back(6);
value.push_back(7);
value.push_back(8);
map<pair<int, int>, int> counts;
vector<vector<vector<float>>> descriptors_1, descriptors_2;
vector<float> oa_simil;
float Overall_Similarity;
for (size_t i = 0; i < pairs.size(); i++) {
counts.insert(make_pair(make_pair(pairs[i].first, pairs[i].second), value[i]));
}
for (const auto& p : counts) {
const auto& p1 = p.first.first;
const auto& p2 = p.first.second;
int count = p.second;
if (p.second >= 3) {
float S = 0;
// Two for-loops that calculate a new S for every p1, p2 combination >= 3
//S = ls_1;
// 5 Linesegments in image 1 are compared to 5 Linesegments in image 2, if p.second >= 3
for (int ls_1 = 0; ls_1 < 5; ls_1++) {
for (int ls_2 = 0; ls_2 < 5; ls_2++) {
pair<int, int> index_1, index_2;
index_1 = make_pair(p1, ls_1);
index_2 = make_pair(p2, ls_2);
// Calculate the Similarity of different pairs of line segments in a complex function
calculateSimilarity(Overall_Similarity, descriptors_1, descriptors_2, index_1, index_2);
oa_simil.push_back(Overall_Similarity);
}
// Get the maximum similarity of every single line segment in one image
float max_M = *max_element(oa_simil.begin(), oa_simil.end());
oa_simil.clear();
// Sum up the maxima -> S contains the maximum for the combination of two Linesegments p1, p2 (if p >=3)
S += max_M;
}
// Now I want to get the maximum value S for every single p1
// In the example I want the maximum S out of e.g. the 3 pairs (1,1), (1,2), (1,4).
// Trying to push the S in a vector<float> when p1 changes.
}
}
}
Я уже пытался перенести все свои ключи и значение S в новую карту, но это кажется пустой тратой времени вычислений, когда я уже перебираю своиключи.