stu96art has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use Data::Dumper; open ( OHA, ">c:/printoutKNAP.txt" ) or die ("could not open file. &!" + ); my @lite[][]; $lite[0][0] = 2; $lite[0][1] = 5; $lite[0][2] = 0; $lite[0][3] = 0; $lite[0][4] = 0; $lite[1][0] = 4; $lite[1][1] = 3; $lite[1][2] = 0; $lite[1][3] = 0; $lite[1][4] = 0; $lite[2][0] = 1; $lite[2][1] = 4; $lite[2][2] = 0; $lite[2][3] = 0; $lite[2][4] = 0; my $waste = 0; my $end = 0; sub KNAP { my $bigx = $_[0]; my $bigy = $_[1]; my $locx = $_[2]; my $locy = $_[3]; my @list[][]; my $listnum = 0; for ( $i = 1; i <= $maxlites; $i ++; ) { if ( $lite[$i][2] == 0 ) { if ( ( $lite[$i][0] <= $bigx ) && ( $lite[$i][1] <= $bigy ) ) { $list[$listnum][0] = $i; $list[$listnum][1] = 0; $list[$listnum][2] = 0; $listnum = $listnum + 1; } if ( ( $lite[$i][1] <= $bigx ) && ( $lite[$i][0] <= $bigy ) ) { $list[$listnum][0] = $i; $list[$listnum][1] = 0; $list[$listnum][2] = 1; $listnum = $listnum + 1; } } } for ( $j = 1; $j <= $listnum; $j++ ) { $list[$list[$j][0]][2] = 1; $list[$list[$j][0]][3] = $locx; $list[$list[$j][0]][4] = $locy; if ( $list[$j][2] == 1 ) { my $temp = $lite[$list[$j][0]][0]; $lite[$list[$j][0]][0] = $lite[$list[$j][0]][1]; $list[$list[$j][0]][1] = $temp; } for ( $k = 1; $k <= $maxlites; $k++ ) { $end = 1; if ( $lite[$k][2] == 0 ) { $end = 0; } } if ( $end == 1 ) { $waste = $waste + ( $bigx*$bigy - $lite[$list[$j][0]][0]*$lite[$ +list[$j][0]][1] ); } $newx = $bigx - $lite[$list[$j][0]][0]; $newy = $bigy - $lite[$list[$j][0]][1]; if ( ( $newx != 0 ) && ( $newy != 0 ) && ( $end != 1 ) ) { &KNAP( $bigx, $newy, $locx, $locy + $lite[$list[j][0]][1] ); &KNAP( $newx, $lite[$list[$j][0]][1], $locx + $lite[$list[$j][0] +][0], $locy ); &KNAP( $lite[$list[$j][0]][0], $newy, $locx, $locy + $lite[$list +[$j][0]][1] ); &KNAP( $newx, $bigy, $locx + $lite[$list[$j][0]][0], $locy ); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with attempting to solve cutting stock problem (knapsack)
by markov (Scribe) on Jan 16, 2004 at 16:51 UTC | |
|
Re: Help with attempting to solve cutting stock problem (knapsack)
by BrowserUk (Patriarch) on Jan 16, 2004 at 17:17 UTC | |
by stu96art (Scribe) on Jan 16, 2004 at 18:03 UTC | |
by shotgunefx (Parson) on Jan 16, 2004 at 20:58 UTC | |
by stu96art (Scribe) on Jan 16, 2004 at 21:52 UTC | |
|
Re: Help with attempting to solve cutting stock problem (knapsack)
by Abigail-II (Bishop) on Jan 16, 2004 at 16:29 UTC | |
by Cine (Friar) on Jan 16, 2004 at 16:42 UTC | |
by revdiablo (Prior) on Jan 17, 2004 at 00:13 UTC |