司守奎《数学建模算法与应用》第二版 第一章线性规划习题答案

司守奎《数学建模算法与应用》第二版 第一章线性规划习题答案

文章目录


1.1

在这里插入图片描述

from scipy.optimize import linprog
import numpy as np

if __name__ == "__main__":
    c = np.array([-3, 1, 1])
    A = np.array([[1, -2, 1], [4, -1, -2]])
    b = np.array([[11, -3]]).T
    Aeq = np.array([[-2, 0, 1]])
    beq = 1
    lb = np.zeros(3)
    ub = np.array([[None] * 3])
    bound = np.vstack((lb, ub)).T

    res = linprog(c, A, b, Aeq, beq, bound)
    print("最优值为", -res.fun)
    print("最优解为", res.x)

# output:最优值为 2.0
# 最优解为 [4. 1. 9.]

1.2

在这里插入图片描述
做变换 u i = ∣ x i ∣ + x i 2 , v i = ∣ x i ∣ − x i 2 , i = 1 , 2 , 3 , 4 u_i=\frac{|x_i|+x_i}{2},v_i=\frac{|x_i|-x_i}{2},i=1,2,3,4 ui=2xi+xi,vi=2xixi,i=1,2,3,4,可以得到
min ⁡   z = u 1 + v 1 + 2 ( u 2 + v 2 ) + 3 ( u 3 + v 3 ) + 4 ( u 4 + v 4 ) s . t . { u 1 − v 1 − ( u 2 − v 2 ) − ( u 3 − v 3 ) + u 4 − v 4 = 0 u 1 − v 1 − ( u 2 − v 2 ) + u 3 − v 3 − 3 ( u 4 − v 4 ) = 1 u 1 − v 1 − ( u 2 − v 2 ) − 2 ( u 3 − v 3 ) + 3 ( u 4 − v 4 ) = − 1 2 u i , v i ≥ 0 , i = 1 , 2 , 3 , 4 \min\ z=u_1+v_1+2(u_2+v_2)+3(u_3+v_3)+4(u_4+v_4)\\ \begin{equation} s.t. \begin{cases} u_1-v_1-(u_2-v_2)-(u_3-v_3)+u_4-v_4=0\\ u_1-v_1-(u_2-v_2)+u_3-v_3-3(u_4-v_4)=1\\ u_1-v_1-(u_2-v_2)-2(u_3-v_3)+3(u_4-v_4)=-\frac{1}{2}\\ u_i,v_i\geq 0,&i=1,2,3,4 \end{cases} \end{equation} min z=u1+v1+2(u2+v2)+3(u3+v3)+4(u4+v4)s.t. u1v1(u2v2)(u3v3)+u4v4=0u1v1(u2v2)+u3v33(u4v4)=1u1v1(u2v2)2(u3v3)+3(u4v4)=21ui,vi0,i=1,2,3,4

from scipy.optimize import linprog
import numpy as np

if __name__ == "__main__":
    c = np.array([1, 2, 3, 4])
    c = np.append(c, c, axis=0)
    Aeq = np.array([[1, -1, -1, 1], [1, -1, 1, -3], [1, -1, -2, 3]])
    Aeq = np.append(Aeq, -Aeq, axis=1)
    beq = np.array([[0, 1, -1 / 2]]).T
    lb = np.zeros(8)
    ub = np.array([[None] * 8])
    bound = np.vstack((lb, ub)).T
    res = linprog(c, A_ub=None, b_ub=None, A_eq=Aeq, b_eq=beq, bounds=bound)

    print("最优值为", res.fun)
    print("最优解为", res.x[:4] - res.x[4:])

# output:最优值为 1.25
# 最优解为 [ 0.25  0.    0.   -0.25]

1.3

在这里插入图片描述
假设 I I I产品需要 A 1 A_1 A1工序 x 1 x_1 x1次, A 2 A_2 A2工序 x 2 x_2 x2次,需要 B 1 B_1 B1工序 x 3 x_3 x3次, B 2 B_2 B2工序 x 4 x_4 x4次, B 3 B_3 B3工序 x 5 x_5 x5次; I I II II差产品需要 A 1 A_1 A1工序 x 6 x_6 x6次, A 2 A_2 A2工序 x 7 x_7 x7次, B 1 B_1 B1工序 x 8 x_8 x8次; I I I III III产品需要 A 2 A_2 A2工序 x 9 x_9 x9次, B 2 B_2 B2工序 x 10 x_{10} x10次。则由题意可得
max ⁡  总利润 = ( 1.25 − 0.25 ) ( x 1 + x 2 ) + ( 2 − 0.35 ) x 8 + ( 2.8 − 0.5 ) x 9 − 300 6000 ( 5 x 1 + 10 x 6 ) − 321 10000 ( 7 x 2 + 9 x 7 + 12 x 9 ) − 250 4000 ( 6 x 3 + 8 x 8 ) − 783 7000 ( 4 x 4 + 11 x 10 ) s . t . { 5 x 1 + 10 x 6 ≤ 6000 7 x 2 + 9 x 7 + 12 x 9 ≤ 10000 6 x 3 + 8 x 8 ≤ 4000 4 x 4 + 11 x 10 ≤ 7000 7 x 5 ≤ 4000 x 1 + x 2 ≥ 1 x 8 ≥ 1 x 9 = x 10 ≥ 1 x i ≥ 0 , i = 1 , 2 , 3 , 4 , 5 , 6 , 7 x 1 + x 2 = x 3 + x 4 + x 5 x 6 + x 7 = x 8 \max\ 总利润=(1.25-0.25)(x_1+x_2)+(2-0.35)x_8+(2.8-0.5)x_9-\frac{300}{6000}(5x_1+10x_6)-\frac{321}{10000}(7x_2+9x_7+12x_9)-\frac{250}{4000}(6x_3+8x_8)-\frac{783}{7000}(4x_4+11x_{10})\\ \begin{equation} s.t. \begin{cases} 5x_1+10x_6\leq 6000\\ 7x_2+9x_7+12x_9\leq 10000\\ 6x_3+8x_8\leq 4000\\ 4x_4+11x_{10}\leq 7000\\ 7x_5\leq 4000\\ x_1+x_2\geq 1\\ x_8\geq 1\\ x_9=x_{10}\geq 1\\ x_i\geq 0,&i=1,2,3,4,5,6,7\\ x_1+x_2=x_3+x_4+x_5\\ x_6+x_7=x_8\\ \end{cases} \end{equation} max 总利润=(1.250.25)(x1+x2)+(20.35)x8+(2.80.5)x96000300(5x1+10x6)10000321(7x2+9x7+12x9)4000250(6x3+8x8)7000783(4x4+11x10)s.t. 5x1+10x660007x2+9x7+12x9100006x3+8x840004x4+11x1070007x54000x1+x21x81x9=x101xi0,x1+x2=x3+x4+x5x6+x7=x8i=1,2,3,4,5,6,7

from scipy.optimize import linprog
import numpy as np

if __name__ == "__main__":
    x1 = (1.25 - 0.25) - 300 * 5 / 6000
    x2 = (1.25 - 0.25) - 321 * 7 / 10000
    x3 = -250 * 6 / 4000
    x4 = -783 * 4 / 7000
    x5 = -200 * 7 / 4000
    x6 = -300 * 10 / 6000
    x7 = -321 * 9 / 10000
    x8 = (2 - 0.35) - 250 * 8 / 4000
    x9 = (2.8 - 0.5) - 321 * 12 / 10000
    x10 = -783 * 11 / 7000

    c = np.array(
        [-x1, -x2, -x3, -x4, -x5, -x6, -x7, -x8, -x9, -x10]
    )  # 由于求的是最大值,所以需要取相反数
    A = np.array(
        [
            [5, 0, 0, 0, 0, 10, 0, 0, 0, 0],
            [0, 7, 0, 0, 0, 0, 9, 0, 12, 0],
            [0, 0, 6, 0, 0, 0, 0, 8, 0, 0],
            [0, 0, 0, 4, 0, 0, 0, 0, 0, 11],
            [0, 0, 0, 0, 7, 0, 0, 0, 0, 0],
            [-1, -1, 0, 0, 0, 0, 0, 0, 0, 0],
        ]
    )
    b = np.array([[6000, 10000, 4000, 7000, 4000, -1]]).T
    Aeq = np.array(
        [
            [1, 1, -1, -1, -1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 1, -1, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 1, -1],
        ]
    )
    beq = np.array([[0, 0, 0]]).T
    lb = np.array([0, 0, 0, 0, 0, 0, 0, 1, 1, 1])
    ub = np.array([[None] * 10])
    bound = np.vstack((lb, ub)).T

    res = linprog(
        c, A, b, Aeq, beq, bound, integrality=1
    )  # linprog也可以求整数规划问题,其中参数integrality=1表示决策变量必须为整数
    print("最优值为", -res.fun)
    print("最优解为", res.x)

# output:最优值为 1146.4142
# 最优解为 [1200.  230.    0.  859.  571.    0.  500.  500.  324.  324.]

1.4

在这里插入图片描述

假设前舱装了货物1 x 1 x_1 x1,货物2 x 2 x_2 x2,货物3 x 3 x_3 x3,货物4 x 4 x_4 x4;中仓装了货物1 x 5 x_5 x5,货物2 x 6 x_6 x6,货物3 x 7 x_7 x7,货物4 x 8 x_8 x8;后舱装了货物1 x 9 x_9 x9,货物2 x 10 x_{10} x10,货物3 x 11 x_{11} x11,货物4 x 12 x_{12} x12。由题意可得
max ⁡  总利润 = 3100 ( x 1 + x 5 + x 9 ) + 3800 ( x 2 + x 6 + x 10 ) + 2500 ( x 3 + x 7 + x 11 ) + 2850 ( x 4 + x 8 + x 12 ) s . t . { x 1 + x 2 + x 3 + x 4 ≤ 10 x 5 + x 6 + x 7 + x 8 ≤ 16 x 9 + x 10 + x 11 + x 12 ≤ 8 480 x 1 + 650 x 2 + 580 x 3 + 390 x 4 ≤ 6800 480 x 5 + 650 x 6 + 580 x 7 + 390 x 8 ≤ 8700 480 x 9 + 650 x 10 + 580 x 11 + 390 x 12 ≤ 5300 x 1 + x 5 + x 9 ≤ 18 x 2 + x 6 + x 10 ≤ 15 x 3 + x 7 + x 11 ≤ 23 x 4 + x 8 + x 12 ≤ 12 x 1 + x 2 + x 3 + x 4 10 = x 5 + x 6 + x 7 + x 8 16 = x 9 + x 10 + x 11 + x 12 8 x i ≥ 0 , i = 1 , 2 , . . . , 12 \max\ 总利润=3100(x_1+x_5+x_9)+3800(x_2+x_6+x_{10})+2500(x_3+x_7+x_{11})+2850(x_4+x_8+x_{12})\\ \begin{equation} s.t. \begin{cases} x_1+x_2+x_3+x_4\leq 10\\ x_5+x_6+x_7+x_8\leq 16\\ x_9+x_{10}+x_{11}+x_{12}\leq 8\\ 480x_1+650x_2+580x_3+390x_4\leq 6800\\ 480x_5+650x_6+580x_7+390x_8\leq 8700\\ 480x_9+650x_{10}+580x_{11}+390x_{12}\leq 5300\\ x_1+x_5+x_9\leq 18\\ x_2+x_6+x_{10}\leq 15\\ x_3+x_7+x_{11}\leq 23\\ x_4+x_8+x_{12}\leq 12\\ \frac{x_1+x_2+x_3+x_4}{10}=\frac{x_5+x_6+x_7+x_8}{16}=\frac{x_9+x_{10}+x_{11}+x_{12}}{8}\\ x_i\geq 0,& i=1,2,...,12 \end{cases} \end{equation} max 总利润=3100(x1+x5+x9)+3800(x2+x6+x10)+2500(x3+x7+x11)+2850(x4+x8+x12)s.t. x1+x2+x3+x410x5+x6+x7+x816x9+x10+x11+x128480x1+650x2+580x3+390x46800480x5+650x6+580x7+390x88700480x9+650x10+580x11+390x125300x1+x5+x918x2+x6+x1015x3+x7+x1123x4+x8+x121210x1+x2+x3+x4=16x5+x6+x7+x8=8x9+x10+x11+x12xi0,i=1,2,...,12

from scipy.optimize import linprog
import numpy as np

if __name__ == "__main__":
    c = np.array([-3100, -3800, -3500, -2850] * 3)
    A = np.array(
        [
            [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
            [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
            [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],
            [480, 650, 580, 390, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 480, 650, 580, 390, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 480, 650, 580, 390],
        ]
    )
    b = np.array([[10, 16, 8, 18, 15, 23, 12, 6800, 8700, 5300]]).T
    Aeq = np.array(
        [
            [16, 16, 16, 16, -10, -10, -10, -10, 0, 0, 0, 0],
            [0, 0, 0, 0, 8, 8, 8, 8, -16, -16, -16, -16],
            [8, 8, 8, 8, 0, 0, 0, 0, -10, -10, -10, -10],
        ]
    )
    beq = np.array([[0, 0, 0]]).T
    lb = np.zeros(12)
    ub = np.array([[None] * 12])
    bound = np.vstack((lb, ub)).T

    res = linprog(c, A, b, Aeq, beq, bound)
    print("最优解为", res.x)
    print("最优值为", -res.fun)

# output:最优解为 [ 0.          7.          3.          0.          0.          0.
#  12.94736842  3.05263158  0.          8.          0.          0.        ]
# 最优值为 121515.78947368421
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值