/* nag_opt_sparse_mps_read(e04mzc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 7 revised, 2001. * */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static void qphess(Integer ncolh, double x[], double hx[], Nag_Comm *comm); #ifdef __cplusplus } #endif static void ex1(void); static void ex2(void); int main(void) { /* Two examples are called: ex1() uses the * default settings to read an MPSX file and * solve the problem, while ex2() uses the * options structure to obtain the column * and row names. */ Vprintf("e04mzc Example Program Results.\n"); ex1(); ex2(); return EXIT_SUCCESS; } static void ex1(void) { Integer iobj, m, n, ncolh, nnz; Integer ninf; Integer *ha, *ka; double *bl, *bu, *a, *xs; double obj, sinf; static NagError fail; Vprintf("\nExample 1: default options used.\n"); fail.print = TRUE; /* Read the MPSX file */ e04mzc((char*)0, &n, &m, &nnz, &iobj, &a, &ha, &ka, &bl, &bu, &xs, E04_DEFAULT, &fail); if (fail.code == NE_NOERROR) { /* Solve the problem */ ncolh = 5; e04nkc(n, m, nnz, iobj, ncolh, qphess, a, ha, ka, bl, bu, xs, &ninf, &sinf, &obj, E04_DEFAULT, NAGCOMM_NULL, &fail); } /* Free the memory allocated by e04mzc */ e04myc(&a, &ha, &ka, &bl, &bu, &xs); } static void qphess(Integer ncolh, double x[], double hx[], Nag_Comm *comm) { /* Function to compute H*x. */ hx[0] = 2.0*x[0] + x[1] + x[2] + x[3] + x[4]; hx[1] = x[0] + 2.0*x[1] + x[2] + x[3] + x[4]; hx[2] = x[0] + x[1] + 2.0*x[2] + x[3] + x[4]; hx[3] = x[0] + x[1] + x[2] + 2.0*x[3] + x[4]; hx[4] = x[0] + x[1] + x[2] + x[3] + 2.0*x[4]; } /* qphess */ /* Example 2 */ static void ex2(void) { Integer iobj, m, n, ncolh, nnz; Integer ninf; Integer *ha, *ka; double *bl, *bu, *a, *xs; double obj, sinf; Nag_E04_Opt options; static NagError fail, fail2; Vprintf("\nExample 2: use of options structure.\n"); fail.print = TRUE; /* Initialise the options structure and read MPSX data */ e04xxc(&options); Vstrcpy(options.prob_name, "..QP 2.."); Vstrcpy(options.obj_name, "..COST.."); e04mzc((char*)0, &n, &m, &nnz, &iobj, &a, &ha, &ka, &bl, &bu, &xs, &options, &fail); /* Column and row names are now available via options */ if (fail.code == NE_NOERROR) { ncolh = 5; e04nkc(n, m, nnz, iobj, ncolh, qphess, a, ha, ka, bl, bu, xs, &ninf, &sinf, &obj, &options, NAGCOMM_NULL, &fail); } /* Free memory returned by e04mzc */ e04myc(&a, &ha, &ka, &bl, &bu, &xs); /* Free memory in options (including column & row names) */ fail2.print = TRUE; e04xzc(&options, "all", &fail2); }