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

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

astyled the devel branch

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