OPL 代码:数据解析和意外符号问题

问题描述 投票:0回答:0

我是 cplex 的初学者。我在编写一些基本的 cplex 时遇到了麻烦,我只是试图实现一个简单的数学供应链模型,但在 cplex 版本 22.1

上一切都不起作用

.模组文件

// Index Sets
range Z;
range I;
range J;
range F;
range P;
range 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]; // Amount of raw material transported z from supplier i to the production center j by transportation means of f
dvar float+ ProductManufacture[P][J]; // Amount of product p that is manufactured in production center j
dvar boolean ProductionCenterBuilt[J]; // Binary variable for production center construction
dvar boolean DisposalCenterBuilt[C]; // Binary variable for disposal center construction

// 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] * ProductManufacture[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 {
  // Raw material supply constraint
  forall(z in Z, i in I) sum(j in J, f in F) (RawMaterialTransport[z][i][j][f]) <= raw_material_availability[z][i];

  // Product demand constraint
  forall(p in P) sum(j in J) (ProductManufacture[p][j]) >= annual_demand[p];

  // Raw material usage constraint
  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]);

  // Production center construction constraint
  forall(j in J) sum(p in P) (ProductManufacture[p][j]) <= LargeConstant * ProductionCenterBuilt[j]; // LargeConstant is a large constant value

  // Disposal center construction constraint
  forall(c in C) sum(p in P) (ProductManufacture[p][c]) <= LargeConstant * DisposalCenterBuilt[c]; // LargeConstant is a large constant value
}

.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

// Raw material availability at each supplier
param raw_material_availability: S1 S2 :=
R1 100 200
R2 150 250;

// Product manufacturing cost at each production center
param MCptj: P1 P2 :=
PR1 10 15
PR2 12 18;

// Disposal cost of each unit of product at disposal centers
param DISDpc: D1 D2 :=
PR1 5 7
PR2 6 8;

// Transportation costs
param transportation_cost :=
R1.S1.T1 2
R1.S1.T2 3
R1.S2.T1 3
R1.S2.T2 4
R2.S1.T1 3
R2.S1.T2 4
R2.S2.T1 4
R2.S2.T2 5;

// Production center construction costs
param construction_cost_j :=
P1 1000
P2 2000;

// Disposal center construction costs
param construction_cost_c :=
D1 1500
D2 2500;

// Annual demand for each product
param annual_demand :=
PR1 50
PR2 100;

// Specific data for the four objective functions
// Economic (Z1)
param economic_weight :=
PR1 0.25
PR2 0.25;

// Environmental (Z2)
param environmental_weight :=
PR1 0.25
PR2 0.25;

// Supply risk (Z3)
param supply_risk_weight :=
PR1 0.25
PR2 0.25;

// Political stability (Z4)
param political_stability_weight :=
PR1 0.25
PR2 0.25;

end;

错误警告是

  • 数据解析错误:语法错误,意外的';',期待来自或 到.

  • 数据解析错误:语法错误,意外的';',期望从或到。 - 数据解析错误:语法错误,意外(标识符),期待从或到。

  • 数据解析错误:语法错误,意外(标识符),期望来自或至。 ✔ 数据解析 - - 错误:语法错误,意外(标识符),期待从或到。

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • ✔ 数据解析错误:语法错误,意外(标识符),期待从或到。

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • 数据解析错误:语法错误,意外(标识符),期望来自或至。 ✔ 数据解析 - - 错误:语法错误,意外(标识符),期待从或到。

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

  • ✔ 数据解析错误:语法错误,意外(标识符),期待从或到。

  • ✔ 数据解析错误:语法错误,意外(标识符),期待从或到。

  • Data parsing error: syntax error, unexpected (identifier), expecting from or to.

任何帮助将不胜感激:)

cplex opl
© www.soinside.com 2019 - 2024. All rights reserved.