@@ -185,8 +185,8 @@ void optimize_tree_search(
185
185
outputs[i].solution_pool .add (solution);
186
186
};
187
187
}
188
+ exception_ptr_list.push_front (std::exception_ptr ());
188
189
if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential) {
189
- exception_ptr_list.push_front (std::exception_ptr ());
190
190
threads.push_back (std::thread (
191
191
wrapper<decltype (&optimize_tree_search_worker), optimize_tree_search_worker>,
192
192
std::ref (exception_ptr_list.front ()),
@@ -196,12 +196,16 @@ void optimize_tree_search(
196
196
branching_scheme_parameters_list[i],
197
197
ibs_parameters_list[i]));
198
198
} 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
+ }
205
209
}
206
210
}
207
211
for (Counter i = 0 ; i < (Counter)threads.size (); ++i)
@@ -580,92 +584,112 @@ packingsolver::irregular::Output packingsolver::irregular::optimize(
580
584
std::forward_list<std::exception_ptr> exception_ptr_list;
581
585
// Tree search.
582
586
if (use_tree_search) {
587
+ exception_ptr_list.push_front (std::exception_ptr ());
583
588
if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
584
589
&& last_algorithm != 0 ) {
585
- exception_ptr_list.push_front (std::exception_ptr ());
586
590
threads.push_back (std::thread (
587
591
wrapper<decltype (&optimize_tree_search), optimize_tree_search>,
588
592
std::ref (exception_ptr_list.front ()),
589
593
std::ref (instance),
590
594
std::ref (parameters),
591
595
std::ref (algorithm_formatter)));
592
596
} 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
+ }
597
605
}
598
606
}
599
607
// Sequential single knapsack.
600
608
if (use_sequential_single_knapsack) {
609
+ exception_ptr_list.push_front (std::exception_ptr ());
601
610
if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
602
611
&& last_algorithm != 1 ) {
603
- exception_ptr_list.push_front (std::exception_ptr ());
604
612
threads.push_back (std::thread (
605
613
wrapper<decltype (&optimize_sequential_single_knapsack), optimize_sequential_single_knapsack>,
606
614
std::ref (exception_ptr_list.front ()),
607
615
std::ref (instance),
608
616
std::ref (parameters),
609
617
std::ref (algorithm_formatter)));
610
618
} 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
+ }
615
627
}
616
628
}
617
629
// Sequential value correction.
618
630
if (use_sequential_value_correction) {
631
+ exception_ptr_list.push_front (std::exception_ptr ());
619
632
if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
620
633
&& last_algorithm != 2 ) {
621
- exception_ptr_list.push_front (std::exception_ptr ());
622
634
threads.push_back (std::thread (
623
635
wrapper<decltype (&optimize_sequential_value_correction), optimize_sequential_value_correction>,
624
636
std::ref (exception_ptr_list.front ()),
625
637
std::ref (instance),
626
638
std::ref (parameters),
627
639
std::ref (algorithm_formatter)));
628
640
} 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
+ }
633
649
}
634
650
}
635
651
// Dichotomic search.
636
652
if (use_dichotomic_search) {
653
+ exception_ptr_list.push_front (std::exception_ptr ());
637
654
if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
638
655
&& last_algorithm != 3 ) {
639
- exception_ptr_list.push_front (std::exception_ptr ());
640
656
threads.push_back (std::thread (
641
657
wrapper<decltype (&optimize_dichotomic_search), optimize_dichotomic_search>,
642
658
std::ref (exception_ptr_list.front ()),
643
659
std::ref (instance),
644
660
std::ref (parameters),
645
661
std::ref (algorithm_formatter)));
646
662
} 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
+ }
651
671
}
652
672
}
653
673
// Column generation.
654
674
if (use_column_generation) {
675
+ exception_ptr_list.push_front (std::exception_ptr ());
655
676
if (parameters.optimization_mode != OptimizationMode::NotAnytimeSequential
656
677
&& last_algorithm != 4 ) {
657
- exception_ptr_list.push_front (std::exception_ptr ());
658
678
threads.push_back (std::thread (
659
679
wrapper<decltype (&optimize_column_generation), optimize_column_generation>,
660
680
std::ref (exception_ptr_list.front ()),
661
681
std::ref (instance),
662
682
std::ref (parameters),
663
683
std::ref (algorithm_formatter)));
664
684
} 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
+ }
669
693
}
670
694
}
671
695
for (Counter i = 0 ; i < (Counter)threads.size (); ++i)
0 commit comments