I have put together a CPLEX model that refers to data in an excel spreadsheet to optimize the number of officers we commission given resourcing limitations. I have managed to fix all errors except for one "Not an array type" error. I have marked the error in the below code using a comment to the right. It is in the Progression Dynamics section. I'm sure it is something simple I am overlooking but I have exhausted by newbie knowledge to figure it out.
// Sets
{string} MSL = ...;
{string} Type = ...;
{string} FY = ...;
// Parameters
float initPop[MSL][Type] = ...; // Initial population per level and type
float gain[MSL][Type] = ...; // External average gain into each level/year
float progressRate[MSL][Type] = ...; // Progression rate to next level
float retainMSL[MSL][Type] = ...; // Non-progression but retained
float CmsnRate[MSL][Type] = ...; // Cmsn rate
float costPerYear[Type] = ...; // Cost per type
float budgetLimit = ...;
int capacityLimit = ...;
int mission = ...;
// Decision variables
dvar int+ cadet[MSL][Type][FY]; // Number of trainees per level/type/year
dvar int+ commissions[Type][FY]; // Graduates per type/year
// Objective
maximize sum(t in Type, y in FY) commissions[t][y];
// Constraints
subject to {
// Progression dynamics
forall(y in FY: y != "2026") {
forall(l in MSL: l != "MSL1") {
forall(t in Type) {
// Progressed from previous level
cadet[l][t][y] == //This is the location of the "Not an array type" error
progressRate[prev(MSL,l)][t] * cadet[prev(MSL,l)][t][prev(FY, y)]
+ retainMSL[l][t] * cadet[l][t][prev(FY, y)]
+ gain[l][t][y];
}
}
// Level 1 has only gain and retained
forall(t in Type) {
cadet["MSL1"][t][y] ==
retainMSL["MSL1"][t] * cadet["MSL1"][t][prev(FY, y)]
+ gain["MSL1"][t];
}
}
// Define graduates as those progressing from L4 to L5
forall(t in Type, y in FY)
commissions[t][y] == CmsnRate["MSL4"][t] * cadet["MSL4"][t][y] + CmsnRate["MSL5"][t] * cadet["MSL5"][t][y];
// Budget constraint per year
forall(y in FY)
sum(l in MSL, t in Type)
costPerYear[t] * cadet[l][t][y] <= budgetLimit;
// Capacity constraint per year
forall(y in FY)
sum(l in MSL, t in Type)
cadet[l][t][y] <= capacityLimit;
// Minimum graduates per year
forall(y in FY)
sum(t in Type) commissions[t][y] >= mission;
}
I have addressed each individual error as it pops up in the Optimization studio. I even ran the error with a reference to the code through AI which made some good sounding suggestions but everything it suggested checked out.
What is not ok is that you wrote
+ gain[l][t][y]
But earlier you wrote
float gain[MSL][Type] = ...;
So gain is a 2D array but you use this as a 3D array