google-research

Форк
0
52 строки · 1.7 Кб
1
// Copyright 2024 The Google Research Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
#include "fair-prophet.h"
16

17
#include <functional>
18

19
namespace fair_secretary {
20

21
using std::vector;
22

23
SecretaryInstance FairProphetAlgorithm::ComputeSolution(
24
    const vector<SecretaryInstance>& elements,
25
    const std::vector<std::reference_wrapper<RandomDistribution>> distributions,
26
    const vector<double>& q) {
27
  double sum = 0;
28
  for (int i = 0; i < elements.size(); i++) {
29
    if (elements[i].value >= distributions[elements[i].type].get().Reverse(
30
                                 1.0 - (q[i] / (2 - sum)))) {
31
      return elements[i];
32
    }
33
    sum += q[i];
34
  }
35
  return SecretaryInstance(-1, -1);
36
}
37

38
SecretaryInstance FairProphetAlgorithm::ComputeSolutionIID(
39
    const vector<SecretaryInstance>& elements,
40
    const std::vector<std::reference_wrapper<RandomDistribution>> distributions,
41
    const vector<double>& q) {
42
  double p = (2.0 / 3.0) / elements.size();
43
  for (int i = 0; i < elements.size(); i++) {
44
    if (elements[i].value >=
45
        distributions[elements[i].type].get().Reverse(1.0 - p / (1 - p * i))) {
46
      return elements[i];
47
    }
48
  }
49
  return SecretaryInstance(-1, -1);
50
}
51

52
}  // namespace fair_secretary
53

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.