mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-18 16:09:18 +00:00
connectivity: TOPO_MATCH now orders reference components by the lowest matching candidate count.
This heuristic seems to make the algorithm reject non-isomorphic mappings much earlier on and converges faster on a solution for typical circuits.
This commit is contained in:
parent
91ee987cfe
commit
8192ba73d9
@ -399,10 +399,68 @@ CONNECTION_GRAPH::STATUS CONNECTION_GRAPH::FindIsomorphism( CONNECTION_GRAPH* aT
|
||||
}
|
||||
|
||||
|
||||
int minMatches = std::numeric_limits<int>::max();
|
||||
COMPONENT* altNextRef = nullptr;
|
||||
COMPONENT* bestNextRef = nullptr;
|
||||
int bestRefIndex;
|
||||
int altRefIndex;
|
||||
|
||||
for( size_t i = 0; i < m_components.size(); i++ )
|
||||
{
|
||||
COMPONENT* cmp = m_components[i];
|
||||
|
||||
if( cmp == current.m_ref )
|
||||
continue;
|
||||
|
||||
bool found = false;
|
||||
|
||||
for( auto it = current.m_locked.begin(); it != current.m_locked.end(); it++ )
|
||||
{
|
||||
if( it->second == cmp )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( found )
|
||||
continue;
|
||||
|
||||
auto matches = aTarget->findMatchingComponents( this, cmp, current );
|
||||
|
||||
int nMatches = matches.size();
|
||||
if( nMatches == 1 )
|
||||
{
|
||||
bestNextRef = cmp;
|
||||
bestRefIndex = i;
|
||||
break;
|
||||
}
|
||||
else if( nMatches == 0 )
|
||||
{
|
||||
altNextRef = cmp;
|
||||
altRefIndex = i;
|
||||
}
|
||||
else if( nMatches < minMatches )
|
||||
{
|
||||
minMatches = nMatches;
|
||||
bestNextRef = cmp;
|
||||
bestRefIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
BACKTRACK_STAGE next( current );
|
||||
next.m_currentMatch = -1;
|
||||
next.m_ref = m_components[current.m_refIndex + 1];
|
||||
next.m_refIndex = current.m_refIndex + 1;
|
||||
|
||||
if( bestNextRef )
|
||||
{
|
||||
next.m_ref = bestNextRef;
|
||||
next.m_refIndex = bestRefIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
next.m_ref = altNextRef;
|
||||
next.m_refIndex = altRefIndex;
|
||||
}
|
||||
|
||||
stack.push_back( next );
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user