52# include <type_traits>
55# include <libxml++/libxml++.h>
56# include <libxml++/parsers/textreader.h>
57# include <libxml++/nodes/node.h>
58# include <libxml++/document.h>
119 template <AlephGraph
GT,
166 reader.move_to_first_attribute();
176 while (
reader.move_to_next_attribute());
186 reader.move_to_first_attribute();
187 size_t src = std::atol(
reader.get_value().c_str());
190 size_t tgt = std::atol(
reader.get_value().c_str());
209 while (
reader.move_to_next_attribute());
221 xmlpp::TextReader
reader(file_name);
235 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne(), ++i)
237 typename GT::Node * p = it.get_curr();
247 for (
size_t i = 0; i < attrs.
size(); ++i)
250 node->set_attribute(
attr.name,
attr.value);
254 xmlpp::Element *
arcs =
element->add_child(
"arcs");
256 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.next_ne(), ++i)
258 typename GT::Arc * a = it.get_curr();
263 arc->set_attribute(
"src", std::to_string(src));
266 arc->set_attribute(
"tgt", std::to_string(tgt));
272 for (
size_t i = 0; i < attrs.
size(); ++i)
275 arc->set_attribute(
attr.name,
attr.value);
280 void write(
GT & g,
const std::string & file_name)
284 doc.write_to_file_formatted(file_name,
"UTF-8");
345 static std::optional<F>
copy_own(
const std::optional<F> & src)
347 if constexpr (std::is_copy_constructible_v<F>)
352 <<
"Xml_Graph: cannot copy a reader/writer that owns a "
353 "non-copy-constructible functor; share it instead "
354 "(construct from an lvalue)";
417 return read(file_name);
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
T & append()
Allocate a new entry to the end of array.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Data & find(const Key &key)
Find the value associated with key.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Class that writes and reads a graph (in a very elementary way) as XML.
void write_graph(GT &g, xmlpp::Document &doc)
const std::string & get_arc_name() const
const std::string & get_node_name() const
std::optional< Arc_Reader > own_arc_reader
Xml_Graph(Node_Reader &&_node_reader=Node_Reader(), Arc_Reader &&_arc_reader=Arc_Reader(), Node_Writer &&_node_writer=Node_Writer(), Arc_Writer &&_arc_writer=Arc_Writer())
Build a reader/writer that owns its functors.
Xml_Graph(const Xml_Graph &other)
Copy constructor.
Xml_Graph(Node_Reader &_node_reader, Arc_Reader &_arc_reader, Node_Writer &_node_writer, Arc_Writer &_arc_writer)
Build a reader/writer that shares the caller's functors.
std::optional< Arc_Writer > own_arc_writer
static std::optional< F > copy_own(const std::optional< F > &src)
Copy an other reader/writer whose functor may not be copy-constructible.
GT read_graph(xmlpp::TextReader &reader)
const std::string & get_graph_name() const
void set_graph_name(const std::string &_graph_name)
void set_node_name(const std::string &_node_name)
Node_Writer & node_writer
void write(GT &g, const std::string &file_name)
std::optional< Node_Writer > own_node_writer
GT read(const std::string &file_name)
GT operator()(const std::string &file_name)
void set_arc_name(const std::string &_arc_name)
std::optional< Node_Reader > own_node_reader
Node_Reader & node_reader
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
DynArray< Graph::Node * > nodes
DynArray< Graph::Arc * > arcs
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
void operator()(GT &, typename GT::Arc *, DynArray< Attr > &)
void operator()(GT &, typename GT::Arc *, DynArray< Attr > &)
void operator()(GT &, typename GT::Node *, DynArray< Attr > &)
void operator()(GT &, typename GT::Node *, DynArray< Attr > &)
Lazy and scalable dynamic array implementation.
Dynamic key-value map based on balanced binary search trees.
Generic graph and digraph implementations.