title: How to write average constraints in CPLEX OPL?
body: <p>I have several questions regarding modelling constraints. I guess it should be really simple, but I am unable to figure it out. First, let me sketch the situation: I would like to optimize a multi-dimensional knapsack problem. However, I get some difficulties with two constraint.</p>
  
  <p>I am first reading an Excel sheet with the following columns:</p>
  
  <pre><code>{string} Items = …;
  tuple Item {
  int weight;
  int classification_1;
  int classification_2;
  …}
  
  dvar int a[Items] in 0..1;
  </code></pre>
  
  <p>classification_1 and classification_2 are two separate classifications of the objects, you can imagine that for example classification_1 contains an integer that represents a color, while classification_2 has another property (for example the shape, where a number represents a certain shape).
  To clarify things even more, you can imagine an object as follows:</p>
  
  <pre><code>Ball_object; 23; 1; 2; …
  </code></pre>
  
  <p>Where Ball_object is the name, 23 is the weight, 1 the color blue and 2 a circle shape, the other properties are not immediately relevant for my question.
  Now suppose I have the following constraint:
  1.  For all items, their weights should be less than 10% of the total weight of the selected items.</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>Subjected to {
      Forall ( i_1 in Items )
      ctItemRatio:
      (Item[i_1].weight * a[i_1]) / (sum (I in Items) (Item[i].weight * a[i])) &lt;= 0.1;
  }
  </code></pre>
  
  <p>But this does not appear to work, as my CPLEX studio cannot extract expression. But I am a bit confused what I actually did wrong with this constraint. Does anyone have an idea how I can solve this?</p>
  
  <ol start="2">
  <li>For every shape, the total weights of a given shape should not exceed 15% of the total weight.</li>
  </ol>
  
  <p>I have actually not a really clue how to do this, since I cannot just iterate through classification_2 right? How can I model it such that I can use a forall through classification_2? (I would love to find a OPL solution rather than just naming all the shapes by hand.</p>
  
  <p>Thank you for your help!</p>