Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

SyncPlanOptions.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 // enable if you have nlohmann json.hpp available
34 #if 0
35 
39 
40 # include <json.hpp>
41 
42 namespace ogdf::sync_plan {
43 
44 namespace internal {
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; // Extra space for '\0'
48  if (size <= 0) {
49  throw std::runtime_error("Error during formatting.");
50  }
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); // We don't want the '\0' inside
54 }
55 }
56 
58 class OGDF_EXPORT SyncPlanOptions {
59  struct EdgeOrder {
60  int node;
61  List<string> edges;
62 
63  EdgeOrder(int node) : node(node) { }
64  };
65 
66  FrozenPipeBij pipes;
67  List<List<int>> partitions;
68  List<EdgeOrder> orders;
69 
70 public:
71  void parseOptionPipes(char* optarg);
72 
73  void parseOptionPartitions(char* optarg);
74 
75  void parseOptionEmbedding(char* optarg);
76 
77  void apply(Graph& G, GraphAttributes& GA, SyncPlan& pq);
78 
79  static void applyConfigJSON(Graph& G, GraphAttributes& GA, SyncPlan& pq, nlohmann::json& j);
80 
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(); }) {
87  using nlohmann::json;
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());
94  }
95  pipes.push_back(json::array({nl(pipe.node1), nl(pipe.node2), adj1, adj2}));
96  }
97  j["pipes"] = pipes;
98 
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)) {
104  ids += nl(n);
105 
106  json adj = json::array();
107  for (adjEntry a : n->adjEntries) {
108  adj += el(a->theEdge());
109  }
110  embeddings.push_back(json::array({nl(n), adj}));
111  }
112  partitions.push_back(ids);
113  }
114  j["partitions"] = partitions;
115  j["embeddings"] = embeddings;
116  }
117 };
118 
119 }
120 
121 #endif
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::sync_plan
Definition: clustering.h:44
Bijection.h
Utilities for working with the bijections between the edges incident to the two endpoints of a Pipe.
ogdf::tlp::Attribute::size
@ size
ogdf::adjEntry
AdjElement * adjEntry
The type of adjacency entries.
Definition: Graph_d.h:78
ogdf::edge
EdgeElement * edge
The type of edges.
Definition: Graph_d.h:74
ogdf::node
NodeElement * node
The type of nodes.
Definition: Graph_d.h:70
ogdf::sync_plan::FrozenPipeBij
List< FrozenPipeBijPair > FrozenPipeBij
Definition: Bijection.h:51
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
SyncPlan.h
The main code for modelling and solving Synchronized Planarity instances.