Blis 0.94
Loading...
Searching...
No Matches
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-2019, 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
41class BlisModel;
42
43
44//#############################################################################
45
46
49
50 private:
51
53 BlisHeuristic & operator = (const BlisHeuristic& rhs);
54
55 protected:
56
59
61 char *name_;
62
71
74
77
79 double time_;
80
82 int calls_;
83
86
87public:
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
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
@ BlisHeurStrategyAuto
Definition Blis.h:81
Heuristic base class.
BlisModel * model_
Pointer to the model.
int noSolCalls() const
Number called and no cons found.
void addCalls(int c=1)
Record number of times called.
virtual BlisHeuristic * clone() const
Clone a heuristic.
virtual void setModel(BlisModel *model)
update model (This is needed if cliques update matrix etc).
double time_
Used CPU/User time.
virtual void setStrategy(BlisHeurStrategy strategy)
Get/set strategy.
virtual void setHeurCallFrequency(int freq)
Get/set call frequency.
int numSolutions_
Number of solutions found.
BlisHeuristic(BlisModel *model, const char *name, BlisHeurStrategy strategy, int heurCallFrequency)
Useful constructor.
virtual ~BlisHeuristic()
Distructor.
void addNoSolCalls(int n=1)
Increase the number of no cons called.
BlisHeuristic(const BlisHeuristic &rhs)
Copy constructor.
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...
int heurCallFrequency_
The frequency with which to call the heuristic.
int numSolutions() const
Number of solutions found.
void addTime(double t=0.0)
Record Cpu time used.
BlisHeuristic()
Default Constructor.
double time() const
Cpu time used.
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...
int calls() const
Number of times called.
char * name_
Heuristics name.
BlisHeurStrategy strategy_
When to call findSolution() routine.
void addNumSolutions(int num=1)
Record number of solutions found.
int noSolsCalls_
The times of calling this heuristic and no solutions found.
const char * name() const
return name of generator.
virtual int heurCallFrequency() const
int calls_
The times of calling this heuristic.
virtual BlisHeurStrategy strategy() const