Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_bison.cpp
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <fstream>
10 
12 
13 using std::cout;
14 using std::cin;
15 using std::endl;
16 using std::string;
17 
21 {
22  public:
24  typedef LpParser::int64_t int64_t;
27  {
28  cout << "constructing LpDataBase" << endl;
29  }
34  void add_variable(string const& vname, double l, double r)
35  {
36  cout << l << " <= " << vname << " <= " << r << endl;
37  }
43  void add_constraint(string const& cname, LpParser::TermArray const& terms, char compare, double constant)
44  {
45  cout << cname << ": ";
46  for (LpParser::TermArray::const_iterator it = terms.begin(); it != terms.end(); ++it)
47  cout << " + " << it->coef << " " << it->var;
48  cout << " " << compare << " " << constant << endl;
49  }
53  void add_objective(bool minimize, LpParser::TermArray const& terms)
54  {
55  if (minimize)
56  cout << "Minimize\n";
57  else
58  cout << "Maximize\n";
59  for (LpParser::TermArray::const_iterator it = terms.begin(); it != terms.end(); ++it)
60  cout << " + " << it->coef << " " << it->var;
61  cout << endl;
62  cout << "Subject To\n";
63  }
67  void set_integer(string const& vname, bool binary)
68  {
69  if (binary)
70  cout << vname << ": BINARY\n";
71  else
72  cout << vname << ": INTEGER\n";
73  }
74 };
75 
77 void test1(string const& filename)
78 {
79  cout << "////////////// test1 ////////////////" << endl;
80  LpDataBase db;
81  LpParser::read(db, filename);
82 }
83 
85 void test2(string const& filename)
86 {
87  cout << "////////////// test2 ////////////////" << endl;
88  LpDataBase db;
89  LpParser::Driver driver (db);
90  //driver.trace_scanning = true;
91  //driver.trace_parsing = true;
92 
93  driver.parse_file(filename);
94 }
95 
100 int main(int argc, char** argv)
101 {
102  if (argc > 1)
103  {
104  test1(argv[1]);
105  test2(argv[1]);
106  }
107  else
108  cout << "at least 1 argument is required" << endl;
109 
110  return 0;
111 }
Base class for lp database. Only pure virtual functions are defined. User needs to inheritate this cl...
Definition: LpDataBase.h:114
Custom class that inheritates LpParser::LpDataBase with all the required callbacks defined...
Definition: test_bison.cpp:20
bool parse_file(const string &filename)
std::vector< Term > TermArray
array of terms
Definition: LpDataBase.h:105
LpDataBase()
constructor
Definition: test_bison.cpp:26
LpParser::int64_t int64_t
use int64_t in base type
Definition: test_bison.cpp:24
void test2(string const &filename)
test 2: use class wrapper BookshelfParser::Driver
Definition: test_bison.cpp:104
void set_integer(string const &vname, bool binary)
set integer variables
Definition: test_bison.cpp:67
void add_objective(bool minimize, LpParser::TermArray const &terms)
add object terms
Definition: test_bison.cpp:53
void test1(string const &filename)
test 1: use function wrapper BookshelfParser::read
Definition: test_bison.cpp:96
void add_constraint(string const &cname, LpParser::TermArray const &terms, char compare, double constant)
add constraint that terms compare constant.
Definition: test_bison.cpp:43
Driver for Lp parser.
bool read(LpDataBase &db, const string &lpFile)
API for LpParser. Read LP file and initialize database by calling user-defined callback functions...
int main(int argc, char **argv)
main function
Definition: test_bison.cpp:119
void add_variable(string const &vname, double l, double r)
add variable that l <= vname <= r.
Definition: test_bison.cpp:34