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

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

Fixes too few degrees of freedom

File size: 4.8 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 = -3/** Solver reached iteration limit. */,
31    computationError = -2/** Some error was made in the computations. */,
32    notEnoughFreedom = -1/** not enough degrees of freedom.*/,
33    illDefinedProblem = -4/** The solver finds that the problem is not well defined. */,
34    illegalOption =-5/** An option is not valid. */,
35    externalException =-6/** Some unrecovered exception occured in an external tool used by the solver. */,
36    exception =-7/** Some unrocevered exception */,
37    solvedOptimal = 1/** Problem solved to an optimal solution.*/,
38    solvedOptimalTol =2/** Problem solved to "acceptable level of tolerance. */,
39    provenInfeasible =3/** Infeasibility Proven. */,
40    unbounded = 4/** Problem is unbounded.*/
41  };
42
43
44
45//#############################################################################
46
47  /** We will throw this error when a problem is not solved.
48      Eventually store the error code from solver*/
49  class UnsolvedError
50  {
51  public:
52    /** Constructor */
53    UnsolvedError(int errorNum):errorNum_(errorNum)
54    {}
55    /** Print error message.*/
56    void printError(std::ostream & os);
57    /** Get the string corresponding to error.*/
58    virtual const std::string& errorName() const = 0;
59    /** Return the name of the solver. */
60    virtual const std::string& solverName() const = 0;
61    /** Return error number. */
62    int errorNum() const{
63    return errorNum_;}
64    /** destructor. */
65    virtual ~UnsolvedError(){}
66  private:
67    int errorNum_;
68  }
69  ;
70
71  virtual UnsolvedError * newUnsolvedError(int num) = 0;
72 
73
74
75  /// Constructor
76   TNLPSolver();
77
78  ///virtual constructor
79  virtual TNLPSolver * createNew() = 0;
80 
81
82   /// Virtual destructor
83   virtual ~TNLPSolver();
84
85   /** Initialize the TNLPSolver (read options from params_file)
86   */
87   virtual void Initialize(std::string params_file) = 0;
88
89   /** Initialize the TNLPSolver (read options from istream is)
90   */
91   virtual void Initialize(std::istream& is) = 0;
92
93   /** @name Solve methods */
94   //@{
95   /// Solves a problem expresses as a TNLP
96   virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
97
98   /// Resolves a problem expresses as a TNLP
99   virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
100
101  /// Set the warm start in the solver
102  virtual bool setWarmStart(const CoinWarmStart * warm, 
103                            Ipopt::SmartPtr<TMINLP2TNLP> tnlp) = 0;
104
105  /// Get the warm start form the solver
106  virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
107
108  virtual CoinWarmStart * getEmptyWarmStart() const = 0;
109
110  /// Enable the warm start options in the solver
111  virtual void enableWarmStart() = 0;
112
113  /// Disable the warm start options in the solver
114  virtual void disableWarmStart() = 0;
115   //@}
116
117  ///Get a pointer to a journalist
118  virtual Ipopt::SmartPtr<Ipopt::Journalist> Jnlst() = 0;
119
120   ///Get a pointer to RegisteredOptions (generally used to add new ones)
121   virtual Ipopt::SmartPtr<Ipopt::RegisteredOptions> RegOptions() = 0;
122
123   /// Get the options (for getting theur values).
124   virtual Ipopt::SmartPtr<const Ipopt::OptionsList> Options() const = 0;
125
126   /// Get the options (for getting and setting their values).
127   virtual Ipopt::SmartPtr<Ipopt::OptionsList> Options() = 0;
128
129   /// Register this solver options into passed roptions
130   virtual void RegisterOptions(Ipopt::SmartPtr<Ipopt::RegisteredOptions> roptions) = 0;
131
132   /// Get the CpuTime of the last optimization.
133   virtual double CPUTime() = 0;
134
135   /// Get the iteration count of the last optimization.
136   virtual int IterationCount() = 0;
137
138
139  /// turn off all output from the solver
140  virtual void turnOffOutput() = 0 ;
141  /// turn on all output from the solver
142  virtual void turnOnOutput() = 0;
143  /// Get the solver name
144  virtual std::string & solverName() = 0;
145protected:
146  bool zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp, 
147                     ReturnStatus &optimization_status);
148   private:
149   /// There is no copy constructor for this class
150   TNLPSolver(TNLPSolver &other); 
151};
152}
153#endif
154
155
Note: See TracBrowser for help on using the repository browser.