-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphColoring.cpp
More file actions
42 lines (36 loc) · 1.13 KB
/
Copy pathGraphColoring.cpp
File metadata and controls
42 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Created by 吴 歆韵 on 2025/3/17.
//
#include "GraphColoring.h"
#include <fstream>
#include <string>
namespace graph_coloring{
using std::ifstream;
using std::stoll;
auto read_instance_file(const string& file) -> pair<uint64_t, vector<array<string, 2>>>{
ifstream ifs(file);
if (!ifs.is_open()) {
std::cerr << "Could not open file " << file << std::endl;
std::abort();
}
print("Reading file: {}\n", file);
string data;
do{ifs>>data;}while(data != "edge");
ifs>>data;
const uint64_t vertex_num {static_cast<uint64_t>(stoll(data))};
ifs>>data;
const uint64_t edge_num {static_cast<uint64_t>(stoll(data))};
print("vertex num: {}, edge num: {}\n", vertex_num, edge_num);
vector<array<string, 2>> edges;
edges.reserve(edge_num);
while(!ifs.eof()){
ifs>>data;
if(ifs.eof())break;
assert(data == "e");
string source, target;
ifs>>source>>target;
edges.push_back({source, target});
}
return {vertex_num, edges};
}
}