aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
schedule_inl.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
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
44
46
47namespace gum {
48
51
53 INLINE Schedule* Schedule::clone() const { return new Schedule(*this); }
54
56 INLINE bool Schedule::operator!=(const Schedule& from) const { return !operator==(from); }
57
59 INLINE Idx Schedule::versionNumber() const { return _version_number_; }
60
62 INLINE const DAG& Schedule::dag() const { return _dag_; }
63
65 INLINE const ScheduleOperator& Schedule::operation(const NodeId node_id) const {
66 return *(_node2op_.second(node_id));
67 }
68
70 INLINE NodeId Schedule::nodeId(const ScheduleOperator& op) const {
71 return _node2op_.first(const_cast< ScheduleOperator* >(&op));
72 }
73
76 std::vector< NodeId >& new_available_nodes,
77 const bool check) {
79 if (check) {
80 if (!_node2op_.existsSecond(const_cast< ScheduleOperator* >(&op))) {
81 GUM_ERROR(UnknownScheduleOperation,
82 "the schedule cannot be updated because Operation "
83 << op.toString() << " that has been executed does not belong to its DAG.");
84 }
85 }
86
87 updateAfterExecution(_node2op_.first(const_cast< ScheduleOperator* >(&op)),
88 new_available_nodes,
89 check);
90 }
91
93 INLINE const IScheduleMultiDim* Schedule::scheduleMultiDim(const NodeId id) const {
94 return _multidim2id_.first(id);
95 }
96
98 INLINE bool Schedule::existsScheduleMultiDim(const NodeId id) const {
99 return _multidim2id_.existsSecond(id);
100 }
101
103 INLINE NodeId Schedule::scheduleMultiDimId(const IScheduleMultiDim* multidim) const {
104 return _multidim2id_.second(multidim);
105 }
106
108 INLINE const ScheduleOperator*
110 return _multidim_location_[multidim].first;
111 }
112
114 INLINE const ScheduleOperator* Schedule::scheduleMultiDimCreator(const NodeId id) const {
115 return scheduleMultiDimCreator(_multidim2id_.first(id));
116 }
117
118} /* namespace gum */
119
120#endif /* DOXYGEN_SHOULD_SKIP_THIS */
Base class for dag.
Definition DAG.h:121
The Table-agnostic base class of scheduleMultiDim.
the base class for "low-level" operators used to schedule inferences
Class containing a schedule of operations to perform on multidims.
Definition schedule.h:80
static std::atomic< Idx > _overall_version_number_
Definition schedule.h:446
void updateAfterExecution(const NodeId exec_node, std::vector< NodeId > &new_available_nodes, const bool check=false)
updates the schedule after a given operation has been executed
const ScheduleOperator & operation(const NodeId id) const
returns the scheduleOperation corresponding to an id in the DAG
Idx versionNumber() const
returns the version number of the schedule
Schedule(const Size nb_ops=256)
default constructor (construct an empty sequence)
NodeId nodeId(const ScheduleOperator &) const
returns the id of the node corresponding to a given ScheduleOperator
const DAG & dag() const
returns a DAG indicating in which order the operations can be performed
bool operator==(const Schedule &) const
operator ==
Bijection< const IScheduleMultiDim *, Idx > _multidim2id_
a bijection between pointers to IScheduleMultiDim and their Ids
Definition schedule.h:402
Idx _version_number_
a number that identifies the current version of the schedule
Definition schedule.h:426
const IScheduleMultiDim * scheduleMultiDim(const NodeId id) const
returns the ScheduleMultiDim corresponding to a given id
bool existsScheduleMultiDim(const NodeId id) const
indicates whether the schedule contains a given ScheduleMultiDim
static Idx _newVersionNumber_()
returns a new distinct version for each schedule
NodeId scheduleMultiDimId(const IScheduleMultiDim *multidim) const
returns the id of a given IScheduleMultiDim
Bijection< NodeId, ScheduleOperator * > _node2op_
a mapping between the ids of the operations and their pointer
Definition schedule.h:384
virtual Schedule * clone() const
virtual copy constructor
const ScheduleOperator * scheduleMultiDimCreator(const NodeId id) const
returns the operation, if any, that created a given scheduleMultiDim
DAG _dag_
the DAG of the operations to perform
Definition schedule.h:378
HashTable< const IScheduleMultiDim *, std::pair< ScheduleOperator *, Idx > > _multidim_location_
a structure to indicate precisely where a ScheduleMultiDim comes from
Definition schedule.h:399
bool operator!=(const Schedule &) const
operator !=
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Class containing a schedule of operations to perform on multidims.