1525 | | if (_blossom_set->trivial(blossom)) { |
1526 | | int bi = (*_node_index)[base]; |
1527 | | Value pot = (*_node_data)[bi].pot; |
1528 | | |
1529 | | (*_matching)[base] = matching; |
1530 | | _blossom_node_list.push_back(base); |
1531 | | (*_node_potential)[base] = pot; |
1532 | | } else { |
1533 | | |
1534 | | Value pot = (*_blossom_data)[blossom].pot; |
1535 | | int bn = _blossom_node_list.size(); |
1536 | | |
1537 | | std::vector<int> subblossoms; |
1538 | | _blossom_set->split(blossom, std::back_inserter(subblossoms)); |
1539 | | int b = _blossom_set->find(base); |
1540 | | int ib = -1; |
1541 | | for (int i = 0; i < int(subblossoms.size()); ++i) { |
1542 | | if (subblossoms[i] == b) { ib = i; break; } |
| 1534 | std::vector<ExtractBlossomItem> stack; |
| 1535 | stack.push_back(ExtractBlossomItem(blossom, base, matching)); |
| 1536 | while (!stack.empty()) { |
| 1537 | if (_blossom_set->trivial(stack.back().blossom)) { |
| 1538 | int bi = (*_node_index)[stack.back().base]; |
| 1539 | Value pot = (*_node_data)[bi].pot; |
| 1540 | |
| 1541 | (*_matching)[stack.back().base] = stack.back().matching; |
| 1542 | (*_node_potential)[stack.back().base] = pot; |
| 1543 | _blossom_node_list.push_back(stack.back().base); |
| 1544 | for (int i = 0; i < int(stack.back().closed.size()); ++i) { |
| 1545 | _blossom_potential[stack.back().closed[i]].end = _blossom_node_list.size(); |
| 1546 | } |
| 1547 | stack.pop_back(); |
| 1548 | } else { |
| 1549 | Value pot = (*_blossom_data)[stack.back().blossom].pot; |
| 1550 | int bn = _blossom_node_list.size(); |
| 1551 | stack.back().closed.push_back(_blossom_potential.size()); |
| 1552 | _blossom_potential.push_back(BlossomVariable(bn, pot)); |
| 1553 | |
| 1554 | std::vector<int> subblossoms; |
| 1555 | _blossom_set->split(stack.back().blossom, std::back_inserter(subblossoms)); |
| 1556 | int b = _blossom_set->find(stack.back().base); |
| 1557 | int ib = -1; |
| 1558 | for (int i = 0; i < int(subblossoms.size()); ++i) { |
| 1559 | if (subblossoms[i] == b) { ib = i; break; } |
| 1560 | } |
| 1561 | |
| 1562 | stack.back().blossom = subblossoms[ib]; |
| 1563 | for (int i = 1; i < int(subblossoms.size()); i += 2) { |
| 1564 | int sb = subblossoms[(ib + i) % subblossoms.size()]; |
| 1565 | int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
| 1566 | |
| 1567 | Arc m = (*_blossom_data)[tb].next; |
| 1568 | stack.push_back(ExtractBlossomItem(sb, _graph.target(m), _graph.oppositeArc(m))); |
| 1569 | stack.push_back(ExtractBlossomItem(tb, _graph.source(m), m)); |
| 1570 | } |
1544 | | |
1545 | | for (int i = 1; i < int(subblossoms.size()); i += 2) { |
1546 | | int sb = subblossoms[(ib + i) % subblossoms.size()]; |
1547 | | int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
1548 | | |
1549 | | Arc m = (*_blossom_data)[tb].next; |
1550 | | extractBlossom(sb, _graph.target(m), _graph.oppositeArc(m)); |
1551 | | extractBlossom(tb, _graph.source(m), m); |
1552 | | } |
1553 | | extractBlossom(subblossoms[ib], base, matching); |
1554 | | |
1555 | | int en = _blossom_node_list.size(); |
1556 | | |
1557 | | _blossom_potential.push_back(BlossomVariable(bn, en, pot)); |
2953 | | if (_blossom_set->trivial(blossom)) { |
2954 | | int bi = (*_node_index)[base]; |
2955 | | Value pot = (*_node_data)[bi].pot; |
2956 | | |
2957 | | (*_matching)[base] = matching; |
2958 | | _blossom_node_list.push_back(base); |
2959 | | (*_node_potential)[base] = pot; |
2960 | | } else { |
2961 | | |
2962 | | Value pot = (*_blossom_data)[blossom].pot; |
2963 | | int bn = _blossom_node_list.size(); |
2964 | | |
2965 | | std::vector<int> subblossoms; |
2966 | | _blossom_set->split(blossom, std::back_inserter(subblossoms)); |
2967 | | int b = _blossom_set->find(base); |
2968 | | int ib = -1; |
2969 | | for (int i = 0; i < int(subblossoms.size()); ++i) { |
2970 | | if (subblossoms[i] == b) { ib = i; break; } |
| 2976 | std::vector<ExtractBlossomItem> stack; |
| 2977 | stack.push_back(ExtractBlossomItem(blossom, base, matching)); |
| 2978 | while (!stack.empty()) { |
| 2979 | if (_blossom_set->trivial(stack.back().blossom)) { |
| 2980 | int bi = (*_node_index)[stack.back().base]; |
| 2981 | Value pot = (*_node_data)[bi].pot; |
| 2982 | |
| 2983 | (*_matching)[stack.back().base] = stack.back().matching; |
| 2984 | (*_node_potential)[stack.back().base] = pot; |
| 2985 | _blossom_node_list.push_back(stack.back().base); |
| 2986 | for (int i = 0; i < int(stack.back().closed.size()); ++i) { |
| 2987 | _blossom_potential[stack.back().closed[i]].end = _blossom_node_list.size(); |
| 2988 | } |
| 2989 | stack.pop_back(); |
| 2990 | } else { |
| 2991 | Value pot = (*_blossom_data)[stack.back().blossom].pot; |
| 2992 | int bn = _blossom_node_list.size(); |
| 2993 | stack.back().closed.push_back(_blossom_potential.size()); |
| 2994 | _blossom_potential.push_back(BlossomVariable(bn, pot)); |
| 2995 | |
| 2996 | std::vector<int> subblossoms; |
| 2997 | _blossom_set->split(stack.back().blossom, std::back_inserter(subblossoms)); |
| 2998 | int b = _blossom_set->find(stack.back().base); |
| 2999 | int ib = -1; |
| 3000 | for (int i = 0; i < int(subblossoms.size()); ++i) { |
| 3001 | if (subblossoms[i] == b) { ib = i; break; } |
| 3002 | } |
| 3003 | |
| 3004 | stack.back().blossom = subblossoms[ib]; |
| 3005 | for (int i = 1; i < int(subblossoms.size()); i += 2) { |
| 3006 | int sb = subblossoms[(ib + i) % subblossoms.size()]; |
| 3007 | int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
| 3008 | |
| 3009 | Arc m = (*_blossom_data)[tb].next; |
| 3010 | stack.push_back(ExtractBlossomItem(sb, _graph.target(m), _graph.oppositeArc(m))); |
| 3011 | stack.push_back(ExtractBlossomItem(tb, _graph.source(m), m)); |
| 3012 | } |
2972 | | |
2973 | | for (int i = 1; i < int(subblossoms.size()); i += 2) { |
2974 | | int sb = subblossoms[(ib + i) % subblossoms.size()]; |
2975 | | int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
2976 | | |
2977 | | Arc m = (*_blossom_data)[tb].next; |
2978 | | extractBlossom(sb, _graph.target(m), _graph.oppositeArc(m)); |
2979 | | extractBlossom(tb, _graph.source(m), m); |
2980 | | } |
2981 | | extractBlossom(subblossoms[ib], base, matching); |
2982 | | |
2983 | | int en = _blossom_node_list.size(); |
2984 | | |
2985 | | _blossom_potential.push_back(BlossomVariable(bn, en, pot)); |