TCPSPSuite
fbilp.hpp
1 #ifndef ILP_FBILP_HPP
2 #define ILP_FBILP_HPP
3 
4 #include "../manager/solvers.hpp"
5 #include "generated_config.hpp" // for GUROBI_FOUND
6 #include "ilp.hpp" // for ILPBase
7 #include "../util/log.hpp" // for Log
8 
9 class AdditionalResultStorage;
10 class Instance;
11 class Job;
12 class SolverConfig;
13 namespace solvers {
14 template <unsigned int>
15 struct registry_hook;
16 }
17 
18 #if defined(GUROBI_FOUND)
19 #include "../contrib/ilpabstraction/src/ilpa_gurobi.hpp"
20 #endif
21 
22 #if defined(CPLEX_FOUND)
23 #include "../contrib/ilpabstraction/src/ilpa_cplex.hpp"
24 #endif
25 
26 template <class SolverT>
27 class FBILP : public ILPBase<SolverT> {
28 public:
29  FBILP(const Instance & instance, AdditionalResultStorage & additional,
30  const SolverConfig & sconf);
31 
32  void run();
33  static std::string get_id();
34 
35 private:
36  Log l;
37 
38  using Base = ILPBase<SolverT>;
39  using MIPSolver = typename Base::MIPSolver;
40  using Model = typename Base::Model;
41  using Variable = typename Base::Variable;
42  using Expression = typename Base::Expression;
43  using VarType = typename Base::VarType;
44  using ParamType = typename Base::ParamType;
45  using ModelStatus = typename Base::ModelStatus;
46  using Constraint = typename Base::Constraint;
47 
48  const bool proxy_flow;
49  std::vector<std::optional<const Job *>> proxies;
50 
51  // sequence_vars[i][j] becomes 1 only if i finishes before j starts
52  std::vector<std::unordered_map<unsigned int, Variable>> sequence_vars;
53  // flow_vars[r][i][j] denotes the amout of flow for resource r that flows
54  // from i to j
55  std::vector<std::vector<std::unordered_map<unsigned int, Variable>>>
56  flow_vars;
57  // inflow_vars[r][i] denotes the amount of resource r that i does not receive
58  // from other jobs
59  std::vector<std::vector<Variable>> inflow_vars;
60 
61  void prepare_variables();
62  void prepare_sequence_constraints();
63  void prepare_flow_constraints();
64  void prepare_objective();
65 
66  void prepare();
67 
68  bool dbg_verify_variables();
69 };
70 
71 // Register the solver
72 namespace solvers {
73 #if defined(GUROBI_FOUND)
74 template <>
75 struct registry_hook<
76  solvers::get_free_N<FBILP<ilpabstraction::GurobiInterface>>()>
77 {
78  constexpr static unsigned int my_N =
79  solvers::get_free_N<FBILP<ilpabstraction::GurobiInterface>>();
80 
81  auto
82  operator()()
83  {
84  return solvers::register_class<FBILP<ilpabstraction::GurobiInterface>,
85  my_N>{}();
86  }
87 };
88 #endif
89 
90 #if defined(CPLEX_FOUND)
91 template <>
92 struct registry_hook<
93  solvers::get_free_N<FBILP<ilpabstraction::CPLEXInterface>>()>
94 {
95  constexpr static unsigned int my_N =
96  solvers::get_free_N<FBILP<ilpabstraction::CPLEXInterface>>();
97 
98  auto
99  operator()()
100  {
101  return solvers::register_class<FBILP<ilpabstraction::CPLEXInterface>,
102  my_N>{}();
103  }
104 };
105 #endif
106 } // namespace solvers
107 
108 #endif
Instance
a TCPSP instance
Definition: instance.hpp:24
Job
A job of an TCPSP instance.
Definition: job.hpp:21