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:
{
cout << "constructing LpDataBase" << endl;
}
{
cout << l << " <= " << vname << " <= " << r << endl;
}
{
cout << cname << ": ";
for (LpParser::TermArray::const_iterator it = terms.begin(); it != terms.end(); ++it)
cout << " + " << it->coef << " " << it->var;
cout << " " << compare << " " << constant << endl;
}
{
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";
}
{
if (binary)
cout << vname << ": BINARY\n";
else
cout << vname << ": INTEGER\n";
}
};
void test1(
string const& filename)
{
cout << "////////////// test1 ////////////////" << endl;
}
void test2(
string const& filename)
{
cout << "////////////// test2 ////////////////" << endl;
driver.parse_file(filename);
}
int main(
int argc,
char** argv)
{
if (argc > 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