BlisHeuristic.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the BiCePS Linear Integer Solver (BLIS). *
3  * *
4  * BLIS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Ted Ralphs, Lehigh University *
11  * *
12  * Conceptual Design: *
13  * *
14  * Yan Xu, Lehigh University *
15  * Ted Ralphs, Lehigh University *
16  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17  * Matthew Saltzman, Clemson University *
18  * *
19  * *
20  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21  * All Rights Reserved. *
22  *===========================================================================*/
23 
24 
25 //#############################################################################
26 // This file is modified from COIN/Cbc/CbcHeuristic.hpp
27 //#############################################################################
28 
29 
30 #ifndef BlisHeuristic_h_
31 #define BlisHeuristic_h_
32 
33 #include <string>
34 #include <vector>
35 
36 #include "CoinPackedMatrix.hpp"
37 #include "OsiCuts.hpp"
38 
39 #include "Blis.h"
40 
41 class BlisModel;
42 
43 
44 //#############################################################################
45 
46 
48 class BlisHeuristic {
49 
50  private:
51 
54 
55  protected:
56 
59 
61  char *name_;
62 
71 
74 
76  int numSolutions_;
77 
79  double time_;
80 
82  int calls_;
83 
86 
87 public:
88 
91  model_ = NULL;
92  name_ = strdup("Unknown");
95  numSolutions_ = 0;
96  time_ = 0.0;
97  calls_ = 0;
98  noSolsCalls_ = 0;
99  }
100 
102  BlisHeuristic(BlisModel *model, const char *name,
104  model_ = model;
105  if (name) {
106  name_ = strdup(name);
107  }
108  else {
109  name_ = strdup("Unknown");
110  }
113  numSolutions_ = 0;
114  time_ = 0.0;
115  calls_ = 0;
116  noSolsCalls_ = 0;
117  }
118 
120  virtual ~BlisHeuristic() { if (name_) free(name_); }
121 
123  BlisHeuristic(const BlisHeuristic & rhs) {
124  model_ = rhs.model_;
125  name_ = strdup(rhs.name_);
126  strategy_ = rhs.strategy_; // What if disabled?
128  numSolutions_ = 0;
129  time_ = 0.0;
130  calls_ = 0;
131  noSolsCalls_ = 0;
132  }
133 
135  virtual void setModel(BlisModel * model) { model_ = model ;}
136 
140  virtual BlisHeurStrategy strategy() const { return strategy_; }
141  //@]
142 
145  virtual void setHeurCallFrequency(int freq) { heurCallFrequency_ = freq; }
146  virtual int heurCallFrequency() const { return heurCallFrequency_; }
147  //@]
148 
150  virtual BlisHeuristic * clone() const {
151  BlisHeuristic *h = NULL;
152  assert(0);
153  return h;
154  }
155 
161  virtual bool searchSolution(double & objectiveValue,
162  double * newSolution)=0;
163 
172  virtual bool searchSolution(double & objectiveValue,
173  double * newSolution,
174  OsiCuts & cs) { return 0; }
175 
177  inline const char * name() const { return name_; }
178 
180  inline void addNumSolutions(int num=1) { numSolutions_ += num; }
181 
183  inline int numSolutions() const { return numSolutions_; }
184 
186  inline void addTime(double t=0.0) { time_ += t; }
187 
189  inline double time() const { return time_; }
190 
192  inline void addCalls(int c=1) { calls_ += c; }
193 
195  inline int calls() const { return calls_; }
196 
198  inline int noSolCalls() const { return noSolsCalls_; }
199 
201  inline void addNoSolCalls(int n=1) { noSolsCalls_ += n; }
202 };
203 
204 #endif
205 
BlisHeurStrategy
Definition: Blis.h:77
void addNumSolutions(int num=1)
Record number of solutions found.
virtual bool searchSolution(double &objectiveValue, double *newSolution, OsiCuts &cs)
returns 0 if no solution, 1 if valid solution, -1 if just returning an estimate of best possible solu...
virtual int heurCallFrequency() const
Get/set strategy.
BlisHeuristic & operator=(const BlisHeuristic &rhs)
Illegal Assignment operator.
Heuristic base class.
Definition: BlisHeuristic.h:46
virtual void setModel(BlisModel *model)
update model (This is needed if cliques update matrix etc).
int noSolsCalls_
The times of calling this heuristic and no solutions found.
Definition: BlisHeuristic.h:85
int noSolCalls() const
Number called and no cons found.
void addNoSolCalls(int n=1)
Increase the number of no cons called.
int calls() const
Number of times called.
int strategy_
When to call findSolution() routine.
Definition: BlisHeuristic.h:67
virtual BlisHeurStrategy strategy() const
Get/set strategy.
int heurCallFrequency_
The frequency with which to call the heuristic.
Definition: BlisHeuristic.h:73
virtual BlisHeuristic * clone() const
Clone a heuristic.
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
BlisHeurStrategy strategy_
When to call findSolution() routine.
Definition: BlisHeuristic.h:70
virtual void setHeurCallFrequency(int freq)
Get/set call frequency.
virtual ~BlisHeuristic()
Distructor.
BlisHeuristic(const BlisHeuristic &rhs)
Copy constructor.
int numSolutions_
Number of solutions found.
Definition: BlisHeuristic.h:70
virtual void setStrategy(BlisHeurStrategy strategy)
Get/set strategy.
double time() const
Cpu time used.
double time_
Used CPU/User time.
Definition: BlisHeuristic.h:73
int numSolutions() const
Number of solutions found.
const char * name() const
return name of generator.
BlisModel * model_
Pointer to the model.
Definition: BlisHeuristic.h:56
char * name_
Heuristics name.
Definition: BlisHeuristic.h:59
void addCalls(int c=1)
Record number of times called.
void addTime(double t=0.0)
Record Cpu time used.
int calls_
The times of calling this heuristic.
Definition: BlisHeuristic.h:76
BlisHeuristic()
Default Constructor.
Definition: BlisHeuristic.h:90
BlisHeuristic(BlisModel *model, const char *name, BlisHeurStrategy strategy, int heurCallFrequency)
Useful constructor.
virtual bool searchSolution(double &objectiveValue, double *newSolution)=0
returns 0 if no solution, 1 if valid solution with better objective value than one passed in Sets sol...
virtual int strategy()
Get/set strategy.