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