MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
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
12
namespace
pbqp
{
13
14
/// A graph together with the optional `rn_priority` for `solve`.
15
struct
Instance
{
16
Graph
graph
;
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.
33
void
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.
37
void
write_json
(std::ostream& out,
const
Graph
& graph, fe::View<size_t> rn_priority = {});
38
39
}
// namespace pbqp
pbqp::Graph
A PBQP problem graph.
Definition
graph.h:252
graph.h
pbqp
Definition
dot.h:9
pbqp::write_json
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
pbqp::Instance::graph
Graph graph
Definition
json.h:16
pbqp::read_json
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
pbqp::Instance::rn_priority
fe::Vector< size_t > rn_priority
Empty, or one entry per node id.
Definition
json.h:18
pbqp::Instance
A graph together with the optional rn_priority for solve.
Definition
json.h:15
include
pbqp
json.h
Generated by
1.18.0