Hi Richard,

After reading your question, my first reaction was "How am I going to show this 
without going through pages of explanations?" :) :-/

I guess the best way is just to show you how I come up with material 
requirement that is needed by the production floor and warehouse to produce an 
order. NOTE: I really have to gravely simplify some stuff so bear with me.

STEP 1: Generate the material consumption. The data below would just apply 
to one Size (let's say SMALL) so the key data will be the Material Code, 
Material Color and Product Color
Our BOM data looks like this which you can type in EXCEL and just copy to J 
using the clipboard or TARA:
+-------------+-----------------+-----+-----+----+
|MATERIAL CODE|CONSUMPTION (YDS)|WHITE|GREEN|BLUE|
+-------------+-----------------+-----+-----+----+
|FABRIC1      |1.2              |puti |     |asul|
+-------------+-----------------+-----+-----+----+
|FABRIC2      |0.95             |     |berde|asul|
+-------------+-----------------+-----+-----+----+
Since, I am more at ease with numbers, I have a function (searchLOOKUP) that 
would convert this value to number with the caption removed:
boxopen=: <^:(L.=0:)
LOOKUP_z_=: '';'0';'1';'2';'3';'4';'5';'6';'7';'8';'9';' '
searchLOOKUP=: 3 : 0
data=. boxopen y
LOOKUP_z_=: ~. LOOKUP_z_ ,~. data
LOOKUP_z_ i. data
)
   [data
+-------------+-----------------+-----+-----+----+
|MATERIAL CODE|CONSUMPTION (YDS)|WHITE|GREEN|BLUE|
+-------------+-----------------+-----+-----+----+
|FABRIC1      |1.2              |puti |     |asul|
+-------------+-----------------+-----+-----+----+
|FABRIC2      |0.95             |     |berde|asul|
+-------------+-----------------+-----+-----+----+
   [bom=. searchLOOKUP each }. data
+--+--+--+--+--+
|17|18|19|0 |20|
+--+--+--+--+--+
|21|22|0 |23|20|
+--+--+--+--+--+
    [bom=. >bom
17 18 19  0 20
21 22  0 23 20

STEP 2: Now to convert the data from a bill of material to a material 
consumption by color.:
NB. bom2consump by Raul Miller <[email protected]>
bom2consump=: [: (#~ 0 ~: 1&{"1)@; <@(0&{,. 1&{ (~...@],. (] +//. ["0),. [* 
=...@]) 2&}.)"1
   [bconsump=. bom2consump bom
17 19 18 18  0  0
17 20 18  0  0 18
21 23 22  0 22  0
21 20 22  0  0 22
To make the data more coherent, here is the same data converted back to string 
with captions:
   [wired=. (;: 'MAT_CODE MAT_COLOR TOTAL_CONSUMP WHITE GREEN BLUE'), bconsump 
{ LOOKUP
+--------+---------+-------------+-----+-----+----+
|MAT_CODE|MAT_COLOR|TOTAL_CONSUMP|WHITE|GREEN|BLUE|
+--------+---------+-------------+-----+-----+----+
|FABRIC1 |puti     |1.2          |1.2  |     |    |
+--------+---------+-------------+-----+-----+----+
|FABRIC1 |asul     |1.2          |     |     |1.2 |
+--------+---------+-------------+-----+-----+----+
|FABRIC2 |berde    |0.95         |     |0.95 |    |
+--------+---------+-------------+-----+-----+----+
|FABRIC2 |asul     |0.95         |     |     |0.95|
+--------+---------+-------------+-----+-----+----+

STEP 3: Compute for material requirement:
So if you have an order for 93 pcs of POLO Ralph Lauren Shirts size SMALL, I 
can just multiply it against my consumption above like so:
   (5 4 $ ,> ". each 2 }. "1 }. wired) * 93
111.6 111.6     0     0
111.6     0     0 111.6
88.35     0 88.35     0
88.35     0     0 88.35
111.6 111.6     0     0

OR ... as a report:
   [SMALL=. (2 {. "1 }. wired),. < every (4 4 $ ,> ". each 2 }. "1 }. wired) * 
93
+-------+-----+-----+-----+-----+-----+
|FABRIC1|puti |111.6|111.6|0    |0    |
+-------+-----+-----+-----+-----+-----+
|FABRIC1|asul |111.6|0    |0    |111.6|
+-------+-----+-----+-----+-----+-----+
|FABRIC2|berde|88.35|0    |88.35|0    |
+-------+-----+-----+-----+-----+-----+
|FABRIC2|asul |88.35|0    |0    |88.35|
+-------+-----+-----+-----+-----+-----+
OR With Captions:
   (;:'MAT_CODE MAT_COLOR TOT_IN_YDS WHITE GREEN BLUE'),SMALL
+--------+---------+----------+-----+-----+-----+
|MAT_CODE|MAT_COLOR|TOT_IN_YDS|WHITE|GREEN|BLUE |
+--------+---------+----------+-----+-----+-----+
|FABRIC1 |puti     |111.6     |111.6|0    |0    |
+--------+---------+----------+-----+-----+-----+
|FABRIC1 |asul     |111.6     |0    |0    |111.6|
+--------+---------+----------+-----+-----+-----+
|FABRIC2 |berde    |88.35     |0    |88.35|0    |
+--------+---------+----------+-----+-----+-----+
|FABRIC2 |asul     |88.35     |0    |0    |88.35|
+--------+---------+----------+-----+-----+-----+

Actually, this is NOT how the actual production code looks like (its more 
complicated but  generic) ... but I'm at a loss for words how to explain them 
using email without diagrams attached.

Still, your question was:
>>At the risk of going off-topic it would be good to know how you solved the 
>>multi-level problem using linear algebra in J.
>>(ie multi-level with common subassy)
It's been years since I left school (almost 2 decades???) and if I try to 
explain it in linear algebra ... everyone would just laugh at me. Teeheee. :P 
One thing I am sure though is that I knew about identity matrices and matrix 
computation in school but I could not implement them directly using any of the 
programming language I know until I encountered J. 

In my example, you should look at how this function by Raul Miller work:
bom2consump=: [: (#~ 0 ~: 1&{"1)@; <@(0&{,. 1&{ (~...@],. (] +//. ["0),. [* 
=...@]) 2&}.)"1

It converted data from this format:
17 18 19  0 20
21 22  0 23 20
To this format:
17 19 18 18  0  0
17 20 18  0  0 18
21 23 22  0 22  0
21 20 22  0  0 22

I do have my own implementation of this code and I asked the forum how to 
optimized it and Raul's work was the best. ;)

I don't know if I helped you or confused you more or showed my pretty obvious 
ignorance. ;) bwahahahahaha (my evil take over the world laugh).

r/Alex

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Richard Hill
Sent: Monday, August 23, 2010 12:14 PM
To: 'Programming forum'
Subject: Re: [Jprogramming] Creating a matrix (some polish required)

Alex,
At the risk of going off-topic it would be good to know how you solved the 
multi-level problem using linear algebra in J.
(ie multi-level with common subassy)
A ref to the appropriate wiki or J phrase would be enough.


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Alex Rufon
Sent: Monday, 23 August 2010 12:10
To: Programming forum
Subject: Re: [Jprogramming] Creating a matrix (some polish required)

I remember identity matrix taught in my linear algebra class and wondering how 
to use it in "real life" situation. 

Because of J, I actually used this concept to compute for Raw Material 
Consumption and Material Requirement Planning for Shoes and Apparel 
manufacturing (and soon for the Fishing Industry).  I remember doing RMC and 
MRP in VB+PL/SQL when I was still working in the Paper Industry and the code 
was mind boggling. I remember being confused where an IF-ENDIF block ends 
because of the multi-leveling. Learning J to implement identity matrix and 
matrix math is totally worth it. 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Roger Hui
Sent: Friday, August 20, 2010 9:55 PM
To: Programming forum
Subject: Re: [Jprogramming] Creating a matrix (some polish required)

http://www.jsoftware.com/jwiki/Essays/Identity%20Matrix

34 ways to create the identity matrix.  Adapt one to create the anti-diagonal 
matrix.  e.g. method 23:

   a23=: |....@i.
   a23 5
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0



----- Original Message -----
From: Alex Gian <[email protected]>
Date: Friday, August 20, 2010 3:42
Subject: [Jprogramming] Creating a matrix (some polish required)
To: Programming forum <[email protected]>

> The "flipped" identity matrix is quite interesting. (Basically it's 
> the identity matrix flipped or mirrored about either the vertical or 
> horizontal axis.  IOW, for a 3x3:
> 0 0 1
> 0 1 0
> 1 0 0
> I don't know if it has any special name, I stumbled on it by chance 
> while messing around with a simple FSA for a puzzle game.
> Pre-multiplying by this matrix flips any same size matrix vertically, 
> post-multiplying flips it horizontally.  Its square is obviously the 
> identity matrix.
> 
> Now, I have created this matrix on various systems, (e.g. HP/RPL, 
> Scheme, TI-Basic), usually - if an id matrix is provided - just by 
> reversing its rows, otherwise just by starting off with the vector, 
> say,
> 0 0 0 1, and then rotating the "1" each time and appending that vector 
> to a string, which is eventually converted to a matrix.
> 
> I can do this using loops and explicit coding, but am looking for any 
> suggestions to make it into a J one-liner, such that:
> flipidm 4
>   0 0 0 1
>   0 0 1 0
>   0 1 0 0
>   1 0 0 0
> 
> Hope my explanation was clear enough, TIA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3084 - Release Date: 08/21/10
04:35:00

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to