source: branches/devel/Bonmin/src/Interfaces/BonTNLPSolver.hpp @ 90

Last change on this file since 90 was 90, checked in by pbonami, 13 years ago

Bug fixes in interface for filter

File size: 4.7 KB
Line 
1// (C) Copyright International Business Machines (IBM) 2005
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// Pierre Bonami, IBM
7//
8// Date : 26/09/2006
9
10
11#ifndef TNLPSolver_H
12#define TNLPSolver_H
13#include "IpTNLP.hpp"
14#include "BonTMINLP2TNLP.hpp"
15
16//Some declarations
17#include "IpOptionsList.hpp"
18#include "IpRegOptions.hpp"
19#include "CoinWarmStart.hpp"
20
21namespace Bonmin  {
22/** This is a generic class for calling an NLP solver to solve a TNLP.
23    A TNLPSolver is able to solve and resolve a problem, it has some options (stored
24    with Ipopt OptionList structure and registeredOptions) it produces some statistics (in SolveStatisctics and sometimes some errorCodes.
25*/
26class TNLPSolver: public Ipopt::ReferencedObject{
27 public:
28
29  enum ReturnStatus /** Standard return statuses for a solver*/{
30    iterationLimit/** Solver reached iteration limit. */,
31    computationError /** Some error was made in the computations. */,
32    illDefinedProblem /** The solver finds that the problem is not well defined. */,
33    illegalOption /** An option is not valid. */,
34    externalException /** Some unrecovered exception occured in an external tool used by the solver. */,
35    exception /** Some unrocevered exception */,
36    solvedOptimal /** Problem solved to an optimal solution.*/,
37    solvedOptimalTol /** Problem solved to "acceptable level of tolerance. */,
38    provenInfeasible /** Infeasibility Proven. */,
39    unbounded /** Problem is unbounded.*/
40  };
41
42
43
44//#############################################################################
45
46  /** We will throw this error when a problem is not solved.
47      Eventually store the error code from solver*/
48  class UnsolvedError
49  {
50  public:
51    /** Constructor */
52    UnsolvedError(int errorNum):errorNum_(errorNum)
53    {}
54    /** Print error message.*/
55    void printError(std::ostream & os);
56    /** Get the string corresponding to error.*/
57    virtual const std::string& errorName() const = 0;
58    /** Return the name of the solver. */
59    virtual const std::string& solverName() const = 0;
60    /** Return error number. */
61    int errorNum() const{
62    return errorNum_;}
63    /** destructor. */
64    virtual ~UnsolvedError(){}
65  private:
66    int errorNum_;
67  }
68  ;
69
70  virtual UnsolvedError * newUnsolvedError(int num) = 0;
71 
72
73
74  /// Constructor
75   TNLPSolver();
76
77  ///virtual constructor
78  virtual TNLPSolver * createNew() = 0;
79 
80
81   /// Virtual destructor
82   virtual ~TNLPSolver();
83
84   /** Initialize the TNLPSolver (read options from params_file)
85   */
86   virtual void Initialize(std::string params_file) = 0;
87
88   /** Initialize the TNLPSolver (read options from istream is)
89   */
90   virtual void Initialize(std::istream& is) = 0;
91
92   /** @name Solve methods */
93   //@{
94   /// Solves a problem expresses as a TNLP
95   virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
96
97   /// Resolves a problem expresses as a TNLP
98   virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
99
100  /// Set the warm start in the solver
101  virtual bool setWarmStart(const CoinWarmStart * warm, 
102                            Ipopt::SmartPtr<TMINLP2TNLP> tnlp) = 0;
103
104  /// Get the warm start form the solver
105  virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
106
107  virtual CoinWarmStart * getEmptyWarmStart() const = 0;
108
109  /// Enable the warm start options in the solver
110  virtual void enableWarmStart() = 0;
111
112  /// Disable the warm start options in the solver
113  virtual void disableWarmStart() = 0;
114   //@}
115
116  ///Get a pointer to a journalist
117  virtual Ipopt::SmartPtr<Ipopt::Journalist> Jnlst() = 0;
118
119   ///Get a pointer to RegisteredOptions (generally used to add new ones)
120   virtual Ipopt::SmartPtr<Ipopt::RegisteredOptions> RegOptions() = 0;
121
122   /// Get the options (for getting theur values).
123   virtual Ipopt::SmartPtr<const Ipopt::OptionsList> Options() const = 0;
124
125   /// Get the options (for getting and setting their values).
126   virtual Ipopt::SmartPtr<Ipopt::OptionsList> Options() = 0;
127
128   /// Register this solver options into passed roptions
129   virtual void RegisterOptions(Ipopt::SmartPtr<Ipopt::RegisteredOptions> roptions) = 0;
130
131   /// Get the CpuTime of the last optimization.
132   virtual double CPUTime() = 0;
133
134   /// Get the iteration count of the last optimization.
135   virtual int IterationCount() = 0;
136
137
138  /// turn off all output from the solver
139  virtual void turnOffOutput() = 0 ;
140  /// turn on all output from the solver
141  virtual void turnOnOutput() = 0;
142  /// Get the solver name
143  virtual std::string & solverName() = 0;
144protected:
145  bool zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp, 
146                     ReturnStatus &optimization_status);
147   private:
148   /// There is no copy constructor for this class
149   TNLPSolver(TNLPSolver &other); 
150};
151}
152#endif
153
154
Note: See TracBrowser for help on using the repository browser.