aGrUM  0.14.2
graphChange.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
29 #ifndef GUM_LEARNING_GRAPH_CHANGE_H
30 #define GUM_LEARNING_GRAPH_CHANGE_H
31 
32 #include <iostream>
33 #include <string>
34 
35 #include <agrum/agrum.h>
36 #include <agrum/core/hashFunc.h>
38 
39 namespace gum {
40 
41  namespace learning {
42 
50  };
51 
52  /* =========================================================================
53  */
54  /* === GRAPH CHANGE CLASS ===
55  */
56  /* =========================================================================
57  */
62  class GraphChange {
63  public:
64  // ##########################################################################
66  // ##########################################################################
68 
71 
73  GraphChange(const GraphChange& from) noexcept;
74 
76  GraphChange(GraphChange&& from) noexcept;
77 
79  ~GraphChange() noexcept;
80 
82 
83  // ##########################################################################
85  // ##########################################################################
87 
89  GraphChange& operator=(const GraphChange& from) noexcept;
90 
92  GraphChange& operator=(GraphChange&& from) noexcept;
93 
95  bool operator==(const GraphChange& from) const noexcept;
96 
98  bool operator!=(const GraphChange& from) const noexcept;
99 
101 
102  // ##########################################################################
104  // ##########################################################################
106 
108  GraphChangeType type() const noexcept;
109 
111  NodeId node1() const noexcept;
112 
114  NodeId node2() const noexcept;
115 
117  virtual std::string toString() const;
118 
120 
121  private:
124 
127 
130  };
131 
132  /* =========================================================================
133  */
134  /* === ARC ADDITION CLASS ===
135  */
136  /* =========================================================================
137  */
147  class ArcAddition : public GraphChange {
148  public:
149  // ##########################################################################
151  // ##########################################################################
153 
155  ArcAddition(NodeId node1, NodeId node2) noexcept;
156 
158  ArcAddition(const ArcAddition& from) noexcept;
159 
161  ArcAddition(ArcAddition&& from) noexcept;
162 
164  ~ArcAddition() noexcept;
165 
167 
168  // ##########################################################################
170  // ##########################################################################
172 
174  ArcAddition& operator=(const ArcAddition& from) noexcept;
175 
177  ArcAddition& operator=(ArcAddition&& from) noexcept;
178 
180  bool operator==(const ArcAddition& from) const noexcept;
181 
183  bool operator!=(const ArcAddition& from) const noexcept;
184 
186 
187  // ##########################################################################
189  // ##########################################################################
191 
193  virtual std::string toString() const final;
194 
196  };
197 
198  /* =========================================================================
199  */
200  /* === ARC DELETION CLASS ===
201  */
202  /* =========================================================================
203  */
213  class ArcDeletion : public GraphChange {
214  public:
215  // ##########################################################################
217  // ##########################################################################
219 
221  ArcDeletion(NodeId node1, NodeId node2) noexcept;
222 
224  ArcDeletion(const ArcDeletion& from) noexcept;
225 
227  ArcDeletion(ArcDeletion&& from) noexcept;
228 
230  ~ArcDeletion() noexcept;
231 
233 
234  // ##########################################################################
236  // ##########################################################################
238 
240  ArcDeletion& operator=(const ArcDeletion& from) noexcept;
241 
243  ArcDeletion& operator=(ArcDeletion&& from) noexcept;
244 
246  bool operator==(const ArcDeletion& from) const noexcept;
247 
249  bool operator!=(const ArcDeletion& from) const noexcept;
250 
252 
253  // ##########################################################################
255  // ##########################################################################
257 
259  virtual std::string toString() const final;
260 
262  };
263 
264  /* =========================================================================
265  */
266  /* === ARC REVERSAL CLASS ===
267  */
268  /* =========================================================================
269  */
279  class ArcReversal : public GraphChange {
280  public:
281  // ##########################################################################
283  // ##########################################################################
285 
287  ArcReversal(NodeId node1, NodeId node2) noexcept;
288 
290  ArcReversal(const ArcReversal& from) noexcept;
291 
293  ArcReversal(ArcReversal&& from) noexcept;
294 
296  ~ArcReversal() noexcept;
297 
299 
300  // ##########################################################################
302  // ##########################################################################
304 
306  ArcReversal& operator=(const ArcReversal& from) noexcept;
307 
309  ArcReversal& operator=(ArcReversal&& from) noexcept;
310 
312  bool operator==(const ArcReversal& from) const noexcept;
313 
315  bool operator!=(const ArcReversal& from) const noexcept;
316 
318 
319  // ##########################################################################
321  // ##########################################################################
323 
325  virtual std::string toString() const final;
326 
328  };
329 
330  /* =========================================================================
331  */
332  /* === EDGE ADDITION CLASS ===
333  */
334  /* =========================================================================
335  */
345  class EdgeAddition : public GraphChange {
346  public:
347  // ##########################################################################
349  // ##########################################################################
351 
353  EdgeAddition(NodeId node1, NodeId node2) noexcept;
354 
356  EdgeAddition(const EdgeAddition& from) noexcept;
357 
359  EdgeAddition(EdgeAddition&& from) noexcept;
360 
362  ~EdgeAddition() noexcept;
363 
365 
366  // ##########################################################################
368  // ##########################################################################
370 
372  EdgeAddition& operator=(const EdgeAddition& from) noexcept;
373 
375  EdgeAddition& operator=(EdgeAddition&& from) noexcept;
376 
378  bool operator==(const EdgeAddition& from) const noexcept;
379 
381  bool operator!=(const EdgeAddition& from) const noexcept;
382 
384 
385  // ##########################################################################
387  // ##########################################################################
389 
391  virtual std::string toString() const final;
392 
394  };
395 
396  /* =========================================================================
397  */
398  /* === EDGE DELETION CLASS ===
399  */
400  /* =========================================================================
401  */
411  class EdgeDeletion : public GraphChange {
412  public:
413  // ##########################################################################
415  // ##########################################################################
417 
419  EdgeDeletion(NodeId node1, NodeId node2) noexcept;
420 
422  EdgeDeletion(const EdgeDeletion& from) noexcept;
423 
425  EdgeDeletion(EdgeDeletion&& from) noexcept;
426 
428  ~EdgeDeletion() noexcept;
429 
431 
432  // ##########################################################################
434  // ##########################################################################
436 
438  EdgeDeletion& operator=(const EdgeDeletion& from) noexcept;
439 
441  EdgeDeletion& operator=(EdgeDeletion&& from) noexcept;
442 
444  bool operator==(const EdgeDeletion& from) const noexcept;
445 
447  bool operator!=(const EdgeDeletion& from) const noexcept;
448 
450 
451  // ##########################################################################
453  // ##########################################################################
455 
457  virtual std::string toString() const final;
458 
460  };
461 
463  std::ostream& operator<<(std::ostream& stream, const GraphChange& change);
464 
466  std::ostream& operator<<(std::ostream& stream, const ArcAddition& change);
467 
469  std::ostream& operator<<(std::ostream& stream, const ArcDeletion& change);
470 
472  std::ostream& operator<<(std::ostream& stream, const ArcReversal& change);
473 
475  std::ostream& operator<<(std::ostream& stream, const EdgeAddition& change);
476 
478  std::ostream& operator<<(std::ostream& stream, const EdgeDeletion& change);
479 
480  } /* namespace learning */
481 
483  template <>
484  class HashFunc< learning::GraphChange >
485  : public HashFuncBase< learning::GraphChange > {
486  public:
492  static Size castToSize(const learning::GraphChange& key);
493 
495  virtual Size operator()(const learning::GraphChange& key) const override final;
496  };
497 
499  template <>
500  class HashFunc< learning::ArcAddition >
501  : public HashFuncBase< learning::ArcAddition > {
502  public:
508  static Size castToSize(const learning::ArcAddition& key);
509 
511  virtual Size operator()(const learning::ArcAddition& key) const override final;
512  };
513 
515  template <>
516  class HashFunc< learning::ArcDeletion >
517  : public HashFuncBase< learning::ArcDeletion > {
518  public:
524  static Size castToSize(const learning::ArcDeletion& key);
525 
527  virtual Size operator()(const learning::ArcDeletion& key) const override final;
528  };
529 
531  template <>
532  class HashFunc< learning::ArcReversal >
533  : public HashFuncBase< learning::ArcReversal > {
534  public:
540  static Size castToSize(const learning::ArcReversal& key);
541 
543  virtual Size operator()(const learning::ArcReversal& key) const override final;
544  };
545 
547  template <>
548  class HashFunc< learning::EdgeAddition >
549  : public HashFuncBase< learning::EdgeAddition > {
555  static Size castToSize(const learning::EdgeAddition& key);
556 
558  virtual Size
559  operator()(const learning::EdgeAddition& key) const override final;
560  };
561 
563  template <>
564  class HashFunc< learning::EdgeDeletion >
565  : public HashFuncBase< learning::EdgeDeletion > {
566  public:
572  static Size castToSize(const learning::EdgeDeletion& key);
573 
575  virtual Size
576  operator()(const learning::EdgeDeletion& key) const override final;
577  };
578 
579 } /* namespace gum */
580 
581 #ifndef GUM_NO_INLINE
583 #endif // GUM_NOINLINE
584 
585 #endif /* GUM_LEARNING_GRAPH_CHANGE_H */
Base node set class for graphs.
The class for notifying learning algorithms of new arc additionsThis class is convenient to know at c...
Definition: graphChange.h:147
The class for notifying learning algorithms of arc removalsThis class is convenient to know at compil...
Definition: graphChange.h:213
Classes providing basic hash functions for hash tables.
std::ostream & operator<<(std::ostream &stream, const IdSet< ALLOC > &idset)
the display operator
Class template representing hashing function of LpCol.
Definition: hashFunc.h:469
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
NodeId __node2
the second node in the edge or arc to be modified
Definition: graphChange.h:129
~GraphChange() noexcept
destructor
A class to account for changes in a graph.
The class for notifying learning algorithms of edge removalsThis class is convenient to know at compi...
Definition: graphChange.h:411
GraphChange & operator=(const GraphChange &from) noexcept
copy constructor
bool operator==(const GraphChange &from) const noexcept
returns whether two graph changes are identical or not
The class for notifying learning algorithms of new edge additionsThis class is convenient to know at ...
Definition: graphChange.h:345
GraphChangeType type() const noexcept
returns the type of the operation
GraphChangeType __type
the type of modification
Definition: graphChange.h:123
NodeId node2() const noexcept
returns the second node involved in the modification
virtual std::string toString() const
put the content of the graph change into a string
Definition: graphChange.cpp:40
NodeId __node1
the first node in the edge or arc to be modified
Definition: graphChange.h:126
bool operator!=(const GraphChange &from) const noexcept
returns whether two graph changes are different or not
The class for notifying learning algorithms of arc reversalsThis class is convenient to know at compi...
Definition: graphChange.h:279
GraphChangeType
the type of modification that can be applied to the graph
Definition: graphChange.h:44
All hash functions should inherit from this class.
Definition: hashFunc.h:147
GraphChange(GraphChangeType type, NodeId node1, NodeId node2) noexcept
default constructor
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size NodeId
Type for node ids.
Definition: graphElements.h:97
NodeId node1() const noexcept
returns the first node involved in the modification