google-research

Форк
0
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

23
namespace fair_secretary {
24

25
using std::string;
26
using std::vector;
27

28
vector<SecretaryInstance> BankOracle::GetSecretaryInput(int num_elements) {
29
  // The path to the dataset.
30
  string input_path ="";
31
  std::ifstream in(input_path);
32
  string input;
33
  // Ignoring the first line.
34
  std::getline(in, input);
35
  int counter = 0;
36
  vector<SecretaryInstance> instance;
37
  while (counter < num_elements) {
38
    int age, color = 0;
39
    if (!(in >> age)) {
40
      break;
41
    }
42
    color = (age - 21) / 10;
43
    if (age <= 30) {
44
      color = 0;
45
    }
46
    if (age > 60) {
47
      color = 4;
48
    }
49
    for (int i = 0; i < 11; i++) {
50
      std::getline(in, input, ';');
51
    }
52
    double value;
53
    in >> value;
54
    std::getline(in, input);
55
    SecretaryInstance element(value + counter * 0.0000001, color);
56
    instance.push_back(element);
57
    counter++;
58
  }
59
  num_colors = 0;
60
  for (int i = 0; i < instance.size(); i++) {
61
    num_colors = std::max(num_colors, instance[i].color);
62
  }
63
  num_colors++;
64
  return instance;
65
}
66

67
}  //  namespace fair_secretary
68

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

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

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

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