google-research
67 строк · 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 "bank_oracle.h"
16
17#include <fstream>
18#include <iostream>
19#include <string>
20
21#include "utils.h"
22
23namespace fair_secretary {
24
25using std::string;
26using std::vector;
27
28vector<SecretaryInstance> BankOracle::GetSecretaryInput(int num_elements) {
29// The path to the dataset.
30string input_path ="";
31std::ifstream in(input_path);
32string input;
33// Ignoring the first line.
34std::getline(in, input);
35int counter = 0;
36vector<SecretaryInstance> instance;
37while (counter < num_elements) {
38int age, color = 0;
39if (!(in >> age)) {
40break;
41}
42color = (age - 21) / 10;
43if (age <= 30) {
44color = 0;
45}
46if (age > 60) {
47color = 4;
48}
49for (int i = 0; i < 11; i++) {
50std::getline(in, input, ';');
51}
52double value;
53in >> value;
54std::getline(in, input);
55SecretaryInstance element(value + counter * 0.0000001, color);
56instance.push_back(element);
57counter++;
58}
59num_colors = 0;
60for (int i = 0; i < instance.size(); i++) {
61num_colors = std::max(num_colors, instance[i].color);
62}
63num_colors++;
64return instance;
65}
66
67} // namespace fair_secretary
68