public static Map<Unit,Unit> mapTransportsToLoad(final Collection<Unit> units,final Collection<Unit> transports){
  final List<Unit> canBeTransported=sortByTransportCostDescending(units);
  final List<Unit> canTransport=sortByTransportCapacityDescendingThenMovesDescending(transports);
  final Map<Unit,Unit> mapping=new HashMap<>();
  final IntegerMap<Unit> addedLoad=new IntegerMap<>();
  for (  final Unit unit : canBeTransported) {
    final Optional<Unit> transport=loadUnitIntoFirstAvailableTransport(unit,canTransport,mapping,addedLoad);
    if (transport.isPresent()) {
      canTransport.remove(transport.get());
      canTransport.add(transport.get());
    }
  }
  return mapping;
}

public static Map < Unit , Unit > mapTransportsToLoad ( final Collection < Unit > units , final Collection < Unit > transports ) { final List < Unit > canBeTransported = sortByTransportCostDescending ( units ) ; final List < Unit > canTransport = sortByTransportCapacityDescendingThenMovesDescending ( transports ) ; final Map < Unit , Unit > mapping = new HashMap < > ( ) ; final IntegerMap < Unit > addedLoad = new IntegerMap < > ( ) ; for ( final Unit unit : canBeTransported ) { final Optional < Unit > transport = loadUnitIntoFirstAvailableTransport ( unit , canTransport , mapping , addedLoad ) ; if ( transport . isPresent ( ) ) { canTransport . remove ( transport . get ( ) ) ; canTransport . add ( transport . get ( ) ) ; } } return mapping ; }
returns a map of unit - > transport . tries to load units evenly across all transports .
