[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] glp_get_col_prim() problem
From: |
Volkan YAZICI |
Subject: |
[Help-glpk] glp_get_col_prim() problem |
Date: |
Thu, 22 Apr 2010 12:08:07 +0300 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Hi,
[First, thanks Mr. Andrew Makhorin for such a fantastic tool. BTW, if
you would need any relatively huge (~200MB) sample CPLEX LP problems to
benchmark GLPK, I'd be happy to share our archives. Moreover, is there
any parallel implementation of GLPK? My other 23 cores are sitting
idle.]
I'm having troubles while trying to get the solution variables via C
API. Below is the code I use in my program:
/* Maximum # of characters will be used by a variable symbol. */
#define MAX_VAR_LEN 32
static int
glp_get_col_val(glp_prob *lp, const char name, int index)
{
char var[MAX_VAR_LEN];
int i;
snprintf(var, (MAX_VAR_LEN * sizeof(char)), "%c%d", name, index);
assert(lp);
i = glp_find_col(lp, var);
assert(i > 0);
return (int) glp_get_col_prim(lp, i);
}
int *
solve_ilp(...)
{
glp_prob *lp;
...
/* Load the problem instance. */
lp = glp_create_prob();
assert(!glp_read_lp(lp, NULL, pathname));
glp_create_index(lp);
/* Solve the problem instance. */
assert(!glp_simplex(lp, NULL) && glp_get_status(lp) == GLP_OPT);
#ifdef DEBUG_ILP
{
int i;
int *xs;
int *ys;
xs = gc_nonref_malloc(g->n * sizeof(int));
for (i = 0; i < g->n; i++) xs[i] = glp_get_col_val(lp, 'x', i);
PRINT_VECTOR(xs, g->n, "xs");
ys = gc_nonref_malloc(g->c * sizeof(int));
for (i = 0; i < g->c; i++) ys[i] = glp_get_col_val(lp, 'y', i);
PRINT_VECTOR(ys, g->c, "ys");
}
#endif
...
}
The problem is, while above program outputs:
Reading problem data from `repl-ilp-Pycj92'...
13 rows, 15 columns, 27 non-zeros
15 integer variables, all of which are binary
33 lines were read
GLPK Simplex Optimizer, v4.43
13 rows, 15 columns, 27 non-zeros
* 0: obj = 0.000000000e+00 infeas = 0.000e+00 (0)
* 13: obj = 2.000000000e+00 infeas = 0.000e+00 (0)
OPTIMAL SOLUTION FOUND
xs[12]: 0 0 0 0 0 0 0 0 0 0 0 0
ys[3]: 0 0 0
glpsol gives a different result.
$ glpsol --cpxlp /tmp/repl-ilp-Pycj92 -o /tmp/repl-ilp-Pycj92.out
glp_read_lp: reading problem data from `/tmp/repl-ilp-Pycj92'...
glp_read_lp: 13 rows, 15 columns, 27 non-zeros
glp_read_lp: 15 integer columns, all of which are binary
glp_read_lp: 33 lines were read
glp_simplex: original LP has 13 rows, 15 columns, 27 non-zeros
glp_simplex: presolved LP has 13 rows, 15 columns, 27 non-zeros
lpx_adv_basis: size of triangular part = 13
* 0: objval = 0.000000000e+00 infeas = 0.000000000e+00 (0)
* 1: objval = 2.000000000e+00 infeas = 0.000000000e+00 (0)
OPTIMAL SOLUTION FOUND
Integer optimization begins...
+ 1: mip = not found yet <= +inf (1; 0)
+ 2: >>>>> 2.000000000e+00 <= 2.000000000e+00 0.0% (1; 0)
+ 2: mip = 2.000000000e+00 <= tree is empty 0.0% (0; 1)
INTEGER OPTIMAL SOLUTION FOUND
Time used: 0.0 secs
Memory used: 0.0 Mb (45904 bytes)
lpx_print_mip: writing MIP problem solution to `/tmp/repl-ilp-Pycj92.out'...
$ cat /tmp/repl-ilp-Pycj92.out
Problem:
Rows: 13
Columns: 15 (15 integer, 15 binary)
Non-zeros: 27
Status: INTEGER OPTIMAL
Objective: obj = 2 (MAXimum)
No. Row name Activity Lower bound Upper bound
------ ------------ ------------- ------------- -------------
1 r.4 0 0
2 r.5 0 0
3 r.6 0 0
4 r.7 0 0
5 r.8 0 0
6 r.9 0 0
7 r.10 0 0
8 r.11 0 0
9 r.12 0 0
10 r.13 0 0
11 r.14 0 0
12 r.15 0 0
13 r.16 1 1
No. Column name Activity Lower bound Upper bound
------ ------------ ------------- ------------- -------------
1 x0 * 0 0 1
2 x1 * 0 0 1
3 x2 * 0 0 1
4 x3 * 0 0 1
5 x4 * 0 0 1
6 x5 * 0 0 1
7 x6 * 0 0 1
8 x7 * 0 0 1
9 x8 * 0 0 1
10 x9 * 0 0 1
11 x10 * 1 0 1
12 x11 * 1 0 1
13 y0 * 0 0 1
14 y1 * 0 0 1
15 y2 * 1 0 1
Integer feasibility conditions:
INT.PE: max.abs.err. = 0.00e+00 on row 0
max.rel.err. = 0.00e+00 on row 0
High quality
INT.PB: max.abs.err. = 0.00e+00 on row 0
max.rel.err. = 0.00e+00 on row 0
High quality
End of output
And the results returned by glpsol are the right ones. What might I be
missing in the C code? (To be honest, I'm in a quite hurry and any
replies will be really really appreciated.)
Regards.
- [Help-glpk] glp_get_col_prim() problem,
Volkan YAZICI <=