Math::LP is an OO interface to linear programs.
SYNOPSIS
use Math::LP qw(:types); # imports optimization types
use Math::LP::Constraint qw(:types); # imports constraint types
# make a new LP
$lp = new Math::LP;
# make the variables for the LP
$x1 = new Math::LP::Variable(name => 'x1');
$x2 = new Math::LP::Variable(name => 'x2');
# maximize the objective function to x1 + 2 x2
$obj_fn = make Math::LP::LinearCombination($x1,1.0,$x2,2.0);
$lp->maximize_for($obj_fn);
# add the constraint x1 + x2 make Math::LP::LinearCombination($x1,1.0,$x2,1.0),
rhs => 2.0,
type => $LE,
);
$lp->add_constraint($constr);
# solve the LP and print the results
$lp->solve() or die "Could not solve the LP";
print "Optimum = ", $obj_fn->{value}, "n";
print "x1 = ", $x1->{value}, "n";
print "x2 = ", $x1->{value}, "n";
print "slack = ", $constr->{slack}, "n";
The Math::LP package provides an object oriented interface to defining and solving mixed linear/integer programs. It uses the lp_solve library as the underlying solver. Please note that this is not a two way relation. An LP is defined using Math::LP, converted to an lp_solve data structure, and solved with lp_solve functions. It is not possible to grab an lp_solve structure somehow and convert it to a Math::LP object for manipulation and inspection. If you want to do that kind of stuff in Perl, use the Math::LP::Solve package instead.
That being said, the logical way of constructing an LP consists of:
1. Construct Math::LP::Variable objects, in the meanwhile marking integer variables
2. Construct Math::LP::LinearCombination objects with the variables and use them as the objective function and constraints
3. Solve the LP
4. Fetch the variable values from the Math::LP::Variable objects, the slacks and dual values from the Math::LP::Constraint objects. and the row values (including the optimum) from the corresponding Math::LP::LinearCombination.
Requirements:
· Perl
Product's homepage
Requirements:
· Perl