Add tests for INFINITY_generate_cut
This commit is contained in:
@@ -86,3 +86,41 @@ CLEANUP:
|
|||||||
LFREE_free_ray_list(&rays);
|
LFREE_free_ray_list(&rays);
|
||||||
if (rval) FAIL();
|
if (rval) FAIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(InfinityTest, generate_cut_test)
|
||||||
|
{
|
||||||
|
int rval = 0;
|
||||||
|
|
||||||
|
double pi0[] = { -0.0553783449, -0.0553783449, -0.1666666667, -0.0553783449, -0.0553783449, -0.0498405104, -0.0553783449, -0.0553783449, -0.0498405104, -0.0498405104, -0.1500000000, -0.0498405104, -0.0272904483, -0.0272904483, -0.0498405104, -0.0498405104, -0.0498405104, -0.0498405104, -0.0272904483, -0.0443026759, -0.0443026759, -0.1333333333, -0.0443026759, -0.0433723197, -0.0438596491, -0.0443026759, -0.0443026759, -0.0443026759, -0.0443026759, -0.0438596491, -0.0332270069, -0.0332270069, -0.1000000000, -0.0332270069, -0.0160818713, -0.0155945419, -0.0332270069, -0.0332270069, -0.0332270069, -0.0332270069, -0.0155945419, -0.0354421407, -0.0354421407, -0.1066666667, -0.0354421407, -0.0433723197, -0.0438596491, -0.0354421407, -0.0354421407, -0.0354421407, -0.0354421407, -0.0438596491, -0.0553783449, -0.0553783449, -0.1666666667, -0.0575934786, -0.0433723197, -0.0506822612, -0.0553783449, -0.0498405104, -0.0553783449, -0.0575934786, -0.0506822612, -0.0433723197, -0.0438596491, -0.0438596491, -0.0498405104, -0.0498405104, -0.1500000000, -0.0487329435, -0.0498405104, -0.0498405104, -0.0498405104, -0.0487329435, 0.7784866206, 0.9113946482, 0.7231082757, 0.9405458090, 0.8958887117, 0.9257930179, -0.5015948963, 0.7441520468, 0.9259259259, 0.0291068581, 0.0291068581, -0.0489668616, -0.1246429204, -0.0667729931, -0.0667729931, -0.0220857700, -0.0934821903, -0.1246429204, -0.0623214602, 0.0291068581, 0.0288853447, 0.0088605352, 0.0147084884, 0.0112085770, 0.0133794081, 0.0288853447, 0.0066454014, 0.0288853447, 0.0088605352, 0.0147084884, 0.0133794081, 0.0288853447, 0.0066454014, 0.0291068581, 0.0121832359, 0.0291068581, 0.0121832359, 0.0291068581, 0.0291068581, 0.0288853447, 0.0088605352, 0.0147084884, 0.0133794081, 0.0288853447, 0.0066454014, 0.0243664717, 0.0620237462, 0.0332270069, 0.0332270069, 0.0545808967, 0.0465178097, 0.0620237462, 0.0011075669, 0.0011075669, 0.0033333333, 0.0011075669, 0.0004873294, 0.0009746589, 0.0011075669, 0.0011075669, 0.0011075669, 0.0011075669, 0.0009746589, 1.0000000000, };
|
||||||
|
double pi1[] = { 0.5000000000, 0.8035714286, 0.2857142857, 0.8035714286, 0.9285714286, 0.8035714286, 1.3571428571, 0.4464285714, 0.6071428571, 0.4464285714, 0.3392857143, 1.0000000000, 0.6071428571, 0.6071428571, 0.4464285714, -0.0178571429, };
|
||||||
|
int indices0[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 80, 81, 82, 83, 84, 89, 97, 101, 102, 103, 104, 105, 106, 107, 108, 113, 118, 119, 120, 121, 122, 123, 124, 126, 127, 128, 130, 131, 132, 137, 142, 145, 147, 153, 161, 166, 167, 168, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 199, };
|
||||||
|
int indices1[] = { 18, 29, 40, 51, 62, 65, 84, 165, 166, 167, 168, 169, 170, 171, 172, 190, };
|
||||||
|
struct Row row0 = {.nz = 138, .head = 199, .pi_zero = 0.1711855396, .pi = pi0, .indices = indices0 };
|
||||||
|
struct Row row1 = {.nz = 16, .head = 169, .pi_zero = 1.3571428571, .pi = pi1, .indices = indices1 };
|
||||||
|
struct Row* rows[] = {&row0, &row1 };
|
||||||
|
char column_types[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, };
|
||||||
|
struct Tableau tableau = {.ncols = 201, .nrows = 2, .rows = rows, .column_types = column_types};
|
||||||
|
|
||||||
|
double pi2[] = { -0.0861798566, -0.0861798566, -0.2593668965, -0.0861798566, -0.0861798566, -0.0775618709, -0.0861798566, -0.0861798566, -0.0775618709, -0.0775618709, -0.2334302068, -0.0775618709, -0.0424694333, -0.0424694333, -0.0775618709, -0.0775618709, -0.0775618709, -0.0775618709, -1.8155682752, -0.0689438853, -0.0689438853, -0.2074935172, -0.0689438853, -0.0674960637, -0.0682544464, -0.0689438853, -0.0689438853, -0.0689438853, -0.0689438853, -2.9178775851, -0.0517079140, -0.0517079140, -0.1556201379, -0.0517079140, -0.0250266304, -0.0242682476, -0.0517079140, -0.0517079140, -0.0517079140, -0.0517079140, -1.0374675858, -0.0551551082, -0.0551551082, -0.1659948137, -0.0551551082, -0.0674960637, -0.0682544464, -0.0551551082, -0.0551551082, -0.0551551082, -0.0551551082, -2.9178775851, -0.0861798566, -0.0861798566, -0.2593668965, -0.0896270509, -0.0674960637, -0.0788718048, -0.0861798566, -0.0775618709, -0.0861798566, -0.0896270509, -3.3717696539, -0.0674960637, -0.0682544464, -2.9178775851, -0.0775618709, -0.0775618709, -0.2334302068, -0.0758382738, -0.0775618709, -0.0775618709, -0.0775618709, -0.0758382738, -0.0946687273, -0.1108311551, -0.0879343823, -0.1143761143, -0.1089455385, -0.1125820848, -0.7805826692, -0.0904934334, -3.3717696539, -0.0035395717, -0.0035395717, -0.0762022975, -0.1939694846, -0.1039122239, -0.1039122239, -0.0343699057, -0.1454771135, -0.1939694846, -0.0969847423, -0.0035395717, -0.0035126343, -0.0010774952, -0.0017886420, -0.0013630314, -0.0016270177, -0.0035126343, -0.0008081214, -0.0035126343, -0.0010774952, -0.0017886420, -0.0016270177, -0.0035126343, -0.0008081214, -0.0035395717, -0.0014815559, -0.0035395717, -0.0014815559, -0.0035395717, -0.0035395717, -1.5831239659, -2.1080971805, -1.5693351889, -1.1802848442, -2.1322275403, -2.1080971805, -1.5727823832, -0.0029631118, -0.0075424663, -0.0040406070, -0.0040406070, -0.0066373704, -0.0056568497, -0.0075424663, -0.0001346869, -0.0001346869, -0.0004053537, -0.0001346869, -0.0001000000, -0.0001185245, -0.0001346869, -0.0001346869, -0.0001346869, -0.0001346869, -0.0273208243, };
|
||||||
|
int indices2[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 80, 81, 82, 83, 84, 89, 97, 101, 102, 103, 104, 105, 106, 107, 108, 113, 118, 119, 120, 121, 122, 123, 124, 126, 127, 128, 130, 131, 132, 137, 142, 145, 147, 153, 161, 165, 166, 167, 168, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, };
|
||||||
|
struct Row row2 = {.nz = 138, .head = 0, .pi_zero = -1.0000000000, .pi = pi2, .indices = indices2 };
|
||||||
|
|
||||||
|
struct Row cut;
|
||||||
|
LP_init_row(&cut, 138);
|
||||||
|
|
||||||
|
rval = INFINITY_generate_cut(&tableau, &cut);
|
||||||
|
abort_if(rval, "INFINITY_generate_cut failed");
|
||||||
|
|
||||||
|
EXPECT_EQ(cut.nz, row2.nz);
|
||||||
|
EXPECT_EQ(cut.head, row2.head);
|
||||||
|
EXPECT_EQ(cut.pi_zero, row2.pi_zero);
|
||||||
|
|
||||||
|
for(int i = 0; i < cut.nz; i++)
|
||||||
|
{
|
||||||
|
EXPECT_NEAR(cut.pi[i], pi2[i], 1e-6);
|
||||||
|
EXPECT_EQ(cut.indices[i], indices2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
CLEANUP:
|
||||||
|
if(rval) FAIL();
|
||||||
|
}
|
||||||
@@ -41,6 +41,7 @@ struct CG
|
|||||||
|
|
||||||
struct Tableau
|
struct Tableau
|
||||||
{
|
{
|
||||||
|
int ncols;
|
||||||
int nrows;
|
int nrows;
|
||||||
struct Row **rows;
|
struct Row **rows;
|
||||||
char *column_types;
|
char *column_types;
|
||||||
|
|||||||
@@ -154,4 +154,6 @@ int LP_write_sage_file(struct LP *lp,
|
|||||||
|
|
||||||
int LP_change_rhs(struct LP *lp, int index, double value);
|
int LP_change_rhs(struct LP *lp, int index, double value);
|
||||||
|
|
||||||
|
int LP_init_row(struct Row *row, int nz_capacity);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -364,6 +364,48 @@ CLEANUP:
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dump_row(FILE *file, const struct Row *row, int k)
|
||||||
|
{
|
||||||
|
fprintf(file, "double pi%d[] = { ", k);
|
||||||
|
for(int i = 0; i < row->nz; i++)
|
||||||
|
fprintf(file, "%.10lf, ", row->pi[i]);
|
||||||
|
fprintf(file, "};\n");
|
||||||
|
|
||||||
|
fprintf(file, "int indices%d[] = { ", k);
|
||||||
|
for(int i = 0; i < row->nz; i++)
|
||||||
|
fprintf(file, "%d, ", row->indices[i]);
|
||||||
|
fprintf(file, "};\n");
|
||||||
|
|
||||||
|
fprintf(file, "struct Row row%d = {", k);
|
||||||
|
fprintf(file, ".nz = %d, ", row->nz);
|
||||||
|
fprintf(file, ".head = %d, ", row->head);
|
||||||
|
fprintf(file, ".pi_zero = %.10lf, ", row->pi_zero);
|
||||||
|
fprintf(file, ".pi = pi%d, ", k);
|
||||||
|
fprintf(file, ".indices = indices%d };\n", k);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dump_tableau(FILE *file, const struct Tableau *tableau)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < tableau->nrows; i++)
|
||||||
|
dump_row(file, tableau->rows[i], i);
|
||||||
|
|
||||||
|
fprintf(file, "struct Row* rows[] = {");
|
||||||
|
for(int i = 0; i < tableau->nrows; i++)
|
||||||
|
fprintf(file, "&row%d, ", i);
|
||||||
|
fprintf(file, "};\n");
|
||||||
|
|
||||||
|
fprintf(file, "char column_types[] = {");
|
||||||
|
for(int i = 0; i < tableau->ncols; i++)
|
||||||
|
fprintf(file, "%d, ", tableau->column_types[i]);
|
||||||
|
fprintf(file, "};\n");
|
||||||
|
|
||||||
|
fprintf(file, "struct Tableau tableau = {");
|
||||||
|
fprintf(file, ".ncols = %d, ", tableau->ncols);
|
||||||
|
fprintf(file, ".nrows = %d, ", tableau->nrows);
|
||||||
|
fprintf(file, ".rows = rows, ");
|
||||||
|
fprintf(file, ".column_types = column_types };\n");
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef TEST_SOURCE
|
#ifndef TEST_SOURCE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -455,7 +497,6 @@ int CG_extract_rays_from_tableau(const struct Tableau *tableau,
|
|||||||
double scale;
|
double scale;
|
||||||
int ray_index;
|
int ray_index;
|
||||||
|
|
||||||
|
|
||||||
log_verbose(" extracted ray (%d):\n", idx_min);
|
log_verbose(" extracted ray (%d):\n", idx_min);
|
||||||
for (int j = 0; j < nrows; j++)
|
for (int j = 0; j < nrows; j++)
|
||||||
log_verbose(" r[%d] = %.12lf\n", j, r[j]);
|
log_verbose(" r[%d] = %.12lf\n", j, r[j]);
|
||||||
@@ -856,14 +897,28 @@ int CG_add_multirow_cuts(struct CG *cg,
|
|||||||
progress_increment();
|
progress_increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Tableau tableau = {nrows, rows, cg->column_types};
|
struct Tableau tableau =
|
||||||
struct Row cut;
|
{
|
||||||
|
.ncols = cg->ncols,
|
||||||
|
.nrows = nrows,
|
||||||
|
.rows = rows,
|
||||||
|
.column_types = cg->column_types
|
||||||
|
};
|
||||||
|
|
||||||
|
if_debug_level
|
||||||
|
{
|
||||||
|
char filename[100];
|
||||||
|
sprintf(filename, "tableau-%03ld.c", count);
|
||||||
|
FILE *file = fopen(filename, "w");
|
||||||
|
dump_tableau(file, &tableau);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
int max_nz = CG_total_nz(&tableau);
|
int max_nz = CG_total_nz(&tableau);
|
||||||
cut.pi = (double *) malloc(max_nz * sizeof(double));
|
|
||||||
cut.indices = (int *) malloc(max_nz * sizeof(int));
|
struct Row cut;
|
||||||
abort_if(!cut.pi, "could not allocate cut.pi");
|
rval = LP_init_row(&cut, max_nz);
|
||||||
abort_if(!cut.indices, "could not allocate cut.indices");
|
abort_if(rval, "LP_init_row failed");
|
||||||
|
|
||||||
double initial_time = get_user_time();
|
double initial_time = get_user_time();
|
||||||
|
|
||||||
@@ -877,6 +932,15 @@ int CG_add_multirow_cuts(struct CG *cg,
|
|||||||
}
|
}
|
||||||
else abort_iff(rval, "generate failed (cut %d)", count);
|
else abort_iff(rval, "generate failed (cut %d)", count);
|
||||||
|
|
||||||
|
if_debug_level
|
||||||
|
{
|
||||||
|
char filename[100];
|
||||||
|
sprintf(filename, "cut-%03ld.c", count);
|
||||||
|
FILE *file = fopen(filename, "w");
|
||||||
|
dump_row(file, &cut, 0);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
double elapsed_time = get_user_time() - initial_time;
|
double elapsed_time = get_user_time() - initial_time;
|
||||||
log_debug(" generate: %.2lf ms\n", elapsed_time * 1000);
|
log_debug(" generate: %.2lf ms\n", elapsed_time * 1000);
|
||||||
|
|
||||||
|
|||||||
@@ -720,3 +720,20 @@ int LP_change_rhs(struct LP *lp, int index, double value)
|
|||||||
CLEANUP:
|
CLEANUP:
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LP_init_row(struct Row *row, int nz_capacity)
|
||||||
|
{
|
||||||
|
int rval = 0;
|
||||||
|
|
||||||
|
row->nz = 0;
|
||||||
|
row->head = 0;
|
||||||
|
row->pi_zero = 0;
|
||||||
|
|
||||||
|
row->pi = (double *) malloc(nz_capacity * sizeof(double));
|
||||||
|
row->indices = (int *) malloc(nz_capacity * sizeof(int));
|
||||||
|
abort_if(!row->pi, "could not allocate row->pi");
|
||||||
|
abort_if(!row->indices, "could not allocate row->indices");
|
||||||
|
|
||||||
|
CLEANUP:
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
@@ -145,7 +145,13 @@ TEST(CGTest, extract_rays_from_rows_test)
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Row *rows[] = { &row1, &row2, &row3 };
|
struct Row *rows[] = { &row1, &row2, &row3 };
|
||||||
struct Tableau tableau = {3, rows, column_types};
|
struct Tableau tableau =
|
||||||
|
{
|
||||||
|
.ncols = 16,
|
||||||
|
.nrows = 3,
|
||||||
|
.rows = rows,
|
||||||
|
.column_types = column_types
|
||||||
|
};
|
||||||
|
|
||||||
int indices[1000];
|
int indices[1000];
|
||||||
int variable_to_ray[1000];
|
int variable_to_ray[1000];
|
||||||
|
|||||||
Reference in New Issue
Block a user