@@ -141,17 +141,21 @@ void optimize_tree_search(
141141 outputs[i].solution_pool .add (solution);
142142 };
143143 }
144+ exception_ptr_list.push_front (std::exception_ptr ());
144145 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential) {
145- exception_ptr_list.push_front (std::exception_ptr ());
146146 threads.push_back (std::thread (
147147 wrapper<decltype (&treesearchsolver::iterative_beam_search_2<BranchingScheme>), treesearchsolver::iterative_beam_search_2<BranchingScheme>>,
148148 std::ref (exception_ptr_list.front ()),
149149 std::ref (branching_schemes[i]),
150150 ibs_parameters_list[i]));
151151 } else {
152- treesearchsolver::iterative_beam_search_2<BranchingScheme>(
153- branching_schemes[i],
154- ibs_parameters_list[i]);
152+ try {
153+ treesearchsolver::iterative_beam_search_2<BranchingScheme>(
154+ branching_schemes[i],
155+ ibs_parameters_list[i]);
156+ } catch (...) {
157+ exception_ptr_list.front () = std::current_exception ();
158+ }
155159 }
156160 }
157161 for (Counter i = 0 ; i < (Counter)threads.size (); ++i)
@@ -569,110 +573,134 @@ packingsolver::rectangle::Output packingsolver::rectangle::optimize(
569573 std::forward_list<std::exception_ptr> exception_ptr_list;
570574 // Tree search.
571575 if (use_tree_search) {
576+ exception_ptr_list.push_front (std::exception_ptr ());
572577 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
573578 && last_algorithm != 0 ) {
574- exception_ptr_list.push_front (std::exception_ptr ());
575579 threads.push_back (std::thread (
576580 wrapper<decltype (&optimize_tree_search), optimize_tree_search>,
577581 std::ref (exception_ptr_list.front ()),
578582 std::ref (instance),
579583 std::ref (parameters),
580584 std::ref (algorithm_formatter)));
581585 } else {
582- optimize_tree_search (
583- instance,
584- parameters,
585- algorithm_formatter);
586+ try {
587+ optimize_tree_search (
588+ instance,
589+ parameters,
590+ algorithm_formatter);
591+ } catch (...) {
592+ exception_ptr_list.front () = std::current_exception ();
593+ }
586594 }
587595 }
588596 // Bender's decomposition.
589597 if (use_benders_decomposition) {
598+ exception_ptr_list.push_front (std::exception_ptr ());
590599 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
591600 && last_algorithm != 1 ) {
592- exception_ptr_list.push_front (std::exception_ptr ());
593601 threads.push_back (std::thread (
594602 wrapper<decltype (&optimize_benders_decomposition), optimize_benders_decomposition>,
595603 std::ref (exception_ptr_list.front ()),
596604 std::ref (instance),
597605 std::ref (parameters),
598606 std::ref (algorithm_formatter)));
599607 } else {
600- optimize_benders_decomposition (
601- instance,
602- parameters,
603- algorithm_formatter);
608+ try {
609+ optimize_benders_decomposition (
610+ instance,
611+ parameters,
612+ algorithm_formatter);
613+ } catch (...) {
614+ exception_ptr_list.front () = std::current_exception ();
615+ }
604616 }
605617 }
606618 // Sequential single knapsack.
607619 if (use_sequential_single_knapsack) {
620+ exception_ptr_list.push_front (std::exception_ptr ());
608621 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
609622 && last_algorithm != 2 ) {
610- exception_ptr_list.push_front (std::exception_ptr ());
611623 threads.push_back (std::thread (
612624 wrapper<decltype (&optimize_sequential_single_knapsack), optimize_sequential_single_knapsack>,
613625 std::ref (exception_ptr_list.front ()),
614626 std::ref (instance),
615627 std::ref (parameters),
616628 std::ref (algorithm_formatter)));
617629 } else {
618- optimize_sequential_single_knapsack (
619- instance,
620- parameters,
621- algorithm_formatter);
630+ try {
631+ optimize_sequential_single_knapsack (
632+ instance,
633+ parameters,
634+ algorithm_formatter);
635+ } catch (...) {
636+ exception_ptr_list.front () = std::current_exception ();
637+ }
622638 }
623639 }
624640 // Sequential value correction.
625641 if (use_sequential_value_correction) {
642+ exception_ptr_list.push_front (std::exception_ptr ());
626643 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
627644 && last_algorithm != 3 ) {
628- exception_ptr_list.push_front (std::exception_ptr ());
629645 threads.push_back (std::thread (
630646 wrapper<decltype (&optimize_sequential_value_correction), optimize_sequential_value_correction>,
631647 std::ref (exception_ptr_list.front ()),
632648 std::ref (instance),
633649 std::ref (parameters),
634650 std::ref (algorithm_formatter)));
635651 } else {
636- optimize_sequential_value_correction (
637- instance,
638- parameters,
639- algorithm_formatter);
652+ try {
653+ optimize_sequential_value_correction (
654+ instance,
655+ parameters,
656+ algorithm_formatter);
657+ } catch (...) {
658+ exception_ptr_list.front () = std::current_exception ();
659+ }
640660 }
641661 }
642662 // Dichotomic search.
643663 if (use_dichotomic_search) {
664+ exception_ptr_list.push_front (std::exception_ptr ());
644665 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
645666 && last_algorithm != 4 ) {
646- exception_ptr_list.push_front (std::exception_ptr ());
647667 threads.push_back (std::thread (
648668 wrapper<decltype (&optimize_dichotomic_search), optimize_dichotomic_search>,
649669 std::ref (exception_ptr_list.front ()),
650670 std::ref (instance),
651671 std::ref (parameters),
652672 std::ref (algorithm_formatter)));
653673 } else {
654- optimize_dichotomic_search (
655- instance,
656- parameters,
657- algorithm_formatter);
674+ try {
675+ optimize_dichotomic_search (
676+ instance,
677+ parameters,
678+ algorithm_formatter);
679+ } catch (...) {
680+ exception_ptr_list.front () = std::current_exception ();
681+ }
658682 }
659683 }
660684 // Column generation.
661685 if (use_column_generation) {
686+ exception_ptr_list.push_front (std::exception_ptr ());
662687 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
663688 && last_algorithm != 5 ) {
664- exception_ptr_list.push_front (std::exception_ptr ());
665689 threads.push_back (std::thread (
666690 wrapper<decltype (&optimize_column_generation), optimize_column_generation>,
667691 std::ref (exception_ptr_list.front ()),
668692 std::ref (instance),
669693 std::ref (parameters),
670694 std::ref (algorithm_formatter)));
671695 } else {
672- optimize_column_generation (
673- instance,
674- parameters,
675- algorithm_formatter);
696+ try {
697+ optimize_column_generation (
698+ instance,
699+ parameters,
700+ algorithm_formatter);
701+ } catch (...) {
702+ exception_ptr_list.front () = std::current_exception ();
703+ }
676704 }
677705 }
678706 for (Counter i = 0 ; i < (Counter)threads.size (); ++i)
0 commit comments