summaryrefslogtreecommitdiffhomepage
path: root/ir/lpp
diff options
context:
space:
mode:
authorChristoph Mallon <christoph.mallon@gmx.de>2012-07-20 09:14:06 +0200
committerChristoph Mallon <christoph.mallon@gmx.de>2012-07-20 09:15:48 +0200
commit62038ec14e9c072a91b13270058bb18958027aa8 (patch)
treee3eb305ca0856ec357568800d47e4f86ac367e5c /ir/lpp
parent8924d174c51bc58493a17b5ab0675a9c2c959815 (diff)
Let matrix_foreach(), matrix_foreach_in_col() and matrix_foreach_in_row() declare their iterator variables.
Diffstat (limited to 'ir/lpp')
-rw-r--r--ir/lpp/lpp.c23
-rw-r--r--ir/lpp/lpp_cplex.c17
-rw-r--r--ir/lpp/lpp_gurobi.c25
-rw-r--r--ir/lpp/mps.c2
-rw-r--r--ir/lpp/sp_matrix.c14
-rw-r--r--ir/lpp/sp_matrix.h6
6 files changed, 39 insertions, 48 deletions
diff --git a/ir/lpp/lpp.c b/ir/lpp/lpp.c
index 85b3093..04732a7 100644
--- a/ir/lpp/lpp.c
+++ b/ir/lpp/lpp.c
@@ -413,7 +413,6 @@ void lpp_dump_plain(lpp_t *lpp, FILE *f)
int i;
for(i = 0; i < lpp->cst_next; ++i) {
- const matrix_elem_t *elm;
lpp_name_t *cst = lpp->csts[i];
fprintf(f, "%16s: ", cst->name);
@@ -470,20 +469,16 @@ void lpp_serialize(lpp_comm_t *comm, const lpp_t *lpp, int with_names)
lpp_writes(comm, name->name);
}
- {
- const matrix_elem_t *elm;
- n = 0;
+ n = 0;
+ matrix_foreach(lpp->m, elm)
+ n++;
- matrix_foreach(lpp->m, elm)
- n++;
-
- assert(n == matrix_get_entries(lpp->m));
- lpp_writel(comm, n);
- matrix_foreach(lpp->m, elm) {
- lpp_writel(comm, elm->row);
- lpp_writel(comm, elm->col);
- lpp_writed(comm, elm->val);
- }
+ assert(n == matrix_get_entries(lpp->m));
+ lpp_writel(comm, n);
+ matrix_foreach(lpp->m, elm) {
+ lpp_writel(comm, elm->row);
+ lpp_writel(comm, elm->col);
+ lpp_writed(comm, elm->val);
}
}
diff --git a/ir/lpp/lpp_cplex.c b/ir/lpp/lpp_cplex.c
index d24c874..0ae2aff 100644
--- a/ir/lpp/lpp_cplex.c
+++ b/ir/lpp/lpp_cplex.c
@@ -85,15 +85,14 @@ static void free_cpx(cpx_t *cpx)
*/
static void cpx_construct(cpx_t *cpx)
{
- const matrix_elem_t *elem;
- int i, o, sv_cnt;
- int numcols, numrows, numentries;
- int objsen, *matbeg, *matcnt, *matind, *indices;
- double *obj, *rhs, *matval, *lb, *ub, *startv;
- char *sense, *vartype;
- char **colname, **rowname;
- struct obstack obst;
- lpp_t *lpp = cpx->lpp;
+ int i, o, sv_cnt;
+ int numcols, numrows, numentries;
+ int objsen, *matbeg, *matcnt, *matind, *indices;
+ double *obj, *rhs, *matval, *lb, *ub, *startv;
+ char *sense, *vartype;
+ char **colname, **rowname;
+ struct obstack obst;
+ lpp_t *lpp = cpx->lpp;
numcols = lpp->var_next-1;
numrows = lpp->cst_next-1;
diff --git a/ir/lpp/lpp_gurobi.c b/ir/lpp/lpp_gurobi.c
index a87e6e1..6f896d9 100644
--- a/ir/lpp/lpp_gurobi.c
+++ b/ir/lpp/lpp_gurobi.c
@@ -97,19 +97,18 @@ static void free_gurobi(gurobi_t *grb)
*/
static void gurobi_construct(gurobi_t *grb)
{
- const matrix_elem_t *elem;
- int i, o;
- //int sv_cnt;
- //int *indices;
- //double *startv;
- int numcols, numrows, numentries;
- int objsen, *matbeg, *matcnt, *matind;
- double *obj, *rhs, *matval, *lb;
- char *sense, *vartype;
- char **colname, **rowname;
- struct obstack obst;
- lpp_t *lpp = grb->lpp;
- int error;
+ int i, o;
+ //int sv_cnt;
+ //int *indices;
+ //double *startv;
+ int numcols, numrows, numentries;
+ int objsen, *matbeg, *matcnt, *matind;
+ double *obj, *rhs, *matval, *lb;
+ char *sense, *vartype;
+ char **colname, **rowname;
+ struct obstack obst;
+ lpp_t *lpp = grb->lpp;
+ int error;
numcols = lpp->var_next-1;
numrows = lpp->cst_next-1;
diff --git a/ir/lpp/mps.c b/ir/lpp/mps.c
index 309451f..a493c0a 100644
--- a/ir/lpp/mps.c
+++ b/ir/lpp/mps.c
@@ -90,7 +90,7 @@ void mps_write_mps(lpp_t *lpp, lpp_mps_style_t style, FILE *out)
{
int i, count, marker_nr = 0;
const lpp_name_t *curr;
- const matrix_elem_t *elem, *before = NULL;
+ const matrix_elem_t *before = NULL;
lpp_var_t last_type;
assert(style == s_mps_fixed || style == s_mps_free);
diff --git a/ir/lpp/sp_matrix.c b/ir/lpp/sp_matrix.c
index 500ba2e..4145316 100644
--- a/ir/lpp/sp_matrix.c
+++ b/ir/lpp/sp_matrix.c
@@ -613,7 +613,6 @@ static int cmp_count(const void *e1, const void *e2)
static inline void matrix_fill_row(sp_matrix_t *m, int row, bitset_t *fullrow)
{
- const matrix_elem_t *e;
bitset_set(fullrow, row);
matrix_foreach_in_col(m, row, e) {
if (! bitset_is_set(fullrow, e->row)) {
@@ -628,7 +627,6 @@ void matrix_optimize(sp_matrix_t *m)
{
int i, size, redo;
int *c;
- const matrix_elem_t *e;
bitset_t *fullrow;
size = MAX(m->maxcol, m->maxrow)+1;
@@ -662,7 +660,8 @@ void matrix_optimize(sp_matrix_t *m)
if (c[i] == 1 && ! bitset_is_set(fullrow, i)) {
redo = 1;
/* if the other row isn't empty move the e in there, else fill e's row */
- if (e = matrix_row_first(m, i), e) {
+ matrix_elem_t const *const e = matrix_row_first(m, i);
+ if (e) {
if (c[e->col] > 0)
matrix_fill_row(m, e->col, fullrow);
else
@@ -687,7 +686,6 @@ void matrix_optimize(sp_matrix_t *m)
void matrix_dump(sp_matrix_t *m, FILE *out, int factor)
{
int i, o, last_idx;
- const matrix_elem_t *e;
for (i = 0; i <= m->maxrow; ++i) {
last_idx = -1;
@@ -709,7 +707,6 @@ void matrix_dump(sp_matrix_t *m, FILE *out, int factor)
void matrix_self_test(int d)
{
int i, o;
- const matrix_elem_t *e;
sp_matrix_t *m = new_matrix(10, 10);
for (i = 0; i < d; ++i)
@@ -757,9 +754,10 @@ void matrix_self_test(int d)
matrix_set(m, 3,5,4);
matrix_set(m, 4,4,5);
matrix_set(m, 5,5,6);
- for (i=1, e = matrix_first(m); e; ++i, e=matrix_next(m))
- assert(e->val == i);
- assert(i == 7);
+ i = 0;
+ matrix_foreach(m, e)
+ assert(e->val == ++i);
+ assert(i == 6);
matrix_set(m, 1,1,0);
assert(5 == matrix_get_entries(m));
del_matrix(m);
diff --git a/ir/lpp/sp_matrix.h b/ir/lpp/sp_matrix.h
index 7b2a2b8..6f17479 100644
--- a/ir/lpp/sp_matrix.h
+++ b/ir/lpp/sp_matrix.h
@@ -117,7 +117,7 @@ unsigned matrix_get_elem_size(void);
* Save against removal of curr
*/
#define matrix_foreach(m,curr) \
- for (curr = matrix_first(m); curr; curr = matrix_next(m))
+ for (matrix_elem_t const *curr = matrix_first(m); curr; curr = matrix_next(m))
/**
* m The matrix
@@ -126,7 +126,7 @@ unsigned matrix_get_elem_size(void);
* Save against removal of curr
*/
#define matrix_foreach_in_row(m,r,curr) \
- for (curr = matrix_row_first(m, r); curr; curr = matrix_next(m))
+ for (matrix_elem_t const *curr = matrix_row_first(m, r); curr; curr = matrix_next(m))
/**
* m The matrix
@@ -135,7 +135,7 @@ unsigned matrix_get_elem_size(void);
* Save against removal of curr
*/
#define matrix_foreach_in_col(m,c,curr) \
- for (curr = matrix_col_first(m, c); curr; curr = matrix_next(m))
+ for (matrix_elem_t const *curr = matrix_col_first(m, c); curr; curr = matrix_next(m))
/**
* Changes the matrix into an equivalent one with maximal number zero-rows.