Compare commits
2 Commits
77a5d93527
...
feature/fe
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b7432b944 | |||
| 78decb06c7 |
@@ -365,6 +365,10 @@ static int create_tight_rays_lp(int nrows,
|
|||||||
rval = LP_relax(lp);
|
rval = LP_relax(lp);
|
||||||
abort_if(rval, "LP_relax failed");
|
abort_if(rval, "LP_relax failed");
|
||||||
|
|
||||||
|
//rval = LP_write(lp, "tight-rays.lp");
|
||||||
|
//abort_if(rval, "LP_write failed");
|
||||||
|
|
||||||
|
|
||||||
CLEANUP:
|
CLEANUP:
|
||||||
if(rmatind) free(rmatind);
|
if(rmatind) free(rmatind);
|
||||||
if(rmatval) free(rmatval);
|
if(rmatval) free(rmatval);
|
||||||
@@ -598,7 +602,7 @@ static int find_interior_point_enum(const int nrows,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(best_value < 0.999) *found = 1;
|
if(!DOUBLE_geq(best_value, 1)) *found = 1;
|
||||||
|
|
||||||
CLEANUP:
|
CLEANUP:
|
||||||
if(beta2) free(beta2);
|
if(beta2) free(beta2);
|
||||||
@@ -661,7 +665,7 @@ static int find_interior_point_cplex(const int nrows,
|
|||||||
|
|
||||||
log_debug(" obj = %.8lf\n", objval);
|
log_debug(" obj = %.8lf\n", objval);
|
||||||
|
|
||||||
if(objval > 0.999)
|
if(DOUBLE_geq(objval, 1.0))
|
||||||
{
|
{
|
||||||
log_debug(" set is lattice-free\n");
|
log_debug(" set is lattice-free\n");
|
||||||
*found = 0;
|
*found = 0;
|
||||||
@@ -1316,7 +1320,9 @@ int INFINITY_ND_generate_lfree(const struct MultiRowModel *model,
|
|||||||
&epsilon_x, tx);
|
&epsilon_x, tx);
|
||||||
abort_if(rval, "bound failed");
|
abort_if(rval, "bound failed");
|
||||||
|
|
||||||
abort_if(isinf(epsilon_x), "epsilon_x is infinite");
|
if(isinf(epsilon_x)) break;
|
||||||
|
|
||||||
|
// epsilon_x = (floor(epsilon_x * 128) / 128);
|
||||||
log_debug(" epsilon_x = %.8lf\n", epsilon_x);
|
log_debug(" epsilon_x = %.8lf\n", epsilon_x);
|
||||||
|
|
||||||
if(DOUBLE_eq(epsilon_x, epsilon))
|
if(DOUBLE_eq(epsilon_x, epsilon))
|
||||||
@@ -1341,7 +1347,7 @@ int INFINITY_ND_generate_lfree(const struct MultiRowModel *model,
|
|||||||
{
|
{
|
||||||
if(t[i])
|
if(t[i])
|
||||||
{
|
{
|
||||||
beta[i] = min(beta[i] * 0.999, epsilon);
|
beta[i] = min(beta[i], epsilon);
|
||||||
}
|
}
|
||||||
else if(!skip_ahull)
|
else if(!skip_ahull)
|
||||||
{
|
{
|
||||||
@@ -1358,6 +1364,7 @@ int INFINITY_ND_generate_lfree(const struct MultiRowModel *model,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alpha = (floor(alpha * 128) / 128);
|
||||||
beta[i] = min(beta[i], alpha);
|
beta[i] = min(beta[i], alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ static int create_cut_from_lfree(const struct Tableau *tableau,
|
|||||||
struct Row *cut)
|
struct Row *cut)
|
||||||
{
|
{
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
double *ray = 0;
|
|
||||||
|
|
||||||
struct LP lp;
|
struct LP lp;
|
||||||
int nvars = map->nvars;
|
int nvars = map->nvars;
|
||||||
@@ -123,41 +122,40 @@ static int create_cut_from_lfree(const struct Tableau *tableau,
|
|||||||
rval = INFINITY_create_psi_lp(lfree, &lp);
|
rval = INFINITY_create_psi_lp(lfree, &lp);
|
||||||
abort_if(rval, "create_psi_lp failed");
|
abort_if(rval, "create_psi_lp failed");
|
||||||
|
|
||||||
ray = (double*) malloc(nrows * sizeof(double));
|
|
||||||
abort_if(!ray, "could not allocate ray");
|
|
||||||
|
|
||||||
cut->nz = nvars;
|
cut->nz = nvars;
|
||||||
for(int i = 0; i < nvars; i++)
|
for(int i = 0; i < nvars; i++)
|
||||||
{
|
{
|
||||||
double value, norm = 0;
|
double value;
|
||||||
double *original_ray = LFREE_get_ray(rays, map->variable_to_ray[i]);
|
const double *q = LFREE_get_ray(rays, map->variable_to_ray[i]);
|
||||||
char type = tableau->column_types[map->indices[i]];
|
char type = tableau->column_types[map->indices[i]];
|
||||||
|
|
||||||
for (int j = 0; j < nrows; j++)
|
|
||||||
{
|
|
||||||
ray[j] = original_ray[j];
|
|
||||||
norm += fabs(ray[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (norm < 0.001)
|
|
||||||
for (int j = 0; j < nrows; j++)
|
|
||||||
ray[j] *= 0.001 / norm;
|
|
||||||
|
|
||||||
if(ENABLE_LIFTING && type == MILP_INTEGER)
|
if(ENABLE_LIFTING && type == MILP_INTEGER)
|
||||||
{
|
{
|
||||||
rval = INFINITY_pi(nrows, ray, map->ray_scale[i], &lp, &value);
|
rval = INFINITY_pi(nrows, q, map->ray_scale[i], &lp, &value);
|
||||||
abort_if(rval, "INFINITY_pi failed");
|
abort_if(rval, "INFINITY_pi failed");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rval = INFINITY_psi(nrows, ray, map->ray_scale[i], &lp, &value);
|
rval = INFINITY_psi(nrows, q, map->ray_scale[i], &lp, &value);
|
||||||
abort_if(rval, "INFINITY_psi failed");
|
abort_if(rval, "INFINITY_psi failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
value *= 1.001;
|
|
||||||
value = fmax(value, 0.001);
|
|
||||||
log_verbose(" psi[%4d] = %20.12lf %d\n", map->indices[i], value);
|
log_verbose(" psi[%4d] = %20.12lf %d\n", map->indices[i], value);
|
||||||
|
|
||||||
|
if_debug_level
|
||||||
|
{
|
||||||
|
time_printf(" q=[");
|
||||||
|
for(int j = 0; j < nrows; j++)
|
||||||
|
printf("%25.20lf ", q[j] * map->ray_scale[i]);
|
||||||
|
printf("] value=%25.20lf\n", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = fmax(value, 1 / 1024.0);
|
||||||
|
|
||||||
|
// value *= 1.001;
|
||||||
|
// value = DOUBLE_max(value, 0.001);
|
||||||
|
|
||||||
cut->indices[i] = map->indices[i];
|
cut->indices[i] = map->indices[i];
|
||||||
cut->pi[i] = -value;
|
cut->pi[i] = -value;
|
||||||
}
|
}
|
||||||
@@ -165,7 +163,6 @@ static int create_cut_from_lfree(const struct Tableau *tableau,
|
|||||||
cut->pi_zero = -1.0;
|
cut->pi_zero = -1.0;
|
||||||
|
|
||||||
CLEANUP:
|
CLEANUP:
|
||||||
if(ray) free(ray);
|
|
||||||
LP_free(&lp);
|
LP_free(&lp);
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
@@ -189,7 +186,12 @@ static int filter_model(const struct MultiRowModel *original_model,
|
|||||||
struct RayList *filtered_rays = &filtered_model->rays;
|
struct RayList *filtered_rays = &filtered_model->rays;
|
||||||
const struct RayList *original_rays = &original_model->rays;
|
const struct RayList *original_rays = &original_model->rays;
|
||||||
|
|
||||||
memcpy(f, original_model->f, nrows * sizeof(double));
|
memcpy(f, original_model->f, 2 * sizeof(double));
|
||||||
|
for(int i = 0; i < nrows; i++)
|
||||||
|
{
|
||||||
|
f[i] = (ceil(f[i] * 128) / 128);
|
||||||
|
if(f[i] <= 0.01) f[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
r = (double*) malloc(nrows * sizeof(double));
|
r = (double*) malloc(nrows * sizeof(double));
|
||||||
abort_if(!r, "could not allocate r");
|
abort_if(!r, "could not allocate r");
|
||||||
@@ -266,18 +268,11 @@ static int append_extra_rays(struct MultiRowModel *model)
|
|||||||
|
|
||||||
for(int i = 0; i < nrows; i++)
|
for(int i = 0; i < nrows; i++)
|
||||||
{
|
{
|
||||||
int found, index;
|
|
||||||
double scale;
|
|
||||||
|
|
||||||
for(int j = 0; j < nrows; j++) r[j] = (i == j ? e : 0);
|
for(int j = 0; j < nrows; j++) r[j] = (i == j ? e : 0);
|
||||||
rval = CG_find_ray(&model->rays, r, &found, &scale, &index);
|
LFREE_push_ray(&model->rays, r);
|
||||||
abort_if(rval, "CG_find_ray failed");
|
|
||||||
if(!found) LFREE_push_ray(&model->rays, r);
|
|
||||||
|
|
||||||
for(int j = 0; j < nrows; j++) r[j] = (i == j ? -e : 0);
|
for(int j = 0; j < nrows; j++) r[j] = (i == j ? -e : 0);
|
||||||
rval = CG_find_ray(&model->rays, r, &found, &scale, &index);
|
LFREE_push_ray(&model->rays, r);
|
||||||
abort_if(rval, "CG_find_ray failed");
|
|
||||||
if(!found) LFREE_push_ray(&model->rays, r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nrows == 2)
|
if(nrows == 2)
|
||||||
@@ -414,9 +409,6 @@ int INFINITY_generate_cut(const struct Tableau *tableau, struct Row *cut)
|
|||||||
rval = CG_init_map(&original_map, max_nrays, tableau->nrows);
|
rval = CG_init_map(&original_map, max_nrays, tableau->nrows);
|
||||||
abort_if(rval, "CG_init_map failed");
|
abort_if(rval, "CG_init_map failed");
|
||||||
|
|
||||||
rval = LFREE_init_conv(&lfree, tableau->nrows, max_nrays);
|
|
||||||
abort_if(rval, "LFREE_init_conv failed");
|
|
||||||
|
|
||||||
rval = extract_models(tableau, &original_model, &filtered_model,
|
rval = extract_models(tableau, &original_model, &filtered_model,
|
||||||
&original_map);
|
&original_map);
|
||||||
abort_if(rval, "extract_models failed");
|
abort_if(rval, "extract_models failed");
|
||||||
@@ -427,17 +419,40 @@ int INFINITY_generate_cut(const struct Tableau *tableau, struct Row *cut)
|
|||||||
goto CLEANUP;
|
goto CLEANUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rval = LFREE_init_conv(&lfree, tableau->nrows, max_nrays);
|
||||||
|
abort_if(rval, "LFREE_init_conv failed");
|
||||||
|
|
||||||
|
// if(tableau->nrows == 2)
|
||||||
|
// rval = INFINITY_2D_generate_lfree(&filtered_model, &lfree);
|
||||||
|
// else
|
||||||
|
// rval = INFINITY_ND_generate_lfree(&filtered_model, &lfree);
|
||||||
|
//
|
||||||
|
// if(rval)
|
||||||
|
// {
|
||||||
|
// rval = ERR_NO_CUT;
|
||||||
|
// goto CLEANUP;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for(int i = 0; i < filtered_model.rays.nrays; i++)
|
||||||
|
// {
|
||||||
|
// double *r = LFREE_get_ray(&filtered_model.rays, i);
|
||||||
|
// for(int j = 0; j < tableau->nrows; j++)
|
||||||
|
// r[j] *= lfree.beta[j];
|
||||||
|
// }
|
||||||
|
|
||||||
rval = append_extra_rays(&filtered_model);
|
rval = append_extra_rays(&filtered_model);
|
||||||
abort_if(rval, "append_extra_rays failed");
|
abort_if(rval, "append_extra_rays failed");
|
||||||
|
|
||||||
if_debug_level
|
// if(tableau->nrows == 2)
|
||||||
{
|
// rval = INFINITY_2D_generate_lfree(&filtered_model, &lfree);
|
||||||
rval = CG_print_model(&filtered_model);
|
// else
|
||||||
abort_if(rval, "CG_print_model failed");
|
rval = INFINITY_ND_generate_lfree(&filtered_model, &lfree);
|
||||||
}
|
|
||||||
|
|
||||||
rval = INFINITY_ND_generate_lfree(&filtered_model, &lfree);
|
if(rval)
|
||||||
abort_if(rval, "INFINITY_ND_generate_lfree failed");
|
{
|
||||||
|
rval = ERR_NO_CUT;
|
||||||
|
goto CLEANUP;
|
||||||
|
}
|
||||||
|
|
||||||
if(SHOULD_DUMP_CUTS)
|
if(SHOULD_DUMP_CUTS)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -370,53 +370,6 @@ CLEANUP:
|
|||||||
if(rval) FAIL();
|
if(rval) FAIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(InfinityNDTest, psi_test_3)
|
|
||||||
{
|
|
||||||
int rval = 0;
|
|
||||||
|
|
||||||
double f[] = { 0.671875, 0.671875 };
|
|
||||||
double rays[] = {
|
|
||||||
-0.007812500000, 0.000000000000,
|
|
||||||
-0.039062500000, 0.046875000000,
|
|
||||||
0.000000000000, 0.046875000000,
|
|
||||||
0.046875000000, 0.000000000000,
|
|
||||||
0.000000000000, -0.039062500000
|
|
||||||
};
|
|
||||||
|
|
||||||
double beta[] = {
|
|
||||||
66.909090909091,
|
|
||||||
29.440000000000,
|
|
||||||
14.000000000000,
|
|
||||||
14.000000000000,
|
|
||||||
29.440000000000,
|
|
||||||
};
|
|
||||||
|
|
||||||
double q[] = { 0 - f[0], 1 - f[1]};
|
|
||||||
|
|
||||||
struct ConvLFreeSet lfree;
|
|
||||||
lfree.f = f;
|
|
||||||
lfree.beta = beta;
|
|
||||||
lfree.rays.nrays = 5;
|
|
||||||
lfree.rays.values = rays;
|
|
||||||
lfree.nrows = lfree.rays.dim = 2;
|
|
||||||
|
|
||||||
double value;
|
|
||||||
struct LP lp;
|
|
||||||
|
|
||||||
rval = LP_open(&lp);
|
|
||||||
abort_if(rval, "LP_open failed");
|
|
||||||
|
|
||||||
rval = INFINITY_create_psi_lp(&lfree, &lp);
|
|
||||||
abort_if(rval, "INFINITY_create_psi_lp failed");
|
|
||||||
|
|
||||||
rval = INFINITY_psi(lfree.nrows, q, 1.0, &lp, &value);
|
|
||||||
abort_if(rval, "GREDDY_ND_psi failed");
|
|
||||||
EXPECT_NEAR(value, 1.0, 1e-6);
|
|
||||||
|
|
||||||
CLEANUP:
|
|
||||||
if(rval) FAIL();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(InfinityNDTest, generate_cut_test_1)
|
TEST(InfinityNDTest, generate_cut_test_1)
|
||||||
{
|
{
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -116,6 +116,4 @@ int CG_total_nz(const struct Tableau *tableau);
|
|||||||
|
|
||||||
double CG_replace_x(const struct Row *row, const double *x);
|
double CG_replace_x(const struct Row *row, const double *x);
|
||||||
|
|
||||||
int CG_print_model(const struct MultiRowModel *model);
|
|
||||||
|
|
||||||
#endif //MULTIROW_CG_H
|
#endif //MULTIROW_CG_H
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ struct RayList
|
|||||||
int dim;
|
int dim;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ConvLFreeSet
|
struct ConvLFreeSet
|
||||||
{
|
{
|
||||||
double *f;
|
double *f;
|
||||||
@@ -81,6 +82,4 @@ int LFREE_init_conv(struct ConvLFreeSet *lfree, int dim, int max_nrays);
|
|||||||
|
|
||||||
void LFREE_free_conv(struct ConvLFreeSet *lfree);
|
void LFREE_free_conv(struct ConvLFreeSet *lfree);
|
||||||
|
|
||||||
int LFREE_print_set(const struct ConvLFreeSet *lfree);
|
|
||||||
|
|
||||||
#endif //LFREE_2D_H
|
#endif //LFREE_2D_H
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
/*
|
/*
|
||||||
* Maximum number of sets that should be considered
|
* Maximum number of sets that should be considered
|
||||||
*/
|
*/
|
||||||
#define MAX_N_SETS 1000
|
#define MAX_N_SETS 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Number of rays that should be generated per set.
|
* Number of rays that should be generated per set.
|
||||||
|
|||||||
@@ -945,10 +945,7 @@ int CG_add_multirow_cuts(struct CG *cg,
|
|||||||
LP_free_row(&cut);
|
LP_free_row(&cut);
|
||||||
goto NEXT_COMBINATION;
|
goto NEXT_COMBINATION;
|
||||||
}
|
}
|
||||||
else if(rval) {
|
else abort_iff(rval, "generate failed (cut %d)", count);
|
||||||
dump_tableau(&tableau, count);
|
|
||||||
abort_iff(1, "generate failed (cut %d)", count);
|
|
||||||
}
|
|
||||||
|
|
||||||
if_verbose_level dump_cut(&cut, count);
|
if_verbose_level dump_cut(&cut, count);
|
||||||
|
|
||||||
@@ -1118,32 +1115,4 @@ int CG_total_nz(const struct Tableau *tableau)
|
|||||||
return total_nz;
|
return total_nz;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CG_print_model(const struct MultiRowModel *model)
|
|
||||||
{
|
|
||||||
int rval = 0;
|
|
||||||
int nrows = model->nrows;
|
|
||||||
|
|
||||||
time_printf(" f = [");
|
|
||||||
for (int i = 0; i < nrows; i++)
|
|
||||||
printf("%20.12lf ", model->f[i]);
|
|
||||||
printf("]\n");
|
|
||||||
|
|
||||||
for (int i = 0; i < model->rays.nrays; i++)
|
|
||||||
{
|
|
||||||
double *ray = LFREE_get_ray(&model->rays, i);
|
|
||||||
double norm = 0;
|
|
||||||
|
|
||||||
time_printf("ray[%3d] = [", i);
|
|
||||||
for (int j = 0; j < nrows; j++)
|
|
||||||
{
|
|
||||||
printf("%20.12lf ", ray[j]);
|
|
||||||
norm += fabs(ray[j]);
|
|
||||||
}
|
|
||||||
printf("] norm=%20.12lf \n", norm);
|
|
||||||
}
|
|
||||||
|
|
||||||
CLEANUP:
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TEST_SOURCE
|
#endif // TEST_SOURCE
|
||||||
|
|||||||
@@ -559,41 +559,6 @@ CLEANUP:
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LFREE_print_set(const struct ConvLFreeSet *set)
|
|
||||||
{
|
|
||||||
int rval = 0;
|
|
||||||
|
|
||||||
log_debug("f=%12.6lf %12.6lf\n", set->f[0], set->f[1]);
|
|
||||||
|
|
||||||
for (int i = 0; i < set->rays.nrays; i++)
|
|
||||||
{
|
|
||||||
double *ray = LFREE_get_ray(&set->rays, i);
|
|
||||||
log_debug("ray[%-3d] = ", i);
|
|
||||||
for (int j = 0; j < set->nrows; j++)
|
|
||||||
printf("%20.12lf ", ray[j]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < set->rays.nrays; i++)
|
|
||||||
{
|
|
||||||
double beta = set->beta[i];
|
|
||||||
log_debug("beta[%-3d] = %20.12lf\n", i, beta);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < set->rays.nrays; i++)
|
|
||||||
{
|
|
||||||
double *ray = LFREE_get_ray(&set->rays, i);
|
|
||||||
double beta = set->beta[i];
|
|
||||||
log_debug("vertex[%-3d] = ", i);
|
|
||||||
for (int j = 0; j < set->nrows; j++)
|
|
||||||
printf("%20.12lf ", ray[j] * beta + set->f[j]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
CLEANUP:
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LFREE_free_conv(struct ConvLFreeSet *lfree)
|
void LFREE_free_conv(struct ConvLFreeSet *lfree)
|
||||||
{
|
{
|
||||||
if(!lfree) return;
|
if(!lfree) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user