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; } |
| 1536 | std::vector<ExtractBlossomItem> stack; |
| 1537 | std::vector<int> close_stack; |
| 1538 | stack.push_back(ExtractBlossomItem(blossom, base, matching, 0)); |
| 1539 | while (!stack.empty()) { |
| 1540 | if (_blossom_set->trivial(stack.back().blossom)) { |
| 1541 | int bi = (*_node_index)[stack.back().base]; |
| 1542 | Value pot = (*_node_data)[bi].pot; |
| 1543 | |
| 1544 | (*_matching)[stack.back().base] = stack.back().matching; |
| 1545 | (*_node_potential)[stack.back().base] = pot; |
| 1546 | _blossom_node_list.push_back(stack.back().base); |
| 1547 | while (int(close_stack.size()) > stack.back().close_index) { |
| 1548 | _blossom_potential[close_stack.back()].end = _blossom_node_list.size(); |
| 1549 | close_stack.pop_back(); |
| 1550 | } |
| 1551 | stack.pop_back(); |
| 1552 | } else { |
| 1553 | Value pot = (*_blossom_data)[stack.back().blossom].pot; |
| 1554 | int bn = _blossom_node_list.size(); |
| 1555 | close_stack.push_back(_blossom_potential.size()); |
| 1556 | _blossom_potential.push_back(BlossomVariable(bn, pot)); |
| 1557 | |
| 1558 | std::vector<int> subblossoms; |
| 1559 | _blossom_set->split(stack.back().blossom, std::back_inserter(subblossoms)); |
| 1560 | int b = _blossom_set->find(stack.back().base); |
| 1561 | int ib = -1; |
| 1562 | for (int i = 0; i < int(subblossoms.size()); ++i) { |
| 1563 | if (subblossoms[i] == b) { ib = i; break; } |
| 1564 | } |
| 1565 | |
| 1566 | stack.back().blossom = subblossoms[ib]; |
| 1567 | for (int i = 1; i < int(subblossoms.size()); i += 2) { |
| 1568 | int sb = subblossoms[(ib + i) % subblossoms.size()]; |
| 1569 | int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
| 1570 | |
| 1571 | Arc m = (*_blossom_data)[tb].next; |
| 1572 | stack.push_back(ExtractBlossomItem( |
| 1573 | sb, _graph.target(m), _graph.oppositeArc(m), close_stack.size())); |
| 1574 | stack.push_back(ExtractBlossomItem( |
| 1575 | tb, _graph.source(m), m, close_stack.size())); |
| 1576 | } |
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; } |
| 2984 | std::vector<ExtractBlossomItem> stack; |
| 2985 | std::vector<int> close_stack; |
| 2986 | stack.push_back(ExtractBlossomItem(blossom, base, matching, 0)); |
| 2987 | while (!stack.empty()) { |
| 2988 | if (_blossom_set->trivial(stack.back().blossom)) { |
| 2989 | int bi = (*_node_index)[stack.back().base]; |
| 2990 | Value pot = (*_node_data)[bi].pot; |
| 2991 | |
| 2992 | (*_matching)[stack.back().base] = stack.back().matching; |
| 2993 | (*_node_potential)[stack.back().base] = pot; |
| 2994 | _blossom_node_list.push_back(stack.back().base); |
| 2995 | while (int(close_stack.size()) > stack.back().close_index) { |
| 2996 | _blossom_potential[close_stack.back()].end = _blossom_node_list.size(); |
| 2997 | close_stack.pop_back(); |
| 2998 | } |
| 2999 | stack.pop_back(); |
| 3000 | } else { |
| 3001 | Value pot = (*_blossom_data)[stack.back().blossom].pot; |
| 3002 | int bn = _blossom_node_list.size(); |
| 3003 | close_stack.push_back(_blossom_potential.size()); |
| 3004 | _blossom_potential.push_back(BlossomVariable(bn, pot)); |
| 3005 | |
| 3006 | std::vector<int> subblossoms; |
| 3007 | _blossom_set->split(stack.back().blossom, std::back_inserter(subblossoms)); |
| 3008 | int b = _blossom_set->find(stack.back().base); |
| 3009 | int ib = -1; |
| 3010 | for (int i = 0; i < int(subblossoms.size()); ++i) { |
| 3011 | if (subblossoms[i] == b) { ib = i; break; } |
| 3012 | } |
| 3013 | |
| 3014 | stack.back().blossom = subblossoms[ib]; |
| 3015 | for (int i = 1; i < int(subblossoms.size()); i += 2) { |
| 3016 | int sb = subblossoms[(ib + i) % subblossoms.size()]; |
| 3017 | int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
| 3018 | |
| 3019 | Arc m = (*_blossom_data)[tb].next; |
| 3020 | stack.push_back(ExtractBlossomItem( |
| 3021 | sb, _graph.target(m), _graph.oppositeArc(m), close_stack.size())); |
| 3022 | stack.push_back(ExtractBlossomItem( |
| 3023 | tb, _graph.source(m), m, close_stack.size())); |
| 3024 | } |
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)); |