aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::learning::StructuralConstraintTotalOrder Class Reference

the structural constraint imposing a total order over some nodes More...

#include <structuralConstraintTotalOrder.h>

Inheritance diagram for gum::learning::StructuralConstraintTotalOrder:
Collaboration diagram for gum::learning::StructuralConstraintTotalOrder:

Public Types

using allConstraints = _ConstraintSet_< void >

Public Member Functions

Constructors / Destructors
 StructuralConstraintTotalOrder ()
 default constructor
 StructuralConstraintTotalOrder (const Sequence< NodeId > &order)
 constructor starting with an empty graph with a given number of nodes
 StructuralConstraintTotalOrder (const DiGraph &graph, const Sequence< NodeId > &order)
 constructor starting with a given graph
 StructuralConstraintTotalOrder (const StructuralConstraintTotalOrder &from)
 copy constructor
 StructuralConstraintTotalOrder (StructuralConstraintTotalOrder &&from)
 move constructor
virtual ~StructuralConstraintTotalOrder ()
 destructor
Operators
StructuralConstraintTotalOrderoperator= (const StructuralConstraintTotalOrder &from)
 copy operator
StructuralConstraintTotalOrderoperator= (StructuralConstraintTotalOrder &&from)
 move operator
Specific Accessors / Modifiers
void setTotalOrder (const Sequence< NodeId > &Total)
 sets the Total order of all the nodes in the property
const Sequence< NodeId > & totalOrder () const
 returns the current Total order
void setGraphAlone (const DiGraph &graph)
 sets a new graph from which we will perform checkings
void modifyGraphAlone (const ArcAddition &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcDeletion &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcReversal &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcTriangleDeletion1 &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcTriangleDeletion2 &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const GraphChange &change)
 notify the constraint of a modification of the graph
bool isAlwaysInvalidAlone (const GraphChange &change) const
 indicates whether a change will always violate the constraint
bool checkArcAdditionAlone (NodeId x, NodeId y) const
 checks whether the constraints enable to add arc (x,y)
bool checkArcDeletionAlone (NodeId x, NodeId y) const
 checks whether the constraints enable to remove arc (x,y)
bool checkArcReversalAlone (NodeId x, NodeId y) const
 checks whether the constraints enable to reverse arc (x,y)
bool checkArcTriangleDeletion1Alone (NodeId node1, NodeId node2, NodeId node3) const
 checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkArcTriangleDeletion2Alone (NodeId node1, NodeId node2, NodeId node3) const
 checks whether the constraints enable to apply an ArcTriangleDeletion2
bool checkModificationAlone (const ArcAddition &change) const
 checks whether the constraints enable to add an arc
bool checkModificationAlone (const ArcDeletion &change) const
 checks whether the constraints enable to remove an arc
bool checkModificationAlone (const ArcReversal &change) const
 checks whether the constraints enable to reverse an arc
bool checkModificationAlone (const ArcTriangleDeletion1 &change) const
 checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkModificationAlone (const ArcTriangleDeletion2 &change) const
 checks whether the constraints enable to apply an ArcTriangleDeletion2
bool checkModificationAlone (const GraphChange &change) const
 checks whether the constraints enable to perform a graph change

Protected Attributes

Sequence< NodeId_total_order_
 the total ordering over the nodes

Detailed Description

the structural constraint imposing a total order over some nodes

Warning
the total order needs not be defined over all the variables in the database. If you define it on a proper subset, then the constraint applies only on this subset.

Definition at line 67 of file structuralConstraintTotalOrder.h.

Member Typedef Documentation

◆ allConstraints

using gum::learning::StructuralConstraintEmpty::allConstraints = _ConstraintSet_< void >
inherited

Definition at line 61 of file structuralConstraint.h.

Constructor & Destructor Documentation

◆ StructuralConstraintTotalOrder() [1/5]

gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder ( )

default constructor

Definition at line 60 of file structuralConstraintTotalOrder.cpp.

60 {
61 GUM_CONSTRUCTOR(StructuralConstraintTotalOrder);
62 }

References StructuralConstraintTotalOrder().

Referenced by StructuralConstraintTotalOrder(), StructuralConstraintTotalOrder(), StructuralConstraintTotalOrder(), StructuralConstraintTotalOrder(), StructuralConstraintTotalOrder(), ~StructuralConstraintTotalOrder(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StructuralConstraintTotalOrder() [2/5]

gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder ( const Sequence< NodeId > & order)

constructor starting with an empty graph with a given number of nodes

param order the partial order

Definition at line 65 of file structuralConstraintTotalOrder.cpp.

66 : _total_order_(order) {
67 GUM_CONSTRUCTOR(StructuralConstraintTotalOrder);
68 }
Sequence< NodeId > _total_order_
the total ordering over the nodes

References StructuralConstraintTotalOrder(), and _total_order_.

Here is the call graph for this function:

◆ StructuralConstraintTotalOrder() [3/5]

gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder ( const DiGraph & graph,
const Sequence< NodeId > & order )

constructor starting with a given graph

Definition at line 71 of file structuralConstraintTotalOrder.cpp.

73 : _total_order_(order) {
74 GUM_CONSTRUCTOR(StructuralConstraintTotalOrder);
75 }

References StructuralConstraintTotalOrder(), and _total_order_.

Here is the call graph for this function:

◆ StructuralConstraintTotalOrder() [4/5]

gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder ( const StructuralConstraintTotalOrder & from)

copy constructor

Definition at line 78 of file structuralConstraintTotalOrder.cpp.

79 : _total_order_(from._total_order_) {
81 }

References StructuralConstraintTotalOrder(), and _total_order_.

Here is the call graph for this function:

◆ StructuralConstraintTotalOrder() [5/5]

gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder ( StructuralConstraintTotalOrder && from)

move constructor

Definition at line 84 of file structuralConstraintTotalOrder.cpp.

85 : _total_order_(std::move(from._total_order_)) {
87 }

References StructuralConstraintTotalOrder(), and _total_order_.

Here is the call graph for this function:

◆ ~StructuralConstraintTotalOrder()

gum::learning::StructuralConstraintTotalOrder::~StructuralConstraintTotalOrder ( )
virtual

destructor

Definition at line 90 of file structuralConstraintTotalOrder.cpp.

90 {
91 GUM_DESTRUCTOR(StructuralConstraintTotalOrder);
92 }

References StructuralConstraintTotalOrder().

Here is the call graph for this function:

Member Function Documentation

◆ checkArcAdditionAlone()

bool gum::learning::StructuralConstraintTotalOrder::checkArcAdditionAlone ( NodeId x,
NodeId y ) const

checks whether the constraints enable to add arc (x,y)

an arc can be added if and only if its extremal nodes belong to the graph and the arc does not already exist and is not a backward-time arc.

Referenced by checkModificationAlone(), and isAlwaysInvalidAlone().

Here is the caller graph for this function:

◆ checkArcDeletionAlone()

bool gum::learning::StructuralConstraintTotalOrder::checkArcDeletionAlone ( NodeId x,
NodeId y ) const

checks whether the constraints enable to remove arc (x,y)

an arc can be removed if and only if the arc exists.

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkArcReversalAlone()

bool gum::learning::StructuralConstraintTotalOrder::checkArcReversalAlone ( NodeId x,
NodeId y ) const

checks whether the constraints enable to reverse arc (x,y)

an arc can be reversed if and only if it exists and arc (y,x) does not and is not a backward-time arc.

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkArcTriangleDeletion1Alone()

bool gum::learning::StructuralConstraintTotalOrder::checkArcTriangleDeletion1Alone ( NodeId node1,
NodeId node2,
NodeId node3 ) const

checks whether the constraints enable to apply an ArcTriangleDeletion1

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

Referenced by checkModificationAlone(), and isAlwaysInvalidAlone().

Here is the caller graph for this function:

◆ checkArcTriangleDeletion2Alone()

bool gum::learning::StructuralConstraintTotalOrder::checkArcTriangleDeletion2Alone ( NodeId node1,
NodeId node2,
NodeId node3 ) const

checks whether the constraints enable to apply an ArcTriangleDeletion2

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

Referenced by checkModificationAlone(), and isAlwaysInvalidAlone().

Here is the caller graph for this function:

◆ checkModificationAlone() [1/6]

bool gum::learning::StructuralConstraintTotalOrder::checkModificationAlone ( const ArcAddition & change) const

checks whether the constraints enable to add an arc

an arc can be added if and only if its extremal nodes belong to the graph and the arc does not already exist and is not a backward-time arc.

◆ checkModificationAlone() [2/6]

bool gum::learning::StructuralConstraintTotalOrder::checkModificationAlone ( const ArcDeletion & change) const

checks whether the constraints enable to remove an arc

an arc can be removed if and only if the arc exists.

◆ checkModificationAlone() [3/6]

bool gum::learning::StructuralConstraintTotalOrder::checkModificationAlone ( const ArcReversal & change) const

checks whether the constraints enable to reverse an arc

an arc can be reversed if and only if it exists and arc (y,x) does not and is not a backward-time arc.

◆ checkModificationAlone() [4/6]

bool gum::learning::StructuralConstraintTotalOrder::checkModificationAlone ( const ArcTriangleDeletion1 & change) const

checks whether the constraints enable to apply an ArcTriangleDeletion1

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

◆ checkModificationAlone() [5/6]

bool gum::learning::StructuralConstraintTotalOrder::checkModificationAlone ( const ArcTriangleDeletion2 & change) const

checks whether the constraints enable to apply an ArcTriangleDeletion2

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

◆ checkModificationAlone() [6/6]

bool gum::learning::StructuralConstraintTotalOrder::checkModificationAlone ( const GraphChange & change) const

checks whether the constraints enable to perform a graph change

An arc can be added if and only if its extremal nodes belong to the graph and the arc does not already exist and is not a backward-time arc. An arc can be removed if and only if the arc exists. An arc (x,y) can be reversed if and only if it exists and arc (y,x) does not and is not a backward-time arc.

Definition at line 132 of file structuralConstraintTotalOrder.cpp.

132 {
133 switch (change.type()) {
135 return checkArcAdditionAlone(change.node1(), change.node2());
136
138 return checkArcDeletionAlone(change.node1(), change.node2());
139
141 return checkArcReversalAlone(change.node1(), change.node2());
142
144 return checkArcTriangleDeletion1Alone(change.node1(), change.node2(), change.node3());
145
147 return checkArcTriangleDeletion2Alone(change.node1(), change.node2(), change.node3());
148
149 default :
150 GUM_ERROR(OperationNotAllowed,
151 "edge modifications are not "
152 "supported by the Total Order structural constraint");
153 }
154 }
bool checkArcTriangleDeletion2Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
bool checkArcTriangleDeletion1Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References gum::learning::ARC_ADDITION, gum::learning::ARC_DELETION, gum::learning::ARC_REVERSAL, gum::learning::ARC_TRIANGLE_DELETION1, gum::learning::ARC_TRIANGLE_DELETION2, checkArcAdditionAlone(), checkArcDeletionAlone(), checkArcReversalAlone(), checkArcTriangleDeletion1Alone(), checkArcTriangleDeletion2Alone(), GUM_ERROR, gum::learning::GraphChange::node1(), gum::learning::GraphChange::node2(), gum::learning::GraphChange::node3(), and gum::learning::GraphChange::type().

Here is the call graph for this function:

◆ isAlwaysInvalidAlone()

bool gum::learning::StructuralConstraintTotalOrder::isAlwaysInvalidAlone ( const GraphChange & change) const

indicates whether a change will always violate the constraint

Some learning algorithms need examine several times whether a given graph change can be applied. For instance, the first time arc (X,Y) addition is considered, the learning algorithm may discard this change because it violates the structural constraint (e.g., if the latter enforces a DAG structure, this arc addition might induce a directed cycle), but, later on, other arc removal may induce that the arc addition is now possible. Such change is thus not always invalid. Conversely, there are changes that can be discarded once and for all. For instance, in a 2TBN structure, it is always impossible to add a backward-time arc. Such graph changes are always invalid and are therefore tagged as such by the isAlwaysInvalid method.

Definition at line 108 of file structuralConstraintTotalOrder.cpp.

108 {
109 switch (change.type()) {
111 return !checkArcAdditionAlone(change.node1(), change.node2());
112
113 case GraphChangeType::ARC_DELETION : return false;
114
116 return !checkArcAdditionAlone(change.node2(), change.node1());
117
119 return !checkArcTriangleDeletion1Alone(change.node1(), change.node2(), change.node3());
120
122 return !checkArcTriangleDeletion2Alone(change.node1(), change.node2(), change.node3());
123
124 default :
125 GUM_ERROR(OperationNotAllowed,
126 "Graph change operation "
127 << change.typeAsString()
128 << " is not supported by the Total Order structural constraint");
129 }
130 }

References gum::learning::ARC_ADDITION, gum::learning::ARC_DELETION, gum::learning::ARC_REVERSAL, gum::learning::ARC_TRIANGLE_DELETION1, gum::learning::ARC_TRIANGLE_DELETION2, checkArcAdditionAlone(), checkArcTriangleDeletion1Alone(), checkArcTriangleDeletion2Alone(), GUM_ERROR, gum::learning::GraphChange::node1(), gum::learning::GraphChange::node2(), gum::learning::GraphChange::node3(), gum::learning::GraphChange::type(), and gum::learning::GraphChange::typeAsString().

Here is the call graph for this function:

◆ modifyGraphAlone() [1/6]

void gum::learning::StructuralConstraintTotalOrder::modifyGraphAlone ( const ArcAddition & change)

notify the constraint of a modification of the graph

Warning
If an already existing arc is added, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeexception is thrown if an arc (x,y) is added and x or y does not belong to the graph nodes
InvalidArcexception is thrown if any time-backward arc is created by the arc addition.

◆ modifyGraphAlone() [2/6]

void gum::learning::StructuralConstraintTotalOrder::modifyGraphAlone ( const ArcDeletion & change)

notify the constraint of a modification of the graph

Warning
If a nonexisting arc is removed, nothing is done. In particular, no exception is raised.

◆ modifyGraphAlone() [3/6]

void gum::learning::StructuralConstraintTotalOrder::modifyGraphAlone ( const ArcReversal & change)

notify the constraint of a modification of the graph

Warning
If an already existing arc is added, or if a nonexisting arc is removed, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeexception is thrown if an arc (x,y) is added and x or y does not belong to the graph nodes
InvalidArcexception is thrown if any time-backward arc is created by the arc reversal.

◆ modifyGraphAlone() [4/6]

void gum::learning::StructuralConstraintTotalOrder::modifyGraphAlone ( const ArcTriangleDeletion1 & change)

notify the constraint of a modification of the graph

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

◆ modifyGraphAlone() [5/6]

void gum::learning::StructuralConstraintTotalOrder::modifyGraphAlone ( const ArcTriangleDeletion2 & change)

notify the constraint of a modification of the graph

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

◆ modifyGraphAlone() [6/6]

void gum::learning::StructuralConstraintTotalOrder::modifyGraphAlone ( const GraphChange & change)

notify the constraint of a modification of the graph

Warning
If an already existing arc is added, or if a nonexisting arc is removed, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeexception is thrown if an arc (x,y) is added or reversed and x or y does not belong to the graph nodes
InvalidArcexception is thrown if any time-backward arc is created by an arc addition or reversal.

◆ operator=() [1/2]

StructuralConstraintTotalOrder & gum::learning::StructuralConstraintTotalOrder::operator= ( const StructuralConstraintTotalOrder & from)

copy operator

Definition at line 96 of file structuralConstraintTotalOrder.cpp.

96 {
97 if (this != &from) { _total_order_ = from._total_order_; }
98 return *this;
99 }

References StructuralConstraintTotalOrder(), and _total_order_.

Here is the call graph for this function:

◆ operator=() [2/2]

StructuralConstraintTotalOrder & gum::learning::StructuralConstraintTotalOrder::operator= ( StructuralConstraintTotalOrder && from)

move operator

Definition at line 103 of file structuralConstraintTotalOrder.cpp.

103 {
104 if (this != &from) { _total_order_ = std::move(from._total_order_); }
105 return *this;
106 }

References StructuralConstraintTotalOrder(), and _total_order_.

Here is the call graph for this function:

◆ setGraphAlone()

void gum::learning::StructuralConstraintTotalOrder::setGraphAlone ( const DiGraph & graph)

sets a new graph from which we will perform checkings

◆ setTotalOrder()

void gum::learning::StructuralConstraintTotalOrder::setTotalOrder ( const Sequence< NodeId > & Total)

sets the Total order of all the nodes in the property

Referenced by gum::learning::K2::learnBN(), and gum::learning::K2::learnStructure().

Here is the caller graph for this function:

◆ totalOrder()

const Sequence< NodeId > & gum::learning::StructuralConstraintTotalOrder::totalOrder ( ) const

returns the current Total order

Member Data Documentation

◆ _total_order_

Sequence< NodeId > gum::learning::StructuralConstraintTotalOrder::_total_order_
protected

The documentation for this class was generated from the following files: