436 /// Sets the heap and the cross reference used by algorithm. |
436 /// Sets the heap and the cross reference used by algorithm. |
437 /// If you don't use this function before calling \ref run(), |
437 /// If you don't use this function before calling \ref run(), |
438 /// it will allocate one. The destuctor deallocates this |
438 /// it will allocate one. The destuctor deallocates this |
439 /// automatically allocated map, of course. |
439 /// automatically allocated map, of course. |
440 /// \return <tt> (*this) </tt> |
440 /// \return <tt> (*this) </tt> |
441 MaxCardinalitySearch &heap(Heap& heap, HeapCrossRef &crossRef) { |
441 MaxCardinalitySearch &heap(Heap& hp, HeapCrossRef &cr) { |
442 if(local_heap_cross_ref) { |
442 if(local_heap_cross_ref) { |
443 delete _heap_cross_ref; |
443 delete _heap_cross_ref; |
444 local_heap_cross_ref = false; |
444 local_heap_cross_ref = false; |
445 } |
445 } |
446 _heap_cross_ref = &crossRef; |
446 _heap_cross_ref = &cr; |
447 if(local_heap) { |
447 if(local_heap) { |
448 delete _heap; |
448 delete _heap; |
449 local_heap = false; |
449 local_heap = false; |
450 } |
450 } |
451 _heap = &heap; |
451 _heap = &hp; |
452 return *this; |
452 return *this; |
453 } |
453 } |
454 |
454 |
455 private: |
455 private: |
456 |
456 |
1166 /// Sets the heap and the cross reference used by algorithm. |
1166 /// Sets the heap and the cross reference used by algorithm. |
1167 /// If you don't use this function before calling \ref run(), |
1167 /// If you don't use this function before calling \ref run(), |
1168 /// it will allocate one. The destuctor deallocates this |
1168 /// it will allocate one. The destuctor deallocates this |
1169 /// automatically allocated heap and cross reference, of course. |
1169 /// automatically allocated heap and cross reference, of course. |
1170 /// \return <tt> (*this) </tt> |
1170 /// \return <tt> (*this) </tt> |
1171 NagamochiIbaraki &heap(Heap& heap, HeapCrossRef &crossRef) |
1171 NagamochiIbaraki &heap(Heap& hp, HeapCrossRef &cr) |
1172 { |
1172 { |
1173 if (local_heap_cross_ref) { |
1173 if (local_heap_cross_ref) { |
1174 delete _heap_cross_ref; |
1174 delete _heap_cross_ref; |
1175 local_heap_cross_ref=false; |
1175 local_heap_cross_ref=false; |
1176 } |
1176 } |
1177 _heap_cross_ref = &crossRef; |
1177 _heap_cross_ref = &cr; |
1178 if (local_heap) { |
1178 if (local_heap) { |
1179 delete _heap; |
1179 delete _heap; |
1180 local_heap=false; |
1180 local_heap=false; |
1181 } |
1181 } |
1182 _heap = &heap; |
1182 _heap = &hp; |
1183 return *this; |
1183 return *this; |
1184 } |
1184 } |
1185 |
1185 |
1186 /// \brief Sets the aux graph. |
1186 /// \brief Sets the aux graph. |
1187 /// |
1187 /// |
1370 |
1371 |
1371 typename AuxGraph::template NodeMap<UEdge> edges(*_aux_graph, INVALID); |
1372 typename AuxGraph::template NodeMap<UEdge> edges(*_aux_graph, INVALID); |
1372 for (typename Ufe::ClassIt c(ufe); c != INVALID; ++c) { |
1373 for (typename Ufe::ClassIt c(ufe); c != INVALID; ++c) { |
1373 if (ufe.size(c) == 1) continue; |
1374 if (ufe.size(c) == 1) continue; |
1374 for (typename Ufe::ItemIt r(ufe, c); r != INVALID; ++r) { |
1375 for (typename Ufe::ItemIt r(ufe, c); r != INVALID; ++r) { |
1375 if ((Node)r == (Node)c) continue; |
1376 if (static_cast<Node>(r) == static_cast<Node>(c)) continue; |
1376 _next->set((*_last)[c], (*_first)[r]); |
1377 _next->set((*_last)[c], (*_first)[r]); |
1377 _last->set(c, (*_last)[r]); |
1378 _last->set(c, (*_last)[r]); |
1378 remnodes.push_back(r); |
1379 remnodes.push_back(r); |
1379 --_node_num; |
1380 --_node_num; |
1380 } |
1381 } |
1405 info.capacity = (*_aux_capacity)[e]; |
1406 info.capacity = (*_aux_capacity)[e]; |
1406 addedges.push_back(info); |
1407 addedges.push_back(info); |
1407 remedges.push_back(e); |
1408 remedges.push_back(e); |
1408 } |
1409 } |
1409 |
1410 |
1410 for (int i = 0; i < (int)remedges.size(); ++i) { |
1411 for (int i = 0; i < int(remedges.size()); ++i) { |
1411 _aux_graph->erase(remedges[i]); |
1412 _aux_graph->erase(remedges[i]); |
1412 } |
1413 } |
1413 |
1414 |
1414 sort(addedges.begin(), addedges.end(), EdgeInfoLess()); |
1415 sort(addedges.begin(), addedges.end(), EdgeInfoLess()); |
1415 |
1416 |
1416 { |
1417 { |
1417 int i = 0; |
1418 int i = 0; |
1418 while (i < (int)addedges.size()) { |
1419 while (i < int(addedges.size())) { |
1419 Node sn = addedges[i].source; |
1420 Node sn = addedges[i].source; |
1420 Node tn = addedges[i].target; |
1421 Node tn = addedges[i].target; |
1421 Value ec = addedges[i].capacity; |
1422 Value ec = addedges[i].capacity; |
1422 ++i; |
1423 ++i; |
1423 while (i < (int)addedges.size() && |
1424 while (i < int(addedges.size()) && |
1424 sn == addedges[i].source && tn == addedges[i].target) { |
1425 sn == addedges[i].source && tn == addedges[i].target) { |
1425 ec += addedges[i].capacity; |
1426 ec += addedges[i].capacity; |
1426 ++i; |
1427 ++i; |
1427 } |
1428 } |
1428 typename AuxGraph::UEdge ne = _aux_graph->addEdge(sn, tn); |
1429 typename AuxGraph::UEdge ne = _aux_graph->addEdge(sn, tn); |
1498 /// It sets the nodes of one of the two partitions to true in |
1499 /// It sets the nodes of one of the two partitions to true in |
1499 /// the given BoolNodeMap. The map contains a valid cut if the |
1500 /// the given BoolNodeMap. The map contains a valid cut if the |
1500 /// map have been set false previously. |
1501 /// map have been set false previously. |
1501 template <typename NodeMap> |
1502 template <typename NodeMap> |
1502 Value quickMinCut(NodeMap& nodeMap) const { |
1503 Value quickMinCut(NodeMap& nodeMap) const { |
1503 for (int i = 0; i < (int)_cut.size(); ++i) { |
1504 for (int i = 0; i < int(_cut.size()); ++i) { |
1504 nodeMap.set(_cut[i], true); |
1505 nodeMap.set(_cut[i], true); |
1505 } |
1506 } |
1506 return minCut(); |
1507 return minCut(); |
1507 } |
1508 } |
1508 |
1509 |