title: Choosing items only once subject to slot constraints
body: <p>I have a set of many (10000+) items, from which have I have to choose exactly <code>k</code> items. I can only choose each item once. </p>
  
  <p>Each item is represented as a tuple:</p>
  
  <p><code>item = ('item code', cost, profit, slot_1, slot_2, ...., slot_N)</code>
  as an example</p>
  
  <p><code>vase = ['000001', 1000, 10000, 1, 0, ..., 0]</code></p>
  
  <p><code>plate = ['000002', 10, 5, 0, 1, ..., 0]</code></p>
  
  <p>and the total set of items is a list of lists:</p>
  
  <p><code>items = [item1, item2, ..., itemN]</code></p>
  
  <p>My profits and costs are also lists:</p>
  
  <p><code>profits = [x[2] for x in items]</code></p>
  
  <p><code>costs = [x[1] for x in items]</code></p>
  
  <p>I represent if an item can be in slot_j as a list of lists:</p>
  
  <pre><code>slots = []
  
  for j in NUM_SLOTS:
      slot[j, :] = [x[3+j] for x in items]
  </code></pre>
  
  <p>My problem is that items with the same code can appear in multiple slots, but can only be chosen once irrespective of the slot. </p>
  
  <p>ie. <code>vase = ['000001', 1000, 10000, 1, 0, ..., 1]</code></p>
  
  <p>I'm confused about how I add the constraint that an item can only be chosen once if it is available in multiple slots.</p>
  
  <p>Only one item can be chosen per slot.</p>
  
  <p>The entire program is below for reference.</p>
  
  <pre><code>from ortools.linear_solver import pywraplp
  
  solver = pywraplp.Solver('SolveAssignmentProblemMIP',
  
  pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
  
  x = {}
  
  for i in range(MAX_ITEMS):
      x[i] = solver.BoolVar('x[%s]' % (i))
  
  #Define the constraints 
  total_chosen = 100
  solver.Add(solver.Sum([x[i] for i in range(MAX_ITEMS)]) == 
  total_chosen)
  
  max_cost = 5.0
  
  for i in range(num_recipes):
      solver.Add(x[i] * cost[i] &lt;= max_cost)
  
  ### Only choose one item per slot
  for i in range(1, num_slots):
      slot = slots[:, i]
      solver.Add(solver.Sum([x[j] * slot[j] for j in range(MAX_ITEMS)]) == 1)
  
  solver.Maximize(solver.Sum([profits[i] * x[i] for i in 
  range(total_chosen)]))
  sol = solver.Solve()
  </code></pre>