python 混合整数规划_混合整数规划仓库位置(Python+GLPK)

本文作者分享了在Python中使用PuLP库和GLPK求解器解决一个包含100个仓库和1000个客户的仓库位置优化问题的经历。模型设定包括仓库的开启成本、容量限制和客户分配。尽管对于小规模问题能有效解决,但在大规模实例上运行时间过长。作者寻求优化模型或改善计算效率的建议。
摘要由CSDN通过智能技术生成

我在优化方面相对较新,我正在尝试优化一个关于仓库位置的问题(两年前Coursera的pas课程)。问题是,它已经运行了6个多小时,它仍然在一个拥有100个仓库和1000个客户的实例上运行。在

问题如下。我有一套仓库,我可以开也可以不开。打开它们每一个都有一个成本,而且它们都有一个最大的容量,cap。

另一方面,有很多客户机,所有客户机都必须连接到一个(而且只有一个)开放仓库。每个客户的仓库都有一个运输成本。

显然,我想要的是,把总成本降到最低。在

因此,我有一个大小等于仓库总数x的数组,每个x[w]是一个整数{0,1},定义仓库w是否打开。

我还有一个由0和1组成的矩阵,定义了哪个仓库为每个客户提供服务。因此,行数与客户数相同,列数与仓库数相同。矩阵称为y,如果waregouse w交付客户c,y[c][w]为1,否则为0。在

到目前为止还不错。这可能是一个MIP问题。

为了编写代码,我在Python中使用PuPL lib(https://pythonhosted.org/PuLP/pulp.html)和GLPK来解决它。在

现在,这是我的模型:#!/usr/bin/python

# -*- coding: utf-8 -*-

from pulp import *

def solveIt(inputData):

# parse the input

lines = inputData.split('\n')

parts = lines[0].split()

warehouseCount = i

Windows 7上安装pulp和glpk步骤: 亲测环境: Windows 6.1.7601 Service Pack 1 Build 7601 x64 Python 2.7.11 PuLP 1.6.8 GLPK 4.34 安装步骤: 1、下载PuLP安装包:前提是,已安装python2.6以及2.6以上版本,在网页(https://pythonhosted.org/PuLP/main/installing_pulp_at_home.html)上点击PuLP zipfile下载pulp包,当然,也可以在我的资源里下载 2、安装PuLP:将zipfile解压缩,并在命令行窗口中,进入解压缩的目录,然后输入命令:setup.py install 3、下载glpk安装包:在网页(https://sourceforge.net/projects/gnuwin32/files/glpk/4.34/)上,下载glpk-4.34-setup.exe(也可以在我的资源里下载),然后双击默认安装 4、按照以上步骤,安装完以后,写一个.py的脚本并运行,脚本内容: from pulp import * pulp.pulpTestAll() 然后,会看到以下类似输出结果: D:\002-Task_150524\117-17data_thesis\004-code\testPulp.py Testing zero subtraction Testing inconsistant lp solution Testing continuous LP solution Testing maximize continuous LP solution Testing unbounded continuous LP solution Testing Long Names Testing repeated Names Testing zero constraint Testing zero objective Testing LpVariable (not LpAffineExpression) objective Testing Long lines in LP Testing LpAffineExpression divide Testing MIP solution Testing MIP solution with floats in objective Testing MIP relaxation Testing feasibility problem (no objective) Testing an infeasible problem Testing an integer infeasible problem Testing column based modelling Testing dual variables and slacks reporting Testing fractional constraints Testing elastic constraints (no change) Testing elastic constraints (freebound) Testing elastic constraints (penalty unchanged) Testing elastic constraints (penalty unbounded) * Solver pulp.solvers.PULP_CBC_CMD passed. Solver pulp.solvers.CPLEX_DLL unavailable Solver pulp.solvers.CPLEX_CMD unavailable Solver pulp.solvers.CPLEX_PY unavailable Solver pulp.solvers.COIN_CMD unavailable Solver pulp.solvers.COINMP_DLL unavailable Testing zero subtraction Testing inconsistant lp solution Testing continuous LP solution Testing maximize continuous LP solution Testing unbounded continuous LP solution Testing Long Names Testing repeated Names Testing zero constraint Testing zero objective Testing LpVariable (not LpAffineExpression) objective Testing LpAffineExpression divide Testing MIP solution Testing MIP solution with floats in objective Testing MIP relaxation Testing feasibility problem (no objective) Testing an infeasible problem Testing an integer infeasible problem Testing column based modelling Testing fractional constraints Testing elastic constraints (no change) Testing elastic constraints (freebound) Testing elastic constraints (penalty unchanged) Testing elastic constraints (penalty unbounded) * Solver pulp.solvers.GLPK_CMD passed. Solver pulp.solvers.XPRESS unavailable Solver pulp.solvers.GUROBI unavailable Solver pulp.solvers.GUROBI_CMD unavailable Solver pulp.solvers.PYGLPK unavailable Solver pulp.solvers.YAPOSIB unavailable 表示已经成功安装pulp和glpk
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值