18 #include "foresighted_layout.h"
37 template<
typename StaticLayout>
47 , m_parallel(std::make_unique<detail::parallel>(threads)) {}
59 m_parallel = std::make_unique<detail::parallel>(count);
64 std::unique_ptr<detail::parallel> m_parallel;
67 std::vector<graph_state>& states
70 ,
float tolerance_value)
override {
71 float temp = this->m_cooling.start_temperature;
72 if (!this->m_relative_distance) {
73 tolerance_value *= this->m_static_layout.relative_unit(width, height)
74 * this->max_nodes(states);
76 detail::barrier bar(m_parallel->count());
77 std::vector<graph_state> copies = states;
78 std::vector<bool> apply(states.size());
79 auto get = [&](
unsigned i) ->
const graph_state& {
89 m_parallel->for_each_interleaved([&](
unsigned begin,
unsigned step){
90 for (
unsigned r = 0; r < this->m_cooling.iterations; ++r) {
91 for (
unsigned i = begin; i < states.size(); i += step) {
93 states[i] = copies[i];
95 copies[i] = states[i];
98 for (
unsigned i = begin; i < states.size(); i += step) {
99 this->m_static_layout.iteration(copies[i], width, height, temp);
105 for (
unsigned i = 0; i < states.size(); ++i) {
107 if ((i == 0 || this->distance(copies[i], get(i - 1)) < tolerance_value)
108 && (i >= states.size() - 1
109 || this->distance(copies[i], states[i + 1]) < tolerance_value)) {
113 temp = this->m_cooling.anneal(temp);