@@ -185,8 +185,8 @@ void optimize_tree_search(
185185 outputs[i].solution_pool .add (solution);
186186 };
187187 }
188+ exception_ptr_list.push_front (std::exception_ptr ());
188189 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential) {
189- exception_ptr_list.push_front (std::exception_ptr ());
190190 threads.push_back (std::thread (
191191 wrapper<decltype (&optimize_tree_search_worker), optimize_tree_search_worker>,
192192 std::ref (exception_ptr_list.front ()),
@@ -196,12 +196,16 @@ void optimize_tree_search(
196196 branching_scheme_parameters_list[i],
197197 ibs_parameters_list[i]));
198198 } else {
199- optimize_tree_search_worker (
200- instance,
201- parameters,
202- algorithm_formatter,
203- branching_scheme_parameters_list[i],
204- ibs_parameters_list[i]);
199+ try {
200+ optimize_tree_search_worker (
201+ instance,
202+ parameters,
203+ algorithm_formatter,
204+ branching_scheme_parameters_list[i],
205+ ibs_parameters_list[i]);
206+ } catch (...) {
207+ exception_ptr_list.front () = std::current_exception ();
208+ }
205209 }
206210 }
207211 for (Counter i = 0 ; i < (Counter)threads.size (); ++i)
@@ -580,92 +584,112 @@ packingsolver::irregular::Output packingsolver::irregular::optimize(
580584 std::forward_list<std::exception_ptr> exception_ptr_list;
581585 // Tree search.
582586 if (use_tree_search) {
587+ exception_ptr_list.push_front (std::exception_ptr ());
583588 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
584589 && last_algorithm != 0 ) {
585- exception_ptr_list.push_front (std::exception_ptr ());
586590 threads.push_back (std::thread (
587591 wrapper<decltype (&optimize_tree_search), optimize_tree_search>,
588592 std::ref (exception_ptr_list.front ()),
589593 std::ref (instance),
590594 std::ref (parameters),
591595 std::ref (algorithm_formatter)));
592596 } else {
593- optimize_tree_search (
594- instance,
595- parameters,
596- algorithm_formatter);
597+ try {
598+ optimize_tree_search (
599+ instance,
600+ parameters,
601+ algorithm_formatter);
602+ } catch (...) {
603+ exception_ptr_list.front () = std::current_exception ();
604+ }
597605 }
598606 }
599607 // Sequential single knapsack.
600608 if (use_sequential_single_knapsack) {
609+ exception_ptr_list.push_front (std::exception_ptr ());
601610 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
602611 && last_algorithm != 1 ) {
603- exception_ptr_list.push_front (std::exception_ptr ());
604612 threads.push_back (std::thread (
605613 wrapper<decltype (&optimize_sequential_single_knapsack), optimize_sequential_single_knapsack>,
606614 std::ref (exception_ptr_list.front ()),
607615 std::ref (instance),
608616 std::ref (parameters),
609617 std::ref (algorithm_formatter)));
610618 } else {
611- optimize_sequential_single_knapsack (
612- instance,
613- parameters,
614- algorithm_formatter);
619+ try {
620+ optimize_sequential_single_knapsack (
621+ instance,
622+ parameters,
623+ algorithm_formatter);
624+ } catch (...) {
625+ exception_ptr_list.front () = std::current_exception ();
626+ }
615627 }
616628 }
617629 // Sequential value correction.
618630 if (use_sequential_value_correction) {
631+ exception_ptr_list.push_front (std::exception_ptr ());
619632 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
620633 && last_algorithm != 2 ) {
621- exception_ptr_list.push_front (std::exception_ptr ());
622634 threads.push_back (std::thread (
623635 wrapper<decltype (&optimize_sequential_value_correction), optimize_sequential_value_correction>,
624636 std::ref (exception_ptr_list.front ()),
625637 std::ref (instance),
626638 std::ref (parameters),
627639 std::ref (algorithm_formatter)));
628640 } else {
629- optimize_sequential_value_correction (
630- instance,
631- parameters,
632- algorithm_formatter);
641+ try {
642+ optimize_sequential_value_correction (
643+ instance,
644+ parameters,
645+ algorithm_formatter);
646+ } catch (...) {
647+ exception_ptr_list.front () = std::current_exception ();
648+ }
633649 }
634650 }
635651 // Dichotomic search.
636652 if (use_dichotomic_search) {
653+ exception_ptr_list.push_front (std::exception_ptr ());
637654 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
638655 && last_algorithm != 3 ) {
639- exception_ptr_list.push_front (std::exception_ptr ());
640656 threads.push_back (std::thread (
641657 wrapper<decltype (&optimize_dichotomic_search), optimize_dichotomic_search>,
642658 std::ref (exception_ptr_list.front ()),
643659 std::ref (instance),
644660 std::ref (parameters),
645661 std::ref (algorithm_formatter)));
646662 } else {
647- optimize_dichotomic_search (
648- instance,
649- parameters,
650- algorithm_formatter);
663+ try {
664+ optimize_dichotomic_search (
665+ instance,
666+ parameters,
667+ algorithm_formatter);
668+ } catch (...) {
669+ exception_ptr_list.front () = std::current_exception ();
670+ }
651671 }
652672 }
653673 // Column generation.
654674 if (use_column_generation) {
675+ exception_ptr_list.push_front (std::exception_ptr ());
655676 if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
656677 && last_algorithm != 4 ) {
657- exception_ptr_list.push_front (std::exception_ptr ());
658678 threads.push_back (std::thread (
659679 wrapper<decltype (&optimize_column_generation), optimize_column_generation>,
660680 std::ref (exception_ptr_list.front ()),
661681 std::ref (instance),
662682 std::ref (parameters),
663683 std::ref (algorithm_formatter)));
664684 } else {
665- optimize_column_generation (
666- instance,
667- parameters,
668- algorithm_formatter);
685+ try {
686+ optimize_column_generation (
687+ instance,
688+ parameters,
689+ algorithm_formatter);
690+ } catch (...) {
691+ exception_ptr_list.front () = std::current_exception ();
692+ }
669693 }
670694 }
671695 for (Counter i = 0 ; i < (Counter)threads.size (); ++i)
0 commit comments