google-research
70 строк · 2.0 Кб
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 "pokec_oracle.h"16
17#include <fstream>18#include <iostream>19#include <map>20#include <ostream>21#include <string>22
23#include "absl/container/btree_map.h"24#include "utils.h"25
26namespace fair_secretary {27
28using std::map;29using std::string;30using std::vector;31
32vector<SecretaryInstance> PokecOracle::GetSecretaryInput() {33string input_bmi = "";34string input_edges = "";35std::ifstream in_bmi(input_bmi);36std::ifstream in_edges(input_edges);37absl::btree_map<int, int> nodes;38absl::btree_map<int, int> ids;39int id, color;40int counter = 0;41while (in_bmi >> id >> color) {42if (nodes.find(id) != nodes.end()) {43std::cout << "Error: ID '" << id << "' does not exists." << std::endl;44}45nodes[id] = color;46ids[id] = counter++;47}48std::cout << counter << std::endl;49vector<int> degrees(counter, 0);50int v1, v2;51while (in_edges >> v1 >> v2) {52if (ids.find(v1) != ids.end() && ids.find(v2) != ids.end()) {53degrees[ids[v1]]++;54degrees[ids[v2]]++;55}56}57vector<SecretaryInstance> instance;58instance.reserve(counter);59for (int i = 0; i < counter; i++) {60instance.push_back(SecretaryInstance(degrees[i] + i * 0.0000001, nodes[i]));61}62num_colors = 0;63for (int i = 0; i < instance.size(); i++) {64num_colors = std::max(num_colors, instance[i].color);65}66num_colors++;67return instance;68}
69
70} // namespace fair_secretary71