Reorganize files; remove dead code

selection
Alinson S. Xavier 9 years ago
parent 484c847612
commit 0ee68e01bc

@ -1,21 +1,19 @@
set(COMMON_SOURCES
src/infinity-2d.c
src/greedy-nd.c
src/greedy-bsearch.c
src/infinity.c
include/infinity/infinity-2d.h
include/infinity/greedy-nd.h
include/infinity/greedy-bsearch.h
include/infinity/infinity.h)
src/infinity-2d.c
src/infinity-nd.c
src/infinity.c
include/infinity/infinity-2d.h
include/infinity/infinity-nd.h
include/infinity/infinity.h)
set(TEST_SOURCES
tests/infinity-2d-test.cpp
tests/greedy-nd-test.cpp
tests/infinity-test.cpp)
tests/infinity-2d-test.cpp
tests/infinity-nd-test.cpp
tests/infinity-test.cpp)
add_library(infinity_static ${COMMON_SOURCES})
set_target_properties(infinity_static PROPERTIES OUTPUT_NAME infinity)
target_include_directories (infinity_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(infinity_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(infinity-test.run ${COMMON_SOURCES} ${TEST_SOURCES})
target_link_libraries(infinity-test.run gtest_main multirow_static lifting_static)

@ -1,74 +0,0 @@
/* Copyright (c) 2015 Alinson Xavier
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MULTIROW_GREEDY_ND_H
#define MULTIROW_GREEDY_ND_H
int GREEDY_create_psi_lp(const struct ConvLFreeSet *lfree, struct LP *lp);
int GREEDY_ND_psi(const int nrows,
const double *q,
const double q_scale,
struct LP *lp,
double *value);
int GREEDY_ND_pi(const int nrows,
const double *q,
const double q_scale,
struct LP *lp,
double *value);
int INFINITY_ND_generate_lfree(const struct MultiRowModel *model,
struct ConvLFreeSet *lfree);
int GREEDY_ND_cone_bound(int nrows,
int nrays,
const double *f,
const double *rays,
const int *rx,
const double *x,
const double *beta,
double *epsilon);
int GREEDY_ND_find_violated_cone(int nrows,
int nrays,
const double *f,
const double *rays,
const double *x,
const double *beta,
double epsilon,
int *rx,
double *sbar,
int *violated_found);
int GREEDY_ND_find_tight_rays(int nrows,
int nrays,
const double *f,
const double *rays,
const double *x,
const double *beta,
double epsilon,
int *tx);
int GREEDY_ND_scale_to_ahull(int nrows,
int nrays,
const double *rays,
const int *rx,
const double *beta,
double epsilon,
const double *d,
double *alpha);
#endif //MULTIROW_GREEDY_ND_H

@ -13,21 +13,24 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MULTIROW_GREEDY_BSEARCH_H
#define MULTIROW_GREEDY_BSEARCH_H
#ifndef MULTIROW_INFINITY_ND_H
#define MULTIROW_INFINITY_ND_H
int create_sfree_mip(int nrows,
int nrays,
const double *f,
const double *rays,
const double *bounds,
double e,
struct LP *lp);
int INFINITY_create_psi_lp(const struct ConvLFreeSet *lfree, struct LP *lp);
int GREEDY_BSEARCH_compute_bounds(int nrows,
int nrays,
const double *f,
const double *rays,
double *bounds);
int INFINITY_psi(const int nrows,
const double *q,
const double q_scale,
struct LP *lp,
double *value);
#endif //MULTIROW_GREEDY_BSEARCH_H
int INFINITY_pi(const int nrows,
const double *q,
const double q_scale,
struct LP *lp,
double *value);
int INFINITY_ND_generate_lfree(const struct MultiRowModel *model,
struct ConvLFreeSet *lfree);
#endif //MULTIROW_INFINITY_ND_H

@ -1,246 +0,0 @@
/* Copyright (c) 2015 Alinson Xavier
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <math.h>
#include <stdlib.h>
#include <multirow/cg.h>
#include <multirow/double.h>
#include <multirow/geometry.h>
#include <multirow/lp.h>
#include <multirow/util.h>
#include <infinity/greedy-bsearch.h>
int create_sfree_mip(int nrows,
int nrays,
const double *f,
const double *rays,
const double *bounds,
double e,
struct LP *lp)
{
int rval = 0;
double rhs;
char sense;
int rmatbeg = 0;
int* rmatind = 0;
double *rmatval = 0;
rmatind = (int *) malloc((nrows + nrays) * sizeof(int));
rmatval = (double *) malloc((nrows + nrays) * sizeof(double));
abort_if(!rmatind, "could not allocate rmatind");
abort_if(!rmatval, "could not allocate rmatval");
rval = LP_create(lp, "greedy");
abort_if(rval, "LP_create failed");
// create x (basic) variables
for (int i = 0; i < nrows; i++)
{
rval = LP_new_col(lp, 0, -MILP_INFINITY, MILP_INFINITY, 'I');
abort_if(rval, "LP_new_col failed");
}
// create s (non-basic) variables
for (int i = 0; i < nrays; i++)
{
rval = LP_new_col(lp, 1.0, 0, MILP_INFINITY, 'C');
abort_if(rval, "LP_new_col failed");
}
// add constraint \sum_{i=1}^m s_i \leq 1
sense = 'L';
rhs = 1.0;
for (int i = 0; i < nrays; i++)
{
rmatind[i] = i + nrows;
rmatval[i] = 1.0;
}
rval = LP_add_rows(lp, 1, nrays, &rhs, &sense, &rmatbeg, rmatind, rmatval);
abort_if(rval, "LP_add_rows failed");
// add constraints x_i - \sum_{j=1}^m min{e,e_j} s_j R_ji = f_i
for (int i = 0; i < nrows; i++)
{
int k = 0;
sense = 'E';
rhs = f[i];
rmatind[k] = i;
rmatval[k] = 1.0;
k++;
for (int j = 0; j < nrays; j++)
{
rmatind[k] = j + nrows;
rmatval[k] = -rays[nrows * j + i] * fmin(e, bounds[j]);
k++;
}
rval = LP_add_rows(lp, 1, nrays + 1, &rhs, &sense, &rmatbeg, rmatind,
rmatval);
abort_if(rval, "LP_add_rows failed");
}
CLEANUP:
if (rmatind) free(rmatind);
if (rmatval) free(rmatval);
return rval;
}
int GREEDY_BSEARCH_compute_bounds(int nrows,
int nrays,
const double *f,
const double *rays,
double *bounds)
{
int rval = 0;
struct LP lp;
double e_upper = 2 * GREEDY_BIG_E;
double e_lower = 0.0;
int cplex_count = 0;
double cplex_time = 0;
int iteration_count = 0;
double *x = 0;
x = (double *) malloc((nrays + nrows) * sizeof(double));
abort_if(!x, "could not allocate x");
for (int i = 0; i < nrays; i++)
bounds[i] = GREEDY_BIG_E;
for (int it = 0;; it++)
{
abort_if(it > 2*nrays, "stuck in an infinite loop");
log_verbose("Starting iteration %d...\n", it);
iteration_count++;
int solution_found = 0;
int inner_count = 0;
while (fabs(e_upper - e_lower) > GREEDY_MAX_GAP)
{
inner_count++;
double e = (e_upper + e_lower) / 2;
log_verbose(" e=%.12lf\n", e);
rval = LP_open(&lp);
abort_if(rval, "LP_open failed");
rval = create_sfree_mip(nrows, nrays, f, rays, bounds, e, &lp);
abort_if(rval, "create_sfree_mip failed");
if_verbose_level
{
rval = LP_write(&lp, "greedy.lp");
abort_if(rval, "LP_write failed");
}
int infeasible;
cplex_count++;
double initial_time = get_user_time();
log_verbose(" Optimizing...\n");
rval = LP_optimize(&lp, &infeasible);
if (rval)
{
// Workaround for CPLEX bug. If CPLEX tell us that this problem
// is unbounded, we disable presolve and try again.
LP_free(&lp);
LP_open(&lp);
rval = create_sfree_mip(nrows, nrays, f, rays, bounds, e, &lp);
abort_if(rval, "create_sfree_mip failed");
LP_disable_presolve(&lp);
rval = LP_optimize(&lp, &infeasible);
abort_if(rval, "LP_optimize failed");
}
cplex_time += get_user_time() - initial_time;
if (infeasible)
{
e_lower = e;
log_verbose(" infeasible\n");
if (e > GREEDY_BIG_E-1)
{
LP_free(&lp);
goto OUT;
}
}
else
{
log_verbose(" feasible\n");
e_upper = e;
solution_found = 1;
rval = LP_get_x(&lp, x);
abort_if(rval, "LP_get_x failed");
}
LP_free(&lp);
}
if (solution_found)
{
for (int j = 0; j < nrays; j++)
{
if (!DOUBLE_geq(x[nrows + j], 0.001)) continue;
bounds[j] = fmin(bounds[j] * 0.99, e_lower * 0.99);
}
}
log_verbose(" %d iterations %12.8lf gap\n", inner_count, e_upper -
e_lower);
e_lower = e_upper;
e_upper = 2 * GREEDY_BIG_E;
}
OUT:
log_debug(" %6d IPs (%.2lfms per call, %.2lfs total)\n", cplex_count,
cplex_time * 1000.0 / cplex_count, cplex_time);
for(int i = 0; i < nrays; i++)
abort_if(DOUBLE_iszero(bounds[i]), "bounds should be positive");
if_verbose_level
{
time_printf("Bounds:\n");
for (int k = 0; k < nrays; k++)
time_printf(" %12.8lf %12.8lf\n", k, bounds[k], 1 / bounds[k]);
}
CLEANUP:
if (x) free(x);
return rval;
}

@ -22,7 +22,7 @@
#include <multirow/util.h>
#include <infinity/infinity.h>
#include <infinity/greedy-nd.h>
#include <infinity/infinity-nd.h>
#include <infinity/infinity-2d.h>
/**
@ -117,7 +117,7 @@ static int create_cut_from_lfree(const struct Tableau *tableau,
rval = LP_open(&lp);
abort_if(rval, "LP_open failed");
rval = GREEDY_create_psi_lp(lfree, &lp);
rval = INFINITY_create_psi_lp(lfree, &lp);
abort_if(rval, "create_psi_lp failed");
cut->nz = nvars;
@ -129,13 +129,13 @@ static int create_cut_from_lfree(const struct Tableau *tableau,
if(ENABLE_LIFTING && type == MILP_INTEGER)
{
rval = GREEDY_ND_pi(nrows, q, map->ray_scale[i], &lp, &value);
abort_if(rval, "GREEDY_ND_pi failed");
rval = INFINITY_pi(nrows, q, map->ray_scale[i], &lp, &value);
abort_if(rval, "INFINITY_pi failed");
}
else
{
rval = GREEDY_ND_psi(nrows, q, map->ray_scale[i], &lp, &value);
abort_if(rval, "GREEDY_ND_psi failed");
rval = INFINITY_psi(nrows, q, map->ray_scale[i], &lp, &value);
abort_if(rval, "INFINITY_psi failed");
}
log_verbose(" psi[%4d] = %20.12lf %d\n", map->indices[i], value);

@ -19,13 +19,12 @@
#define TEST_SOURCE
extern "C" {
#include <math.h>
#include <multirow/lp.h>
#include <multirow/util.h>
#include <multirow/lfree2d.h>
#include <multirow/cg.h>
#include <infinity/greedy-nd.h>
#include "../src/greedy-nd.c"
#include <infinity/infinity-nd.h>
#include "../src/infinity-nd.c"
}
int ENABLE_LIFTING = 0;
@ -34,7 +33,7 @@ int MAX_N_ROWS = 2;
int SHOULD_DUMP_CUTS = 0;
int DUMP_CUT_N = 0;
TEST(GreedyNDTest, find_violated_cone_test)
TEST(InfinityNDTest, find_violated_cone_test)
{
int rval = 0;
@ -56,9 +55,9 @@ TEST(GreedyNDTest, find_violated_cone_test)
int rx[nrays];
int found;
rval = GREEDY_ND_find_violated_cone(nrows, nrays, f, rays, x, beta,
1.0, rx, sbar, &found);
abort_if(rval, "GREEDY_ND_find_violated_cone failed");
rval = find_violated_cone(nrows, nrays, f, rays, x, beta, 1.0, rx, sbar,
&found);
abort_if(rval, "find_violated_cone failed");
EXPECT_TRUE(found);
EXPECT_FALSE(rx[0]);
@ -66,9 +65,9 @@ TEST(GreedyNDTest, find_violated_cone_test)
EXPECT_TRUE(rx[2]);
EXPECT_FALSE(rx[3]);
rval = GREEDY_ND_find_violated_cone(nrows, nrays, f, rays, x, beta,
0.5, rx, sbar, &found);
abort_if(rval, "GREEDY_ND_find_violated_cone failed");
rval = find_violated_cone(nrows, nrays, f, rays, x, beta, 0.5, rx, sbar,
&found);
abort_if(rval, "find_violated_cone failed");
EXPECT_FALSE(found);
@ -76,7 +75,7 @@ TEST(GreedyNDTest, find_violated_cone_test)
if(rval) FAIL();
}
TEST(GreedyNDTest, find_tight_rays_test_1)
TEST(InfinityNDTest, find_tight_rays_test_1)
{
int rval = 0;
@ -97,8 +96,8 @@ TEST(GreedyNDTest, find_tight_rays_test_1)
int tx[6];
rval = GREEDY_ND_find_tight_rays(2, 6, f, rays, x, beta, epsilon, tx);
abort_if(rval, "GREEDY_ND_find_tight_rays failed");
rval = find_tight_rays(2, 6, f, rays, x, beta, epsilon, tx);
abort_if(rval, "find_tight_rays failed");
EXPECT_TRUE(tx[0]);
EXPECT_FALSE(tx[1]);
@ -111,7 +110,7 @@ TEST(GreedyNDTest, find_tight_rays_test_1)
if(rval) FAIL();
}
TEST(GreedyNDTest, find_tight_rays_test_2)
TEST(InfinityNDTest, find_tight_rays_test_2)
{
int rval = 0;
@ -131,8 +130,8 @@ TEST(GreedyNDTest, find_tight_rays_test_2)
int tx[6];
rval = GREEDY_ND_find_tight_rays(2, 6, f, rays, x, beta, epsilon, tx);
abort_if(rval, "GREEDY_ND_find_tight_rays failed");
rval = find_tight_rays(2, 6, f, rays, x, beta, epsilon, tx);
abort_if(rval, "find_tight_rays failed");
EXPECT_TRUE(tx[0]);
EXPECT_FALSE(tx[1]);
@ -145,7 +144,7 @@ TEST(GreedyNDTest, find_tight_rays_test_2)
if(rval) FAIL();
}
TEST(GreedyNDTest, cone_bound_test_1)
TEST(InfinityNDTest, cone_bound_test_1)
{
int rval = 0;
@ -168,19 +167,19 @@ TEST(GreedyNDTest, cone_bound_test_1)
double epsilon;
rval = GREEDY_ND_cone_bound(2, 6, f, rays, rx1, x, beta, &epsilon);
abort_if(rval, "GREEDY_ND_cone_bound failed");
rval = cone_bound(2, 6, f, rays, rx1, x, beta, &epsilon);
abort_if(rval, "cone_bound failed");
EXPECT_NEAR(0.5, epsilon, 1e-6);
rval = GREEDY_ND_cone_bound(2, 6, f, rays, rx2, x, beta, &epsilon);
abort_if(rval, "GREEDY_ND_cone_bound failed");
rval = cone_bound(2, 6, f, rays, rx2, x, beta, &epsilon);
abort_if(rval, "cone_bound failed");
EXPECT_NEAR(1.0, epsilon, 1e-6);
CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNDTest, cone_bound_test_2)
TEST(InfinityNDTest, cone_bound_test_2)
{
int rval = 0;
@ -201,27 +200,27 @@ TEST(GreedyNDTest, cone_bound_test_2)
double epsilon;
rval = GREEDY_ND_cone_bound(2, 2, f, rays, rx, x1, beta1, &epsilon);
abort_if(rval, "GREEDY_ND_cone_bound failed");
rval = cone_bound(2, 2, f, rays, rx, x1, beta1, &epsilon);
abort_if(rval, "cone_bound failed");
EXPECT_NEAR(1.0, epsilon, 1e-6);
rval = GREEDY_ND_cone_bound(2, 2, f, rays, rx, x1, beta2, &epsilon);
abort_if(rval, "GREEDY_ND_cone_bound failed");
rval = cone_bound(2, 2, f, rays, rx, x1, beta2, &epsilon);
abort_if(rval, "cone_bound failed");
EXPECT_EQ(INFINITY, epsilon);
rval = GREEDY_ND_cone_bound(2, 2, f, rays, rx, x2, beta2, &epsilon);
abort_if(rval, "GREEDY_ND_cone_bound failed");
rval = cone_bound(2, 2, f, rays, rx, x2, beta2, &epsilon);
abort_if(rval, "cone_bound failed");
EXPECT_NEAR(1.0, epsilon, 1e-6);
rval = GREEDY_ND_cone_bound(2, 2, f, rays, rx, x2, beta3, &epsilon);
abort_if(rval, "GREEDY_ND_cone_bound failed");
rval = cone_bound(2, 2, f, rays, rx, x2, beta3, &epsilon);
abort_if(rval, "cone_bound failed");
EXPECT_EQ(INFINITY, epsilon);
CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNDTest, bound_test_1)
TEST(InfinityNDTest, bound_test_1)
{
int rval = 0;
@ -277,7 +276,7 @@ CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNDTest, psi_test)
TEST(InfinityNDTest, psi_test)
{
int rval = 0;
@ -309,14 +308,14 @@ TEST(GreedyNDTest, psi_test)
rval = LP_open(&lp);
abort_if(rval, "LP_open failed");
rval = GREEDY_create_psi_lp(&lfree, &lp);
abort_if(rval, "GREEDY_create_psi_lp failed");
rval = INFINITY_create_psi_lp(&lfree, &lp);
abort_if(rval, "INFINITY_create_psi_lp failed");
rval = GREEDY_ND_psi(2, q1, 1.0, &lp, &value);
rval = INFINITY_psi(2, q1, 1.0, &lp, &value);
abort_if(rval, "GREDDY_ND_psi failed");
EXPECT_NEAR(value, 2.0, 1e-6);
rval = GREEDY_ND_psi(2, q2, 2.0, &lp, &value);
rval = INFINITY_psi(2, q2, 2.0, &lp, &value);
abort_if(rval, "GREDDY_ND_psi failed");
EXPECT_NEAR(value, 8.0, 1e-6);
@ -325,7 +324,7 @@ CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNDTest, psi_test_2)
TEST(InfinityNDTest, psi_test_2)
{
int rval = 0;
@ -361,14 +360,14 @@ TEST(GreedyNDTest, psi_test_2)
rval = LP_open(&lp);
abort_if(rval, "LP_open failed");
rval = GREEDY_create_psi_lp(&lfree, &lp);
abort_if(rval, "GREEDY_create_psi_lp failed");
rval = INFINITY_create_psi_lp(&lfree, &lp);
abort_if(rval, "INFINITY_create_psi_lp failed");
rval = GREEDY_ND_psi(3, q1, 1.0, &lp, &value);
rval = INFINITY_psi(3, q1, 1.0, &lp, &value);
abort_if(rval, "GREDDY_ND_psi failed");
EXPECT_NEAR(value, 1.0, 1e-6);
rval = GREEDY_ND_psi(3, q2, 1.0, &lp, &value);
rval = INFINITY_psi(3, q2, 1.0, &lp, &value);
abort_if(rval, "GREDDY_ND_psi failed");
EXPECT_NEAR(value, 2.0, 1e-6);
@ -376,7 +375,7 @@ CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNDTest, generate_cut_test_1)
TEST(InfinityNDTest, generate_cut_test_1)
{
int rval = 0;
@ -415,7 +414,7 @@ CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNDTest, generate_cut_test_2)
TEST(InfinityNDTest, generate_cut_test_2)
{
int rval = 0;
@ -456,7 +455,7 @@ CLEANUP:
if(rval) FAIL();
}
TEST(GreedyNTest, scale_to_ahull_test)
TEST(InfinityNDTest, scale_to_ahull_test)
{
int rval = 0;
@ -478,16 +477,16 @@ TEST(GreedyNTest, scale_to_ahull_test)
double alpha;
rval = GREEDY_ND_scale_to_ahull(3, 4, rays, rx, beta, epsilon, d1, &alpha);
abort_if(rval, "GREEDY_ND_scale_to_ahull failed");
rval = scale_to_ahull(3, 4, rays, rx, beta, epsilon, d1, &alpha);
abort_if(rval, "scale_to_ahull failed");
EXPECT_DOUBLE_EQ(1 / 3.0, alpha);
rval = GREEDY_ND_scale_to_ahull(3, 4, rays, rx, beta, epsilon, d2, &alpha);
abort_if(rval, "GREEDY_ND_scale_to_ahull failed");
rval = scale_to_ahull(3, 4, rays, rx, beta, epsilon, d2, &alpha);
abort_if(rval, "scale_to_ahull failed");
EXPECT_DOUBLE_EQ(0.25, alpha);
rval = GREEDY_ND_scale_to_ahull(3, 4, rays, rx, beta, epsilon, d3, &alpha);
abort_if(rval, "GREEDY_ND_scale_to_ahull failed");
rval = scale_to_ahull(3, 4, rays, rx, beta, epsilon, d3, &alpha);
abort_if(rval, "scale_to_ahull failed");
EXPECT_EQ(INFINITY, alpha);
CLEANUP: