aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
mixedGraph.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
50
51#ifdef GUM_NO_INLINE
53#endif // GU%_NO_INLINE
54
55namespace gum {
56
58 bool nodes_resize_policy,
59 Size arcs_size,
60 bool arcs_resize_policy,
61 Size edges_size,
62 bool edges_resize_policy) :
63 // Note that we need to initialize the NodeGraphPart by ourselves
64 // because
65 // it is a virtual inherited class (see C++ FAQ Lite #25.12 for details)
66 NodeGraphPart(nodes_size, nodes_resize_policy), UndiGraph(edges_size, edges_resize_policy),
67 DiGraph(arcs_size, arcs_resize_policy) { // for debugging purposes
68 GUM_CONSTRUCTOR(MixedGraph);
69 }
70
72 GUM_CONSTRUCTOR(MixedGraph);
73 }
74
76 GUM_CONSTRUCTOR(MixedGraph);
77 }
78
80 NodeGraphPart(g), UndiGraph(g), DiGraph(g) { // for debugging purposes
81 GUM_CONS_CPY(MixedGraph);
82 }
83
85 NodeGraphPart(std::move(g)), UndiGraph(std::move(g)), DiGraph(std::move(g)) {
86 GUM_CONS_MOV(MixedGraph);
87 }
88
89 MixedGraph::~MixedGraph() { // for debugging purposes
90 GUM_DESTRUCTOR(MixedGraph);
91 }
92
93 std::string MixedGraph::toString() const {
94 std::string s = NodeGraphPart::toString();
95 s += " , ";
97 s += " , ";
99 return s;
100 }
101
102 std::string MixedGraph::toDot() const { return toDot(dot::DotOptions()); }
103
104 std::string MixedGraph::toDot(const dot::DotOptions& options) const {
105 const auto style = dot::DotStyle::read();
106 dot::DotWriter writer(true);
107 dot::writePreamble(writer, style, options);
108 writeDotNodes(writer, style, options);
109
110 for (const auto& edge: edges()) {
111 auto attributes = dot::arcAttributes(options.edge(edge.first(), edge.second()));
112 attributes.insert(attributes.begin(), {"dir", "none"});
113 writer.edge(edge.first(), edge.second(), attributes);
114 }
115
116 for (const auto& arc: arcs())
117 writer.edge(arc.tail(), arc.head(), dot::arcAttributes(options.arc(arc.tail(), arc.head())));
118
119 return writer.str();
120 }
121
123 std::ostream& operator<<(std::ostream& stream, const MixedGraph& g) {
124 stream << g.toString();
125 return stream;
126 }
127
128
129} /* namespace gum */
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
std::string toString() const
to friendly display the content of the ArcGraphPart
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition diGraph.cpp:71
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
Base class for mixed graphs.
Definition mixedGraph.h:150
std::string toString() const override
to friendly display the content of the MixedGraph
std::string toDot() const override
to friendly display mixed graph in DOT format
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
~MixedGraph() override
destructor
Class for node sets in graph.
void writeDotNodes(dot::DotWriter &writer, const dot::DotStyle &style, const dot::DotOptions &options) const
writes the nodes in the dot language, see writeDotNode()
virtual std::string toString() const
a function to display the set of nodes
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition undiGraph.cpp:74
The options given to a toDot(const DotOptions&).
Definition dotOptions.h:110
const DotArcOptions * arc(Size tail, Size head) const
the options of the arc from tail to head, or nullptr if none was given for it
const DotArcOptions * edge(Size a, Size b) const
the options of the undirected edge between a and b, given for (a, b) or for (b, a),...
Writes a graph in the dot language, statement after statement, in the order of the calls.
Definition dotWriter.h:100
void edge(std::string_view from, std::string_view to, const DotAttributes &attributes={})
an edge from from to to (-> in a directed graph, -- in an undirected one).
std::string str() const
The graph written so far, closed. It can be called at any moment, and the writer can be used after.
The statements common to the graphs drawn with graphviz : preamble, attributes of nodes and arcs.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Base classes for mixed directed/undirected graphs.
Inline implementation of Base classes for mixed graphs.
void writePreamble(DotWriter &writer, const DotStyle &style, const DotOptions &options, std::string_view defaultLabel)
Writes the beginning of a graph, as pyAgrum displays it.
DotAttributes arcAttributes(const DotArcOptions *options)
The attributes of an arc or an edge given by the options : color, penwidth, label,...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
STL namespace.
static DotStyle read()
the style of the graphs of the section notebook
Definition dotStyle.cpp:89