TCPSPSuite
elitepoolscorer.hpp
1 #ifndef ELITEPOOLSCORER_HPP
2 #define ELITEPOOLSCORER_HPP
3 
4 #include "../util/log.hpp"
5 #include <boost/container/flat_set.hpp>
6 #include <cstddef>
7 #include <random>
8 #include <vector>
9 
10 // Forwards
11 class SolverConfig;
12 class Instance;
13 namespace swag {
14 namespace detail {
15 class Edge;
16 }
17 } // namespace swag
18 
19 namespace swag {
20 
21 class ElitePoolScorer {
22 public:
23  ElitePoolScorer(const Instance & instance, const SolverConfig & sconf);
24 
25  double get_score_for(size_t s, size_t t) const noexcept;
26  void incorporate_result(
27  double quality, const std::vector<unsigned int> & start_times,
28  const std::vector<std::vector<detail::Edge>> & adjacency_list);
29  void iteration(size_t iteration) noexcept;
30 
31 private:
32  constexpr static double EPS_DOUBLE_DELTA = 0.0000001;
33 
34  const Instance & instance;
35 
36  void replace_elite_pool(size_t index, double quality,
37  const std::vector<unsigned int> & start_times);
38 
39  size_t solutions_seen;
40 
41  double start_factor;
42  size_t pool_size;
43  double sigmoid_base;
44  double sigmoid_coefficient;
45 
46  std::mt19937 rng; // TODO initialize!
47 
48  // start_times[jid][i] is the start time of job <jid> in the elite
49  // solution nr. <i>
50  // TODO make this one large vector, for better SIMDing
51  std::vector<std::vector<unsigned int>> pool_start_times;
52 
53  // scores[i] is the quality of elite solution nr <i>
54  std::vector<double> scores;
55  double best_score;
56 
57  // TODO make this a half-matrix
58  struct CacheEntry
59  {
60  size_t i_before_j_count; // TODO this should be the computed double
61  size_t generation;
62  };
63 
64  mutable std::vector<std::vector<CacheEntry>> cache;
65 
66  void update_cache(size_t s, size_t t) const;
67 
68  size_t current_generation;
69 
70  // This is just here for faster iteration
71  std::vector<unsigned int> durations;
72 
73  /* Statistics */
74  size_t num_replaced;
75 
76  Log l;
77 };
78 
79 } // namespace swag
80 
81 #endif
Instance
a TCPSP instance
Definition: instance.hpp:24