MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
json.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <istream>
5#include <ostream>
6
7#include <fe/span.h>
8#include <fe/vector.h>
9
10#include "pbqp/graph.h"
11
12namespace pbqp {
13
14/// A graph together with the optional `rn_priority` for `solve`.
15struct Instance {
17 /// Empty, or one entry per node id.
18 fe::Vector<size_t> rn_priority;
19};
20
21/// Read a PBQP instance into the empty `instance`:
22///
23/// {
24/// "nodes": [{"costs": [0, "inf"]}, {"costs": [7, 0, 2]}],
25/// "edges": [{"src": 1, "dst": 0, "rows": 3, "cols": 2, "costs": [1, "inf", -5, 0, 4, 2]}],
26/// "rn_priority": [5, 9]
27/// }
28///
29/// The position of a node in `nodes` is its id.
30/// Edge `costs` are row-major with `src` as the row; `rows` and `cols` are optional and only checked.
31/// `"inf"` is Cost::inf, `rn_priority` is optional, and unknown keys are skipped.
32/// Throws `fe::Error::Bail`, a `std::exception`, on malformed input; `path` only names the input in its message.
33void read_json(std::istream& in, Instance& instance, const std::filesystem::path& path = "<input>");
34
35/// Write the format that `read_json` reads.
36/// Requires `rn_priority` to be empty or to have one entry per node.
37void write_json(std::ostream& out, const Graph& graph, fe::View<size_t> rn_priority = {});
38
39} // namespace pbqp
A PBQP problem graph.
Definition graph.h:252
Definition dot.h:9
void write_json(std::ostream &out, const Graph &graph, fe::View< size_t > rn_priority={})
Write the format that read_json reads.
Definition json.cpp:447
Graph graph
Definition json.h:16
void read_json(std::istream &in, Instance &instance, const std::filesystem::path &path="<input>")
Read a PBQP instance into the empty instance:
Definition json.cpp:440
fe::Vector< size_t > rn_priority
Empty, or one entry per node id.
Definition json.h:18
A graph together with the optional rn_priority for solve.
Definition json.h:15