static int verify_text_pool (char *poolname, int nodecount) { int rval; int *tour = (int *) NULL; CCtsp_lpcut_in *cuts = (CCtsp_lpcut_in *) NULL; CCtsp_lpcut_in *cnext; int cutcount; int nfail = 0; int nsuccess = 0; int i; tour = CC_SAFE_MALLOC (nodecount, int); if (tour == (int *) NULL) { fprintf (stderr, "Out of memory in verify_text_pool\n"); rval = 1; goto CLEANUP; } for (i=0; i<nodecount; i++) tour[i] = i; rval = CCtsp_file_cuts (poolname, &cuts, &cutcount, nodecount, tour); if (rval) { fprintf (stderr, "CCtsp_file_cuts failed\n"); goto CLEANUP; } while (cuts) { cnext = cuts->next; rval = CCverify_cut (cuts, CC_TYPE_ALL, (int *) NULL); if (rval) { fprintf (stderr, "CCverify_cut failed\n"); nfail++; } else { nsuccess++; } CCtsp_free_lpcut_in (cuts); CC_FREE (cuts, CCtsp_lpcut_in); cuts = cnext; } printf ("%d of %d cuts failed verification\n", nfail, nfail + nsuccess); if (nfail == 0) rval = 0; else rval = -1; CLEANUP: CC_IFFREE (tour, int); while (cuts) { cnext = cuts->next; CCtsp_free_lpcut_in (cuts); CC_FREE (cuts, CCtsp_lpcut_in); cuts = cnext; } return rval; }
static int verify_binary_pool (char *poolname) { int rval; int ncount = 0; CCtsp_lpcuts *pool = (CCtsp_lpcuts *) NULL; int i; CCtsp_lpcut_in cut; int nfail = 0; int nsuccess = 0; rval = CCtsp_init_cutpool (&ncount, poolname, &pool); if (rval) { fprintf (stderr, "CCtsp_init_cutpool failed\n"); goto CLEANUP; } for (i=0; i<pool->cutcount; i++) { rval = CCtsp_lpcut_to_lpcut_in (pool, &(pool->cuts[i]), &cut); if (rval) { fprintf (stderr, "CCtsp_lpcut_to_lpcut_in failed\n"); goto CLEANUP; } rval = CCverify_cut (&cut, CC_TYPE_ALL, (int *) NULL); if (rval) { fprintf (stderr, "CCverify_cut failed\n"); nfail++; } else { nsuccess++; } CCtsp_free_lpcut_in (&cut); } printf ("%d of %d cuts failed verification\n", nfail, nfail + nsuccess); if (nfail == 0) rval = 0; else rval = -1; CLEANUP: if (pool) { CCtsp_free_cutpool (&pool); } return rval; }
static int verify_problem (char *probname, int silent) { int i; int rval; int nfail = 0; int nsuccess = 0; CCtsp_lp *lp = (CCtsp_lp *) NULL; CCtsp_lpcuts *cuts; CCtsp_lpcut_in cut; int ncount = 0; lp = CC_SAFE_MALLOC (1, CCtsp_lp); if (lp == (CCtsp_lp *) NULL) { fprintf (stderr, "Out of memory in verify_problem\n"); rval = 1; goto CLEANUP; } CCtsp_init_tsp_lp_struct (lp); rval = CCtsp_read_probfile (lp, probname, (char *) NULL, &ncount, silent); if (rval) { fprintf (stderr, "CCtsp_read_probfile failed\n"); goto CLEANUP; } rval = CCtsp_build_lpadj (&lp->graph, 0, lp->graph.ecount); if (rval) { fprintf (stderr, "CCtsp_build_lpadj failed\n"); goto CLEANUP; } rval = CCtsp_add_branchhistory_to_lp (lp); if (rval) { fprintf (stderr, "CCtsp_add_branchhistory_to_lp failed\n"); goto CLEANUP; } cuts = &lp->cuts; for (i=0; i<cuts->cutcount; i++) { if (cuts->cuts[i].branch == 0) { rval = CCtsp_lpcut_to_lpcut_in (cuts, &(cuts->cuts[i]), &cut); if (rval) { fprintf (stderr, "CCtsp_lpcut_to_lpcut_in failed\n"); goto CLEANUP; } rval = CCverify_cut (&cut, CC_TYPE_ALL, (int *) NULL); if (rval) { fprintf (stderr, "CCverify_cut failed\n"); nfail++; } else { nsuccess++; } CCtsp_free_lpcut_in (&cut); } } printf ("%d cuts failed verification, %d passed\n", nfail, nsuccess); if (nfail == 0) rval = 0; else rval = -1; CLEANUP: CCtsp_free_tsp_lp_struct (&lp); return rval; }
int add_tsp_cuts(CCtsp_lpcut_in **tsp_cuts, int *cutnum, int vertnum, char tsp_prob, cut_data ***cuts, int *num_cuts, int *alloc_cuts) { cut_data cut; int i, j, k, cliquecount, cuts_added = 0; char *coef, *clique_array; char valid = TRUE; int size = (vertnum >> DELETE_POWER) + 1; CCtsp_lpcut_in *tsp_cut, *tsp_cut_next; if (*cutnum <= 0) return(0); cut.type = CLIQUE; cut.name = CUT__SEND_TO_CP; cut.range = 0; cut.branch = ALLOWED_TO_BRANCH_ON; for (tsp_cut = *tsp_cuts; tsp_cut; tsp_cut = tsp_cut->next){ cliquecount = tsp_cut->cliquecount; cut.sense = 'L'; cut.rhs = (cliquecount == 1 ? 0.0 : -((double)cliquecount)/2.0 + 1.0); cut.size = ISIZE + cliquecount * size; cut.coef = coef = (char *) calloc(cut.size, sizeof(char)); memcpy(cut.coef, (char *) (&cliquecount), ISIZE); clique_array = cut.coef + ISIZE; for (i = 0; i < cliquecount; i++, clique_array += size){ valid = TRUE; for(j = 0; j < tsp_cut->cliques[i].segcount; j++){ for(k = tsp_cut->cliques[i].nodes[j].lo; k <= tsp_cut->cliques[i].nodes[j].hi; k++){ cut.rhs++; if (!k && !tsp_prob){ valid = FALSE; break; } clique_array[k >> DELETE_POWER] |= (1 << (k & DELETE_AND)); } /*For each tooth, we want to add |T|-1 to the rhs so we have to subtract off the one here. It subtracts one for the handle too but that is compensated for above*/ if (!valid) break; } cut.rhs--; if (!valid) break; } if (!valid){ FREE(cut.coef); continue; } cg_send_cut(&cut, num_cuts, alloc_cuts, cuts); cuts_added++; FREE(cut.coef); } for (tsp_cut = *tsp_cuts; tsp_cut; tsp_cut = tsp_cut_next){ tsp_cut_next = tsp_cut->next; CCtsp_free_lpcut_in(tsp_cut); FREE(tsp_cut); } *tsp_cuts = NULL; *cutnum = 0; return(cuts_added); }