Study on the application of genetic algorithm in Jobshop (Part 2: Encoding)

Source: Internet
Author: User
Tags shuffle

    1. Coding

In the previous blog, we discussed the coding of the workshop scheduling problem, in particular, according to the number of work pieces and the number of operations per workpiece to generate 12122 of such a digital arrangement, specifically, how many processes a workpiece contains, then the number of the workpiece will appear how many times. From 12122 we can see a total of two workpiece 1 and 2, the workpiece 1 under the two processes, the workpiece 2 below three operations, so 1 appeared 2 times, 2 appeared 3 times.

In addition, we refer to the concept of a population, which refers to the random generation of a number of work piece permutation of the set, the number of permutations in the set is the size of the population. Let's think about how to program the initial population generation, and look at the python code below:

1 definitpopulation (PS, I):2Gene = [j forJinchXrange (I.N) forTinchI[j]]3Population = []4          forIinchxrange (PS):5 Shuffle (Gene)6Population.append ([j forJinchGene])7         returnPopulation

Line 1th We define a function that generates the initial population, called Initpopulation, which receives two parameters, PS and I. PS is an integer variable whose value represents the size of the population, and I is a list that stores the machine number and the time that is processed on the machine for each operation under each work piece. We still use one of the two artifacts of the previous blog, two machine examples to illustrate

i=[[(3,1), (2,2)],[(5,2), (+)].

I have two lists below, which are i[0]=[(3,1), (2,2)] and i[1]=[(5,2), (+)].

I.N represents the number of artifacts, i.n=2 here.

I.M indicates the number of machines, i.m=2 here.

Line 2nd gene represents the chromosome template, and all chromosomes are produced through this template. As far as this I is concerned, the result of the second line is 1122, that is, by the size of the workpiece number from small to large, each artifact number appears the same number of operations that the workpiece contains.

The 3rd line defines an empty list named population

line 4,5,6 for loop, generate PS chromosome, store in population, and finally return population. The practice is to use Python's shuffle function to randomly disrupt gene's order to make chromosomes (line 5th), such as the first Shuffle (1122) After the result may be 1212, the second result is shuffle (1122) The result may be 2211, This allows the PS-shuffle operation to generate a PS chromosome to be stored in the population (line 6th).

The 7th row Returns the population population.

Study on the application of genetic algorithm in Jobshop (Part 2: Encoding)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.