38 double t_assignment_time_ = 0;
40 bool preprocess_ =
true;
41 bool postprocess_ =
true;
42 bool saveTree_ =
false;
43 bool onlyEmptyTreeDistance_ =
false;
45 bool isCalled_ =
false;
47 double auctionEpsilon_ = -1;
48 double auctionEpsilonDiviser_ = 0;
49 int auctionRound_ = -1;
51 double minMaxPairWeight_ = 1.0;
59 std::vector<std::vector<ftm::idNode>> tree2LevelToNode_;
60 std::vector<int> tree1Level_, tree2Level_;
67#ifdef TTK_ENABLE_OPENMP4
78 preprocess_ = preproc;
82 postprocess_ = postproc;
94 auctionEpsilon_ = aucEpsilon;
98 auctionEpsilonDiviser_ = aucEpsilonDiviser;
102 auctionRound_ = aucNoRounds;
106 onlyEmptyTreeDistance_ = only;
110 minMaxPairWeight_ = weight;
120 template <
class dataType>
123 std::vector<MatchingType> &matchings) {
129 int const nRows = costMatrix.size() - 1;
130 int const nCols = costMatrix[0].size() - 1;
131 int const max_dim = std::max(nRows, nCols);
132 int const min_dim = std::min(nRows, nCols);
135 if((min_dim <= 2 and max_dim <= 2) or (min_dim <= 1 and max_dim <= 6))
136 assignmentSolverID = 1;
138 switch(assignmentSolverID) {
141 assignmentSolver = &solverExhaustive;
145 assignmentSolver = &solverMunkres;
153 assignmentSolver = &solverAuction;
155 assignmentSolver->
setInput(costMatrix);
157 assignmentSolver->
run(matchings);
160 template <
class dataType>
162 std::vector<ftm::idNode> &children1,
163 std::vector<ftm::idNode> &children2,
164 std::vector<std::vector<dataType>> &costMatrix) {
165 unsigned int nRows = children1.size(), nCols = children2.size();
166 for(
unsigned int i = 0; i < nRows; ++i) {
167 int const forestTableI = children1[i] + 1;
168 for(
unsigned int j = 0; j < nCols; ++j) {
169 int const forestTableJ = children2[j] + 1;
171 costMatrix[i][j] = treeTable[forestTableI][forestTableJ];
172 if(tree1Level_[children1[i]] != tree2Level_[children2[j]]
177 costMatrix[i][nCols] = treeTable[forestTableI][0];
179 for(
unsigned int j = 0; j < nCols; ++j) {
180 int const forestTableJ = children2[j] + 1;
182 costMatrix[nRows][j] = treeTable[0][forestTableJ];
184 costMatrix[nRows][nCols] = 0;
187 template <
class dataType>
189 std::vector<MatchingType> &matchings,
190 std::vector<ftm::idNode> &children1,
191 std::vector<ftm::idNode> &children2,
192 std::vector<std::tuple<int, int>> &forestAssignment) {
194 for(
const auto &mTuple : matchings) {
195 cost += std::get<2>(mTuple);
196 if(std::get<0>(mTuple) >= (
int)children1.size()
197 || std::get<1>(mTuple) >= (
int)children2.size())
199 int const tableId1 = children1[std::get<0>(mTuple)] + 1;
200 int const tableId2 = children2[std::get<1>(mTuple)] + 1;
201 forestAssignment.emplace_back(tableId1, tableId2);
206 template <
class dataType>
210 std::vector<std::vector<dataType>> &treeTable,
211 std::vector<ftm::idNode> &children1,
212 std::vector<ftm::idNode> &children2,
213 std::vector<std::tuple<int, int>> &forestAssignment) {
215 int nRows = children1.size(), nCols = children2.size();
216 std::vector<std::vector<dataType>> costMatrix(
217 nRows + 1, std::vector<dataType>(nCols + 1));
223 std::vector<MatchingType> matchings;
227 dataType cost = postprocessAssignment<dataType>(
228 matchings, children1, children2, forestAssignment);
233 template <
class dataType>
239 std::vector<std::vector<dataType>> &treeTable,
240 std::vector<std::vector<dataType>> &forestTable,
241 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
243 std::vector<ftm::idNode> &children1,
244 std::vector<ftm::idNode> &children2) {
245 if(children1.size() != 0 && children2.size() != 0) {
246 dataType forestTerm3;
250 std::vector<std::tuple<int, int>> forestAssignment;
251 forestTerm3 = forestAssignmentProblem<dataType>(
252 tree1, tree2, treeTable, children1, children2, forestAssignment);
258 forestTable[i][j] = forestTerm3;
260 forestBackTable[i][j] = forestAssignment;
262 dataType forestTerm1, forestTerm2;
263 std::tuple<dataType, ftm::idNode> forestCoTerm1, forestCoTerm2;
267 = computeTerm1_2<dataType>(children2, i, forestTable,
true);
268 forestTerm1 = forestTable[0][j] + std::get<0>(forestCoTerm1);
272 = computeTerm1_2<dataType>(children1, j, forestTable,
false);
273 forestTerm2 = forestTable[i][0] + std::get<0>(forestCoTerm2);
277 = std::min(std::min(forestTerm1, forestTerm2), forestTerm3);
280 if(forestTable[i][j] == forestTerm3) {
281 forestBackTable[i][j] = forestAssignment;
282 }
else if(forestTable[i][j] == forestTerm2) {
283 forestBackTable[i][j].push_back(
284 std::make_tuple(std::get<1>(forestCoTerm2), j));
286 forestBackTable[i][j].push_back(
287 std::make_tuple(i, std::get<1>(forestCoTerm1)));
293 = (children1.size() == 0) ? forestTable[0][j] : forestTable[i][0];
300 template <
class dataType>
305 std::vector<std::vector<dataType>> &treeTable,
306 std::vector<std::vector<dataType>> &forestTable) {
307 std::vector<ftm::idNode> children;
309 forestTable[i][0] = 0;
311 forestTable[i][0] += treeTable[child + 1][0];
314 template <
class dataType>
319 std::vector<std::vector<dataType>> &treeTable,
320 std::vector<std::vector<dataType>> &forestTable) {
321 treeTable[i][0] = forestTable[i][0] + deleteCost<dataType>(tree1, nodeI);
324 template <
class dataType>
329 std::vector<std::vector<dataType>> &treeTable,
330 std::vector<std::vector<dataType>> &forestTable) {
331 std::vector<ftm::idNode> children;
333 forestTable[0][j] = 0;
335 forestTable[0][j] += treeTable[0][child + 1];
338 template <
class dataType>
343 std::vector<std::vector<dataType>> &treeTable,
344 std::vector<std::vector<dataType>> &forestTable) {
345 treeTable[0][j] = forestTable[0][j] + insertCost<dataType>(tree2, nodeJ);
349 template <
class dataType>
350 std::tuple<dataType, ftm::idNode>
353 std::vector<std::vector<dataType>> &table,
355 dataType tempMin = (childrens.size() == 0)
356 ? ((computeTerm1) ? table[ind][0] : table[0][ind])
357 : std::numeric_limits<dataType>::max();
363 temp = table[ind][children] - table[0][children];
365 temp = table[children][ind] - table[children][0];
369 bestIdNode = children;
372 return std::make_tuple(tempMin, bestIdNode);
375 template <
class dataType>
383 std::vector<std::vector<dataType>> &treeTable,
384 std::vector<std::vector<dataType>> &forestTable,
385 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
386 std::vector<ftm::idNode> &children1,
387 std::vector<ftm::idNode> &children2) {
392 = forestTable[i][j] + relabelCost<dataType>(tree1, nodeI, tree2, nodeJ);
396 treeTable[i][j] = treeTerm3;
398 treeBackTable[i][j] = std::make_tuple(i, j);
400 dataType treeTerm1, treeTerm2;
401 std::tuple<dataType, ftm::idNode> treeCoTerm1, treeCoTerm2;
404 treeCoTerm1 = computeTerm1_2<dataType>(children2, i, treeTable,
true);
405 treeTerm1 = treeTable[0][j] + std::get<0>(treeCoTerm1);
408 treeCoTerm2 = computeTerm1_2<dataType>(children1, j, treeTable,
false);
409 treeTerm2 = treeTable[i][0] + std::get<0>(treeCoTerm2);
412 treeTable[i][j] = std::min(std::min(treeTerm1, treeTerm2), treeTerm3);
415 if(treeTable[i][j] == treeTerm3) {
416 treeBackTable[i][j] = std::make_tuple(i, j);
417 }
else if(treeTable[i][j] == treeTerm2) {
418 treeBackTable[i][j] = std::make_tuple(std::get<1>(treeCoTerm2), j);
420 treeBackTable[i][j] = std::make_tuple(i, std::get<1>(treeCoTerm1));
428 template <
class dataType>
432 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
433 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
435 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> &outputMatching,
438 outputMatching.clear();
439 std::queue<std::tuple<int, int, bool>> backQueue;
440 backQueue.emplace(startR, startC,
true);
441 while(!backQueue.empty()) {
442 std::tuple<int, int, bool> elem = backQueue.front();
444 bool useTreeTable = std::get<2>(elem);
445 int const i = std::get<0>(elem);
446 int const j = std::get<1>(elem);
449 int const tupleI = std::get<0>(treeBackTable[i][j]);
450 int const tupleJ = std::get<1>(treeBackTable[i][j]);
451 if(tupleI != 0 && tupleJ != 0) {
452 useTreeTable = (tupleI != i || tupleJ != j);
453 backQueue.emplace(tupleI, tupleJ, useTreeTable);
454 if(not useTreeTable) {
459 = relabelCost<dataType>(tree1, tree1Node, tree2, tree2Node);
460 cost =
static_cast<double>(costT);
461 outputMatching.emplace_back(tree1Node, tree2Node, cost);
465 for(std::tuple<int, int> forestBackElem : forestBackTable[i][j]) {
466 int const tupleI = std::get<0>(forestBackElem);
467 int const tupleJ = std::get<1>(forestBackElem);
468 if(tupleI != 0 && tupleJ != 0) {
469 useTreeTable = (tupleI != i && tupleJ != j);
470 backQueue.emplace(tupleI, tupleJ, useTreeTable);
480 template <
class dataType>
484 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>
491 std::vector<std::vector<dataType>> treeTable(
492 nRows, std::vector<dataType>(nCols));
493 std::vector<std::vector<dataType>> forestTable(
494 nRows, std::vector<dataType>(nCols));
497 std::vector<std::vector<std::tuple<int, int>>> treeBackTable(
498 nRows, std::vector<std::tuple<int, int>>(nCols));
499 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
501 nRows, std::vector<std::vector<std::tuple<int, int>>>(nCols));
503 int const indR = tree1->
getRoot() + 1;
504 int const indC = tree2->
getRoot() + 1;
514 forestBackTable, nRows, nCols);
515 dataType distance = treeTable[indR][indC];
516 if(onlyEmptyTreeDistance_)
517 distance = treeTable[indR][0];
520 if(onlyEmptyTreeDistance_)
521 distance -= deleteCost<dataType>(tree1, tree1->
getRoot());
523 distance -= relabelCost<dataType>(
526 if(minMaxPairWeight_ != 1.0) {
527 auto cost = relabelCost<dataType>(
529 distance = distance - cost + minMaxPairWeight_ * cost;
534 distance = std::sqrt(distance);
539 computeMatching<dataType>(tree1, tree2, treeBackTable, forestBackTable,
540 outputMatching, indR, indC);
545 template <
class dataType>
549 std::vector<std::tuple<ftm::idNode, ftm::idNode>> &outputMatching) {
550 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>
553 = computeDistance<dataType>(tree1, tree2, realOutputMatching);
554 for(
auto tup : realOutputMatching)
555 outputMatching.emplace_back(std::get<0>(tup), std::get<1>(tup));
559 template <
class dataType>
562 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>
578 mTree1Copy = ftm::copyMergeTree<dataType>(mTree1);
579 mTree2Copy = ftm::copyMergeTree<dataType>(mTree2);
586 verifyMergeTreeStructure<dataType>(tree1);
587 verifyMergeTreeStructure<dataType>(tree2);
591 preprocessingPipeline<dataType>(
594 preprocessingPipeline<dataType>(
598 tree1 = &(mTree1Int.
tree);
599 tree2 = &(mTree2Int.
tree);
605 = computeDistance<dataType>(tree1, tree2, outputMatching);
611 postprocessingPipeline<dataType>(tree1);
612 postprocessingPipeline<dataType>(tree2);
614 convertBranchDecompositionMatching<dataType>(
615 tree1, tree2, outputMatching);
622 std::stringstream ss2;
623 ss2 <<
"DISTANCE² = "
626 std::stringstream ss3;
631 std::stringstream ss4;
639 template <
class dataType>
643 std::vector<std::tuple<ftm::idNode, ftm::idNode>> &outputMatching) {
644 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>
646 dataType res = execute<dataType>(tree1, tree2, realOutputMatching);
647 for(
auto tup : realOutputMatching)
648 outputMatching.emplace_back(std::get<0>(tup), std::get<1>(tup));
652 template <
class dataType>
656 std::vector<std::vector<dataType>> &treeTable,
657 std::vector<std::vector<dataType>> &forestTable,
658 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
659 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
664 t_assignment_time_ = 0;
668 treeBackTable, forestBackTable, nRows, nCols);
672 tree2->
getRoot(), treeTable, forestTable,
673 treeBackTable, forestBackTable, nRows, nCols);
674 if(onlyEmptyTreeDistance_)
678 tree2->
getRoot(), treeTable, forestTable,
679 treeBackTable, forestBackTable, nRows, nCols);
682 tree2->
getRoot(), treeTable, forestTable,
683 treeBackTable, forestBackTable, nRows, nCols);
690 printMsg(
"Assignment problems", 1, t_assignment_time_,
695 template <
class dataType>
700 bool computeEmptyTree,
703 std::vector<std::vector<dataType>> &treeTable,
704 std::vector<std::vector<dataType>> &forestTable,
705 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
706 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
711 std::vector<ftm::idNode> childrens;
713 for(
auto children : childrens)
715 children, nodeJ, treeTable, forestTable,
716 treeBackTable, forestBackTable, nRows, nCols);
718 std::vector<ftm::idNode> childrens;
720 for(
auto children : childrens)
722 nodeI, children, treeTable, forestTable,
723 treeBackTable, forestBackTable, nRows, nCols);
727 if(computeEmptyTree) {
728 int const i = nodeI + 1;
734 tree1, nodeI, i, treeTable, forestTable);
737 tree2->
getRoot(), treeTable, forestTable,
738 treeBackTable, forestBackTable, nRows, nCols);
740 int const j = nodeJ + 1;
741 if(computeEmptyTree) {
747 tree2, nodeJ, j, treeTable, forestTable);
749 }
else if(
keepSubtree_ or tree1Level_[nodeI] == tree2Level_[nodeJ]) {
750 int const i = nodeI + 1;
751 std::vector<ftm::idNode> children1;
753 std::vector<ftm::idNode> children2;
757 forestBackTable, children1, children2);
761 forestTable, treeBackTable, children1,
770 template <
class dataType>
774 std::vector<std::vector<dataType>> &treeTable,
775 std::vector<std::vector<dataType>> &forestTable,
776 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
777 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
781 std::vector<int> tree1NodeChildSize, tree2NodeChildSize;
783 std::vector<ftm::idNode> children;
785 tree1NodeChildSize.push_back(children.size());
788 std::vector<ftm::idNode> children;
790 tree2NodeChildSize.push_back(children.size());
794 std::vector<ftm::idNode> tree1Leaves;
796 std::vector<ftm::idNode> tree2Leaves;
801 treeTable, forestTable, treeBackTable,
803 if(onlyEmptyTreeDistance_)
807 tree2NodeChildSize, treeTable, forestTable,
808 treeBackTable, forestBackTable);
811 tree1NodeChildSize, tree2Leaves,
812 tree2NodeChildSize, treeTable, forestTable,
813 treeBackTable, forestBackTable,
true);
817 template <
class dataType>
823 std::vector<ftm::idNode> &tree1Leaves,
824 std::vector<int> &tree1NodeChildSize,
825 std::vector<ftm::idNode> &tree2Leaves,
826 std::vector<int> &tree2NodeChildSize,
827 std::vector<std::vector<dataType>> &treeTable,
828 std::vector<std::vector<dataType>> &forestTable,
829 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
830 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
832 bool firstCall =
false) {
837 std::queue<ftm::idNode> treeQueue;
841 treeQueue.emplace(leaf);
844 treeQueue.emplace(leaf);
845 else if(tree1Level_[i - 1] < (
int)tree2LevelToNode_.size())
846 for(
ftm::idNode const node : tree2LevelToNode_[tree1Level_[i - 1]])
847 treeQueue.emplace(node);
851 tree1NodeChildSize, tree2Leaves,
852 tree2NodeChildSize, treeTable, forestTable,
853 treeBackTable, forestBackTable, firstCall,
854 nodeT, treeChildDone, treeNodeDone, treeQueue);
857 tree1NodeChildSize, tree2Leaves,
858 tree2NodeChildSize, treeTable, forestTable,
859 treeBackTable, forestBackTable, nodeT,
860 treeChildDone, treeNodeDone, treeQueue);
864 template <
class dataType>
870 std::vector<ftm::idNode> &tree1Leaves,
871 std::vector<int> &tree1NodeChildSize,
872 std::vector<ftm::idNode> &tree2Leaves,
873 std::vector<int> &tree2NodeChildSize,
874 std::vector<std::vector<dataType>> &treeTable,
875 std::vector<std::vector<dataType>> &forestTable,
876 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
877 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
881 std::vector<int> &treeChildDone,
882 std::vector<bool> &treeNodeDone,
883 std::queue<ftm::idNode> &treeQueue) {
884#ifdef TTK_ENABLE_OPENMP4
885#pragma omp parallel num_threads(this->threadNumber_) if(firstCall)
887#pragma omp single nowait
890 tree1NodeChildSize, tree2Leaves,
891 tree2NodeChildSize, treeTable, forestTable,
892 treeBackTable, forestBackTable, nodeT,
893 treeChildDone, treeNodeDone, treeQueue);
894#ifdef TTK_ENABLE_OPENMP4
901 template <
class dataType>
907 std::vector<ftm::idNode> &tree1Leaves,
908 std::vector<int> &tree1NodeChildSize,
909 std::vector<ftm::idNode> &tree2Leaves,
910 std::vector<int> &tree2NodeChildSize,
911 std::vector<std::vector<dataType>> &treeTable,
912 std::vector<std::vector<dataType>> &forestTable,
913 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
914 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
917 std::vector<int> &treeChildDone,
918 std::vector<bool> &treeNodeDone,
919 std::queue<ftm::idNode> &treeQueue) {
921 while(!treeQueue.empty()) {
922 std::queue<ftm::idNode> taskQueue;
923 nodePerTask = nodePerTask > (int)treeQueue.size() ? treeQueue.size()
925 for(
int j = 0; j < nodePerTask; ++j) {
926 nodeT = treeQueue.front();
928 taskQueue.emplace(nodeT);
930#ifdef TTK_ENABLE_OPENMP4
931#pragma omp task firstprivate(taskQueue, nodeT) UNTIED() \
932 shared(treeTable, forestTable, treeBackTable, forestBackTable, \
933 treeChildDone, treeNodeDone) if(isTree1)
938 while(!taskQueue.empty()) {
939 nodeT = taskQueue.front();
941 int const t = nodeT + 1;
946 tree1, tree2,
false, t, tree1Leaves, tree1NodeChildSize,
947 tree2Leaves, tree2NodeChildSize, treeTable, forestTable,
948 treeBackTable, forestBackTable,
false);
951 or tree1Level_[nodeI] == tree2Level_[nodeT]) {
952 int const j = nodeT + 1;
953 std::vector<ftm::idNode> children1;
955 std::vector<ftm::idNode> children2;
959 forestBackTable, children1, children2);
963 treeTable, forestTable, treeBackTable,
964 children1, children2);
968 and tree1Level_[nodeI] == tree2Level_[nodeT])
973 int const childSize = (isTree1) ? tree1NodeChildSize[nodeTParent]
974 : tree2NodeChildSize[nodeTParent];
975 int oldTreeChildDone;
976#ifdef TTK_ENABLE_OPENMP4
977#pragma omp atomic capture
980 oldTreeChildDone = treeChildDone[nodeTParent];
981 treeChildDone[nodeTParent]++;
982#ifdef TTK_ENABLE_OPENMP4
985 if(not treeNodeDone[nodeTParent]
986 and oldTreeChildDone + 1 == childSize) {
988 taskQueue.emplace(nodeTParent);
989 treeNodeDone[nodeTParent] =
true;
990#ifdef TTK_ENABLE_OPENMP4
997#ifdef TTK_ENABLE_OPENMP4
1001#ifdef TTK_ENABLE_OPENMP4
1007 template <
class dataType>
1011 std::vector<ftm::idNode> &treeLeaves,
1012 std::vector<int> &treeNodeChildSize,
1013 std::vector<std::vector<dataType>> &treeTable,
1014 std::vector<std::vector<dataType>> &forestTable,
1015 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
1016 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
1021 std::queue<ftm::idNode> treeQueue;
1023 treeQueue.emplace(leaf);
1026 treeNodeChildSize, treeTable, forestTable,
1027 treeBackTable, forestBackTable, nodeT,
1028 treeChildDone, treeNodeDone, treeQueue);
1031 treeNodeChildSize, treeTable, forestTable,
1032 treeBackTable, forestBackTable, nodeT,
1033 treeChildDone, treeNodeDone, treeQueue);
1036 template <
class dataType>
1040 std::vector<ftm::idNode> &treeLeaves,
1041 std::vector<int> &treeNodeChildSize,
1042 std::vector<std::vector<dataType>> &treeTable,
1043 std::vector<std::vector<dataType>> &forestTable,
1044 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
1045 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
1048 std::vector<int> &treeChildDone,
1049 std::vector<bool> &treeNodeDone,
1050 std::queue<ftm::idNode> &treeQueue) {
1051#ifdef TTK_ENABLE_OPENMP4
1052#pragma omp parallel num_threads(this->threadNumber_)
1054#pragma omp single nowait
1057 treeNodeChildSize, treeTable, forestTable,
1058 treeBackTable, forestBackTable, nodeT,
1059 treeChildDone, treeNodeDone, treeQueue);
1060#ifdef TTK_ENABLE_OPENMP4
1065 template <
class dataType>
1069 std::vector<ftm::idNode> &
ttkNotUsed(treeLeaves),
1070 std::vector<int> &treeNodeChildSize,
1071 std::vector<std::vector<dataType>> &treeTable,
1072 std::vector<std::vector<dataType>> &forestTable,
1073 std::vector<std::vector<std::tuple<int, int>>> &treeBackTable,
1074 std::vector<std::vector<std::vector<std::tuple<int, int>>>>
1077 std::vector<int> &treeChildDone,
1078 std::vector<bool> &treeNodeDone,
1079 std::queue<ftm::idNode> &treeQueue) {
1080 while(!treeQueue.empty()) {
1081 nodeT = treeQueue.front();
1084#ifdef TTK_ENABLE_OPENMP4
1085#pragma omp task firstprivate(nodeT) UNTIED() \
1086 shared(treeTable, forestTable, treeBackTable, forestBackTable, \
1087 treeChildDone, treeNodeDone)
1090 while((
int)nodeT != -1) {
1092 int const i = nodeT + 1;
1095 tree, nodeT, i, treeTable, forestTable);
1099 tree, nodeT, i, treeTable, forestTable);
1101 int const j = nodeT + 1;
1104 tree, nodeT, j, treeTable, forestTable);
1108 tree, nodeT, j, treeTable, forestTable);
1113 int oldTreeChildDone;
1114#ifdef TTK_ENABLE_OPENMP4
1115#pragma omp atomic capture
1118 oldTreeChildDone = treeChildDone[nodeTParent];
1119 treeChildDone[nodeTParent]++;
1120#ifdef TTK_ENABLE_OPENMP4
1123 if(not treeNodeDone[nodeTParent]
1124 and oldTreeChildDone + 1 == treeNodeChildSize[nodeTParent]) {
1125 nodeT = nodeTParent;
1126 treeNodeDone[nodeTParent] =
true;
1127#ifdef TTK_ENABLE_OPENMP4
1128#pragma omp taskyield
1134#ifdef TTK_ENABLE_OPENMP4
1138#ifdef TTK_ENABLE_OPENMP4
1150 for(
auto itr = theMap.begin(); itr != theMap.end(); ++itr) {
1151 std::stringstream ss;
1152 ss <<
'\t' << itr->first <<
'\t' << itr->second;
1158 template <
class dataType>
1160 bool problem =
false;
1162 bool const isJT = tree->
isJoinTree<dataType>();
1163 std::vector<std::tuple<ftm::idNode, ftm::idNode>> problemNodes;
1164 std::queue<ftm::idNode> queue;
1165 queue.emplace(tree->
getRoot());
1166 while(!queue.empty()) {
1170 if(!tree->
isRoot(node)) {
1173 thisProblem = tree->
getValue<dataType>(node)
1176 thisProblem = tree->
getValue<dataType>(node)
1182 problem |= thisProblem;
1185 std::vector<ftm::idNode> children;
1187 for(
auto c : children)
1192 printErr(
"merge tree in input is not valid");
1193 for(
auto tup : problemNodes) {
1194 std::stringstream ss;
1195 ss << std::get<0>(tup) <<
" _ " << std::get<1>(tup);
1206 template <
class dataType>
1209 std::vector<std::tuple<ftm::idNode, ftm::idNode, dataType>> pairs1,
1213 std::vector<std::vector<dataType>> costMatrix(
1214 pairs1.size() + 1, std::vector<dataType>(pairs2.size() + 1));
1215 std::stringstream
const ss;
1216 ss << costMatrix.size() <<
" _ " << costMatrix[0].size();
1218 for(
unsigned int i = 0; i < costMatrix.size() - 1; ++i) {
1219 dataType nodeIValue = tree1->
getValue<dataType>(std::get<0>(pairs1[i]));
1220 dataType nodeIOriginValue
1221 = tree1->
getValue<dataType>(std::get<1>(pairs1[i]));
1222 for(
unsigned int j = 0; j < costMatrix[0].size() - 1; ++j) {
1224 = tree2->
getValue<dataType>(std::get<0>(pairs2[j]));
1225 dataType nodeJOriginValue
1226 = tree2->
getValue<dataType>(std::get<1>(pairs2[j]));
1227 costMatrix[i][j] = std::pow(nodeIValue - nodeJValue, 2)
1228 + std::pow(nodeIOriginValue - nodeJOriginValue, 2);
1230 costMatrix[i][costMatrix[0].size() - 1]
1231 = 2 * std::pow(std::get<2>(pairs1[i]), 2) / (std::pow(2, 2));
1233 for(
unsigned int j = 0; j < costMatrix[0].size() - 1; ++j)
1234 costMatrix[costMatrix.size() - 1][j]
1235 = 2 * std::pow(std::get<2>(pairs2[j]), 2) / (std::pow(2, 2));
1236 std::vector<MatchingType> matchings;
1237 forestAssignmentProblemMunkres(costMatrix, matchings);
1239 for(
auto tuple : matchings)
1240 cost += std::get<2>(tuple);
1241 std::stringstream ss2;
1242 ss2 <<
"cost = " << cost;
1244 std::stringstream ss3;
1245 ss3 <<
"cost sqrt = " << std::sqrt(cost);
#define TTK_FORCE_USE(x)
Force the compiler to use the function/method parameter.
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
void setEpsilon(double eps)
void setEpsilonDiviserMultiplier(double div)
void setNumberOfRounds(int noRounds)
virtual int run(std::vector< MatchingType > &matchings)=0
virtual int setInput(std::vector< std::vector< dataType > > &C_)
virtual void setBalanced(bool balanced)
Minimalist debugging class.
void setDebugMsgPrefix(const std::string &prefix)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
bool distanceSquaredRoot_
std::vector< std::vector< int > > treesNodeCorr_
bool branchDecomposition_
bool isPersistenceDiagram_
std::tuple< dataType, ftm::idNode > computeTerm1_2(std::vector< ftm::idNode > &childrens, int ind, std::vector< std::vector< dataType > > &table, bool computeTerm1)
void parallelTreeDistanceTask(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, bool isTree1, int i, std::vector< ftm::idNode > &tree1Leaves, std::vector< int > &tree1NodeChildSize, std::vector< ftm::idNode > &tree2Leaves, std::vector< int > &tree2NodeChildSize, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, ftm::idNode nodeT, std::vector< int > &treeChildDone, std::vector< bool > &treeNodeDone, std::queue< ftm::idNode > &treeQueue)
dataType computeDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &outputMatching)
dataType computeDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, std::vector< std::tuple< ftm::idNode, ftm::idNode > > &outputMatching)
void parallelEmptyTreeDistance_v2(ftm::FTMTree_MT *tree, bool isTree1, std::vector< ftm::idNode > &treeLeaves, std::vector< int > &treeNodeChildSize, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable)
void setOnlyEmptyTreeDistance(double only)
void setPreprocess(bool preproc)
void computeEmptyToForestDistance(ftm::FTMTree_MT *tree2, ftm::idNode nodeJ, int j, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable)
void computeForestToEmptyDistance(ftm::FTMTree_MT *tree1, ftm::idNode nodeI, int i, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable)
void classicEditDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, bool processTree1, bool computeEmptyTree, ftm::idNode nodeI, ftm::idNode nodeJ, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, int nRows, int nCols)
void runAssignmentProblemSolver(std::vector< std::vector< dataType > > &costMatrix, std::vector< MatchingType > &matchings)
void computeEmptyToSubtreeDistance(ftm::FTMTree_MT *tree2, ftm::idNode nodeJ, int j, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable)
void parallelEmptyTreeDistancePara(ftm::FTMTree_MT *tree, bool isTree1, std::vector< ftm::idNode > &treeLeaves, std::vector< int > &treeNodeChildSize, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, ftm::idNode nodeT, std::vector< int > &treeChildDone, std::vector< bool > &treeNodeDone, std::queue< ftm::idNode > &treeQueue)
void setPostprocess(bool postproc)
void setTesting(bool test)
void printMapIntInt(std::map< int, int > theMap)
dataType forestAssignmentProblem(ftm::FTMTree_MT *ttkNotUsed(tree1), ftm::FTMTree_MT *ttkNotUsed(tree2), std::vector< std::vector< dataType > > &treeTable, std::vector< ftm::idNode > &children1, std::vector< ftm::idNode > &children2, std::vector< std::tuple< int, int > > &forestAssignment)
void setAuctionEpsilonDiviser(double aucEpsilonDiviser)
void parallelTreeDistance_v2(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, bool isTree1, int i, std::vector< ftm::idNode > &tree1Leaves, std::vector< int > &tree1NodeChildSize, std::vector< ftm::idNode > &tree2Leaves, std::vector< int > &tree2NodeChildSize, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, bool firstCall=false)
void computeEditDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, int nRows, int nCols)
void computeMatching(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &outputMatching, int startR, int startC)
void setSaveTree(bool save)
void computeForestsDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, int i, int j, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, std::vector< ftm::idNode > &children1, std::vector< ftm::idNode > &children2)
void setAuctionEpsilon(double aucEpsilon)
void parallelEmptyTreeDistanceTask(ftm::FTMTree_MT *tree, bool isTree1, std::vector< ftm::idNode > &ttkNotUsed(treeLeaves), std::vector< int > &treeNodeChildSize, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, ftm::idNode nodeT, std::vector< int > &treeChildDone, std::vector< bool > &treeNodeDone, std::queue< ftm::idNode > &treeQueue)
void parallelEditDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, int ttkNotUsed(nRows), int ttkNotUsed(nCols))
void setMinMaxPairWeight(double weight)
void computeSubtreeToEmptyDistance(ftm::FTMTree_MT *tree1, ftm::idNode nodeI, int i, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable)
dataType execute(ftm::MergeTree< dataType > &tree1, ftm::MergeTree< dataType > &tree2, std::vector< std::tuple< ftm::idNode, ftm::idNode > > &outputMatching)
void parallelTreeDistancePara(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, bool isTree1, int i, std::vector< ftm::idNode > &tree1Leaves, std::vector< int > &tree1NodeChildSize, std::vector< ftm::idNode > &tree2Leaves, std::vector< int > &tree2NodeChildSize, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< std::vector< std::vector< std::tuple< int, int > > > > &forestBackTable, bool firstCall, ftm::idNode nodeT, std::vector< int > &treeChildDone, std::vector< bool > &treeNodeDone, std::queue< ftm::idNode > &treeQueue)
void createCostMatrix(std::vector< std::vector< dataType > > &treeTable, std::vector< ftm::idNode > &children1, std::vector< ftm::idNode > &children2, std::vector< std::vector< dataType > > &costMatrix)
void verifyMergeTreeStructure(ftm::FTMTree_MT *tree)
dataType postprocessAssignment(std::vector< MatchingType > &matchings, std::vector< ftm::idNode > &children1, std::vector< ftm::idNode > &children2, std::vector< std::tuple< int, int > > &forestAssignment)
dataType execute(ftm::MergeTree< dataType > &mTree1, ftm::MergeTree< dataType > &mTree2, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &outputMatching)
void computeSubtreesDistance(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2, int i, int j, ftm::idNode nodeI, ftm::idNode nodeJ, std::vector< std::vector< dataType > > &treeTable, std::vector< std::vector< dataType > > &forestTable, std::vector< std::vector< std::tuple< int, int > > > &treeBackTable, std::vector< ftm::idNode > &children1, std::vector< ftm::idNode > &children2)
void classicalPersistenceAssignmentProblem(ftm::FTMTree_MT *tree1, ftm::FTMTree_MT *tree2)
void setAuctionNoRounds(double aucNoRounds)
void setIsCalled(bool ic)
~MergeTreeDistance() override=default
void getLevelToNode(std::vector< std::vector< idNode > > &res)
const scalarType & getValue(SimplexId nodeId) const
idNode getNumberOfNodes() const
std::stringstream printTreeScalars(bool printNodeAlone=true, bool doPrint=true)
bool isRoot(idNode nodeId)
idNode getParentSafe(idNode nodeId)
void getPersistencePairsFromTree(std::vector< std::tuple< ftm::idNode, ftm::idNode, dataType > > &pairs, bool useBD)
void getChildren(idNode nodeId, std::vector< idNode > &res)
void getLeavesFromTree(std::vector< idNode > &res)
void getAllNodeLevel(std::vector< int > &res)
std::stringstream printTree(bool doPrint=true)
unsigned int idNode
Node index in vect_nodes_.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)