aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
schedule.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
41
47#ifndef GUM_SCHEDULE_H
48#define GUM_SCHEDULE_H
49
50#include <atomic>
51#include <memory>
52#include <sstream>
53#include <string>
54#include <utility>
55
56#include <agrum/agrum.h>
57
64
65namespace gum {
66
80 class Schedule {
81 public:
82 // ############################################################################
84 // ############################################################################
86
88 explicit Schedule(const Size nb_ops = 256);
89
91 Schedule(const Schedule& from);
92
95
97 virtual Schedule* clone() const;
98
100 virtual ~Schedule();
101
103
104
105 // ############################################################################
107 // ############################################################################
108
110
113
116
118 bool operator==(const Schedule&) const;
119
121 bool operator!=(const Schedule&) const;
122
124
125
126 // ############################################################################
128 // ############################################################################
130
145 template < typename TABLE >
146 const IScheduleMultiDim* insertTable(const TABLE& table, const bool copy, const Idx id = 0);
147
168
188
190
205 const bool are_results_persistent = false);
206
208
223 template < typename TABLE1, typename TABLE2, typename TABLE_RES >
225 const ScheduleMultiDim< TABLE2 >& table2,
226 TABLE_RES (*combine)(const TABLE1&,
227 const TABLE2&),
228 const bool is_result_persistent = false);
229
231
248 template < typename TABLE >
250 const gum::VariableSet& del_vars,
251 TABLE (*project)(const TABLE&,
252 const gum::VariableSet&),
253 const bool is_result_persistent = false);
254
256
264 template < typename TABLE >
266
268
276 template < typename TABLE, template < typename... > class CONTAINER >
278 CONTAINER< TABLE >& container);
279
281
283 const DAG& dag() const;
284
286
288 const ScheduleOperator& operation(const NodeId id) const;
289
291
294
300
302
318 void updateAfterExecution(const NodeId exec_node,
319 std::vector< NodeId >& new_available_nodes,
320 const bool check = false);
321
323
340 std::vector< NodeId >& new_available_nodes,
341 const bool check = false);
342
345
347 bool existsScheduleMultiDim(const NodeId id) const;
348
351
353
357
359
363
366
368 void clear();
369
371
372
373 private:
375
379
382
385
387
400
403
406
409
422
424
427
429
431 void _copy_(const Schedule& from);
432
434 void _destroy_();
435
437 DAG _fullDAG_() const;
438
440 static std::string _paramString_(Idx i);
441
444
445 // the version numbers help to identify the changes in schedules
446 static std::atomic< Idx > _overall_version_number_;
447 };
448
449} /* namespace gum */
450
451// always include the template implementation
453
454#ifndef GUM_NO_INLINE
456#endif /* GUM_NO_INLINE */
457
458
459#endif /* GUM_SCHEDULE_H */
Base classes for directed acyclic graphs.
Set of pairs of elements with fast search for both elements.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for dag.
Definition DAG.h:121
The class for generic Hash Tables.
Definition hashTable.h:637
The Table-agnostic base class of scheduleMultiDim.
the base class for "low-level" operators used to schedule inferences
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
virtual ~Schedule()
destructor
void _copy_(const Schedule &from)
a function to copy the content of a schedule into another one
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
void _destroy_()
a function to delete from memory the content of a schedule
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
Schedule(const Size nb_ops=256)
default constructor (construct an empty sequence)
Bijection< const IScheduleMultiDim *, NodeId > _deleted_multidim2node_
A bijection mapping ScheduleMultiDims to be deleted with the operations that will delete them.
Definition schedule.h:421
void emplaceScheduleMultiDim(const IScheduleMultiDim &multidim)
inserts without copying it a table as a source operation's input, i.e., this table is not computed by...
void clear()
empty the schedule, i.e., remove its content
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
DAG _fullDAG_() const
returns the graph that would obtain when no operation is 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
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
const IScheduleMultiDim * scheduleMultiDim(const NodeId id) const
returns the ScheduleMultiDim corresponding to a given id
HashTable< const IScheduleMultiDim *, NodeSet > _multidim2nodes_
maps the multidims to the set of operations that use them
Definition schedule.h:408
Schedule(const Schedule &from)
copy constructor
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
const ScheduleOperator * scheduleMultiDimCreator(const IScheduleMultiDim *multidim) const
returns the operation, if any, that created a given scheduleMultiDim
const ScheduleOperator & emplaceStorage(const IScheduleMultiDim &table, CONTAINER< TABLE > &container)
emplace a new schedule storage operation
Set< const IScheduleMultiDim * > _emplaced_multidims_
indicates which ScheduleMultiDims were emplaced
Definition schedule.h:405
const IScheduleMultiDim * insertScheduleMultiDim(const IScheduleMultiDim &multidim)
inserts a copy of a table as a source operation's input, i.e., this table is not computed by any Sche...
NodeId scheduleMultiDimId(const IScheduleMultiDim *multidim) const
returns the id of a given IScheduleMultiDim
const ScheduleOperator & emplaceDeletion(const ScheduleMultiDim< TABLE > &table)
emplace a new schedule deletion operation
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
static std::string _paramString_(Idx i)
returns the adjective corresponding to a parameter index (1st, 2nd, etc.)
NodeId _newId_
the highest node id in the graph
Definition schedule.h:381
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
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
void updateAfterExecution(const ScheduleOperator &exec_op, std::vector< NodeId > &new_available_nodes, const bool check=false)
updates the schedule after executing a given operation
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
NodeSet availableOperations() const
returns the set of ScheduleOperations that are ready to be executed
Schedule & operator=(Schedule &&)
move operator
bool operator!=(const Schedule &) const
operator !=
Schedule & operator=(const Schedule &)
copy operator
Schedule(Schedule &&from)
move constructor
Representation of a set.
Definition set.h:131
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
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
a binary Combination operator class used for scheduling inferences
an operator to force a ScheduleMultiDim to be abstract
a Projection operator class used for scheduling inferences
Class for storing multidimensional tables in scheduling inferences.
Class containing a schedule of operations to perform.