parameters: (items, max_capacity)
return_statement: return states, transitions
docstring: Create a state graph from a multiset of items, and a maximum capacity.
docstring_summary: Create a state graph from a multiset of items, and a maximum capacity.
docstring_tokens: Create a state graph from a multiset of items and a maximum capacity .
function: def create_state_graph(items, max_capacity):
      """Create a state graph from a multiset of items, and a maximum capacity."""
      states = []
      state_to_index = {}
      states.append(0)
      state_to_index[0] = 0
      transitions = []
  
      for item_index, size_and_count in enumerate(items):
          size, count = size_and_count
          num_states = len(states)
          for state_index in range(num_states):
              current_state = states[state_index]
              current_state_index = state_index
  
              for card in range(count):
                  new_state = current_state + size * (card + 1)
                  if new_state > max_capacity:
                      break
                  new_state_index = -1
                  if new_state in state_to_index:
                      new_state_index = state_to_index[new_state]
                  else:
                      new_state_index = len(states)
                      states.append(new_state)
                      state_to_index[new_state] = new_state_index
                  # Add the transition
                  transitions.append([
                      current_state_index, new_state_index, item_index, card + 1
                  ])
  
      return states, transitions
function_tokens: def create_state_graph ( items , max_capacity ) : states = [ ] state_to_index = { } states . append ( 0 ) state_to_index [ 0 ] = 0 transitions = [ ] for item_index , size_and_count in enumerate ( items ) : size , count = size_and_count num_states = len ( states ) for state_index in range ( num_states ) : current_state = states [ state_index ] current_state_index = state_index for card in range ( count ) : new_state = current_state + size * ( card + 1 ) if new_state > max_capacity : break new_state_index = - 1 if new_state in state_to_index : new_state_index = state_to_index [ new_state ] else : new_state_index = len ( states ) states . append ( new_state ) state_to_index [ new_state ] = new_state_index # Add the transition transitions . append ( [ current_state_index , new_state_index , item_index , card + 1 ] ) return states , transitions