@lp constraints 7 == x1 - 1 * x2 2 * x1 + x3 / 2 <= 7 x2 + -3 * x3 >= 8 3 <= x2 - 2 * x1 <= 8 bounds x1 >= 3 2 <= x2 <= 5 0 <= x3 <= 8 objective min x1 + 2 * x2 - x3
The first part gives the constraints to the lp. The constraints could be equality, lower bound, upper bound or range for an expression or equality, less or more for two expressions.
The second part gives the bounds for the variables. The bounds could be the same as for the single expression so equality, lower bound, upper bound or range.
The third part is the objective function, it should start with min
or max
and then a valid linear expression.
The reader constructs automatically the variable for a name if there is not already a variable with the same name.
The basic way to read an LP problem is made by the next code:
Of course instead of LemonReader
you can give a GraphReader
to the LpReader constructor. Also useful that you can mix lp problems and graphs in the same file. #include <lemon/lp_utils.h>
Public Member Functions | |
LpReader (LemonReader &_reader, LpSolverBase &_lp, const std::string &_name=std::string()) | |
Constructor. | |
virtual | ~LpReader () |
Destructor. | |
Protected Member Functions | |
virtual bool | header (const std::string &line) |
Gives back true when the SectionReader can process the section with the given header line. | |
virtual void | read (std::istream &is) |
Reader function of the section. |
LpReader | ( | LemonReader & | _reader, | |
LpSolverBase & | _lp, | |||
const std::string & | _name = std::string() | |||
) | [inline] |
Constructor for LpReader. It creates the LpReader and attachs it into the given LemonReader. The lp reader will add variables, constraints and objective function to the given lp solver.
virtual bool header | ( | const std::string & | line | ) | [inline, protected, virtual] |
It gives back true when the header line starts with @lp
, and the header line's name and the nodeset's name are the same.
Implements SectionReader.
virtual void read | ( | std::istream & | is | ) | [inline, protected, virtual] |
It reads the content of the section.
Implements SectionReader.