Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
GraphIO.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/Graph.h>
38#include <ogdf/basic/List.h>
39#include <ogdf/basic/Logger.h>
40#include <ogdf/basic/basic.h>
43
44#include <cctype>
45#include <cstdint>
46#include <fstream>
47#include <functional>
48#include <string>
49#include <type_traits>
50#include <unordered_map>
51#include <vector>
52
53namespace ogdf {
54class GridLayout;
55template<typename T>
56class EdgeWeightedGraph;
57
59
62class GraphIO {
63public:
65
67 using ReaderFunc = bool (*)(Graph&, std::istream&);
68
70 using WriterFunc = bool (*)(const Graph&, std::ostream&);
71
73 using AttrReaderFunc = bool (*)(GraphAttributes&, Graph&, std::istream&);
74
76 using AttrWriterFunc = bool (*)(const GraphAttributes&, std::ostream&);
77
79 using ClusterReaderFunc = bool (*)(ClusterGraph&, Graph&, std::istream&);
80
82 using ClusterWriterFunc = bool (*)(const ClusterGraph&, std::ostream&);
83
86 std::istream&);
87
89 using ClusterAttrWriterFunc = bool (*)(const ClusterGraphAttributes&, std::ostream&);
90
91 struct FileType {
92 std::vector<std::string> extensions;
105
106 explicit FileType(std::vector<std::string> extensions, ReaderFunc readerFunc = nullptr,
107 WriterFunc writerFunc = nullptr, AttrReaderFunc attrReaderFunc = nullptr,
108 AttrWriterFunc attrWriterFunc = nullptr,
109 ClusterReaderFunc clusterReaderFunc = nullptr,
110 ClusterWriterFunc clusterWriterFunc = nullptr,
111 ClusterAttrReaderFunc clusterAttrReaderFunc = nullptr,
112 ClusterAttrWriterFunc clusterAttrWriterFunc = nullptr);
113
115 AttrReaderFunc attrReaderFunc = nullptr,
116 ClusterReaderFunc clusterReaderFunc = nullptr,
117 ClusterAttrReaderFunc clusterAttrReaderFunc = nullptr);
118 };
119
120 static const OGDF_EXPORT std::vector<FileType> FILE_TYPES;
121 static OGDF_EXPORT std::unordered_map<string, const FileType*> FILE_TYPE_MAP;
122
123 static OGDF_EXPORT const std::unordered_map<string, const FileType*>& getFileTypeMap();
124
125 static OGDF_EXPORT const FileType* getFileType(const string& filename);
126
129 double m_margin;
135 string m_width;
136 string m_height;
137
138 public:
140
142 bool bezierInterpolation() const { return m_bezierInterpolation; }
143
145 double margin() const { return m_margin; }
146
148 double curviness() const { return m_curviness; }
149
151 int fontSize() const { return m_fontSize; }
152
154 const string& fontColor() const { return m_fontColor; }
155
157 const string& fontFamily() const { return m_fontFamily; }
158
160 const string& width() const { return m_width; }
161
163 const string& height() const { return m_height; }
164
166 void margin(double m) { m_margin = m; }
167
169 void curviness(double value) {
170 OGDF_ASSERT(value >= 0);
171 OGDF_ASSERT(value <= 1);
172
173 m_curviness = value;
174 }
175
177 void bezierInterpolation(bool enable) { m_bezierInterpolation = enable; }
178
180 void fontSize(int fs) { m_fontSize = fs; }
181
183 void fontColor(const string& fc) { m_fontColor = fc; }
184
186 void fontFamily(const string& fm) { m_fontFamily = fm; }
187
189
192 void width(const string& width) { m_width = width; }
193
195
198 void height(const string& height) { m_height = height; }
199 };
200
320
330 static OGDF_EXPORT bool read(Graph& G, const string& filename, ReaderFunc reader = nullptr);
331
342 static OGDF_EXPORT bool read(GraphAttributes& GA, Graph& G, const string& filename,
343 AttrReaderFunc reader = nullptr);
344
355 static OGDF_EXPORT bool read(ClusterGraph& CG, Graph& G, const string& filename,
356 ClusterReaderFunc reader = nullptr);
357
372 const string& filename, ClusterAttrReaderFunc reader = nullptr);
373
383 static OGDF_EXPORT bool read(Graph& G, std::istream& is);
384
395 static OGDF_EXPORT bool read(GraphAttributes& GA, Graph& G, std::istream& is);
396
407 static OGDF_EXPORT bool read(ClusterGraph& CG, Graph& G, std::istream& is);
408
423 std::istream& is);
424
433 static OGDF_EXPORT bool write(const Graph& G, const string& filename,
434 WriterFunc writer = nullptr);
435
444 static OGDF_EXPORT bool write(const GraphAttributes& GA, const string& filename,
445 AttrWriterFunc writer = nullptr);
446
455 static OGDF_EXPORT bool write(const ClusterGraph& CG, const string& filename,
456 ClusterWriterFunc writer = nullptr);
457
468 static OGDF_EXPORT bool write(const ClusterGraphAttributes& GA, const string& filename,
469 ClusterAttrWriterFunc writer = nullptr);
470
472
473#pragma mark GML
480
482
494 static OGDF_EXPORT bool readGML(Graph& G, std::istream& is);
495
497
509 static OGDF_EXPORT bool writeGML(const Graph& G, std::ostream& os);
510
512
521 static OGDF_EXPORT bool readGML(ClusterGraph& C, Graph& G, std::istream& is);
522
524
531 static OGDF_EXPORT bool writeGML(const ClusterGraph& C, std::ostream& os);
532
534
545 std::istream& is);
546
548
555 static OGDF_EXPORT bool writeGML(const ClusterGraphAttributes& A, std::ostream& os);
556
558
567 static OGDF_EXPORT bool readGML(GraphAttributes& A, Graph& G, std::istream& is);
568
570
577 static OGDF_EXPORT bool writeGML(const GraphAttributes& A, std::ostream& os);
578
580
581#pragma mark Rome
588
590
603 static OGDF_EXPORT bool readRome(Graph& G, std::istream& is);
604
606
613 static OGDF_EXPORT bool writeRome(const Graph& G, std::ostream& os);
614
616
617#pragma mark LEDA
624
626
639 static OGDF_EXPORT bool readLEDA(Graph& G, std::istream& is);
640
642
655 static OGDF_EXPORT bool writeLEDA(const Graph& G, std::ostream& os);
656
658
659#pragma mark Chaco
666
668
681 static OGDF_EXPORT bool readChaco(Graph& G, std::istream& is);
682
684
697 static OGDF_EXPORT bool writeChaco(const Graph& G, std::ostream& os);
698
700
701#pragma mark PMDissGraph
708
710
725 static OGDF_EXPORT bool readPMDissGraph(Graph& G, std::istream& is);
726
728
743 static OGDF_EXPORT bool writePMDissGraph(const Graph& G, std::ostream& os);
744
746
747#pragma mark YGraph
754
756
776 static OGDF_EXPORT bool readYGraph(Graph& G, std::istream& is);
777
779
780#pragma mark Graph6
790
792
800 static OGDF_EXPORT bool readGraph6(Graph& G, std::istream& is, bool forceHeader = false);
801
803
810 static OGDF_EXPORT bool writeGraph6(const Graph& G, std::ostream& os);
811
813
814#pragma mark Digraph6
823
825
833 static OGDF_EXPORT bool readDigraph6(Graph& G, std::istream& is, bool forceHeader = false);
834
836
843 static OGDF_EXPORT bool writeDigraph6(const Graph& G, std::ostream& os);
844
846
847#pragma mark Sparse6
856
858
866 static OGDF_EXPORT bool readSparse6(Graph& G, std::istream& is, bool forceHeader = false);
867
869
876 static OGDF_EXPORT bool writeSparse6(const Graph& G, std::ostream& os);
877
879
880#pragma mark MatrixMarket
887
889
894 static OGDF_EXPORT bool readMatrixMarket(Graph& G, std::istream& inStream);
895
897
898#pragma mark Rudy
903
905
914 static OGDF_EXPORT bool readRudy(GraphAttributes& A, Graph& G, std::istream& is);
915
917
924 static OGDF_EXPORT bool readRudy(Graph& G, std::istream& is) {
926 return readRudy(A, G, is);
927 }
928
930
938 static OGDF_EXPORT bool writeRudy(const GraphAttributes& A, std::ostream& os);
939
941
942#pragma mark BENCH
947
949
966 static OGDF_EXPORT bool readBENCH(Graph& G, List<node>& hypernodes, List<edge>* shell,
967 std::istream& is);
968
970
971#pragma mark PLA
976
978
995 static OGDF_EXPORT bool readPLA(Graph& G, List<node>& hypernodes, List<edge>* shell,
996 std::istream& is);
997
999
1000#pragma mark ChallengeGraph
1008
1010
1019 static OGDF_EXPORT bool readChallengeGraph(Graph& G, GridLayout& gl, std::istream& is);
1020
1022
1031 static OGDF_EXPORT bool writeChallengeGraph(const Graph& G, const GridLayout& gl,
1032 std::ostream& os);
1033
1035
1036#pragma mark GraphML
1043
1045
1052 static OGDF_EXPORT bool readGraphML(Graph& G, std::istream& is);
1053
1055
1064 static OGDF_EXPORT bool readGraphML(ClusterGraph& C, Graph& G, std::istream& is);
1065
1067
1076 static OGDF_EXPORT bool readGraphML(GraphAttributes& A, Graph& G, std::istream& is);
1077
1079
1090 std::istream& is);
1091
1093
1099 static OGDF_EXPORT bool writeGraphML(const Graph& G, std::ostream& os);
1100
1102
1108 static OGDF_EXPORT bool writeGraphML(const ClusterGraph& C, std::ostream& os);
1109
1111
1117 static OGDF_EXPORT bool writeGraphML(const GraphAttributes& A, std::ostream& os);
1118
1120
1126 static OGDF_EXPORT bool writeGraphML(const ClusterGraphAttributes& A, std::ostream& os);
1127
1129
1130#pragma mark DOT
1137
1139
1146 static OGDF_EXPORT bool readDOT(Graph& G, std::istream& is);
1147
1149
1158 static OGDF_EXPORT bool readDOT(ClusterGraph& C, Graph& G, std::istream& is);
1159
1161
1170 static OGDF_EXPORT bool readDOT(GraphAttributes& A, Graph& G, std::istream& is);
1171
1173
1184 std::istream& is);
1185
1187
1193 static OGDF_EXPORT bool writeDOT(const Graph& G, std::ostream& os);
1194
1196
1202 static OGDF_EXPORT bool writeDOT(const ClusterGraph& C, std::ostream& os);
1203
1205
1211 static OGDF_EXPORT bool writeDOT(const GraphAttributes& A, std::ostream& os);
1212
1214
1220 static OGDF_EXPORT bool writeDOT(const ClusterGraphAttributes& A, std::ostream& os);
1221
1223
1224#pragma mark GEXF
1231
1233
1240 static OGDF_EXPORT bool readGEXF(Graph& G, std::istream& is);
1241
1243
1252 static OGDF_EXPORT bool readGEXF(ClusterGraph& C, Graph& G, std::istream& is);
1253
1255
1264 static OGDF_EXPORT bool readGEXF(GraphAttributes& A, Graph& G, std::istream& is);
1265
1267
1278 std::istream& is);
1279
1281
1287 static OGDF_EXPORT bool writeGEXF(const Graph& G, std::ostream& os);
1288
1290
1296 static OGDF_EXPORT bool writeGEXF(const ClusterGraph& C, std::ostream& os);
1297
1299
1305 static OGDF_EXPORT bool writeGEXF(const GraphAttributes& A, std::ostream& os);
1306
1308
1314 static OGDF_EXPORT bool writeGEXF(const ClusterGraphAttributes& A, std::ostream& os);
1315
1317
1318#pragma mark GDF
1325
1327
1334 static OGDF_EXPORT bool readGDF(Graph& G, std::istream& is);
1335
1337
1346 static OGDF_EXPORT bool readGDF(GraphAttributes& A, Graph& G, std::istream& is);
1347
1349
1355 static OGDF_EXPORT bool writeGDF(const Graph& G, std::ostream& os);
1356
1358
1364 static OGDF_EXPORT bool writeGDF(const GraphAttributes& A, std::ostream& os);
1365
1367
1368#pragma mark TLP
1375
1377
1384 static OGDF_EXPORT bool readTLP(Graph& G, std::istream& is);
1385
1387
1396 static OGDF_EXPORT bool readTLP(ClusterGraph& C, Graph& G, std::istream& is);
1397
1399
1408 static OGDF_EXPORT bool readTLP(GraphAttributes& A, Graph& G, std::istream& is);
1409
1411
1422 std::istream& is);
1423
1425
1431 static OGDF_EXPORT bool writeTLP(const Graph& G, std::ostream& os);
1432
1434
1440 static OGDF_EXPORT bool writeTLP(const ClusterGraph& C, std::ostream& os);
1441
1443
1449 static OGDF_EXPORT bool writeTLP(const GraphAttributes& A, std::ostream& os);
1450
1452
1458 static OGDF_EXPORT bool writeTLP(const ClusterGraphAttributes& A, std::ostream& os);
1459
1461
1462#pragma mark DL
1469
1471
1478 static OGDF_EXPORT bool readDL(Graph& G, std::istream& is);
1479
1481
1490 static OGDF_EXPORT bool readDL(GraphAttributes& A, Graph& G, std::istream& is);
1491
1493
1499 static OGDF_EXPORT bool writeDL(const Graph& G, std::ostream& os);
1500
1502
1508 static OGDF_EXPORT bool writeDL(const GraphAttributes& A, std::ostream& os);
1509
1511
1512#pragma mark STP
1519
1527 static OGDF_EXPORT bool readSTP(GraphAttributes& attr, Graph& G, List<node>& terminals,
1528 NodeArray<bool>& isTerminal, std::istream& is);
1529
1540 static OGDF_EXPORT bool readSTP(GraphAttributes& attr, Graph& G, std::istream& is) {
1541 List<node> terminals;
1542 NodeArray<bool> isTerminal;
1543 return readSTP(attr, G, terminals, isTerminal, is);
1544 }
1545
1553 static OGDF_EXPORT bool readSTP(Graph& G, std::istream& is) {
1554 GraphAttributes attr(G);
1555 return readSTP(attr, G, is);
1556 }
1557
1571 template<typename T>
1572 static bool readSTP(EdgeWeightedGraph<T>& wG, List<node>& terminals,
1573 NodeArray<bool>& isTerminal, std::istream& is) {
1574 wG.clear();
1575 GraphAttributes attr(wG, getEdgeWeightFlag<T>());
1576 bool res = readSTP(attr, wG, terminals, isTerminal, is);
1577 for (edge e : wG.edges) {
1578 wG.setWeight(e, getEdgeWeightAttribute<T>(attr, e));
1579 }
1580 return res;
1581 }
1582
1600 static OGDF_EXPORT bool writeSTP(const GraphAttributes& attr, const List<node>& terminals,
1601 std::ostream& os, const string& comments = "");
1602
1615 template<typename T>
1616 static bool writeSTP(const EdgeWeightedGraph<T>& wG, const List<node>& terminals,
1617 std::ostream& os, const string& comments = "") {
1618 GraphAttributes attr(wG, getEdgeWeightFlag<T>());
1619 for (edge e : wG.edges) {
1620 getEdgeWeightAttribute<T>(attr, e) = wG.weight(e);
1621 }
1622 return writeSTP(attr, terminals, os, comments);
1623 }
1624
1626
1627#pragma mark DMF
1634
1640 static OGDF_EXPORT bool readDMF(GraphAttributes& attr, Graph& graph, node& source, node& sink,
1641 std::istream& is);
1642
1652 static OGDF_EXPORT bool readDMF(GraphAttributes& attr, Graph& graph, std::istream& is) {
1653 node sink;
1654 node source;
1655 return readDMF(attr, graph, sink, source, is);
1656 };
1657
1670 template<typename T>
1671 static bool readDMF(Graph& graph, EdgeArray<T>& weights, node& source, node& sink,
1672 std::istream& is) {
1673 GraphAttributes attr(graph, getEdgeWeightFlag<T>());
1674 bool result = readDMF(attr, graph, source, sink, is);
1675 weights.init(graph);
1676 for (edge e : graph.edges) {
1677 weights[e] = getEdgeWeightAttribute<T>(attr, e);
1678 }
1679 return result;
1680 }
1681
1690 static OGDF_EXPORT bool readDMF(Graph& graph, std::istream& is) {
1691 GraphAttributes attr(graph);
1692 node source;
1693 node sink;
1694 return readDMF(attr, graph, source, sink, is);
1695 }
1696
1710 static OGDF_EXPORT bool writeDMF(const GraphAttributes& attr, const node source,
1711 const node sink, std::ostream& os);
1712
1724 template<typename T>
1725 static bool writeDMF(const Graph& graph, const EdgeArray<T>& weights, const node source,
1726 const node sink, std::ostream& os) {
1727 GraphAttributes attr(graph, getEdgeWeightFlag<T>());
1728 for (edge e : graph.edges) {
1729 getEdgeWeightAttribute<T>(attr, e) = weights[e];
1730 }
1731 return writeDMF(attr, source, sink, os);
1732 }
1733
1734#pragma mark TsplibXml
1741
1743
1748 static OGDF_EXPORT bool readTsplibXml(Graph& G, std::istream& is);
1749
1751
1759 static OGDF_EXPORT bool readTsplibXml(GraphAttributes& GA, Graph& G, std::istream& is);
1761
1763
1769
1771
1779 static OGDF_EXPORT bool readEdgeListSubgraph(Graph& G, List<edge>& delEdges, std::istream& is);
1780
1782
1790 static OGDF_EXPORT bool writeEdgeListSubgraph(const Graph& G, const List<edge>& delEdges,
1791 std::ostream& os);
1792
1794
1799
1800 static OGDF_EXPORT bool drawSVG(const GraphAttributes& A, std::ostream& os,
1801 const SVGSettings& settings);
1802
1803 static inline bool drawSVG(const GraphAttributes& A, std::ostream& os) {
1804 // we may not use a defaulted argument settings=svgSettings here if drawSVG should be a AttrWriterFunc:
1805 // https://stackoverflow.com/a/2225426/805569
1806 return drawSVG(A, os, svgSettings);
1807 }
1808
1809 static inline bool drawSVG(const GraphAttributes& A, const string& filename,
1810 const SVGSettings& settings = svgSettings) {
1811 std::ofstream os(filename);
1812 return os.good() && drawSVG(A, os, settings);
1813 }
1814
1815 static OGDF_EXPORT bool drawSVG(const ClusterGraphAttributes& A, std::ostream& os,
1816 const SVGSettings& settings);
1817
1818 static inline bool drawSVG(const ClusterGraphAttributes& A, std::ostream& os) {
1819 return drawSVG(A, os, svgSettings);
1820 }
1821
1822 static inline bool drawSVG(const ClusterGraphAttributes& A, const string& filename,
1823 const SVGSettings& settings = svgSettings) {
1824 std::ofstream os(filename);
1825 return os.good() && drawSVG(A, os, settings);
1826 }
1827
1835 static OGDF_EXPORT bool drawTikz(const GraphAttributes& A, std::ostream& os);
1836
1844 static OGDF_EXPORT bool drawTikz(const ClusterGraphAttributes& A, std::ostream& os);
1845
1847
1853
1855 static char indentChar() { return s_indentChar; }
1856
1858 static int indentWidth() { return s_indentWidth; }
1859
1861
1864 static void setIndentChar(char c) {
1865 OGDF_ASSERT(isspace((int)c));
1866 s_indentChar = c;
1867 }
1868
1870
1874 static void setIndentWidth(int w) {
1875 if (w >= 0) {
1876 s_indentWidth = w;
1877 }
1878 }
1879
1881 static OGDF_EXPORT std::ostream& indent(std::ostream& os, int depth);
1882
1886
1889 static OGDF_EXPORT bool setColorValue(int value, std::function<void(uint8_t)> setFunction) {
1890 if (value < 0 || value > 255) {
1891 GraphIO::logger.lout() << "Error: color value is not between 0 and 255." << std::endl;
1892 return false;
1893 }
1894 setFunction(static_cast<uint8_t>(value));
1895 return true;
1896 }
1897
1899
1902 template<typename T, typename std::enable_if<std::is_integral<T>::value, bool>::type = 0>
1903 static long getEdgeWeightFlag() {
1905 }
1906
1908
1911 template<typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = 0>
1912 static long getEdgeWeightFlag() {
1914 }
1915
1917
1922 template<typename T, typename std::enable_if<std::is_integral<T>::value, bool>::type = 0>
1924 return attr.intWeight(e);
1925 }
1926
1928
1933 template<typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = 0>
1935 return attr.doubleWeight(e);
1936 }
1937
1939
1941
1942private:
1945};
1946
1947}
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Declares ClusterGraphAttributes, an extension of class GraphAttributes, to store clustergraph layout ...
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Contains logging functionality.
Basic declarations, included by all source files.
Stores additional attributes of a clustered graph (like layout information).
Representation of clustered graphs.
Class for the representation of edges.
Definition Graph_d.h:364
T weight(const edge e) const
void setWeight(const edge e, T weight)
Stores additional attributes of a graph (like layout information).
int intWeight(edge e) const
Returns the (integer) weight of edge e.
double doubleWeight(edge e) const
Returns the (real number) weight of edge e.
static const long edgeDoubleWeight
Corresponds to edge attribute doubleWeight(edge).
static const long edgeIntWeight
Corresponds to edge attribute intWeight(edge).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
virtual void clear()
Removes all nodes and all edges from the graph.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
Condensed settings for drawing SVGs.
Definition GraphIO.h:128
const string & fontFamily() const
Returns the default font family.
Definition GraphIO.h:157
const string & height() const
Returns the default height.
Definition GraphIO.h:163
void curviness(double value)
Sets the curviness of all edges (value ranges from 0 to 1).
Definition GraphIO.h:169
const string & width() const
Returns the default width.
Definition GraphIO.h:160
int fontSize() const
Returns the default font size (font height in pixels).
Definition GraphIO.h:151
void fontFamily(const string &fm)
Sets the default font family to fm.
Definition GraphIO.h:186
void margin(double m)
Sets the size of the margin around the drawing to m.
Definition GraphIO.h:166
bool bezierInterpolation() const
Returns whether Bézier-interpolation for curved edges is enabled.
Definition GraphIO.h:142
void height(const string &height)
Sets the height.
Definition GraphIO.h:198
double curviness() const
Returns the curviness of the edges (value ranges from 0 to 1).
Definition GraphIO.h:148
const string & fontColor() const
Returns the default font color.
Definition GraphIO.h:154
void fontSize(int fs)
Sets the default font size (font height in pixels) to fs.
Definition GraphIO.h:180
double margin() const
Returns the size of the margin around the drawing.
Definition GraphIO.h:145
void fontColor(const string &fc)
Sets the default font color to fc.
Definition GraphIO.h:183
void width(const string &width)
Sets the width.
Definition GraphIO.h:192
void bezierInterpolation(bool enable)
Enables or disables Bézier-interpolation.
Definition GraphIO.h:177
Utility class providing graph I/O in various exchange formats.
Definition GraphIO.h:62
static bool writeEdgeListSubgraph(const Graph &G, const List< edge > &delEdges, std::ostream &os)
Writes graph G with subgraph defined by delEdges to stream os.
static bool writeTLP(const Graph &G, std::ostream &os)
Writes graph G in TLP format to output stream os.
static bool readDMF(Graph &graph, EdgeArray< T > &weights, node &source, node &sink, std::istream &is)
Reads a maximum flow instance in DIMACS format.
Definition GraphIO.h:1671
static bool writeDMF(const Graph &graph, const EdgeArray< T > &weights, const node source, const node sink, std::ostream &os)
Writes a maximum flow problem instance to a DIMACS maximum flow file.
Definition GraphIO.h:1725
static bool read(ClusterGraphAttributes &GA, ClusterGraph &CG, Graph &G, std::istream &is)
Reads graph G, a clustering CG of G and their attributes GA from a stream is and try to guess the con...
static bool writeDOT(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in DOT format to output stream os.
static bool drawSVG(const GraphAttributes &A, std::ostream &os)
Definition GraphIO.h:1803
static bool writeGML(const ClusterGraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GML format to output stream os.
static bool readDigraph6(Graph &G, std::istream &is, bool forceHeader=false)
Reads graph G in Digraph6 format from input stream is.
static bool readRudy(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with edge weights stored in A in Rudy format from input stream is.
static bool writeDigraph6(const Graph &G, std::ostream &os)
Writes graph G in Digraph6 format to output stream os.
static bool readDOT(ClusterGraphAttributes &A, ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) with attributes A in DOT format from input stream is.
bool(*)(Graph &, std::istream &) ReaderFunc
Type of simple graph reader functions working on streams.
Definition GraphIO.h:67
static bool readTsplibXml(Graph &G, std::istream &is)
Reads graph G in TsplibXml format from input stream is.
static bool readGEXF(Graph &G, std::istream &is)
Reads graph G in GEXF format from input stream is.
static bool writeGML(const ClusterGraph &C, std::ostream &os)
Writes clustered graph C in GML format to output stream os.
static bool readSTP(GraphAttributes &attr, Graph &G, std::istream &is)
Reads a graph in SteinLib format from std::istream is.
Definition GraphIO.h:1540
static bool readChaco(Graph &G, std::istream &is)
Reads graph G in Chaco format from input stream is.
static bool drawSVG(const ClusterGraphAttributes &A, const string &filename, const SVGSettings &settings=svgSettings)
Definition GraphIO.h:1822
static bool write(const Graph &G, const string &filename, WriterFunc writer=nullptr)
Writes graph G to a file with name filename and infers the format to use from the file's extension.
static bool writeGEXF(const ClusterGraph &C, std::ostream &os)
Writes clustered graph C in GEXF format to output stream os.
static bool writeSTP(const GraphAttributes &attr, const List< node > &terminals, std::ostream &os, const string &comments="")
Writes an Steiner problem instance to an STP file.
static bool readRudy(Graph &G, std::istream &is)
Reads graph G in Rudy format from input stream is.
Definition GraphIO.h:924
static double & getEdgeWeightAttribute(GraphAttributes &attr, edge e)
Returns a reference to the doubleWeight()-value of attr for e.
Definition GraphIO.h:1934
static bool readDOT(ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) in DOT format from input stream is.
static bool writeGraphML(const ClusterGraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GraphML format to output stream os.
static bool write(const GraphAttributes &GA, const string &filename, AttrWriterFunc writer=nullptr)
Writes graph G and its attributes GA to a file with name filename and infers the format to use from t...
static std::unordered_map< string, const FileType * > FILE_TYPE_MAP
Definition GraphIO.h:121
static bool writeChaco(const Graph &G, std::ostream &os)
Writes graph G in Chaco format to output stream os.
static SVGSettings svgSettings
Definition GraphIO.h:1940
static bool readGraphML(Graph &G, std::istream &is)
Reads graph G in GraphML format from input stream is.
static bool writeDL(const Graph &G, std::ostream &os)
Writes graph G in DL format to output stream os.
static bool writeGraphML(const ClusterGraph &C, std::ostream &os)
Writes clustered graph C in GraphML format to output stream os.
static bool readTLP(Graph &G, std::istream &is)
Reads graph G in TLP format from input stream is.
static bool readGEXF(ClusterGraphAttributes &A, ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) with attributes A in GEXF format from input stream is.
static bool readGML(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in GML format from input stream is.
static bool readTLP(ClusterGraphAttributes &A, ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) with attributes A in TLP format from input stream is.
static bool readDMF(GraphAttributes &attr, Graph &graph, std::istream &is)
Reads a maximum flow instance in DIMACS format.
Definition GraphIO.h:1652
static bool setColorValue(int value, std::function< void(uint8_t)> setFunction)
Set a color value (R/G/B/A) based on an integer. Checks if the value is in the right range.
Definition GraphIO.h:1889
static const std::vector< FileType > FILE_TYPES
Definition GraphIO.h:120
static std::ostream & indent(std::ostream &os, int depth)
Prints indentation for indentation depth to output stream os and returns os.
bool(*)(ClusterGraphAttributes &, ClusterGraph &, Graph &, std::istream &) ClusterAttrReaderFunc
Type of cluster graph attributes reader functions working on streams.
Definition GraphIO.h:86
static bool writeDOT(const ClusterGraph &C, std::ostream &os)
Writes clustered graph C in DOT format to output stream os.
static bool readMatrixMarket(Graph &G, std::istream &inStream)
Reads graph G in Matrix Market exchange format from stream inStream.
static bool readGDF(Graph &G, std::istream &is)
Reads graph G in GDF format from input stream is.
static bool readGML(ClusterGraphAttributes &A, ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) with attributes A in GML format from input stream is.
static bool readSTP(EdgeWeightedGraph< T > &wG, List< node > &terminals, NodeArray< bool > &isTerminal, std::istream &is)
Reads a SteinLib instance from an inputstream is and converts it into a weighted graph wG and a set o...
Definition GraphIO.h:1572
static bool writeRome(const Graph &G, std::ostream &os)
Writes graph G in Rome-Lib format to output stream os.
static bool read(Graph &G, std::istream &is)
Reads graph G from a stream is and try to guess the contained format by trying all available readers.
static char s_indentChar
Character used for indentation.
Definition GraphIO.h:1943
static bool writeTLP(const ClusterGraph &C, std::ostream &os)
Writes clustered graph C in TLP format to output stream os.
static bool write(const ClusterGraphAttributes &GA, const string &filename, ClusterAttrWriterFunc writer=nullptr)
Writes graph G, a clustering CG of G and their attributes CGA to a file with name filename and infers...
static bool drawSVG(const ClusterGraphAttributes &A, std::ostream &os, const SVGSettings &settings)
static bool read(ClusterGraph &CG, Graph &G, const string &filename, ClusterReaderFunc reader=nullptr)
Reads graph G and a clustering CG of G from a file with name filename and infers the used format from...
static bool readPLA(Graph &G, List< node > &hypernodes, List< edge > *shell, std::istream &is)
Reads a hypergraph (as point-based expansion) in PLA format from input stream is.
static bool readGraphML(ClusterGraphAttributes &A, ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) with attributes A in GraphML format from input stream is.
bool(*)(const ClusterGraph &, std::ostream &) ClusterWriterFunc
Type of cluster graph writer functions working on streams.
Definition GraphIO.h:82
static bool writeRudy(const GraphAttributes &A, std::ostream &os)
Writes graph with edge weights stored in A in Rudy format to output stream os.
static bool readTLP(ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) in TLP format from input stream is.
static bool readGEXF(ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) in GEXF format from input stream is.
static bool readDMF(Graph &graph, std::istream &is)
Reads a maximum flow instance in DIMACS format.
Definition GraphIO.h:1690
static bool writeGraphML(const Graph &G, std::ostream &os)
Writes graph G in GraphML format to output stream os.
static void setIndentChar(char c)
Sets the indentation character to c.
Definition GraphIO.h:1864
static bool writeGraphML(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GraphML format to output stream os.
static bool read(GraphAttributes &GA, Graph &G, const string &filename, AttrReaderFunc reader=nullptr)
Reads graph G and its attributes GA from a file with name filename and infers the used format from th...
static long getEdgeWeightFlag()
Returns GraphAttributes::edgeIntWeight.
Definition GraphIO.h:1903
static bool writeDOT(const Graph &G, std::ostream &os)
Writes graph G in DOT format to output stream os.
static bool readSparse6(Graph &G, std::istream &is, bool forceHeader=false)
Reads graph G in Sparse6 format from input stream is.
static bool writeGML(const Graph &G, std::ostream &os)
Writes graph G in GML format to output stream os.
static bool writeDOT(const ClusterGraphAttributes &A, std::ostream &os)
Writes graph with attributes A in DOT format to output stream os.
static bool readPMDissGraph(Graph &G, std::istream &is)
Reads graph G in a simple format as used in Petra Mutzel's thesis from input stream is.
static bool readTLP(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in TLP format from input stream is.
bool(*)(const Graph &, std::ostream &) WriterFunc
Type of simple graph writer functions working on streams.
Definition GraphIO.h:70
static bool readDOT(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in DOT format from input stream is.
static bool read(ClusterGraphAttributes &GA, ClusterGraph &CG, Graph &G, const string &filename, ClusterAttrReaderFunc reader=nullptr)
Reads graph G, a clustering CG of G and their attributes CGA from a file with name filename and infer...
static bool writeGML(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GML format to output stream os.
static bool writeGEXF(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GEXF format to output stream os.
bool(*)(const ClusterGraphAttributes &, std::ostream &) ClusterAttrWriterFunc
Type of cluster graph attributes writer functions working on streams.
Definition GraphIO.h:89
static bool drawSVG(const GraphAttributes &A, std::ostream &os, const SVGSettings &settings)
static bool writeChallengeGraph(const Graph &G, const GridLayout &gl, std::ostream &os)
Writes graph G with grid layout gl in GD-Challenge-format to output stream os.
static bool read(ClusterGraph &CG, Graph &G, std::istream &is)
Reads graph G and a clustering CG of G from a stream is and try to guess the contained format by tryi...
static bool drawTikz(const ClusterGraphAttributes &A, std::ostream &os)
Draws a cluster graph from its attributes in LaTeX+TikZ format.
static Logger logger
Definition GraphIO.h:64
static bool readGraphML(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in GraphML format from input stream is.
static int & getEdgeWeightAttribute(GraphAttributes &attr, edge e)
Returns a reference to the intWeight()-value of attr for e.
Definition GraphIO.h:1923
static bool writeTLP(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in TLP format to output stream os.
static bool readBENCH(Graph &G, List< node > &hypernodes, List< edge > *shell, std::istream &is)
Reads a hypergraph (as point-based expansion) in BENCH format from input stream is.
static bool readDL(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in DL format from input stream is.
static bool readDMF(GraphAttributes &attr, Graph &graph, node &source, node &sink, std::istream &is)
Reads a maximum flow instance in DIMACS format.
static bool writeLEDA(const Graph &G, std::ostream &os)
Writes graph G in LEDA graph format to output stream os.
static bool readDL(Graph &G, std::istream &is)
Reads graph G in DL format from input stream is.
static const std::unordered_map< string, const FileType * > & getFileTypeMap()
static bool readLEDA(Graph &G, std::istream &is)
Reads graph G in LEDA graph format from input stream is.
static bool writeDL(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in DL format to output stream os.
static bool readSTP(GraphAttributes &attr, Graph &G, List< node > &terminals, NodeArray< bool > &isTerminal, std::istream &is)
Reads a graph in SteinLib format from std::istream is.
static bool readTsplibXml(GraphAttributes &GA, Graph &G, std::istream &is)
Reads graph G with attributes GA in TsplibXml format from input stream is.
static bool readRome(Graph &G, std::istream &is)
Reads graph G in Rome-Lib format from input stream is.
static bool writeGEXF(const Graph &G, std::ostream &os)
Writes graph G in GEXF format to output stream os.
static bool writeTLP(const ClusterGraphAttributes &A, std::ostream &os)
Writes graph with attributes A in TLP format to output stream os.
static bool writePMDissGraph(const Graph &G, std::ostream &os)
Writes graph G in a simple format as used in Petra Mutzel's thesis to output stream os.
static bool readGEXF(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in GEXF format from input stream is.
bool(*)(const GraphAttributes &, std::ostream &) AttrWriterFunc
Type of simple graph attributes writer functions working on streams.
Definition GraphIO.h:76
static int s_indentWidth
Number of indent characters used for indentation.
Definition GraphIO.h:1944
static bool writeGDF(const GraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GDF format to output stream os.
static bool readGML(ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) in GML format from input stream is.
static bool drawSVG(const GraphAttributes &A, const string &filename, const SVGSettings &settings=svgSettings)
Definition GraphIO.h:1809
static bool readEdgeListSubgraph(Graph &G, List< edge > &delEdges, std::istream &is)
Reads graph G with subgraph defined by delEdges from stream is.
static bool readGraph6(Graph &G, std::istream &is, bool forceHeader=false)
Reads graph G in Graph6 format from input stream is.
static bool writeDMF(const GraphAttributes &attr, const node source, const node sink, std::ostream &os)
Writes a maximum flow problem instance to a DIMACS maximum flow file.
static bool readDOT(Graph &G, std::istream &is)
Reads graph G in DOT format from input stream is.
static bool readGML(Graph &G, std::istream &is)
Reads graph G in GML format from input stream is.
static const FileType * getFileType(const string &filename)
static bool readChallengeGraph(Graph &G, GridLayout &gl, std::istream &is)
Reads graph G with grid layout gl in GD-Challenge-format from input stream is.
static bool read(Graph &G, const string &filename, ReaderFunc reader=nullptr)
Reads graph G from a file with name filename and infers the used format from the file's extension.
static bool readGDF(GraphAttributes &A, Graph &G, std::istream &is)
Reads graph G with attributes A in GDF format from input stream is.
static bool writeGraph6(const Graph &G, std::ostream &os)
Writes graph G in Graph6 format to output stream os.
static bool readYGraph(Graph &G, std::istream &is)
Reads graph G in Y-graph format from input stream is.
static bool writeSparse6(const Graph &G, std::ostream &os)
Writes graph G in Sparse6 format to output stream os.
static bool read(GraphAttributes &GA, Graph &G, std::istream &is)
Reads graph G and its attributes GA from a stream is and try to guess the contained format by trying ...
static bool writeGDF(const Graph &G, std::ostream &os)
Writes graph G in GDF format to output stream os.
bool(*)(GraphAttributes &, Graph &, std::istream &) AttrReaderFunc
Type of simple graph attributes reader functions working on streams.
Definition GraphIO.h:73
static bool drawSVG(const ClusterGraphAttributes &A, std::ostream &os)
Definition GraphIO.h:1818
static bool write(const ClusterGraph &CG, const string &filename, ClusterWriterFunc writer=nullptr)
Writes graph G and a clustering CG of G to a file with name filename and infers the format to use fro...
static bool drawTikz(const GraphAttributes &A, std::ostream &os)
Draws a graph from its attributes in LaTeX+TikZ format.
static void setIndentWidth(int w)
Sets the indentation width to w.
Definition GraphIO.h:1874
static bool readSTP(Graph &G, std::istream &is)
Reads a graph in SteinLib format from std::istream is.
Definition GraphIO.h:1553
static bool readGraphML(ClusterGraph &C, Graph &G, std::istream &is)
Reads clustered graph (C, G) in GraphML format from input stream is.
static char indentChar()
Returns the currently used indentation character.
Definition GraphIO.h:1855
static bool writeGEXF(const ClusterGraphAttributes &A, std::ostream &os)
Writes graph with attributes A in GEXF format to output stream os.
static bool writeSTP(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, std::ostream &os, const string &comments="")
Writes an Steiner problem instance to an STP file.
Definition GraphIO.h:1616
static int indentWidth()
Returns the currently used indentation width.
Definition GraphIO.h:1858
bool(*)(ClusterGraph &, Graph &, std::istream &) ClusterReaderFunc
Type of cluster graph reader functions working on streams.
Definition GraphIO.h:79
Representation of a graph's grid layout.
Definition GridLayout.h:47
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Centralized global and local logging facility working on streams like std::cout.
Definition Logger.h:102
std::ostream & lout(Level level=Level::Default, bool indent=true) const
stream for logging-output (local)
Definition Logger.h:160
Class for the representation of nodes.
Definition Graph_d.h:241
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
WriterFunc writer_func
Definition GraphIO.h:95
FileType(std::vector< std::string > extensions, ReaderFunc readerFunc=nullptr, WriterFunc writerFunc=nullptr, AttrReaderFunc attrReaderFunc=nullptr, AttrWriterFunc attrWriterFunc=nullptr, ClusterReaderFunc clusterReaderFunc=nullptr, ClusterWriterFunc clusterWriterFunc=nullptr, ClusterAttrReaderFunc clusterAttrReaderFunc=nullptr, ClusterAttrWriterFunc clusterAttrWriterFunc=nullptr)
ClusterAttrReaderFunc cluster_attr_reader_func
Definition GraphIO.h:102
ReaderFunc auto_reader_func
Definition GraphIO.h:94
ClusterReaderFunc auto_cluster_reader_func
Definition GraphIO.h:100
std::vector< std::string > extensions
Definition GraphIO.h:92
FileType & replaceAutoReaders(ReaderFunc readerFunc=nullptr, AttrReaderFunc attrReaderFunc=nullptr, ClusterReaderFunc clusterReaderFunc=nullptr, ClusterAttrReaderFunc clusterAttrReaderFunc=nullptr)
ClusterWriterFunc cluster_writer_func
Definition GraphIO.h:101
ClusterAttrWriterFunc cluster_attr_writer_func
Definition GraphIO.h:104
AttrWriterFunc attr_writer_func
Definition GraphIO.h:98
ReaderFunc reader_func
Definition GraphIO.h:93
ClusterReaderFunc cluster_reader_func
Definition GraphIO.h:99
ClusterAttrReaderFunc auto_cluster_attr_reader_func
Definition GraphIO.h:103
AttrReaderFunc attr_reader_func
Definition GraphIO.h:96
AttrReaderFunc auto_attr_reader_func
Definition GraphIO.h:97