89 ApproximationScheme::operator=(from);
100 ApproximationScheme::operator=(std::move(from));
125 const HashTable< std::pair< NodeId, NodeId >,
char >& constraints) {
172 for (
const auto parent:
graph.parents(n2)) {
173 if (
graph.existsArc(n2, parent))
continue;
174 if (parent == n1)
continue;
190 while (!nodeFIFO.
empty()) {
191 current = nodeFIFO.
front();
193 for (
const auto new_one:
graph.parents(current)) {
194 if (
graph.existsArc(current, new_one))
continue;
195 if (new_one == n1)
return true;
196 if (mark.
exists(new_one))
continue;
215 bool withdrawFlag_L =
false;
216 for (
auto arc:
ArcSet(L)) {
219 bool withdrawFlag_arc =
false;
221 if (tail_head && !head_tail) {
223 withdrawFlag_arc =
true;
224 }
else if (!tail_head && head_tail) {
226 withdrawFlag_arc =
true;
227 }
else if (!tail_head && !head_tail) {
229 withdrawFlag_arc =
true;
232 if (withdrawFlag_arc) {
234 withdrawFlag_L =
true;
237 if (L.
empty())
break;
240 if (!withdrawFlag_L) {
241 auto arc = *L.
begin();
252 if (
graph.existsEdge(arc.head(), arc.tail()))
graph.eraseEdge(
Edge(arc.head(), arc.tail()));
253 if (!
graph.existsArc(arc.tail(), arc.head())) {
256 "Add Arc" << arc.tail() <<
"->" << arc.head(),
258 graph.addArc(arc.tail(), arc.head());
262 if (
graph.existsEdge(
Edge(arc.tail(), arc.head()))) {
263 graph.eraseEdge(
Edge(arc.tail(), arc.head()));
264 graph.addArc(arc.head(), arc.tail());
267 "Add Arc" << arc.head() <<
"->" << arc.tail(),
268 "Forbidden in the other orientation")
276 graph.addNodeWithId(n);
279 if (x > y) std::swap(x, y);
281 GUM_SL_EMIT(x, y,
"Remove " << x <<
" - " << y,
"Constraints : Forbidden edge")
282 else graph.addEdge(x, y);
287 const std::vector< NodeId > nodes(template_graph.
nodes().
begin(),
289 for (std::size_t i = 0; i < nodes.size(); ++i)
290 for (std::size_t j = i + 1; j < nodes.size(); ++j)
291 addEdgeIfAllowed(nodes[i], nodes[j]);
293 for (
const auto& edge: template_graph.
edges())
294 addEdgeIfAllowed(edge.first(), edge.second());
300 std::vector< ThreePoints >
302 std::vector< ThreePoints > triples;
306 if (y < x && !
graph.existsEdge(x, y) && !
graph.existsArc(x, y)
307 && !
graph.existsArc(y, x)) {
308 triples.emplace_back(x, y, z);
Abstract base class for constraint-based structure learning algorithms.
#define GUM_SL_EMIT(x, y, action, explain)
ApproximationScheme(bool verbosity=false)
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
The base class for all directed edges.
Base class for all oriented graphs.
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
The base class for all undirected edges.
The class for generic Hash Tables.
Generic doubly linked lists.
Val & front() const
Returns a reference to first element of a list, if any.
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
void popFront()
Removes the first element of a List, if any.
Base class for mixed graphs.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
const node_iterator & end() const noexcept
the end iterator to parse the set of nodes contained in the NodeGraphPart
Base class for partially directed acyclic graphs.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
iterator begin() const
The usual unsafe begin iterator to parse the set.
void insert(const Key &k)
Inserts a new element into the set.
void erase(const Key &k)
Erases an element from the set.
Abstract base class for constraint-based structure learning algorithms.
gum::DAG _mandatoryGraph_
gum::DiGraph _forbiddenGraph_
void setMandatoryGraph(const gum::DAG &mandaGraph)
std::vector< ThreePoints > unshieldedTriples_(const MixedGraph &graph)
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
static bool _existsNonTrivialDirectedPath_(const MixedGraph &graph, NodeId n1, NodeId n2)
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
gum::MeekRules meekRules_
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
bool isForbiddenEdge_(NodeId x, NodeId y) const
bool isMaxIndegree_(const MixedGraph &graph, NodeId x)
bool isForbiddenArc_(NodeId x, NodeId y) const
void setMaxIndegree(gum::Size n)
void setForbiddenGraph(const gum::DiGraph &forbidGraph)
const std::vector< Arc > latentVariables() const
bool isArcValid_(const MixedGraph &graph, NodeId x, NodeId y)
void orientDoubleHeadedArcs_(MixedGraph &mg)
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
PDAG learnPDAG(MixedGraph graph)
learns the essential graph (CPDAG)
HashTable< std::pair< NodeId, NodeId >, char > _initialMarks_
static bool _existsDirectedPath_(const MixedGraph &graph, NodeId n1, NodeId n2)
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
ConstraintBasedLearning()
void addConstraints(const HashTable< std::pair< NodeId, NodeId >, char > &constraints)
virtual MixedGraph learnMixedStructure(MixedGraph graph)=0
ConstraintBasedLearning & operator=(const ConstraintBasedLearning &)
~ConstraintBasedLearning() override
DAG learnDAG(MixedGraph graph)
learns a DAG
void applyStructuralConstraints_(MixedGraph &graph)
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
MixedGraph initGraph_(const MixedGraph &template_graph)
Builds a complete MixedGraph on the nodes of template_graph, minus edges forbidden by structural cons...
std::vector< Arc > _latentCouples_
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
Class hash tables iterators.
Base classes for mixed directed/undirected graphs.
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities