【发布时间】:2021-11-07 21:31:31
【问题描述】:
我对 CPLEX 中的约束函数有疑问。
我有一种情况,需要从 8 艘船为多个营地提供库存。船只需要停泊在两个港口之一。两种运输方式,即船舶运输(基于吨位运输)和从港口到营地的运输(基于船舶数量)均需额外付费。
我需要添加一个约束条件,即供应量至少等于需求量,而目标是最小化成本。但是,我的约束没有给出正确的输出。
谁能帮我纠正我的限制并解释为什么它不起作用?
/// Indices
int nrofships = 8;
range ships = 1..nrofships;
int nrofports = 2;
range ports = 1..nrofports;
int nrofmonths = 5;
range months = 1..nrofmonths;
int nrofcamps = 6;
range camps = 1..nrofcamps;
// Parameters
float capacity[ships] = [1.250, 2.740, 1.890, 4.980, 2.630, 16.000, 9.610, 3.540];
int demand[camps][months]= [[11, 5, 1, 1, 1],[3, 0, 3, 0, 2],[6, 3, 4, 3, 7],[5, 5, 5, 2, 6],[7, 1, 7, 1, 4],[0, 3, 5, 0, 0]];
int preparation[ships] = [250000, 655000, 412300, 876900, 470025, 3655000, 1914500, 700000];
int transportationcosts[ports][ships] = [[129, 132, 129, 132, 178, 160, 161, 144],[134, 155, 130, 139, 142, 139, 154, 122]];
int distributioncosts[ports][camps] = [[130, 81, 77, 83, 89, 116],[71, 125, 114, 85, 86, 86]];
// decision variable
dvar float+ x[ships][ports][months];
dvar float+ y[ports][camps][months];
dvar boolean binx[ships][ports][months];
//Expression of Decision
// dexpr float Costs = sum(s in ships, c in camps, p in ports, m in months) preparation[s]*binx[s][p][m];
dexpr float TotalCost = sum(s in ships, m in months, c in camps, p in ports) preparation[s]*binx[s][p][m] +
sum(s in ships, m in months, c in camps, p in ports) transportationcosts[p][s]*x[s][p][m] +
sum(s in ships, m in months, c in camps, p in ports) distributioncosts[p][c]*y[p][c][m];
//Objective function
minimize TotalCost;
//Constraints
constraint ctdemand[ships][camps][months];
subject to {
forall(s in ships, c in camps, m in months) ctdemand[s][c][m]:
sum(p in ports) x[s][p][m]*capacity[s] >= demand[c][m];
}
【问题讨论】:
-
欢迎。请查看How to Ask,然后修改您的帖子标题以提出一个清晰、具体的问题。不要添加标签。另外,请拨打tour。你不应该发布你的后续作为答案。
标签: constraints cplex