MineLink
 All Data Structures Functions Variables Pages
etheuristics.h
1 #ifndef __ETHEURISTICS_H__
2 #define __ETHEURISTICS_H__
3 
4 #include "../heuristics.h"
5 #ifndef NO_GUROBI
6  #include "../../fractional_scheduler/bz/gurobi_bz.h"
7  #include "gurobi_model.h"
8 #endif
9 #ifdef CBC
10  #include "../../fractional_scheduler/bz/cbc_bz.h"
11  #include "cbc_model.h"
12 #endif
13 #include <algorithm>
14 #include <vector>
15 //#include <typeinfo>
16 
17 using namespace std;
18 
19 
20 
21 namespace delphos {
22 
30 public:
36 };
37 
45 protected:
46  vector<double> _exptime;
47 public:
53  RankedFractionalScheduleToSchedule(delphos::SchedulingInstance & si,const vector<double>& exptime);
58 };
59 
60 //void mycallback(const double& percentage);
61 
69 private:
70  //bool _bUseET;
71  //vector<int> _tmin;
72  BlockIndexType _nb_blk_with_exptime_in_horizon;
73 
74  typedef struct node {
75  set<BlockIndexType> precedenceSet;
76  set<BlockIndexType> succSet;
77  BlockIndexType number;
78  float w;
79  }Node;
80 
81  typedef struct ress{
82  set<unsigned int> index;
83  string attr;
84  float min;
85  float max;
86  unsigned int period;
87  }Ress;
88 
89  vector<Node>* CreateGraph();
90  BlockIndexType* TopoSort();
91 
92 public:
103  TopoHeuristic(delphos::SchedulingInstance & si,const vector<double>& exptime);//,const bool bUseET=true);
104 
108  ~TopoHeuristic();
109 
113  bool Run();
114 
115 };
116 
117 #ifndef ACADEMIC
118 
121 class ETDelta: public RankedFractionalScheduleToSchedule {
122 private:
123  const float _delta;
124  Model::OptimizationSense _optimization_sense;
125  Model::Emphasis _mip_emphasis;
126  float _mipgap;
127  string _logfile;
128  string _sched_name;
129 public:
140  ETDelta(delphos::SchedulingInstance& si,const vector<double>& exptime,float delta=0.5
141 #ifndef NO_GUROBI
142  ,const string& sched_name=Scheduler::GUROBI_MIPScheduler);
143 #else
144  ,const string& sched_name=Scheduler::CBC_MIPScheduler);
145 #endif
146 
150  bool Run();
151 
157  void SetOptimizationSense(const Model::OptimizationSense& sense);
158 
163  void SetLogFile(const string& name);
164 
168  void SetGap(const float& gap);
169 
174  void SetMIPEmphasis(const Model::Emphasis& emphasis);
175 };
176 
184 class ETInc: public RankedFractionalScheduleToSchedule {
185 private:
186  Model::OptimizationSense _optimization_sense;
187  Model::Emphasis _mip_emphasis;
188  float _mipgap;
189  string _logfile;
190  const unsigned int _windowsize;
191  const float _delta;
192  const unsigned int _step;
193  string _sched_name;
194 public:
211  ,const vector<double>& exptime
212  ,const unsigned int windowsize=1
213  , const float delta=0.5
214  , const unsigned int step=1
215 #ifndef NO_GUROBI
216  ,const string& sched_name=Scheduler::GUROBI_MIPScheduler);
217 #else
218  ,const string& sched_name=Scheduler::CBC_MIPScheduler);
219 #endif
220 
221 
225  bool Run();
226 
232  void SetOptimizationSense(const Model::OptimizationSense& sense);
233 
238  void SetLogFile(const string& name);
239 
243  void SetGap(const float& gap);
244 
249  void SetMIPEmphasis(const Model::Emphasis& emphasis);
250 };
251 #endif
252 
257 public:
266 
270  virtual ~BZHeuristic();
271 
275  virtual bool Run();
276 
280  bool RunBZ(unsigned int nbitermax=1000000);
281 
285  void SetMipAsPitSolver();
286 
291  double* GetRelaxedSol();
292 
297  double* GetRelaxedDecisionSol();
298 
303  vector<double> GetExpectedTime();
304 
309  bool SetExpectedTime(const string& column);
310 
315  bool ExpectedTimeToTextFile(const char * exptime_file) const;
316 
321  bool RunTopoHeur();//const bool& TE=true);
322 
336 #ifndef ACADEMIC
337  bool RunETInc(const unsigned int& windowsize=1, const float& delta=0.5, const unsigned int& step=1
338 #ifndef NO_GUROBI
339  ,const string& sched_name=Scheduler::GUROBI_MIPScheduler);
340 #else
341  ,const string& sched_name=Scheduler::CBC_MIPScheduler);
342 #endif
343 
351  bool RunETDelta(const float& delta=0.5
352 #ifndef NO_GUROBI
353  ,const string& sched_name=Scheduler::GUROBI_MIPScheduler);
354 #else
355  ,const string& sched_name=Scheduler::CBC_MIPScheduler);
356 #endif
357 #endif
358 
365  void SetHeurParameters(const unsigned int& windowsize, const float& delta, const unsigned int& step);
366 
371  bool CheckRelaxedSol();
372 
379  bool RelaxedSolToTextFile(const char * relsol_file, const char* stocks_file="") ;
380 
384  void SetGap(const double & gap);
385 
389  const double GetGap() const;
390 
395  void SetEmphasis(const Model::Emphasis & emph);
396 
400  const Model::Emphasis GetEmphasis() const;
401 
406  double GetRelaxedObj();
407 
412  unsigned int GetNBIterationsBZ();
413 
418  const map<string,double>& GetBZDuals();
419 
424  bool IsFeasible();
425 
426 
427 private:
428 
429  BZ* _pflpsolver;
430 
431  bool _use_mip_as_pitsolver;
432 
433  unsigned int _nb_iterations_bz;
434  double _relobjvalue;
435 
436  vector<double> _exptime;
437  unsigned int* _tmin;
438 
439  //bool _stocks;
440 
441  unsigned int _K;
442  float _delta;
443  unsigned int _eps;
444  bool _TEIncParameterIsSet;
445 
446  Model::Emphasis _emph;
447  double _gap;
448  Model::OptimizationSense _sense;
449  string _logfile;
450 
451  double _max_cost;
452  SchedulingInstance & GetInstance();
453  //map<BlockIndexType,bool> _assigned_vars;
454 
455  bool _optimized;
456 };
457 
458 
459 
460 #endif
461 }
Dummy class that define required methods for a Bienstock Zuckerberg solver of a scheduling instance...
Definition: bz.h:14
Dummy class that define required methods for a fractional schedule to schedule heuristic that solve a...
Definition: etheuristics.h:29
Defines a scheduling instance to be solved.
Definition: instance.h:41
Dummy class that define required methods for a heuristic that solve a scheduling instance.
Definition: heuristics.h:18
A dummy class that specifies the methods of an algorithm that can solve a final pit instance...
Definition: fp.h:57
Dummy class that define required methods for a ranked fractional schedule to schedule heuristic that ...
Definition: etheuristics.h:44
Class that defines a modified Topological sort heuristic that solve a scheduling instance. Only PrecedenceConstraint and AttributeSumConstraint are supported. Use of BlockSelection not null in Constraints not implemented. An attempt of considering AttributeAvgConstraint is implemented.
Definition: etheuristics.h:68
Class that defines heuristics that use expected times for blocks, computed by Bienstock Zuckerberg al...
Definition: etheuristics.h:256