parameters: ()
docstring: Linear Sum Assignment example.
docstring_summary: Linear Sum Assignment example.
docstring_tokens: Linear Sum Assignment example .
function: def main():
      """Linear Sum Assignment example."""
      # [START solver]
      assignment = pywrapgraph.LinearSumAssignment()
      # [END solver]
  
      # [START data]
      costs = [
          [90, 76, 75, 70],
          [35, 85, 55, 65],
          [125, 95, 90, 105],
          [45, 110, 95, 115],
      ]
      num_workers = len(costs)
      num_tasks = len(costs[0])
      # [END data]
  
      # [START constraints]
      for worker in range(num_workers):
          for task in range(num_tasks):
              if costs[worker][task]:
                  assignment.AddArcWithCost(worker, task, costs[worker][task])
      # [END constraints]
  
      # [START solve]
      status = assignment.Solve()
      # [END solve]
  
      # [START print_solution]
      if status == assignment.OPTIMAL:
          print(f'Total cost = {assignment.OptimalCost()}\n')
          for i in range(0, assignment.NumNodes()):
              print(f'Worker {i} assigned to task {assignment.RightMate(i)}.' +
                    f'  Cost = {assignment.AssignmentCost(i)}')
      elif status == assignment.INFEASIBLE:
          print('No assignment is possible.')
      elif status == assignment.POSSIBLE_OVERFLOW:
          print(
              'Some input costs are too large and may cause an integer overflow.')
function_tokens: def main ( ) : # [START solver] assignment = pywrapgraph . LinearSumAssignment ( ) # [END solver] # [START data] costs = [ [ 90 , 76 , 75 , 70 ] , [ 35 , 85 , 55 , 65 ] , [ 125 , 95 , 90 , 105 ] , [ 45 , 110 , 95 , 115 ] , ] num_workers = len ( costs ) num_tasks = len ( costs [ 0 ] ) # [END data] # [START constraints] for worker in range ( num_workers ) : for task in range ( num_tasks ) : if costs [ worker ] [ task ] : assignment . AddArcWithCost ( worker , task , costs [ worker ] [ task ] ) # [END constraints] # [START solve] status = assignment . Solve ( ) # [END solve] # [START print_solution] if status == assignment . OPTIMAL : print ( f'Total cost = {assignment.OptimalCost()}\n' ) for i in range ( 0 , assignment . NumNodes ( ) ) : print ( f'Worker {i} assigned to task {assignment.RightMate(i)}.' + f'  Cost = {assignment.AssignmentCost(i)}' ) elif status == assignment . INFEASIBLE : print ( 'No assignment is possible.' ) elif status == assignment . POSSIBLE_OVERFLOW : print ( 'Some input costs are too large and may cause an integer overflow.' )