Algorithm-Simplex
view release on metacpan or search on metacpan
lib/Algorithm/Simplex.pm view on Meta::CPAN
);
has objective_function_value => (
is => 'lazy',
isa => Str,
);
has number_of_rows => (
is => 'lazy',
isa => Int,
init_arg => undef,
);
has number_of_columns => (
is => 'lazy',
isa => Int,
init_arg => undef,
);
has number_of_pivots_made => (
is => 'rw',
isa => Int,
default => sub { 0 },
);
has EPSILON => (
is => 'rw',
isa => Num,
default => sub { 1e-13 },
);
has MAXIMUM_PIVOTS => (
is => 'rw',
isa => Int,
default => sub { 200 },
);
has x_variables => (
is => 'lazy',
isa => ArrayRef [ HashRef [Str] ],
);
has 'y_variables' => (
is => 'lazy',
isa => ArrayRef [ HashRef [Str] ],
);
has u_variables => (
is => 'lazy',
isa => ArrayRef [ HashRef [Str] ],
);
has v_variables => (
is => 'lazy',
isa => ArrayRef [ HashRef [Str] ],
);
=head1 Name
Algorithm::Simplex - Simplex Algorithm Implementation using Tucker Tableaux
=head1 Synopsis
Given a linear program formulated as a Tucker tableau, a 2D matrix or
ArrayRef[ArrayRef] in Perl, seek an optimal solution.
use Algorithm::Simplex::Rational;
my $matrix = [
[ 5, 2, 30],
[ 3, 4, 20],
[10, 8, 0],
];
my $tableau = Algorithm::Simplex::Rational->new( tableau => $matrix );
$tableau->solve;
my ($primal_solution, $dual_solution) = $tableau->current_solution;
=head1 Methods
=head2 _build_number_of_rows
Set the number of rows.
This number represent the number of rows of the
coefficient matrix. It is one less than the full tableau.
=cut
sub _build_number_of_rows {
my $self = shift;
return scalar @{ $self->tableau } - 1;
}
=head2 _build_number_of_columns
Set the number of columns given the tableau matrix.
This number represent the number of columns of the
coefficient matrix.
=cut
sub _build_number_of_columns {
my $self = shift;
return scalar @{ $self->tableau->[0] } - 1;
}
=head2 _build_x_variables
Set x variable names for the given tableau, x1, x2 ... xn
These are the decision variables of the maximization problem.
The maximization problem is read horizontally in a Tucker tableau.
=cut
sub _build_x_variables {
my $self = shift;
my $x_vars;
for my $j (0 .. $self->number_of_columns - 1) {
my $x_index = $j + 1;
$x_vars->[$j]->{'generic'} = 'x' . $x_index;
}
return $x_vars;
}
( run in 1.138 second using v1.01-cache-2.11-cpan-0068ddc7af1 )