You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CPLEX 22.1 OPL供应链模型数据解析错误技术求助

CPLEX供应链模型数据解析错误修复方案

核心错误原因

  1. 集合类型不匹配:.mod中用range(数值范围集合)定义字符串命名集合,.dat中用set赋值,两者语法不兼容。
  2. 多维参数格式错误:四维数组transportation_cost的.dat写法不符合OPL规范。
  3. 参数缺失赋值:LargeConstant未在.dat中提供数值。
  4. 冗余参数存在:.dat中economic_weight在.mod里没有定义,引发解析报错。
  5. 索引逻辑错误:目标函数中ProductManufacture[p][c]的索引c不属于生产中心集合J,维度不匹配。

修改后的.mod文件

// Index Sets
set of string Z;
set of string I;
set of string J;
set of string F;
set of string P;
set of string C;

// Parameters
float raw_material_availability[Z][I];
float MCptj[P][J];
float DISDpc[P][C];
float transportation_cost[Z][I][J][F];
float construction_cost_j[J];
float construction_cost_c[C];
float annual_demand[P];
float environmental_weight[P];
float supply_risk_weight[P];
float political_stability_weight[P];
float LargeConstant;

// Decision variables
dvar float+ RawMaterialTransport[Z][I][J][F]; // 从供应商i运输原材料z到生产中心j,运输方式f的数量
dvar float+ ProductManufacture[P][J]; // 生产中心j生产产品p的数量
dvar float+ ProductDisposal[P][C]; // 处理中心c处理产品p的数量(新增变量修正索引逻辑)
dvar boolean ProductionCenterBuilt[J]; // 生产中心是否建设的二进制变量
dvar boolean DisposalCenterBuilt[C]; // 处理中心是否建设的二进制变量

// Objective functions
dexpr float EconomicObjective = 
  sum(p in P, j in J) (MCptj[p][j] * ProductManufacture[p][j]) + 
  sum(z in Z, i in I, j in J, f in F) (transportation_cost[z][i][j][f] * RawMaterialTransport[z][i][j][f]) + 
  sum(c in C, p in P) (DISDpc[p][c] * ProductDisposal[p][c]) + 
  sum(j in J) (construction_cost_j[j] * ProductionCenterBuilt[j]) + 
  sum(c in C) (construction_cost_c[c] * DisposalCenterBuilt[c]);

dexpr float EnvironmentalObjective = sum(p in P, j in J) (environmental_weight[p] * ProductManufacture[p][j]);
dexpr float SupplyRiskObjective = sum(p in P, j in J) (supply_risk_weight[p] * ProductManufacture[p][j]);
dexpr float PoliticalStabilityObjective = sum(p in P, j in J) (political_stability_weight[p] * ProductManufacture[p][j]);

// Weighted objective function
float weightEconomic = 0.25;
float weightEnvironmental = 0.25;
float weightSupplyRisk = 0.25;
float weightPoliticalStability = 0.25;

dexpr float WeightedObjective = weightEconomic * EconomicObjective + weightEnvironmental * EnvironmentalObjective + weightSupplyRisk * SupplyRiskObjective + weightPoliticalStability * PoliticalStabilityObjective;

minimize WeightedObjective;

// Constraints
subject to {
  // 原材料供应约束
  forall(z in Z, i in I) sum(j in J, f in F) (RawMaterialTransport[z][i][j][f]) <= raw_material_availability[z][i];

  // 产品需求约束
  forall(p in P) sum(j in J) (ProductManufacture[p][j]) >= annual_demand[p];

  // 原材料使用约束(假设单位产品消耗1单位原材料,可按需调整系数)
  forall(z in Z, j in J) sum(i in I, f in F) (RawMaterialTransport[z][i][j][f]) >= sum(p in P) (ProductManufacture[p][j]);

  // 生产中心建设约束
  forall(j in J) sum(p in P) (ProductManufacture[p][j]) <= LargeConstant * ProductionCenterBuilt[j];

  // 处理中心建设约束
  forall(c in C) sum(p in P) (ProductDisposal[p][c]) <= LargeConstant * DisposalCenterBuilt[c];

  // 产品处理平衡约束
  forall(p in P) sum(c in C) (ProductDisposal[p][c]) >= sum(j in J) (ProductManufacture[p][j]);
}

修改后的.dat文件

data;

// Sets
set Z := R1 R2;
set I := S1 S2;
set J := P1 P2;
set F := T1 T2;
set P := PR1 PR2;
set C := D1 D2;

// Parameters

// 供应商原材料可用性
param raw_material_availability: S1 S2 :=
R1 100 200
R2 150 250;

// 生产中心产品制造成本
param MCptj: P1 P2 :=
PR1 10 15
PR2 12 18;

// 处理中心产品处理成本
param DISDpc: D1 D2 :=
PR1 5 7
PR2 6 8;

// 运输成本(修正四维数组格式)
param transportation_cost:
[R1, S1, P1, T1] = 2
[R1, S1, P1, T2] = 3
[R1, S2, P1, T1] = 3
[R1, S2, P1, T2] = 4
[R2, S1, P1, T1] = 3
[R2, S1, P1, T2] = 4
[R2, S2, P1, T1] = 4
[R2, S2, P1, T2] = 5;
// 如需添加其他生产中心的运输成本,补充[z,i,J,f]对应值即可

// 生产中心建设成本
param construction_cost_j :=
P1 1000
P2 2000;

// 处理中心建设成本
param construction_cost_c :=
D1 1500
D2 2500;

// 产品年需求
param annual_demand :=
PR1 50
PR2 100;

// 目标函数权重参数
param environmental_weight :=
PR1 0.25
PR2 0.25;

param supply_risk_weight :=
PR1 0.25
PR2 0.25;

param political_stability_weight :=
PR1 0.25
PR2 0.25;

// 大常数赋值
param LargeConstant := 10000;

end;

关键修改说明

  1. 集合定义:将range改为set of string,匹配.dat中的字符串集合类型。
  2. 运输成本格式:四维数组使用[z,i,j,f] = 值的标准OPL语法赋值。
  3. 新增变量:添加ProductDisposal[P][C]修正原目标函数的索引不匹配问题,并补充处理平衡约束。
  4. 冗余参数删除:移除.dat中未在.mod定义的economic_weight。
  5. 大常数赋值:在.dat中给LargeConstant设置足够大的数值(如10000)。

内容的提问来源于stack exchange,提问作者setupspawn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 08:27:09