int NCP_Path(int n, double* z, FuncEvalPtr F, JacEvalPtr jacobianF, int* iparam, double* dparam) { /* Lower bounds on the variables = 0 for NCP */ double *lb = (double *)malloc(sizeof(double) * n); /* Upper bounds on the variables = +inf for NCP */ double *ub = (double *)malloc(sizeof(double) * n); /* Function evaluation */ double *f = (double *)malloc(sizeof(double) * n);; /* Number of nonzeros */ int nnz = n * n; /* Termination status from PATH */ int status; int j; /* Connect F and its jacobian to input functions */ setFuncEval(F); setJacEval(jacobianF); /**************************************/ /* Fill in the lower and upper bounds */ /**************************************/ for (j = 0; j < n; j++) { lb[j] = 0; ub[j] = 1e20; } /************************************************************************/ /* Set fill_structure to true (we ALWAYS need to fill in the structure */ /* of the jacobian at least once per call to PATH). */ /************************************************************************/ fill_structure = 1; /************************************************************************/ /* Call PATH. */ /************************************************************************/ pathMain(n, nnz, &status, z, f, lb, ub); /************************************************************************/ /* Deallocate memory. */ /************************************************************************/ free(lb); free(ub); free(f); return 0; }
int main() { double *lb; /* Lower bounds on the variables */ double *ub; /* Upper bounds on the variables */ double *z; /* Solution vector */ double *f; /* Function evaluation */ int n; /* Number of variable (N*N) */ int nnz; /* Number of nonzeros (5*N*N - 4*N) */ int status; /* Termination status from PATH */ int i, j; /************************************************************************/ /* Read in the number of elements to use on the X and Y axes. */ /************************************************************************/ printf("Input n: "); status = scanf("%d", &N); if ((status != 1) || (N < 2)) { N = 2; } /************************************************************************/ /* Determine n (number of variables) and nnz (number of nonzeros) */ /************************************************************************/ n = N*N; nnz = 5*N*N - 4*N; /************************************************************************/ /* Allocate space for the bounds, starting point, and function value. */ /************************************************************************/ lb = (double *)malloc(sizeof(double)*n); ub = (double *)malloc(sizeof(double)*n); z = (double *)malloc(sizeof(double)*n); f = (double *)malloc(sizeof(double)*n); /************************************************************************/ /* Fill in the lower and upper bounds and a starting point. */ /************************************************************************/ for (j = 0; j < N; j++) { for (i = 0; i < N; i++) { lb[i + j*N] = pow(sin(9.2*i/(N+1.0))*sin(9.3*j/(N+1.0)), 3.0); ub[i + j*N] = pow(sin(9.2*i/(N+1.0))*sin(9.3*j/(N+1.0)), 2.0) + 0.02; z[i + j*N] = 0.1; } } /************************************************************************/ /* Set fill_structure to true (we ALWAYS need to fill in the structure */ /* of the jacobian at least once per call to PATH). */ /************************************************************************/ fill_structure = 1; /************************************************************************/ /* Call PATH. */ /************************************************************************/ pathMain(n, nnz, &status, z, f, lb, ub); /************************************************************************/ /* Deallocate memory. */ /************************************************************************/ free(lb); free(ub); free(z); free(f); return 0; }