| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Algorithm::Simplex::Role::Solve; |
|
2
|
3
|
|
|
3
|
|
24276
|
use Moo::Role; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 Name |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Algorithm::Simplex::Role::Solve - solve() method implemented as Moose role. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=cut |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 Synposis |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Algorithm::Simplex::Rational; |
|
13
|
|
|
|
|
|
|
use Data::Dumper; |
|
14
|
|
|
|
|
|
|
my $matrix = [ |
|
15
|
|
|
|
|
|
|
[ 5, 2, 30], |
|
16
|
|
|
|
|
|
|
[ 3, 4, 20], |
|
17
|
|
|
|
|
|
|
[10, 8, 0], |
|
18
|
|
|
|
|
|
|
]; |
|
19
|
|
|
|
|
|
|
my $tableau = Algorithm::Simplex::Rational->new( tableau => $matrix ); |
|
20
|
|
|
|
|
|
|
$tableau->solve; |
|
21
|
|
|
|
|
|
|
print Dumper $tableau_object->display_tableau; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
requires( |
|
26
|
|
|
|
|
|
|
'tableau', 'determine_bland_pivot_row_and_column_numbers', |
|
27
|
|
|
|
|
|
|
'pivot', 'exchange_pivot_variables' |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 Methods |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 solve |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Walk the simplex of feasible solutions by moving to an adjacent vertex |
|
35
|
|
|
|
|
|
|
one step at a time. Each vertex of the feasible region corresponds to |
|
36
|
|
|
|
|
|
|
a tableau. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This solve() method assumes we are starting with a feasible solution. |
|
39
|
|
|
|
|
|
|
This is referred to a phase 2 of the Simplex algorithm, where phase 1 |
|
40
|
|
|
|
|
|
|
is obtaining a feasible solution so phase 2 can be applied. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Returns 1 if an optimal solution is found, 0 otherwise. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub solve { |
|
47
|
18
|
|
|
18
|
1
|
5966
|
my $tableau_object = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
18
|
|
|
|
|
35
|
my $counter = 1; |
|
50
|
18
|
|
|
|
|
80
|
until ($tableau_object->is_optimal) { |
|
51
|
20
|
|
|
|
|
72
|
my ($pivot_row_number, $pivot_column_number) = |
|
52
|
|
|
|
|
|
|
$tableau_object->determine_bland_pivot_row_and_column_numbers; |
|
53
|
20
|
|
|
|
|
406
|
$tableau_object->pivot($pivot_row_number, $pivot_column_number); |
|
54
|
20
|
|
|
|
|
142
|
$tableau_object->exchange_pivot_variables($pivot_row_number, |
|
55
|
|
|
|
|
|
|
$pivot_column_number); |
|
56
|
20
|
|
|
|
|
31
|
$counter++; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Too many pivots? |
|
59
|
20
|
50
|
|
|
|
322
|
if ($counter > $tableau_object->MAXIMUM_PIVOTS) { |
|
60
|
0
|
|
|
|
|
0
|
warn "HALT: Exceeded the maximum number of pivots allowed: " |
|
61
|
|
|
|
|
|
|
. $tableau_object->MAXIMUM_PIVOTS . "\n"; |
|
62
|
0
|
|
|
|
|
0
|
return 0; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
18
|
|
|
|
|
51
|
return 1; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |