-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.cpp
More file actions
executable file
·61 lines (46 loc) · 1.73 KB
/
read.cpp
File metadata and controls
executable file
·61 lines (46 loc) · 1.73 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <fstream>
#include "json.hpp"
#include "read.h"
using namespace std;
using json = nlohmann::json;
int numVar;
// Read JSON file and extract examples
vector<Example> readExamples(const string& filename) {
vector<Example> examples;
// Read the JSON file
ifstream inputFile(filename);
if (!inputFile) {
throw runtime_error("Could not open the file!");
}
json j;
inputFile >> j;
// Extract the initial example
Example initialExample;
const auto& initialInputs = j["initial"]["inputs"];
const auto& initialOutput = j["initial"]["outputs"].begin().value(); // Assuming one output
// Set numVar based on the number of inputs
numVar = initialInputs.size();
// Extract initial inputs
for (const auto& input : initialInputs.items()) {
initialExample.inputs.push_back(stoull(input.value()["value"].get<string>(), nullptr, 16));
}
// Extract initial output
initialExample.output = stoull(initialOutput["value"].get<string>(), nullptr, 16);
// Add the initial example to the vector
examples.push_back(initialExample);
// Extract sampling examples
for (const auto& item : j["sampling"].items()) {
Example example;
const auto& inputs = item.value()["inputs"];
const auto& output = item.value()["outputs"].begin().value(); // Assuming one output
// Extract inputs
for (const auto& input : inputs.items()) {
example.inputs.push_back(stoull(input.value()["value"].get<string>(), nullptr, 16));
}
// Extract output
example.output = stoull(output["value"].get<string>(), nullptr, 16);
// Add the example to the vector
examples.push_back(example);
}
return examples;
}