(self, target_capacity)
return new_market_counts
Given a target capacity and current spot market prices, find instances to add to achieve the target capacity

        :param target_capacity: the desired total capacity of the fleet
        :returns: a dictionary suitable for passing to SimulatedAWSCluster.modify_size
        :raises ValueError: if target_capacity is less than the current self.target_capacity
Given a target capacity and current spot market prices, find instances to add to achieve the target capacity
Given a target capacity and current spot market prices find instances to add to achieve the target capacity
def _get_new_market_counts(self, target_capacity):
        """ Given a target capacity and current spot market prices, find instances to add to achieve the target capacity

        :param target_capacity: the desired total capacity of the fleet
        :returns: a dictionary suitable for passing to SimulatedAWSCluster.modify_size
        :raises ValueError: if target_capacity is less than the current self.target_capacity
        """
        if target_capacity < self.target_capacity:
            raise ValueError(f"Target capacity {target_capacity} < current capacity {self.target_capacity}")

        available_markets = self._find_available_markets()
        residuals = self._compute_market_residuals(target_capacity, available_markets)

        residual_correction = 0  # If we overflow in one market, correct the residuals in the remaining markets
        new_market_counts = {market: len(ids) for market, ids in self.instance_ids_by_market.items()}

        for i, (market, residual) in enumerate(residuals):
            remaining_markets = len(residuals) - (i + 1)

            # If the residual correction is larger than the residual, this means we shouldn't add any more instances
            # in this market because its residual has been "eaten up" by overflow in previous markets.  When this
            # happens, we just update the correction with any overflow that might have been introduced in *this* market.
            # Sorting the residuals in ascending order ensures correction has been updated by negative residuals
            # first.
            if residual < residual_correction:
                if remaining_markets > 0:
                    residual_correction += (residual_correction - residual) / remaining_markets
                continue

            residual -= residual_correction
            weight = self._instance_types[market].weight
            instance_num, remainder = divmod(residual, weight)

            # If the instance weight doesn't evenly divide the residual, add an extra instance (which will
            # cause some overflow in that market)
            if remainder > 0:
                instance_num += 1
                overflow = (instance_num * weight) - residual

                # Evenly divide the overflow among the remaining markets
                if remaining_markets > 0:
                    residual_correction += overflow / remaining_markets

            if instance_num != 0:
                new_market_counts[market] = instance_num + self.market_size(market)
        return new_market_counts
def _get_new_market_counts ( self , target_capacity ) : if target_capacity < self . target_capacity : raise ValueError ( f"Target capacity {target_capacity} < current capacity {self.target_capacity}" ) available_markets = self . _find_available_markets ( ) residuals = self . _compute_market_residuals ( target_capacity , available_markets ) residual_correction = 0 # If we overflow in one market, correct the residuals in the remaining markets new_market_counts = { market : len ( ids ) for market , ids in self . instance_ids_by_market . items ( ) } for i , ( market , residual ) in enumerate ( residuals ) : remaining_markets = len ( residuals ) - ( i + 1 ) # If the residual correction is larger than the residual, this means we shouldn't add any more instances # in this market because its residual has been "eaten up" by overflow in previous markets.  When this # happens, we just update the correction with any overflow that might have been introduced in *this* market. # Sorting the residuals in ascending order ensures correction has been updated by negative residuals # first. if residual < residual_correction : if remaining_markets > 0 : residual_correction += ( residual_correction - residual ) / remaining_markets continue residual -= residual_correction weight = self . _instance_types [ market ] . weight instance_num , remainder = divmod ( residual , weight ) # If the instance weight doesn't evenly divide the residual, add an extra instance (which will # cause some overflow in that market) if remainder > 0 : instance_num += 1 overflow = ( instance_num * weight ) - residual # Evenly divide the overflow among the remaining markets if remaining_markets > 0 : residual_correction += overflow / remaining_markets if instance_num != 0 : new_market_counts [ market ] = instance_num + self . market_size ( market ) return new_market_counts