/* 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 static int ex1(void); static int ex2(void); int main(void) { Integer exit_status_ex1=0; Integer exit_status_ex2=0; Vprintf("nag_ip_mps_read (h02buc) Example Program Results.\n"); exit_status_ex1 = ex1(); exit_status_ex2 = ex2(); return exit_status_ex1 == 0 && exit_status_ex2 == 0 ? 0 : 1; } static int ex1(void) { Nag_Boolean *intvar; Integer exit_status=0, m, n; NagError fail; double *a, *bl, *bu, *c, objf, *x; INIT_FAIL(fail); Vprintf("\nExample 1: default options used.\n"); /* Read MPSX data */ /* nag_ip_mps_read (h02buc). * Read MPSX data for IP, LP or QP problem from a file */ nag_ip_mps_read(0, Nag_TRUE, &n, &m, &a, &bl, &bu, &intvar, &c, &x, H02_DEFAULT, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_ip_mps_read (h02buc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Solve IP problem defined by data as an LP problem */ /* nag_opt_lp (e04mfc). * Linear programming */ nag_opt_lp(n, m, a, n, bl, bu, c, x, &objf, E04_DEFAULT, NAGCOMM_NULL, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_opt_lp (e04mfc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Free memory allocated by nag_ip_mps_read (h02buc) */ /* nag_ip_mps_free (h02bvc). * Free memory allocated by nag_ip_mps_read (h02buc) */ nag_ip_mps_free(&a, &bl, &bu, &intvar, &c, &x); END: return exit_status; } static int ex2(void) { Nag_Boolean *intvar; Integer exit_status=0, m, n; NagError fail; Nag_H02_Opt options; double *a, *bl, *bu, *c, objf, *x; INIT_FAIL(fail); Vprintf("\nExample 2: use of options structure.\n"); /* Initialise options structure and read option settings. */ /* nag_ip_init (h02xxc). * Initialize option structure to null values */ nag_ip_init(&options); /* nag_ip_read (h02xyc). * Read optional parameter values from a file */ nag_ip_read("h02buc", "stdin", &options, (Nag_Boolean)Nag_TRUE, "stdout", &fail); if (fail.code != NE_NOERROR) { Vprintf("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. */ nag_ip_mps_read(0, Nag_TRUE, &n, &m, &a, &bl, &bu, &intvar, &c, &x, &options, &fail); if (fail.code != NE_NOERROR) { Vprintf("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 */ nag_ip_bb(n, m, a, n, bl, bu, intvar, c, (double*)0, 0, NULLFN, x, &objf, &options, NAGCOMM_NULL, &fail); if (fail.code != NE_NOERROR) { Vprintf("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) { Vprintf("Error from nag_ip_free (h02xzc).\n%s\n", fail.message); exit_status = 1; goto END; } END: return exit_status; }