diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-02-24 09:03:40 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-02-24 09:03:40 +0000 |
commit | 4ebde988645cb1d2d60f8df8605ec8254713a9d9 (patch) | |
tree | 3fd001a92921dcc553e01c8c32849f5e8135247a /packages/glpk/lib/Numeric/LinearProgramming/glpk.c | |
parent | e0605467b60f65478d0f5cc8f82ba14a99168f7b (diff) |
removed simplexDense
Diffstat (limited to 'packages/glpk/lib/Numeric/LinearProgramming/glpk.c')
-rw-r--r-- | packages/glpk/lib/Numeric/LinearProgramming/glpk.c | 83 |
1 files changed, 6 insertions, 77 deletions
diff --git a/packages/glpk/lib/Numeric/LinearProgramming/glpk.c b/packages/glpk/lib/Numeric/LinearProgramming/glpk.c index 0f4ad79..bfbb435 100644 --- a/packages/glpk/lib/Numeric/LinearProgramming/glpk.c +++ b/packages/glpk/lib/Numeric/LinearProgramming/glpk.c | |||
@@ -1,84 +1,14 @@ | |||
1 | typedef struct { double r, i; } doublecomplex; | ||
2 | |||
3 | #define DVEC(A) int A##n, double*A##p | 1 | #define DVEC(A) int A##n, double*A##p |
4 | #define CVEC(A) int A##n, doublecomplex*A##p | ||
5 | #define DMAT(A) int A##r, int A##c, double*A##p | 2 | #define DMAT(A) int A##r, int A##c, double*A##p |
6 | #define CMAT(A) int A##r, int A##c, doublecomplex*A##p | ||
7 | 3 | ||
8 | #define AT(M,r,co) (M##p[(r)*M##c+(co)]) | 4 | #define AT(M,r,co) (M##p[(r)*M##c+(co)]) |
9 | 5 | ||
10 | /*-----------------------------------------------------*/ | ||
11 | |||
12 | #include <stdlib.h> | 6 | #include <stdlib.h> |
13 | #include <stdio.h> | 7 | #include <stdio.h> |
14 | #include <glpk.h> | 8 | #include <glpk.h> |
15 | #include <math.h> | 9 | #include <math.h> |
16 | 10 | ||
17 | int c_simplex_dense(DMAT(c), DMAT(b), DVEC(s)) { | 11 | /*-----------------------------------------------------*/ |
18 | glp_prob *lp; | ||
19 | lp = glp_create_prob(); | ||
20 | glp_set_obj_dir(lp, GLP_MAX); | ||
21 | |||
22 | int m = cr-1; | ||
23 | int n = cc; | ||
24 | glp_add_rows(lp, m); | ||
25 | glp_add_cols(lp, n); | ||
26 | int * ia = malloc((1+m*n)*sizeof(int)); | ||
27 | int * ja = malloc((1+m*n)*sizeof(int)); | ||
28 | double * ar = malloc((1+m*n)*sizeof(double)); | ||
29 | int i,j,k; | ||
30 | k=0; | ||
31 | for (i=1;i<=m;i++) { | ||
32 | for(j=1;j<=n;j++) { | ||
33 | k++; | ||
34 | ia[k] = i; | ||
35 | ja[k] = j; | ||
36 | ar[k] = AT(c,i,j-1); | ||
37 | //printf("%d %d %f\n",ia[k],ja[k],ar[k]); | ||
38 | } | ||
39 | } | ||
40 | glp_load_matrix(lp, k, ia, ja, ar); | ||
41 | for (j=1;j<=n;j++) { | ||
42 | glp_set_obj_coef(lp, j, AT(c,0,j-1)); | ||
43 | } | ||
44 | int t; | ||
45 | for (i=1;i<=m;i++) { | ||
46 | switch((int)rint(AT(b,i-1,0))) { | ||
47 | case 0: { t = GLP_FR; break; } | ||
48 | case 1: { t = GLP_LO; break; } | ||
49 | case 2: { t = GLP_UP; break; } | ||
50 | case 3: { t = GLP_DB; break; } | ||
51 | default: { t = GLP_FX; break; } | ||
52 | } | ||
53 | glp_set_row_bnds(lp, i, t , AT(b,i-1,1), AT(b,i-1,2)); | ||
54 | } | ||
55 | for (j=1;j<=n;j++) { | ||
56 | switch((int)rint(AT(b,m+j-1,0))) { | ||
57 | case 0: { t = GLP_FR; break; } | ||
58 | case 1: { t = GLP_LO; break; } | ||
59 | case 2: { t = GLP_UP; break; } | ||
60 | case 3: { t = GLP_DB; break; } | ||
61 | default: { t = GLP_FX; break; } | ||
62 | } | ||
63 | glp_set_col_bnds(lp, j, t , AT(b,m+j-1,1), AT(b,m+j-1,2)); | ||
64 | } | ||
65 | glp_term_out(0); | ||
66 | glp_simplex(lp, NULL); | ||
67 | sp[0] = glp_get_status(lp); | ||
68 | sp[1] = glp_get_obj_val(lp); | ||
69 | for (k=1; k<=n; k++) { | ||
70 | sp[k+1] = glp_get_col_prim(lp, k); | ||
71 | } | ||
72 | |||
73 | glp_delete_prob(lp); | ||
74 | free(ia); | ||
75 | free(ja); | ||
76 | free(ar); | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | /* ---------------------------------------------------- */ | ||
82 | 12 | ||
83 | int c_simplex_sparse(int m, int n, DMAT(c), DMAT(b), DVEC(s)) { | 13 | int c_simplex_sparse(int m, int n, DMAT(c), DMAT(b), DVEC(s)) { |
84 | glp_prob *lp; | 14 | glp_prob *lp; |
@@ -108,25 +38,25 @@ int c_simplex_sparse(int m, int n, DMAT(c), DMAT(b), DVEC(s)) { | |||
108 | //printf("%d %d %f\n",ia[k],ja[k],ar[k]); | 38 | //printf("%d %d %f\n",ia[k],ja[k],ar[k]); |
109 | } | 39 | } |
110 | glp_load_matrix(lp, tot, ia, ja, ar); | 40 | glp_load_matrix(lp, tot, ia, ja, ar); |
111 | 41 | ||
112 | int t; | 42 | int t; |
113 | for (i=1;i<=m;i++) { | 43 | for (i=1;i<=m;i++) { |
114 | switch((int)rint(AT(b,i-1,0))) { | 44 | switch((int)rint(AT(b,i-1,0))) { |
115 | case 0: { t = GLP_FR; break; } | 45 | case 0: { t = GLP_FR; break; } |
116 | case 1: { t = GLP_LO; break; } | 46 | case 1: { t = GLP_LO; break; } |
117 | case 2: { t = GLP_UP; break; } | 47 | case 2: { t = GLP_UP; break; } |
118 | case 3: { t = GLP_DB; break; } | 48 | case 3: { t = GLP_DB; break; } |
119 | default: { t = GLP_FX; break; } | 49 | default: { t = GLP_FX; break; } |
120 | } | 50 | } |
121 | glp_set_row_bnds(lp, i, t , AT(b,i-1,1), AT(b,i-1,2)); | 51 | glp_set_row_bnds(lp, i, t , AT(b,i-1,1), AT(b,i-1,2)); |
122 | } | 52 | } |
123 | for (j=1;j<=n;j++) { | 53 | for (j=1;j<=n;j++) { |
124 | switch((int)rint(AT(b,m+j-1,0))) { | 54 | switch((int)rint(AT(b,m+j-1,0))) { |
125 | case 0: { t = GLP_FR; break; } | 55 | case 0: { t = GLP_FR; break; } |
126 | case 1: { t = GLP_LO; break; } | 56 | case 1: { t = GLP_LO; break; } |
127 | case 2: { t = GLP_UP; break; } | 57 | case 2: { t = GLP_UP; break; } |
128 | case 3: { t = GLP_DB; break; } | 58 | case 3: { t = GLP_DB; break; } |
129 | default: { t = GLP_FX; break; } | 59 | default: { t = GLP_FX; break; } |
130 | } | 60 | } |
131 | glp_set_col_bnds(lp, j, t , AT(b,m+j-1,1), AT(b,m+j-1,2)); | 61 | glp_set_col_bnds(lp, j, t , AT(b,m+j-1,1), AT(b,m+j-1,2)); |
132 | } | 62 | } |
@@ -144,4 +74,3 @@ int c_simplex_sparse(int m, int n, DMAT(c), DMAT(b), DVEC(s)) { | |||
144 | 74 | ||
145 | return 0; | 75 | return 0; |
146 | } | 76 | } |
147 | |||