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

📄 hs102.c

📁 sqp程序包。用sqp算法实现非线性约束的优化求解
💻 C
📖 第 1 页 / 共 2 页
字号:
/* **************************************************************************** */
/*                                 user functions                               */
/* **************************************************************************** */
#include "o8para.h"

main() {
    void donlp2(void);
    
    donlp2();
    
    exit(0);
}

/* **************************************************************************** */
/*                              donlp2 standard setup                           */
/* **************************************************************************** */
/* from Hock & Schittkowski */
/*    hs102  */
void setup0(void) {
    #define  X extern
    #include "o8comm.h"
    #undef   X
    
    static INTEGER i;

    strcpy(name,"hs102");

    for (i = 1 ; i <= 7 ; i++) {
        x[i] = 6.e0;
    }
    n    = 7;
    nh   = 0;
    ng   = 20;
    del0 = 0.05e0;
    tau0 = 0.05e0;
    tau  = 0.1e0;
    
    for (i = 0 ; i <= 6 ; i++) {
        gunit[1][i] = -1;
        gunit[2][i] = 0;
        gunit[3][i] = 0;
    }
    for (i = 7 ; i <= 13 ; i++) {
        gunit[1][i]   = 1;
        gunit[2][i]   = i-6;
        gunit[3][i]   = 1;
        gunit[1][i+7] = 1;
        gunit[2][i+7] = i-6;
        gunit[3][i+7] = -1;
    }
    cold   = TRUE;
    silent = 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
    
    void fgeo(DOUBLE x[],DOUBLE con,DOUBLE gam[],LOGICAL lin,DOUBLE dl[],void *pk,
              void *pal,INTEGER nlen,INTEGER nanz,INTEGER nx,DOUBLE *fx);

    static DOUBLE  dl[NX+1];
     
    static INTEGER kf[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 1, 1, 1},
            {0,      2, 2, 2, 2},
            {0,      4, 3, 4, 3},
            {0,      6, 4, 5, 5},
            {0,      7, 5, 6, 6},
            {0,      0, 7, 0, 7} };
                            
    static DOUBLE gamf[] = { 0., /* not used : index 0 */
                            10.e0,15.e0,20.e0,25.e0 };
    
    static DOUBLE alf[][5] = {
            {0.e0,      0.e0, 0.e0, 0.e0, 0.e0},
             
            {0.e0,       1.e0   , -1.e0,-2.e0, 2.e0 },
            {0.e0,      -1.e0   , -2.e0, 1.e0, 2.e0 },
            {0.e0,       2.e0   ,  1.e0,-1.e0,-1.e0 },
            {0.e0,      -3.e0   ,  1.e0,-2.e0,  .5e0},
            {0.e0,       0.125e0, -1.e0, 1.e0,-2.e0 },
            {0.e0,       0.e0   , -.5e0, 0.e0, 1.e0 } };
                                
    icf = icf+1;
    
    fgeo(x,0.e0,gamf,FALSE,dl,kf,alf,6,4,7,fx);
    
    return;
}

/* **************************************************************************** */
/*                          gradient of objective function                      */
/* **************************************************************************** */
void egradf(DOUBLE x[],DOUBLE gradf[]) {
    #define  X extern
    #include "o8fuco.h"
    #undef   X
    
    void dfgeo(DOUBLE x[],DOUBLE gam[],LOGICAL lin,DOUBLE dl[],void *pk,
               void *pal,INTEGER nlen,INTEGER nanz,DOUBLE g[],INTEGER nx);

    static DOUBLE  dl[NX+1];
     
    static INTEGER kf[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 1, 1, 1},
            {0,      2, 2, 2, 2},
            {0,      4, 3, 4, 3},
            {0,      6, 4, 5, 5},
            {0,      7, 5, 6, 6},
            {0,      0, 7, 0, 7} };
                            
    static DOUBLE gamf[] = { 0., /* not used : index 0 */
                            10.e0,15.e0,20.e0,25.e0 };
    
    static DOUBLE alf[][5] = {
            {0.e0,      0.e0, 0.e0, 0.e0, 0.e0},
             
            {0.e0,       1.e0   , -1.e0,-2.e0, 2.e0 },
            {0.e0,      -1.e0   , -2.e0, 1.e0, 2.e0 },
            {0.e0,       2.e0   ,  1.e0,-1.e0,-1.e0 },
            {0.e0,      -3.e0   ,  1.e0,-2.e0,  .5e0},
            {0.e0,       0.125e0, -1.e0, 1.e0,-2.e0 },
            {0.e0,       0.e0   , -.5e0, 0.e0, 1.e0 } };

    icgf = icgf+1;
    
    dfgeo(x,gamf,FALSE,dl,kf,alf,6,4,gradf,7);
    
    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
    
    cres[i] = cres[i]+1;
    
    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

    cgres[i] = cgres[i]+1;

    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
    
    void fgeo(DOUBLE x[],DOUBLE con,DOUBLE gam[],LOGICAL lin,DOUBLE dl[],void *pk,
              void *pal,INTEGER nlen,INTEGER nanz,INTEGER nx,DOUBLE *fx);
    
    static DOUBLE  dl[NX+1];
     
    static INTEGER kf[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 1, 1, 1},
            {0,      2, 2, 2, 2},
            {0,      4, 3, 4, 3},
            {0,      6, 4, 5, 5},
            {0,      7, 5, 6, 6},
            {0,      0, 7, 0, 7} };
                            
    static DOUBLE gamf[] = { 0., /* not used : index 0 */
                            10.e0,15.e0,20.e0,25.e0 };
    
    static DOUBLE alf[][5] = {
            {0.e0,       0.e0  ,  0.e0, 0.e0, 0.e0},
             
            {0.e0,       1.e0   , -1.e0,-2.e0, 2.e0 },
            {0.e0,      -1.e0   , -2.e0, 1.e0, 2.e0 },
            {0.e0,       2.e0   ,  1.e0,-1.e0,-1.e0 },
            {0.e0,      -3.e0   ,  1.e0,-2.e0,  .5e0},
            {0.e0,       0.125e0, -1.e0, 1.e0,-2.e0 },
            {0.e0,       0.e0   , -.5e0, 0.e0, 1.e0 } };
            
    static DOUBLE gam1[] = { 0., /* not used : index 0 */
                            -.5e-3,-.7e-3,-.2e-3,0.e0 };

    static DOUBLE gam2[] = { 0., /* not used : index 0 */
                            -1.3e-3,-.8e-3,-3.1e-3,0.e-3 };
                            
    static DOUBLE gam3[] = { 0., /* not used : index 0 */
                            -2.0e-3,-.1e-3,-1.0e-3,-.65e-3 };
                            
    static DOUBLE gam4[] = { 0., /* not used : index 0 */
                            -.20e-3,-.3e-3,-.40e-3,-.5e-3 };
                            
    static DOUBLE al1[][5] = {
            {0.e0,       0.e0, 0.e0 , 0.e0              ,0.e0},
             
            {0.e0,       .5e0, 3.e0 ,-1.e0              ,0.e0},
            {0.e0,      -1.e0, 1.e0 , 1.e0              ,0.e0},
            {0.e0,      -2.e0,-2.e0 ,- .5e0             ,0.e0},
            {0.e0,       1.e0, 1.e0 ,  .66666666666666e0,0.e0},
            {0.e0,       0.e0,  .5e0,  .25e0            ,0.e0},
            {0.e0,       0.e0, 0.e0 , 0.e0              ,0.e0} };
             
    static DOUBLE al2[][5] = {
            {0.e0,       0.e0 , 0.e0, 0.e0              ,0.e0},
             
            {0.e0,      - .5e0, 1.e0,-1.e0              ,0.e0},
            {0.e0,       1.e0 ,-1.e0,  .5e0             ,0.e0},
            {0.e0,      -1.e0 ,-1.e0,-2.e0              ,0.e0},
            {0.e0,      -1.e0 , 2.e0,-1.e0              ,0.e0},
            {0.e0,       1.e0 , 0.e0,  .33333333333333e0,0.e0},
            {0.e0,       0.e0 , 0.e0, 0.e0              ,0.e0} };
             
    static DOUBLE al3[][5] = {
            {0.e0,       0.e0              , 0.e0 , 0.e0 , 0.e0},
             
            {0.e0,       1.e0              , 1.e0 ,-1.e0 ,-2.e0},
            {0.e0,      -1.5e0             ,- .5e0, 1.e0 , 1.e0},
            {0.e0,       1.e0              , 1.e0 ,  .5e0, 1.e0},
            {0.e0,      -1.e0              ,-1.e0 , 1.e0 ,-1.e0},
            {0.e0,        .33333333333333e0,- .5e0, 0.e0 , 1.e0},
            {0.e0,       0.e0              , 0.e0 , 0.e0 , 0.e0} };
                            
    static DOUBLE al4[][5] = {
            {0.e0,       0.e0              , 0.e0              , 0.e0  , 0.e0 },
             
            {0.e0,      -2.e0              ,  .5e0             ,-3.e0  ,-2.e0 },
            {0.e0,       1.e0              , 2.e0              ,-2.e0  , 1.e0 },
            {0.e0,      -1.e0              , 1.e0              , 1.e0  ,  .5e0},
            {0.e0,        .5e0             ,  .33333333333333e0, 1.e0  , 0.e0 },
            {0.e0,        .33333333333333e0,  .25e0            ,  .75e0, 0.e0 },
            {0.e0,       0.e0              , -.66666666666666e0, 0.e0  , 0.e0 } };

    static INTEGER k1[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 1, 2, 0},
            {0,      3, 2, 3, 0},
            {0,      6, 3, 4, 0},
            {0,      7, 6, 6, 0},
            {0,      0, 7, 7, 0},
            {0,      0, 0, 0, 0} };

    static INTEGER k2[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 3, 1, 0},
            {0,      2, 4, 2, 0},
            {0,      3, 5, 4, 0},
            {0,      5, 6, 5, 0},
            {0,      6, 0, 6, 0},
            {0,      0, 0, 0, 0} };

    static INTEGER k3[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 2, 1, 2},
            {0,      3, 3, 2, 3},
            {0,      5, 5, 3, 5},
            {0,      6, 6, 5, 6},
            {0,      7, 7, 0, 7},
            {0,      0, 0, 0, 0} };
    
    static INTEGER k4[][5] = {
            {0,      0, 0, 0, 0},
            
            {0,      1, 1, 1, 3},
            {0,      2, 2, 2, 4},
            {0,      4, 3, 3, 7},
            {0,      5, 4, 5, 0},
            {0,      7, 7, 7, 0},
            {0,      0, 5, 0, 0} };
                            
    static DOUBLE ug[] = { 0., /* not used : index 0 */
            .1e0,.1e0,.1e0,.1e0,.1e0,.1e0,.01e0 };
    
    if ( i <= 6 ) cres[i+nh] = cres[i+nh]+1;
    if ( i  > 6 ) goto L700;
    
    switch (i) {
    case 1:
    
        fgeo(x,1.e-3,gam1,FALSE,dl,k1,al1,6,4,7,gxi);
        
        return;
        
    case 2:

        fgeo(x,1.e-3,gam2,FALSE,dl,k2,al2,6,4,7,gxi);
        
        return;

⌨️ 快捷键说明

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