1 /* $Id$ */
2 // (C) Copyright International Business Machines Corporation 2007
3 // All Rights Reserved.
4 // This code is published under the Eclipse Public License (EPL).
5 //
6 // Authors :
7 // Pierre Bonami, International Business Machines Corporation
8 //
9 // Date : 04/09/2007
10 
11 #ifndef BonIpoptHeuristic_HPP
12 #define BonIpoptHeuristic_HPP
13 
14 #include "BonOsiTMINLPInterface.hpp"
15 #include "CbcHeuristic.hpp"
16 #include "BonOsiTMINLPInterface.hpp"
17 #include "CouenneProblem.hpp"
18 
19 namespace Couenne {
20 
21   /** A heuristic to call an NlpSolver if all CouenneObjects are close
22       to be satisfied (for other integer objects, rounding is
23       performed, if SOS's are not satisfied it does not run).
24    */
25 
26   const double maxNlpInf_0 = 1e-5;
27 
28   class NlpSolveHeuristic : public CbcHeuristic{
29 
30   public:
31     /** Default constructor.*/
32     NlpSolveHeuristic();
33     /** Constructor with model and Ipopt problems.*/
34     NlpSolveHeuristic(CbcModel & mip, Bonmin::OsiTMINLPInterface &nlp, bool cloneNlp = false, CouenneProblem * couenne = NULL);
35     /** Copy constructor.*/
36     NlpSolveHeuristic(const NlpSolveHeuristic &other);
37 
38     /** Destructor*/
39     virtual ~NlpSolveHeuristic();
40 
41     /** Clone.*/
42     virtual CbcHeuristic * clone() const;
43 
44     /** Assignment operator */
45     NlpSolveHeuristic & operator=(const NlpSolveHeuristic &rhs);
46 
47     /** Set the nlp solver.*/
48     void setNlp (Bonmin::OsiTMINLPInterface &nlp, bool cloneNlp = true);
49 
50     /** set the couenne problem to use.*/
51     void setCouenneProblem(CouenneProblem *);
52     /** Does nothing. */
resetModel(CbcModel * model)53     virtual void resetModel(CbcModel * model){}
54     /** Run heuristic, return 1 if a better solution than the one passed is found and 0 otherwise.
55         \argument objectiveValue Best known solution in input and value of solution found in output
56         \argument newSolution Solution found by heuristic.
57 	\todo Find a quicker way to get to Couenne objects, store them or something
58     */
59     virtual int solution( double & objectiveValue, double * newSolution);
60     /** set maxNlpInf. */
setMaxNlpInf(double value)61     void setMaxNlpInf(double value){
62       maxNlpInf_ = value;}
63     /** set number of nlp's solved for each given level of the tree*/
setNumberSolvePerLevel(int value)64     void setNumberSolvePerLevel(int value){
65       numberSolvePerLevel_ = value;}
66 
67     /// initialize options
68     static void registerOptions (Ipopt::SmartPtr <Bonmin::RegisteredOptions>);
69 
70   private:
71     /** Pointer to an nlp solver interface.*/
72     Bonmin::OsiTMINLPInterface * nlp_;
73     /** is nlp_ cloned or just a pointer?*/
74     bool hasCloned_;
75     /** maximum nlp infeasibility under which try to solve problem with Ipopt.*/
76     double maxNlpInf_;
77     /** Number of nlp's solved for each given level of the tree*/
78     int numberSolvePerLevel_;
79     /** Pointer to a couenne representation of the problem. */
80     CouenneProblem * couenne_;
81   };
82 
83 }
84 
85 #endif
86