Limbo 3.5.4
Loading...
Searching...
No Matches
test_bison.cpp
Go to the documentation of this file.
1
7
8#include <iostream>
9#include <fstream>
10
12
13using std::cout;
14using std::cin;
15using std::endl;
16using std::string;
17
21{
22 public:
24 typedef LpParser::int64_t int64_t;
27 {
28 cout << "constructing LpDataBase" << endl;
29 }
30
34 void add_variable(string const& vname, double l, double r)
35 {
36 cout << l << " <= " << vname << " <= " << r << endl;
37 }
38
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 }
50
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 }
64
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
77void test1(string const& filename)
78{
79 cout << "////////////// test1 ////////////////" << endl;
80 LpDataBase db;
81 LpParser::read(db, filename);
82}
83
85void 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
100int 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}
Driver for Lp parser.
void test2(string const &filename)
test 2: use class wrapper BookshelfParser::Driver
Custom class that inheritates LpParser::LpDataBase with all the required callbacks defined.
LpDataBase()
constructor
LpParser::int64_t int64_t
use int64_t in base type
void add_constraint(string const &cname, LpParser::TermArray const &terms, char compare, double constant)
add constraint that terms compare constant.
void add_variable(string const &vname, double l, double r)
add variable that l <= vname <= r.
void set_integer(string const &vname, bool binary)
set integer variables
void add_objective(bool minimize, LpParser::TermArray const &terms)
add object terms
bool parse_file(const string &filename)
Base class for lp database. Only pure virtual functions are defined. User needs to inheritate this ...
Definition LpDataBase.h:115
std::vector< Term > TermArray
array of terms
Definition LpDataBase.h:105
bool read(LpDataBase &db, const string &lpFile)
API for LpParser. Read LP file and initialize database by calling user-defined callback functions.
int main()
void test1()
test function API