Error Messages/40935

Error text examples

The 'Shelf_space' constraint in the structured NLP defined in 'My_opt_def' evaluates to a result 
containing the following unexpected index(es):  'Product'. 


While an optimization was being solved, a constraint was evaluated and found to have extra, unexpected indexes. There are basically three causes:

  1. An error in your model's logic -- you may have forgotten to Sum over the index or apply some other array-reducing function.
  2. You intended there to be an array of constraints - a separate constraint along each of these extra indexes within the same optimization problem.
  3. Your intention was to array-abstract over these indexes, resulting in multiple optimization problem instances, each solved separately.


The correct remedy depends on which of the above cases fits your situation. For example, let's consider the following constraint that causes this error:

Ceil(Num_units/Stacking_height)*Unit_width <= Shelf_length

Case 1: Need array-reducing function

Suppose that all products need to share the same available shelf space. Shelf_length then does not vary by Product, while Num_units, Unit_width and Stacking_height does. Then it appears that we forgot to Sum by product to compute the total amount of shelf length consumed by all products. When evaluated, the optimizer encountered the unexpected dimension, Product. We can fix the problem by changing our definition to:

Sum(Ceil(Num_units/Stacking_height)*Unit_width, Product) <= Shelf_length

Case 2: Array of constraints

Suppose that a certain amount of shelf space has been allocated to each product type. Hence,Shelf_length varies with Product (i.e., is indexed by Product), and what we really intend is to have an array of constraints all inside the same single optimization problem. In this case, we'll have one Shelf_space constraint for each product.

To do this, we need to tell the optimizer that the index Product is to be included as an optimization dimension for this constraint. There are several ways to do this, each may be convenient in different cases, depending on how you have formulated your constraint.

One general approach is to include the over keyword in your inequality expression. Here we've appended it to the end:

Ceil(Num_units/Stacking_height)*Unit_width <= Linear_shelf_space over Project

The syntax also allows you to prepend it to the front, or place it next to the inequality as demonstrated by these:

over Project Ceil(Num_units/Stacking_height)*Unit_width <= Linear_shelf_space
Ceil(Num_units/Stacking_height)*Unit_width <= over Project Linear_shelf_space

The flexibility in syntax so that you can chose the one that is most readable in your particular case. This syntax can be used even if you specify your constraint directly in the parameter of DefineOptimization.

Alternatively, you can leave the constraint as is and list the index in the OptDimensions attribute. You can access the OptDimensions attribute in the Attribute panel, or in the Object window. However, to view it in the object window, you need to enable the visibility of the OptDimensions attribute from the Attributes... dialog on the Object menu. The attribute can only be used when your constraint is defined inside a constraint object, or inside a User-Defined Function. You cannot use this method when you specify the inequality expression directly in the «constraints» parameter of DefineOptimization.

Case 3: Array-abstracting

Suppose there are no interactions between different products in your model. Each product has its own shelf space, and you want to optimize each product separately. In other words, you wish to array-abstract over the Product index, and solve a separate optimization problem for each Product. The Shelf_space constraint, therefore, should be treated as a single constraint in each optimization problem.

However, because Num_units, Unit_width, Stacking_height and Shelf_length are all indexed by Product in your model, Product is an extra dimension here. With array-abstraction, the optimization problem corresponding to the first product should use only the constraint for [@Product = 1].

To treat Product as an array-abstraction index, you need to indicate this to DefineOptimization using some combination of the «Over» and «SetContext» parameters. In this case, «SetContext» does the job -- we change our optimization definition to:

DefineOptimization(...; constraints:Self_space,... ; SetContext: Product)

The «SetContext» parameter imposes certain requirements and restrictions on your model. You may need to refine your own model somewhat in order to utilize «SetContext» effectively.

See Also


You are not allowed to post comments.