Debian Codegraph @

Bonmin/src/CbcBonmin/Heuristics/BonLocalSolverBasedHeuristic.hpp

raw
1 // (C) Copyright CNRS
2 // This code is published under the Eclipse Public License.
3 //
4 // Authors :
5 // Pierre Bonami, LIF Université de la Méditérannée-CNRS
6 //
7 // Date : 06/18/2008
8
9 #ifndef BonLocalSolverBasedHeuristic_H
10 #define BonLocalSolverBasedHeuristic_H
11 #include "BonBonminSetup.hpp"
12 #include "CbcHeuristic.hpp"
13
14 namespace Bonmin {
15 class LocalSolverBasedHeuristic : public CbcHeuristic {
16 public:
17 /** Default constructor.*/
18 LocalSolverBasedHeuristic();
19
20 /** Constructor with setup.*/
21 LocalSolverBasedHeuristic(BonminSetup * setup);
22
23 /** Copy constructor.*/
24 LocalSolverBasedHeuristic(const LocalSolverBasedHeuristic & other);
25
26 /** Destructor.*/
27 ~LocalSolverBasedHeuristic();
28
29 /** Virtual copy constructor.*/
30 virtual CbcHeuristic * clone() const = 0;
31
32 /// Assignment operator
33 LocalSolverBasedHeuristic & operator=(const LocalSolverBasedHeuristic& rhs);
34
35 #if 0
36 /// update model (This is needed if cliques update matrix etc)
37 virtual void setModel(CbcModel * model){throw -1;}
38 #endif
39 /// Resets stuff if model changes
40 virtual void resetModel(CbcModel * model){
41 setModel(model);
42 }
43
44 /** Change setup used for heuristic.*/
45 void setSetup(BonminSetup * setup){
46 setup_ = setup;
47 Initialize(setup_->options());
48 }
49 /** Performs heuristic */
50 virtual int solution(double & objectiveValue,
51 double * newSolution)=0;
52
53 /** Performs heuristic which adds cuts */
54 virtual int solution(double & objectiveValue,
55 double * newSolution,
56 OsiCuts & cs) {return 0;}
57
58
59 /** Do a local search based on setup and passed solver.*/
60 int doLocalSearch(OsiTMINLPInterface * solver,
61 double *solution,
62 double & solValue,
63 double cutoff, std::string prefix = "local_solver.") const;
64
65 /** Register the options common to all local search based heuristics.*/
66 static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
67
68 /** Setup the defaults.*/
69 virtual void setupDefaults(Ipopt::SmartPtr<Ipopt::OptionsList> options);
70
71 /** Initiaize using passed options.*/
72 void Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options);
73 protected:
74 /** Setup to use for local searches (will make copies).*/
75 BonminSetup * setup_;
76
77 static void changeIfNotSet(Ipopt::SmartPtr<Ipopt::OptionsList> options,
78 std::string prefix,
79 const std::string &option,
80 const std::string &value);
81
82 static void changeIfNotSet(Ipopt::SmartPtr<Ipopt::OptionsList> options,
83 std::string prefix,
84 const std::string &option,
85 const double &value);
86
87 static void changeIfNotSet(Ipopt::SmartPtr<Ipopt::OptionsList> options,
88 std::string prefix,
89 const std::string &option,
90 const int &value);
91 private:
92 /** Time limit in local search.*/
93 double time_limit_;
94 /** maximal number of nodes in local search.*/
95 int max_number_nodes_;
96 /** Maximal number of solutions in local search.*/
97 int max_number_solutions_;
98 };
99 } /** ends namespace Bonmin.*/
100
101 #endif
102