return a->incomingEdges().count() > b->incomingEdges().count();
}
+bool cmp2(Edge *a, Edge *b)
+{
+ return a->startNode()->outgoingEdges().count() > b->startNode()->outgoingEdges().count();
+}
+
void PMC::run()
{
while(!step())
qSort(nodesByIncomingCount.begin(), nodesByIncomingCount.end(), cmp);
// Check if possible
+ if (m_graph->nodes().count() < 2 * m() - 1)
+ {
+ emit log("|E|>=2m+1 not met. END");
+ m_failed = true;
+ m_finished = true;
+ return true;
+ }
+
bool can = true;
bool allAtM = true;
for (int i = 0; i < nodesByIncomingCount.count(); ++i)
return true;
}
- qSort(nodes.begin(), nodes.end());
+ qSort(nodes.begin(), nodes.end(), cmp);
QVector<Node *> combination(nodes.count() - 2 * m() + m() - 1);
for (int i = 0; i < nodesByIncomingCount.count(); ++i)
n->setColor(Qt::red);
continue;
}
+ if (n->incomingEdges().count() == m())
+ {
+ continue;
+ }
n->setColor(Qt::yellow);
- for (int j = 0; j < n->incomingEdges().count(); ++j)
+ QVector<Edge *> edges = n->incomingEdges().toVector();
+
+ qSort(edges.begin(), edges.end(), cmp2);
+ for (int j = 0; j < edges.count(); ++j)
{
- Edge *e = n->incomingEdges()[j];
+ Edge *e = edges[j];
Node *otherNode = e->startNode();
bool removable = true;
// HAKIMI
- for (int p = 0; p < m() - 1; ++p)
+ for (int p = 0; p <= m() - 1; ++p)
{
int Ep = nodes.count() - 2 * m() + p;
qCopy(nodes.begin(), nodes.begin() + Ep, combination.begin());
do {
int sum = 0;
+
for (int k = 0; k < Ep; ++k)
- sum += combination.at(k)->outgoingEdges().count();
- if (combination.contains(otherNode))
- --sum;
+ {
+ Node *hn = combination[k];
+ for (int m = 0; m < hn->outgoingEdges().count(); ++m)
+ {
+ Edge *he = hn->outgoingEdges()[m];
+ if (combination.contains(he->endNode()))
+ continue;
+ if (he->startNode() == otherNode && he->endNode() == n)
+ continue;
+ ++sum;
+ }
+ }
if (sum <= p)
{