@@ -396,24 +396,36 @@ void fold2_reduction::restore(branch_and_reduce_algorithm* br_alg) {
396396}
397397
398398void fold2_reduction::apply (branch_and_reduce_algorithm* br_alg) {
399- auto & status = br_alg->status ;
400- auto nodes = restore_vec.back ().nodes ;
401- auto main_status = status.node_status [nodes.main ];
402- restore (br_alg);
403-
404- if (main_status == IS_status::included) {
405- status.node_status [nodes.main ] = IS_status::excluded;
406- status.node_status [nodes.rest [0 ]] = IS_status::included;
407- status.node_status [nodes.rest [1 ]] = IS_status::included;
408-
409- status.is_weight += status.weights [nodes.rest [0 ]] + status.weights [nodes.rest [1 ]];
410- } else {
411- status.node_status [nodes.main ] = IS_status::included;
412- status.node_status [nodes.rest [0 ]] = IS_status::excluded;
413- status.node_status [nodes.rest [1 ]] = IS_status::excluded;
414-
415- status.is_weight += status.weights [nodes.main ];
416- }
399+ #ifndef NDEBUG
400+ NodeWeight previous_is_weight = br_alg->status .is_weight + br_alg->status .reduction_offset ;
401+ #endif
402+
403+ auto & status = br_alg->status ;
404+ auto nodes = restore_vec.back ().nodes ;
405+ auto main_status = status.node_status [nodes.main ];
406+ restore (br_alg);
407+
408+ if (main_status == IS_status::included) {
409+ status.node_status [nodes.main ] = IS_status::excluded;
410+ status.node_status [nodes.rest [0 ]] = IS_status::included;
411+ status.node_status [nodes.rest [1 ]] = IS_status::included;
412+
413+ // weight of folded vertex was added to is_weight while reducing:
414+ // status.is_weight += status.weights[nodes.rest[0]] + status.weights[nodes.rest[1]] - status.weights[nodes.main]
415+ // only need to add status.weights[nodes.main] to is_weight
416+ status.is_weight += status.weights [nodes.main ];
417+ // old: status.is_weight += status.weights[nodes.rest[0]] + status.weights[nodes.rest[1]];
418+ } else {
419+ status.node_status [nodes.main ] = IS_status::included;
420+ status.node_status [nodes.rest [0 ]] = IS_status::excluded;
421+ status.node_status [nodes.rest [1 ]] = IS_status::excluded;
422+
423+ status.is_weight += status.weights [nodes.main ];
424+ }
425+ #ifndef NDEBUG
426+ // invariant that has to hold
427+ ASSERT_TRUE (br_alg->status .is_weight + br_alg->status .reduction_offset == previous_is_weight);
428+ #endif
417429}
418430
419431bool clique_reduction::reduce (branch_and_reduce_algorithm* br_alg) {
@@ -780,7 +792,7 @@ bool generalized_neighborhood_reduction::reduce(branch_and_reduce_algorithm* br_
780792 continue ;
781793 }
782794
783- if (status.weights [v] >= neighborhood_br_alg.get_current_is_weight ())
795+ if (status.weights [v] >= neighborhood_br_alg.get_is_weight ())
784796 br_alg->set (v, IS_status::included);
785797 }
786798 }
@@ -845,7 +857,7 @@ bool generalized_fold_reduction::reduce(branch_and_reduce_algorithm* br_alg) {
845857 continue ;
846858 }
847859
848- NodeWeight MWIS_weight = neighborhood_br_alg.get_current_is_weight ();
860+ NodeWeight MWIS_weight = neighborhood_br_alg.get_is_weight ();
849861 NodeWeight min_MWIS_neighbor_weight = std::numeric_limits<NodeWeight>::max ();
850862
851863 if (status.weights [v] >= MWIS_weight) {
@@ -889,7 +901,7 @@ bool generalized_fold_reduction::reduce(branch_and_reduce_algorithm* br_alg) {
889901 std::cerr << " %generalized_fold_reduction br_call loop time out" << std::endl;
890902 check_failed = true ;
891903 }
892- else if (neighborhood_br_alg.get_current_is_weight () >= status.weights [v]) {
904+ else if (neighborhood_br_alg.get_is_weight () >= status.weights [v]) {
893905 check_failed = true ;
894906 }
895907
@@ -942,7 +954,7 @@ bool generalized_fold_reduction::reduce(branch_and_reduce_algorithm* br_alg) {
942954 }
943955 else {
944956 // if the weight of every MWIS in N(v) which contains "node" is smaller than w(v) then we can remove "node"
945- remove_node = neighborhood_br_alg.get_current_is_weight () + status.weights [node] <= status.weights [v];
957+ remove_node = neighborhood_br_alg.get_is_weight () + status.weights [node] <= status.weights [v];
946958 }
947959
948960 for (const NodeID neighbor : status.graph [node]) {
@@ -1058,6 +1070,9 @@ void generalized_fold_reduction::restore(branch_and_reduce_algorithm* br_alg) {
10581070}
10591071
10601072void generalized_fold_reduction::apply (branch_and_reduce_algorithm* br_alg) {
1073+ #ifndef NDEBUG
1074+ NodeWeight previous_is_weight = br_alg->status .is_weight + br_alg->status .reduction_offset ;
1075+ #endif
10611076 auto & status = br_alg->status ;
10621077 auto nodes = restore_vec.back ().nodes ;
10631078 auto MWIS_weight = restore_vec.back ().MWIS_weight ;
@@ -1071,7 +1086,8 @@ void generalized_fold_reduction::apply(branch_and_reduce_algorithm* br_alg) {
10711086 status.node_status [node] = IS_status::included;
10721087 }
10731088
1074- status.is_weight += MWIS_weight;
1089+ status.is_weight += status.weights [nodes.main ]; // for details see fold2::apply
1090+ // wrong: status.is_weight += MWIS_weight;
10751091 } else {
10761092 status.node_status [nodes.main ] = IS_status::included;
10771093
@@ -1081,4 +1097,8 @@ void generalized_fold_reduction::apply(branch_and_reduce_algorithm* br_alg) {
10811097
10821098 status.is_weight += status.weights [nodes.main ];
10831099 }
1100+ #ifndef NDEBUG
1101+ // invariant that has to hold
1102+ ASSERT_TRUE (br_alg->status .is_weight + br_alg->status .reduction_offset == previous_is_weight);
1103+ #endif
10841104}
0 commit comments