source: branches/devel/Bonmin/src/BonminAmplInterface/BonAmplTMINLP.hpp @ 57

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

Rename file with Bon prefix part II

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 7.7 KB
Line 
1// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2004
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// Carl D. Laird, Carnegie Mellon University,
7// Andreas Waechter, International Business Machines Corporation
8// Pierre Bonami, Carnegie Mellon University,
9//
10// Date : 12/01/2004
11
12#ifndef __IPAMPLTMINLP_HPP__
13#define __IPAMPLTMINLP_HPP__
14
15#include "BonTMINLP.hpp"
16#include "IpSmartPtr.hpp"
17#include "CoinPackedMatrix.hpp"
18#include "OsiCuts.hpp"
19// Declarations, so that we don't have to include the Ipopt AMPL headers
20namespace Ipopt{
21  class AmplTNLP;
22  class AmplSuffixHandler;
23  class AmplOptionsList;
24}
25
26namespace Bonmin
27{
28
29
30
31  /** Ampl MINLP Interface.
32   *  Ampl MINLP Interface, implemented as a TMINLP.
33   *  This interface creates a AmplTNLP and also retrieves
34   *  the information about the binary and integer variables
35   */
36  class AmplTMINLP : public TMINLP
37  {
38  public:
39    /**@name Constructors/Destructors */
40    //@{
41    /** Constructor */
42    AmplTMINLP(const SmartPtr<const Journalist>& jnlst,
43        const SmartPtr<OptionsList> options,
44        char**& argv,
45        AmplSuffixHandler* suffix_handler = NULL,
46        const std::string& appName = "bonmin",
47        std::string* nl_file_content = NULL);
48
49    virtual void Initialize(const SmartPtr<const Journalist>& jnlst,
50        const SmartPtr<OptionsList> options,
51        char**& argv,
52        AmplSuffixHandler* suffix_handler =NULL,
53        const std::string& appName = "bonmin",
54        std::string* nl_file_content = NULL);
55
56    /** read the branching priorities from ampl suffixes.*/
57    void read_priorities();
58
59    /** read the sos constraints from ampl suffixes */
60    void read_sos();
61
62    AmplTMINLP();
63
64    virtual AmplTMINLP * createEmpty()
65    {
66      AmplTMINLP * tminlp = new AmplTMINLP;
67      return tminlp;
68    }
69
70    /** Default destructor */
71    virtual ~AmplTMINLP();
72    //@}
73
74    /**@name methods to gather information about the NLP. These
75    * methods are overloaded from TMINLP. See TMINLP for their more
76    * detailed documentation. */
77    //@{
78    /** returns dimensions of the nlp. Overloaded from TMINLP */
79    virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
80        Index& nnz_h_lag,
81        TNLP::IndexStyleEnum& index_style);
82
83    /** returns the vector of variable types */
84    virtual bool get_var_types(Index n, VariableType* var_types);
85    /** return the vector of constraints types*/
86    virtual bool get_constraints_types(Index n, ConstraintType* const_types);
87    /** returns bounds of the nlp. Overloaded from TMINLP */
88    virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
89        Index m, Number* g_l, Number* g_u);
90
91    /** provides a starting point for the nlp variables. Overloaded
92    from TMINLP */
93    virtual bool get_starting_point(Index n, bool init_x, Number* x,
94                                    bool init_z, Number* z_L, Number* z_U,
95        Index m, bool init_lambda, Number* lambda);
96
97    /** evaluates the objective value for the nlp. Overloaded from TMINLP */
98    virtual bool eval_f(Index n, const Number* x, bool new_x,
99        Number& obj_value);
100
101    /** evaluates the gradient of the objective for the
102    nlp. Overloaded from TMINLP */
103    virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
104        Number* grad_f);
105
106    /** evaluates the constraint residuals for the nlp. Overloaded from TMINLP */
107    virtual bool eval_g(Index n, const Number* x, bool new_x,
108        Index m, Number* g);
109
110    /** specifies the jacobian structure (if values is NULL) and
111     *  evaluates the jacobian values (if values is not NULL) for the
112     *  nlp. Overloaded from TMINLP */
113    virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
114        Index m, Index nele_jac, Index* iRow,
115        Index *jCol, Number* values);
116
117    /** specifies the structure of the hessian of the lagrangian (if
118     *  values is NULL) and evaluates the values (if values is not
119     *  NULL). Overloaded from TMINLP */
120    virtual bool eval_h(Index n, const Number* x, bool new_x,
121        Number obj_factor, Index m, const Number* lambda,
122        bool new_lambda, Index nele_hess, Index* iRow,
123        Index* jCol, Number* values);
124    //@}
125
126    /** @name Solution Methods */
127    //@{
128    virtual void finalize_solution(SolverReturn status,
129        Index n, const Number* x, const Number* z_L, const Number* z_U,
130        Index m, const Number* g, const Number* lambda,
131        Number obj_value);
132
133    void write_solution(const std::string & message, const Number *x_sol, const Number * lambda_sol);
134    //@}
135
136    /** Write the solution file.  This is a wrapper for AMPL's
137     *  write_sol.  TODO Maybe this should be at a different place, or
138     *  collect the numbers itself? */
139    void write_solution_file(const std::string& message) const;
140    //@}
141
142   
143    virtual const BranchingInfo * branchingInfo() const
144    {
145      return &branch_;
146    } 
147
148    virtual const SosInfo * sosConstraints() const
149    {
150      return &sos_;
151    }
152
153    /** @name User callbacks */
154    //@{
155    /** Additional application specific options.*/
156    virtual void fillApplicationOptions(AmplOptionsList* amplOptList)
157    {}
158    //@}
159
160
161    /** This methods gives the linear part of the objective function */
162    virtual void getLinearPartOfObjective(double * obj);
163    /** Journlist */
164    SmartPtr<const Journalist> jnlst_;
165
166    /** Sign of the objective fn (1 for min, -1 for max) */
167    double obj_sign_;
168
169    /**@name Problem Size Data*/
170    //@{
171    Index nz_h_full_; // number of nonzeros in the full_x hessian
172    /* the rest of the problem size data is available easily through the ampl variables */
173    //@}
174
175    /**@name Internal copies of data */
176    //@{
177    /** A non-const copy of x - this is kept up-to-date in apply_new_x */
178    Number* non_const_x_;
179
180    /** Solution Vectors */
181    Number* x_sol_;
182    Number* z_L_sol_;
183    Number* z_U_sol_;
184    Number* g_sol_;
185    Number* lambda_sol_;
186    Number obj_sol_;
187    //@}
188
189    /**@name Flags to track internal state */
190    //@{
191    /** true when the objective value has been calculated with the
192     *  current x, set to false in apply_new_x, and set to true in
193     *  internal_objval */
194    bool objval_called_with_current_x_;
195    /** true when the constraint values have been calculated with the
196     *  current x, set to false in apply_new_x, and set to true in
197     *  internal_conval */
198    bool conval_called_with_current_x_;
199    //@}
200
201
202    /** Make the objective call to ampl */
203    bool internal_objval(Number& obj_val);
204
205    /** Make the constraint call to ampl*/
206    bool internal_conval(Index m, Number* g=NULL);
207
208    /** Internal function to update the internal and ampl state if the
209    x value changes */
210    void apply_new_x(bool new_x, Index n, const Number* x);
211
212    /** Method to add the extra option for ampl */
213    void fillAmplOptionList(AmplOptionsList* amplOptList);
214
215    /**@name Default Compiler Generated Methods
216     * (Hidden to avoid implicit creation/calling).
217     * These methods are not implemented and
218     * we do not want the compiler to implement
219     * them for us, so we declare them private
220     * and do not define them. This ensures that
221     * they will not be implicitly created/called. */
222    //@{
223
224    /** Copy Constructor */
225    AmplTMINLP(const AmplTMINLP&);
226
227    /** Overloaded Equals Operator */
228    void operator=(const AmplTMINLP&);
229    //@}
230
231    /** pointer to the internal AmplTNLP */
232    AmplTNLP* ampl_tnlp_;
233
234    /** Storage of branching priorities information.*/
235    BranchingInfo branch_;
236    /** Storage of sos constraints */
237    SosInfo sos_;
238    /** Store a suffix handler (since Ipopt does not want to give access to his >:( ).*/
239    SmartPtr<AmplSuffixHandler> suffix_handler_;
240  };
241} // namespace Ipopt
242
243#endif
Note: See TracBrowser for help on using the repository browser.