Skip to content

Commit

Permalink
[pal] Remove calculation of total solution cost which was done
Browse files Browse the repository at this point in the history
before solving labeling and once after solving labeling, yet
was never retrieved anywhere

This is a non-trival cost to calculate, involving spatial index
lookups for every label to determine if it is in conflict. Removing
the unused calculation saves a significant amount of time from the
label placement routine!
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Jan 7, 2022
1 parent a9c699a commit a97b693
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
46 changes: 1 addition & 45 deletions src/core/pal/problem.cpp
Expand Up @@ -580,22 +580,15 @@ void Problem::chain_search()

std::fill( ok, ok + mFeatureCount, false );

//initialization();
init_sol_falp();

//check_solution();
solution_cost();

int iter = 0;

double amin[2];
double amax[2];

while ( true )
{

//check_solution();

for ( seed = ( iter + 1 ) % mFeatureCount;
ok[seed] && seed != iter;
seed = ( seed + 1 ) % mFeatureCount )
Expand Down Expand Up @@ -643,19 +636,17 @@ void Problem::chain_search()

ok[fid] = false;
}
mSol.totalCost += retainedChain->delta;
}
else
{
// no chain or the one is not god enough
// no chain or the one is not good enough
ok[seed] = true;
}

delete_chain( retainedChain );
popit++;
}

solution_cost();
delete[] ok;
}

Expand Down Expand Up @@ -699,38 +690,3 @@ QList<LabelPosition *> Problem::getSolution( bool returnInactive, QList<LabelPos

return finalLabelPlacements;
}

void Problem::solution_cost()
{
mSol.totalCost = 0.0;

LabelPosition *lp = nullptr;

double amin[2];
double amax[2];

for ( std::size_t i = 0; i < mFeatureCount; i++ )
{
if ( mSol.activeLabelIds[i] == -1 )
{
mSol.totalCost += mInactiveCost[i];
}
else
{
lp = mLabelPositions[ mSol.activeLabelIds[i] ].get();

lp->getBoundingBox( amin, amax );
mActiveCandidatesIndex.intersects( QgsRectangle( amin[0], amin[1], amax[0], amax[1] ), [&lp, this]( const LabelPosition * lp2 )->bool
{
if ( candidatesAreConflicting( lp, lp2 ) )
{
mSol.totalCost += mInactiveCost[lp2->getProblemFeatureId()] + lp2->cost();
}

return true;
} );

mSol.totalCost += lp->cost();
}
}
}
3 changes: 0 additions & 3 deletions src/core/pal/problem.h
Expand Up @@ -214,12 +214,9 @@ namespace pal
//! Placeholder list for active labels. Will contain label id for active labels, or -1 for empty positions in list
std::vector< int > activeLabelIds;

double totalCost = 0;

void init( std::size_t featureCount )
{
activeLabelIds.resize( featureCount, -1 );
totalCost = 0;
}
};

Expand Down

0 comments on commit a97b693

Please sign in to comment.