| ... | ... |
@@ -886,49 +886,49 @@ |
| 886 | 886 |
} |
| 887 | 887 |
} |
| 888 | 888 |
|
| 889 | 889 |
return OPTIMAL; |
| 890 | 890 |
} |
| 891 | 891 |
|
| 892 | 892 |
// Execute the algorithm and transform the results |
| 893 | 893 |
void start(Method method) {
|
| 894 | 894 |
// Maximum path length for partial augment |
| 895 | 895 |
const int MAX_PATH_LENGTH = 4; |
| 896 | 896 |
|
| 897 | 897 |
// Initialize data structures for buckets |
| 898 | 898 |
_max_rank = _alpha * _res_node_num; |
| 899 | 899 |
_buckets.resize(_max_rank); |
| 900 | 900 |
_bucket_next.resize(_res_node_num + 1); |
| 901 | 901 |
_bucket_prev.resize(_res_node_num + 1); |
| 902 | 902 |
_rank.resize(_res_node_num + 1); |
| 903 | 903 |
|
| 904 | 904 |
// Execute the algorithm |
| 905 | 905 |
switch (method) {
|
| 906 | 906 |
case PUSH: |
| 907 | 907 |
startPush(); |
| 908 | 908 |
break; |
| 909 | 909 |
case AUGMENT: |
| 910 |
startAugment(); |
|
| 910 |
startAugment(_res_node_num - 1); |
|
| 911 | 911 |
break; |
| 912 | 912 |
case PARTIAL_AUGMENT: |
| 913 | 913 |
startAugment(MAX_PATH_LENGTH); |
| 914 | 914 |
break; |
| 915 | 915 |
} |
| 916 | 916 |
|
| 917 | 917 |
// Compute node potentials for the original costs |
| 918 | 918 |
_arc_vec.clear(); |
| 919 | 919 |
_cost_vec.clear(); |
| 920 | 920 |
for (int j = 0; j != _res_arc_num; ++j) {
|
| 921 | 921 |
if (_res_cap[j] > 0) {
|
| 922 | 922 |
_arc_vec.push_back(IntPair(_source[j], _target[j])); |
| 923 | 923 |
_cost_vec.push_back(_scost[j]); |
| 924 | 924 |
} |
| 925 | 925 |
} |
| 926 | 926 |
_sgr.build(_res_node_num, _arc_vec.begin(), _arc_vec.end()); |
| 927 | 927 |
|
| 928 | 928 |
typename BellmanFord<StaticDigraph, LargeCostArcMap> |
| 929 | 929 |
::template SetDistMap<LargeCostNodeMap>::Create bf(_sgr, _cost_map); |
| 930 | 930 |
bf.distMap(_pi_map); |
| 931 | 931 |
bf.init(0); |
| 932 | 932 |
bf.start(); |
| 933 | 933 |
|
| 934 | 934 |
// Handle non-zero lower bounds |
| ... | ... |
@@ -1063,49 +1063,49 @@ |
| 1063 | 1063 |
} |
| 1064 | 1064 |
} |
| 1065 | 1065 |
} |
| 1066 | 1066 |
|
| 1067 | 1067 |
// Finish search if there are no more active nodes |
| 1068 | 1068 |
if (_excess[u] > 0) {
|
| 1069 | 1069 |
total_excess -= _excess[u]; |
| 1070 | 1070 |
if (total_excess <= 0) break; |
| 1071 | 1071 |
} |
| 1072 | 1072 |
} |
| 1073 | 1073 |
if (total_excess <= 0) break; |
| 1074 | 1074 |
} |
| 1075 | 1075 |
|
| 1076 | 1076 |
// Relabel nodes |
| 1077 | 1077 |
for (int u = 0; u != _res_node_num; ++u) {
|
| 1078 | 1078 |
int k = std::min(_rank[u], r); |
| 1079 | 1079 |
if (k > 0) {
|
| 1080 | 1080 |
_pi[u] -= _epsilon * k; |
| 1081 | 1081 |
_next_out[u] = _first_out[u]; |
| 1082 | 1082 |
} |
| 1083 | 1083 |
} |
| 1084 | 1084 |
} |
| 1085 | 1085 |
|
| 1086 | 1086 |
/// Execute the algorithm performing augment and relabel operations |
| 1087 |
void startAugment(int max_length |
|
| 1087 |
void startAugment(int max_length) {
|
|
| 1088 | 1088 |
// Paramters for heuristics |
| 1089 | 1089 |
const int EARLY_TERM_EPSILON_LIMIT = 1000; |
| 1090 | 1090 |
const double GLOBAL_UPDATE_FACTOR = 3.0; |
| 1091 | 1091 |
|
| 1092 | 1092 |
const int global_update_freq = int(GLOBAL_UPDATE_FACTOR * |
| 1093 | 1093 |
(_res_node_num + _sup_node_num * _sup_node_num)); |
| 1094 | 1094 |
int next_update_limit = global_update_freq; |
| 1095 | 1095 |
|
| 1096 | 1096 |
int relabel_cnt = 0; |
| 1097 | 1097 |
|
| 1098 | 1098 |
// Perform cost scaling phases |
| 1099 | 1099 |
std::vector<int> path; |
| 1100 | 1100 |
for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? |
| 1101 | 1101 |
1 : _epsilon / _alpha ) |
| 1102 | 1102 |
{
|
| 1103 | 1103 |
// Early termination heuristic |
| 1104 | 1104 |
if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) {
|
| 1105 | 1105 |
if (earlyTermination()) break; |
| 1106 | 1106 |
} |
| 1107 | 1107 |
|
| 1108 | 1108 |
// Initialize current phase |
| 1109 | 1109 |
initPhase(); |
| 1110 | 1110 |
|
| 1111 | 1111 |
// Perform partial augment and relabel operations |
0 comments (0 inline)