Limbo
3.5.4
Toggle main menu visibility
Loading...
Searching...
No Matches
test
parsers
lp
test_bison.cpp
Go to the documentation of this file.
1
7
8
#include <iostream>
9
#include <fstream>
10
11
#include <
limbo/parsers/lp/bison/LpDriver.h
>
12
13
using
std::cout;
14
using
std::cin;
15
using
std::endl;
16
using
std::string;
17
20
class
LpDataBase
:
public
LpParser::LpDataBase
21
{
22
public
:
24
typedef
LpParser::int64_t
int64_t
;
26
LpDataBase
()
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
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
}
LpDriver.h
Driver for Lp parser.
test2
void test2(string const &filename)
test 2: use class wrapper BookshelfParser::Driver
Definition
test_bison.cpp:149
LpDataBase
Custom class that inheritates LpParser::LpDataBase with all the required callbacks defined.
Definition
test_bison.cpp:21
LpDataBase::LpDataBase
LpDataBase()
constructor
Definition
test_bison.cpp:26
LpDataBase::int64_t
LpParser::int64_t int64_t
use int64_t in base type
Definition
test_bison.cpp:24
LpDataBase::add_constraint
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
LpDataBase::add_variable
void add_variable(string const &vname, double l, double r)
add variable that l <= vname <= r.
Definition
test_bison.cpp:34
LpDataBase::set_integer
void set_integer(string const &vname, bool binary)
set integer variables
Definition
test_bison.cpp:67
LpDataBase::add_objective
void add_objective(bool minimize, LpParser::TermArray const &terms)
add object terms
Definition
test_bison.cpp:53
LpParser::Driver
Definition
LpDriver.h:36
LpParser::Driver::parse_file
bool parse_file(const string &filename)
LpParser::LpDataBase
Base class for lp database. Only pure virtual functions are defined. User needs to inheritate this ...
Definition
LpDataBase.h:115
LpParser::TermArray
std::vector< Term > TermArray
array of terms
Definition
LpDataBase.h:105
LpParser::read
bool read(LpDataBase &db, const string &lpFile)
API for LpParser. Read LP file and initialize database by calling user-defined callback functions.
main
int main()
Definition
test_ChromaticNumber.cpp:78
test1
void test1()
test function API
Definition
test_solvers.cpp:11
Generated on
for Limbo by
1.17.0