MeshKit  1.0
IARoundingHeuristicMINLP.cpp
Go to the documentation of this file.
00001 // IARoundingHeuristicMINLP.cpp
00002 // Interval Assignment for Meshkit
00003 //
00004 // Adapted from
00005 // Copyright (C) 2005, 2006 International Business Machines and others.
00006 // All Rights Reserved.
00007 // This code is published under the Eclipse Public License.
00008 //
00009 // $Id: hs071_nlp.cpp 1864 2010-12-22 19:21:02Z andreasw $
00010 //
00011 // Authors:  Carl Laird, Andreas Waechter     IBM    2005-08-16
00012 
00013 #include "meshkit/IANlp.hpp"
00014 #include "meshkit/IARoundingHeuristicMINLP.hpp"
00015 #include "meshkit/IAData.hpp"
00016 #include "meshkit/IPData.hpp"
00017 #include "meshkit/IASolution.hpp"
00018 
00019 #include <math.h>
00020 
00021 // for printf
00022 #ifdef HAVE_CSTDIO
00023 # include <cstdio>
00024 #else
00025 # ifdef HAVE_STDIO_H
00026 #  include <stdio.h>
00027 # else
00028 #  error "don't have header file for stdio"
00029 # endif
00030 #endif
00031 
00032 // constructor
00033 IARoundingHeuristicMINLP::IARoundingHeuristicMINLP(const IAData *data_ptr, const IPData *ip_data_ptr, IASolution *solution_ptr): 
00034 data(data_ptr), ip_data(ip_data_ptr), solution(solution_ptr),
00035 debugging(true), verbose(true), baseNlp(data_ptr, solution_ptr) // true
00036 {
00037   printf("\nIARoundingHeuristicMINLP Problem size:\n");
00038   printf("  number of variables: %lu\n", data->I.size());
00039   printf("  number of constraints: %lu\n\n", data->constraints.size());
00040 }
00041 
00042 
00043 // n = number of variables
00044 // m = number of constraints (not counting variable bounds)
00045 
00046 
00047 IARoundingHeuristicMINLP::~IARoundingHeuristicMINLP() {data = NULL;}
00048 
00049 // returns the size of the problem
00050 bool IARoundingHeuristicMINLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00051                              Index& nnz_h_lag, IndexStyleEnum& index_style)
00052 {
00053   return baseNlp.get_nlp_info(n, m, nnz_jac_g, nnz_h_lag, index_style);
00054 }
00055 
00056 // returns the variable bounds
00057 bool IARoundingHeuristicMINLP::get_bounds_info(Index n, Number* x_l, Number* x_u,
00058                                 Index m, Number* g_l, Number* g_u)
00059 {
00060 
00061   const bool base_ok = baseNlp.get_bounds_info(n, x_l, x_u, m, g_l, g_u);
00062   
00063   // add bounds from integer constraints
00064   if (ip_data->varIntegerBound.size())
00065   {
00066     for (Index i=0; i<n; ++i) 
00067     {
00068       const double b = ip_data->varIntegerBound[i];
00069       if (b != 0) // if 0 then it is unconstrained so far
00070       {
00071         // b is a lower bound if it is bigger than the goal
00072         if (b > data->I[i]) 
00073         {
00074           x_l[i] = b;
00075           x_u[i] = MESHKIT_IA_upperUnbound; 
00076         }
00077         // otherwise b is an upper bound
00078         else
00079         {
00080           x_l[i] = 1.0; 
00081           x_u[i] = b; 
00082         }
00083       }
00084     }
00085   }
00086 
00087   //printf("b ");
00088   return true && base_ok; //means what?
00089 }
00090 
00091 // returns the initial point for the problem
00092 bool IARoundingHeuristicMINLP::get_starting_point(Index n, bool init_x, Number* x_init,
00093                                    bool init_z, Number* z_L, Number* z_U,
00094                                    Index m, bool init_lambda,
00095                                    Number* lambda)
00096 {
00097   const bool base_ok = baseNlp.get_starting_point(n, init_x, x_init, init_z, z_L, z_U, m, init_lambda, lambda);
00098   
00099   // initialize x to the prior solution
00100   if (ip_data->varIntegerBound.size())
00101     for (int i = 0; i<data->I.size(); ++i)
00102     {
00103       // todo: test if we need to modify this for x violating the variable bounds?
00104       x_init[i]= solution->x_solution[i]; 
00105     }
00106   
00107   return true && base_ok;
00108 }
00109 
00110 
00111 // returns the value of the objective function
00112 bool IARoundingHeuristicMINLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
00113 {
00114   return baseNlp.eval_f(n, x, new_x, obj_value);
00115 }
00116 
00117 // return the gradient of the objective function grad_{x} f(x)
00118 bool IARoundingHeuristicMINLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
00119 {
00120   return baseNlp.eval_grad_f(n, x, new_x, grad_f);
00121 }
00122 
00123 // return the value of the constraints: g(x)
00124 bool IARoundingHeuristicMINLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
00125 {
00126   return baseNlp.eval_g(n, x, new_x, m, g);
00127 }
00128 
00129 // return the structure or values of the jacobian
00130 bool IARoundingHeuristicMINLP::eval_jac_g(Index n, const Number* x, bool new_x,
00131                            Index m, Index nele_jac, Index* iRow, Index *jCol,
00132                            Number* values)
00133 {
00134   return baseNlp.eval_jac_g(n, x, new_x, m, nele_jac, iRow, jCol, values);
00135 }
00136 
00137 //return the structure or values of the hessian
00138 bool IARoundingHeuristicMINLP::eval_h(Index n, const Number* x, bool new_x,
00139                        Number obj_factor, Index m, const Number* lambda,
00140                        bool new_lambda, Index nele_hess, Index* iRow,
00141                        Index* jCol, Number* values)
00142 {
00143   return baseNlp.eval_h(n, x, new_x, obj_factor, m, lambda, new_lambda, nele_hess, iRow, jCol, values);
00144 }
00145 
00146 void IARoundingHeuristicMINLP::finalize_solution(SolverReturn status,
00147                                   Index n, const Number* x, const Number* z_L, const Number* z_U,
00148                                   Index m, const Number* g, const Number* lambda,
00149                                   Number obj_value,
00150                                   const IpoptData* ip_data,
00151                                   IpoptCalculatedQuantities* ip_cq)
00152 {
00153   // overwrites or fills in solution->x_solution
00154   baseNlp.finalize_solution(status, n, x, z_L, z_U, m, g, lambda, obj_value, ip_data, ip_cq);
00155 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines