53 delete[] chain->
label;
59 : nbLabelledLayers( 0 )
64 , labelPositionCost( nullptr )
66 , featStartId( nullptr )
68 , inactiveCost( nullptr )
79 candidates =
new RTree<LabelPosition*, double, 2, double>();
80 candidates_sol =
new RTree<LabelPosition*, double, 2, double>();
81 candidates_subsol =
nullptr;
100 qDeleteAll( mLabelPositions );
101 mLabelPositions.clear();
104 delete[] inactiveCost;
107 delete candidates_sol;
109 if ( candidates_subsol )
111 delete candidates_subsol;
124 return ( reinterpret_cast< SubPart* >( l ) )->borderSize > (
reinterpret_cast< SubPart*
>( r ) )->borderSize;
138 bool *ok =
new bool[nblp];
141 for ( i = 0; i < nblp; i++ )
152 for ( i = 0; i < nbft; i++ )
155 for ( j = 0; j < featNbLp[i]; j++ )
157 if ( !ok[featStartId[i] + j] )
159 if ( mLabelPositions.at( featStartId[i] + j )->getNumOverlaps() == 0 )
162 ok[featStartId[i] + j] =
true;
165 counter += featNbLp[i] - j - 1;
167 for ( k = j + 1; k < featNbLp[i]; k++ )
170 lpid = featStartId[i] + k;
172 lp2 = mLabelPositions.at( lpid );
189 this->nblp -= counter;
205 sol->
s =
new int[nbft];
207 for ( i = 0; i < nbft; i++ )
243 context->
list = list;
266 RTree <LabelPosition*, double, 2, double> *candidates = context->
candidates;
295 context->
list = list;
299 for ( i = 0; i < nbft; i++ )
300 for ( j = 0; j < featNbLp[i]; j++ )
302 label = featStartId[i] + j;
305 list->
insert( label, mLabelPositions.at( label )->getNumOverlaps() );
315 if (
pal->isCancelled() )
325 lp = mLabelPositions.at( label );
327 if ( lp->
getId() != label )
333 sol->
s[probFeatId] = label;
335 for ( i = featStartId[probFeatId]; i < featStartId[probFeatId] + featNbLp[probFeatId]; i++ )
337 ignoreLabel( mLabelPositions.at( i ), list, candidates );
344 candidates->Search( amin, amax,
falpCallback1, reinterpret_cast< void* >( context ) );
345 candidates_sol->Insert( amin, amax, lp );
360 for ( i = 0; i < nbft; i++ )
362 if ( sol->
s[i] == -1 )
365 start_p = featStartId[i];
366 for ( p = 0; p < featNbLp[i]; p++ )
368 lp = mLabelPositions.at( start_p + p );
382 sol->
s[i] = retainedLabel->
getId();
401 bool *ok =
new bool[nbft];
403 int r =
pal->popmusic_r;
407 candidates_subsol =
new RTree<LabelPosition*, double, 2, double>();
415 labelPositionCost =
new double[all_nblp];
416 nbOlap =
new int[all_nblp];
418 featWrap =
new int[nbft];
419 memset( featWrap, -1,
sizeof(
int ) *nbft );
422 int *isIn =
new int[nbft];
424 memset( isIn, 0,
sizeof(
int ) *nbft );
427 for ( i = 0; i < nbft; i++ )
429 parts[i] =
subPart( r, i, isIn );
447 for ( i = ( seed + 1 ) % nbft; ok[i] && i !=
seed; i = ( i + 1 ) % nbft )
450 if ( i == seed && ok[seed] )
458 current = parts[
seed];
462 candidates_subsol->RemoveAll();
464 for ( i = 0; i < current->
subSize; i++ )
466 current->
sol[i] = sol->
s[current->
sub[i]];
467 if ( current->
sol[i] != -1 )
469 mLabelPositions.at( current->
sol[i] )->insertIntoIndex( candidates_subsol );
473 switch ( searchMethod )
501 ok[current->
sub[i]] =
false;
504 for ( i = current->
borderSize; i < current->subSize; i++ )
507 if ( sol->
s[current->
sub[i]] != -1 )
509 mLabelPositions.at( sol->
s[current->
sub[i]] )->removeFromIndex( candidates_sol );
512 sol->
s[current->
sub[i]] = current->
sol[i];
514 if ( current->
sol[i] != -1 )
516 mLabelPositions.at( current->
sol[i] )->insertIntoIndex( candidates_sol );
519 ok[current->
sub[i]] =
false;
530 delete[] labelPositionCost;
533 for ( i = 0; i < nbft; i++ )
535 delete[] parts[i]->
sub;
536 delete[] parts[i]->
sol;
556 int *isIn = context->
isIn;
590 context.
queue = queue;
593 queue->
append( featseed );
603 featS = featStartId[id];
606 for ( i = featS; i < featS + p; i++ )
608 lp = mLabelPositions.at( i );
613 candidates->Search( amin, amax,
subPartCallback, reinterpret_cast< void* >( &context ) );
648 subPart->
seed = featseed;
659 context.
nbOv = nbOverlap;
660 context.
cost = &cost;
670 lp = mLabelPositions.at( label_id );
681 cost = inactiveCost[part->
sub[feat_id]];
697 for ( i = 0; i < part->
subSize; i++ )
719 return ( reinterpret_cast< Triple* >( tl ) )->cost < (
reinterpret_cast< Triple*
>( tr ) )->cost;
723 double candidateBaseFactor,
double *candidateFactor,
724 int minCandidateListSize,
double reductionFactor,
725 int minTabuTSize,
double tabuFactor,
int *tenure,
int n )
728 if ( *candidateFactor > candidateBaseFactor )
729 *candidateFactor /= reductionFactor;
731 if ( iteration % m == 0 )
733 *tenure = minTabuTSize +
static_cast< int >( tabuFactor * nbOverlap );
734 *candidateListSize = minCandidateListSize +
static_cast< int >( *candidateFactor * nbOverlap );
736 if ( *candidateListSize > n )
737 *candidateListSize = n;
744 double *candidateFactor,
int minCandidateListSize,
double growingFactor,
int n )
747 candidateBaseFactor += 0;
749 if ( *candidateListSize < n )
750 *candidateFactor = *candidateFactor * growingFactor;
751 *candidateListSize = minCandidateListSize +
static_cast< int >( *candidateFactor * nbOverlap );
753 if ( *candidateListSize > n )
754 *candidateListSize = n;
786 if ( feat_id >= 0 && ctx->
sol[feat_id] == lp->
getId() )
788 if (( feat_id2 = feat_id - ctx->
borderSize ) >= 0 )
806 int *sub = part->
sub;
807 int *sol = part->
sol;
812 int * best_sol =
new int[subSize];
818 int *tabu_list =
new int[probSize];
848 int minTabuTSize = 9;
849 double tabuFactor = 0.5;
851 int minCandidateListSize = 18;
853 double candidateBaseFactor = 0.73;
855 double growingFactor = 15;
856 double reductionFactor = 1.3;
858 int candidateListSize = minCandidateListSize;
859 double candidateFactor = candidateBaseFactor;
865 max_it = probSize *
pal->tabuMaxIt;
866 itwImp = probSize *
pal->tabuMinIt;
874 for ( i = 0; i < subSize; i++ )
875 featWrap[sub[i]] = i;
877 for ( i = 0; i < subSize; i++ )
879 j = featStartId[sub[i]];
880 for ( lp = 0; lp < featNbLp[sub[i]]; lp++ )
887 first_lp = ( displayAll ? 0 : -1 );
888 for ( i = 0; i < probSize; i++ )
893 candidateList[i] =
new Triple();
894 candidateList[i]->
feat_id = i + borderSize;
895 candidateList[i]->
label_id = sol[i+borderSize];
897 candidateListUnsorted[i] = candidateList[i];
899 if ( sol[i+borderSize] >= 0 )
901 j = sol[i+borderSize];
902 candidateList[i]->
cost = labelPositionCost[j];
907 candidateList[i]->
cost = inactiveCost[sub[i+borderSize]];
914 for ( i = 0; i < subSize; i++ )
918 cur_cost += inactiveCost[sub[i]];
922 nbOverlap += nbOlap[sol[i]];
923 cur_cost += labelPositionCost[sol[i]];
929 best_cost = cur_cost;
930 initial_cost = cur_cost;
931 memcpy( best_sol, sol,
sizeof(
int ) *( subSize ) );
936 while ( it < stop_it && best_cost >=
EPSILON )
938 actualizeTabuCandidateList( m, it, nbOverlap, &candidateListSize, candidateBaseFactor, &candidateFactor, minCandidateListSize, reductionFactor, minTabuTSize, tabuFactor, &tenure, probSize );
945 for ( i = 0; i < candidateListSize; i++ )
947 feat_id = candidateList[i]->
feat_id;
948 feat_sub_id = sub[feat_id];
949 label_id = candidateList[i]->
label_id;
951 int oldPos = ( label_id < 0 ? -1 : label_id - featStartId[feat_sub_id] );
954 p = featNbLp[feat_sub_id];
958 for ( j = first_lp; j < p; j++ )
963 if ( sol[feat_id] < 0 )
965 delta = -inactiveCost[feat_sub_id];
969 delta = -labelPositionCost[sol[feat_id]];
970 delta -= nbOlap[sol[feat_id]] * ( inactiveCost[feat_sub_id] + mLabelPositions.at( label_id )->cost() );
975 delta += labelPositionCost[featStartId[feat_sub_id] + j];
976 delta += nbOlap[featStartId[feat_sub_id] + j] * ( inactiveCost[feat_sub_id] + mLabelPositions.at( featStartId[feat_sub_id] + j )->cost() );
980 delta += inactiveCost[feat_sub_id];
984 authorized = ( tabu_list[feat_id - borderSize] <= it ) || ( cur_cost + delta < best_cost );
986 if ( delta < delta_min && authorized )
988 choosed_feat = feat_id;
993 choosed_label = featStartId[feat_sub_id] + j;
1003 if ( choosed_feat >= 0 )
1006 int old_label = sol[choosed_feat];
1008 tabu_list[choosed_feat-borderSize] = it + tenure;
1009 sol[choosed_feat] = choosed_label;
1010 candidateList[candidateId]->
label_id = choosed_label;
1012 if ( old_label != -1 )
1013 mLabelPositions.at( old_label )->removeFromIndex( candidates_subsol );
1016 double local_inactive = inactiveCost[sub[choosed_feat]];
1018 if ( choosed_label != -1 )
1020 candidateList[candidateId]->
cost = labelPositionCost[choosed_label];
1021 candidateList[candidateId]->
nbOverlap = nbOlap[choosed_label];
1025 candidateList[candidateId]->
cost = local_inactive;
1026 candidateList[candidateId]->
nbOverlap = 1;
1029 cur_cost += delta_min;
1044 if ( old_label >= 0 )
1046 lp = mLabelPositions.at( old_label );
1056 if ( choosed_label >= 0 )
1058 lp = mLabelPositions.at( choosed_label );
1073 if ( best_cost - cur_cost >
EPSILON )
1075 best_cost = cur_cost;
1076 memcpy( best_sol, sol,
sizeof(
int ) *( subSize ) );
1077 stop_it = it + itwImp;
1078 if ( stop_it > max_it )
1086 &candidateFactor, minCandidateListSize, growingFactor, probSize );
1091 memcpy( sol, best_sol,
sizeof(
int ) *( subSize ) );
1093 for ( i = 0; i < subSize; i++ )
1094 featWrap[sub[i]] = -1;
1096 for ( i = 0; i < probSize; i++ )
1097 delete candidateList[i];
1099 delete[] candidateList;
1100 delete[] candidateListUnsorted;
1105 return initial_cost - best_cost;
1134 bool sub =
nullptr != ctx->
featWrap;
1145 if ( feat >= 0 && ctx->
tmpsol[feat] == lp->
getId() )
1147 if ( sub && feat < ctx->borderSize )
1157 if (( *cur )->feat == feat )
1183 int *sub = part->
sub;
1184 int *sol = part->
sol;
1189 double delta_best = DBL_MAX;
1194 Chain *retainedChain =
nullptr;
1196 int max_degree =
pal->ejChainDeg;
1203 int *tmpsol =
new int[subSize];
1204 memcpy( tmpsol, sol,
sizeof(
int ) *subSize );
1215 context.
feat =
nullptr;
1221 while ( seed != -1 )
1223 subseed = sub[
seed];
1224 seedNbLp = featNbLp[subseed];
1225 delta_min = DBL_MAX;
1230 if ( tmpsol[seed] == -1 )
1231 delta -= inactiveCost[subseed];
1233 delta -= mLabelPositions.at( tmpsol[seed] )->cost();
1236 for ( i = -1; i < seedNbLp; i++ )
1241 if ( !( tmpsol[seed] == -1 && i == -1 ) && i + featStartId[subseed] != tmpsol[seed] )
1245 lid = featStartId[subseed] + i;
1248 lp = mLabelPositions.at( lid );
1256 candidates_subsol->Search( amin, amax,
chainCallback, reinterpret_cast< void* >( &context ) );
1261 if ( !retainedChain || delta + lp->
cost() < delta_best )
1264 if ( retainedChain )
1266 delete[] retainedChain->
label;
1267 delete[] retainedChain->
feat;
1271 retainedChain =
new Chain();
1274 delta_best = delta + lp->
cost();
1276 retainedChain->
degree = currentChain->
size() + 1;
1277 retainedChain->
feat =
new int[retainedChain->
degree];
1278 retainedChain->
label =
new int[retainedChain->
degree];
1282 while ( current != currentChain->
end() )
1285 retainedChain->
feat[j] = move->
feat;
1291 retainedChain->
label[j] = lid;
1292 retainedChain->
delta = delta + mLabelPositions.at( retainedChain->
label[j] )->cost();
1297 else if ( conflicts->
size() == 1 )
1299 if ( delta_tmp < delta_min )
1301 delta_min = delta_tmp;
1302 retainedLabel = lid;
1321 while ( current != currentChain->
end() )
1331 newChain->
label[j] = lid;
1332 newChain->
delta = delta + mLabelPositions.at( newChain->
label[j] )->cost();
1336 while ( !conflicts->
isEmpty() )
1339 newChain->
feat[j] = ftid;
1340 newChain->
label[j] = -1;
1341 newChain->
delta += inactiveCost[sub[ftid]];
1345 if ( newChain->
delta < delta_best )
1347 if ( retainedChain )
1350 delta_best = newChain->
delta;
1351 retainedChain = newChain;
1361 if ( !retainedChain || delta + inactiveCost[subseed] < delta_best )
1363 if ( retainedChain )
1365 delete[] retainedChain->
label;
1366 delete[] retainedChain->
feat;
1369 retainedChain =
new Chain();
1371 delta_best = delta + inactiveCost[subseed];
1373 retainedChain->
degree = currentChain->
size() + 1;
1374 retainedChain->
feat =
new int[retainedChain->
degree];
1375 retainedChain->
label =
new int[retainedChain->
degree];
1379 while ( current != currentChain->
end() )
1382 retainedChain->
feat[j] = move->
feat;
1388 retainedChain->
label[j] = -1;
1389 retainedChain->
delta = delta + inactiveCost[subseed];
1401 if ( next_seed == -1 )
1405 else if ( currentChain->
size() > max_degree )
1415 currentChain->
append( et );
1419 mLabelPositions.at( et->
old_label )->removeFromIndex( candidates_subsol );
1424 mLabelPositions.at( et->
new_label )->insertIntoIndex( candidates_subsol );
1427 tmpsol[
seed] = retainedLabel;
1428 delta += mLabelPositions.at( retainedLabel )->cost();
1433 while ( !currentChain->
isEmpty() )
1439 mLabelPositions.at( et->
new_label )->removeFromIndex( candidates_subsol );
1444 mLabelPositions.at( et->
old_label )->insertIntoIndex( candidates_subsol );
1449 delete currentChain;
1455 return retainedChain;
1459 inline Chain *Problem::chain(
int seed )
1469 double delta_best = DBL_MAX;
1474 Chain *retainedChain =
nullptr;
1476 int max_degree =
pal->ejChainDeg;
1483 int *tmpsol =
new int[nbft];
1484 memcpy( tmpsol, sol->s,
sizeof(
int ) *nbft );
1495 context.
feat =
nullptr;
1501 while ( seed != -1 )
1503 seedNbLp = featNbLp[
seed];
1504 delta_min = DBL_MAX;
1510 if ( tmpsol[seed] == -1 )
1511 delta -= inactiveCost[
seed];
1513 delta -= mLabelPositions.at( tmpsol[seed] )->cost();
1515 for ( i = -1; i < seedNbLp; i++ )
1520 if ( !( tmpsol[seed] == -1 && i == -1 ) && i + featStartId[seed] != tmpsol[seed] )
1524 lid = featStartId[
seed] + i;
1527 lp = mLabelPositions.at( lid );
1534 candidates_sol->Search( amin, amax,
chainCallback, reinterpret_cast< void* >( &context ) );
1539 if ( !retainedChain || delta + lp->
cost() < delta_best )
1541 if ( retainedChain )
1543 delete[] retainedChain->
label;
1544 delete[] retainedChain->
feat;
1548 retainedChain =
new Chain();
1551 delta_best = delta + lp->
cost();
1553 retainedChain->
degree = currentChain->
size() + 1;
1554 retainedChain->
feat =
new int[retainedChain->
degree];
1555 retainedChain->
label =
new int[retainedChain->
degree];
1559 while ( current != currentChain->
end() )
1562 retainedChain->
feat[j] = move->
feat;
1568 retainedChain->
label[j] = lid;
1569 retainedChain->
delta = delta + lp->
cost();
1574 else if ( conflicts->
size() == 1 )
1576 if ( delta_tmp < delta_min )
1578 delta_min = delta_tmp;
1579 retainedLabel = lid;
1599 while ( current != currentChain->
end() )
1610 newChain->
label[j] = lid;
1611 newChain->
delta = delta + mLabelPositions.at( newChain->
label[j] )->cost();
1615 while ( !conflicts->
isEmpty() )
1618 newChain->
feat[j] = ftid;
1619 newChain->
label[j] = -1;
1620 newChain->
delta += inactiveCost[ftid];
1624 if ( newChain->
delta < delta_best )
1626 if ( retainedChain )
1629 delta_best = newChain->
delta;
1630 retainedChain = newChain;
1641 if ( !retainedChain || delta + inactiveCost[seed] < delta_best )
1643 if ( retainedChain )
1645 delete[] retainedChain->
label;
1646 delete[] retainedChain->
feat;
1649 retainedChain =
new Chain();
1651 delta_best = delta + inactiveCost[
seed];
1653 retainedChain->
degree = currentChain->
size() + 1;
1654 retainedChain->
feat =
new int[retainedChain->
degree];
1655 retainedChain->
label =
new int[retainedChain->
degree];
1659 while ( current != currentChain->
end() )
1662 retainedChain->
feat[j] = move->
feat;
1668 retainedChain->
label[j] = -1;
1669 retainedChain->
delta = delta + inactiveCost[
seed];
1681 if ( next_seed == -1 )
1685 else if ( currentChain->
size() > max_degree )
1696 currentChain->
append( et );
1700 mLabelPositions.at( et->
old_label )->removeFromIndex( candidates_sol );
1705 mLabelPositions.at( et->
new_label )->insertIntoIndex( candidates_sol );
1709 tmpsol[
seed] = retainedLabel;
1710 delta += mLabelPositions.at( retainedLabel )->cost();
1716 while ( !currentChain->
isEmpty() )
1722 mLabelPositions.at( et->
new_label )->removeFromIndex( candidates_sol );
1727 mLabelPositions.at( et->
old_label )->insertIntoIndex( candidates_sol );
1732 delete currentChain;
1738 return retainedChain;
1749 int *sub = part->
sub;
1750 int *sol = part->
sol;
1752 int *best_sol =
new int[subSize];
1754 for ( i = 0; i < subSize; i++ )
1756 featWrap[sub[i]] = i;
1757 best_sol[i] = sol[i];
1760 double initial_cost;
1761 double cur_cost = 0;
1762 double best_cost = 0;
1773 int *tabu_list =
new int[subSize];
1775 Chain *current_chain =
nullptr;
1784 int tenure =
pal->tenure;
1786 for ( i = 0; i < subSize; i++ )
1792 initial_cost = cur_cost;
1793 best_cost = cur_cost;
1797 maxit = probSize *
pal->tabuMaxIt;
1799 itwimp = probSize *
pal->tabuMinIt;
1804 for ( i = 0; i < borderSize; i++ )
1805 tabu_list[i] = maxit;
1807 for ( i = 0; i < probSize; i++ )
1808 tabu_list[i+borderSize] = -1;
1810 while ( it < stop_it )
1812 seed = ( it % probSize ) + borderSize;
1814 current_chain = chain( part, seed );
1815 if ( current_chain )
1820 if ( tabu_list[seed] < it || ( cur_cost + current_chain->
delta ) - best_cost < 0.0 )
1823 for ( i = 0; i < current_chain->
degree; i++ )
1825 fid = current_chain->
feat[i];
1826 lid = current_chain->
label[i];
1828 if ( sol[fid] >= 0 )
1830 mLabelPositions.at( sol[fid] )->removeFromIndex( candidates_subsol );
1834 if ( sol[fid] >= 0 )
1836 mLabelPositions.at( lid )->insertIntoIndex( candidates_subsol );
1839 tabu_list[fid] = it + tenure;
1842 cur_cost += current_chain->
delta;
1845 if ( best_cost - cur_cost >
EPSILON )
1847 best_cost = cur_cost;
1848 memcpy( best_sol, sol,
sizeof(
int ) *subSize );
1850 stop_it = ( it + itwimp > maxit ? maxit : it + itwimp );
1858 memcpy( sol, best_sol,
sizeof(
int ) *subSize );
1878 for ( i = 0; i < subSize; i++ )
1879 featWrap[sub[i]] = -1;
1885 return initial_cost - best_cost;
1895 int *sub = part->
sub;
1896 int *sol = part->
sol;
1898 int *best_sol =
new int[subSize];
1900 for ( i = 0; i < subSize; i++ )
1902 featWrap[sub[i]] = i;
1905 double initial_cost;
1906 double cur_cost = 0;
1907 double best_cost = 0;
1918 int *tabu_list =
new int[subSize];
1920 Chain *retainedChain =
nullptr;
1921 Chain *current_chain =
nullptr;
1930 int tenure =
pal->tenure;
1937 for ( i = 0; i < subSize; i++ )
1943 initial_cost = cur_cost;
1944 best_cost = cur_cost;
1948 maxit = probSize *
pal->tabuMaxIt;
1950 itwimp = probSize *
pal->tabuMinIt;
1954 for ( i = 0; i < borderSize; i++ )
1955 tabu_list[i] = maxit;
1958 for ( i = 0; i < probSize; i++ )
1960 tabu_list[i+borderSize] = -1;
1962 candidates[i] =
new Triple();
1963 candidates[i]->
feat_id = i + borderSize;
1964 candidatesUnsorted[i] = candidates[i];
1966 candidates[i]->
cost = ( sol[i+borderSize] == -1 ? inactiveCost[i+borderSize] : mLabelPositions.at( sol[i+borderSize] )->cost() );
1971 int candidateListSize;
1972 candidateListSize = int (
pal->candListSize * static_cast< double >( probSize ) + 0.5 );
1974 if ( candidateListSize > probSize )
1975 candidateListSize = probSize;
1977 while ( it < stop_it )
1979 retainedChain =
nullptr;
1981 for ( itC = 0; itC < candidateListSize; itC++ )
1983 seed = candidates[itC]->
feat_id;
1985 current_chain = chain( part, seed );
1987 if ( current_chain )
1990 if ( tabu_list[seed] < it || ( cur_cost + current_chain->
delta ) - best_cost < 0.0 )
1992 if ( !retainedChain )
1994 retainedChain = current_chain;
1999 retainedChain = current_chain;
2013 if ( retainedChain )
2015 for ( i = 0; i < retainedChain->
degree; i++ )
2017 fid = retainedChain->
feat[i];
2018 lid = retainedChain->
label[i];
2020 if ( sol[fid] >= 0 )
2021 mLabelPositions.at( sol[fid] )->removeFromIndex( candidates_subsol );
2026 mLabelPositions.at( lid )->insertIntoIndex( candidates_subsol );
2028 tabu_list[fid] = it + tenure;
2029 candidatesUnsorted[fid-borderSize]->
cost = ( lid == -1 ? inactiveCost[sub[fid]] : mLabelPositions.at( lid )->cost() );
2033 cur_cost += retainedChain->
delta;
2037 if ( best_cost - cur_cost >
EPSILON )
2039 best_cost = cur_cost;
2040 memcpy( best_sol, sol,
sizeof(
int ) * subSize );
2042 stop_it = ( it + itwimp > maxit ? maxit : it + itwimp );
2049 memcpy( sol, best_sol,
sizeof(
int ) *subSize );
2051 for ( i = 0; i < probSize; i++ )
2052 delete candidates[i];
2054 delete[] candidates;
2055 delete[] candidatesUnsorted;
2057 for ( i = 0; i < subSize; i++ )
2058 featWrap[sub[i]] = -1;
2064 return initial_cost - best_cost;
2076 void Problem::check_solution()
2078 int *solution =
new int[nbft];
2090 candidates_sol->Search( amin, amax,
checkCallback, reinterpret_cast< void* >( list ) );
2094 for ( i = 0; i < nbft; i++ )
2097 if ( sol->s[i] >= 0 )
2101 if ( list->
size() != nbActive )
2111 solution[probFeatId] = lp->
getId();
2129 int *wrap = ctx->
wrap;
2154 bool *ok =
new bool[nbft];
2163 context.
wrap =
nullptr;
2165 Chain *retainedChain;
2169 for ( i = 0; i < nbft; i++ )
2187 for ( seed = ( iter + 1 ) % nbft;
2188 ok[
seed] && seed != iter;
2189 seed = ( seed + 1 ) % nbft )
2198 iter = ( iter + 1 ) % nbft;
2199 retainedChain = chain( seed );
2201 if ( retainedChain && retainedChain->
delta < -
EPSILON )
2204 for ( i = 0; i < retainedChain->
degree; i++ )
2206 fid = retainedChain->
feat[i];
2207 lid = retainedChain->
label[i];
2209 if ( sol->s[fid] >= 0 )
2217 candidates->Search( amin, amax,
nokCallback, &context );
2222 if ( sol->s[fid] >= 0 )
2229 sol->cost += retainedChain->
delta;
2263 for ( i = 0; i < nbft; i++ )
2265 if ( sol->s[i] != -1 )
2267 solList->
push_back( mLabelPositions.at( sol->s[i] ) );
2269 else if ( returnInactive
2270 || mLabelPositions.at( featStartId[i] )->getFeaturePart()->layer()->displayAll()
2271 || mLabelPositions.at( featStartId[i] )->getFeaturePart()->alwaysShow() )
2273 solList->
push_back( mLabelPositions.at( featStartId[i] ) );
2278 if ( returnInactive )
2292 stats->nbObjects = nbft;
2293 stats->nbLabelledObjects = 0;
2295 stats->nbLayers = nbLabelledLayers;
2296 stats->layersNbObjects =
new int[stats->nbLayers];
2297 stats->layersNbLabelledObjects =
new int[stats->nbLayers];
2299 for ( i = 0; i < stats->nbLayers; i++ )
2301 stats->layersName << labelledLayersName[i];
2302 stats->layersNbObjects[i] = 0;
2303 stats->layersNbLabelledObjects[i] = 0;
2308 for ( i = 0; i < nbft; i++ )
2310 lyrName = mLabelPositions.
at( featStartId[i] )->getFeaturePart()->feature()->provider()->name();
2312 for ( j = 0; j < stats->nbLayers; j++ )
2314 if ( lyrName == stats->layersName[j] )
2322 stats->layersNbObjects[k]++;
2323 if ( sol->s[i] >= 0 )
2325 stats->layersNbLabelledObjects[k]++;
2326 stats->nbLabelledObjects++;
2338 void Problem::solution_cost()
2349 context.
nbOv = &nbOv;
2350 context.
cost = &sol->cost;
2357 for ( i = 0; i < nbft; i++ )
2359 if ( sol->s[i] == -1 )
2361 sol->
cost += inactiveCost[i];
2367 lp = mLabelPositions.at( sol->s[i] );
bool isInConflict(LabelPosition *ls)
Check whether or not this overlap with another labelPosition.
double popmusic_chain(SubPart *part)
POPMUSIC, chain.
bool borderSizeInc(void *l, void *r)
static bool compareLabelArea(pal::LabelPosition *l1, pal::LabelPosition *l2)
void push_back(const T &value)
double compute_feature_cost(SubPart *part, int feat_id, int label_id, int *nbOverlap)
void getBoundingBox(double amin[2], double amax[2]) const
Return bounding box - amin: xmin,ymin - amax: xmax,ymax.
int probSize
of features in problem
RTree< LabelPosition *, double, 2, double > * candidates
bool subPartCallback(LabelPosition *lp, void *ctx)
QLinkedList< int > * queue
Thrown when something is added in a Full set.
bool chainCallback(LabelPosition *lp, void *context)
is slower and best than TABU, worse and faster than TABU_CHAIN
bool checkCallback(LabelPosition *lp, void *ctx)
struct _nokContext NokContext
static bool countFullOverlapCallback(LabelPosition *lp, void *ctx)
int getProblemFeatureId() const
struct pal::_elementary_transformation ElemTrans
static bool removeOverlapCallback(LabelPosition *lp, void *ctx)
is a little bit better than CHAIN but slower
bool falpCallback1(LabelPosition *lp, void *ctx)
bool updateCandidatesCost(LabelPosition *lp, void *context)
double cost() const
Returns the candidate label position's geographical cost.
void chain_search()
Test with very-large scale neighborhood.
QList< LabelPosition * > * getSolution(bool returnInactive)
SubPart * subPart(int r, int featseed, int *isIn)
void seed(uint32_t value)
static void sort(void **items, int N, bool(*greater)(void *l, void *r))
Sort an array of pointers.
void insertIntoIndex(RTree< LabelPosition *, double, 2, double > *index)
double popmusic_tabu(SubPart *part)
bool nokCallback(LabelPosition *lp, void *context)
void actualizeCandidateList(int nbOverlap, int *candidateListSize, double candidateBaseFactor, double *candidateFactor, int minCandidateListSize, double growingFactor, int n)
void actualizeTabuCandidateList(int m, int iteration, int nbOverlap, int *candidateListSize, double candidateBaseFactor, double *candidateFactor, int minCandidateListSize, double reductionFactor, int minTabuTSize, double tabuFactor, int *tenure, int n)
void insert(int key, double p)
void popmusic()
popmusic framework
void removeFromIndex(RTree< LabelPosition *, double, 2, double > *index)
double * labelPositionCost
int getId() const
return id
struct pal::_subpart SubPart
int * sub
wrap bw sub feat and main feat
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
double compute_subsolution_cost(SubPart *part, int *s, int *nbOverlap)
int getNumOverlaps() const
void delete_chain(Chain *chain)
const QChar at(int position) const
QLinkedList< int > * conflicts
int subSize
total # features (prob + border)
Summary statistics of labelling problem.
void ignoreLabel(LabelPosition *lp, PriorityQueue *list, RTree< LabelPosition *, double, 2, double > *candidates)
LabelPosition is a candidate feature label position.
QLinkedList< ElemTrans * > * currentChain
bool decreaseCost(void *tl, void *tr)
bool falpCallback2(LabelPosition *lp, void *ctx)
SearchMethod
Search method to use.
int borderSize
of features bounding the problem
double popmusic_tabu_chain(SubPart *part)
POPMUSIC, Tabu search with chain'.
void init_sol_empty()
Basic initial solution : every feature to -1.
bool contains(const T &value) const
void append(const T &value)
int seed
first feat in sub part
void decreaseKey(int key)