/* nag_opt_sparse_mps_read (e04mzc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 7 revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static void NAG_CALL qphess(Integer ncolh, double x[], double hx[], Nag_Comm *comm); #ifdef __cplusplus } #endif int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *infile, *outfile; Integer exit_status = 0; Integer *ha, iobj, *ka, m, n, ncolh, ninf, nnz; Nag_E04_Opt options; double *a, *bl, *bu, obj, sinf, *xs; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); (void) nag_example_file_io(argc, argv, "-nag_read", &infile); fpout = nag_example_file_io(argc, argv, "-results", NULL); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); if (!outfile) { outfile = NAG_ALLOC(7, char); strcpy(outfile, "stdout"); } fprintf(fpout, "nag_opt_sparse_mps_read (e04mzc) Example Program Results\n"); /* Initialise the options structure and read MPSX data */ /* nag_opt_init (e04xxc). * Initialization function for option setting */ nag_opt_init(&options); strcpy(options.outfile, outfile); Vstrcpy(options.prob_name, "..QP 2.."); Vstrcpy(options.obj_name, "..COST.."); /* nag_opt_sparse_mps_read (e04mzc), see above. */ if (strcmp(outfile, "stdout")) fclose(fpout); nag_opt_sparse_mps_read(infile, &n, &m, &nnz, &iobj, &a, &ha, &ka, &bl, &bu, &xs, &options, &fail); if (strcmp(outfile, "stdout")) { fpout = fopen(outfile, "a"); } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_opt_sparse_mps_read (e04mzc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Column and row names are now available via options */ ncolh = 5; /* nag_opt_sparse_convex_qp (e04nkc), see above. */ if (strcmp(outfile, "stdout")) fclose(fpout); nag_opt_sparse_convex_qp(n, m, nnz, iobj, ncolh, qphess, a, ha, ka, bl, bu, xs, &ninf, &sinf, &obj, &options, NAGCOMM_NULL, &fail); if (strcmp(outfile, "stdout")) { fpout = fopen(outfile, "a"); } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_opt_sparse_convex_qp (e04nkc).\n%s\n", fail.message); exit_status = 1; } /* Free memory returned by nag_opt_sparse_mps_read (e04mzc) */ /* nag_opt_sparse_mps_free (e04myc), see above. */ nag_opt_sparse_mps_free(&a, &ha, &ka, &bl, &bu, &xs); /* Free memory in options (including column & row names) */ /* nag_opt_free (e04xzc). * Memory freeing function for use with option setting */ nag_opt_free(&options, "all", &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_opt_free (e04xzc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (outfile) NAG_FREE(outfile); return exit_status; } static void NAG_CALL 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 */