Skip to content

Commit

Permalink
Fix cstat and rstat arrays in select_branching_object()
Browse files Browse the repository at this point in the history
cstat and rstat were initialized with tmp arrays in LPData and were
occasionally overwritten during strong branching. Two fields
have been added to LPData struct so that they are resized/freed similarly
to other structures.
  • Loading branch information
febattista committed Apr 10, 2024
1 parent 89754e7 commit da964ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions include/sym_lp_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ typedef struct LPDATA{
cgl_params cgl;

int *frac_var_cnt;
// feb223
int *cstat; /* to be used in branching to save the basis */
int *rstat;

}LPdata;

Expand Down
5 changes: 3 additions & 2 deletions src/LP/lp_branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ int select_branching_object(lp_prob *p, int *cuts, branch_obj **candidate)
st_time = used_time(&total_time);
total_iters = 0;

int *cstat = lp_data->tmp.i1;
int *rstat = lp_data->tmp.i2;

int *cstat = lp_data->cstat; //lp_data->tmp.i1;
int *rstat = lp_data->rstat; //lp_data->tmp.i2;

get_basis(lp_data, cstat, rstat);

Expand Down
37 changes: 26 additions & 11 deletions src/LP/lp_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void free_lp_arrays(LPdata *lp_data)
//Anahita
FREE(lp_data->raysol);
FREE(lp_data->slacks);
// feb223
FREE(lp_data->cstat);
FREE(lp_data->rstat);

FREE(lp_data->random_hash);
FREE(lp_data->hashes);
FREE(lp_data->accepted_ind);
Expand Down Expand Up @@ -192,21 +196,26 @@ void size_lp_arrays(LPdata *lp_data, char do_realloc, char set_max,
if (! do_realloc){
FREE(lp_data->dualsol);
lp_data->dualsol = (double *) malloc(lp_data->maxm * DSIZE);
//Anahita
//Anahita
FREE(lp_data->raysol);
lp_data->raysol = (double *) malloc(lp_data->maxm * DSIZE);
//
FREE(lp_data->slacks);
lp_data->slacks = (double *) malloc(lp_data->maxm * DSIZE);

FREE(lp_data->slacks);
lp_data->slacks = (double *) malloc(lp_data->maxm * DSIZE);
FREE(lp_data->rstat);
lp_data->rstat = (int *)malloc((lp_data->maxm) * ISIZE);
}else{
lp_data->dualsol = (double *) realloc((char *)lp_data->dualsol,
lp_data->maxm * DSIZE);
//Anahita
lp_data->raysol = (double *) realloc((char *)lp_data->raysol,
lp_data->maxm * DSIZE);
//
lp_data->slacks = (double *) realloc((void *)lp_data->slacks,
lp_data->maxm * DSIZE);
//Anahita
lp_data->raysol = (double *) realloc((char *)lp_data->raysol,
lp_data->maxm * DSIZE);
//
lp_data->slacks = (double *) realloc((void *)lp_data->slacks,
lp_data->maxm * DSIZE);
// feb223
lp_data->rstat = (int *)realloc((void *)lp_data->rstat,
(lp_data->maxm) * ISIZE);
}
/* rows is realloc'd in either case just to keep the base constr */
lp_data->rows = (row_data *) realloc((char *)lp_data->rows,
Expand All @@ -228,7 +237,10 @@ void size_lp_arrays(LPdata *lp_data, char do_realloc, char set_max,
FREE(lp_data->heur_solution);
lp_data->heur_solution = (double *) malloc(lp_data->maxn * DSIZE);
FREE(lp_data->col_solution);
lp_data->col_solution = (double *) malloc(lp_data->maxn * DSIZE);
lp_data->col_solution = (double *)malloc(lp_data->maxn * DSIZE);
// feb223
FREE(lp_data->cstat);
lp_data->cstat = (int *)malloc((lp_data->maxn) * ISIZE);
#ifdef __CPLEX__
FREE(lp_data->lb);
lp_data->lb = (double *) malloc(lp_data->maxn * DSIZE);
Expand All @@ -248,6 +260,9 @@ void size_lp_arrays(LPdata *lp_data, char do_realloc, char set_max,
lp_data->heur_solution, lp_data->maxn * DSIZE);
lp_data->col_solution = (double *) realloc((char *)
lp_data->col_solution, lp_data->maxn * DSIZE);
// feb223
lp_data->cstat = (int *)realloc((void *)lp_data->cstat,
(lp_data->maxn) * ISIZE);
#ifdef __CPLEX__
lp_data->lb = (double *) realloc((char *)lp_data->lb,
lp_data->maxn * DSIZE);
Expand Down

0 comments on commit da964ae

Please sign in to comment.