线性规划条件约束

问题描述 投票:0回答:1

有22名司机。每个驾驶员必须工作最少7.6小时,最多可以工作10小时。每个驱动器的成本和生产率都不同。

如果一些司机加班(超过7.6小时),前2小时,我们需要支付1.5倍。剩余0.4小时,我们需要支付2次。

22名司机必须完成195小时的工作。我们需要以这样的方式安排成本可以最小化。

Driver,Cost,Productivity
A,70,0.8
B,22,0.8
C,24,0.8
D,26,0.8
E,28,0.8
F,30,0.8
G,32,0.8
H,34,0.8
I,36,0.8
J,38,0.8
K,40,0.8
L,42,0.9
M,44,0.9
N,46,0.9
O,48,0.9
P,50,0.9
Q,52,0.9
R,54,0.9
S,56,0.9
T,58,0.9
U,60,0.9
V,62,0.5

决策变量:

X1,X2 ........ X22表示分配给每个驱动程序的总小时数

目标功能:

最小Z = 20 * X1 + 22 * X2 ...... 62 * X22

约束:

X1> = 7.6,X2> = 7.6 .... X22> = 7.6

X1 <= 10,X2 <= 10 .... X22 <= 10

X1 + X2 ..... + X22 <= 195

我到目前为止尝试过python程序。

import pulp
import pandas as pd


def main():
    model = pulp.LpProblem("Cost minimising scheduling problem", pulp.LpMinimize)

    totalHours = 192
    minHourEachDriver = 7.6
    maxHourEachDriver = 10

    # importing data from CSV

    drivers = pd.DataFrame.from_csv('csv/drivers.csv', index_col=['Driver', 'Cost', 'Productivity'])

    # Decision Variables
    drv = pulp.LpVariable.dicts("driverName", indexs=((i) for i, j, k in drivers.index), lowBound=0,
                                cat='Continuous')

    # Objective
    model += pulp.lpSum([j * (1 / k) * drv[i] for i, j, k in drivers.index]), "Cost"

    # Constraints

    # total no of hours work to be done
    model += pulp.lpSum([drv[i] for i, j, k in drivers.index]) == totalHours

    for i, j, k in drivers.index:
        # minimum hours driver has to work
        model += drv[i] >= minHourEachDriver
        # Maximum hour driver can work
        model += drv[i] <= maxHourEachDriver

    model.solve()

    # model status
    print(pulp.LpStatus[model.status])

    # Total Cost
    print(pulp.value(model.objective))

    # No of hrs allocated to each driver

    for i, j, k in drivers.index:
        var_value = drv[i].varValue
        # print(var_value)
        print("The number hours for driver {0} are {1}".format(i, var_value))


if __name__ == '__main__':
    main()

但是,我无法弄清楚,我们如何设置以下约束。

如果一些司机加班(超过7.6小时),前2小时,我们需要支付1.5倍。剩余0.4小时,我们需要支付2次。

python-3.x linear-programming pulp
1个回答
1
投票

如果每个驾驶员必须工作7.6h,则无需将其置于条件下。可以从总小时数(成本)中减去静态时间(成本),因为它总是会发生:

195 - (NumDrivers * 7.6)=是需要在驾驶员之间灵活分配的剩余时间,因为他们的加班时间达到195小时(总小时数> NumDrivers * 7,6)。

我会用两个变量表示每个驱动程序(一个用于1.5速率工作,第二个工作时间以双倍速率工作)并制作以下​​LP:

Xij =表示在j-working模式下分配给i-driver的小时数(假设j = 1表示1,5,j = 2表示2)

根据提供的输入文件:


g = 70 * 1,x * x 11 + 70 * a * x 12 + 22 * 1,x * x 1 + 22 * a *衣服+ ......

约束:

X11 + X12 + X21 + X22 + ... X221 + X222 = 27,8(195 - (22 * 7,6))

X11 + X12 <= 3,4 X21 + X22 <= 3,4 ... X221 + X222 <= 3,4

X11 <= 2 X21 <= 2 ... X221 <= 2

为了完整性,还应该有一组条件表示每个驱动程序只能在1.5 *完成2小时后以j模式(2 *)开始,但在这种情况下,目标函数应自动生成。

© www.soinside.com 2019 - 2024. All rights reserved.