mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
clean up int_solver
Signed-off-by: Lev Nachmanson <levnach@hotmail.com> add a diagnostic method Signed-off-by: Lev Nachmanson <levnach@hotmail.com> white space change Signed-off-by: Lev Nachmanson <levnach@microsoft.com> cleanup in int_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> some cleanup Signed-off-by: Lev Nachmanson <levnach@microsoft.com> remove m_became_zeros Signed-off-by: Lev Nachmanson <levnach@microsoft.com> start cut_solver, work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> start cut_solver, work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> workin on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> working on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> working on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> working on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs in disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs in gisjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs in gisjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs in disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs in disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> fix bugs is disjoint intervals Signed-off-by: Lev Nachmanson <levnach@microsoft.com> bug fixes in disjoint_intervals Signed-off-by: Lev Nachmanson <levnach@hotmail.com> disjoint_intervals passes the test Signed-off-by: Lev Nachmanson <levnach@hotmail.com> test disjoint_intervals push(), pop() Signed-off-by: Lev Nachmanson <levnach@hotmail.com> cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com> work on cut_solver Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
db8f01894f
commit
58ca4518e5
28 changed files with 2469 additions and 1307 deletions
|
@ -47,13 +47,16 @@ Revision History:
|
|||
#include "util/lp/stacked_unordered_set.h"
|
||||
#include "util/lp/int_set.h"
|
||||
#include "util/stopwatch.h"
|
||||
#include "util/lp/integer_domain.h"
|
||||
#include "util/lp/stacked_map.h"
|
||||
#include <cstdlib>
|
||||
namespace lp {
|
||||
unsigned seed = 1;
|
||||
|
||||
random_gen g_rand;
|
||||
static unsigned my_random() {
|
||||
return g_rand();
|
||||
}
|
||||
random_gen g_rand;
|
||||
static unsigned my_random() {
|
||||
return g_rand();
|
||||
}
|
||||
struct simple_column_namer:public column_namer
|
||||
{
|
||||
std::string get_column_name(unsigned j) const override {
|
||||
|
@ -66,7 +69,7 @@ template <typename T, typename X>
|
|||
void test_matrix(sparse_matrix<T, X> & a) {
|
||||
auto m = a.dimension();
|
||||
|
||||
// copy a to b in the reversed order
|
||||
// copy a to b in the reversed order
|
||||
sparse_matrix<T, X> b(m);
|
||||
std::cout << "copy b to a"<< std::endl;
|
||||
for (int row = m - 1; row >= 0; row--)
|
||||
|
@ -198,9 +201,9 @@ void init_non_basic_part_of_basis_heading(vector<int> & basis_heading, vector<un
|
|||
non_basic_columns.clear();
|
||||
for (int j = basis_heading.size(); j--;){
|
||||
if (basis_heading[j] < 0) {
|
||||
non_basic_columns.push_back(j);
|
||||
// the index of column j in m_nbasis is (- basis_heading[j] - 1)
|
||||
basis_heading[j] = - static_cast<int>(non_basic_columns.size());
|
||||
non_basic_columns.push_back(j);
|
||||
// the index of column j in m_nbasis is (- basis_heading[j] - 1)
|
||||
basis_heading[j] = - static_cast<int>(non_basic_columns.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -554,7 +557,7 @@ void test_lp_0() {
|
|||
vector<unsigned> nbasis;
|
||||
vector<int> heading;
|
||||
|
||||
lp_primal_core_solver<double, double> lpsolver(m_, b, x_star, basis, nbasis, heading, costs, column_types, upper_bound_values, settings, cn);
|
||||
lp_primal_core_solver<double, double> lpsolver(m_, b, x_star, basis, nbasis, heading, costs, column_types, upper_bound_values, settings, cn);
|
||||
|
||||
lpsolver.solve();
|
||||
}
|
||||
|
@ -674,7 +677,7 @@ void test_swap_rows(sparse_matrix<T, X>& m, unsigned i0, unsigned i1){
|
|||
for (unsigned i = 0; i < m.dimension(); i++)
|
||||
for (unsigned j = 0; j < m.dimension(); j++) {
|
||||
mcopy(i, j)= m(i, j);
|
||||
}
|
||||
}
|
||||
std::cout << "swapping rows "<< i0 << "," << i1 << std::endl;
|
||||
m.swap_rows(i0, i1);
|
||||
|
||||
|
@ -690,7 +693,7 @@ void test_swap_columns(sparse_matrix<T, X>& m, unsigned i0, unsigned i1){
|
|||
for (unsigned i = 0; i < m.dimension(); i++)
|
||||
for (unsigned j = 0; j < m.dimension(); j++) {
|
||||
mcopy(i, j)= m(i, j);
|
||||
}
|
||||
}
|
||||
m.swap_columns(i0, i1);
|
||||
|
||||
for (unsigned j = 0; j < m.dimension(); j++) {
|
||||
|
@ -722,7 +725,7 @@ void test_pivot_like_swaps_and_pivot(){
|
|||
sparse_matrix<double, double> m(10);
|
||||
fill_matrix(m);
|
||||
// print_matrix(m);
|
||||
// pivot at 2,7
|
||||
// pivot at 2,7
|
||||
m.swap_columns(0, 7);
|
||||
// print_matrix(m);
|
||||
m.swap_rows(2, 0);
|
||||
|
@ -732,7 +735,7 @@ void test_pivot_like_swaps_and_pivot(){
|
|||
}
|
||||
// print_matrix(m);
|
||||
|
||||
// say pivot at 3,4
|
||||
// say pivot at 3,4
|
||||
m.swap_columns(1, 4);
|
||||
// print_matrix(m);
|
||||
m.swap_rows(1, 3);
|
||||
|
@ -790,7 +793,7 @@ void test_swap_rows() {
|
|||
// print_matrix(m);
|
||||
test_swap_rows(m, 0, 7);
|
||||
|
||||
// go over some corner cases
|
||||
// go over some corner cases
|
||||
sparse_matrix<double, double> m0(2);
|
||||
test_swap_rows(m0, 0, 1);
|
||||
m0(0, 0) = 3;
|
||||
|
@ -942,7 +945,7 @@ void test_swap_columns() {
|
|||
|
||||
test_swap_columns(m, 0, 7);
|
||||
|
||||
// go over some corner cases
|
||||
// go over some corner cases
|
||||
sparse_matrix<double, double> m0(2);
|
||||
test_swap_columns(m0, 0, 1);
|
||||
m0(0, 0) = 3;
|
||||
|
@ -1042,7 +1045,7 @@ void test_apply_reverse_from_right_to_perm(permutation_matrix<double, double> &
|
|||
auto rs = pclone * rev;
|
||||
lp_assert(p == rs)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void test_apply_reverse_from_right() {
|
||||
auto vec = vector_of_permutaions();
|
||||
|
@ -1818,7 +1821,7 @@ std::unordered_map<std::string, double> * get_solution_from_glpsol_output(std::s
|
|||
}
|
||||
auto split = string_split(s, " \t", false);
|
||||
if (split.size() == 0) {
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
lp_assert(split.size() > 3);
|
||||
|
@ -1880,6 +1883,8 @@ void test_replace_column() {
|
|||
|
||||
|
||||
void setup_args_parser(argument_parser & parser) {
|
||||
parser.add_option_with_help_string("-dji", "test integer_domain");
|
||||
parser.add_option_with_help_string("-cs", "test cut_solver");
|
||||
parser.add_option_with_help_string("-xyz_sample", "run a small interactive scenario");
|
||||
parser.add_option_with_after_string_with_help("--density", "the percentage of non-zeroes in the matrix below which it is not dense");
|
||||
parser.add_option_with_after_string_with_help("--harris_toler", "harris tolerance");
|
||||
|
@ -2058,15 +2063,15 @@ void test_stacked() {
|
|||
}
|
||||
|
||||
char * find_home_dir() {
|
||||
#ifdef _WINDOWS
|
||||
#else
|
||||
#ifdef _WINDOWS
|
||||
#else
|
||||
char * home_dir = getenv("HOME");
|
||||
if (home_dir == nullptr) {
|
||||
if (home_dir == nullptr) {
|
||||
std::cout << "cannot find home directory" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2088,8 +2093,8 @@ struct mem_cpy_place_holder {
|
|||
|
||||
void finalize(unsigned ret) {
|
||||
/*
|
||||
finalize_util_module();
|
||||
finalize_numerics_module();
|
||||
finalize_util_module();
|
||||
finalize_numerics_module();
|
||||
*/
|
||||
// return ret;
|
||||
}
|
||||
|
@ -2227,7 +2232,7 @@ bool values_are_one_percent_close(double a, double b) {
|
|||
|
||||
// returns true if both are optimal
|
||||
void compare_costs(std::string glpk_out_file_name,
|
||||
std::string lp_out_file_name,
|
||||
std::string lp_out_file_name,
|
||||
unsigned & successes,
|
||||
unsigned & failures) {
|
||||
double a = get_glpk_cost(glpk_out_file_name);
|
||||
|
@ -2306,78 +2311,78 @@ void process_test_file(std::string test_dir, std::string test_file_name, argumen
|
|||
}
|
||||
/*
|
||||
int my_readdir(DIR *dirp, struct dirent *
|
||||
#ifndef LEAN_WINDOWS
|
||||
entry
|
||||
#endif
|
||||
, struct dirent **result) {
|
||||
#ifdef LEAN_WINDOWS
|
||||
*result = readdir(dirp); // NOLINT
|
||||
return *result != nullptr? 0 : 1;
|
||||
#else
|
||||
return readdir_r(dirp, entry, result);
|
||||
#endif
|
||||
}
|
||||
#ifndef LEAN_WINDOWS
|
||||
entry
|
||||
#endif
|
||||
, struct dirent **result) {
|
||||
#ifdef LEAN_WINDOWS
|
||||
*result = readdir(dirp); // NOLINT
|
||||
return *result != nullptr? 0 : 1;
|
||||
#else
|
||||
return readdir_r(dirp, entry, result);
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
/*
|
||||
vector<std::pair<std::string, int>> get_file_list_of_dir(std::string test_file_dir) {
|
||||
DIR *dir;
|
||||
if ((dir = opendir(test_file_dir.c_str())) == nullptr) {
|
||||
std::cout << "Cannot open directory " << test_file_dir << std::endl;
|
||||
throw 0;
|
||||
}
|
||||
vector<std::pair<std::string, int>> ret;
|
||||
struct dirent entry;
|
||||
struct dirent* result;
|
||||
int return_code;
|
||||
for (return_code = my_readdir(dir, &entry, &result);
|
||||
#ifndef LEAN_WINDOWS
|
||||
result != nullptr &&
|
||||
#endif
|
||||
return_code == 0;
|
||||
return_code = my_readdir(dir, &entry, &result)) {
|
||||
DIR *tmp_dp = opendir(result->d_name);
|
||||
struct stat file_record;
|
||||
if (tmp_dp == nullptr) {
|
||||
std::string s = test_file_dir+ "/" + result->d_name;
|
||||
int stat_ret = stat(s.c_str(), & file_record);
|
||||
if (stat_ret!= -1) {
|
||||
ret.push_back(make_pair(result->d_name, file_record.st_size));
|
||||
} else {
|
||||
perror("stat");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
closedir(tmp_dp);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
return ret;
|
||||
}
|
||||
vector<std::pair<std::string, int>> get_file_list_of_dir(std::string test_file_dir) {
|
||||
DIR *dir;
|
||||
if ((dir = opendir(test_file_dir.c_str())) == nullptr) {
|
||||
std::cout << "Cannot open directory " << test_file_dir << std::endl;
|
||||
throw 0;
|
||||
}
|
||||
vector<std::pair<std::string, int>> ret;
|
||||
struct dirent entry;
|
||||
struct dirent* result;
|
||||
int return_code;
|
||||
for (return_code = my_readdir(dir, &entry, &result);
|
||||
#ifndef LEAN_WINDOWS
|
||||
result != nullptr &&
|
||||
#endif
|
||||
return_code == 0;
|
||||
return_code = my_readdir(dir, &entry, &result)) {
|
||||
DIR *tmp_dp = opendir(result->d_name);
|
||||
struct stat file_record;
|
||||
if (tmp_dp == nullptr) {
|
||||
std::string s = test_file_dir+ "/" + result->d_name;
|
||||
int stat_ret = stat(s.c_str(), & file_record);
|
||||
if (stat_ret!= -1) {
|
||||
ret.push_back(make_pair(result->d_name, file_record.st_size));
|
||||
} else {
|
||||
perror("stat");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
closedir(tmp_dp);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
struct file_size_comp {
|
||||
unordered_map<std::string, int>& m_file_sizes;
|
||||
file_size_comp(unordered_map<std::string, int>& fs) :m_file_sizes(fs) {}
|
||||
int operator()(std::string a, std::string b) {
|
||||
std::cout << m_file_sizes.size() << std::endl;
|
||||
std::cout << a << std::endl;
|
||||
std::cout << b << std::endl;
|
||||
struct file_size_comp {
|
||||
unordered_map<std::string, int>& m_file_sizes;
|
||||
file_size_comp(unordered_map<std::string, int>& fs) :m_file_sizes(fs) {}
|
||||
int operator()(std::string a, std::string b) {
|
||||
std::cout << m_file_sizes.size() << std::endl;
|
||||
std::cout << a << std::endl;
|
||||
std::cout << b << std::endl;
|
||||
|
||||
auto ls = m_file_sizes.find(a);
|
||||
std::cout << "fa" << std::endl;
|
||||
auto rs = m_file_sizes.find(b);
|
||||
std::cout << "fb" << std::endl;
|
||||
if (ls != m_file_sizes.end() && rs != m_file_sizes.end()) {
|
||||
std::cout << "fc " << std::endl;
|
||||
int r = (*ls < *rs? -1: (*ls > *rs)? 1 : 0);
|
||||
std::cout << "calc r " << std::endl;
|
||||
return r;
|
||||
} else {
|
||||
std::cout << "sc " << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
auto ls = m_file_sizes.find(a);
|
||||
std::cout << "fa" << std::endl;
|
||||
auto rs = m_file_sizes.find(b);
|
||||
std::cout << "fb" << std::endl;
|
||||
if (ls != m_file_sizes.end() && rs != m_file_sizes.end()) {
|
||||
std::cout << "fc " << std::endl;
|
||||
int r = (*ls < *rs? -1: (*ls > *rs)? 1 : 0);
|
||||
std::cout << "calc r " << std::endl;
|
||||
return r;
|
||||
} else {
|
||||
std::cout << "sc " << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
*/
|
||||
struct sort_pred {
|
||||
|
@ -2389,26 +2394,26 @@ struct sort_pred {
|
|||
|
||||
void test_files_from_directory(std::string test_file_dir, argument_parser & args_parser) {
|
||||
/*
|
||||
std::cout << "loading files from directory \"" << test_file_dir << "\"" << std::endl;
|
||||
std::string out_dir = args_parser.get_option_value("--out_dir");
|
||||
if (out_dir.size() == 0) {
|
||||
out_dir = "/tmp/test";
|
||||
}
|
||||
DIR *out_dir_p = opendir(out_dir.c_str());
|
||||
if (out_dir_p == nullptr) {
|
||||
std::cout << "Cannot open output directory \"" << out_dir << "\"" << std::endl;
|
||||
return;
|
||||
}
|
||||
closedir(out_dir_p);
|
||||
vector<std::pair<std::string, int>> files = get_file_list_of_dir(test_file_dir);
|
||||
std::sort(files.begin(), files.end(), sort_pred());
|
||||
unsigned max_iters, time_limit;
|
||||
get_time_limit_and_max_iters_from_parser(args_parser, time_limit, max_iters);
|
||||
unsigned successes = 0, failures = 0, inconclusives = 0;
|
||||
for (auto & t : files) {
|
||||
process_test_file(test_file_dir, t.first, args_parser, out_dir, max_iters, time_limit, successes, failures, inconclusives);
|
||||
}
|
||||
std::cout << "comparing with glpk: successes " << successes << ", failures " << failures << ", inconclusives " << inconclusives << std::endl;
|
||||
std::cout << "loading files from directory \"" << test_file_dir << "\"" << std::endl;
|
||||
std::string out_dir = args_parser.get_option_value("--out_dir");
|
||||
if (out_dir.size() == 0) {
|
||||
out_dir = "/tmp/test";
|
||||
}
|
||||
DIR *out_dir_p = opendir(out_dir.c_str());
|
||||
if (out_dir_p == nullptr) {
|
||||
std::cout << "Cannot open output directory \"" << out_dir << "\"" << std::endl;
|
||||
return;
|
||||
}
|
||||
closedir(out_dir_p);
|
||||
vector<std::pair<std::string, int>> files = get_file_list_of_dir(test_file_dir);
|
||||
std::sort(files.begin(), files.end(), sort_pred());
|
||||
unsigned max_iters, time_limit;
|
||||
get_time_limit_and_max_iters_from_parser(args_parser, time_limit, max_iters);
|
||||
unsigned successes = 0, failures = 0, inconclusives = 0;
|
||||
for (auto & t : files) {
|
||||
process_test_file(test_file_dir, t.first, args_parser, out_dir, max_iters, time_limit, successes, failures, inconclusives);
|
||||
}
|
||||
std::cout << "comparing with glpk: successes " << successes << ", failures " << failures << ", inconclusives " << inconclusives << std::endl;
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -2654,7 +2659,7 @@ void check_lu_from_file(std::string lufile_name) {
|
|||
lp_settings settings;
|
||||
vector<unsigned> non_basic_columns;
|
||||
lu<double, double> lsuhl(A, basis, settings);
|
||||
indexed_vector<double> d(A.row_count());
|
||||
indexed_vector<double> d(A.row_count());
|
||||
unsigned entering = 26;
|
||||
lsuhl.solve_Bd(entering, d, v);
|
||||
#ifdef Z3DEBUG
|
||||
|
@ -2765,21 +2770,21 @@ void test_evidence_for_total_inf_simple(argument_parser & args_parser) {
|
|||
}
|
||||
void test_bound_propagation_one_small_sample1() {
|
||||
/*
|
||||
(<= (+ a (* (- 1.0) b)) 0.0)
|
||||
(<= (+ b (* (- 1.0) x_13)) 0.0)
|
||||
--> (<= (+ a (* (- 1.0) c)) 0.0)
|
||||
(<= (+ a (* (- 1.0) b)) 0.0)
|
||||
(<= (+ b (* (- 1.0) x_13)) 0.0)
|
||||
--> (<= (+ a (* (- 1.0) c)) 0.0)
|
||||
|
||||
the inequality on (<= a c) is obtained from a triangle inequality (<= a b) (<= b c).
|
||||
If b becomes basic variable, then it is likely the old solver ends up with a row that implies (<= a c).
|
||||
a - b <= 0.0
|
||||
b - c <= 0.0
|
||||
the inequality on (<= a c) is obtained from a triangle inequality (<= a b) (<= b c).
|
||||
If b becomes basic variable, then it is likely the old solver ends up with a row that implies (<= a c).
|
||||
a - b <= 0.0
|
||||
b - c <= 0.0
|
||||
|
||||
got to get a <= c
|
||||
got to get a <= c
|
||||
*/
|
||||
std::function<bool (unsigned, bool, bool, const mpq & )> bound_is_relevant =
|
||||
[&](unsigned j, bool is_low_bound, bool strict, const rational& bound_val) {
|
||||
return true;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
lar_solver ls;
|
||||
unsigned a = ls.add_var(0, false);
|
||||
unsigned b = ls.add_var(1, false);
|
||||
|
@ -2815,34 +2820,34 @@ void test_bound_propagation_one_small_samples() {
|
|||
test_bound_propagation_one_small_sample1();
|
||||
/*
|
||||
(>= x_46 0.0)
|
||||
(<= x_29 0.0)
|
||||
(not (<= x_68 0.0))
|
||||
(<= (+ (* (/ 1001.0 1998.0) x_10) (* (- 1.0) x_151) x_68) (- (/ 1001.0 999.0)))
|
||||
(<= (+ (* (/ 1001.0 999.0) x_9)
|
||||
(* (- 1.0) x_152)
|
||||
(* (/ 1001.0 999.0) x_151)
|
||||
(* (/ 1001.0 999.0) x_68))
|
||||
(- (/ 1502501.0 999000.0)))
|
||||
(not (<= (+ (* (/ 999.0 2.0) x_10) (* (- 1.0) x_152) (* (- (/ 999.0 2.0)) x_151))
|
||||
(/ 1001.0 2.0)))
|
||||
(not (<= x_153 0.0))z
|
||||
(>= (+ x_9 (* (- (/ 1001.0 999.0)) x_10) (* (- 1.0) x_153) (* (- 1.0) x_68))
|
||||
(/ 5003.0 1998.0))
|
||||
--> (not (<= (+ x_10 x_46 (* (- 1.0) x_29)) 0.0))
|
||||
(<= x_29 0.0)
|
||||
(not (<= x_68 0.0))
|
||||
(<= (+ (* (/ 1001.0 1998.0) x_10) (* (- 1.0) x_151) x_68) (- (/ 1001.0 999.0)))
|
||||
(<= (+ (* (/ 1001.0 999.0) x_9)
|
||||
(* (- 1.0) x_152)
|
||||
(* (/ 1001.0 999.0) x_151)
|
||||
(* (/ 1001.0 999.0) x_68))
|
||||
(- (/ 1502501.0 999000.0)))
|
||||
(not (<= (+ (* (/ 999.0 2.0) x_10) (* (- 1.0) x_152) (* (- (/ 999.0 2.0)) x_151))
|
||||
(/ 1001.0 2.0)))
|
||||
(not (<= x_153 0.0))z
|
||||
(>= (+ x_9 (* (- (/ 1001.0 999.0)) x_10) (* (- 1.0) x_153) (* (- 1.0) x_68))
|
||||
(/ 5003.0 1998.0))
|
||||
--> (not (<= (+ x_10 x_46 (* (- 1.0) x_29)) 0.0))
|
||||
|
||||
and
|
||||
and
|
||||
|
||||
(<= (+ a (* (- 1.0) b)) 0.0)
|
||||
(<= (+ b (* (- 1.0) x_13)) 0.0)
|
||||
--> (<= (+ a (* (- 1.0) x_13)) 0.0)
|
||||
(<= (+ a (* (- 1.0) b)) 0.0)
|
||||
(<= (+ b (* (- 1.0) x_13)) 0.0)
|
||||
--> (<= (+ a (* (- 1.0) x_13)) 0.0)
|
||||
|
||||
In the first case, there typically are no atomic formulas for bounding x_10. So there is never some
|
||||
basic lemma of the form (>= x46 0), (<= x29 0), (>= x10 0) -> (not (<= (+ x10 x46 (- x29)) 0)).
|
||||
Instead the bound on x_10 falls out from a bigger blob of constraints.
|
||||
In the first case, there typically are no atomic formulas for bounding x_10. So there is never some
|
||||
basic lemma of the form (>= x46 0), (<= x29 0), (>= x10 0) -> (not (<= (+ x10 x46 (- x29)) 0)).
|
||||
Instead the bound on x_10 falls out from a bigger blob of constraints.
|
||||
|
||||
In the second case, the inequality on (<= x19 x13) is obtained from a triangle inequality (<= x19 x9) (<= x9 x13).
|
||||
If x9 becomes basic variable, then it is likely the old solver ends up with a row that implies (<= x19 x13).
|
||||
*/
|
||||
In the second case, the inequality on (<= x19 x13) is obtained from a triangle inequality (<= x19 x9) (<= x9 x13).
|
||||
If x9 becomes basic variable, then it is likely the old solver ends up with a row that implies (<= x19 x13).
|
||||
*/
|
||||
}
|
||||
void test_bound_propagation_one_row() {
|
||||
lar_solver ls;
|
||||
|
@ -3083,11 +3088,134 @@ void test_rationals() {
|
|||
std::cout << T_to_string(r) << std::endl;
|
||||
}
|
||||
|
||||
void test_lp_local(int argn, char**argv) {
|
||||
std::cout << "resize\n";
|
||||
vector<mpq> r;
|
||||
r.resize(1);
|
||||
void get_random_interval(bool& neg_inf, bool& pos_inf, int& x, int &y) {
|
||||
int i = my_random() % 10;
|
||||
if (i == 0) {
|
||||
neg_inf = true;
|
||||
} else {
|
||||
neg_inf = false;
|
||||
x = my_random() % 100;
|
||||
}
|
||||
i = my_random() % 10;
|
||||
if (i == 0) {
|
||||
pos_inf = true;
|
||||
} else {
|
||||
pos_inf = false;
|
||||
if (!neg_inf) {
|
||||
y = x + my_random() % (101 - x);
|
||||
lp_assert(y >= x);
|
||||
}
|
||||
else {
|
||||
y = my_random() % 100;
|
||||
}
|
||||
}
|
||||
lp_assert((neg_inf || (0 <= x && x <= 100)) && (pos_inf || (0 <= y && y <= 100)));
|
||||
}
|
||||
|
||||
void test_integer_domain_intersection(integer_domain<int> & d) {
|
||||
int x, y; bool neg_inf, pos_inf;
|
||||
get_random_interval(neg_inf, pos_inf, x, y);
|
||||
if (neg_inf) {
|
||||
if (!pos_inf) {
|
||||
d.intersect_with_upper_bound(y);
|
||||
}
|
||||
}
|
||||
else if (pos_inf)
|
||||
d.intersect_with_lower_bound(x);
|
||||
else
|
||||
d.intersect_with_interval(x, y);
|
||||
}
|
||||
|
||||
void test_integer_domain_union(integer_domain<int> & d) {
|
||||
int x, y; bool neg_inf, pos_inf;
|
||||
get_random_interval(neg_inf, pos_inf, x, y);
|
||||
if (neg_inf) {
|
||||
if (!pos_inf) {
|
||||
d.unite_with_interval_neg_inf_x(y);
|
||||
}
|
||||
else
|
||||
d.init_to_contain_all();
|
||||
}
|
||||
else if (pos_inf)
|
||||
d.unite_with_interval_x_pos_inf(x);
|
||||
else
|
||||
d.unite_with_interval(x, y);
|
||||
|
||||
lp_assert(d.is_correct());
|
||||
}
|
||||
|
||||
|
||||
void test_integer_domain_randomly(integer_domain<int> & d) {
|
||||
int i = my_random() % 10;
|
||||
if (i == 0)
|
||||
test_integer_domain_intersection(d);
|
||||
else
|
||||
test_integer_domain_union(d);
|
||||
}
|
||||
|
||||
void test_integer_domain() {
|
||||
integer_domain<int> d;
|
||||
vector<integer_domain<int>> stack;
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
test_integer_domain_randomly(d);
|
||||
stack.push_back(d);
|
||||
d.push();
|
||||
if (i > 0 && i%100 == 0) {
|
||||
if (stack.size() == 0) continue;
|
||||
unsigned k = my_random() % stack.size();
|
||||
if (k == 0)
|
||||
k = 1;
|
||||
d.pop(k);
|
||||
d.restore_domain();
|
||||
for (unsigned j = 0; j + 1 < k; j++) {
|
||||
stack.pop_back();
|
||||
}
|
||||
std::cout<<"comparing i = " << i << std::endl;
|
||||
lp_assert(d == *stack.rbegin());
|
||||
stack.pop_back();
|
||||
}
|
||||
//d.print(std::cout);
|
||||
}
|
||||
}
|
||||
|
||||
void test_cut_solver() {
|
||||
cut_solver<int> cs([](unsigned i)
|
||||
{
|
||||
if (i == 0) return std::string("x");
|
||||
if (i == 1) return std::string("y");
|
||||
return std::to_string(i);
|
||||
});
|
||||
vector<std::pair<int, unsigned>> term;
|
||||
unsigned x = 0;
|
||||
unsigned y = 1;
|
||||
term.push_back(std::make_pair(2, x));
|
||||
term.push_back(std::make_pair(-3, y));
|
||||
unsigned ineq_index = cs.add_ineq(term, mpq(3));
|
||||
|
||||
|
||||
cs.print_ineq(ineq_index, std::cout);
|
||||
|
||||
mpq l;
|
||||
auto ineq = cs.m_ineqs[ineq_index];
|
||||
cs.add_lower_bound_for_user_var(x, 1);
|
||||
cs.add_lower_bound_for_user_var(y, 1);
|
||||
bool has_lower = cs.lower(ineq.m_poly, l);
|
||||
if (has_lower) {
|
||||
std::cout << "lower = " << l << std::endl;
|
||||
} else {
|
||||
std::cout << "no lower" << std::endl;
|
||||
}
|
||||
cs.add_upper_bound_for_user_var(y, 1);
|
||||
has_lower = cs.lower(ineq.m_poly, l);
|
||||
if (has_lower) {
|
||||
std::cout << "lower = " << l << std::endl;
|
||||
} else {
|
||||
std::cout << "no lower" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void test_lp_local(int argn, char**argv) {
|
||||
|
||||
// initialize_util_module();
|
||||
// initialize_numerics_module();
|
||||
int ret;
|
||||
|
@ -3102,6 +3230,14 @@ void test_lp_local(int argn, char**argv) {
|
|||
|
||||
args_parser.print();
|
||||
|
||||
if (args_parser.option_is_used("-dji")) {
|
||||
test_integer_domain();
|
||||
return finalize(0);
|
||||
}
|
||||
if (args_parser.option_is_used("-cs")) {
|
||||
test_cut_solver();
|
||||
return finalize(0);
|
||||
}
|
||||
if (args_parser.option_is_used("--test_mpq")) {
|
||||
test_rationals();
|
||||
return finalize(0);
|
||||
|
@ -3112,7 +3248,7 @@ void test_lp_local(int argn, char**argv) {
|
|||
return finalize(0);
|
||||
}
|
||||
|
||||
if (args_parser.option_is_used("--test_mpq_np_plus")) {
|
||||
if (args_parser.option_is_used("--test_mpq_np_plus")) {
|
||||
test_rationals_no_numeric_pairs_plus();
|
||||
return finalize(0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue