3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

add cube mode

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-09-24 10:53:57 -07:00
commit ae9a6664d4
144 changed files with 6012 additions and 3174 deletions

157
src/test/argument_parser.h Normal file
View file

@ -0,0 +1,157 @@
/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
<name>
Abstract:
<abstract>
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#include <unordered_map>
#include <vector>
#include <string>
#include <set>
#include <iostream>
namespace lp {
class argument_parser {
std::unordered_map<std::string, std::string> m_options;
std::unordered_map<std::string, std::string> m_options_with_after_string;
std::set<std::string> m_used_options;
std::unordered_map<std::string, std::string> m_used_options_with_after_string;
std::vector<std::string> m_free_args;
std::vector<std::string> m_args;
public:
std::string m_error_message;
argument_parser(unsigned argn, char * const* args) {
for (unsigned i = 0; i < argn; i++) {
m_args.push_back(std::string(args[i]));
}
}
void add_option(std::string s) {
add_option_with_help_string(s, "");
}
void add_option_with_help_string(std::string s, std::string help_string) {
m_options[s]=help_string;
}
void add_option_with_after_string(std::string s) {
add_option_with_after_string_with_help(s, "");
}
void add_option_with_after_string_with_help(std::string s, std::string help_string) {
m_options_with_after_string[s]=help_string;
}
bool parse() {
bool status_is_ok = true;
for (unsigned i = 0; i < m_args.size(); i++) {
std::string ar = m_args[i];
if (m_options.find(ar) != m_options.end() )
m_used_options.insert(ar);
else if (m_options_with_after_string.find(ar) != m_options_with_after_string.end()) {
if (i == m_args.size() - 1) {
m_error_message = "Argument is missing after "+ar;
return false;
}
i++;
m_used_options_with_after_string[ar] = m_args[i];
} else {
if (starts_with(ar, "-") || starts_with(ar, "//"))
status_is_ok = false;
m_free_args.push_back(ar);
}
}
return status_is_ok;
}
bool contains(std::unordered_map<std::string, std::string> & m, std::string s) {
return m.find(s) != m.end();
}
bool contains(std::set<std::string> & m, std::string s) {
return m.find(s) != m.end();
}
bool option_is_used(std::string option) {
return contains(m_used_options, option) || contains(m_used_options_with_after_string, option);
}
std::string get_option_value(std::string option) {
auto t = m_used_options_with_after_string.find(option);
if (t != m_used_options_with_after_string.end()){
return t->second;
}
return std::string();
}
bool starts_with(std::string s, char const * prefix) {
return starts_with(s, std::string(prefix));
}
bool starts_with(std::string s, std::string prefix) {
return s.substr(0, prefix.size()) == prefix;
}
std::string usage_string() {
std::string ret = "";
std::vector<std::string> unknown_options;
for (auto t : m_free_args) {
if (starts_with(t, "-") || starts_with(t, "\\")) {
unknown_options.push_back(t);
}
}
if (unknown_options.size()) {
ret = "Unknown options:";
}
for (auto unknownOption : unknown_options) {
ret += unknownOption;
ret += ",";
}
ret += "\n";
ret += "Usage:\n";
for (auto allowed_option : m_options)
ret += allowed_option.first + " " + (allowed_option.second.size() == 0 ? std::string("") : std::string("/") + allowed_option.second) + std::string("\n");
for (auto s : m_options_with_after_string) {
ret += s.first + " " + (s.second.size() == 0? " \"option value\"":("\""+ s.second+"\"")) + "\n";
}
return ret;
}
void print() {
if (m_used_options.size() == 0 && m_used_options_with_after_string.size() == 0 && m_free_args.size() == 0) {
std::cout << "no options are given" << std::endl;
return;
}
std::cout << "options are: " << std::endl;
for (std::string s : m_used_options) {
std::cout << s << std::endl;
}
for (auto & t : m_used_options_with_after_string) {
std::cout << t.first << " " << t.second << std::endl;
}
if (m_free_args.size() > 0) {
std::cout << "free arguments are: " << std::endl;
for (auto & t : m_free_args) {
std::cout << t << " " << std::endl;
}
}
}
};
}

View file

@ -27,36 +27,36 @@ static void tst1() {
unsigned n = rand()%10000;
for (unsigned i = 0; i < n; i++) {
int op = rand()%6;
if (op <= 1) {
bool val = (rand()%2) != 0;
v1.push_back(val);
v2.push_back(val);
ENSURE(v1.size() == v2.size());
}
else if (op <= 3) {
ENSURE(v1.size() == v2.size());
if (v1.size() > 0) {
bool val = (rand()%2) != 0;
unsigned idx = rand()%v1.size();
ENSURE(v1.get(idx) == v2[idx]);
v1.set(idx, val);
v2[idx] = val;
ENSURE(v1.get(idx) == v2[idx]);
}
}
else if (op <= 4) {
ENSURE(v1.size() == v2.size());
if (v1.size() > 0) {
unsigned idx = rand()%v1.size();
VERIFY(v1.get(idx) == v2[idx]);
}
}
else if (op <= 5) {
ENSURE(v1.size() == v2.size());
for (unsigned j = 0; j < v1.size(); j++) {
ENSURE(v1.get(j) == v2[j]);
}
}
if (op <= 1) {
bool val = (rand()%2) != 0;
v1.push_back(val);
v2.push_back(val);
ENSURE(v1.size() == v2.size());
}
else if (op <= 3) {
ENSURE(v1.size() == v2.size());
if (v1.size() > 0) {
bool val = (rand()%2) != 0;
unsigned idx = rand()%v1.size();
ENSURE(v1.get(idx) == v2[idx]);
v1.set(idx, val);
v2[idx] = val;
ENSURE(v1.get(idx) == v2[idx]);
}
}
else if (op <= 4) {
ENSURE(v1.size() == v2.size());
if (v1.size() > 0) {
unsigned idx = rand()%v1.size();
VERIFY(v1.get(idx) == v2[idx]);
}
}
else if (op <= 5) {
ENSURE(v1.size() == v2.size());
for (unsigned j = 0; j < v1.size(); j++) {
ENSURE(v1.get(j) == v2[j]);
}
}
}
}
@ -309,6 +309,6 @@ void tst_bit_vector() {
tst2();
for (unsigned i = 0; i < 20; i++) {
std::cerr << i << std::endl;
tst1();
tst1();
}
}

View file

@ -200,6 +200,20 @@ void tst_ddnf(char ** argv, int argc, int& i) {
dealloc(ddnf);
}
void tst_ddnf1() {
enable_trace("ddnf");
unsigned W = 2;
datalog::ddnf_core ddnf(W);
tbv_manager& tbvm = ddnf.get_tbv_manager();
tbv* tXX = tbvm.allocate("xx");
tbv* t1X = tbvm.allocate("1x");
tbv* tX1 = tbvm.allocate("x1");
tbv* t11 = tbvm.allocate("11");
ddnf.insert(*tXX);
ddnf.insert(*t11);
ddnf.insert(*tX1);
ddnf.insert(*t1X);
ddnf.display(std::cout);
}

View file

@ -33,7 +33,7 @@ template class dl_graph<diff_logic_ext>;
typedef dl_graph<diff_logic_ext> dlg;
struct tst_dl_functor {
smt::literal_vector m_literals;
smt::literal_vector m_literals;
void operator()(smt::literal l) {
m_literals.push_back(l);
}

View file

@ -98,8 +98,8 @@ void tst_expr_rand(char** argv, int argc, int& i) {
i += 1;
if (i + 1 < argc && 0 == strncmp(argv[i+1],"/rs:",3)) {
rand_seed = atol(argv[i+1]+4);
std::cout << "random seed:" << rand_seed << "\n";
i += 1;
std::cout << "random seed:" << rand_seed << "\n";
i += 1;
}
if (i + 1 < argc && 0 == strcmp(argv[i+1],"/arith")) {

3257
src/test/lp.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -16,20 +16,20 @@
// and print "PASS" to indicate success.
//
#define TST(MODULE) { \
std::string s("test "); \
s += #MODULE; \
void tst_##MODULE(); \
#define TST(MODULE) { \
std::string s("test "); \
s += #MODULE; \
void tst_##MODULE(); \
if (do_display_usage) \
std::cout << #MODULE << "\n"; \
for (int i = 0; i < argc; i++) \
if (test_all || strcmp(argv[i], #MODULE) == 0) { \
for (int i = 0; i < argc; i++) \
if (test_all || strcmp(argv[i], #MODULE) == 0) { \
enable_trace(#MODULE); \
enable_debug(#MODULE); \
timeit timeit(true, s.c_str()); \
tst_##MODULE(); \
enable_debug(#MODULE); \
timeit timeit(true, s.c_str()); \
tst_##MODULE(); \
std::cout << "PASS" << std::endl; \
} \
} \
}
#define TST_ARGV(MODULE) { \
@ -39,13 +39,13 @@
if (do_display_usage) \
std::cout << #MODULE << "\n"; \
for (int i = 0; i < argc; i++) \
if (strcmp(argv[i], #MODULE) == 0) { \
if (strcmp(argv[i], #MODULE) == 0) { \
enable_trace(#MODULE); \
enable_debug(#MODULE); \
timeit timeit(true, s.c_str()); \
tst_##MODULE(argv, argc, i); \
enable_debug(#MODULE); \
timeit timeit(true, s.c_str()); \
tst_##MODULE(argv, argc, i); \
std::cout << "PASS" << std::endl; \
} \
} \
}
void error(const char * msg) {
@ -78,48 +78,48 @@ void parse_cmd_line_args(int argc, char ** argv, bool& do_display_usage, bool& t
while (i < argc) {
char * arg = argv[i];
char * eq_pos = 0;
if (arg[0] == '-' || arg[0] == '/') {
char * opt_name = arg + 1;
char * opt_arg = 0;
char * colon = strchr(arg, ':');
if (colon) {
opt_arg = colon + 1;
*colon = 0;
}
if (strcmp(opt_name, "h") == 0 ||
if (arg[0] == '-' || arg[0] == '/') {
char * opt_name = arg + 1;
char * opt_arg = 0;
char * colon = strchr(arg, ':');
if (colon) {
opt_arg = colon + 1;
*colon = 0;
}
if (strcmp(opt_name, "h") == 0 ||
strcmp(opt_name, "?") == 0) {
display_usage();
display_usage();
do_display_usage = true;
return;
}
else if (strcmp(opt_name, "v") == 0) {
if (!opt_arg)
error("option argument (/v:level) is missing.");
long lvl = strtol(opt_arg, 0, 10);
set_verbosity_level(lvl);
}
else if (strcmp(opt_name, "w") == 0) {
}
else if (strcmp(opt_name, "v") == 0) {
if (!opt_arg)
error("option argument (/v:level) is missing.");
long lvl = strtol(opt_arg, 0, 10);
set_verbosity_level(lvl);
}
else if (strcmp(opt_name, "w") == 0) {
enable_warning_messages(true);
}
else if (strcmp(opt_name, "a") == 0) {
}
else if (strcmp(opt_name, "a") == 0) {
test_all = true;
}
}
#ifdef _TRACE
else if (strcmp(opt_name, "tr") == 0) {
if (!opt_arg)
error("option argument (/tr:tag) is missing.");
enable_trace(opt_arg);
}
else if (strcmp(opt_name, "tr") == 0) {
if (!opt_arg)
error("option argument (/tr:tag) is missing.");
enable_trace(opt_arg);
}
#endif
#ifdef Z3DEBUG
else if (strcmp(opt_name, "dbg") == 0) {
if (!opt_arg)
error("option argument (/dbg:tag) is missing.");
enable_debug(opt_arg);
}
else if (strcmp(opt_name, "dbg") == 0) {
if (!opt_arg)
error("option argument (/dbg:tag) is missing.");
enable_debug(opt_arg);
}
#endif
}
}
else if (arg[0] != '"' && (eq_pos = strchr(arg, '='))) {
char * key = arg;
*eq_pos = 0;
@ -131,7 +131,7 @@ void parse_cmd_line_args(int argc, char ** argv, bool& do_display_usage, bool& t
std::cerr << ex.msg() << "\n";
}
}
i++;
i++;
}
}
@ -238,6 +238,7 @@ int main(int argc, char ** argv) {
TST(sat_user_scope);
TST(pdr);
TST_ARGV(ddnf);
TST(ddnf1);
TST(model_evaluator);
TST(get_consequences);
TST(pb2bv);

View file

@ -54,7 +54,7 @@ static void add_random_ineq(opt::model_based_opt& mbo,
continue;
}
unsigned sign = r(2);
coeff = sign == 0 ? coeff : -coeff;
coeff = sign == 0 ? coeff : -coeff;
vars.push_back(var(x, rational(coeff)));
value += coeff*values[x];
}

View file

@ -36,11 +36,11 @@ struct OptFoo {
int m_y;
OptFoo(int x, int y):m_x(x), m_y(y) {
TRACE("optional", tout << "OptFoo created: " << m_x << " : " << m_y << "\n";);
TRACE("optional", tout << "OptFoo created: " << m_x << " : " << m_y << "\n";);
}
~OptFoo() {
TRACE("optional", tout << "OptFoo deleted: " << m_x << " : " << m_y << "\n";);
TRACE("optional", tout << "OptFoo deleted: " << m_x << " : " << m_y << "\n";);
}
};

409
src/test/smt_reader.h Normal file
View file

@ -0,0 +1,409 @@
/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
<name>
Abstract:
<abstract>
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#pragma once
// reads an MPS file reperesenting a Mixed Integer Program
#include <string>
#include <vector>
#include <unordered_map>
#include "util/lp/lp_primal_simplex.h"
#include "util/lp/lp_dual_simplex.h"
#include "util/lp/lar_solver.h"
#include <iostream>
#include <fstream>
#include <functional>
#include <algorithm>
#include "util/lp/mps_reader.h"
#include "util/lp/ul_pair.h"
#include "util/lp/lar_constraints.h"
#include <sstream>
#include <cstdlib>
namespace lp {
template<typename T>
T from_string(const std::string& str) {
std::istringstream ss(str);
T ret;
ss >> ret;
return ret;
}
class smt_reader {
public:
struct lisp_elem {
std::string m_head;
std::vector<lisp_elem> m_elems;
void print() {
if (m_elems.size()) {
std::cout << '(';
std::cout << m_head << ' ';
for (auto & el : m_elems)
el.print();
std::cout << ')';
} else {
std::cout << " " << m_head;
}
}
unsigned size() const { return static_cast<unsigned>(m_elems.size()); }
bool is_simple() const { return size() == 0; }
};
struct formula_constraint {
lconstraint_kind m_kind;
std::vector<std::pair<mpq, std::string>> m_coeffs;
mpq m_right_side;
void add_pair(mpq c, std::string name) {
m_coeffs.push_back(make_pair(c, name));
}
formula_constraint() : m_right_side(numeric_traits<mpq>::zero()) {}
};
lisp_elem m_formula_lisp_elem;
std::unordered_map<std::string, unsigned> m_name_to_var_index;
std::vector<formula_constraint> m_constraints;
bool m_is_OK;
unsigned m_line_number;
std::string m_file_name;
std::ifstream m_file_stream;
std::string m_line;
smt_reader(std::string file_name):
m_is_OK(true),
m_line_number(0),
m_file_name(file_name),
m_file_stream(file_name) {
}
void set_error() {
std::cout << "setting error" << std::endl;
m_is_OK = false;
}
bool is_ok() {
return m_is_OK;
}
bool prefix(const char * pr) {
return m_line.find(pr) == 0;
}
int first_separator() {
unsigned blank_pos = static_cast<unsigned>(m_line.find(' '));
unsigned br_pos = static_cast<unsigned>(m_line.find('('));
unsigned reverse_br_pos = static_cast<unsigned>(m_line.find(')'));
return std::min(blank_pos, std::min(br_pos, reverse_br_pos));
}
void fill_lisp_elem(lisp_elem & lm) {
if (m_line[0] == '(')
fill_nested_elem(lm);
else
fill_simple_elem(lm);
}
void fill_simple_elem(lisp_elem & lm) {
int separator = first_separator();
SASSERT(-1 != separator && separator != 0);
lm.m_head = m_line.substr(0, separator);
m_line = m_line.substr(separator);
}
void fill_nested_elem(lisp_elem & lm) {
SASSERT(m_line[0] == '(');
m_line = m_line.substr(1);
int separator = first_separator();
lm.m_head = m_line.substr(0, separator);
m_line = m_line.substr(lm.m_head.size());
eat_blanks();
while (m_line.size()) {
if (m_line[0] == '(') {
lisp_elem el;
fill_nested_elem(el);
lm.m_elems.push_back(el);
} else {
if (m_line[0] == ')') {
m_line = m_line.substr(1);
break;
}
lisp_elem el;
fill_simple_elem(el);
lm.m_elems.push_back(el);
}
eat_blanks();
}
}
void eat_blanks() {
while (m_line.size()) {
if (m_line[0] == ' ')
m_line = m_line.substr(1);
else
break;
}
}
void fill_formula_elem() {
fill_lisp_elem(m_formula_lisp_elem);
}
void parse_line() {
if (m_line.find(":formula") == 0) {
int first_br = static_cast<int>(m_line.find('('));
if (first_br == -1) {
std::cout << "empty formula" << std::endl;
return;
}
m_line = m_line.substr(first_br);
fill_formula_elem();
}
}
void set_constraint_kind(formula_constraint & c, lisp_elem & el) {
if (el.m_head == "=") {
c.m_kind = EQ;
} else if (el.m_head == ">=") {
c.m_kind = GE;
} else if (el.m_head == "<=") {
c.m_kind = LE;
} else if (el.m_head == ">") {
c.m_kind = GT;
} else if (el.m_head == "<") {
c.m_kind = LT;
} else {
std::cout << "kind " << el.m_head << " is not supported " << std::endl;
set_error();
}
}
void adjust_rigth_side(formula_constraint & /* c*/, lisp_elem & /*el*/) {
// SASSERT(el.m_head == "0"); // do nothing for the time being
}
void set_constraint_coeffs(formula_constraint & c, lisp_elem & el) {
SASSERT(el.m_elems.size() == 2);
set_constraint_coeffs_on_coeff_element(c, el.m_elems[0]);
adjust_rigth_side(c, el.m_elems[1]);
}
bool is_integer(std::string & s) {
if (s.size() == 0) return false;
return atoi(s.c_str()) != 0 || isdigit(s.c_str()[0]);
}
void add_complex_sum_elem(formula_constraint & c, lisp_elem & el) {
if (el.m_head == "*") {
add_mult_elem(c, el.m_elems);
} else if (el.m_head == "~") {
lisp_elem & minel = el.m_elems[0];
SASSERT(minel.is_simple());
c.m_right_side += mpq(str_to_int(minel.m_head));
} else {
std::cout << "unexpected input " << el.m_head << std::endl;
set_error();
return;
}
}
std::string get_name(lisp_elem & name) {
SASSERT(name.is_simple());
SASSERT(!is_integer(name.m_head));
return name.m_head;
}
void add_mult_elem(formula_constraint & c, std::vector<lisp_elem> & els) {
SASSERT(els.size() == 2);
mpq coeff = get_coeff(els[0]);
std::string col_name = get_name(els[1]);
c.add_pair(coeff, col_name);
}
mpq get_coeff(lisp_elem & le) {
if (le.is_simple()) {
return mpq(str_to_int(le.m_head));
} else {
SASSERT(le.m_head == "~");
SASSERT(le.size() == 1);
lisp_elem & el = le.m_elems[0];
SASSERT(el.is_simple());
return -mpq(str_to_int(el.m_head));
}
}
int str_to_int(std::string & s) {
SASSERT(is_integer(s));
return atoi(s.c_str());
}
void add_sum_elem(formula_constraint & c, lisp_elem & el) {
if (el.size()) {
add_complex_sum_elem(c, el);
} else {
SASSERT(is_integer(el.m_head));
int v = atoi(el.m_head.c_str());
mpq vr(v);
c.m_right_side -= vr;
}
}
void add_sum(formula_constraint & c, std::vector<lisp_elem> & sum_els) {
for (auto & el : sum_els)
add_sum_elem(c, el);
}
void set_constraint_coeffs_on_coeff_element(formula_constraint & c, lisp_elem & el) {
if (el.m_head == "*") {
add_mult_elem(c, el.m_elems);
} else if (el.m_head == "+") {
add_sum(c, el.m_elems);
} else {
SASSERT(false); // unexpected input
}
}
void create_constraint(lisp_elem & el) {
formula_constraint c;
set_constraint_kind(c, el);
set_constraint_coeffs(c, el);
m_constraints.push_back(c);
}
void fill_constraints() {
if (m_formula_lisp_elem.m_head != "and") {
std::cout << "unexpected top element " << m_formula_lisp_elem.m_head << std::endl;
set_error();
return;
}
for (auto & el : m_formula_lisp_elem.m_elems)
create_constraint(el);
}
void read() {
if (!m_file_stream.is_open()){
std::cout << "cannot open file " << m_file_name << std::endl;
set_error();
return;
}
while (m_is_OK && getline(m_file_stream, m_line)) {
parse_line();
m_line_number++;
}
m_file_stream.close();
fill_constraints();
}
/*
void fill_lar_solver_on_row(row * row, lar_solver *solver) {
if (row->m_name != m_cost_row_name) {
lar_constraint c(get_lar_relation_from_row(row->m_type), row->m_right_side);
for (auto s : row->m_row_columns) {
var_index i = solver->add_var(s.first);
c.add_variable_to_constraint(i, s.second);
}
solver->add_constraint(&c);
} else {
// ignore the cost row
}
}
void fill_lar_solver_on_rows(lar_solver * solver) {
for (auto row_it : m_rows) {
fill_lar_solver_on_row(row_it.second, solver);
}
}
void create_low_constraint_for_var(column* col, bound * b, lar_solver *solver) {
lar_constraint c(GE, b->m_low);
var_index i = solver->add_var(col->m_name);
c.add_variable_to_constraint(i, numeric_traits<T>::one());
solver->add_constraint(&c);
}
void create_upper_constraint_for_var(column* col, bound * b, lar_solver *solver) {
lar_constraint c(LE, b->m_upper);
var_index i = solver->add_var(col->m_name);
c.add_variable_to_constraint(i, numeric_traits<T>::one());
solver->add_constraint(&c);
}
void create_equality_contraint_for_var(column* col, bound * b, lar_solver *solver) {
lar_constraint c(EQ, b->m_fixed_value);
var_index i = solver->add_var(col->m_name);
c.add_variable_to_constraint(i, numeric_traits<T>::one());
solver->add_constraint(&c);
}
void fill_lar_solver_on_columns(lar_solver * solver) {
for (auto s : m_columns) {
mps_reader::column * col = s.second;
solver->add_var(col->m_name);
auto b = col->m_bound;
if (b == nullptr) return;
if (b->m_free) continue;
if (b->m_low_is_set) {
create_low_constraint_for_var(col, b, solver);
}
if (b->m_upper_is_set) {
create_upper_constraint_for_var(col, b, solver);
}
if (b->m_value_is_fixed) {
create_equality_contraint_for_var(col, b, solver);
}
}
}
*/
unsigned register_name(std::string s) {
auto it = m_name_to_var_index.find(s);
if (it!= m_name_to_var_index.end())
return it->second;
unsigned ret = static_cast<unsigned>(m_name_to_var_index.size());
m_name_to_var_index[s] = ret;
return ret;
}
void add_constraint_to_solver(lar_solver * solver, formula_constraint & fc) {
vector<std::pair<mpq, var_index>> ls;
for (auto & it : fc.m_coeffs) {
ls.push_back(std::make_pair(it.first, solver->add_var(register_name(it.second))));
}
solver->add_constraint(ls, fc.m_kind, fc.m_right_side);
}
void fill_lar_solver(lar_solver * solver) {
for (formula_constraint & fc : m_constraints)
add_constraint_to_solver(solver, fc);
}
lar_solver * create_lar_solver() {
lar_solver * ls = new lar_solver();
fill_lar_solver(ls);
return ls;
}
};
}

View file

@ -15,8 +15,6 @@ Copyright (c) 2015 Microsoft Corporation
#include "smt/smt_kernel.h"
#include "smt/params/smt_params.h"
struct ast_ext {
ast_manager& m;
ast_ext(ast_manager& m):m(m) {}

View file

@ -0,0 +1,87 @@
/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
<name>
Abstract:
<abstract>
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#pragma once
// reads a text file
#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
#include <fstream>
#include "util/lp/lp_utils.h"
#include "util/lp/lp_solver.h"
namespace lp {
template <typename T>
struct test_result {
lp_status m_status;
T m_cost;
std::unordered_map<std::string, T> column_values;
};
template <typename T>
class test_file_reader {
struct raw_blob {
std::vector<std::string> m_unparsed_strings;
std::vector<raw_blob> m_blobs;
};
struct test_file_blob {
std::string m_name;
std::string m_content;
std::unordered_map<std::string, std::string> m_table;
std::unordered_map<std::string, test_file_blob> m_blobs;
test_result<T> * get_test_result() {
test_result<T> * tr = new test_result<T>();
throw "not impl";
return tr;
}
};
std::ifstream m_file_stream;
public:
// constructor
test_file_reader(std::string file_name) : m_file_stream(file_name) {
if (!m_file_stream.is_open()) {
std::cout << "cannot open file " << "\'" << file_name << "\'" << std::endl;
}
}
raw_blob scan_to_row_blob() {
}
test_file_blob scan_row_blob_to_test_file_blob(raw_blob /* rblob */) {
}
test_result<T> * get_test_result() {
if (!m_file_stream.is_open()) {
return nullptr;
}
raw_blob rblob = scan_to_row_blob();
test_file_blob tblob = scan_row_blob_to_test_file_blob(rblob);
return tblob.get_test_result();
}
};
}