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

📄 tp383mod.c

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

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

/* **************************************************************************** */
/*                              donlp2 standard setup                           */
/* **************************************************************************** */
void setup0(void) {
    #define  X extern
    #include "o8comm.h"
    #undef   X
    
    static INTEGER i;
    
    /* # s383.mod OLR2-AN-14-29                                                 */
    /* # Original AMPL coding by Elena Bobrovnikova (summer 1996 at Bell Labs). */

    /* # Ref.: K. Schittkowski, More Test Examples for Nonlinear Programming    */
    /* # Codes.                                                                 */
    /* # Lecture Notes in Economics and Mathematical Systems, v. 282,           */
    /* # Springer-Verlag, New York, 1987, p. 202.                               */

    /* # Number of variables:  14   */
    /* # Number of constraints:  29 */
    /* # Objective separable convex */
    /* # Linear constraints         */

    /* set i : =  1 .. 14; */

    /* param a{i}; */
    /* param c{i}; */

    /* var x{i} > =  0 : =  0.01; */

    strcpy(name,"tp383mod");

    n    = 14;
    nh   = 1;
    ng   = 28;
    tau  = 0.1e0;
    tau0 = 1.e0;
    del0 = 1.e0;
    for (i = 1 ; i <= 14 ; i++) {
        x[i] = 0.01e0;
    }
    silent = FALSE;
    cold   = TRUE;
    analyt = TRUE;
    epsdif = 1.e-8;

    for (i = 0 ; i <= 1 ; i++) {
        gunit[1][i] = -1;
        gunit[2][i] = 0;
        gunit[3][i] = 0;
    }
    gconst[0] = FALSE;
    for (i = 1 ; i <= 29 ; i++) {
        gconst[i] = TRUE;
    }
    for (i = 2 ; i <= 29 ; i++) {
        gunit[1][i] = 1;
        if ( i-1 <= 14 ) {
            gunit[1][i] = 1;
            gunit[3][i] = 1;
            gunit[2][i] = i-1;
    } else {
            gunit[1][i] = 1;
            gunit[2][i] = i-15;
            gunit[3][i] = -1;
        }
    }
    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

    static INTEGER i;
    static DOUBLE  sum;
    static DOUBLE  a[] = {0., /* not used : index 0 */
                       12842.275e0 ,    
                         634.25e0  ,    
                         634.25e0  ,    
                         634.125e0 ,    
                        1268.e0    ,    
                         633.875e0 ,    
                         633.75e0  ,
                         
                        1267.e0    ,     
                         760.05e0  ,   
                         633.25e0  ,   
                        1266.25e0  ,   
                         632.875e0 ,  
                         394.46e0  ,   
                         940.838e0 };

    /* minimize obj:                      */
    /*          sum {i in i} a[i] / x[i]; */
    
    icf = icf+1;
    sum = 0.e0;
    for (i = 1 ; i <= 14 ; i++) {
        sum = sum+a[i]/x[i];
    }
    *fx = sum;
    
    return;
}

/* **************************************************************************** */
/*                          gradient of objective function                      */
/* **************************************************************************** */
void egradf(DOUBLE x[],DOUBLE gradf[]) {
    #define  X extern
    #include "o8fuco.h"
    #undef   X

    static INTEGER i;
    static DOUBLE  a[] = {0., /* not used : index 0 */
                       12842.275e0 ,    
                         634.25e0  ,    
                         634.25e0  ,    
                         634.125e0 ,    
                        1268.e0    ,    
                         633.875e0 ,    
                         633.75e0  ,
                         
                        1267.e0    ,     
                         760.05e0  ,   
                         633.25e0  ,   
                        1266.25e0  ,   
                         632.875e0 ,  
                         394.46e0  ,   
                         940.838e0 };
    icgf = icgf+1;
    for (i = 1 ; i <= 14 ; i++) {
        gradf[i] = -a[i]/pow(x[i],2);
    }
    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
    
    static INTEGER j;
    static DOUBLE  sum;
    static DOUBLE  c[] = {0., /* not used : index 0 */
                           5.47934e0,       
                            .83234e0,       
                            .94749e0,       
                           1.11082e0,       
                           2.64824e0,       
                           1.55868e0,       
                           1.73215e0,
                           
                           3.90896e0,    
                           2.74284e0, 
                           2.60541e0,    
                           5.96184e0,     
                           3.29522e0,     
                           1.83517e0,     
                           2.81372e0};    
         
    cres[1] = cres[1]+1;

    /*  s.t. g1:                       */
    /*  sum {i in i} c[i] * x[i] == 1; */

    sum = 0.e0;
    for (j = 1 ; j <= 14 ; j++) {
        sum = sum+c[j]*x[j];
    }
    *hxi = sum-1.e0;
    
    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
    
    static INTEGER j;
    static DOUBLE  c[] = {0., /* not used : index 0 */
                           5.47934e0,       
                            .83234e0,       
                            .94749e0,       
                           1.11082e0,       
                           2.64824e0,       
                           1.55868e0,       
                           1.73215e0,
                           
                           3.90896e0,    
                           2.74284e0, 
                           2.60541e0,    
                           5.96184e0,     
                           3.29522e0,     
                           1.83517e0,     
                           2.81372e0};    

     for (j = 1 ; j <= 14 ; j++) {
         gradhi[j] = c[j];
     }
     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
    
    /* !!!! the original statement of problem 383 is erroneous              */
    /*  the lower bound zero used there makes no sense here, clearly        */
    /*  hence we introduce the tiny lower bound 1.e-4, which is not binding */
    /*  at the solution                                                     */

    static DOUBLE ug[] = {0., /* not used : index 0 */ 
    1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,1.e-4 ,
    1.e-4 ,1.e-4 ,1.e-4 ,1.e-4};
    static DOUBLE og[] = {0., /* not used : index 0 */
    0.04e0,0.04e0,0.04e0,0.04e0,0.04e0,0.03e0,0.03e0,0.03e0,0.03e0,0.03e0,
    0.03e0,0.03e0,0.03e0,0.03e0};
    
    /* s.t. b1 {i in {1..5}}:           */
    /*      x[i] <= 0.04;               */
    /* s.t. b2 {i in {6..14}}:          */
    /*      x[i] <= 0.03;               */
    /* evaluation of bounds not counted */
    
    if ( i  > 14 ) {
        *gxi = og[i-14]-x[i-14];
    } else {
        *gxi = x[i]-ug[i];
    }
    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

    return;
}

/* **************************************************************************** */
/*                        user functions (if bloc == TRUE)                      */
/* **************************************************************************** */
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 + -