Study on the application of genetic algorithm in Jobshop (PART3: Crossover)

Source: Internet
Author: User

2. Crossover

Crossover is an important operation in genetic algorithms, which is designed to assemble a new chromosome from each of the two chromosomes. Here, a common crossover method in shop scheduling is called the Generalized Order crossover method (GOX), assuming there are three artifacts a,b,c , there are three processes under each workpiece, according to which we can randomly generate two chromosomes using the coding techniques described in the previous section:

We can use a list to store a chromosome,

Each element in this list is an ordered pair, the first element of an ordered pair is the workpiece number, and the second element is the operation number.

Parent1 with List can be expressed as [(b,1), (a,1), (b,2), (b,3), (c,1), (a,2), (c,2), (c,3), (b,1), (a,3))]

An ordered pair of icons is

The Gox crossover is the random extraction of a part of it from the Parent2 to create a new chromosome in the Parent1, for example, we choose "(a,2) (c,1) (a,3) (b,3)" This fragment

We first randomly select a position in the Parent1 to insert this "(a,2) (c,1) (a,3) (b,3)" fragment into the position

at the same time, we delete the original Parent1 from the part that was transplanted from the Parent2, that is, we can get the new crossed chromosome:

The implementation code for the above procedure is as follows:

1 defCrossover (P1, p2, i)://P1,P2 is two chromosomes to be crossed, I store information on operations and artifacts (see coding section)2         """Crossover operation for the GA. Generalized Order Crossover (GOX)."""3         defIndex (P1, i)://index (p1,i)//This function receives two parameters P1 and I, returning P1 corresponding ordered even list4CT = [0 forJinchxrange (I.N)]5s = []6              forIinchP1:7 S.append ((i, ct[i]))8Ct[i] = Ct[i] + 19             returnsTenIDX_P1 =Index (P1, I)//p1 ordered even List,p1 is the Parent2 above OneIDX_P2 =Index (P2, I)//p2 ordered even LIST,P2 is the Parent1 above ANT = Len (IDX_P1)Length of//p1 -i = Randint (1, NT)//1 random number between NT -j = Randint (0, Nt-1) random number between//0 and NT theK =randint (0, NT)//k insertion point when inserting Parent1
//implant equivalent to the above "(a,2) (c,1) (a,3) (b,3)" is the fragment extracted from Parent2 -Implant = Idx_p1[j:min (j+i,nt)] + idx_p1[:i-min (j+i,nt) +J] - -Lft_child =Idx_p2[:k] +Rgt_child =Idx_p2[k:] - forJtinchimplant://from Parent1 to delete an ordered couple that repeats with the inserted fragment + ifJtinchLft_child:lft_child.remove (JT) A ifJtinchRgt_child:rgt_child.remove (JT) at //child:That is equivalent to BABACABCCB -Child = [Job for(Job, Task)inchLft_child + implant +Rgt_child] - returnChild

Study on the application of genetic algorithm in Jobshop (PART3: Crossover)

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.