Implement time limit
This commit is contained in:
@@ -127,6 +127,7 @@ static int BNC_solve_node(struct BNC *bnc, int depth)
|
||||
abort_if(rval, "LP_get_obj_val failed");
|
||||
|
||||
if(depth == 1) ROOT_VALUE = objval;
|
||||
abort_if(get_current_time() - INITIAL_TIME >= MAX_TOTAL_TIME, "time limit exceeded");
|
||||
|
||||
if (ceil(objval) > *best_val + LP_EPSILON)
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ int add_comb_cut(
|
||||
// }
|
||||
|
||||
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
|
||||
log_debug("Generated cut:\n");
|
||||
log_verbose("Generated cut:\n");
|
||||
if (OPTIMAL_X)
|
||||
{
|
||||
for (int i = 0; i < nz; i++)
|
||||
@@ -99,17 +99,17 @@ int add_comb_cut(
|
||||
if (rmatind[i] >= node_count)
|
||||
{
|
||||
struct Edge *e = &graph->edges[rmatind[i] - node_count];
|
||||
log_debug(" %.2lf x%d (%d %d %.4lf)\n", rmatval[i],
|
||||
log_verbose(" %.2lf x%d (%d %d %.4lf)\n", rmatval[i],
|
||||
rmatind[i], e->from->index, e->to->index,
|
||||
OPTIMAL_X[rmatind[i]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_debug(" %.2lf x%d (%.4lf)\n", rmatval[i], rmatind[i],
|
||||
log_verbose(" %.2lf x%d (%.4lf)\n", rmatval[i], rmatind[i],
|
||||
OPTIMAL_X[rmatind[i]]);
|
||||
}
|
||||
}
|
||||
log_debug(" %c %.2lf\n", sense, rhs);
|
||||
log_verbose(" %c %.2lf\n", sense, rhs);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -118,7 +118,7 @@ int add_comb_cut(
|
||||
double sum = 0;
|
||||
for (int i = 0; i < nz; i++)
|
||||
sum += rmatval[i] * OPTIMAL_X[rmatind[i]];
|
||||
log_debug("%.2lf >= %.2lf\n", sum, rhs);
|
||||
log_verbose("%.2lf >= %.2lf\n", sum, rhs);
|
||||
abort_if(sum <= rhs - LP_EPSILON, "cannot add invalid cut");
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ int add_comb_cut(
|
||||
for (int i = 0; i < nz; i++)
|
||||
lhs += rmatval[i] * x[rmatind[i]];
|
||||
|
||||
log_debug("Violation: %.4lf >= %.4lf\n", lhs, rhs);
|
||||
log_verbose("Violation: %.4lf >= %.4lf\n", lhs, rhs);
|
||||
|
||||
if (lhs + LP_EPSILON > rhs)
|
||||
{
|
||||
@@ -426,11 +426,11 @@ int find_comb_cuts(struct LP *lp, struct GTSP *data)
|
||||
&tooth_count);
|
||||
abort_if(rval, "find_teeth failed");
|
||||
|
||||
log_debug("Component %d has %d teeth:\n", i, tooth_count);
|
||||
log_verbose("Component %d has %d teeth:\n", i, tooth_count);
|
||||
for (int j = 0; j < cluster_count; j++)
|
||||
{
|
||||
if (teeth[j] < 0) continue;
|
||||
log_debug(" %d %d\n", j, teeth[j]);
|
||||
log_verbose(" %d %d\n", j, teeth[j]);
|
||||
}
|
||||
|
||||
if (tooth_count % 2 == 0)
|
||||
|
||||
@@ -245,6 +245,7 @@ int GTSP_add_cutting_planes(struct LP *lp, struct GTSP *data)
|
||||
}
|
||||
|
||||
current_round++;
|
||||
abort_if(get_current_time() - INITIAL_TIME >= MAX_TOTAL_TIME, "time limit exceeded");
|
||||
|
||||
int original_cut_pool_size;
|
||||
int added_cuts_count;
|
||||
@@ -510,8 +511,7 @@ int GTSP_solution_found(struct BNC *bnc, struct GTSP *data, double *x)
|
||||
log_info("Writting solution to file %s\n", filename);
|
||||
rval = GTSP_write_solution(data, filename, x);
|
||||
abort_if(rval, "GTSP_write_solution failed");
|
||||
|
||||
|
||||
|
||||
rval = build_tour_from_x(data,tour,x);
|
||||
abort_if(rval, "build_tour_from_x failed");
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ int SUBTOUR_NODE_CLUSTER_COUNT = 0;
|
||||
int SUBTOUR_NODE_NODE_COUNT = 0;
|
||||
int COMBS_COUNT = 0;
|
||||
|
||||
double INITIAL_TIME = 0;
|
||||
|
||||
static const struct option options_tab[] = {
|
||||
{"help", no_argument, 0, 'h'}, {"tsp", no_argument, 0, 't'},
|
||||
|
||||
@@ -22,6 +22,7 @@ extern long CUT_POOL_MAX_MEMORY;
|
||||
extern int FLOW_MAX_FLOW_COUNT;
|
||||
|
||||
extern double TOTAL_TIME;
|
||||
extern double INITIAL_TIME;
|
||||
extern double ROOT_VALUE;
|
||||
|
||||
extern int SUBTOUR_CLUSTER_CLUSTER_COUNT;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#define ENABLE_COMB_INEQUALITIES
|
||||
|
||||
#define MAX_TOTAL_TIME 3600
|
||||
|
||||
//#define ALLOW_FRACTIONAL_SOLUTIONS
|
||||
|
||||
#endif //PROJECT_PARAMS_H
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include "util.h"
|
||||
#include "main.h"
|
||||
|
||||
double get_current_time()
|
||||
{
|
||||
@@ -19,8 +20,6 @@ double get_real_time()
|
||||
return (double) time (0);
|
||||
}
|
||||
|
||||
static double INITIAL_TIME = 0;
|
||||
|
||||
void time_printf(const char *fmt, ...)
|
||||
{
|
||||
if (INITIAL_TIME == 0)
|
||||
|
||||
Reference in New Issue
Block a user