Skip to content

Commit

Permalink
Adding GLP_ICUTSELECT callback:
Browse files Browse the repository at this point in the history
- ios_process_cuts marks the cuts as selected after turning the cut into a row.
- This callback happens after ios_process_cuts marks and before the pool is
  cleared by ios_clear_pool.
  • Loading branch information
timothy-king committed Dec 29, 2013
1 parent afca2a6 commit c65ac7d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
51 changes: 50 additions & 1 deletion src/cutlog01.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ IOSAUX *ios_create_aux(int n, const int rows[], const double coeffs[]){
aux->nrows = n;
aux->rows = xcalloc(1+n, sizeof(int));
aux->mult = xcalloc(1+n, sizeof(double));
aux->selected = -1;
aux->mir_cset = NULL;

for ( i = 1; i <= n; i++)
Expand Down Expand Up @@ -93,7 +94,7 @@ static void cut_set_aux_mir(IOSAUX *aux, double delta,
for ( i = 1; i <= n; i++)
{ aux->mir_cset[i] = cset[i];
}

aux->mir_delta = delta;
}

Expand Down Expand Up @@ -192,3 +193,51 @@ void glp_ios_cut_get_aux_mir(glp_tree *tree, int ord,
}
}
}

void ios_cut_set_selected(IOSCUT *cut, int sel){
#ifdef CUT_DEBUG
static int i = 0;
++i;
printf("ios_cut_set_selected: %d %d %p\n", i, sel, cut);
#endif

IOSAUX *aux;
aux = cut->aux;
if ( aux != NULL ){
aux->selected = sel;
}
}

int glp_ios_selected_cuts(glp_tree *tree, int ords[], int sel[]){
int len, j, N, s;
IOSPOOL* pool;
IOSCUT* cut;
IOSAUX* aux;
if ( tree == NULL ){
xerror("glp_ios_selected_cuts: not called with a valid tree.\n");
}
if ( tree->reason != GLP_ICUTSELECT ){
xerror("glp_ios_selected_cuts: not called during cut selected.\n");
}

pool = tree->local;
if ( pool == NULL ){
xerror("glp_ios_selected_cuts: called on a malformed tree.\n");
}

for (len = 0, j = 1, cut = pool->head; cut != NULL; cut = cut->next, j++)
{ aux = cut->aux;
#ifdef CUT_DEBUG
printf("glp_ios_selected_cuts: %d %p\n", j, cut);
#endif
if ( aux != NULL )
{ s = aux->selected;
if ( s >= 0 )
{ len++;
if (ords != NULL) { ords[len] = j; }
if (sel != NULL) { sel[len] = s; }
}
}
}
return len;
}
10 changes: 8 additions & 2 deletions src/glpapi13.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,14 @@ void glp_ios_row_attr(glp_tree *tree, int i, glp_attr *attr)

int glp_ios_pool_size(glp_tree *tree)
{ /* determine current size of the cut pool */
if (tree->reason != GLP_ICUTGEN && tree->reason != GLP_ICUTADDED )
xerror("glp_ios_pool_size: operation not allowed\n");
switch(tree->reason)
{ case GLP_ICUTGEN:
case GLP_ICUTADDED:
case GLP_ICUTSELECT:
break;
default:
xerror("glp_ios_pool_size: operation not allowed\n");
}
xassert(tree->local != NULL);
return tree->local->size;
}
Expand Down
8 changes: 8 additions & 0 deletions src/glpios.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ struct IOSAUX
int *rows;
double *mult;

int selected;
/* when < 0 this has not yet been turned into a row
when >=0 this is the id of the row added. */

char *mir_cset;
/* complimented set */
Expand Down Expand Up @@ -661,8 +664,13 @@ void ios_cut_set_single_aux(glp_tree *T, int ord, int j);
void ios_cut_set_aux(glp_tree *T, int ord, int n,
const int rows[], const double coeffs[]);
/* sets an arbitrary aux sum */

void ios_cut_set_aux_mir(glp_tree *T, int ord, double delta,
int n, const char cset[]);
/* sets the extra mir information */

void ios_cut_set_selected(IOSCUT *cut, int i);
/* the cut has been added as row i */

#endif

Expand Down
8 changes: 8 additions & 0 deletions src/glpios03.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,14 @@ int ios_driver(glp_tree *T)
ios_process_cuts(T);
T->reason = 0;
}
/* if the local cut pool is not empty and the callback func is there,
this gives the callback the chance to see what was selected. */
if (T->parm->cb_func != NULL && T->local->size > 0)
{ xassert(T->reason == 0);
T->reason = GLP_ICUTSELECT;
T->parm->cb_func(T, T->parm->cb_info);
T->reason = 0;
}
/* clear the local cut pool */
ios_clear_pool(T, T->local);
/* perform re-optimization, if necessary */
Expand Down
3 changes: 3 additions & 0 deletions src/glpios11.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ void ios_process_cuts(glp_tree *T)
glp_set_mat_row(T->mip, i, len, ind, val);
xassert(cut->type == GLP_LO || cut->type == GLP_UP);
glp_set_row_bnds(T->mip, i, cut->type, cut->rhs, cut->rhs);

/* setting this as selected */
ios_cut_set_selected(cut, i);
}
/* free working arrays */
xfree(info);
Expand Down
5 changes: 5 additions & 0 deletions src/glpk.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ typedef struct
#define GLP_ISELECT 0x06 /* request for subproblem selection */
#define GLP_IPREPRO 0x07 /* request for preprocessing */
#define GLP_ICUTADDED 0x08 /* cut was added to the pool */
#define GLP_ICUTSELECT 0x09 /* cuts were selected as rows */

/* branch selection indicator: */
#define GLP_NO_BRNCH 0 /* select no branch */
Expand Down Expand Up @@ -1082,6 +1083,10 @@ void glp_ios_cut_get_aux_mir(glp_tree *tree, int ord,
char cset[], double *delta);
/* gets mir cut specific information. */

int glp_ios_selected_cuts(glp_tree *tree, int ords[], int sel[]);
/* gets the list of selected cuts.
Can only be called when GLP_ICUTSELECT */

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit c65ac7d

Please sign in to comment.