I have been asked to develop a program which will let us calculate the optimal sequence to cut lengths of steel for customers resulting in the least waste and time.

Lengths of steel are purchased in industry standard lengths of 20, 40 and 60 feet.

We may have 10 clients. 5 want 12 lengths of 22 feet, 3 want 8 lengths of 43 feet and the last 2 want 20 lengths of 33 feet.

I want to write a program where i enter the lengths of standard pipe we have on hand, then enter the lengths we need to cut. The program spits out the best use of the lengths we have on hand to minimize waste and cuts.

I don't need to know how to write the program, just need help with the algorithms and use in the C# windows forms world. Researching on the web has come up with many theories on Stock Cutting but nothing i can understand at a level to modify to my needs.

Thanks in advance for any help

Cheers

@lengths=(20,40,60);

@clients=([5*12,22],[3*8,4

our %Q;

our @Q0;

sub dp{

my ($l0,$l,$p,$s,@s)=@_;

my $q=int($l/$s);

if( @s ){

do{

#print "(@{$p},$q),$l,$s,$s[0]\n"

dp($l0,$l-$s*$q,[@{$p},$q]

}while( $q-- && $l > $s[0] );

}elsif( !$Q{"@{$p} $q"} || $Q{"@{$p} $q"}[0]>$l-$s*$q ){

$Q{"@{$p} $q"}=[$l-$s*$q,[$l0,@{$p},

}

}

sub dpl{

my @l=@{+shift};

my @C=sort{$b->[1]<=>$a->[1]}

my @s=map{$_->[1]}@C;

#print "@l\n@s\n";

for( @l ){

my @q;

dp($_,$_,[],@s);

}

#print Dumper \%Q;

@Q0=grep/[1-9]/,keys %Q;

my ($s,@S)=@{search(map{$_->[

#print Dumper $s,@S;

my %c;

for my$s( @S ){

$c{$s->[0]}{join",",map{($

}

for my $p( keys %c ){

for( keys %{$c{$p}} ){

print "cut $p into ($_) $c{$p}{$_} times\n";

}

}

}

dpl(\@lengths,@clients);

sub search{

my @c=@_;

return $Q{"@c"} if $Q{"@c"};

#print "search(@c)\n";

my @s;

for( @Q0 ){

no warnings 'recursion';

my @q=split;

my @c1=();

for( 0..$#c ){

last if $c[$_]<$q[$_];

push @c1,$c[$_]-$q[$_];

}

next if @c1<@c;

my($t0,@t0)=@{$Q{$_}};

my($t1,@t1)=@{search(@c1)}

@s=($t0+$t1,@t0,@t1) if !@s||$t0+$t1<$s[0];

}

return $Q{"@c"}=[@s];

}

__END__

prints

cut 60 into (22,22) 10 times

cut 60 into (43) 24 times

cut 60 into (33,22) 40 times