You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  1. /* nppsamp.c */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <glpk.h>
  5. int main(void)
  6. { glp_prep *prep;
  7. glp_prob *P, *Q;
  8. int ret;
  9. prep = glp_npp_alloc_wksp();
  10. P = glp_create_prob();
  11. ret = glp_read_mps(P, GLP_MPS_DECK, NULL, "murtagh.mps");
  12. if (ret != 0)
  13. { printf("Error on reading problem data\n");
  14. goto skip;
  15. }
  16. glp_set_obj_dir(P, GLP_MAX);
  17. glp_npp_load_prob(prep, P, GLP_SOL, GLP_ON);
  18. ret = glp_npp_preprocess1(prep, 0);
  19. switch (ret)
  20. { case 0:
  21. break;
  22. case GLP_ENOPFS:
  23. printf("LP has no primal feasible solution\n");
  24. goto skip;
  25. case GLP_ENODFS:
  26. printf("LP has no dual feasible solution\n");
  27. goto skip;
  28. default:
  29. glp_assert(ret != ret);
  30. }
  31. Q = glp_create_prob();
  32. glp_npp_build_prob(prep, Q);
  33. ret = glp_simplex(Q, NULL);
  34. if (ret == 0 && glp_get_status(Q) == GLP_OPT)
  35. { glp_npp_postprocess(prep, Q);
  36. glp_npp_obtain_sol(prep, P);
  37. }
  38. else
  39. printf("Unable to recover non-optimal solution\n");
  40. glp_delete_prob(Q);
  41. skip: glp_npp_free_wksp(prep);
  42. glp_delete_prob(P);
  43. return 0;
  44. }
  45. /* eof */