(self, target_capacity, markets)
return sorted([(market, residual(market)) for market in markets], key=residual_sort_key,)
Given a target capacity and list of available markets, compute the residuals needed to bring all markets up
        to an (approximately) equal capacity such that the total capacity meets or exceeds the target capacity

        :param target_capacity: the desired total capacity of the fleet
        :param markets: a list of available markets
        :returns: a list of (market, residual) tuples, sorted first by lowest capacity and next by lowest spot price
Given a target capacity and list of available markets, compute the residuals needed to bring all markets up
        to an (approximately) equal capacity such that the total capacity meets or exceeds the target capacity
Given a target capacity and list of available markets compute the residuals needed to bring all markets up to an ( approximately ) equal capacity such that the total capacity meets or exceeds the target capacity
def _compute_market_residuals(self, target_capacity, markets):
        """ Given a target capacity and list of available markets, compute the residuals needed to bring all markets up
        to an (approximately) equal capacity such that the total capacity meets or exceeds the target capacity

        :param target_capacity: the desired total capacity of the fleet
        :param markets: a list of available markets
        :returns: a list of (market, residual) tuples, sorted first by lowest capacity and next by lowest spot price
        """
        target_capacity_per_market = target_capacity / len(markets) if len(markets) != 0 else 0

        # Some helper closures for computing residuals and sorting;
        @lru_cache()  # memoize the results
        def residual(market):
            return target_capacity_per_market - self.market_capacities.get(market, 0)

        def residual_sort_key(value_tuple):
            market, residual = value_tuple
            return (
                residual,
                self.simulator.instance_prices[market].call(self.simulator.current_time),
            )

        return sorted([(market, residual(market)) for market in markets], key=residual_sort_key,)
def _compute_market_residuals ( self , target_capacity , markets ) : target_capacity_per_market = target_capacity / len ( markets ) if len ( markets ) != 0 else 0 # Some helper closures for computing residuals and sorting; @ lru_cache ( ) # memoize the results def residual ( market ) : return target_capacity_per_market - self . market_capacities . get ( market , 0 ) def residual_sort_key ( value_tuple ) : market , residual = value_tuple return ( residual , self . simulator . instance_prices [ market ] . call ( self . simulator . current_time ) , ) return sorted ( [ ( market , residual ( market ) ) for market in markets ] , key = residual_sort_key , )