aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
multiDimCombineAndProject_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-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#pragma once
42
43
49
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53# include <agrum/agrum.h>
54
55namespace gum {
56
57 // default constructor
58 template < class TABLE >
60 // for debugging purposes
61 GUM_CONSTRUCTOR(MultiDimCombineAndProject);
62 }
63
64 // copy constructor
65 template < class TABLE >
68 // for debugging purposes
69 GUM_CONS_CPY(MultiDimCombineAndProject);
70 }
71
72 // destructor
73 template < class TABLE >
75 // for debugging purposes
76 GUM_DESTRUCTOR(MultiDimCombineAndProject);
77 }
78
79 // add to a given schedule the set of operations needed
80 template < class TABLE >
82 Schedule& schedule,
83 const Set< const IScheduleMultiDim* >& original_tables,
84 const gum::VariableSet& del_vars,
85 const bool is_result_persistent) const {
86 // compute the set of operations to perform and insert them into the schedule
87 auto ops_res = operations(original_tables, del_vars, false);
88 for (const auto op: ops_res.first)
89 schedule.insertOperation(*op);
90
91 // get the results actually stored into the schedule
92 Set< const IScheduleMultiDim* > result(ops_res.second.size());
93 if (!is_result_persistent) {
94 for (const auto pot: ops_res.second)
95 result.insert(schedule.scheduleMultiDim(pot->id()));
96 } else {
97 for (const auto pot: ops_res.second) {
98 const IScheduleMultiDim* table = schedule.scheduleMultiDim(pot->id());
99 const auto creating_op = schedule.scheduleMultiDimCreator(table);
100 if (creating_op != nullptr) {
101 const_cast< ScheduleOperator* >(creating_op)->makeResultsPersistent(true);
102 }
103 result.insert(table);
104 }
105 }
106
107 // free memory
108 for (const auto op: ops_res.first)
109 delete op;
110
111 return result;
112 }
113
114} /* namespace gum */
115
116#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The Table-agnostic base class of scheduleMultiDim.
A generic interface to combine and project efficiently MultiDim tables.
virtual ~MultiDimCombineAndProject()
destructor
Set< const IScheduleMultiDim * > schedule(Schedule &schedule, const Set< const IScheduleMultiDim * > &original_tables, const gum::VariableSet &del_vars, const bool is_result_persistent=false) const
add to a given schedule the set of operations needed to perform all the combinations and projections
MultiDimCombineAndProject()
default constructor
the base class for "low-level" operators used to schedule inferences
Class containing a schedule of operations to perform on multidims.
Definition schedule.h:79
Representation of a set.
Definition set.h:129
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet