python constraint 模块

前言

最近了解关于constraint programming方面的问题。即一个问题,有很多限制条件,求个最优解。恩,这种描述方式是很笼统的,不妨具体到我们的问题------Nurse scheduling problem.维基百科nurse scheduling problem

The nurse scheduling problem (NSP), also called the nurse rostering problem (NRP), is the operations research problem of finding an optimal way to assign nurses to shifts, typically with a set of hard constraints which all valid solutions must follow, and a set of soft constraints which define the relative quality of valid solutions.[1] Solutions to the nurse scheduling problem can be applied to constrained scheduling problems in other fields.[2][3][4]

The nurse scheduling problem has been studied since before 1969,[5] and is known to have NP-hard complexity.

问题说明

前面说了问题有a set of hard constraits and soft constraits。像如下的是硬性要求:

  • A nurse does not work the day shift, night shift and late night shift on the same day (for obvious reasons).

       A nurse may go on a holiday and will not work shifts during this time。

       A nurse does not do a late night shift followed by a day shift the next day

软要求则如:

Soft constraints may include minimum and maximum numbers of shifts assigned to a given nurse in a given week, of hours worked per week, of days worked consecutively, of days off consecutively, and so on.

遗传算法解空间

我们在应用遗传算法这种启发式算法时,有一个很重要的概念群,即是解空间。相信大家在讨论编码问题时,会遇到这个相关的概念。首先,我们要明确解空间是什么范围,我们初始化时,开始的解是解空间随便的几个量;同时我们也要保证我们的一些算子得到的新的个体也是在解空间中的,不能超出解空间,不然得到结果可能在解空间外。

遗传算法的crossover

1,Single-point

2,Two-point

3,uniform and half uniform

评价,这个算法交叉过程并没有详细写,只是说交换“A single crossover point on both parents' organism strings is selected”,至于这个point是啥,说的很模糊。这里处理的单位应该是单个基因,此种理解生物上好解释些。那么,对应护士的排课表,就是单个时间段的课,某一节课。连续上的两节课,是两个基因片段。这样交叉就不会出现脱离解空间的情况了。

猜你喜欢

转载自blog.csdn.net/tortelee/article/details/79312454
今日推荐