92 {
93
94 if(maxThreads == 0) {
95 maxThreads = std::thread::hardware_concurrency();
96 if(maxThreads == 0) {
97 assert(0 && "Failed to get the number of concurrent threads supported by the implementation");
99 }
100 }
101
102 std::vector<std::future<geometrize::State>> futures{maxThreads};
103 for(std::uint32_t i = 0; i < futures.size(); i++) {
104 std::future<geometrize::State> handle{std::async(std::launch::async, [&](const std::uint32_t seed, const double lastScore) {
105
106
107
109
113 futures[i] = std::move(handle);
114 }
115
116 std::vector<geometrize::State> states;
117
118 for(auto& f : futures) {
119 try {
120 states.emplace_back(f.get());
121 } catch(std::exception& e) {
122 assert(0 && "Encountered exception when getting hill climb state");
123 std::cout << e.what() << std::endl;
124 throw e;
125 } catch (...) {
126 assert(0 && "Encountered exception when getting hill climb state");
127 throw;
128 }
129 }
130 return states;
131 }
static const std::uint32_t defaultMaxThreads
Definition: model.cpp:216
void seedRandomGenerator(const std::uint32_t seed)
seedRandomGenerator Seeds the (thread-local) random number generators.
Definition: commonutil.cpp:24
geometrize::State bestHillClimbState(const std::function< std::shared_ptr< geometrize::Shape >(void)> &shapeCreator, const std::uint32_t alpha, const std::uint32_t n, const std::uint32_t age, const geometrize::Bitmap &target, const geometrize::Bitmap ¤t, geometrize::Bitmap &buffer, const double lastScore, const EnergyFunction &customEnergyFunction)
bestHillClimbState Gets the best state using a hill climbing algorithm.
Definition: core.cpp:233