Error Messages/20250
Error Message
The Variable Side_material is not valid as a SetContext variable in DefineOptimization because Side_material_cost contains a call to Sum that operates over the index Side_material. When used in SetContext, the optimizer needs to be able to set Side_material to a single value, which would invalidate its use as an index in Side_material_cost.
Cause
This error arises when you are using the «SetContext» parameter of DefineOptimization or NlpDefine when array abstracting over optimization problems. The error displays when one of the variables you've listed in that parameter cannot be used as a context variable because of the presence of another variable that treats it as an index. When the optimizer processes context variables, it sets them to a slice of their current value. In this case, changing an index to a scalar would break definitions that treat this variable as an index. Hence, this is likely not the variable you want to use as a context variable.
Remedy
You will probably want to locate a different variable (or variables) downstream of this one to use as the context variable. The ideal (but not requirement) is that the context variables are not downstream from your decision variables, but are also such that if you slice the extra indexes from them, they won't appear in any of the downstream variables used by the optimization.
Enable comment auto-refresher