def action()

in online_attacks/online_algorithms/stochastic_modified_virtual.py [0:0]


    def action(self, value: float, index: int):
        if self.sampling_phase:
            self.R.append([value, index])
            self.R.sort(key=lambda tup: tup[0], reverse=True)  # sorts in place
            self.R = self.R[: self.k]

            if index >= self.threshold:
                self.sampling_phase = False
        else:
            k_value, k_index = self.R[-1]
            num_picked = len(self.S)
            num_left_to_pick = self.k - num_picked
            num_samples_left = self.N - index
            if (
                num_samples_left <= num_left_to_pick
                and self.exhaust
                and num_left_to_pick > 0
            ):
                # Just Pick the last samples to exhaust K
                self.S.append([value, index])
            elif value > k_value and num_left_to_pick > 0:
                # Update and pick
                self.S.append([value, index])
                self.R.append([value, index])
                self.R.sort(key=lambda tup: tup[0], reverse=True)  # sorts in place
                self.R = self.R[: self.k]