1 #include "IGraphPairwise.h" 7 addEdge(srcNode, dstNode, 0, pot);
18 addArc(Node1, Node2, 0, pot);
25 addEdge(Node1, Node2, group, Mat());
26 addEdge(Node2, Node1, group, Mat());
31 addEdge(Node1, Node2, group, Pot);
32 addEdge(Node2, Node1, group, Pot.t());
66 for (
size_t node : nodes) {
67 vec_size_t parentNodes, childNodes, managers;
72 for (
size_t child : childNodes) {
74 auto isArc = std::find(parentNodes.begin(), parentNodes.end(), child);
75 if (isArc != parentNodes.end())
continue;
77 auto isInZ = std::find(nodes.begin(), nodes.end(), child);
78 if (isInZ != nodes.end())
continue;
80 managers.push_back(child);
83 for (
size_t parent : parentNodes) {
84 auto isInZ = std::find(nodes.begin(), nodes.end(), parent);
85 if (isInZ != nodes.end())
continue;
89 if (pot1.empty() && pot2.empty())
addEdge(parent, child);
91 pot1.empty() ? pot = pot2 + pot1 : pot = pot1 + pot2;
98 if (managers.size() >= 2)
99 for (
size_t i = 0; i < managers.size() - 1; i++)
100 for (
size_t j = i + 1; j < managers.size(); j++) {
101 getEdge(node, managers[i], pot1);
102 getEdge(node, managers[j], pot2);
103 if (pot1.empty() && pot2.empty())
addArc(managers[i], managers[j]);
105 pot1.empty() ? pot = pot2 + pot1 : pot = pot1 + pot2;
106 addArc(managers[i], managers[j], pot);
111 for (
size_t &parent : parentNodes)
removeEdge(parent, node);
112 for (
size_t &child : childNodes)
removeEdge(node, child);
virtual void setArcGroup(size_t Node1, size_t Node2, byte group)
Assigns an undirected edge (arc) (Node1) – (Node2) to the group group.
void addArc(size_t Node1, size_t Node2, const Mat &pot=EmptyMat)
Adds an additional udirected edge (arc) with specified potentional.
virtual bool isEdgeExists(size_t srcNode, size_t dstNode) const =0
Checks whether the edge exists.
virtual void setEdgeGroup(size_t srcNode, size_t dstNode, byte group)=0
Assigns a directed edge (srcNode) –> (dstNode) to the group group.
virtual void getChildNodes(size_t node, vec_size_t &vNodes) const =0
Returns the set of IDs of the child nodes of the argument node.
virtual void getParentNodes(size_t node, vec_size_t &vNodes) const =0
Returns the set of IDs of the parent nodes of the argument node.
void marginalize(const vec_size_t &nodes)
Marginalizes a set of nodes.
virtual void removeArc(size_t Node1, size_t Node2)
Removes the specified arc.
virtual bool isArcExists(size_t Node1, size_t Node2) const
Checks whether the arc exists.
void addEdge(size_t srcNode, size_t dstNode, const Mat &pot=EmptyMat)
Adds an additional directed edge with specified potentional.
virtual void getEdge(size_t srcNode, size_t dstNode, Mat &pot) const =0
Returns the edge potential.
virtual void setEdge(size_t srcNode, size_t dstNode, const Mat &pot)=0
Sets or changes the potentional of directed edge.
virtual void setArc(size_t Node1, size_t Node2, const Mat &pot)
Sets or changes the potentional of udirected edge (arc)
virtual void removeEdge(size_t srcNode, size_t dstNode)=0
Removes the specified edge.
virtual bool isEdgeArc(size_t srcNode, size_t dstNode) const
Checks whether the edge is a part of an arc.