⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hs32.c

📁 sqp程序包。用sqp算法实现非线性约束的优化求解
💻 C
字号:
/* *****************************************************************************//*                                 user functions*//* *****************************************************************************/#include "o8para.h"main() {    void donlp2(void);    donlp2();    exit(0);}/*  hs32                *//*  solution is (0,0,1)*//* **************************************************************************** *//*                              donlp2 standard setup                           *//* **************************************************************************** */void setup0(void) {    #define  X extern    #include "o8comm.h"    #undef   X    static INTEGER i,j,nuser = 3;    static DOUBLE  xst0[] = {0., /* not used : index 0 */                             .1e0, .7e0, .2e0 };/* name is ident of the example/user and can be set at users will           *//* the first static char [] must be alphabetic.  40 static char [s] maximum */    strcpy(name,"hs32");    /* x is initial guess and also holds the current solution */    /* problem dimension n = dim(x), nh = dim(h), ng = dim(g) */        n      = nuser;    nh     = 1;    ng     = 4;    analyt = TRUE;    epsdif = 1.e-16;/*  old    del0   = 1.e0; */    del0 = 1.e1;    tau0   = 1.e4;    for (i = 1 ; i <= n ; i++) {        x[i] = xst0[i];    }    /* gunit-array, see donlpdoc.ps */    gunit[1][0] = -1;    gunit[2][0] = 0;    gunit[3][0] = 0;    for (j = 3 ; j <= 5 ; j++)      gunit[1][j] = 1;	    for (j = 3 ; j <= 5 ; j++)      {	gunit[2][j] = j-2;	gunit[3][j] = 1;      }    gunit[1][1]= gunit[1][2] = -1;    gunit[2][1]= gunit[3][1] = gunit[2][2] = gunit [3][2] = 0 ;    gconst[1] = TRUE ;    gconst[2] = FALSE ;        return;}/* **************************************************************************** *//*                                 special setup                                *//* **************************************************************************** */void setup(void) {    #define  X extern    #include "o8comm.h"    #undef   X    return;}/* **************************************************************************** *//*  the user may add additional computations using the computed solution here   *//* **************************************************************************** */void solchk(void) {    #define  X extern    #include "o8comm.h"    #undef   X    #include "o8cons.h"    return;}/* **************************************************************************** *//*                               objective function                             *//* **************************************************************************** */void ef(DOUBLE x[],DOUBLE *fx) {    #define  X extern    #include "o8fuco.h"    #undef   X    *fx = pow(x[1]+3.0*x[2]+x[3],2)+4.0*pow(x[1]-x[2],2);        return;}/* **************************************************************************** *//*                          gradient of objective function                      *//* **************************************************************************** */void egradf(DOUBLE x[],DOUBLE gradf[]) {    #define  X extern    #include "o8fuco.h"    #undef   X    gradf[1] = 2.0*(x[1]+3.0*x[2]+x[3])+8.0*(x[1]-x[2]);    gradf[2] = 6.0*(x[1]+3.0*x[2]+x[3])-8.0*(x[1]-x[2]);    gradf[3] = 2.0*(x[1]+3.0*x[2]+x[3]);    return;}/* **************************************************************************** *//*                compute the i-th equality constaint, value is hxi             *//* **************************************************************************** */void eh(INTEGER i,DOUBLE x[],DOUBLE *hxi) {    #define  X extern    #include "o8fuco.h"    #undef   X    *hxi = 1.0-x[1]-x[2]-x[3];    return;}/* **************************************************************************** *//*              compute the gradient of the i-th equality constraint            *//* **************************************************************************** */void egradh(INTEGER i,DOUBLE x[],DOUBLE gradhi[]) {    #define  X extern    #include "o8fuco.h"    #undef   X    gradhi[1] = -1.0;    gradhi[2] = -1.0;    gradhi[3] = -1.0;    return;}/* **************************************************************************** *//*              compute the i-th inequality constaint, bounds included          *//* **************************************************************************** */void eg(INTEGER i,DOUBLE x[],DOUBLE *gxi) {    #define  X extern    #include "o8fuco.h"    #undef   X        switch (i) {    case 1:      *gxi = 6.0*x[2]+4.0*x[3]-pow(x[1],3)-3.0;      return;    case 2:      *gxi = x[1];      return;    case 3:      *gxi = x[2];      return;    case 4:      *gxi = x[3];      return;    }    }/* **************************************************************************** *//*              compute the gradient of the i-th inequality constraint          *//*          not necessary for bounds, but constant gradients must be set        *//*                      here e.g. using dcopy from a data-field                 *//* **************************************************************************** */void egradg(INTEGER i,DOUBLE x[],DOUBLE gradgi[]) {    #define  X extern    #include "o8fuco.h"    #undef   X    if ( i == 1 )    {      gradgi[1] = -3.0*x[1]*x[1];      gradgi[2] = 6.0 ;      gradgi[3] = 4.0 ;    }    else    {      gradgi[1] = gradgi[2] = gradgi[3] = 0;      gradgi[i-1] = 1.0 ;     }    return;}void eval_extern(INTEGER mode) {    #define  X extern    #include "o8comm.h"    #include "o8fint.h"    #undef   X    #include "o8cons.h"    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -