/* nag_ip_mps_read (h02buc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * * Mark 6 revised, 2000. * Mark 8 revised, 2004. */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *optionsfile; char *infile, *outfile; Integer exit_status = 0; Nag_Boolean *intvar; Integer m, n; Nag_H02_Opt options; double *a, *bl, *bu, *c, objf, *x; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); (void) nag_example_file_io(argc, argv, "-nag_read", &infile); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); (void) nag_example_file_io(argc, argv, "-options", &optionsfile); if (!outfile) { outfile = NAG_ALLOC(7, char); strcpy(outfile, "stdout"); } fprintf(fpout, "nag_ip_mps_read (h02buc) Example Program Results\n"); /* Initialise options structure and read option settings. */ /* nag_ip_init (h02xxc). * Initialize option structure to null values */ nag_ip_init(&options); strcpy(options.outfile, outfile); /* nag_ip_read (h02xyc). * Read optional parameter values from a file */ if (strcmp(outfile, "stdout")) fclose(fpout); nag_ip_read("h02buc", optionsfile, &options, (Nag_Boolean) Nag_TRUE, options.outfile, &fail); if (strcmp(outfile, "stdout")) { fpout = fopen(outfile, "a"); } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_ip_read (h02xyc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Read MPSX data */ /* nag_ip_mps_read (h02buc), see above. */ if (strcmp(outfile, "stdout")) fclose(fpout); nag_ip_mps_read(infile, Nag_TRUE, &n, &m, &a, &bl, &bu, &intvar, &c, &x, &options, &fail); if (strcmp(outfile, "stdout")) { fpout = fopen(outfile, "a"); } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_ip_mps_read (h02buc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Solve IP problem defined by data */ options.list = Nag_TRUE; /* nag_ip_bb (h02bbc). * Solves integer programming problems using a branch and * bound method */ if (strcmp(outfile, "stdout")) fclose(fpout); nag_ip_bb(n, m, a, n, bl, bu, intvar, c, (double *) 0, 0, NULLFN, x, &objf, &options, NAGCOMM_NULL, &fail); if (strcmp(outfile, "stdout")) { fpout = fopen(outfile, "a"); } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_ip_bb (h02bbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Free memory allocated by nag_ip_mps_read (h02buc) */ /* nag_ip_mps_free (h02bvc), see above. */ nag_ip_mps_free(&a, &bl, &bu, &intvar, &c, &x); /* Free options memory */ /* nag_ip_free (h02xzc). * Free NAG allocated memory from option structures */ nag_ip_free(&options, "all", &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_ip_free (h02xzc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (optionsfile) NAG_FREE(optionsfile); if (outfile) NAG_FREE(outfile); return exit_status; }