int main(int ac, char **av) { int val = 0; int i; wctproblem problem; wctproblem_init(&problem); CCcheck_val(val, "Failed in wctproblem_init"); wctparms *parms = &(problem.parms); wctdata *pd = &(problem.root_pd); val = program_header(ac, av); CCcheck_val(val, "Failed in programheader"); CCutil_start_timer(&(problem.tot_cputime)); double start_time = CCutil_zeit(); wctdata_init(pd); pd->id = 0; problem.nwctdata = 1; val = parseargs(ac, av, parms); problem.real_time = getRealTime(); if (val) { goto CLEAN; } get_problem_name(pd->pname, parms->jobfile); if (dbg_lvl() > 1) { printf("Debugging turned on\n"); } fflush(stdout); /** Reading and preprocessing the data */ val = read_problem(parms->jobfile, &(pd->njobs), &(problem.duration), &(problem.weight)); pd->nmachines = parms->nmachines; CCcheck_val(val, "read_adjlist failed"); pd->orig_node_ids = (int *)CC_SAFE_MALLOC(pd->njobs, int); CCcheck_NULL_2(pd->orig_node_ids, "No memory to allocated orig_node_ids\n"); for (i = 0; i < pd->njobs; i++) { pd->orig_node_ids[i] = i; } Preprocessdata(&problem, pd); printf("Reading and preprocessing of the data took %f seconds\n", CCutil_zeit() - start_time); /** Computing initial lowerbound */ CCutil_start_timer(&(problem.tot_lb)); problem.global_lower_bound = lowerbound_eei(pd->jobarray, pd->njobs, pd->nmachines); problem.global_lower_bound = CC_MAX(problem.global_lower_bound, lowerbound_cp(pd->jobarray, pd->njobs, pd->nmachines)); problem.global_lower_bound = CC_MAX(problem.global_lower_bound, lowerbound_cw(pd->jobarray, pd->njobs, pd->nmachines)); CCutil_stop_timer(&(problem.tot_lb), 0); printf("Computing lowerbound EEI, CP and CW took %f seconds\n", problem.tot_lb.cum_zeit); /** Construction Pricersolver at the root node */ CCutil_start_resume_time(&(problem.tot_build_dd)); pd->solver = newSolver(pd->duration, pd->weights, pd->releasetime, pd->duetime, pd->njobs, pd->H_min, pd->H_max); CCutil_suspend_timer(&(problem.tot_build_dd)); /** Construct Feasible solutions */ if (parms->nb_feas_sol > 0) { construct_feasible_solutions(&problem); } /** Compute Schedule with Branch and Price */ compute_schedule(&problem); problem.real_time = getRealTime() - problem.real_time; CCutil_stop_timer(&(problem.tot_cputime), 0); /** Print all the information to screen and csv */ if (problem.parms.print) { print_to_csv(&problem); } print_to_screen(&problem); CLEAN: wctproblem_free(&problem); return val; }
int main (int ac, char **av) { double szeit = CCutil_zeit (); int ncount = 0, rval = 0; int *tour = (int *) NULL; double len = 0.0; FILE *out = (FILE *) NULL; if (parseargs (ac, av)) return 1; { int i, dum, w; FILE *in = fopen (cyclefilename, "r"); if (in == (FILE *) NULL) { perror (cyclefilename); fprintf (stderr, "Unable to open %s for input\n", cyclefilename); rval = 1; goto CLEANUP; } ncount = CCutil_readint (in); i = CCutil_readint (in); printf ("Number of nodes: %d\n", ncount); fflush (stdout); if (i != ncount) { fprintf (stderr, "Not an edge-cycle file\n"); fclose (in); rval = 1; goto CLEANUP; } for (i = 0; i < ncount; i++) { dum = CCutil_readint (in); dum = CCutil_readint (in); w = CCutil_readint (in); len += (double) w; } printf ("Tour Length: %.0f\n", len); fflush (stdout); fclose (in); } tour = CC_SAFE_MALLOC (ncount, int); if (!tour) { fprintf (stderr, "out of memory in main\n"); rval = 1; goto CLEANUP; } rval = CCutil_getcycle_edgelist (ncount, cyclefilename, tour, 0); if (rval) { fprintf (stderr, "CCutil_getcycle_edgelist failed\n"); goto CLEANUP; } if (outfname) { int i; out = fopen (outfname, "w"); if (!out) { perror (cyclefilename); fprintf (stderr, "Unable to open %s for input\n", cyclefilename); rval = 1; goto CLEANUP; } fprintf (out, "%d\n", ncount); for (i = 0; i < ncount; i++) { fprintf (out, "%d\n", tour[i]); } } printf ("Total Running Time: %.2f (seconds)\n", CCutil_zeit () - szeit); fflush (stdout); CLEANUP: CC_IFFREE (tour, int); if (out) fclose (out); return rval; }
int main (int ac, char **av) { int k, ncount; double val, best; double startzeit; int tempcount, *templist; int *incycle = (int *) NULL, *outcycle = (int *) NULL; CCdatagroup dat; int rval = 0; CCrandstate rstate; int allow_dups; int use_gridsize; CCutil_printlabel (); CCutil_init_datagroup (&dat); rval = print_command (ac, av); CCcheck_rval (rval, "print_command failed"); seed = (int) CCutil_real_zeit (); if (parseargs (ac, av)) return 1; CCutil_sprand (seed, &rstate); printf ("Chained Lin-Kernighan with seed %d\n", seed); fflush (stdout); if ((!nnodes_want && !nodefile) || (tsplib_in && !nodefile)) { usage (av[0]); return 1; } startzeit = CCutil_zeit (); if (tsplib_in) { if (CCutil_gettsplib (nodefile, &ncount, &dat)) { fprintf (stderr, "could not read the TSPLIB file\n"); rval = 1; goto CLEANUP; } CCutil_dat_getnorm (&dat, &norm); } else { ncount = nnodes_want; if (gridsize < 0) { use_gridsize = -gridsize; allow_dups = 0; } else if (gridsize > 0) { use_gridsize = gridsize; allow_dups = 1; } else { use_gridsize = nnodes_want; allow_dups = 0; } if (CCutil_getdata (nodefile, binary_in, norm, &ncount, &dat, use_gridsize, allow_dups, &rstate)) { rval = 1; goto CLEANUP; } } if (in_repeater == -1) in_repeater = ncount; incycle = CC_SAFE_MALLOC (ncount, int); if (!incycle) { rval = 1; goto CLEANUP; } if (cycfname) { if (CCutil_getcycle (ncount, cycfname, incycle, binary_edges)) { fprintf (stderr, "CCutil_getcycle failed\n"); rval = 1; goto CLEANUP; } } else if (edgecycfname) { if (CCutil_getcycle_edgelist (ncount, edgecycfname, incycle, binary_edges)) { fprintf (stderr, "CCutil_getcycle_edgelist failed\n"); rval = 1; goto CLEANUP; } } if (goodfname) { int *templen = (int *) NULL; if (CCutil_getedgelist (ncount, goodfname, &tempcount, &templist, &templen, binary_edges)) { rval = 1; goto CLEANUP; } if (templen) CC_FREE (templen, int); printf ("Read good-edge file: %d edges\n", tempcount); fflush (stdout); } else if (edgegenfname) { CCedgegengroup plan; if (CCedgegen_read (edgegenfname, &plan)) { fprintf (stderr, "CCedgegen_read failed\n"); rval = 1; goto CLEANUP; } if (CCedgegen_edges (&plan, ncount, &dat, (double *) NULL, &tempcount, &templist, 0, &rstate)) { fprintf (stderr, "CCedgegen_edges failed\n"); rval = 1; goto CLEANUP; } } if ((norm & CC_NORM_BITS) == CC_KD_NORM_TYPE) { CCkdtree localkt; double kzeit = CCutil_zeit (); if ((!goodfname && !edgegenfname) || (!cycfname && !edgecycfname)) { if (CCkdtree_build (&localkt, ncount, &dat, (double *) NULL, &rstate)) { fprintf (stderr, "CCkdtree_build failed\n"); rval = 1; goto CLEANUP; } printf ("Time to build kdtree: %.2f\n", CCutil_zeit () - kzeit); fflush (stdout); if (!goodfname && !edgegenfname) { kzeit = CCutil_zeit (); if (nearnum) { if (CCkdtree_k_nearest (&localkt, ncount, nearnum, &dat, (double *) NULL, 1, &tempcount, &templist, run_silently, &rstate)) { fprintf (stderr, "CCkdtree_k_nearest failed\n"); rval = 1; goto CLEANUP; } if (!run_silently) { printf ("Time to find %d-nearest: %.2f\n", nearnum, CCutil_zeit () - kzeit); fflush (stdout); } } else { if (CCkdtree_quadrant_k_nearest (&localkt, ncount, quadtry, &dat, (double *) NULL, 1, &tempcount, &templist, run_silently, &rstate)) { fprintf (stderr, "CCkdtree-quad nearest code failed\n"); rval = 1; goto CLEANUP; } if (!run_silently) { printf ("Time to find quad %d-nearest: %.2f\n", quadtry, CCutil_zeit () - kzeit); fflush (stdout); } } } if (!cycfname && !edgecycfname) { kzeit = CCutil_zeit (); if (tour_type == LK_GREEDY) { if (CCkdtree_greedy_tour (&localkt, ncount, &dat, incycle, &val, run_silently, &rstate)) { fprintf (stderr, "CCkdtree greedy-tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_QBORUVKA) { if (CCkdtree_qboruvka_tour (&localkt, ncount, &dat, incycle, &val, &rstate)) { fprintf (stderr, "CCkdtree qboruvka-tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_BORUVKA) { if (CCkdtree_boruvka_tour (&localkt, ncount, &dat, incycle, &val, &rstate)) { fprintf (stderr, "CCkdtree boruvka-tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_RANDOM) { randcycle (ncount, incycle, &rstate); } else { if (CCkdtree_nearest_neighbor_tour (&localkt, ncount, CCutil_lprand (&rstate) % ncount, &dat, incycle, &val, &rstate)) { fprintf (stderr, "CCkdtree NN-tour failed\n"); rval = 1; goto CLEANUP; } } if (!run_silently) { printf ("Time to grow tour: %.2f\n", CCutil_zeit () - kzeit); fflush (stdout); } } CCkdtree_free (&localkt); } } else if ((norm & CC_NORM_BITS) == CC_X_NORM_TYPE) { double xzeit = CCutil_zeit (); if (!goodfname && !edgegenfname) { if (nearnum) { if (CCedgegen_x_k_nearest (ncount, nearnum, &dat, (double *) NULL, 1, &tempcount, &templist, run_silently)) { fprintf (stderr, "CCedgegen_x_k_nearest failed\n"); rval = 1; goto CLEANUP; } if (!run_silently) { printf ("Time to find %d-nearest: %.2f\n", nearnum, CCutil_zeit () - xzeit); fflush (stdout); } } else { if (CCedgegen_x_quadrant_k_nearest (ncount, quadtry, &dat, (double *) NULL, 1, &tempcount, &templist, run_silently)) { fprintf (stderr, "x-quad nearest code failed\n"); rval = 1; goto CLEANUP; } if (!run_silently) { printf ("Time to find quad %d-nearest: %.2f\n", quadtry, CCutil_zeit () - xzeit); fflush (stdout); } } } if (!cycfname && !edgecycfname) { xzeit = CCutil_zeit (); if (tour_type == LK_GREEDY) { if (CCedgegen_x_greedy_tour (ncount, &dat, incycle, &val, tempcount, templist, run_silently)) { fprintf (stderr, "CCedgegen_x_greedy_tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_QBORUVKA) { if (CCedgegen_x_qboruvka_tour (ncount, &dat, incycle, &val, tempcount, templist, run_silently)) { fprintf (stderr, "CCedgegen_x_qboruvka_tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_RANDOM) { randcycle (ncount, incycle, &rstate); } else { if (CCedgegen_x_nearest_neighbor_tour (ncount, CCutil_lprand (&rstate) % ncount, &dat, incycle, &val)) { fprintf (stderr, "CCedgegen_x_nearest_neighbor_tour failed\n"); rval = 1; goto CLEANUP; } } if (!run_silently) { printf ("Time to grow tour: %.2f\n", CCutil_zeit () - xzeit); fflush (stdout); } } } else { double jzeit = CCutil_zeit (); if (!goodfname && !edgegenfname) { if (!nearnum) nearnum = 4 * quadtry; if (CCedgegen_junk_k_nearest (ncount, nearnum, &dat, (double *) NULL, 1, &tempcount, &templist, run_silently)) { fprintf (stderr, "CCedgegen_junk_k_nearest failed\n"); rval = 1; goto CLEANUP; } if (!run_silently) { printf ("Time to find %d nearest: %.2f\n", nearnum, CCutil_zeit () - jzeit); fflush (stdout); } } if (!cycfname && !edgecycfname) { jzeit = CCutil_zeit(); if (tour_type == LK_GREEDY) { if (CCedgegen_junk_greedy_tour (ncount, &dat, incycle, &val, tempcount, templist, run_silently)) { fprintf (stderr, "CCedgegen_junk_greedy_tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_QBORUVKA) { if (CCedgegen_junk_qboruvka_tour (ncount, &dat, incycle, &val, tempcount, templist, run_silently)) { fprintf (stderr, "CCedgegen_junk_qboruvka_tour failed\n"); rval = 1; goto CLEANUP; } } else if (tour_type == LK_RANDOM) { randcycle (ncount, incycle, &rstate); } else { if (CCedgegen_junk_nearest_neighbor_tour (ncount, CCutil_lprand (&rstate) % ncount, &dat, incycle, &val, run_silently)) { fprintf (stderr, "CCedgegen_junk_nearest_neighbor_tour failed\n"); rval = 1; goto CLEANUP; } } if (!run_silently) { printf ("Time to grow tour: %.2f\n", CCutil_zeit () - jzeit); fflush (stdout); } } } outcycle = CC_SAFE_MALLOC (ncount, int); if (!outcycle) { rval = 1; goto CLEANUP; } if (number_runs) { k = 0; best = BIGDOUBLE; do { printf ("\nStarting Run %d\n", k); if (CClinkern_tour (ncount, &dat, tempcount, templist, 100000000, in_repeater, incycle, outcycle, &val, run_silently, time_bound, length_bound, (char *) NULL, kick_type, &rstate)) { fprintf (stderr, "CClinkern_tour failed\n"); rval = 1; goto CLEANUP; } if (val < best) { best = val; if (saveit_final) { if (CCutil_writecycle_edgelist (ncount, saveit_final, outcycle, &dat, binary_edges)) { fprintf (stderr, "could not write the cycle\n"); rval = 1; goto CLEANUP; } } } } while (++k < number_runs); printf ("Overall Best Cycle: %.0f\n", val); fflush (stdout); } else { double lkzeit = CCutil_zeit (); int attempt = 1; do { if (CClinkern_tour (ncount, &dat, tempcount, templist, 10000000, in_repeater, incycle, outcycle, &val, run_silently, time_bound, length_bound, saveit_name, kick_type, &rstate)) { fprintf (stderr, "CClinkern_tour failed\n"); rval = 1; goto CLEANUP; } if (length_bound != -1 && val > length_bound) { printf ("Cycle of value %.0f - did not reach %.0f\n", val, length_bound); printf ("Try again. Number of attempts: %d\n", ++attempt); } } while (length_bound != -1 && val > length_bound); if (saveit_final) { if (CCutil_writecycle_edgelist (ncount, saveit_final, outcycle, &dat, binary_edges)) { fprintf (stderr, "could not write the cycle\n"); rval = 1; goto CLEANUP; } } if (run_silently) printf ("Lin-Kernighan Running Time: %.2f\n", CCutil_zeit () - lkzeit); printf ("Final Cycle: %.0f\n", val); fflush (stdout); } printf ("Total Running Time: %.2f\n", CCutil_zeit () - startzeit); fflush (stdout); CLEANUP: #ifndef BIG_PROBLEM CC_IFFREE (templist, int); #endif CC_IFFREE (incycle, int); CC_IFFREE (outcycle, int); CCutil_freedatagroup (&dat); return rval; }