列生成算法

文章介绍了如何用Python编程实现对偶单纯形法和列生成算法来解决整数规划问题。首先展示了对偶单纯形法的代码,然后详细解释了列生成算法的过程,包括初始化、迭代求解子问题和计算最佳方案。最后,通过实例展示了算法的运行结果,给出了最优解和方案选择。
摘要由CSDN通过智能技术生成

列生成算法

一、声明

本文前篇分析摘抄自博客园一位短短的路走走停停的作者,前篇分析中有些许错误,笔者已在程序中改正,即初始方案中,方案2改成切成3个5m长的纸卷,以及纸卷长度限制是17而非是16,并且在最后结果中,共有六个方案集合,利用整数规划方法求解最后的方案集合即可得到最优方案组。

二、例题

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fHIDYaMo-1683195341597)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230504171441483.png)]
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1、对偶单纯形法代码实现

import pandas as pd, numpy as np


# 求最小问题的对偶单纯形法
class Dual_Simplex_Method_minimize(object):
    # 初始化表,将已经标准化的原问题的A0,b0,输入进来
    def __init__(self, A0, b0, ci):
        # 初始化
        self.A0 = A0
        self.b0 = b0
        self.ci = ci
        # 获取行列数
        self.index_nums = len(self.A0)  # 行数
        self.columns_nums = len(self.A0[0])  # 列数
        # 获取增广矩阵
        self.ci_up = self.get_ci_up()
        self.data = self.form_data()  # 矩阵形式的data,初始数据
        # 初始化表,将原表取负后的表
        self.Simplex_table = pd.DataFrame(
            data=self.update_data(),  # 取负后更新过的数据
            index=self.get_index(),
            columns=self.get_columns()
        )
        self.Simplex_table = self.doo(self.Simplex_table)

    # 获取ci的增广矩阵
    def get_ci_up(self):
        self.ci.insert(0, 0)
        return self.ci

    # 矩阵的拼接,形成data数据表
    def form_data(self):
        bi = 0
        for list in self.A0:
            list.insert(0, self.b0[bi])
            bi += 1
        self.A0.append(self.ci_up)
        return self.A0

    # 获取单纯形表的行标签
    def get_index(self):
        index = [f'x{j + 1 + (self.columns_nums - self.index_nums)}' for j in range(self.index_nums)]
        index.append('cgm')
        return index

    # 获取单纯形表的列标签
    def get_columns(self):
        columns = [f'x{i + 1}' for i in range(self.columns_nums)]
        columns.insert(0, 'b')
        return columns

    # 最大值转最小值,更新单纯形表数据
    def update_data(self):
        data_update = -1 * np.array(self.data)
        return data_update

    # 定义推进函数
    def doo(self, Simplex_table):
        k = 0
        print('初始对偶单纯形表为:')
        print(Simplex_table)
        # 判断b是否小于0,否则,则为最优解
        b_min = Simplex_table.iloc[:self.index_nums, 0].min()
        while b_min < 0:
            # 确定出基变量
            x_out = Simplex_table.iloc[:self.index_nums, 0].idxmin()  # 最小的b出基
            # 确定进基变量
            cta = []
            series_index = []
            for i in range(1, self.columns_nums + 1):
                if Simplex_table.loc[x_out, f'x{i}'] < 0:
                    cta.append(Simplex_table.loc['cgm', f'x{i}'] / Simplex_table.loc[x_out, f'x{i}'])
                    series_index.append(f'x{i}')
            x_in_index = cta.index(min(cta))
            x_in = series_index[x_in_index]
            # 行初等变化
            # 出基行除以对应位化为1
            Simplex_table.loc[x_out] = (Simplex_table.loc[x_out]) / Simplex_table.loc[x_out, x_in]
            for x in (Simplex_table.index).tolist():
                if x != x_out:
                    Simplex_table.loc[x] = Simplex_table.loc[x] - Simplex_table.loc[x_out] * \
                                           Simplex_table.loc[x, x_in]
            # 交换出基进基变量标签,即更新表格行标签,将进基变量和出基变量的位置对调
            out_x_list = Simplex_table.index.tolist()
            out_x_index = out_x_list.index(x_out)
            out_x_list[out_x_index] = x_in
            Simplex_table.index = out_x_list
            k += 1
            b_min = Simplex_table.iloc[:self.index_nums, 0].min()
            print(f'第{k}次单纯形表为:')
            print(Simplex_table)
            if i == 999:
                print("该问题无解或因退化暂时无法解决")
                return 0

        return Simplex_table


# 脚本自调试
if __name__ == '__main__':
    # 写入化为标准型后的约束系数矩阵,资源系数矩阵和价值系数矩阵(填最开始的ci)
    # 两阶段法
    initial_A = [[5, 0, 0, -1, 0, 0],
                 [0, 2, 0, 0, -1, 0],
                 [0, 0, 2, 0, 0, -1]]
    c = [1, 1, 1, 0, 0, 0]
    b = [25, 20, 18]
    # 实例化对象
    test = Dual_Simplex_Method_minimize(initial_A, b, c)
    print(f"最优解为\n{test.Simplex_table.iloc[:-1, 0]}")
    print(f'最优化结果为{test.Simplex_table.iloc[-1, 0]}')

2、列生成代码实现

import numpy as np, DualSimplexMethod_Min, copy, pulp as pp, pandas as pd


# 列生成算法
class Columns_Generator(object):
    # 定义初始化函数
    def __init__(self, initial_A, b, c):
        self.initial_A = initial_A
        self.b = b
        self.c = c

    # 获取CB*B-1,对偶变量
    def get_w_list(self, initial_A, b, c):
        # 对偶单纯形法求解出对偶变量(松弛变量的检验数)
        res = DualSimplexMethod_Min.Dual_Simplex_Method_minimize(initial_A, b, c)
        # 获取CB*B-1,对偶变量
        w_list = -res.Simplex_table.loc['cgm'][-(len(res.Simplex_table.index.tolist()) - 1):]
        w_list = w_list.tolist()
        return w_list

    # 求解整数规划,constraint_type==‘<=’,不等式约束为小于等于
    def integerPro(self, A_gq, b_gq, c, constraint_type, objective_function_type="MAX"):
        # 确定最大最小化问题,默认求解最大化问题
        if objective_function_type.upper() == "MAX":
            m = pp.LpProblem(sense=pp.LpMaximize)
        elif objective_function_type.upper() == "MIN":
            m = pp.LpProblem(sense=pp.LpMinimize)
        # 定义决策变量放到列表中 生成x1 x2 x3……
        x = [pp.LpVariable(f'x{i + 1}', lowBound=0, cat='Integer') for i in range(len(A_gq[0]))]
        # 定义目标函数,并将目标函数加入求解的问题中
        m += pp.lpDot(c, x)  # lpDot 用于计算点积
        # 设置比较条件(根据输入判断不等式约束类型)
        if constraint_type == '<=':
            for i in range(len(A_gq)):  # 大于等于
                m += (pp.lpDot(A_gq[i], x) <= b_gq[i])
        elif constraint_type == '>=':
            for i in range(len(A_gq)):  # 大于等于
                m += (pp.lpDot(A_gq[i], x) >= b_gq[i])
        # 求解
        m.solve()
        # 返回值一个为目标函数的方程,如:0.2 * x1 + 0.5 * x2 + 0.5 * x3 + 0.0,另一个为列表类型,代表子问题每一个决策变量的取值,如:[1.0, 2.0, 0.0]
        return [m.objective, [pp.value(var) for var in x]]

    # 列生成子问题求解
    def solve_subproblem(self, required_size, required_number):
        # 深拷贝,因为后面要将新生成的方案加入到原方案数组中,避免下面的方法将初始化实例变量改变
        # 初始可行方案数组
        initial_A = copy.deepcopy(self.initial_A)
        # 需求的数量约束系数
        b = copy.deepcopy(self.b)
        # 每种方案的选择个数(子问题目标函数价值系数),已手动标准化
        c = copy.deepcopy(self.c)
        # 输入深拷贝
        objective_w = self.get_w_list(copy.deepcopy(initial_A), copy.deepcopy(b), copy.deepcopy(c))
        # 求解整数规划解
        integer_solve = self.integerPro(A_gq=required_size, b_gq=required_number, c=objective_w, constraint_type='<=')
        # 获取决策变量取值
        integer_value = integer_solve[1]
        # 计算检验数cgm,当cgm小于0时,说明还有更好的方案,继续迭代
        cgm = 1 - np.array(np.matrix(integer_value) * np.matrix(objective_w).T).tolist()[0][0]
        # 进入迭代
        while cgm < 0:
            # 获取去掉标准化增加的单位矩阵的方案数组
            new_A = [list1[:-len(initial_A)] for list1 in initial_A]
            # 生成对角矩阵,对角线元素为-1,因为约束是 >=
            dig1 = (np.array(np.diag([-1 for i in range(len(new_A))]))).tolist()
            k = 0
            # 将整数规划求解出来的方案数量矩阵加入到原方案数组中
            for na in new_A:
                na.append(integer_value[k])
                k += 1
            # 将数组类型变成np矩阵,便于拼接
            new_A_matrix = np.matrix(new_A)
            dig1_matrix = np.matrix(dig1)
            # 将新的方案矩阵和对角阵拼接,自动标准化,以便于输入到对偶单纯形法模块中
            initial_A = np.array(np.hstack((new_A_matrix, dig1_matrix))).tolist()
            c = c[:-len(initial_A)]
            c.append(1)
            for i in range(len(initial_A)):
                c.append(0)
            # 利用对偶单纯形法模块的方法,取出松弛变量的检验数cgm
            objective_w = self.get_w_list(copy.deepcopy(initial_A), copy.deepcopy(b), copy.deepcopy(c))
            # 利用integerPro函数求解整数规划解,返回值一个为目标函数的方程,如:0.2*x1 + 0.5*x2 + 0.5*x3 + 0.0,另一个为列表类型,代表子问题每一个决策变量的取值,如:[1.0, 2.0, 0.0]
            integer_solve = self.integerPro(A_gq=required_size, b_gq=required_number, c=objective_w,
                                            constraint_type='<=')
            # 获取决策变量取值
            integer_value = integer_solve[1]
            # 计算检验数cgm,判断是否需要继续迭代
            cgm = 1 - np.array(np.matrix(integer_value) * np.matrix(objective_w).T).tolist()[0][0]
        # 迭代完成后,获取去掉标准化加上的对角矩阵,获得方案数组
        initial_A = [list1[:-len(initial_A)] for list1 in initial_A]
        # 获取每个方案对应的
        c = c[:-len(initial_A)]
        # 利用整数规划方法计算出最后的方案组对应的最佳方案个数选择,使得目标函数值最小,即损耗最小
        res = self.integerPro(initial_A, b, c, ">=", "min")
        # 将方案数组转换成dataframe数据类型
        scheme_df = pd.DataFrame(np.array(initial_A), columns=[f"方案{i + 1}" for i in range(len(initial_A[0]))])
        # 第一个返回值为最佳方案个数选择,第二个为方案表格
        return [res, scheme_df]


# 脚本自调试
if __name__ == '__main__':
    # 初始可行方案(初始可行基),需要手动标准化,一个方案完成一个需求尺寸,显然是最差的方案
    initial_A = [[5, 0, 0, -1, 0, 0],
                 [0, 3, 0, 0, -1, 0],
                 [0, 0, 2, 0, 0, -1]]
    # 表示第 j 种方案选择个数的系数(子问题目标函数价值系数,均为1),需要手动标准化
    c = [1, 1, 1, 0, 0, 0]
    # 需求的数量约束系数
    b = [25, 20, 18]
    test1 = Columns_Generator(initial_A, b, c)
    # 需求的尺寸约束系数(每个方案对应的切法,一个方案完成一个需求尺寸,显然是最差的方案)
    requiresize = [[3, 5, 7]]
    # 卷钢长度约束
    requirenumber = [17]
    # 深拷贝,避免可变变量被函数改变
    required_size = copy.deepcopy(requiresize)
    required_number = copy.deepcopy(requirenumber)
    res = test1.solve_subproblem(required_size, required_number)
    # 输出迭代出的方案矩阵
    strs = "*" * 20
    res_df = res[1]
    print(f"{strs}迭代生成得到的方案表格为{strs}\n{res_df}")
    print(f"{strs}每种方案的选择个数对应如下{strs}\n{res[0][1]}")
    # 格式化输出
    k = 0
    for option in res[0][1]:
        k += 1
        if option != 0:
            print(f"方案{k}:选择{int(option)}次")

输出结果展示

初始对偶单纯形表为:
      b  x1  x2  x3  x4  x5  x6
x4  -25  -5   0   0   1   0   0
x5  -20   0  -3   0   0   1   0
x6  -18   0   0  -2   0   0   1
cgm   0  -1  -1  -1   0   0   0
第1次单纯形表为:
        b   x1   x2   x3   x4   x5   x6
x1    5.0  1.0 -0.0 -0.0 -0.2 -0.0 -0.0
x5  -20.0  0.0 -3.0  0.0  0.0  1.0  0.0
x6  -18.0  0.0  0.0 -2.0  0.0  0.0  1.0
cgm   5.0  0.0 -1.0 -1.0 -0.2  0.0  0.0
第2次单纯形表为:
             b   x1   x2   x3   x4        x5   x6
x1    5.000000  1.0  0.0 -0.0 -0.2 -0.000000 -0.0
x2    6.666667 -0.0  1.0 -0.0 -0.0 -0.333333 -0.0
x6  -18.000000  0.0  0.0 -2.0  0.0  0.000000  1.0
cgm  11.666667  0.0  0.0 -1.0 -0.2 -0.333333  0.0
第3次单纯形表为:
             b   x1   x2   x3   x4        x5   x6
x1    5.000000  1.0  0.0  0.0 -0.2 -0.000000 -0.0
x2    6.666667 -0.0  1.0  0.0 -0.0 -0.333333 -0.0
x3    9.000000 -0.0 -0.0  1.0 -0.0 -0.000000 -0.5
cgm  20.666667  0.0  0.0  0.0 -0.2 -0.333333 -0.5
Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

command line - C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\pulp\solverdir\cbc\win\64\cbc.exe C:\Users\ADMINI~1\AppData\Local\Temp\5732295859de44538fb220141efd093f-pulp.mps max timeMode elapsed branch printingOptions all solution C:\Users\ADMINI~1\AppData\Local\Temp\5732295859de44538fb220141efd093f-pulp.sol
At line 2 NAME          MODEL
At line 3 ROWS
At line 6 COLUMNS
At line 19 RHS
At line 21 BOUNDS
At line 25 ENDATA
Problem MODEL has 1 rows, 3 columns and 3 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Continuous objective value is 1.21429 - 0.00 seconds
Cgl0004I processed model has 1 rows, 3 columns (3 integer (0 of which binary)) and 3 elements
Cbc0012I Integer solution of -1.2 found by DiveCoefficient after 0 iterations and 0 nodes (0.00 seconds)
Cbc0001I Search completed - best objective -1.2, took 0 iterations and 0 nodes (0.00 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from -1.2 to -1.2
Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
ZeroHalf was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Optimal solution found

Objective value:                1.20000000
Enumerated nodes:               0
Total iterations:               0
Time (CPU seconds):             0.00
Time (Wallclock seconds):       0.00

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.00   (Wallclock seconds):       0.00

初始对偶单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7
x5  -25.0 -5.0 -0.0 -0.0 -1.0  1.0 -0.0 -0.0
x6  -20.0 -0.0 -3.0 -0.0 -0.0 -0.0  1.0 -0.0
x7  -18.0 -0.0 -0.0 -2.0 -2.0 -0.0 -0.0  1.0
cgm  -0.0 -1.0 -1.0 -1.0 -1.0 -0.0 -0.0 -0.0
第1次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7
x1    5.0  1.0  0.0  0.0  0.2 -0.2  0.0  0.0
x6  -20.0  0.0 -3.0  0.0  0.0 -0.0  1.0  0.0
x7  -18.0  0.0  0.0 -2.0 -2.0 -0.0  0.0  1.0
cgm   5.0  0.0 -1.0 -1.0 -0.8 -0.2  0.0  0.0
第2次单纯形表为:
             b   x1   x2   x3   x4   x5        x6   x7
x1    5.000000  1.0  0.0  0.0  0.2 -0.2  0.000000  0.0
x2    6.666667 -0.0  1.0 -0.0 -0.0  0.0 -0.333333 -0.0
x7  -18.000000  0.0  0.0 -2.0 -2.0 -0.0  0.000000  1.0
cgm  11.666667  0.0  0.0 -1.0 -0.8 -0.2 -0.333333  0.0
第3次单纯形表为:
             b   x1   x2   x3   x4   x5        x6   x7
x1    3.200000  1.0  0.0 -0.2  0.0 -0.2  0.000000  0.1
x2    6.666667 -0.0  1.0  0.0  0.0  0.0 -0.333333 -0.0
x4    9.000000 -0.0 -0.0  1.0  1.0  0.0 -0.000000 -0.5
cgm  18.866667  0.0  0.0 -0.2  0.0 -0.2 -0.333333 -0.4
Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

command line - C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\pulp\solverdir\cbc\win\64\cbc.exe C:\Users\ADMINI~1\AppData\Local\Temp\39c1f6eeb6b24a9fbbde98eb0a2e1b4f-pulp.mps max timeMode elapsed branch printingOptions all solution C:\Users\ADMINI~1\AppData\Local\Temp\39c1f6eeb6b24a9fbbde98eb0a2e1b4f-pulp.sol
At line 2 NAME          MODEL
At line 3 ROWS
At line 6 COLUMNS
At line 19 RHS
At line 21 BOUNDS
At line 25 ENDATA
Problem MODEL has 1 rows, 3 columns and 3 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Continuous objective value is 1.13333 - 0.00 seconds
Cgl0004I processed model has 1 rows, 3 columns (3 integer (0 of which binary)) and 3 elements
Cbc0012I Integer solution of -1 found by DiveCoefficient after 0 iterations and 0 nodes (0.00 seconds)
Cbc0012I Integer solution of -1.1333333 found by DiveCoefficient after 1 iterations and 0 nodes (0.00 seconds)
Cbc0031I 1 added rows had average density of 3
Cbc0013I At root node, 1 cuts changed objective from -1.1333333 to -1.1333333 in 2 passes
Cbc0014I Cut generator 0 (Probing) - 2 row cuts average 2.0 elements, 1 column cuts (1 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 1 (Gomory) - 1 row cuts average 3.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 2 (Knapsack) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 4 (MixedIntegerRounding2) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 5 (FlowCover) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0001I Search completed - best objective -1.1333333333333, took 1 iterations and 0 nodes (0.00 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from -1.13333 to -1.13333
Probing was tried 2 times and created 3 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 2 times and created 1 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
ZeroHalf was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Optimal solution found

Objective value:                1.13333333
Enumerated nodes:               0
Total iterations:               1
Time (CPU seconds):             0.00
Time (Wallclock seconds):       0.00

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.01   (Wallclock seconds):       0.01

初始对偶单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8
x6  -25.0 -5.0 -0.0 -0.0 -1.0 -4.0  1.0 -0.0 -0.0
x7  -20.0 -0.0 -3.0 -0.0 -0.0 -1.0 -0.0  1.0 -0.0
x8  -18.0 -0.0 -0.0 -2.0 -2.0 -0.0 -0.0 -0.0  1.0
cgm  -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.0 -0.0 -0.0
第1次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8
x1    5.0  1.0  0.0  0.0  0.2  0.8 -0.2  0.0  0.0
x7  -20.0  0.0 -3.0  0.0  0.0 -1.0 -0.0  1.0  0.0
x8  -18.0  0.0  0.0 -2.0 -2.0  0.0 -0.0  0.0  1.0
cgm   5.0  0.0 -1.0 -1.0 -0.8 -0.2 -0.2  0.0  0.0
第2次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8
x1  -11.0  1.0 -2.4  0.0  0.2  0.0 -0.2  0.8  0.0
x5   20.0 -0.0  3.0 -0.0 -0.0  1.0  0.0 -1.0 -0.0
x8  -18.0  0.0  0.0 -2.0 -2.0  0.0 -0.0  0.0  1.0
cgm   9.0  0.0 -0.4 -1.0 -0.8  0.0 -0.2 -0.2  0.0
第3次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8
x1  -12.8  1.0 -2.4 -0.2  0.0  0.0 -0.2  0.8  0.1
x5   20.0 -0.0  3.0  0.0  0.0  1.0  0.0 -1.0 -0.0
x4    9.0 -0.0 -0.0  1.0  1.0 -0.0  0.0 -0.0 -0.5
cgm  16.2  0.0 -0.4 -0.2  0.0  0.0 -0.2 -0.2 -0.4
第4次单纯形表为:
             b        x1   x2        x3   x4   x5        x6        x7        x8
x2    5.333333 -0.416667  1.0  0.083333 -0.0 -0.0  0.083333 -0.333333 -0.041667
x5    4.000000  1.250000  0.0 -0.250000  0.0  1.0 -0.250000  0.000000  0.125000
x4    9.000000 -0.000000  0.0  1.000000  1.0 -0.0  0.000000 -0.000000 -0.500000
cgm  18.333333 -0.166667  0.0 -0.166667  0.0  0.0 -0.166667 -0.333333 -0.416667
Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

command line - C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\pulp\solverdir\cbc\win\64\cbc.exe C:\Users\ADMINI~1\AppData\Local\Temp\a373ac61ef1b47a4af891c618d178de1-pulp.mps max timeMode elapsed branch printingOptions all solution C:\Users\ADMINI~1\AppData\Local\Temp\a373ac61ef1b47a4af891c618d178de1-pulp.sol
At line 2 NAME          MODEL
At line 3 ROWS
At line 6 COLUMNS
At line 19 RHS
At line 21 BOUNDS
At line 25 ENDATA
Problem MODEL has 1 rows, 3 columns and 3 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Continuous objective value is 1.13333 - 0.00 seconds
Cgl0004I processed model has 1 rows, 3 columns (3 integer (0 of which binary)) and 3 elements
Cbc0012I Integer solution of -1 found by DiveCoefficient after 0 iterations and 0 nodes (0.00 seconds)
Cbc0012I Integer solution of -1.0833333 found by DiveCoefficient after 3 iterations and 0 nodes (0.00 seconds)
Cbc0031I 2 added rows had average density of 3
Cbc0013I At root node, 2 cuts changed objective from -1.1190476 to -1.0833333 in 3 passes
Cbc0014I Cut generator 0 (Probing) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 1 (Gomory) - 2 row cuts average 3.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is 1
Cbc0014I Cut generator 2 (Knapsack) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 4 (MixedIntegerRounding2) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 5 (FlowCover) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0001I Search completed - best objective -1.0833333333333, took 3 iterations and 0 nodes (0.00 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from -1.11905 to -1.08333
Probing was tried 3 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 3 times and created 2 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 3 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 3 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 3 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 3 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
ZeroHalf was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Optimal solution found

Objective value:                1.08333333
Enumerated nodes:               0
Total iterations:               3
Time (CPU seconds):             0.00
Time (Wallclock seconds):       0.00

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.01   (Wallclock seconds):       0.00

初始对偶单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8   x9
x7  -25.0 -5.0 -0.0 -0.0 -1.0 -4.0 -0.0  1.0 -0.0 -0.0
x8  -20.0 -0.0 -3.0 -0.0 -0.0 -1.0 -2.0 -0.0  1.0 -0.0
x9  -18.0 -0.0 -0.0 -2.0 -2.0 -0.0 -1.0 -0.0 -0.0  1.0
cgm  -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.0 -0.0 -0.0
第1次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8   x9
x1    5.0  1.0  0.0  0.0  0.2  0.8  0.0 -0.2  0.0  0.0
x8  -20.0  0.0 -3.0  0.0  0.0 -1.0 -2.0 -0.0  1.0  0.0
x9  -18.0  0.0  0.0 -2.0 -2.0  0.0 -1.0 -0.0  0.0  1.0
cgm   5.0  0.0 -1.0 -1.0 -0.8 -0.2 -1.0 -0.2  0.0  0.0
第2次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8   x9
x1  -11.0  1.0 -2.4  0.0  0.2  0.0 -1.6 -0.2  0.8  0.0
x5   20.0 -0.0  3.0 -0.0 -0.0  1.0  2.0  0.0 -1.0 -0.0
x9  -18.0  0.0  0.0 -2.0 -2.0  0.0 -1.0 -0.0  0.0  1.0
cgm   9.0  0.0 -0.4 -1.0 -0.8  0.0 -0.6 -0.2 -0.2  0.0
第3次单纯形表为:
        b   x1   x2   x3   x4   x5   x6   x7   x8   x9
x1  -12.8  1.0 -2.4 -0.2  0.0  0.0 -1.7 -0.2  0.8  0.1
x5   20.0 -0.0  3.0  0.0  0.0  1.0  2.0  0.0 -1.0 -0.0
x4    9.0 -0.0 -0.0  1.0  1.0 -0.0  0.5  0.0 -0.0 -0.5
cgm  16.2  0.0 -0.4 -0.2  0.0  0.0 -0.2 -0.2 -0.2 -0.4
第4次单纯形表为:
             b        x1        x2        x3  ...   x6        x7        x8        x9
x6    7.529412 -0.588235  1.411765  0.117647  ...  1.0  0.117647 -0.470588 -0.058824
x5    4.941176  1.176471  0.176471 -0.235294  ...  0.0 -0.235294 -0.058824  0.117647
x4    5.235294  0.294118 -0.705882  0.941176  ...  0.0 -0.058824  0.235294 -0.470588
cgm  17.705882 -0.117647 -0.117647 -0.176471  ...  0.0 -0.176471 -0.294118 -0.411765

[4 rows x 10 columns]
Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

command line - C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\pulp\solverdir\cbc\win\64\cbc.exe C:\Users\ADMINI~1\AppData\Local\Temp\6aa0150c1cba45088032accaebc0e339-pulp.mps max timeMode elapsed branch printingOptions all solution C:\Users\ADMINI~1\AppData\Local\Temp\6aa0150c1cba45088032accaebc0e339-pulp.sol
At line 2 NAME          MODEL
At line 3 ROWS
At line 6 COLUMNS
At line 19 RHS
At line 21 BOUNDS
At line 25 ENDATA
Problem MODEL has 1 rows, 3 columns and 3 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Continuous objective value is 1 - 0.00 seconds
Cgl0004I processed model has 1 rows, 3 columns (3 integer (0 of which binary)) and 3 elements
Cbc0012I Integer solution of -1 found by DiveCoefficient after 0 iterations and 0 nodes (0.00 seconds)
Cbc0001I Search completed - best objective -1.0000000000001, took 0 iterations and 0 nodes (0.00 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from -1 to -1
Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
ZeroHalf was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Optimal solution found

Objective value:                1.00000000
Enumerated nodes:               0
Total iterations:               0
Time (CPU seconds):             0.00
Time (Wallclock seconds):       0.00

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.00   (Wallclock seconds):       0.00

Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

command line - C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\pulp\solverdir\cbc\win\64\cbc.exe C:\Users\ADMINI~1\AppData\Local\Temp\fe546406354d458badcb6ec8a58cd382-pulp.mps timeMode elapsed branch printingOptions all solution C:\Users\ADMINI~1\AppData\Local\Temp\fe546406354d458badcb6ec8a58cd382-pulp.sol
At line 2 NAME          MODEL
At line 3 ROWS
At line 8 COLUMNS
At line 36 RHS
At line 40 BOUNDS
At line 47 ENDATA
Problem MODEL has 3 rows, 6 columns and 9 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Continuous objective value is 17.7059 - 0.00 seconds
Cgl0003I 0 fixed, 6 tightened bounds, 0 strengthened rows, 0 substitutions
Cgl0004I processed model has 3 rows, 6 columns (6 integer (0 of which binary)) and 9 elements
Cutoff increment increased from 1e-05 to 0.9999
Cbc0012I Integer solution of 19 found by greedy cover after 0 iterations and 0 nodes (0.00 seconds)
Cbc0012I Integer solution of 18 found by DiveCoefficient after 2 iterations and 0 nodes (0.00 seconds)
Cbc0031I 2 added rows had average density of 6
Cbc0013I At root node, 2 cuts changed objective from 17.705882 to 18 in 2 passes
Cbc0014I Cut generator 0 (Probing) - 0 row cuts average 0.0 elements, 1 column cuts (1 active)  in 0.000 seconds - new frequency is 1
Cbc0014I Cut generator 1 (Gomory) - 3 row cuts average 6.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is 1
Cbc0014I Cut generator 2 (Knapsack) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 4 (MixedIntegerRounding2) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 5 (FlowCover) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0001I Search completed - best objective 18, took 2 iterations and 0 nodes (0.00 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Cuts at root node changed objective from 17.7059 to 18
Probing was tried 2 times and created 1 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 2 times and created 3 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 2 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
ZeroHalf was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)

Result - Optimal solution found

Objective value:                18.00000000
Enumerated nodes:               0
Total iterations:               2
Time (CPU seconds):             0.00
Time (Wallclock seconds):       0.00

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.01   (Wallclock seconds):       0.00

********************迭代生成得到的方案表格为********************
   方案1  方案2  方案3  方案4  方案5  方案6
0  5.0  0.0  0.0  1.0  4.0  0.0
1  0.0  3.0  0.0  0.0  1.0  2.0
2  0.0  0.0  2.0  2.0  0.0  1.0
********************每种方案的选择个数对应如下********************
[0.0, 0.0, 0.0, 5.0, 5.0, 8.0]
方案4:选择5次
方案5:选择5次
方案6:选择8次

进程已结束,退出代码为 0

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰冷冷的挈挈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值