我在优化方面相对较新,我正在尝试优化一个关于仓库位置的问题(两年前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