int cg_send_cut(cut_data *new_cut, int *num_cuts, int *alloc_cuts, cut_data ***cuts) { #ifdef COMPILE_IN_CG int i; cut_data *tmp_cut; for (i = 0; i < *num_cuts; i++){ if (new_cut->type != (*cuts)[i]->type || new_cut->size != (*cuts)[i]->size || new_cut->rhs != (*cuts)[i]->rhs){ continue; } if (!new_cut->coef){ return(0); } if (memcmp(new_cut->coef, (*cuts)[i]->coef, new_cut->size) == 0){ return(0); } } if (new_cut->name != CUT__DO_NOT_SEND_TO_CP) new_cut->name = CUT__SEND_TO_CP; tmp_cut = (cut_data *) malloc (sizeof(cut_data)); memcpy((char *)tmp_cut, (char *)new_cut, sizeof(cut_data)); if (new_cut->size >0){ tmp_cut->coef = (char *) malloc (new_cut->size * sizeof(char)); memcpy((char *)tmp_cut->coef, (char *)new_cut->coef, new_cut->size * sizeof(char)); } REALLOC((*cuts), cut_data *, (*alloc_cuts), (*num_cuts + 1), BB_BUNCH); (*cuts)[(*num_cuts)++] = tmp_cut; #else int s_bufid; if (new_cut->name != CUT__DO_NOT_SEND_TO_CP) new_cut->name = CUT__SEND_TO_CP; s_bufid = init_send(DataInPlace); pack_cut(new_cut); send_msg(p->cur_sol.lp, PACKED_CUT); freebuf(s_bufid); #endif return(1); }
node_desc *create_explicit_node_desc(lp_prob *p) { LPdata *lp_data = p->lp_data; int m = lp_data->m, n = lp_data->n; int bvarnum = p->base.varnum; var_desc **extravars = lp_data->vars + bvarnum; int extravarnum = n - bvarnum; int bcutnum = p->base.cutnum; row_data *rows = lp_data->rows; int extrarownum = m - bcutnum; int cutindsize; node_desc *desc = (node_desc *) calloc(1, sizeof(node_desc)); /* Will need these anyway for basis */ int *rstat = (int *) malloc(m * ISIZE); int *cstat = (int *) malloc(n * ISIZE); int *erstat = (extrarownum == 0) ? NULL : (int *) malloc(extrarownum*ISIZE); int *ecstat = (extravarnum == 0) ? NULL : (int *) malloc(extravarnum*ISIZE); int *ulist, *clist; /* this later uses tmp.i1 */ int cutcnt, i, j; #ifndef COMPILE_IN_LP int s_bufid, r_bufid; #endif get_basis(lp_data, cstat, rstat); if (extrarownum > 0) memcpy(erstat, rstat + bcutnum, extrarownum * ISIZE); if (extravarnum > 0) memcpy(ecstat, cstat + bvarnum, extravarnum * ISIZE); /* To start with, send the non-indexed cuts (only those which will be saved) to the treemanager and ask for names */ for (cutcnt = cutindsize = 0, i = bcutnum; i < m; i++){ if ((rows[i].cut->branch & CUT_BRANCHED_ON) || !rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)){ cutindsize++; if (rows[i].cut->name < 0) cutcnt++; } } if (cutcnt > 0){ #ifdef COMPILE_IN_LP row_data *tmp_rows = (row_data *) malloc(cutcnt*sizeof(row_data)); for (j = 0, i = bcutnum; j < cutcnt; i++){ if (rows[i].cut->name < 0 && (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC))) tmp_rows[j++] = rows[i]; } unpack_cut_set(p->tm, 0, cutcnt, tmp_rows); FREE(tmp_rows); #else s_bufid = init_send(DataInPlace); send_int_array(&cutcnt, 1); for (i = bcutnum; i < m; i++){ if (rows[i].cut->name < 0 && (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC))) pack_cut(rows[i].cut); } send_msg(p->tree_manager, LP__CUT_NAMES_REQUESTED); freebuf(s_bufid); #endif } /* create the uind list and the extravars basis description */ desc->uind.type = EXPLICIT_LIST; desc->uind.added = 0; desc->uind.size = extravarnum; desc->basis.extravars.type = EXPLICIT_LIST; desc->basis.extravars.size = extravarnum; desc->basis.extravars.list = NULL; if (extravarnum > 0){ desc->uind.list = ulist = (int *) malloc(extravarnum * ISIZE); desc->basis.extravars.stat = ecstat; for (i = extravarnum - 1; i >= 0; i--) ulist[i] = extravars[i]->userind; if (lp_data->ordering == COLIND_ORDERED) qsortucb_ii(ulist, ecstat, extravarnum); }else{ desc->uind.list = NULL; desc->basis.extravars.stat = NULL; } /* create the basevars basis description */ desc->basis.basevars.type = EXPLICIT_LIST; desc->basis.basevars.size = bvarnum; desc->basis.basevars.list = NULL; if (bvarnum) desc->basis.basevars.stat = cstat; else FREE(cstat); /* create the not_fixed list */ desc->nf_status = lp_data->nf_status; if (desc->nf_status == NF_CHECK_AFTER_LAST || desc->nf_status == NF_CHECK_UNTIL_LAST){ desc->not_fixed.type = EXPLICIT_LIST; desc->not_fixed.added = 0; if ((desc->not_fixed.size = lp_data->not_fixed_num) > 0){ desc->not_fixed.list = (int *) malloc(desc->not_fixed.size * ISIZE); memcpy(desc->not_fixed.list, lp_data->not_fixed, lp_data->not_fixed_num * ISIZE); }else{ desc->not_fixed.list = NULL; } } #ifndef COMPILE_IN_LP /* At this point we will need the missing names */ if (cutcnt > 0){ static struct timeval tout = {15, 0}; int *names = lp_data->tmp.i1; /* m */ double start = wall_clock(NULL); do{ r_bufid = treceive_msg(p->tree_manager, LP__CUT_NAMES_SERVED, &tout); if (! r_bufid){ if (pstat(p->tree_manager) != PROCESS_OK){ printf("TM has died -- LP exiting\n\n"); exit(-301); } } }while (! r_bufid); p->comp_times.idle_names += wall_clock(NULL) - start; receive_int_array(names, cutcnt); for (j = 0, i = bcutnum; j < cutcnt; i++){ if (rows[i].cut->name < 0 && (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC))) rows[i].cut->name = names[j++]; } } #endif /* create the cutind list and the extrarows basis description */ desc->cutind.type = EXPLICIT_LIST; desc->cutind.added = 0; desc->cutind.size = cutindsize; desc->basis.extrarows.type = EXPLICIT_LIST; desc->basis.extrarows.list = NULL; desc->basis.extrarows.size = cutindsize; if (cutindsize > 0){ desc->cutind.list = clist = (int *) malloc(cutindsize * ISIZE); desc->basis.extrarows.stat = erstat; for (cutindsize = 0, i = bcutnum; i < m; i++){ if ((rows[i].cut->branch & CUT_BRANCHED_ON) || !rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)){ clist[cutindsize] = rows[i].cut->name; erstat[cutindsize++] = rstat[i]; } } qsortucb_ii(clist, erstat, cutindsize); }else{ desc->cutind.list = NULL; desc->basis.extrarows.stat = NULL; } /* create the baserows basis description */ desc->basis.baserows.type = EXPLICIT_LIST; desc->basis.baserows.size = bcutnum; desc->basis.baserows.list = NULL; if (bcutnum) desc->basis.baserows.stat = rstat; else FREE(rstat); /* Mark that there is a basis */ desc->basis.basis_exists = TRUE; /* Add user description */ add_to_desc_u(p, desc); return(desc); }