TCPSPSuite
jobset.hpp
1 #ifndef JOBSET_H
2 #define JOBSET_H
3 
4 #include <iostream> // for basic_ostream
5 #include <set> // for set
6 #include <utility> // for pair
7 #include "../instance/job.hpp" // for Job, Job::JobId
8 
9 class JobSet {
10 public:
11  using JobId = Job::JobId;
12 
13  // Default constructor. *Must* spit out the neutral element!
14  JobSet();
15  JobSet(JobId job, double amount); // initialize with only one job
16 
17  inline void add(JobId job, double amount);
18  inline void remove(JobId job, double amount);
19  JobSet & operator+=(const JobSet & rhs);
20  JobSet & operator-=(const JobSet & rhs);
21 
22  const auto & get() const;
23 
24  double get_amount() const;
25 
26  // TODO speed this up by hashing
27  bool operator==(const JobSet &rhs) const;
28 private:
29  std::set<std::pair<JobId, double>> content;
30  double amount;
31 
32  template<class _CharT, class _Traits>
33  friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& stream, const JobSet & jobset);
34 };
35 
36 /*
37  * Debug output methods
38  */
39 
40 template<class _CharT, class _Traits>
41 std::basic_ostream<_CharT, _Traits>&
42 operator<<(std::basic_ostream<_CharT, _Traits>& stream, const JobSet & jobset)
43 {
44  stream << "JS([";
45  bool first = true;
46  for (const auto & entry : jobset.content) {
47  if (!first) {
48  stream << ", ";
49  }
50 
51  stream << "(" << entry.first << ": " << entry.second << ")";
52  first = false;
53  }
54 
55  stream << "], " << jobset.amount << ")";
56  return stream;
57 }
58 #endif