summaryrefslogtreecommitdiff
path: root/packages/glpk/lib/Numeric/LinearProgramming
diff options
context:
space:
mode:
Diffstat (limited to 'packages/glpk/lib/Numeric/LinearProgramming')
-rw-r--r--packages/glpk/lib/Numeric/LinearProgramming/glpk.c76
1 files changed, 0 insertions, 76 deletions
diff --git a/packages/glpk/lib/Numeric/LinearProgramming/glpk.c b/packages/glpk/lib/Numeric/LinearProgramming/glpk.c
deleted file mode 100644
index bfbb435..0000000
--- a/packages/glpk/lib/Numeric/LinearProgramming/glpk.c
+++ /dev/null
@@ -1,76 +0,0 @@
1#define DVEC(A) int A##n, double*A##p
2#define DMAT(A) int A##r, int A##c, double*A##p
3
4#define AT(M,r,co) (M##p[(r)*M##c+(co)])
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <glpk.h>
9#include <math.h>
10
11/*-----------------------------------------------------*/
12
13int c_simplex_sparse(int m, int n, DMAT(c), DMAT(b), DVEC(s)) {
14 glp_prob *lp;
15 lp = glp_create_prob();
16 glp_set_obj_dir(lp, GLP_MAX);
17 int i,j,k;
18 int tot = cr - n;
19 glp_add_rows(lp, m);
20 glp_add_cols(lp, n);
21
22 //printf("%d %d\n",m,n);
23
24 // the first n values
25 for (k=1;k<=n;k++) {
26 glp_set_obj_coef(lp, k, AT(c, k-1, 2));
27 //printf("%d %f\n",k,AT(c, k-1, 2));
28 }
29
30 int * ia = malloc((1+tot)*sizeof(int));
31 int * ja = malloc((1+tot)*sizeof(int));
32 double * ar = malloc((1+tot)*sizeof(double));
33
34 for (k=1; k<= tot; k++) {
35 ia[k] = rint(AT(c,k-1+n,0));
36 ja[k] = rint(AT(c,k-1+n,1));
37 ar[k] = AT(c,k-1+n,2);
38 //printf("%d %d %f\n",ia[k],ja[k],ar[k]);
39 }
40 glp_load_matrix(lp, tot, ia, ja, ar);
41
42 int t;
43 for (i=1;i<=m;i++) {
44 switch((int)rint(AT(b,i-1,0))) {
45 case 0: { t = GLP_FR; break; }
46 case 1: { t = GLP_LO; break; }
47 case 2: { t = GLP_UP; break; }
48 case 3: { t = GLP_DB; break; }
49 default: { t = GLP_FX; break; }
50 }
51 glp_set_row_bnds(lp, i, t , AT(b,i-1,1), AT(b,i-1,2));
52 }
53 for (j=1;j<=n;j++) {
54 switch((int)rint(AT(b,m+j-1,0))) {
55 case 0: { t = GLP_FR; break; }
56 case 1: { t = GLP_LO; break; }
57 case 2: { t = GLP_UP; break; }
58 case 3: { t = GLP_DB; break; }
59 default: { t = GLP_FX; break; }
60 }
61 glp_set_col_bnds(lp, j, t , AT(b,m+j-1,1), AT(b,m+j-1,2));
62 }
63 glp_term_out(0);
64 glp_simplex(lp, NULL);
65 sp[0] = glp_get_status(lp);
66 sp[1] = glp_get_obj_val(lp);
67 for (k=1; k<=n; k++) {
68 sp[k+1] = glp_get_col_prim(lp, k);
69 }
70 glp_delete_prob(lp);
71 free(ia);
72 free(ja);
73 free(ar);
74
75 return 0;
76}