void DDSIP_PrintStateUB (int heur) { double wall_secs, cpu_secs; int wall_hrs, wall_mins, cpu_hrs, cpu_mins; printf ("*%6d %6d ", DDSIP_bb->curnode, DDSIP_bb->nonode); fprintf (DDSIP_outfile, "*%6d %6d ", DDSIP_bb->curnode, DDSIP_bb->nonode); if (DDSIP_bb->DDSIP_step == eev) { printf (" exp. value sol "); fprintf (DDSIP_outfile, " exp. value sol "); } else if (DDSIP_bb->DDSIP_step == adv) { fprintf (DDSIP_outfile, " start point "); } else { printf (" Heuristic %2d ", heur); fprintf (DDSIP_outfile, " Heuristic %2d ", heur); } // DDSIP_bb->heurval contains the objective value of the heuristic solution // DDSIP_bb->skip indicates whether the evaluation of an heuristic solution was skip for some reason printf (" %-16.12g", DDSIP_bb->heurval); fprintf (DDSIP_outfile, " %-16.12g", DDSIP_bb->heurval); if (fabs (DDSIP_bb->bestvalue) < DDSIP_infty) { printf (" %-16.12g", DDSIP_bb->bestvalue); fprintf (DDSIP_outfile, " %-16.12g", DDSIP_bb->bestvalue); } else { printf (" "); fprintf (DDSIP_outfile, " "); } printf (" "); fprintf (DDSIP_outfile," "); DDSIP_translate_time (DDSIP_GetCpuTime(),&cpu_hrs,&cpu_mins,&cpu_secs); time (&DDSIP_bb->cur_time); DDSIP_translate_time (difftime(DDSIP_bb->cur_time,DDSIP_bb->start_time),&wall_hrs,&wall_mins,&wall_secs); printf (" %3dh %02d:%02.0f %3dh %02d:%02.0f\n", wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs); fprintf (DDSIP_outfile," %3dh %02d:%02.0f %3dh %02d:%02.0f\n", wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs); }
void DDSIP_PrintState (int noiter) { // char state[DDSIP_max_str_ln]; double wall_secs, cpu_secs; int wall_hrs, wall_mins, cpu_hrs, cpu_mins, print_violations = 1; double rgap, factor; //best<>0 ? if (!DDSIP_Equal (fabs (DDSIP_bb->bestvalue), 0.0)) rgap = 100. * (DDSIP_bb->bestvalue - DDSIP_bb->bestbound) / fabs (DDSIP_bb->bestvalue); else rgap = 100. * (DDSIP_bb->bestvalue - DDSIP_bb->bestbound) / (fabs (DDSIP_bb->bestvalue) + DDSIP_param->accuracy); rgap = DDSIP_Dmin (rgap, 100.0); factor = (DDSIP_bb->bestvalue < 0.)? 1.-1.e-12 : 1.+1.e-12; // A headline is printed every 20th call if (!((noiter) % (DDSIP_param->logfreq * 20)) || (DDSIP_param->cb && !(noiter % DDSIP_Imax(DDSIP_param->cb,10)) && DDSIP_param->outlev > 1)) { printf ("\n Node Nodes Left Objective Heuristic"); fprintf (DDSIP_outfile, "\n Node Nodes Left Objective Heuristic"); printf (" Best Value Bound Viol./Dispersion Gap Wall Time CPU Time Father Depth\n"); fprintf (DDSIP_outfile, " Best Value Bound Viol./Dispersion Gap Wall Time CPU Time Father Depth\n"); } if (!DDSIP_bb->violations && fabs(DDSIP_bb->bestvalue - DDSIP_node[DDSIP_bb->curnode]->bound)/(fabs(DDSIP_bb->bestvalue) + 3.e-16) < 5.e-16) { printf ("*%6d %6d %6d", DDSIP_bb->curnode, DDSIP_bb->nonode, DDSIP_bb->nofront); fprintf (DDSIP_outfile, "*%6d %6d %6d", DDSIP_bb->curnode, DDSIP_bb->nonode, DDSIP_bb->nofront); } else { printf (" %6d %6d %6d", DDSIP_bb->curnode, DDSIP_bb->nonode, DDSIP_bb->nofront); fprintf (DDSIP_outfile, " %6d %6d %6d", DDSIP_bb->curnode, DDSIP_bb->nonode, DDSIP_bb->nofront); } //bound=inf if (DDSIP_node[DDSIP_bb->curnode]->bound >= DDSIP_infty) { printf (" infeasible "); fprintf (DDSIP_outfile, " infeasible "); print_violations = 0; } else if (DDSIP_node[DDSIP_bb->curnode]->bound > DDSIP_bb->bestvalue*factor) { printf (" cutoff "); fprintf (DDSIP_outfile, " cutoff "); print_violations = 0; } else if (DDSIP_node[DDSIP_bb->curnode]->bound < DDSIP_infty) { printf (" %-16.12g", DDSIP_node[DDSIP_bb->curnode]->bound); fprintf (DDSIP_outfile, " %-16.12g", DDSIP_node[DDSIP_bb->curnode]->bound); } //bound=-inf else { printf (" unbounded "); fprintf (DDSIP_outfile, " unbounded "); } // DDSIP_bb->heurval contains the objective value of the heuristic solution // DDSIP_bb->skip indicates whether the evaluation of an heuristic solution was skipped for some reason if (fabs (DDSIP_bb->heurval) < DDSIP_infty) { printf (" %-16.12g", DDSIP_bb->heurval); fprintf (DDSIP_outfile, " %-16.12g", DDSIP_bb->heurval); } else { if (DDSIP_bb->skip >= 100) { // Print the number of the scenario which caused the stop printf (" %4d-stop", DDSIP_bb->skip - 100 + 1); fprintf (DDSIP_outfile, " %4d-stop", DDSIP_bb->skip - 100 + 1); } else if (DDSIP_bb->skip == 2 || DDSIP_bb->skip == 1 || DDSIP_bb->skip == 3) { printf (" "); fprintf (DDSIP_outfile, " "); } else if (DDSIP_bb->skip == 4) { printf (" multiple "); fprintf (DDSIP_outfile, " multiple "); } else { printf (" infeasible "); fprintf (DDSIP_outfile, " infeasible "); } } if (fabs (DDSIP_bb->bestvalue) < DDSIP_infty) { printf (" %-16.12g", DDSIP_bb->bestvalue); fprintf (DDSIP_outfile, " %-16.12g", DDSIP_bb->bestvalue); } else { printf (" "); fprintf (DDSIP_outfile, " "); } if (fabs (DDSIP_bb->bestbound - DDSIP_infty) < DDSIP_param->accuracy) { printf (" infeasible"); fprintf (DDSIP_outfile, " infeasible"); } else { printf (" %-16.12g", DDSIP_bb->bestbound); fprintf (DDSIP_outfile, " %-16.12g", DDSIP_bb->bestbound); } if (!print_violations || fabs (DDSIP_bb->bestbound - DDSIP_infty) < DDSIP_param->accuracy || fabs(DDSIP_node[DDSIP_bb->curnode]->dispnorm) >= DDSIP_infty) { printf (" "); fprintf (DDSIP_outfile, " "); } else { //number of violations of nonanticipativity printf (" %4d",DDSIP_bb->violations); fprintf (DDSIP_outfile, " %4d",DDSIP_bb->violations); //max dispersion of the variables printf (" %-10.5g",DDSIP_node[DDSIP_bb->curnode]->dispnorm); fprintf (DDSIP_outfile, " %-10.5g",DDSIP_node[DDSIP_bb->curnode]->dispnorm); } if (DDSIP_bb->bestvalue < DDSIP_infty && fabs (DDSIP_bb->bestbound) < DDSIP_infty) { printf (" %9.4g%%", rgap); fprintf (DDSIP_outfile, " %9.4g%%", rgap); } else { printf (" "); fprintf (DDSIP_outfile, " "); } DDSIP_translate_time (DDSIP_GetCpuTime(),&cpu_hrs,&cpu_mins,&cpu_secs); time (&DDSIP_bb->cur_time); DDSIP_translate_time (difftime(DDSIP_bb->cur_time,DDSIP_bb->start_time),&wall_hrs,&wall_mins,&wall_secs); printf (" %3dh %02d:%02.0f %3dh %02d:%02.0f %8d %5d\n", wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs,DDSIP_node[DDSIP_bb->curnode]->father,DDSIP_node[DDSIP_bb->curnode]->depth); fprintf (DDSIP_outfile," %3dh %02d:%02.0f %3dh %02d:%02.0f %8d %5d\n" ,wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs,DDSIP_node[DDSIP_bb->curnode]->father,DDSIP_node[DDSIP_bb->curnode]->depth); }
//========================================================================== // This function solves the expected value problem int DDSIP_ExpValProb (void) { int status, j, mipstatus, nodes_1st = -1; int wall_hrs, wall_mins,cpu_hrs, cpu_mins; double objval, bobjval, time_start, time_end, wall_secs, cpu_secs, gap; char fname[DDSIP_ln_fname]; double *mipx = (double *) DDSIP_Alloc (sizeof (double), (DDSIP_bb->firstvar + DDSIP_bb->secvar), "mipx(ExpValProb)"); printf ("Solving expected value problem\n"); if (DDSIP_param->outlev) fprintf (DDSIP_bb->moreoutfile, "Solving expected value problem...\n"); status = DDSIP_ChgProb (-1, 0); if (status) { fprintf (stderr, "ERROR: Failed to change problem \n"); goto TERMINATE; } if (DDSIP_param->files > 1) { sprintf (fname, "%s/ev%s", DDSIP_outdir, DDSIP_param->coretype); status = CPXwriteprob (DDSIP_env, DDSIP_lp, fname, NULL); if (status) { fprintf (stderr, "ERROR: Failed to write problem\n"); goto TERMINATE; } } // New cplex parameters if (DDSIP_param->cpxnoeev) { status = DDSIP_SetCpxPara (DDSIP_param->cpxnoeev, DDSIP_param->cpxeevisdbl, DDSIP_param->cpxeevwhich, DDSIP_param->cpxeevwhat); if (status) { fprintf (stderr, "ERROR: Failed to set CPLEX parameters (ExpValProb) \n"); goto TERMINATE; } } time_start = DDSIP_GetCpuTime (); mipstatus = CPXmipopt (DDSIP_env, DDSIP_lp); // Reset cplex parameters if (DDSIP_param->cpxnoeev) { status = DDSIP_SetCpxPara (DDSIP_param->cpxno, DDSIP_param->cpxisdbl, DDSIP_param->cpxwhich, DDSIP_param->cpxwhat); if (status) { fprintf (stderr, "ERROR: Failed to reset CPLEX parameters (ExpValProb) \n"); goto TERMINATE; } } if (DDSIP_Error (mipstatus)) { fprintf (stderr, "ERROR: Failed to optimize EXP\n"); status = mipstatus; goto TERMINATE; } // Error ? (blatant infeasible, scenario problem limit) if (DDSIP_Infeasible (mipstatus)) { status = 1; goto TERMINATE; } // No solution found ? (integer infeasible, some limit (node, time)) mipstatus = CPXgetstat (DDSIP_env, DDSIP_lp); if (DDSIP_NoSolution (mipstatus)) { status = 1; goto TERMINATE; } status = CPXgetx (DDSIP_env, DDSIP_lp, mipx, 0, DDSIP_bb->firstvar + DDSIP_bb->secvar - 1); if (status) { fprintf (stderr, "ERROR: Failed to get solution \n"); goto TERMINATE; } // output of result if (DDSIP_param->outlev) { status = CPXgetobjval (DDSIP_env, DDSIP_lp, &objval); if (status) { fprintf (stderr, "ERROR*: Failed to get best objective value \n"); fprintf (DDSIP_outfile, "ERROR*: Failed to get best objective value \n"); if (DDSIP_param->outlev) fprintf (DDSIP_bb->moreoutfile, "ERROR*: Failed to get best objective value \n"); goto TERMINATE; } if (mipstatus == CPXMIP_OPTIMAL) { bobjval = objval; } else { status = CPXgetbestobjval (DDSIP_env, DDSIP_lp, &bobjval); if (status) { fprintf (stderr, "ERROR: Failed to get value of best remaining node\n"); fprintf (DDSIP_outfile, "ERROR: Failed to get value of best remaining node\n"); if (DDSIP_param->outlev) fprintf (DDSIP_bb->moreoutfile, "ERROR: Failed to get value of best remaining node\n"); goto TERMINATE; } } gap = 100.0*(objval-bobjval)/(fabs(objval)+1e-4); nodes_1st = CPXgetnodecnt (DDSIP_env,DDSIP_lp); time_end = DDSIP_GetCpuTime (); time_start = time_end-time_start; time (&DDSIP_bb->cur_time); DDSIP_translate_time (difftime(DDSIP_bb->cur_time,DDSIP_bb->start_time),&wall_hrs,&wall_mins,&wall_secs); DDSIP_translate_time (time_end,&cpu_hrs,&cpu_mins,&cpu_secs); if (mipstatus == CPXMIP_OPTIMAL) fprintf (DDSIP_bb->moreoutfile, " exp. val. prob: Best=%-20.14g\tBound=%-20.14g (%9.4g%%) \t %3dh %02d:%02.0f / %3dh %02d:%05.2f (%6.2fs n: %4d)", objval, bobjval, gap, wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs, time_start, nodes_1st); else if (mipstatus == CPXMIP_OPTIMAL_TOL) fprintf (DDSIP_bb->moreoutfile, " exp. val. prob: Best=%-20.14g\tBound=%-20.14g (%9.4g%%) tol.\t %3dh %02d:%02.0f / %3dh %02d:%05.2f (%6.2fs n: %4d)", objval, bobjval, gap, wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs, time_start, nodes_1st); else if (mipstatus == CPXMIP_TIME_LIM_FEAS) fprintf (DDSIP_bb->moreoutfile, " exp. val. prob: Best=%-20.14g\tBound=%-20.14g (%9.4g%%) TIME\t %3dh %02d:%02.0f / %3dh %02d:%05.2f (%6.2fs n: %4d)", objval, bobjval, gap, wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs, time_start, nodes_1st); else fprintf (DDSIP_bb->moreoutfile, " exp. val. prob: Best=%-20.14g\tBound=%-20.14g (%9.4g%%) %-4d\t %3dh %02d:%02.0f / %3dh %02d:%05.2f (%6.2fs n: %4d)", objval, bobjval, gap, mipstatus, wall_hrs,wall_mins,wall_secs,cpu_hrs,cpu_mins,cpu_secs, time_start, nodes_1st); } // Returns sometimes rubbish, don't know why.. if (!DDSIP_bb->adv_sol) DDSIP_bb->adv_sol = (double *) DDSIP_Alloc (sizeof (double), DDSIP_bb->firstvar, "DDSIP_bb->adv_sol(sipread)"); for (j = 0; j < DDSIP_bb->firstvar; j++) { // Numerical errors ? if (DDSIP_Equal (mipx[DDSIP_bb->firstindex[j]], 0.0)) mipx[DDSIP_bb->firstindex[j]] = 0.0; DDSIP_bb->adv_sol[j] = mipx[DDSIP_bb->firstindex[j]]; } TERMINATE: DDSIP_Free ((void **) &(mipx)); return status; }