Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Limbo.Parsers.LpParser

Table of Contents

Introduction

LP format is among the various file format to describe optimization problems. The parser can read a special case of linear programming problem in the LP format compatible to Gurobi, which contains only differential constaints. The special linear programming problem can be solved by dual min-cost flow algorithm in the Limbo.Solvers package. Here is a sample file.

Minimize
b_5829890_x2
+ b_5880854_x2
Subject To
- 2 b_5829890_x2 + 2 b_5829890_x1 <= -64
b_5880854_x2 - b_5880854_x1 >= 32
Bounds
b_5829890_x1 >= 10
10 >= b_5880854_x1
1014 <= b_5829890_x2 <= 1917
1014 <= b_5880854_x2 <= 1917
Generals
b_5829890_x2 b_5880854_x2
Binary
b_5829890_x1
End

Examples

Flex/Bison Parser

See documented version: test/parsers/lp/test_bison.cpp

#include <iostream>
#include <fstream>
using std::cout;
using std::cin;
using std::endl;
using std::string;
{
public:
typedef LpParser::int64_t int64_t;
{
cout << "constructing LpDataBase" << endl;
}
void add_variable(string const& vname, double l, double r)
{
cout << l << " <= " << vname << " <= " << r << endl;
}
void add_constraint(string const& cname, LpParser::TermArray const& terms, char compare, double constant)
{
cout << cname << ": ";
for (LpParser::TermArray::const_iterator it = terms.begin(); it != terms.end(); ++it)
cout << " + " << it->coef << " " << it->var;
cout << " " << compare << " " << constant << endl;
}
void add_objective(bool minimize, LpParser::TermArray const& terms)
{
if (minimize)
cout << "Minimize\n";
else
cout << "Maximize\n";
for (LpParser::TermArray::const_iterator it = terms.begin(); it != terms.end(); ++it)
cout << " + " << it->coef << " " << it->var;
cout << endl;
cout << "Subject To\n";
}
void set_integer(string const& vname, bool binary)
{
if (binary)
cout << vname << ": BINARY\n";
else
cout << vname << ": INTEGER\n";
}
};
void test1(string const& filename)
{
cout << "////////////// test1 ////////////////" << endl;
LpParser::read(db, filename);
}
void test2(string const& filename)
{
cout << "////////////// test2 ////////////////" << endl;
LpParser::Driver driver (db);
//driver.trace_scanning = true;
//driver.trace_parsing = true;
driver.parse_file(filename);
}
int main(int argc, char** argv)
{
if (argc > 1)
{
test1(argv[1]);
test2(argv[1]);
}
else
cout << "at least 1 argument is required" << endl;
return 0;
}

Compiling and running commands (assuming LIMBO_DIR is exported as the environment variable to the path where limbo library is installed)

1 g++ -o test_bison test_bison.cpp -I $LIMBO_DIR/include -L $LIMBO_DIR/lib -llpparser
2 ./test_bison benchmarks/problem.lp

All Examples

References