MineLink
 All Data Structures Functions Variables Pages
cbc_fractional_scheduler.h
1 
2 #ifndef __CBCFractionalScheduler_H__
3 #define __CBCFractionalScheduler_H__
4 
5 #include <string>
6 #include <sstream>
7 #include <map>
8 #include <typeinfo>
9 #include "fractional_scheduler.h"
10 #include "cbc_model.h"
11 #include "../../../problems/scheduling/filtering.h"
12 #include <iostream>
13 
14 namespace delphos{
15 
16 
21 private:
22 
23  CBCModel* _cmodel;
24  //BlockIndexType* _colid;
25  //unsigned long _rowcount;
26  //vector<string> _options;
27  //bool _novar;
28  unsigned int _loglevel;
29  unsigned int _numthread;
30  double _objvalue;
31  bool _bmodelcreated;
32 
33  bool _created_vars;
34  string _logfile;
35  Model::OptimizationSense _optimization_sense;
36 
37  bool CreateVariables();
38  //bool CreateGoalFunction();
39  bool CreateCoreConstraints();
40  bool CreateUserConstraints();
41 
42 
43  void ApplyPrecedenceConstraint(const PrecedenceConstraint& pc);
44  void ApplyAttributeSumConstraint(const AttributeSumConstraint& asc);
45  void ApplyAttributeAvgConstraint(const AttributeAvgConstraint& asc);
46  void ApplyDoNotMineBeforeConstraint(const DoNotMineBeforeConstraint& dc);
47  void ApplyForceMiningByConstraint(const ForceMiningByConstraint& fc);
48  void ApplyDoNotSendToConstraint(const DoNotSendToConstraint& dnsc);
49  void ApplyGeometricConstraint(const GeometricConstraint& gc);
50  void ApplyMinExtractPeriodConstraint(const MinExtractPeriodConstraint& mepc);
51  void ApplyBlockSelectionPrecedenceConstraint(const BlockSelectionPrecedenceConstraint& bspc);
52  void ApplyConstraint(const Constraint& ctr);
53 
54  bool SetFractionalSchedule();
55  bool CreateGoalFunction();
56  vector<BlockIndexType> _index_in_bs;
57  unsigned long _nb_prec;
58 
59 public:
60 #ifndef DOXYGEN
61  Variable ProcVar(
62  const BlockIndexType& block_index,
63  const unsigned int& period,
64  const unsigned int& destination);
65 
66  Variable StockVar(
67  const unsigned int& stock_index,
68  const unsigned int& period,
69  const unsigned int& destination);
70 
71  LinearExpr RealProcVar(
72  const BlockIndexType& block_index,
73  const unsigned int& period,
74  const unsigned int& destination);
75 
76  BlockIndexType ProcVarId(
77  const delphos::BlockIndexType& block_index,
78  const unsigned int& period,
79  const unsigned int& destination);
80 
81  BlockIndexType StockVarId(
82  const unsigned int& stock_index,
83  const unsigned int& period,
84  const unsigned int& destination);
85 
86  static string ProcVarName(
87  const BlockIndexType& block_index,
88  const unsigned int& period,
89  const unsigned int& destination);
90 
91  static string StockVarName(
92  const unsigned long& stock_index,
93  const unsigned int& period,
94  const unsigned int& destination);
95  #endif
96 
102 
106  virtual ~CBCFractionalScheduler();
107 
113  virtual bool Run();
114 
115  #ifndef DOXYGEN
116 
122  void Optimize();
123  #endif
124 
128  const bool IsStock();
129 
135  bool CreateModel();
136 
142  void SetOptimizationSense(const Model::OptimizationSense& sense);
143 
151  void WriteLP(const string outfile);
152  //void WriteSol(const string outfile);
153  //void WriteInfeasibleLP(const string outfile);
154 
158  CBCModel& GetMathematicalModel();
159 
163  double GetObjValue();
164 
169  void AddSetting(const string& setting);
170 
175  void SetLogLevel(const unsigned int& level);
176 
181  void SetNumThread(const unsigned int& nthreads);
182  //const bool UpdatedConstrs() const;
183 
191  const double GetDual(const string& cname);
192 
197  void ComputeExpectedTime(const string column);
198 
203 
208  void SetLogFile(const string& name);
209 
210 };
211 
212 
213 
214 
215 }
216 #endif
217 
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
void SetLogLevel(const unsigned int &level)
Set the nivel of log.
Definition: cbc_fractional_scheduler.cpp:929
Defines a scheduling instance to be solved.
Definition: instance.h:41
bool CreateModel()
Inits the solver and load the model in CBC.
Definition: cbc_fractional_scheduler.cpp:215
A constraint that prevents certain blocks to be sent to given processes.
Definition: filtering.h:107
void SetNumThread(const unsigned int &nthreads)
Set the number of threads used by CBC.
Definition: cbc_fractional_scheduler.cpp:934
A constraint on the average values of attributes of blocks.
Definition: constraint.h:426
CBCModel & GetMathematicalModel()
Returns the mathematical model.
Definition: cbc_fractional_scheduler.cpp:54
Abstracts a CBC LP solver that can solve a scheduling instance.
Definition: cbc_fractional_scheduler.h:20
void SetOptimizationSense(const Model::OptimizationSense &sense)
Set the sense of the optimization model.
Definition: cbc_fractional_scheduler.cpp:967
void SetLogFile(const string &name)
Set the use of the log with given file name.
Definition: cbc_fractional_scheduler.cpp:1226
A geometric constraint.
Definition: constraint.h:632
const double GetDual(const string &cname)
Returns the dual value of given constraint.
Definition: cbc_fractional_scheduler.cpp:299
A constraint that forces a block to be mined before or at some period.
Definition: filtering.h:19
virtual bool Run()
Generates the model in CBC and optimize it.
Definition: cbc_fractional_scheduler.cpp:181
Defines a fractional scheduling of blocks.
Definition: fractional_schedule.h:22
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: cbc_fractional_scheduler.cpp:270
CBCFractionalScheduler(delphos::SchedulingInstance &si)
Creates a CBC fractional scheduler with given scheduling instance.
Definition: cbc_fractional_scheduler.cpp:42
void ComputeExpectedTime(const string column)
Computes the expected times.
Definition: cbc_fractional_scheduler.cpp:1096
Defines the base class for all constraints.
Definition: constraint.h:33
const delphos::FractionalSchedule & GetFractionalSchedule()
Returns the result fractional schedule.
Definition: cbc_fractional_scheduler.cpp:1091
virtual ~CBCFractionalScheduler()
The destructor.
Definition: cbc_fractional_scheduler.cpp:254
A precedence constraint.
Definition: constraint.h:513
A block selection precedence constraint.
Definition: constraint.h:572
Dummy class that define required methods for a solver of a scheduling instance.
Definition: fractional_scheduler.h:14
void WriteLP(const string outfile)
Writes the LP model in given file.
Definition: cbc_fractional_scheduler.cpp:289
const bool IsStock()
Return true only if the inner scheduling instance has stoks.
Definition: cbc_fractional_scheduler.cpp:949
void AddSetting(const string &setting)
Adds a setting for the solve process.
Definition: cbc_fractional_scheduler.cpp:312