r5796 - trunk/gta02-core/bom

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Jan 26 17:36:41 CET 2010


Author: werner
Date: 2010-01-26 17:36:41 +0100 (Tue, 26 Jan 2010)
New Revision: 5796

Modified:
   trunk/gta02-core/bom/Makefile
   trunk/gta02-core/bom/gta02-core.inv
   trunk/gta02-core/bom/part2order
Log:
BOM processing: added price optimization algorithm for quantity discounts.



Modified: trunk/gta02-core/bom/Makefile
===================================================================
--- trunk/gta02-core/bom/Makefile	2010-01-26 15:03:30 UTC (rev 5795)
+++ trunk/gta02-core/bom/Makefile	2010-01-26 16:36:41 UTC (rev 5796)
@@ -3,7 +3,7 @@
 all:		gta02-core.ord
 
 gta02-core.ord:	part2order gta02-core.par fic/fic.inv gta02-core.inv
-		perl part2order fic/fic.inv gta02-core.inv gta02-core.par
+		perl part2order 20 fic/fic.inv gta02-core.inv gta02-core.par
 # \ >$@ || { rm -rf $@; exit 1; }
 	
 gta02-core.par:	bom2part fic/fic.equ ../gta02-core.lst gta02-core.inv

Modified: trunk/gta02-core/bom/gta02-core.inv
===================================================================
--- trunk/gta02-core/bom/gta02-core.inv	2010-01-26 15:03:30 UTC (rev 5795)
+++ trunk/gta02-core/bom/gta02-core.inv	2010-01-26 16:36:41 UTC (rev 5796)
@@ -1,2 +1,2 @@
 #INV
-GTA02-CORE TST 99999 1 USD 0
+GTA02-CORE TST 99999 USD 1 0

Modified: trunk/gta02-core/bom/part2order
===================================================================
--- trunk/gta02-core/bom/part2order	2010-01-26 15:03:30 UTC (rev 5795)
+++ trunk/gta02-core/bom/part2order	2010-01-26 16:36:41 UTC (rev 5796)
@@ -2,6 +2,7 @@
 
 require "parser.pl";
 
+$mult = shift(@ARGV);
 &parse;
 
 
@@ -9,8 +10,9 @@
 {
     local ($id) = @_;
 
-    my $n = $inv{$id}[0];
-    return $want{$id} < $n ? $want{$id} : $n;
+    my $s = $inv{$id}[0];
+    my $n = $want{$id}*$mult;
+    return $n < $s ? $n : $s;
 
 }
 
@@ -21,6 +23,48 @@
 
 for (sort { &number($b) <=> &number($a) } keys %want) {
     my $n = &number($_);
+    $n -= $n % $mult;
     next unless $n;
-    print "$_ $n\n";
+    my @f = @{ $inv{$_} };
+    my $max = shift @f;
+    my $currency = shift @f;
+    my @qty;
+    my @price;
+    my %index;
+    my $best_qty;
+    my $best_price = undef;
+    while (@f) {
+	my $q = shift @f;
+	my $p = shift @f;
+	if (defined $index{$q}) {
+	    $price[$index{$q}] = $p;
+	} else {
+	    push(@qty, $q);
+	    push(@price, $p);
+	    $index{$q} = $#qty;
+	    # @@@ this fails if smaller quantities following a large quantity
+	    # differ from the quantities preceding them. E.g., 1 10 100 25
+	    # wouldn't yield correct results.
+	}
+	for (my $i = $#qty; $i >= 0; $i--) {
+	    my $order = 0;
+	    my $price = 0;
+	    my $left = $n;
+	    for (my $j = $#qty; $j >= $i; $j--) {
+		while ($left >= ($j == $i ? 1 : $qty[$j])) {
+		    $left -= $qty[$j];
+		    $order += $qty[$j];
+		    $price += $price[$j]*$qty[$j];
+		}
+	    }
+	    next if $order > $max;
+	    if (!defined $best_price || $price < $best_price) {
+		$best_price = $price;
+		$best_qty = $order;
+	    }
+	}
+    }
+    next if !defined $best_price;
+    print "$_ $best_qty $currency $best_price\n";
+# tested until price composition. todo: demand adjustment
 }




More information about the commitlog mailing list