// Copyright (C) 2005, 2006 International Business Machines and others. // All Rights Reserved. // This code is published under the Eclipse Public License. // // $Id: LuksanVlcek6.cpp 2005 2011-06-06 12:55:16Z stefan $ // // Authors: Andreas Waechter IBM 2005-10-127 #include "LuksanVlcek6.hpp" #ifdef HAVE_CONFIG_H #include "config.h" #else #include "configall_system.h" #endif #ifdef HAVE_CMATH # include #else # ifdef HAVE_MATH_H # include # else # error "don't have header file for math" # endif #endif #ifdef HAVE_CSTDIO # include #else # ifdef HAVE_STDIO_H # include # else # error "don't have header file for stdio" # endif #endif using namespace Ipopt; inline static Index Sgn(Number a) { if (a>0.) { return 1; } else { return -1; } } LuksanVlcek6::LuksanVlcek6(Number g_l, Number g_u) { g_l_ = g_l; g_u_ = g_u; } bool LuksanVlcek6::InitializeProblem(Index N) { N_=N; if (2*(N_/2)!=N_ || N<=1) { printf("N needs to be even and at least 2.\n"); return false; } return true; } // returns the size of the problem bool LuksanVlcek6::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_lag, IndexStyleEnum& index_style) { // The problem described in LuksanVlcek6.hpp has 4 variables, x[0] through x[3] n = N_+1; m = N_/2; nnz_jac_g = 3 * m; nnz_h_lag = n + n-1 + n-2 + n-3 + n-4 + n-5 + n-6; // use the C style numbering of matrix indices (starting at 0) index_style = TNLP::C_STYLE; return true; } // returns the variable bounds bool LuksanVlcek6::get_bounds_info(Index n, Number* x_l, Number* x_u, Index m, Number* g_l, Number* g_u) { // none of the variables have bounds for (Index i=0; i=Max(0,i-5); j--) { values[ih+j] += obj_factor*a1apb2*(1.+2.*x[j]); ih += ip; ip--; } for (Index j=Max(0,i-5); j=Max(0,i-5); k--) { values[ih+k] += obj_factor*apb2*(1.+2.*x[k])*axj; ih += ip; ip--; } } if (i=Max(0,i-5); k--) { values[ih+k] = obj_factor*apb2*(1.+2.*x[k])*axj; ih += ip; ip--; } // x[j=i+1] x[k=i+1] values[i+1] = obj_factor*(apb2*axj*axj+ 2.*apb1); } else { // We could just not set those non-zero elements in the // structure, but I'm too lazy to do that now values[n+i] = 0.; ih = n+n-1; ip = n-2; for (Index k=i-1; k>=Max(0,i-5); k--) { values[ih+k] = 0.; ih += ip; ip--; } // x[j=i+1] x[k=i+1] values[i+1] = 0.; } } // Now the constraints for (Index i=0; i