Newsgroups: comp.ai.genetic
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!bloom-beacon.mit.edu!news.kei.com!ub!freenet.buffalo.edu!ah818
From: ah818@freenet.buffalo.edu (Phillip M. Fries)
Subject: Re: Seek help
Message-ID: <D5DD69.KKJ@freenet.buffalo.edu>
Sender: nntp@acsu.buffalo.edu
Nntp-Posting-Host: freenet.buffalo.edu
Reply-To: ah818@freenet.buffalo.edu (Phillip M. Fries)
Organization: State University of New York At Buffalo, NY (USA)
References: <hoffman.19.001A7E98@hk.super.net>  
Date: Mon, 13 Mar 1995 08:06:08 GMT
Lines: 170


In a previous article, hoffman@hk.super.net (Hoffman Hung) says:

>Dear sir/madam,
>
>I have a problem to be solved. If you could spend a little time to make
>any suggestion or reference to me, it will be greatly appericated.
>
>Problem :
>
>A factory receives order of purchasing steel plates.  An order may contains
>different volume of different sizes of plates.  However, they must be in
>rectangle sharp.  For example, an order may have 10 pieces of size 1m*1m, 5
>pieces of 2m*3m and 4 pieces of 4m*5m.  The factory have to make these
>plates by cutting from large steel plates, says 10m*7m.  Now the problem is
>how to produce the order's plates with minimum large steel plates.  In
>another word, how to make those small plates 'best fit' into the large plates.
>
>However, there is one more thing we have to consider.  We don't want the
>outcome cutting layout too complicated as it will introduce problem in
>cutting.  That is, we do also want to minimize the number of cutting
>required, or says, minimize the number of lines on the cutting layout.


Hello all,

I've read some of the comments on this request and have a couple of my 
own to add. I don't know if they'll help, but maybe some ideas will come 
from them.

It struck me that the problem here is really two separate problems
from the aspect of genetic programming. [1] assigning x plates to y sheets
and [2] assigning x plates to y sheet coordinates. I visualize the
problem this way:

PART 1
------

  USER INPUT:  The sheet numbers here are made up, but the plate numbers
               come from the example you spoke of.

               SHEETS                                PLATES    
           ---------------                       ---------------
  Type      A   B   C   D               Type      A   B   C   D 
  Width     7   6   5   8               Width     1   2   4   0 
  Heigth   10   9   6   4               Heigth    1   3   5   0 
  Quantity  3   1   1   2               Quantity 10   5   4   0 
    
This table information can be input by the user, but the GA program
would expand these tables to produce:

  SHEETTBL:

  Type         A   A   A   B   C   D   D
  Width        7   7   7   6   5   8   8
  Heigth      10  10  10   9   6   4   8
  Accumulator  0   0   0   0   0   0   0

  PLATETBL:
  
  Type      A  A  A  A  A  A  A  A  A  A  B  B  B  B  B  C  C  C  C
  Width     1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  4  4  4  4
  Heigth    1  1  1  1  1  1  1  1  1  1  3  3  3  3  3  5  5  5  5

The first problem, assigning plates to sheets, is attacked by using a
chrome equal to the width, left to right, of PLATETBL. The values of
the individual genes in the chrome will equal the number of sheets
needed to fill the order. The number of sheets required is easily
calculated from the tables, and you can get however complicated you
wish in the logic of which sheets to select from the stockpile defined
by SHEETTBL. In your example, a chrome would be 19 genes in length, and
only the first 2 sheets are needed to provide enough raw material for
the plates. You might want to throw in one extra sheet for safety. You
end up with a chrome that looks like:

  19 chars: 1  2  1  1  2  1  1  2  2  2  1  2  1  1  1  1  1  2  2

Fitness can be measured by accumulating the total area of the plates
assigned to each sheet and subtracting that amount from each sheet area,
i.e. the amount of unused sheet area, the smaller the fitness the better. 
when accumulating the total fitness for the chrome, don't add in
individual sheet fitness scores that are less than 0. This "penalizes"
chromes that attempt to assign too many plates to a sheet and they'll fall
out fast. The best fitness score you will achive will always be equal to
the total area of all the sheets less the total area of all the plates.
And you'll get plenty of them. (When I refer to sheets, I'm talking about 
the sheets that have been selected from the stockpile SHEETTBL)

PART 2
------

Having a chrome with a "best fitness score", the GA can move to the 2nd
part of the problem, assigning the x plates defined by the chrome to the
y coordinates of the sheet they were assigned to, for each sheet in the
PART 1 chrome. In other words, repeat the following steps for each
sheet.

The grid concept in one proposed solution makes sense, and I utilize it
here also. But with a twist. Now that I have a fixed number of plates to be
assigned to a given sheet I can construct a chrome of length equal to the
number of plates. I also have the size of the sheet; 7 x 10 in the example.
Thus I construct a chrome of length 11 and randomly assign values to each
of the genes of 1 to 70 - the number of "units" on the sheet. (The principle
prevails no matter how "units" are defined, so long as the "unit" is based
on a common denominator for the plates and the sheets.) Thus a PART 2
chrome would look like:

           11 chars: 1  10  27  45  59  42  60  15  65  22

The fitness function for evaluating this second set of chromes is a matrix
equal to the size of the sheet, 10x70. The first step of evaluation is to
initialize each cell in the matrix to 0. Next, loop through the chrome and
ADD 1 TO THE VALUE IN EVERY MATRIX CELL REPRESENTED BY THE GENE. In other
words, if the gene is 10, then that plate's start position on the matrix
is the 10th cell, counting left to right and top to bottom. We also know
from PLATETBL the sizes of the 11 plates assigned to the sheet, so we can
calculate which cells in the matrix represent the space taken up by the
plates represented by the 11 genes in this chrome. After "adding up" all
11 of the genes in the chrome, total the matrix. The more overlap you have
amoung the 11 plates, the higher will be the sum of the matrix. The best
fitness score will be equal to the total area of the plates assigned to
that sheet, i.e. all plates accomodated with no overlaps. 

In this example, I would even test the concept of automatically "killing
off" chromes that have any overlap whatsoever, because you can't overlap
the steel plates you want to cut out. How dramatically this might effect
the results of the GA is hard to tell, but you can do this by assigning an
arbitarily high value to the fitness result. (Actually, any method that
can determine overlaps will work for this stage - because all you want to
do in the end is kill chromes that define overlapping plates)

If the chrome passes the matrix fitness test (no overlapping), I would then
analyze the chrome (plate starting position) and the plate table (length and
width of the plate) to determine the number of plate edge intersections in
the chrome definition. The fewer the intersections, the less complicated the
cuts involved.

Actually, this could be done along with the matrix analysis if you use a
2nd matrix initialized to blanks, and fill in draw box characters as you
calculate which cells to add to. Then you could just loop through the 2nd
matrix and count the intersections (remembering that only chromes with no
overlapping plates reach this stage of the analysis). You're probably 
going to need some kind of routine to print out the layout anyway, and a 
matrix type subroutine could serve double duty here. 

Adding up the STEP 2 fitness for each plate, the final fitness function, in
effect becomes a rational combination of the PART 1 fitness (least wasted
space) and the PART 2 fitness (least number of intersections).

END COMMENTS
------------

In the end analysis, I guess one could say that this example uses a genetic
algorithm as a fitness function for a genetic algorithm. I'm currently try-
ing to build a set of standard genetic algorithm routines for the language
I've chosen to use for my efforts, and I've even coded PART 1 already. This
looks a good example for finding out if I can build a "recursive" set of
routines, if possible.

If you have any comments on my approach I'd appreciate hearing them. Like I
said, being new at this and being a hobbyist, I don't get a lot of feedback
on my thoughts and their direction - except when my retrospectively stupid
programming ideas blow up on me. :)

					Happy Programming!


-- 
Phillip M. Fries
ah818@freenet.buffalo.edu
