summaryrefslogtreecommitdiff
path: root/glpk-5.0/examples/nppsamp.c
diff options
context:
space:
mode:
authorPasha <pasha@member.fsf.org>2023-01-27 00:54:07 +0000
committerPasha <pasha@member.fsf.org>2023-01-27 00:54:07 +0000
commitef800d4ffafdbde7d7a172ad73bd984b1695c138 (patch)
tree920cc189130f1e98f252283fce94851443641a6d /glpk-5.0/examples/nppsamp.c
parentec4ae3c2b5cb0e83fb667f14f832ea94f68ef075 (diff)
downloadoneapi-master.tar.gz
oneapi-master.tar.bz2
simplex-glpk with modified glpk for fpgaHEADmaster
Diffstat (limited to 'glpk-5.0/examples/nppsamp.c')
-rw-r--r--glpk-5.0/examples/nppsamp.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/glpk-5.0/examples/nppsamp.c b/glpk-5.0/examples/nppsamp.c
new file mode 100644
index 0000000..65f0e69
--- /dev/null
+++ b/glpk-5.0/examples/nppsamp.c
@@ -0,0 +1,48 @@
+/* nppsamp.c */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glpk.h>
+
+int main(void)
+{ glp_prep *prep;
+ glp_prob *P, *Q;
+ int ret;
+ prep = glp_npp_alloc_wksp();
+ P = glp_create_prob();
+ ret = glp_read_mps(P, GLP_MPS_DECK, NULL, "murtagh.mps");
+ if (ret != 0)
+ { printf("Error on reading problem data\n");
+ goto skip;
+ }
+ glp_set_obj_dir(P, GLP_MAX);
+ glp_npp_load_prob(prep, P, GLP_SOL, GLP_ON);
+ ret = glp_npp_preprocess1(prep, 0);
+ switch (ret)
+ { case 0:
+ break;
+ case GLP_ENOPFS:
+ printf("LP has no primal feasible solution\n");
+ goto skip;
+ case GLP_ENODFS:
+ printf("LP has no dual feasible solution\n");
+ goto skip;
+ default:
+ glp_assert(ret != ret);
+ }
+ Q = glp_create_prob();
+ glp_npp_build_prob(prep, Q);
+ ret = glp_simplex(Q, NULL);
+ if (ret == 0 && glp_get_status(Q) == GLP_OPT)
+ { glp_npp_postprocess(prep, Q);
+ glp_npp_obtain_sol(prep, P);
+ }
+ else
+ printf("Unable to recover non-optimal solution\n");
+ glp_delete_prob(Q);
+skip: glp_npp_free_wksp(prep);
+ glp_delete_prob(P);
+ return 0;
+}
+
+/* eof */