2.交叉

交叉是遗传算法中的一个重要操作,它的目的是从两条染色体中各自取出一部分来组合成一条新的染色体这里,在车间调度中一种常见的交叉方法叫Generalized Order Crossover方法(GOX),假设有三个工件A,B,C, 每个工件下面包含三道工序,根据这一信息我们可以利用上一节介绍的编码技术随机生成两条染色体如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUUAAAAeCAIAAAA0KJuKAAAEG0lEQVR4nO2bQbKkIAyGuWNfwjNwBQ/SF8gx3Ltmz5a1s0hNihHBmGDrUPkWU12OMQn4B0j3c5thGKPgng7AMIxumJ4NYxxMz4YxDqZnwxgH07NhjIPp2TDGwfRsGONgejaMcTA9G8Y4mJ7/b1JKKaWno2CRUooxCqLV5ChzKg5VTK95PNezqzNNUwhBH8QveYMAYowAME2Tc+77/QIA/jvPMwBcehQa3uexS6jee7o5hAAA67oCQIyRY87MsYvTq1a9plKWYwl3fUYBf7/fPAK82CWOjszzfHh9WRbv/XsCBgDn/hn/GKNzznvPfwhOwd0eNaF+Pp+y6IcQnHNMPV/KUeNUHKp+KgU5Hj/nkr+dEkjSj694OaWe13V1zs3zXFalB8HR213EN4O561nXFVcG5v1ijxrDWnn13nP0fDVHsVNNqMqpFORYQ6VnjJhfaH9Do869akNRFnW6yKw4uDnkZyT2KDPEMrosS+1/OcvA1RxlTpWhKqfyao4N+q/P6S/4Ob+/vHg4TLXb8qNv7oWIMeIivPzlMIvDIf79FuOwqGP8nPoYQsAEsZFxq0eZ4ekNp2kKcpQ5VYaqmUpBjg1UesbjaH5IwDqHgsHP+V4lpYR1iLoF+IT8gbTnyc8tZIh7ErTF56/runs4xolwsqBHdTnA8CmLOr4BzE0XZXH4MvX1KDPUD6kgR5lTZaiaqRTk2OCanr331MRr7MBJk3jbbj3EG/BivryjtvN6hn3CXQz508ppaE9MbX1+RM80OHlT1HtPFerUnD4zt2pijzJD/ZAKcnxEz5qpFOTYQN7frgEAVJZ28s4fhZ9psU0plWO6K3sc9XL0fDhkAFA7Pt3E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vADagqECTTvEC9zrkbqW0CXVB/h1JWcRpMG58TDXlUURO3+hfnXE+JP5qcyA1zhC3D4ynJiYPravgBPqfj1ZEMDUMaTF0Q1nWd5xnxA/QV9g/pCK5MtfpUa+C9BzHs/3tMqlUcEbWLJtuQR3V35l2njOREbpgjbBkex5MD9GoVq1PalKNaoJbgM63mIQRUGtp2wzydjZa+tGUnQ3QUsMXkJLb0GvODVoR/e+AHu2LiWb3fWybZlbjxu10i25BHdTyljOREbpgjbBkez3reNrWqtabDrkZXTJLDZWkbgG8xkq7J0G1aS7AYZgSyqbJoO+OHr3SqB7WaRdTT6VFW01NHrfVuS8825FEdTykjOZEb5ghbhsfLtdqzqzHGUDnJpJtRpEUyhFBSz2pVjzJ74ocsy7tujLn/ZNh7n5ZepVTPWWV1d9SzA2cb8qgOPo685ERumOeuq7seL9dq/+GH1lprjRO8La0S0PFifipOWYd8ilazzvlxWGvTYvz5fHru31ZDOO39SMA25FHN7mCJ9hkBLzmRG+YIW4bHweT8uqh67VlXs6a3va4SSKstTge1Wi6S1tq01lhrHxdtRtJa21MQq1U8dpQqtiGPKq5pdCvt4xNeciI3zBG2DI+Dyfl1seW1nalScpDurla3xtNIjmo1+8o5h31yWqcpHfjluv+k8SyUt6pHNtUqTid5VxiOUN36CXFXdTyPcSw/PLY8jyPJITC1Wm47O9fV+PcAmdA2LEfSvqI8nS5RXtCI7nRUd8jluVfVsKR66X6VTTVuv5pznceRbTmbLc8jz12KnfeBG4r13mObSu9w0jt9tOpuTVIufQijNKRTaJqZJlFK4RAijbYq1DS5N6+reIm09Ehx4by93LHAkB7ZtEdol9FBQwbVFEqp1Ateeb3CIzvMQbYjHg+5K/EtL98J/ifgvya+53XUNm5my3YnWhUI3gHRqkDwDohWBYJ34B/toeR3UmsdugAAAABJRU5ErkJggg==" alt="" />

我们可以用一个list来存储一条染色体,

这个list中的每个元素是一个有序偶,有序偶的第一个元素是工件号,第二个元素是工序号。

Parent1用list可以表示为[(B,1),(A,1),(B,2),(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7zgKT+GY8ij79M1M4KfGTH/8wR+jOjf0nm7/UnRZflHnoy9cd/2qlWGBJFm+pE/aIaY1xlYVIyL/7TuP7XVKzaWYEP7fgv13++APM8931PCdLPegzxHCqP/+M4ltYhpcflNZriLq9WVIuhIsxlWcYI/gVK4WtyJ1Rs0dk61ON/8nhz95xd/Scmfd9P08Tr/OR/b0ngfSI1x3962yw+IhltkmqvM/7rimoxtIdZKuATKlZ+qhq1/tffe/vr3l7dx8zfIQT+X5ovJFLH/p8c/hFHQjhDTt6iU6yrqxXVaGgMs1T/J1Rs0dmldBtorlKUk3sYBnpixy9IJOdIMn/TmbEX7jW/d/ynYLvot1UvNeSHrzFyj9z0RW+qVy6qJcbVEOY8z7x1VfrsQOeR+NZBD3wd+Ve8/gz1w7R4hP4BaBfoH4B2gf4BaBfoH4B2gf4BaBfoH4B2+Q/eGeKR43jSGAAAAABJRU5ErkJggg==" alt="" />

GOX交叉就是从Parent2中随机抽取其中的一部分把它移植到Parent1中生成新的染色体,比如,我们选取 “(A,2)(C,1)(A,3)(B,3)” 这个片段

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAT4AAABCCAIAAABBzS1pAAAGs0lEQVR4nO2du5XkIBBFlWMnoRhIQYF0AoQhHxtfrmzWeGfqMKAPKvRj511jzyytogqkx68R3QVCSIN0TwdACNFA6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJQuIU1C6RLSJJTui5jneZ7np6MoQh3qPM/TNClsH6kcdbQ3uCuVbrdO3/fe+4qAbwW1A56OJeX7/Vprdy+bpsla2/d913Uwwb/DMGybqw3VocYYY8TEe2+tdc5ZawtvRLnHU4p5KNp6j4rKOdbrQqvf71dSvt8vEo/eyEsZhmEx3RiD2jTGIOxxHG+ObQOEVHixtTa5eJqmruuMMRcZqkMNIXw+n7x99953XVco3aMea4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fj/x9M1raHJoAkhz0j3zccyEtIE+o2QNarDQZXtjlX+Mrh32OineOlKcQps7LT8SIBKw/dz1av25bmdkhW5B+dcvFc8Pj14F5w3pHt+Yi/dwcPldIbv58JX7QtzOyUrcg/Y9C//xcsAh7b4Kp4fCF5eIcLJDZcaNgGlSw6AWyZiwOtcR3M4+vwkJ56WPzZqwyaokm7hAasx8Rmra1W5fZJr/ndyGbkOHJUmyxyQ7tW9bp6D7vwwteE7qZWu3TtgVfDex68Uyxu88TUlJ7ni7Xl5Jdj+/C7L237N4C+wdqTLBpXSNcbofuBKbfhaThgw52tXuYSgw0VD+e/uSa4QJ969xt/xzaB070ehQ7V05Xy5owvFasOXc8IKcy6Yxe40H67El5Wc5Copa4eGPHIU658Fx30etdKtMCc56MTPFeadznMjZUO6JSe5hp8zaOpvP6nEOafQbThDP4pl7UrDd3JTr1su3e0Apmnq+x6H8f5PLWhbJAfiHkLR7OLMRJlJlU+w1YZNcFOvm3zDtnjZonQTk77vnXMyrY0/feoo1r8G9ifFKVevMCf3urzzVBs2wU3SDb9Xj8PSqtLuSa7ee/kUvXQsVC5T3YP84hQ4OmxWSDfZs1U+x1YbNkHVHuZDB6yGEIZhwNc58nOpyWUlJ7niytgRmlX2ujcgX+nFFNrihnbRz82V+/1+vxj34kvB8rViteH7YR9F2mB3t8/phi+H0iWkSShdQpqE0iWkSShdQpqE0iWkSf4BDRmXM36t2cQAAAAASUVORK5CYII=" alt="" />

我们首先随机选取Parent1中的一个位置,把这个“(A,2)(C,1)(A,3)(B,3)”片段插到该位置之后

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdgAAABJCAIAAAAR9qCcAAAJ7ElEQVR4nO2dQZa0KgyF2WNtwjW4BRfiBliGc8bOnTr2DfI6h19RIQTQqvsN+lRbEiCkLogoZnsh8zxba4/Hx3GsX5jnY4yZpql1KV4JXAfqYFoXQMK6rsMwLMviH7TWzvPcqkhPBmoiBq4DdXilEBPjOA7DMI6jtbbrOqjwkXV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F0xe8gdlp+tDjn8oW4WtASEOI3UVOIyfMciPRmO1nWu23Sy7VpISFWdMXvIHZafrTQ6DuzjaoF7f/29S3+K8SRW9z7+Lvcn9WfzR6PsPFgRq8eyNQUYmvtMAw8y08/JBXvmctdGDItlxDicq74YrSclhotFAD5QpxZjGT7+hYPQsz33M62uGfmefZfC81vKPbP6fueXwNPrUuN7WdE73rnVx5ba+mcJq91V6SmEO/Qiuy+7683Y8+h9EQeof4j/wVkTkuNlnmeSS5126ho0BKVpibo4PUW96SqwYT8L0mzvxiDOl7+l6SW3utMn30PQoibZE3whozlbkDXEeI6uXwZqU6TRctuD8y0IuoVQ0ClVRNH+QsOdY/jf/+04wZLW8jjdORsl5TgPihv4ejYOmlpp21Z2mBJCglZTh0j0XXFj5DjtPhoGceRR11nmzqLKd37Vh0Rxxy5EGLeCYkXJ9ISv50d2s2owm+yPk1GxHQPWpZpkHKrDkr/WtRd8QtkOi0yWmiXI/5Xffqo9FKZB42I44X4ugDLsnRd9/l8vu8Ssv6IeJqmfB/S1rw8oVRujrVo76viil9D4DRZtKzrOnkMw0BiIn6mrFrQEg8aEe8W7gVPCwrxLknXdc45ng72v6289ac6lUfE9GSRf0Q2Itg1xBtHxFqu+ClkTlOJlnzdrBa0/2enb1EqxNu/KyK20L01OrIb9fhJ5nnmb2kE7csubtYlJaE1+fYP8QXm7qmqctOs5YRYyxU/hcxpKtGSL8TVgpYo/q6JpC3ut20bhoEWnPGq7N1pzrlhGPx9s+krPyM608+Ierb3joippuZvQ+8kuZGl5bWDPtLib+M40lUerSlUvwed459bdF3xI+Q4LSdalmXhW0eZqx1KB60P4glU4vZBHgCYh0RLtWJAiAEAoDEQYgAAaAyEGAAAGgMhBgCAxkCIAQCgMRBiAABoDIQYAAAaAyEGAIDGQIgBAKAxEGIAAGgMhBgAABoDIQYAgMZAiAEAoDEQYgAAaMx/XSsFoaBDoiEAAAAASUVORK5CYII=" alt="" />

同时,我们把原Parent1中与从Parent2中移植过来的部分中重复的有序偶删掉,即可以得到新的交叉后的染色体:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWcAAABACAIAAABJBCHgAAAIKklEQVR4nO2dzZGtIBCFyfEmYQymYAQvAhMwgAnAvWv3bl37FqemqwfUC83P/anzLaZGrm03qEcEBHcQQkgK7tUBEEI+DKoGISQNqgYhJA2qBiEkDaoGISQNqgYhJA2qBiEkDaoGISQNqgYhJA2qBiEkDaoGISQNqgYhJI03Uo1937dtk7+SIpuVWNe17/t///7Vc/Em7PtetSTLOtVXQhuPOeREW/sKL05F1ViWZZom59w0TeM4OufGcVzX9XTnruv6vl+WBZvDMDjnuq47jqPve+dcvWJFkM69kYB6bNs2TVPXdShDlOc0TcMwTNMUfxxYtfSY5FTo+15M1nWdpgnX0rZtZT0WyaY52iTDgmckn1q3yjzPzrm+73Ui7v8wk0jXgqJv49q39LIszrnH41HPRRGgbjpl27awkG9ILcl8jwanj8cjfLSs6+qci1SNltk0R2szLHJG8ql1N17l5FQ4wtOsUyDAleL8IFBf8xJxGV3V4DTLsuBJFbNzEY8Gp+M4DsNw+lPf9zGq0TKb5mhzDDPPSBGqqMZVneL4zbb3xnGvGgSEzxlJHMfxqTnqw1fnpYbHVKeo9M3zfPVrzFtqs2yao83JZv4ZKUL5O3Pf9/t7Hr+iCWOeZ7zLoBwFnaKPLA1dUrKyqVO89jDPxPtfnIb73xzTy/Lp/+FmDqfPGTQAPX0Ir+uKDEprUW2PBqdPj/xW2TRHm5PNzDNSivKqASl9qho4u9M0SWPk9IvUR/C/HFZeebTi7vsuR5D2VMQgbauyjzQdoTakj6YD1sdEM1V4TAkJEUquIXmRRZFE+JzB5RJTNZUH7+llV8OjwWl+WbXMpjnanGxmnpFSvEw1fn5+vJRwHy9F18Ge7o/S1Dc5VAMHwf5SETgNGImeU72blp7j90qd51lOYVnVkH4o3X6uO57ubXUuImvvOR4NTvPLqmU2X6IamWekFC+ua+iUcJ8wBZWRq2PqlLATR+8jNYgr85iovE08B7z31Wmart5gU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A2GmaH2fW/7lNFseFjLJ9WjLPvy5aqhE+9n5YMEnBrKJnREd81A8mUTuoBpWvC/PitUjfauDYZmXzLtcGrHhNlQSI3Z5lHuoO9UDa8NPLxXTysRYW1N73a6tltYfEi5mhztdMK4TyEs2Da2fd/bJhyyGeaEKkdopnFHRvkkeRzHUR6BSYtFFeQFdY2YlBvVkHn3pJMcPd7ecWSBhZbrX7bhJXUNvfZdG8P8dg1Dx43Z0JzNJI+YB1A2Wdf4kxKjGvcBbNvWdR0WxWg/sWJV2tc15nk2vyzkCFxqqJhZVl5d428qsyEwZNPmEXNQCZg4rv20Mm9X1/D6sU93O1UNz6TrumVZ9PKr8lPZBQfa07iugSGMOiXyIWw2BIZQvXMdX2UwGx7WbOZ4FL6zrmFQjSOYRC9svESK9yDSJuu6yq+om2iNYGtokom3ekN8PdxsmBOqNolvaDAbHtZs5ngUvkc1XMC2bZFrBQjDMKCvVIayeLstyyKrHOBvuNoA9tSOIO2fW9dATt3vbP1JN5XNVrq9NVUNzaGKLarr6HGP75uwGWZm0xbq8bsOoSww9PGrQxPyWp4OICxuaKa9xyJQNQghaVA1CCFpUDUIIWlQNQghaVA1CCFpUDUIIWlQNQghaVA1CCFpUDUIIWlQNQghaVA1CCFpUDUIIWlQNQghafwHeq9aYEateq8AAAAASUVORK5CYII=" alt="" />

上述过程的实现代码如下:

 def Crossover(p1, p2, I)://p1,p2是两条待交叉的染色体,I存放工序和工件的信息(见编码部分)
"""Crossover operation for the GA. Generalized Order Crossover (GOX)."""
def Index(p1, I)://Index(p1,I)//这个函数接收两个参数p1和I,返回p1对应的有序偶list
ct = [0 for j in xrange(I.n)]
s = []
for i in p1:
s.append((i, ct[i]))
ct[i] = ct[i] + 1
return s
idx_p1 = Index(p1, I) //p1的有序偶list,p1即上文的Parent2
idx_p2 = Index(p2, I) //p2的有序偶list,p2即上文的Parent1
nt = len(idx_p1) //p1的长度
i = randint(1, nt)//1到nt间的随机数
j = randint(0, nt-1)//0 到nt间的随机数
k = randint(0, nt)//k为插入Parent1时的插入点
//implant 相当于上面的“(A,2)(C,1)(A,3)(B,3)”即从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:]
for jt in implant://从Parent1删除与插入片段重复的有序偶
if jt in lft_child: lft_child.remove(jt)
if jt in rgt_child: rgt_child.remove(jt)
//Child:即相当于BABACABCCB
child = [ job for (job, task) in lft_child + implant + rgt_child ]
return child

遗传算法在JobShop中的应用研究(part3:交叉)的更多相关文章

  1. 遗传算法在JobShop中的应用研究(part1: 绪论)

    1. 什么是JobShop问题 Job,中文翻译成工件.一个工件又由若干道工序加工完成. resource, 资源.在本文的车间调度中资源指的是机器,每道工序要在某个特定机器上加工. Constrai ...

  2. 遗传算法在JobShop中的应用研究(part 5:解码)

    解码操作是整个遗传算法最重要的一步,在这步里面我们利用配置文件中的信息将染色体解码成一个有向无环图. 在介绍解码操作之前我们先来看一下配置文件,在part1绪论中我们已经介绍了一个车间调度问题的基本信 ...

  3. 遗传算法在JobShop中的应用研究(part4:变异)

    下面,我们以车间调度为例来谈谈遗传算法中的另一个重要操作变异.变异操作通常发生在交叉操作之后,它的操作对象是交叉得到的新染色体.在本文中我们通过随机交换染色体的两个位置上的值来得到变异后的染色体,变异 ...

  4. 遗传算法在JobShop中的应用研究(part 7:整体流程)

    """ pop是种群,种群中的每个个体的形式是,(makespan, 染色体)""" pop = [(ComputeStartTimes(g ...

  5. 遗传算法在JobShop中的应用研究(part 6:结果显示)

    def FormatSolution(s, C, I): T = [0 for j in xrange(I.n)] S = [[0 for t in I[j]] for j in xrange(I.n ...

  6. 遗传算法在JobShop中的应用研究(part 2:编码)

    编码 在上一篇博客中我们讨论了车间调度问题的编码,具体说就是根据工件的个数和每个工件的工序数来生成12122这样的数字排列,具体的说一个工件包含多少道工序,那么这个工件的编号就出现多少次.从12122 ...

  7. (转)RRU交织冗余在LTE-R组网中的应用研究

    RRU交织冗余在LTE-R组网中的应用研究 王 芳1,2 庞萌萌1,2 (1.北京全路通信信号研究设计院集团有限公司,北京 100070; 2.北京市高速铁路运行控制系统工程技术研究中心,北京 100 ...

  8. Pywinauto在Windows Twain Driver自动化测试中的应用研究

    摘  要: 以Python为基础,结合对Twain Driver测试工具的具体需求,将Pywinauto引入到Twain Driver的自动化测试中.介绍了Pywinauto的基本概念,通过测试用例说 ...

  9. 关于sklearn中的导包交叉验证问题

    机器学习sklearn中的检查验证模块: 原版本导包: from sklearn.cross_validation import cross_val_score 导包报错: 模块继承在cross_va ...

随机推荐

  1. MyEclipse不能重新发布的解决方案

    myeclipse2015已发布项目上右键clear不重新发布的解决方案: 该项目在server.xml中没有设置自动发布reloadable="true"

  2. 累积进度图及本周PSP饼状图

    每周进度   项目:词频统计  项目类型:个人项目 项目完成情况:已完成 C类别 C内容 S开始时间 E结束时间 I间隔 T净时间 分析 需求,设计 10:00 10:49 20 29 编码 代码的实 ...

  3. javascript大神修炼记(7)——OOP思想(多态)

    读者朋友们大家好,今天我们就接着前面的内容讲,前面我们已经讲到了继承,今天我们就来讲OOP目前最后一个体现,那就是多态,因为javascript语言的灵活性,所以我们是没有办法使用接口的,所以这也给j ...

  4. 20145221高其&20145326蔡馨熠《信息安全系统设计基础》实验二 固件设计

    20145221高其&20145326蔡馨熠<信息安全系统设计基础>实验二 固件设计 实验目的与要求 了解多线程程序设计的基本原理,学习 pthread 库函数的使用. 了解在 l ...

  5. cacti监控apache和nginx的配置

    一.监控apache1.下载http://forums.cacti.net/about25227.html&highlight=apachestats2.其中的ss_apache_stats. ...

  6. 使用CSS将图片转换成黑白(灰色、置灰)z转

    小tip: 使用CSS将图片转换成黑白(灰色.置灰) by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.c ...

  7. Qt中使用ActiveX(3篇)

    由于最近需要使用ActiveX,一般来说可以使用微软提供的MFC或者ATL框架来开发,由于我个人对这部分内容不是很熟悉,好在Qt也提供对于ActiveX的支持.本文主要记录个人学习ActiveX的一些 ...

  8. [LeetCode]题解(python):119 Pascal's Triangle II

    题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...

  9. 基于docker+etcd+confd + haproxy构建高可用、自发现的web服务

    基于docker+etcd+confd + haproxy构建高可用.自发现的web服务 2016-05-16 15:12 595人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主 ...

  10. mysqldump database table

    一)在同一个数据库服务器上面进行数据表间的数据导入导出: 1. 如果表tb1和tb2的结构是完全一样的,则使用以下的命令就可以将表tb1中的数据导入到表tb2中: insert into db2.tb ...