File indexing completed on 2025-08-06 08:11:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/tools/output_test_stream.hpp>
0011 #include <boost/test/unit_test.hpp>
0012
0013 #include "Acts/Utilities/AnnealingUtility.hpp"
0014
0015 #include <iostream>
0016 #include <vector>
0017
0018 namespace Acts::Test {
0019
0020 BOOST_AUTO_TEST_CASE(annealing_tool_singleChi2_tests) {
0021 std::vector<double> temperatures{64., 16., 4., 2., 1.5, 1.};
0022 AnnealingUtility::Config config;
0023 config.setOfTemperatures = temperatures;
0024 AnnealingUtility annealingTool(config);
0025
0026 AnnealingUtility::State state;
0027
0028
0029
0030
0031 double chi2 = config.cutOff + 3.14;
0032
0033
0034 double previousWeight = 1.;
0035
0036 std::cout << "Check weight decrease:" << std::endl;
0037 for (auto temp : temperatures) {
0038 double weight = annealingTool.getWeight(state, chi2);
0039
0040 bool hasDecreased = weight < previousWeight;
0041
0042 BOOST_CHECK(hasDecreased);
0043
0044 previousWeight = weight;
0045 annealingTool.anneal(state);
0046
0047 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0048 << std::endl;
0049 }
0050
0051
0052 BOOST_CHECK_EQUAL(state.equilibriumReached, true);
0053
0054
0055 state = AnnealingUtility::State();
0056
0057 BOOST_CHECK_EQUAL(state.currentTemperatureIndex, 0u);
0058 BOOST_CHECK_EQUAL(state.equilibriumReached, false);
0059
0060
0061
0062
0063 chi2 = config.cutOff - 3.14;
0064
0065
0066 previousWeight = 0.;
0067
0068 std::cout << "Check weight increase:" << std::endl;
0069 for (auto temp : temperatures) {
0070 double weight = annealingTool.getWeight(state, chi2);
0071
0072 bool hasIncreased = weight > previousWeight;
0073
0074 BOOST_CHECK(hasIncreased);
0075
0076 previousWeight = weight;
0077 annealingTool.anneal(state);
0078
0079 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0080 << std::endl;
0081 }
0082
0083
0084 state = AnnealingUtility::State();
0085
0086
0087
0088
0089 chi2 = config.cutOff;
0090
0091
0092 previousWeight = 0.5;
0093
0094 std::cout << "Check weight insensitivity:" << std::endl;
0095 for (auto temp : temperatures) {
0096 double weight = annealingTool.getWeight(state, chi2);
0097
0098 bool hasNotChanged = weight == previousWeight;
0099
0100 BOOST_CHECK(hasNotChanged);
0101
0102 previousWeight = weight;
0103 annealingTool.anneal(state);
0104
0105 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0106 << std::endl;
0107 }
0108 }
0109
0110 BOOST_AUTO_TEST_CASE(annealing_tool_multiChi2_tests) {
0111
0112 std::vector<double> allChi2{1.3, 4.5, 8.4, 0.4, 10.3, 12.3,
0113 3.5, 5.8, 11.0, 1.1, 3.5, 6.7};
0114
0115 std::vector<double> temperatures{64., 16., 4., 2., 1.5, 1.};
0116 AnnealingUtility::Config config;
0117 config.setOfTemperatures = {64., 16., 4., 2., 1.5, 1.};
0118 AnnealingUtility annealingTool(config);
0119
0120 AnnealingUtility::State state;
0121
0122
0123
0124
0125 double chi2 = config.cutOff + 5.;
0126
0127
0128 double previousWeight = 1.;
0129
0130 std::cout << "Check weight decrease:" << std::endl;
0131 for (auto temp : temperatures) {
0132 double weight = annealingTool.getWeight(state, chi2, allChi2);
0133
0134 bool hasDecreased = weight < previousWeight;
0135
0136 BOOST_CHECK(hasDecreased);
0137
0138 previousWeight = weight;
0139 annealingTool.anneal(state);
0140
0141 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0142 << std::endl;
0143 }
0144
0145
0146 BOOST_CHECK_EQUAL(state.equilibriumReached, true);
0147
0148
0149 state = AnnealingUtility::State();
0150
0151 BOOST_CHECK_EQUAL(state.currentTemperatureIndex, 0u);
0152 BOOST_CHECK_EQUAL(state.equilibriumReached, false);
0153
0154
0155
0156
0157 chi2 = 1.234;
0158
0159
0160 previousWeight = 0.;
0161
0162 std::cout << "Check weight increase:" << std::endl;
0163 for (auto temp : temperatures) {
0164 double weight = annealingTool.getWeight(state, chi2, allChi2);
0165
0166 bool hasIncreased = weight > previousWeight;
0167
0168 BOOST_CHECK(hasIncreased);
0169
0170 previousWeight = weight;
0171 annealingTool.anneal(state);
0172
0173 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0174 << std::endl;
0175 }
0176 }
0177
0178 }