NAG Library Manual, Mark 30
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_mip_ilp_mpsx_convert (h02buc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.0, 2024.
 *
 */

#include <nag.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  const char *optionsfile = "h02buce.opt";
  Integer exit_status = 0;
  Nag_Boolean *intvar;
  Integer m, n;
  Nag_H02_Opt options;
  double *a, *bl, *bu, *c, objf, *x;
  Nag_Comm comm;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_mip_ilp_mpsx_convert (h02buc) Example Program Results\n");

  /* Initialize 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
   */
  fflush(stdout);
  nag_ip_read("h02buc", optionsfile, &options, (Nag_Boolean)Nag_TRUE, "stdout",
              &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_ip_read (h02xyc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Read MPSX data */
  /* nag_mip_ilp_mpsx_convert (h02buc), see above. */
  nag_mip_ilp_mpsx_convert(0, Nag_TRUE, &n, &m, &a, &bl, &bu, &intvar, &c, &x,
                           &options, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_mip_ilp_mpsx_convert (h02buc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Solve IP problem defined by data */
  options.list = Nag_TRUE;
  options.print_level = Nag_Soln;
  /* nag_mip_ilp_dense (h02bbc).
   * Solves integer programming problems using a branch and
   * bound method
   */
  nag_mip_ilp_dense(n, m, a, n, bl, bu, intvar, c, (double *)0, 0, NULLFN, x,
                    &objf, &options, &comm, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_mip_ilp_dense (h02bbc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Free memory allocated by nag_mip_ilp_mpsx_convert (h02buc) */
  /* nag_mip_ilp_print (h02bvc), see above. */
  nag_mip_ilp_print(&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) {
    printf("Error from nag_ip_free (h02xzc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

END:

  return exit_status;
}