Commit 62038ec1 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Let matrix_foreach(), matrix_foreach_in_col() and matrix_foreach_in_row()...

Let matrix_foreach(), matrix_foreach_in_col() and matrix_foreach_in_row() declare their iterator variables.
parent 8924d174
......@@ -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);
}
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment