lemon/bipartite_matching.h
changeset 2138 a683f63b54e2
parent 2058 0b1fc1566fdb
child 2151 38ec4a930c05
equal deleted inserted replaced
2:07146d970d32 3:64f8bac33cb4
  1323       for (ANodeIt it(*graph); it != INVALID; ++it) {
  1323       for (ANodeIt it(*graph); it != INVALID; ++it) {
  1324         if (anode_matching[it] == INVALID) {
  1324         if (anode_matching[it] == INVALID) {
  1325           _heap->push(it, 0);
  1325           _heap->push(it, 0);
  1326         }
  1326         }
  1327       }
  1327       }
       
  1328       Value bdistMax = 0;
  1328 
  1329 
  1329       while (!_heap->empty()) {
  1330       while (!_heap->empty()) {
  1330         Node anode = _heap->top();
  1331         Node anode = _heap->top();
  1331         Value avalue = _heap->prio();
  1332         Value avalue = _heap->prio();
  1332         _heap->pop();
  1333         _heap->pop();
  1336           Value bvalue = avalue + (*cost)[jt] + 
  1337           Value bvalue = avalue + (*cost)[jt] + 
  1337             anode_potential[anode] - bnode_potential[bnode];
  1338             anode_potential[anode] - bnode_potential[bnode];
  1338           if (bpred[bnode] == INVALID || bvalue < bdist[bnode]) {
  1339           if (bpred[bnode] == INVALID || bvalue < bdist[bnode]) {
  1339             bdist[bnode] = bvalue;
  1340             bdist[bnode] = bvalue;
  1340             bpred[bnode] = jt;
  1341             bpred[bnode] = jt;
       
  1342           }
       
  1343           if (bvalue > bdistMax) {
       
  1344             bdistMax = bvalue;
  1341           }
  1345           }
  1342           if (bnode_matching[bnode] != INVALID) {
  1346           if (bnode_matching[bnode] != INVALID) {
  1343             Node newanode = graph->aNode(bnode_matching[bnode]);
  1347             Node newanode = graph->aNode(bnode_matching[bnode]);
  1344             switch (_heap->state(newanode)) {
  1348             switch (_heap->state(newanode)) {
  1345             case Heap::PRE_HEAP:
  1349             case Heap::PRE_HEAP:
  1371       ++matching_size;
  1375       ++matching_size;
  1372 
  1376 
  1373       for (BNodeIt it(*graph); it != INVALID; ++it) {
  1377       for (BNodeIt it(*graph); it != INVALID; ++it) {
  1374         if (bpred[it] != INVALID) {
  1378         if (bpred[it] != INVALID) {
  1375           bnode_potential[it] += bdist[it];
  1379           bnode_potential[it] += bdist[it];
       
  1380         } else {
       
  1381           bnode_potential[it] += bdistMax;
  1376         }
  1382         }
  1377       }
  1383       }
  1378       for (ANodeIt it(*graph); it != INVALID; ++it) {
  1384       for (ANodeIt it(*graph); it != INVALID; ++it) {
  1379         if (anode_matching[it] != INVALID) {
  1385         if (anode_matching[it] != INVALID) {
  1380           Node bnode = graph->bNode(anode_matching[it]);
  1386           Node bnode = graph->bNode(anode_matching[it]);
  1381           if (bpred[bnode] != INVALID) {
  1387           if (bpred[bnode] != INVALID) {
  1382             anode_potential[it] += bdist[bnode];
  1388             anode_potential[it] += bdist[bnode];
       
  1389           } else {
       
  1390             anode_potential[it] += bdistMax;
  1383           }
  1391           }
  1384         }
  1392         }
  1385       }
  1393       }
  1386 
  1394 
  1387       while (bestNode != INVALID) {
  1395       while (bestNode != INVALID) {