cplexopl

OPL code: issues with data parsing and unexpected symbols


i'm a beginner in cplex . im having trouble writing just some basic cplex, im trying to just implement a simple mathemetical supply chain model but everything isnt working im on cplex version 22.1

. mod file

// 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 file

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;

error warnings are

any help will be appreciated :)


Solution

  • You model looks OPL but you data file looks more AMPL than OPL

    For instance to comply with .mod

    // Index Sets
    {string} Z=...;
    

    the .dat should look like

    Z = {R1, R2};