r5797 - in trunk/gta02-core/bom: . test test/1 test/2

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Jan 26 21:42:25 CET 2010


Author: werner
Date: 2010-01-26 21:42:25 +0100 (Tue, 26 Jan 2010)
New Revision: 5797

Added:
   trunk/gta02-core/bom/test/
   trunk/gta02-core/bom/test/1/
   trunk/gta02-core/bom/test/1/1.inv
   trunk/gta02-core/bom/test/1/1.par
   trunk/gta02-core/bom/test/1/Makefile
   trunk/gta02-core/bom/test/2/
   trunk/gta02-core/bom/test/2/2.inv
   trunk/gta02-core/bom/test/2/2.par
   trunk/gta02-core/bom/test/2/Makefile
Modified:
   trunk/gta02-core/bom/gta02-core.inv
   trunk/gta02-core/bom/parser.pl
   trunk/gta02-core/bom/part2order
Log:
- bom/test/: added regression tests for part2order
- bom/parser.pl: documented global variables set by parser
- bom/part2order: part numbers are now adjusted and we can take parts from
  multiple inventories



Modified: trunk/gta02-core/bom/gta02-core.inv
===================================================================
--- trunk/gta02-core/bom/gta02-core.inv	2010-01-26 16:36:41 UTC (rev 5796)
+++ trunk/gta02-core/bom/gta02-core.inv	2010-01-26 20:42:25 UTC (rev 5797)
@@ -1,2 +1,2 @@
 #INV
-GTA02-CORE TST 99999 USD 1 0
+GTA02-CORE TST 999999 USD 1 0

Modified: trunk/gta02-core/bom/parser.pl
===================================================================
--- trunk/gta02-core/bom/parser.pl	2010-01-26 16:36:41 UTC (rev 5796)
+++ trunk/gta02-core/bom/parser.pl	2010-01-26 20:42:25 UTC (rev 5797)
@@ -6,6 +6,15 @@
 }
 
 
+#
+# "bom" populates the following global variable:
+#
+# $cmp{component-reference}[0] = value
+# $cmp{component-reference}[1] = footprint
+# $cmp{component-reference}[2] = field1
+# ...
+#
+
 sub bom
 {
     if (/^#End Cmp/) {
@@ -20,6 +29,17 @@
 }
 
 
+#
+# "equ" populates the following global variables:
+#
+# $id{item-number} = "namespace item-number"
+#   This is used for heuristics that look up parts commonly referred to by
+#   their part number.
+#
+# $eq{"namespace0 item-number0"}[] = ("namespace1 item-number1", ...)
+#   List of all parts a given part is equivalent to.
+#
+
 sub equ
 {
     my @f = split(/\s+/);
@@ -32,6 +52,20 @@
 }
 
 
+#
+# "inv" populates the following global variables:
+#
+# $id{item-number} = "namespace item-number"
+#   This is used for heuristics that look up parts commonly referred to by
+#   their part number.
+#
+# $inv{"namespace item-number"}[0] = items-in-stock
+# $inv{"namespace item-number"}[1] = currency
+# $inv{"namespace item-number"}[2] = order-quantity
+# $inv{"namespace item-number"}[3] = unit-price
+#   [2] and [3] may repeat.
+#
+
 sub inv
 {
     my @f = split(/\s+/);
@@ -44,6 +78,21 @@
 }
 
 
+#
+# "par" populates the following global variables:
+#
+# $parts{component-ref}[0] = namespace
+# $parts{component-ref}[1] = item-number
+# [0] and [1] may repeat
+#
+# $want{"namespace item"} = number of times we may use the part. If multiple
+#   parts are eligible for a component, each of them is counted as desirable
+#   for each component.
+#
+# $comps{"namespace item"}{component-ref} = 1
+#   Set of components a part may be used for.
+#
+
 sub par
 {
     my @f = split(/\s+/);
@@ -53,7 +102,7 @@
 	my @id = splice(@f, 0, 2);
 	my $id = "$id[0] $id[1]";
 	$want{$id}++;
-	push @{ $comps{$id} }, $ref;
+	$comps{$id}{$ref} = 1;
     }
 }
 

Modified: trunk/gta02-core/bom/part2order
===================================================================
--- trunk/gta02-core/bom/part2order	2010-01-26 16:36:41 UTC (rev 5796)
+++ trunk/gta02-core/bom/part2order	2010-01-26 20:42:25 UTC (rev 5797)
@@ -17,11 +17,43 @@
 }
 
 
+#
+# The heuristics here aren't very nice. We give zero-cost stock priority over
+# any other stock, when we go by stock size up to the quantity we need. The
+# idea is to exhause local stock (zero-cost) first, then try to obtain the
+# parts with as few orders as possible.
+#
+# It would be better to have some sort of priority, so that we can express a
+# preference among stock we already own. Also, if non-zero-cost stock has widly
+# different prices, the smallest order cost may not be a good indicator of
+# which source we prefer.
+#
+# Furthermore, the algorithm doesn't consider the number of sources we use in
+# total or things like lead time, shipping cost, customs, etc.
+#
+
+sub rank
+{
+    local ($a, $b) = @_;
+
+    my $na = &number($a);
+    my $nb = &number($b);
+    my $pa = $inv{$a}[3];
+    my $pb = $inv{$b}[3];
+
+#print STDERR "a=$a b=$b na=$na nb=$nb pa=$pa pb=$pb\n";
+    return 1 if !$pa && $pb;
+    return -1 if $pa && !$pb;
+    return $na <=> $nb if $na != $nb;
+    return $pb <=> $pa;
+}
+
+
 for (keys %parts) {
     $parts++;
 }
 
-for (sort { &number($b) <=> &number($a) } keys %want) {
+for (sort { &rank($b, $a) } keys %want) {
     my $n = &number($_);
     $n -= $n % $mult;
     next unless $n;
@@ -65,6 +97,21 @@
 	}
     }
     next if !defined $best_price;
-    print "$_ $best_qty $currency $best_price\n";
-# tested until price composition. todo: demand adjustment
+    print "$_ $best_qty $currency $best_price";
+    my $id = $_;
+    while (keys %{ $comps{$id} }) {
+	last if $best_qty < $mult;
+	$best_qty -= $mult;
+	my $ref = (sort keys %{ $comps{$id} })[0];
+#print STDERR "$id: $ref + ", join("|", keys %{ $comps{$id} }), "\n";
+	my @f = @{ $parts{$ref} };
+	while (@f) {
+	    my @id2 = splice(@f, 0, 2);
+	    my $id2 = "$id2[0] $id2[1]";
+	    $want{$id2}--;
+	    delete $comps{$id2}{$ref};
+	}
+	print " $ref";
+    }
+    print "\n";
 }

Added: trunk/gta02-core/bom/test/1/1.inv
===================================================================
--- trunk/gta02-core/bom/test/1/1.inv	                        (rev 0)
+++ trunk/gta02-core/bom/test/1/1.inv	2010-01-26 20:42:25 UTC (rev 5797)
@@ -0,0 +1,2 @@
+#INV
+TEST TST 999999 ARS 1 0.1 10 0.05

Added: trunk/gta02-core/bom/test/1/1.par
===================================================================
--- trunk/gta02-core/bom/test/1/1.par	                        (rev 0)
+++ trunk/gta02-core/bom/test/1/1.par	2010-01-26 20:42:25 UTC (rev 5797)
@@ -0,0 +1,10 @@
+#PAR
+TP001 TEST TST
+TP002 TEST TST
+TP003 TEST TST
+TP004 TEST TST
+TP005 TEST TST
+TP006 TEST TST
+TP007 TEST TST
+TP008 TEST TST
+TP009 TEST TST

Added: trunk/gta02-core/bom/test/1/Makefile
===================================================================
--- trunk/gta02-core/bom/test/1/Makefile	                        (rev 0)
+++ trunk/gta02-core/bom/test/1/Makefile	2010-01-26 20:42:25 UTC (rev 5797)
@@ -0,0 +1,2 @@
+all:
+	perl -I../.. ../../part2order 1 1.par 1.inv

Added: trunk/gta02-core/bom/test/2/2.inv
===================================================================
--- trunk/gta02-core/bom/test/2/2.inv	                        (rev 0)
+++ trunk/gta02-core/bom/test/2/2.inv	2010-01-26 20:42:25 UTC (rev 5797)
@@ -0,0 +1,3 @@
+#INV
+TEST TST 3 EUR 1 0
+ALT TST 999999 EUR 1 0.1

Added: trunk/gta02-core/bom/test/2/2.par
===================================================================
--- trunk/gta02-core/bom/test/2/2.par	                        (rev 0)
+++ trunk/gta02-core/bom/test/2/2.par	2010-01-26 20:42:25 UTC (rev 5797)
@@ -0,0 +1,6 @@
+#PAR
+TP001 TEST TST ALT TST
+TP002 TEST TST ALT TST
+TP003 TEST TST ALT TST
+TP004 TEST TST ALT TST
+TP005 TEST TST ALT TST

Added: trunk/gta02-core/bom/test/2/Makefile
===================================================================
--- trunk/gta02-core/bom/test/2/Makefile	                        (rev 0)
+++ trunk/gta02-core/bom/test/2/Makefile	2010-01-26 20:42:25 UTC (rev 5797)
@@ -0,0 +1,2 @@
+all:
+	perl -I../.. ../../part2order 1 2.par 2.inv




More information about the commitlog mailing list