google-research
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
19namespace fair_secretary {
20
21using std::vector;
22
23SecretaryInstance FairProphetAlgorithm::ComputeSolution(
24const vector<SecretaryInstance>& elements,
25const std::vector<std::reference_wrapper<RandomDistribution>> distributions,
26const vector<double>& q) {
27double sum = 0;
28for (int i = 0; i < elements.size(); i++) {
29if (elements[i].value >= distributions[elements[i].type].get().Reverse(
301.0 - (q[i] / (2 - sum)))) {
31return elements[i];
32}
33sum += q[i];
34}
35return SecretaryInstance(-1, -1);
36}
37
38SecretaryInstance FairProphetAlgorithm::ComputeSolutionIID(
39const vector<SecretaryInstance>& elements,
40const std::vector<std::reference_wrapper<RandomDistribution>> distributions,
41const vector<double>& q) {
42double p = (2.0 / 3.0) / elements.size();
43for (int i = 0; i < elements.size(); i++) {
44if (elements[i].value >=
45distributions[elements[i].type].get().Reverse(1.0 - p / (1 - p * i))) {
46return elements[i];
47}
48}
49return SecretaryInstance(-1, -1);
50}
51
52} // namespace fair_secretary
53