aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
graphicalModel.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
#include <chrono>
42
#include <format>
43
44
#include <
agrum/base/graphicalModels/graphicalModel.h
>
45
46
#ifdef GUM_NO_INLINE
47
# include <
agrum/base/graphicalModels/graphicalModel_inl.h
>
48
#endif
/* GUM_NO_INLINE */
49
50
namespace
gum
{
51
GraphicalModel::GraphicalModel
() { GUM_CONSTRUCTOR(
GraphicalModel
) }
52
53
GraphicalModel::GraphicalModel
(
const
GraphicalModel
& from) {
54
GUM_CONS_CPY(
GraphicalModel
)
55
_propertiesMap_
= from.
_propertiesMap_
;
56
}
57
58
GraphicalModel::GraphicalModel
(
GraphicalModel
&& from) noexcept :
59
_propertiesMap_
(std::move(from._propertiesMap_)) {
60
GUM_CONS_MOV(
GraphicalModel
);
61
}
62
63
GraphicalModel::~GraphicalModel
() { GUM_DESTRUCTOR(
GraphicalModel
); }
64
65
GraphicalModel
&
GraphicalModel::operator=
(
const
GraphicalModel
& source) {
66
if
(
this
!= &source) {
67
_propertiesMap_
= source.
_propertiesMap_
;
68
GUM_OP_CPY(
GraphicalModel
);
69
}
70
return
*
this
;
71
}
72
73
GraphicalModel
&
GraphicalModel::operator=
(
GraphicalModel
&& source)
noexcept
{
74
if
(
this
!= &source) {
75
_propertiesMap_
= std::move(source._propertiesMap_);
76
GUM_OP_MOV(
GraphicalModel
);
77
}
78
return
*
this
;
79
}
80
81
void
GraphicalModel::updateMetaData
() {
82
auto
const
time = std::chrono::time_point_cast< std::chrono::milliseconds >(
83
std::chrono::system_clock::now());
84
auto
const
currentdate = std::format(
"{:%Y-%m-%d %T}"
, time);
85
86
const
std::string currentSoftware =
"aGrUM "
GUM_VERSION;
87
if
(
auto
software =
_propertiesMap_
.
tryGet
(
"software"
)) {
88
*software = currentSoftware;
89
}
else
{
90
_propertiesMap_
.
insert
(
"software"
, currentSoftware);
91
}
92
93
if
(!
_propertiesMap_
.
tryGet
(
"creation"
)) {
_propertiesMap_
.
insert
(
"creation"
, currentdate); }
94
95
if
(
auto
lastModification =
_propertiesMap_
.
tryGet
(
"lastModification"
)) {
96
*lastModification = currentdate;
97
}
else
{
98
_propertiesMap_
.
insert
(
"lastModification"
, currentdate);
99
}
100
}
101
102
NodeSet
GraphicalModel::nodeset
(
const
std::vector< std::string >&
names
)
const
{
103
NodeSet
res;
104
for
(
const
auto
& name:
names
) {
105
res.
insert
(
idFromName
(name));
106
}
107
return
res;
108
}
109
110
std::string
GraphicalModel::spaceCplxToString
(
double
dSize,
int
dim,
Size
usedMem) {
111
std::string result;
112
if
(dSize > 6) result = std::format(
"domainSize: 10^{:.6g}"
, dSize);
113
else
result = std::format(
"domainSize: {}"
, (
long
long
)std::round(std::pow(10.0, dSize)));
114
115
result += std::format(
", dim: {}, mem: "
, dim);
116
117
if
(
const
Size
go = usedMem / (1024 * 1024 * 1024); go > 0) result += std::format(
"{}Go "
, go);
118
if
(
const
Size
mo = (usedMem / (1024 * 1024)) % 1024; mo > 0)
119
result += std::format(
"{}Mo "
, mo);
120
if
(
const
Size
ko = (usedMem / 1024) % 1024; ko > 0) result += std::format(
"{}Ko "
, ko);
121
result += std::format(
"{}o"
, usedMem % 1024);
122
return
result;
123
}
124
}
// namespace gum
gum::GraphicalModel::~GraphicalModel
virtual ~GraphicalModel()
Destructor.
Definition
graphicalModel.cpp:63
gum::GraphicalModel::operator=
GraphicalModel & operator=(const GraphicalModel &source)
Private copy operator.
Definition
graphicalModel.cpp:65
gum::GraphicalModel::_propertiesMap_
HashTable< std::string, std::string > _propertiesMap_
The properties of this Directed Graphical Model.
Definition
graphicalModel.h:262
gum::GraphicalModel::updateMetaData
void updateMetaData()
update the meta data of this Graphical Model (version, creation date, last modification date) This me...
Definition
graphicalModel.cpp:81
gum::GraphicalModel::names
std::vector< std::string > names(const std::vector< NodeId > &ids) const
transform a vector of NodeId in a vector of names
Definition
graphicalModel_inl.h:117
gum::GraphicalModel::GraphicalModel
GraphicalModel()
Default constructor.
Definition
graphicalModel.cpp:51
gum::GraphicalModel::idFromName
virtual NodeId idFromName(std::string_view name) const =0
Getter by name.
gum::GraphicalModel::nodeset
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
Definition
graphicalModel.cpp:102
gum::GraphicalModel::spaceCplxToString
static std::string spaceCplxToString(double dSize, int dim, Size usedMem)
send to the stream the space complexity with 3 parametrs
Definition
graphicalModel.cpp:110
gum::HashTable::insert
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Definition
hashTable_tpl.h:754
gum::HashTable::tryGet
optional_ref< Val > tryGet(const Key &key)
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
Definition
hashTable_tpl.h:605
gum::Set::insert
void insert(const Key &k)
Inserts a new element into the set.
Definition
set_tpl.h:510
graphicalModel.h
Class representing probabilistic DAG model.
graphicalModel_inl.h
Interface-like class encapsulating basic functionalities for both a IBayesNet and IMarkovRandomField.
gum::Size
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition
types.h:74
gum::NodeSet
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Definition
graphElements.h:392
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0