TCPSPSuite
dtilp.hpp
1 #ifndef TCPSPSUITE_DTILP_HPP
2 #define TCPSPSUITE_DTILP_HPP
3 
4 #include "../manager/solvers.hpp"
5 #include "ilp.hpp"
6 
7 #if defined(GUROBI_FOUND)
8 #include "../contrib/ilpabstraction/src/ilpa_gurobi.hpp"
9 #endif
10 
11 #if defined(CPLEX_FOUND)
12 #include "../contrib/ilpabstraction/src/ilpa_cplex.hpp"
13 #endif
14 
15 template <class MIPSolverT>
16 class DTILP : public ILPBase<MIPSolverT> {
17 public:
18  DTILP(const Instance & instance, AdditionalResultStorage & additional,
19  const SolverConfig & sconf);
20 
21  void prepare_warmstart();
22  void warmstart_with_fixed(std::vector<bool> fixed_jobs,
23  std::vector<unsigned int> start_pos,
24  unsigned int time_limit,
25  Maybe<double> extension_time_usage_cost_coefficient,
26  Maybe<double> extension_job_usage_cost_coefficient,
27  Maybe<unsigned int> extension_time_limit,
28  Maybe<unsigned int> extension_job_limit);
29  void run();
30  static std::string get_id();
31 
32 private:
33  Log l;
34 
35  using Base = ILPBase<MIPSolverT>;
36  using MIPSolver = typename Base::MIPSolver;
37  using Model = typename Base::Model;
38  using Variable = typename Base::Variable;
39  using Expression = typename Base::Expression;
40  using VarType = typename Base::VarType;
41  using ParamType = typename Base::ParamType;
42  using ModelStatus = typename Base::ModelStatus;
43  using Constraint = typename Base::Constraint;
44 
45  void prepare();
46 
47  // Switch-On-Variables
48  std::vector<std::vector<Variable>> variables;
49 
50  /* First entry: First time step at which the job can be executed (i.e., the
51  * time step that the first switch-on variable is associated with). Second
52  * entry: The number of switch-on variables, i.e., the window size (taking
53  * possible window extension into account). */
54  std::vector<std::pair<unsigned int, unsigned int>> time_step_bounds;
55 
56  // Sum up duration, force overduration
57  void prepare_duration_constraint();
58 
59  // Overduration indicator variables
60  std::vector<std::vector<Variable>> overduration_variables;
61 
62  // Overshoot of each resource in every timestep
63  std::vector<std::vector<Variable>> overshoot_variables;
64 
65  // Overduration / switch-on ANDing
66  // overduration_and_swon_variables[i][x][y] will indicate whether:
67  // job i
68  // - has an overduration of at least y time steps
69  // - and is switched on at (job-relative) time step x
70  std::vector<std::vector<std::vector<Variable>>>
71  overduration_and_swon_variables;
72 
73  void prepare_start_point_constraints();
74 
75  void prepare_variables();
76 
77  // constraint (5) modified s.t. it is not limited
78  // by a value but by a variable
79  void prepare_resource_constraints();
80 
81  // constraint (6)
82  void prepare_job_constraints();
83 
84  // Overshoot costs
85  void prepare_overshoot_costs();
86 
87  void prepare_extension_constraints();
88 
89  // TODO totally switch these three off
90  // Window-left-extension variables
91  // IMPLEMENTATION must define these
92  std::vector<Variable> left_extension_var;
93 
94  // Window-right-extension variables
95  // IMPLEMENTATION must define these
96  std::vector<Variable> right_extension_var;
97 
98  Variable window_extension_time_var;
99  Variable window_extension_job_var;
100  Constraint window_extension_time_constraint;
101  Constraint window_extension_job_constraint;
102 
103  /*
104  * Warmstart-related things
105  */
106  std::vector<bool> job_is_fixed;
107  void fix_job(unsigned int jid, unsigned int time);
108  void unfix_job(unsigned int jid);
109 
110  /*
111  * Options
112  */
113  bool use_sos1_for_starts;
114 
115  void print_profile() const;
116 };
117 
118 // Register the solver
119 namespace solvers {
120 #if defined(GUROBI_FOUND)
121 template <>
122 struct registry_hook<
123  solvers::get_free_N<DTILP<ilpabstraction::GurobiInterface>>()>
124 {
125  constexpr static unsigned int my_N =
126  solvers::get_free_N<DTILP<ilpabstraction::GurobiInterface>>();
127 
128  auto
129  operator()()
130  {
131  return solvers::register_class<DTILP<ilpabstraction::GurobiInterface>,
132  my_N>{}();
133  }
134 };
135 #endif
136 
137 #if defined(CPLEX_FOUND)
138 template <>
139 struct registry_hook<
140  solvers::get_free_N<DTILP<ilpabstraction::CPLEXInterface>>()>
141 {
142  constexpr static unsigned int my_N =
143  solvers::get_free_N<DTILP<ilpabstraction::CPLEXInterface>>();
144 
145  auto
146  operator()()
147  {
148  return solvers::register_class<DTILP<ilpabstraction::CPLEXInterface>,
149  my_N>{}();
150  }
151 };
152 #endif
153 } // namespace solvers
154 
155 #endif // TCPSPSUITE_DTILP_HPP
Instance
a TCPSP instance
Definition: instance.hpp:24