MineLink
 All Data Structures Functions Variables Pages
gurobimipscheduler.h
1 
2 #ifndef __GUROBIMIPSCHEDULER_H__
3 #define __GUROBIMIPSCHEDULER_H__
4 
5 #include <algorithm>
6 #include <string>
7 #include <sstream>
8 #include <map>
9 #include <typeinfo>
10 #include "named.h"
11 #include "mip_scheduler.h"
12 #include "gurobi_model.h"
13 #include "../../../problems/scheduling/filtering.h"
14 #include <iostream>
15 
16 
17 namespace delphos{
18 
23 private:
24  GurobiModel* _gmodel;
25 
26  bool CreateGoalFunction();
27  bool CreateCoreConstraints();
28 
29  bool _bmodelcreated;
30 
31  void ApplyPrecedenceConstraint(const PrecedenceConstraint& pc);
32  void ApplyAttributeSumConstraint(const AttributeSumConstraint& asc);
33  void ApplyAttributeAvgConstraint(const AttributeAvgConstraint& asc);
34  void ApplyDoNotMineBeforeConstraint(const DoNotMineBeforeConstraint& dc);
35  void ApplyForceMiningByConstraint(const ForceMiningByConstraint& fc);
36  void ApplyDoNotSendToConstraint(const DoNotSendToConstraint& dnsc);
37  void ApplyGeometricConstraint(const GeometricConstraint& gc);
38  void ApplyMinExtractPeriodConstraint(const MinExtractPeriodConstraint& mepc);
39  void ApplyBlockSelectionPrecedenceConstraint(const BlockSelectionPrecedenceConstraint& bsprc);
40 
41  BlockIndexType* _index_in_bs;
42  bool _buser_constraintscreated;
43 
44  BlockIndexType ProcVarId(
45  const BlockIndexType & block_index,
46  const unsigned int & period,
47  const unsigned int & destination);
48 
49  Variable& ProcVar(
50  const BlockIndexType& block_index,
51  const unsigned int& period,
52  const unsigned int& destination);
53 
54  unsigned long _nb_prec;
55 
56  inline void unsigned_to_decimal( unsigned long number, char* buffer )
57  {
58  if( number == 0 )
59  {
60  *buffer++ = '0';
61  }
62  else
63  {
64  char* p_first = buffer;
65  while( number != 0 )
66  {
67  *buffer++ = '0' + number % 10;
68  number /= 10;
69  }
70  reverse( p_first, buffer );
71  }
72  *buffer = '\0';
73  }
74 
75 public:
76 
81  bool SetSchedule();
82 
83  #ifndef DOXYGEN
84  Variable& StockVar(
85  const unsigned int& stock_index,
86  const unsigned int& period,
87  const unsigned int& destination);
88 
89  LinearExpr RealProcVar(
90  const BlockIndexType& block_index,
91  const unsigned int& period,
92  const unsigned int& destination);
93  #endif
94 
101 
105  virtual ~GurobiMIPScheduler();
106 
112  virtual bool Run();
113 
114  #ifndef DOXYGEN
115 
121  void Optimize();
122  #endif
123 
127  const delphos::Schedule & GetSchedule();
128 
134  bool CreateModel();
135 
139  bool CreateVariables();
140 
144  bool CreateUserConstraints();
145 
153  void WriteLP(const string outfile);
154 
162  void WriteSol(const string outfile);
163  //void WriteInfeasibleLP(const string outfile);
164 
168  GurobiModel& GetMathematicalModel();
169 
173  double GetObjValue();
174 
182  const double GetDual(const string& cname);
183 
187  double GetMIPGap();
188 
189 };
190 
191 
192 
193 
194 }
195 #endif
196 
bool CreateUserConstraints()
Creates the user constraints of the model.
Definition: gurobimipscheduler.cpp:399
bool SetSchedule()
Set The result schedule This method put the result from the gurobi optimization into a schedule...
Definition: gurobimipscheduler.cpp:1441
virtual ~GurobiMIPScheduler()
The destructor.
Definition: gurobimipscheduler.cpp:33
A constraint on the addition of the attributes of a block.
Definition: constraint.h:264
A constraint limiting the period at which a block should be mined.
Definition: filtering.h:62
bool CreateVariables()
Creates the variables of the model.
Definition: gurobimipscheduler.cpp:77
bool CreateModel()
Inits the solver and load the model in gurobi.
Definition: gurobimipscheduler.cpp:449
const delphos::Schedule & GetSchedule()
Returns the result schedule.
Definition: gurobimipscheduler.cpp:1584
Defines a scheduling instance to be solved.
Definition: instance.h:41
A constraint that prevents certain blocks to be sent to given processes.
Definition: filtering.h:107
virtual void Optimize()
Optimizes the model.
Definition: mip_scheduler.cpp:61
void WriteLP(const string outfile)
Writes the LP model in given file.
Definition: gurobimipscheduler.cpp:1539
A constraint on the average values of attributes of blocks.
Definition: constraint.h:426
const double GetDual(const string &cname)
Returns the dual value of given constraint.
Definition: gurobimipscheduler.cpp:1554
GurobiMIPScheduler(delphos::SchedulingInstance &si)
Creates a gurobi MIP scheduler with given scheduling instance.
Definition: gurobimipscheduler.cpp:18
A geometric constraint.
Definition: constraint.h:632
A constraint that forces a block to be mined before or at some period.
Definition: filtering.h:19
void WriteSol(const string outfile)
Writes the solution in given file.
Definition: gurobimipscheduler.cpp:1546
A constraint that prevents certain blocks that can't be extracted before a period due to capacities c...
Definition: filtering.h:178
double GetObjValue()
Returns the objective value of the optimized model.
Definition: gurobimipscheduler.cpp:523
Abstracts a Gurobi MIP solver that can solve a scheduling instance.
Definition: gurobimipscheduler.h:22
Dummy class that define required methods for a MIP solver of a scheduling instance.
Definition: mip_scheduler.h:24
GurobiModel & GetMathematicalModel()
Return the mathematical model.
Definition: gurobimipscheduler.cpp:518
A precedence constraint.
Definition: constraint.h:513
A block selection precedence constraint.
Definition: constraint.h:572
Defines a scheduling of blocks.
Definition: schedule.h:23
virtual bool Run()
Generates the model in Gurobi and optimize it.
Definition: gurobimipscheduler.cpp:411
double GetMIPGap()
Returns the relative integer gap.
Definition: gurobimipscheduler.cpp:1589