parameters: ()
docstring: MinCostFlow simple interface example.
  
    Note that this example is actually a linear sum assignment example and will
    be more efficiently solved with the pywrapgraph.LinearSumAssignement class.
docstring_summary: MinCostFlow simple interface example.
docstring_tokens: MinCostFlow simple interface example .
function: def MinCostFlow():
      """MinCostFlow simple interface example.
  
    Note that this example is actually a linear sum assignment example and will
    be more efficiently solved with the pywrapgraph.LinearSumAssignement class.
    """
      print('MinCostFlow on 4x4 matrix.')
      num_sources = 4
      num_targets = 4
      costs = [[90, 75, 75, 80], [35, 85, 55, 65], [125, 95, 90, 105],
               [45, 110, 95, 115]]
      expected_cost = 275
      min_cost_flow = pywrapgraph.SimpleMinCostFlow()
      for source in range(0, num_sources):
          for target in range(0, num_targets):
              min_cost_flow.AddArcWithCapacityAndUnitCost(source,
                                                          num_sources + target, 1,
                                                          costs[source][target])
      for node in range(0, num_sources):
          min_cost_flow.SetNodeSupply(node, 1)
          min_cost_flow.SetNodeSupply(num_sources + node, -1)
      status = min_cost_flow.Solve()
      if status == min_cost_flow.OPTIMAL:
          print('Total flow', min_cost_flow.OptimalCost(), '/', expected_cost)
          for i in range(0, min_cost_flow.NumArcs()):
              if min_cost_flow.Flow(i) > 0:
                  print('From source %d to target %d: cost %d' %
                        (min_cost_flow.Tail(i), min_cost_flow.Head(i) -
                         num_sources, min_cost_flow.UnitCost(i)))
      else:
          print('There was an issue with the min cost flow input.')
function_tokens: def MinCostFlow ( ) : print ( 'MinCostFlow on 4x4 matrix.' ) num_sources = 4 num_targets = 4 costs = [ [ 90 , 75 , 75 , 80 ] , [ 35 , 85 , 55 , 65 ] , [ 125 , 95 , 90 , 105 ] , [ 45 , 110 , 95 , 115 ] ] expected_cost = 275 min_cost_flow = pywrapgraph . SimpleMinCostFlow ( ) for source in range ( 0 , num_sources ) : for target in range ( 0 , num_targets ) : min_cost_flow . AddArcWithCapacityAndUnitCost ( source , num_sources + target , 1 , costs [ source ] [ target ] ) for node in range ( 0 , num_sources ) : min_cost_flow . SetNodeSupply ( node , 1 ) min_cost_flow . SetNodeSupply ( num_sources + node , - 1 ) status = min_cost_flow . Solve ( ) if status == min_cost_flow . OPTIMAL : print ( 'Total flow' , min_cost_flow . OptimalCost ( ) , '/' , expected_cost ) for i in range ( 0 , min_cost_flow . NumArcs ( ) ) : if min_cost_flow . Flow ( i ) > 0 : print ( 'From source %d to target %d: cost %d' % ( min_cost_flow . Tail ( i ) , min_cost_flow . Head ( i ) - num_sources , min_cost_flow . UnitCost ( i ) ) ) else : print ( 'There was an issue with the min cost flow input.' )