aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
schedule_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 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-2025 *
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#pragma once
41
42
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
49
50# include <agrum/agrum.h>
51
52namespace gum {
53
55 template < typename TABLE >
57 Schedule::insertTable(const TABLE& table, const bool copy, const Idx id) {
58 // if the schedule already contains the id, throw an error
59 if (_multidim2id_.existsSecond(id)) {
60 GUM_ERROR(DuplicateScheduleMultiDim,
61 "A table with Id " << id << " already exists in the schedule");
62 }
63
64 // allocate the new table within the schedule
65 ScheduleMultiDim< TABLE >* new_multidim = new ScheduleMultiDim< TABLE >(table, copy, id);
66
67 // keep track that this is a source multidim
68 _multidim2nodes_.insert(new_multidim, NodeSet());
69 _multidim_location_.insert(new_multidim, std::pair< ScheduleOperator*, Idx >(nullptr, Idx(0)));
70 _multidim2id_.insert(new_multidim, new_multidim->id());
71
72 // indicate that the schedule has been modified
74
75 return new_multidim;
76 }
77
79 template < typename TABLE1, typename TABLE2, typename TABLE_RES >
80 const ScheduleOperator&
82 const ScheduleMultiDim< TABLE2 >& table2,
83 TABLE_RES (*combine)(const TABLE1&, const TABLE2&),
84 const bool is_result_persistent) {
85 // note that the insertOperation will check that table1 and table2
86 // already belong to the schedule
87 return insertOperation(
88 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >(table1, table2, combine, false),
89 is_result_persistent);
90 }
91
93 template < typename TABLE >
95 const gum::VariableSet& del_vars,
96 TABLE (*project)(const TABLE&,
97 const gum::VariableSet&),
98 const bool is_result_persistent) {
99 // note that the insertOperation will check that table already belongs
100 // to the schedule
101 return insertOperation(ScheduleProjection< TABLE >(table, del_vars, project, false),
102 is_result_persistent);
103 }
104
106 template < typename TABLE >
108 // note that the insertOperation will check that table already belongs
109 // to the schedule
110 return insertOperation(ScheduleDeletion< TABLE >(table), false);
111 }
112
114 template < typename TABLE, template < typename... > class CONTAINER >
116 CONTAINER< TABLE >& container) {
117 // note that the insertOperation will check that table already belongs
118 // to the schedule
119 return insertOperation(ScheduleStorage< TABLE, CONTAINER >(table, container), false);
120 }
121
122} /* namespace gum */
123
124#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The Table-agnostic base class of scheduleMultiDim.
the base class for "low-level" operators used to schedule inferences
const ScheduleOperator & emplaceBinaryCombination(const ScheduleMultiDim< TABLE1 > &table1, const ScheduleMultiDim< TABLE2 > &table2, TABLE_RES(*combine)(const TABLE1 &, const TABLE2 &), const bool is_result_persistent=false)
emplace a new schedule binary combination operation
Bijection< const IScheduleMultiDim *, Idx > _multidim2id_
a bijection between pointers to IScheduleMultiDim and their Ids
Definition schedule.h:402
const IScheduleMultiDim * insertTable(const TABLE &table, const bool copy, const Idx id=0)
inserts a new table as a source operation's input, i.e., this table is not computed by any ScheduleOp...
Idx _version_number_
a number that identifies the current version of the schedule
Definition schedule.h:426
HashTable< const IScheduleMultiDim *, NodeSet > _multidim2nodes_
maps the multidims to the set of operations that use them
Definition schedule.h:408
const ScheduleOperator & emplaceStorage(const IScheduleMultiDim &table, CONTAINER< TABLE > &container)
emplace a new schedule storage operation
const ScheduleOperator & emplaceDeletion(const ScheduleMultiDim< TABLE > &table)
emplace a new schedule deletion operation
const ScheduleOperator & insertOperation(const ScheduleOperator &op, const bool are_results_persistent=false)
inserts an operation into the schedule
HashTable< const IScheduleMultiDim *, std::pair< ScheduleOperator *, Idx > > _multidim_location_
a structure to indicate precisely where a ScheduleMultiDim comes from
Definition schedule.h:399
const ScheduleOperator & emplaceProjection(const ScheduleMultiDim< TABLE > &table, const gum::VariableSet &del_vars, TABLE(*project)(const TABLE &, const gum::VariableSet &), const bool is_result_persistent=false)
emplace a new schedule projection operation
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Size Idx
Type for indexes.
Definition types.h:79
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet