45 template<
typename... Args>
46 std::string string_format(
const std::string& format,
const Args... args) {
47 size_t size = snprintf(
nullptr, 0, format.c_str(), args...) + 1;
49 throw std::runtime_error(
"Error during formatting.");
51 std::unique_ptr<char[]> buf(
new char[size]);
52 snprintf(buf.get(), size, format.c_str(), args...);
53 return std::string(buf.get(), buf.get() + size - 1);
67 List<List<int>> partitions;
68 List<EdgeOrder> orders;
71 void parseOptionPipes(
char* optarg);
73 void parseOptionPartitions(
char* optarg);
75 void parseOptionEmbedding(
char* optarg);
77 void apply(Graph& G, GraphAttributes& GA, SyncPlan& pq);
79 static void applyConfigJSON(Graph& G, GraphAttributes& GA, SyncPlan& pq, nlohmann::json& j);
81 template<
typename NodeLabeler = std::function<
int(node)>,
82 typename EdgeLabeler = std::function<
int(edge)>>
83 static void generateConfigJSON(
84 SyncPlan& pq, nlohmann::json& j,
85 const NodeLabeler& nl = [](
node n) ->
int {
return n->index(); },
86 const EdgeLabeler& el = [](
edge e) ->
int {
return e->index(); }) {
88 json pipes = json::array();
89 for (
const auto& pipe : pq.matchings) {
90 json adj1 = json::array(), adj2 = json::array();
91 for (
auto edges : pq.matchings.getIncidentEdgeBijection(pipe.node1)) {
92 adj1 += el(edges.first->theEdge());
93 adj2 += el(edges.second->theEdge());
95 pipes.push_back(json::array({nl(pipe.node1), nl(pipe.node2), adj1, adj2}));
99 json partitions = json::array();
100 json embeddings = json::array();
101 for (
int p = 0; p < pq.partitions.partitionCount(); p++) {
102 json ids = json::array();
103 for (
node n : pq.partitions.nodesInPartition(p)) {
106 json adj = json::array();
108 adj += el(a->theEdge());
110 embeddings.push_back(json::array({nl(n), adj}));
112 partitions.push_back(ids);
114 j[
"partitions"] = partitions;
115 j[
"embeddings"] = embeddings;