📄 irreg1.c
字号:
/* **************************************************************************** *//* user functions *//* **************************************************************************** */#include "o8para.h"main() { void donlp2(void); donlp2(); exit(0);}/* example where extended mfcq doesn't hold; *//* nlp itself quite regular *//* solution 1/sqrt(2),1/sqrt(2) . with tau0 = 0.5 the methods fails because *//* at zero the most violated constraint (the equality) cannot be reduced *//* since its gradient is zero. with tau0 larger than one this will not *//* occur since grad(f) takes us away from zero *//* **************************************************************************** *//* donlp2 standard setup *//* **************************************************************************** */void setup0(void) { #define X extern #include "o8comm.h" #undef X static INTEGER i,j,nuser = 2; static DOUBLE xst0[] = {0., /* not used : index 0 */ -0.4e0,-0.4e0}; /* 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,"nmcfqmhh"); /* 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 = 2; analyt = TRUE; epsdif = 1.e-16; del0 = 0.5e0; tau0 = 0.5e0; for (i = 1 ; i <= n ; i++) { x[i] = xst0[i]; } /* gunit-array, see donlpdoc.txt */ for (j = 0 ; j <= nh+ng ; j++) { gunit[1][j] = -1; gunit[2][j] = 0; gunit[3][j] = 0; } 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 icf = icf+1; *fx = -(x[1]+x[2]); return;}/* **************************************************************************** *//* gradient of objective function *//* **************************************************************************** */void egradf(DOUBLE x[],DOUBLE gradf[]) { #define X extern #include "o8fuco.h" #undef X static INTEGER j; icgf = icgf+1; for (j = 1 ; j <= 2 ; j++) { gradf[j] = -1.e0; } 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; *hxi = pow(x[1],2)+pow(x[2],2)-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; if ( gunit[1][i] != 1 ) cgres[i] = cgres[i]+1; for ( j = 1 ; j <= n ; j++) { gradhi[j] = x[j]*2.e0; } 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 if ( gunit[1][i+nh] == -1 ) cres[i+nh] = cres[i+nh]+1; switch (i) { case 1: *gxi = x[1]; return; case 2: *gxi = x[2]; 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 ( gunit[1][i+nh] == -1 ) cgres[i+nh] = cgres[i+nh]+1; switch (i) { case 1: gradgi[1] = 1.e0; gradgi[2] = 0.e0; return; case 2: gradgi[1] = 0.e0; gradgi[2] = 1.e0; 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 + -