85 double margin()
const {
return m_margin; }
94 const string &
fontColor()
const {
return m_fontColor; }
97 const string &
fontFamily()
const {
return m_fontFamily; }
100 const string &
width()
const {
return m_width; }
103 const string &
height()
const {
return m_height; }
155 ifstream is(filename);
156 return is.good() && reader(G, is);
167 ofstream os(filename);
168 return os.good() && writer(G, os);
201 ifstream is(filename);
202 return is.good() && reader(GA, G, is);
213 ofstream os(filename);
214 return os.good() && writer(GA, os);
819 #pragma mark PMDissGraph 997 #pragma mark MatrixMarket 1175 #pragma mark ChallengeGraph 1236 #pragma mark GraphML 2251 bool res =
readSTP(wG, terminals, isTerminal, is);
2267 template<
typename T>
2273 const
string &filename)
2275 ifstream is(filename);
2276 return readSTP(wG, terminals, isTerminal, is);
2290 template<
typename T>
2299 isTerminal.
init(wG);
2300 int expectedNumberOfTerminals = -1;
2301 int expectedNumberOfEdges = -1;
2305 enum class Section {
2323 std::vector<string> firstline{
"33D32945",
"STP",
"File,",
"STP",
"Format",
"Version"};
2324 for (
int i = 0; i < 6; ++i) {
2327 logger.
lout() <<
"Could not parse first line." << endl;
2332 if (!is.good() || version != 1.0) {
2333 logger.
lout() <<
"Encountered unknwon STP format version." << endl;
2337 while (std::getline(is, buffer)) {
2340 if (buffer.empty() || buffer[0] ==
'#') {
2344 std::istringstream iss(buffer);
2356 section = Section::Comment;
2362 section = Section::Ignore;
2369 if (!terminals.
empty()) {
2371 section = Section::Ignore;
2373 section = Section::Terminals;
2377 section = Section::Ignore;
2390 if(expectedNumberOfTerminals != -1 && expectedNumberOfTerminals != terminals.
size()) {
2392 <<
"Invalid number of terminals. Was " << terminals.
size()
2393 <<
" but expected " << expectedNumberOfTerminals <<
"." << endl;
2396 if(expectedNumberOfEdges != -1 && expectedNumberOfEdges != wG.
numberOfEdges()) {
2399 <<
" but expected " << expectedNumberOfEdges <<
"." << endl;
2405 case Section::Ignore:
2406 case Section::Comment:
2415 logger.
lout() <<
"Invalid number of nodes specified: " << n << endl;
2420 for (
int i = 1; i <= n; ++i) {
2421 indexToNode[i] = wG.
newNode();
2422 isTerminal[indexToNode[i]] =
false;
2425 iss >> expectedNumberOfEdges;
2428 int source = -1, target = -1;
2430 iss >> source >> target >> weight;
2434 logger.
lout() <<
"Invalid edge given: " << source <<
"->" << target <<
"(weight: " << weight <<
")" << endl;
2437 wG.
newEdge(indexToNode[source], indexToNode[target], weight);
2443 case Section::Terminals:
2445 iss >> expectedNumberOfTerminals;
2450 logger.
lout() <<
"Invalid terminal encountered: " << v << endl;
2453 terminals.
pushBack(indexToNode[v]);
2454 isTerminal[indexToNode[v]] =
true;
2461 logger.
lout() <<
"Unexpected end of file." << endl;
2476 template<
typename T>
2481 const
string &filename,
2482 const
string &comments = "")
2484 ofstream os(filename);
2485 return writeSTP(wG, terminals, os, comments);
2499 template<
typename T>
2504 const string &comments =
"")
2506 if(!os.good())
return false;
2508 os <<
"33d32945 STP File, STP Format Version 1.00" << endl;
2510 os << endl <<
"Section Comment" << endl;
2511 if (comments.length() != 0) {
2512 os << comments << endl;
2514 os <<
"End" << endl;
2516 os << endl <<
"Section Graph" << endl;
2523 nodeToIndex[v] = i++;
2526 os <<
"E " << nodeToIndex[e->
source()]
2527 <<
" " << nodeToIndex[e->
target()]
2528 <<
" " << std::fixed << wG.
weight(e) << endl;
2532 <<
"Section Terminals" << endl
2533 <<
"Terminals " << terminals.
size() << endl;
2534 for (
node v : terminals) {
2535 os <<
"T " << nodeToIndex[v] << endl;
2566 template<
typename T>
2573 const
string &filename) {
2574 ifstream is(filename);
2575 return readDMF(graph, weights, source, sink, is);
2588 template<
typename T>
2596 int expectedNumberOfEdges = -1;
2599 weights.
init(graph, 0);
2605 while (std::getline(is, buffer)) {
2607 std::istringstream iss(buffer);
2611 if (!buffer.empty() && buffer[0] !=
'c') {
2612 if(buffer[0] ==
'p') {
2614 if(!graph.
empty()) {
2615 logger.
lout() <<
"Ambigious problem definition encountered." << endl;
2619 string problemType =
"";
2621 if(problemType.compare(
"max")) {
2622 logger.
lout() <<
"Invalid problem type encountered: " << problemType << endl;
2626 int numberOfNodes = -1;
2627 iss >> numberOfNodes >> expectedNumberOfEdges;
2629 if(numberOfNodes < 2) {
2630 logger.
lout() <<
"The given number of nodes is invalid (at least two)." << endl;
2634 if(expectedNumberOfEdges < 0) {
2635 logger.
lout() <<
"The given number of edges is invalid." << endl;
2639 for(
int i = 0; i < numberOfNodes; i++) {
2643 }
else if(buffer[0] ==
'n') {
2646 string nodeTypeString =
"";
2647 iss >> nodeIndex >> nodeTypeString;
2649 if (nodeIndex < 1 || nodeIndex > nodes.
size()) {
2650 logger.
lout() <<
"Invalid node index supplied: " << nodeIndex << endl;
2654 node w = *nodes.
get(nodeIndex - 1);
2655 if (!nodeTypeString.compare(
"t")) {
2656 if(sink !=
nullptr) {
2657 logger.
lout() <<
"Duplicate sink encountered: " << nodeTypeString << endl;
2661 }
else if (!nodeTypeString.compare(
"s")) {
2662 if(source !=
nullptr) {
2663 logger.
lout() <<
"Duplicate source encountered: " << nodeTypeString << endl;
2668 logger.
lout() <<
"Malformed node type encountered: " << nodeTypeString << endl;
2672 }
else if (buffer[0] ==
'a') {
2674 int sourceIndex = -1;
2675 int targetIndex = -1;
2678 iss >> sourceIndex >> targetIndex >> cap;
2680 if (sourceIndex < 1 || sourceIndex > nodes.
size()) {
2681 logger.
lout() <<
"Invalid node index supplied: " << sourceIndex << endl;
2684 node newSource = *nodes.
get(sourceIndex - 1);
2686 if (targetIndex < 1 || targetIndex > nodes.
size()) {
2687 logger.
lout() <<
"Invalid node index supplied: " << targetIndex << endl;
2690 node newTarget = *nodes.
get(targetIndex - 1);
2693 logger.
lout() <<
"Negative capacity supplied: " << targetIndex << endl;
2700 logger.
lout() <<
"Encountered invalid line: " << buffer << endl;
2706 if (graph.
empty()) {
2707 logger.
lout() <<
"Missing problem definition." << endl;
2711 if (source ==
nullptr) {
2712 logger.
lout() <<
"Missing source node." << endl;
2716 if(sink ==
nullptr) {
2717 logger.
lout() <<
"Missing sink node." << endl;
2721 if(sink == source) {
2722 logger.
lout() <<
"Source must be different from sink." << endl;
2727 logger.
lout() <<
"Invalid number of edges: expected " << expectedNumberOfEdges <<
" but was " << graph.
numberOfEdges() << endl;
2745 template<
typename T>
2752 const
string &filename)
2754 ofstream os(filename);
2755 return writeDMF(graph, weights, source, sink, os);
2769 template<
typename T>
2777 if(!os.good())
return false;
2783 nodeIndices[v] = ++counter;
2787 os <<
"n " << nodeIndices[source] <<
" s" << endl;
2788 os <<
"n " << nodeIndices[sink] <<
" t" << endl;
2791 os <<
"a " << nodeIndices[e->
source()] <<
" " << nodeIndices[e->
target()] <<
" " << weights(e) << endl;
2915 if (value < 0 || value > 255) {
2919 setFunction(static_cast<uint8_t>(value));
static bool readSTP(EdgeWeightedGraph< T > &wG, List< node > &terminals, NodeArray< bool > &isTerminal, istream &is)
Reads a SteinLib instance from an inputstream is and converts it into a weighted graph wG and a set o...
node target() const
Returns the target node of the edge.
Representation of a graph's grid layout.
bool equalIgnoreCase(const string &str1, const string &str2)
Compares the two strings str1 and str2, ignoring the case of characters.
void clear()
Removes all elements from the list.
static bool readGDF(Graph &G, const string &filename)
Reads graph G in GDF format from file filename.
static bool readYGraph(Graph &G, const string &filename)
Reads graph G in Y-graph format from file filename.
static ostream & indent(ostream &os, int depth)
Prints indentation for indentation depth to output stream os and returns os.
static bool write(const GraphAttributes &GA, const string &filename, AttrWriterFunc writer)
Writes arbitrary format to a file specified by name.
static bool writeDMF(const Graph &graph, const EdgeArray< T > &weights, const node source, const node sink, ostream &os)
Writes a maximum flow problem instance to a DIMACS maximum flow file.
void curviness(double value)
Sets the curviness of all edges (value ranges from 0 to 1).
virtual void clear()
Removes all nodes and all edges from the graph.
bool m_bezierInterpolation
void init()
Reinitializes the array. Associates the array with no graph.
static void setIndentWidth(int w)
Sets the indentation width to w.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
static bool writeGML(const Graph &G, const string &filename)
Writes graph G in GML format to file filename.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
void init()
Reinitializes the array. Associates the array with no graph.
static bool writeDL(const Graph &G, const string &filename)
Writes graph G in DL format to file filename.
static bool readGEXF(Graph &G, const string &filename)
Reads graph G in GEXF format from file filename.
double curviness() const
Returns the curviness of the edges (value ranges from 0 to 1).
static bool readRudy(GraphAttributes &A, Graph &G, const string &filename)
Reads graph G with edge weights stored in A in Rudy format from file filename.
Utility class providing graph I/O in various exchange formats.
bool(*)(const Graph &, ostream &) WriterFunc
Type of simple graph writer functions working on streams.
static bool drawSVG(const GraphAttributes &A, ostream &os)
static bool writeChallengeGraph(const Graph &G, const GridLayout &gl, const string &filename)
Writes graph G with grid layout gl in GD-Challenge-format to file filename.
Dynamic arrays indexed with edges.
static bool writeGraphML(const Graph &G, const string &filename)
Writes graph G in GraphML format to file filename.
static bool readPLA(Graph &G, List< node > &hypernodes, List< edge > *shell, const string &filename)
Reads a hypergraph (as point-based expansion) in PLA format from file filename.
static bool readGraphML(Graph &G, const string &filename)
Reads graph G in GraphML format from file filename.
static bool writeEdgeListSubgraph(const Graph &G, const List< edge > &delEdges, const string &filename)
Writes graph G with subgraph defined by delEdges to file filename.
static bool readTLP(Graph &G, const string &filename)
Reads graph G in TLP format from file filename.
T weight(const edge e) const
static bool readPMDissGraph(Graph &G, const string &filename)
Reads graph G in a simple format as used in Petra Mutzel's thesis from file filename.
static bool readDL(Graph &G, const string &filename)
Reads graph G in DL format from file filename.
std::ostream & lout(Level l=Level::Default) const
stream for logging-output (local)
bool(*)(Graph &, istream &) ReaderFunc
Type of simple graph reader functions working on streams.
bool(*)(GraphAttributes &, Graph &, istream &) AttrReaderFunc
Type of simple graph attributes reader functions working on streams.
static bool readGML(Graph &G, const string &filename)
Reads graph G in GML format from file filename.
static bool readEdgeListSubgraph(Graph &G, List< edge > &delEdges, const string &filename)
Reads graph G with subgraph defined by delEdges from file filename.
edge newEdge(node v, node w, T weight)
Representation of clustered graphs.
static bool readChallengeGraph(Graph &G, GridLayout &gl, const string &filename)
Reads graph G with grid layout gl in GD-Challenge-format from file filename.
static bool readBENCH(Graph &G, List< node > &hypernodes, List< edge > *shell, const string &filename)
Reads a hypergraph (as point-based expansion) in BENCH format from file filename. ...
static bool writeGEXF(const Graph &G, const string &filename)
Writes graph G in GEXF format to file filename.
static bool read(GraphAttributes &GA, Graph &G, const string &filename, AttrReaderFunc reader)
Reads arbitrary format from a file specified by name.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
void removeTrailingWhitespace(string &str)
Removes trailing space, horizontal and vertical tab, feed, newline, and carriage return from str...
static void setIndentChar(char c)
Sets the indentation character to c.
static SVGSettings svgSettings
static bool writeGraph6(const Graph &G, const string &filename)
Writes graph G in Graph6 format to file filename.
static bool writeGDF(const Graph &G, const string &filename)
Writes graph G in GDF format to file filename.
static char s_indentChar
Character used for indentation.
static bool writeTLP(const Graph &G, const string &filename)
Writes graph G in TLP format to file filename.
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...
Declaration of class GridLayout.
Stores additional attributes of a graph (like layout information).
static bool readDMF(Graph &graph, EdgeArray< T > &weights, node &source, node &sink, const string &filename)
Reads a maximum flow instance in DIMACS format.
Doubly linked lists (maintaining the length of the list).
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
Definition of exception classes.
const string & width() const
Returns the default width.
int fontSize() const
Returns the default font size (font height in pixels).
Class for the representation of edges.
static bool readDOT(Graph &G, const string &filename)
Reads graph G in DOT format from file filename.
Stores additional attributes of a clustered graph (like layout information).
Declaration of class EdgeWeightedGraph.
static bool writeSTP(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, ostream &os, const string &comments="")
Writes an Steiner problem instance to an STP file.
static bool readSTP(Graph &G, istream &is)
Reads a graph in SteinLib format from istream is.
const string & height() const
Returns the default height.
static bool writePMDissGraph(const Graph &G, const string &filename)
Writes graph G in a simple format as used in Petra Mutzel's thesis to file filename.
const_iterator get(int pos) const
Returns a const iterator pointing to the element at position pos.
double margin() const
Returns the size of the margin around the drawing.
Class for the representation of nodes.
static bool writeChaco(const Graph &G, const string &filename)
Writes graph G in Chaco format to file filename.
void height(const string &height)
Sets the height.
void fontSize(int fs)
Sets the default font size (font height in pixels) to fs.
void width(const string &width)
Sets the width.
static bool drawSVG(const ClusterGraphAttributes &A, ostream &os)
static bool readDMF(Graph &graph, EdgeArray< T > &weights, node &source, node &sink, istream &is)
Reads a maximum flow instance in DIMACS format.
Declares ClusterGraphAttributes, an extension of class GraphAttributes, to store clustergraph layout ...
void margin(double m)
Sets the size of the margin around the drawing to m.
static int s_indentWidth
Number of indent characters used for indentation.
static bool readMatrixMarket(Graph &G, istream &inStream)
Reads graph G in Matrix Market exchange format from stream inStream.
static bool readChaco(Graph &G, const string &filename)
Reads graph G in Chaco format from file filename.
Condensed settings for drawing SVGs.
Centralized global and local logging facility working on streams like cout.
bool bezierInterpolation() const
Returns whether Bézier-interpolation for curved edges is enabled.
static bool write(const Graph &G, const string &filename, WriterFunc writer)
Writes arbitrary format to a file specified by name.
int size() const
Returns the number of elements in the list.
static bool writeOGML(const Graph &G, const string &filename)
Writes graph G in OGML format to file filename.
static int indentWidth()
Returns the currently used indentation width.
const string & fontFamily() const
Returns the default font family.
void allNodes(NODELIST &nodeList) const
Returns a list with all nodes of the graph.
static bool readGraph6(Graph &G, const string &filename)
Reads graph G in Graph6 format from file filename.
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
void fontFamily(const string &fm)
Sets the default font family to fm.
node source() const
Returns the source node of the edge.
void fontColor(const string &fc)
Sets the default font color to fc.
void bezierInterpolation(bool enable)
Enables or disables Bézier-interpolation.
The namespace for all OGDF objects.
static bool writeRudy(const GraphAttributes &A, const string &filename)
Writes graph with edge weights stored in A in Rudy format to file filename.
const string & fontColor() const
Returns the default font color.
static bool writeDOT(const Graph &G, const string &filename)
Writes graph G in DOT format to file filename.
int numberOfNodes() const
Returns the number of nodes in the graph.
static bool readLEDA(Graph &G, const string &filename)
Reads graph G in LEDA graph format from file filename.
node newNode()
Creates a new node and returns it.
static bool writeRome(const Graph &G, const string &filename)
Writes graph G in Rome-Lib format to file filename.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
static bool writeLEDA(const Graph &G, const string &filename)
Writes graph G in LEDA graph format to file filename.
static bool writeSTP(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, const string &filename, const string &comments="")
Writes an Steiner problem instance to an STP file.
static bool readOGML(Graph &G, const string &filename)
Reads graph G in OGML format from file filename.
static bool drawSVG(const GraphAttributes &A, const string &filename, const SVGSettings &settings=svgSettings)
static char indentChar()
Returns the currently used indentation character.
bool empty() const
Returns true iff the list is empty.
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
static bool read(Graph &G, const string &filename, ReaderFunc reader=GraphIO::read)
Reads arbitrary format from a file specified by name.
static bool readRome(Graph &G, const string &filename)
Reads graph G in Rome-Lib format from file filename.
static bool writeDMF(const Graph &graph, const EdgeArray< T > &weights, const node source, const node sink, const string &filename)
Writes a maximum flow problem instance to a DIMACS maximum flow file.
bool(*)(const GraphAttributes &, ostream &) AttrWriterFunc
Type of simple graph attributes writer functions working on streams.