From 7f21cf0f43ab47ad7fef43b729b81b4dfaa3087e Mon Sep 17 00:00:00 2001 From: SaraP Date: Fri, 19 Nov 2021 17:10:59 +0100 Subject: [PATCH] EgtNumKernel : - in ShortestPath reintrodotto MAXDIST. --- ShortestPath.h | 3 +++ ShortestPathTsp.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ShortestPath.h b/ShortestPath.h index 5dd8d1e..630b686 100644 --- a/ShortestPath.h +++ b/ShortestPath.h @@ -15,6 +15,9 @@ #include "/EgtDev/Include/ENkShortestPath.h" +//---------------------------------------------------------------------------- +#define MAXDIST 1073741823U // 2^30 - 1 per evitare overflow + //---------------------------------------------------------------------------- struct SpPoint { double dXi ; diff --git a/ShortestPathTsp.cpp b/ShortestPathTsp.cpp index 10c936f..a4560c2 100644 --- a/ShortestPathTsp.cpp +++ b/ShortestPathTsp.cpp @@ -297,7 +297,7 @@ ShortestPath::CalcDistances( void) nDist = 0 ; break ; } - m_Dists[ Index( m_nNumPnts - 1, i)] = nDist ; + m_Dists[ Index( m_nNumPnts - 1, i)] = min( nDist, MAXDIST) ; // verifico se nuovo minimo di linea if ( nDist < nRowMinDist) nRowMinDist = nDist ; @@ -333,10 +333,10 @@ ShortestPath::CalcDistances( void) nDist = 0 ; break ; } - m_Dists[ Index( i, m_nNumPnts - 1)] = nDist ; + m_Dists[ Index( i, m_nNumPnts - 1)] = min( nDist, MAXDIST) ; } // punto su diagonale principale - m_Dists[ Index( m_nNumPnts - 1, m_nNumPnts - 1)] = UINT_MAX ; + m_Dists[ Index( m_nNumPnts - 1, m_nNumPnts - 1)] = MAXDIST ; // devo ancora calcolare le righe/colonne precedenti nLimit = m_nNumPnts - 1 ; } @@ -352,14 +352,14 @@ ShortestPath::CalcDistances( void) float dDz = float( m_Points[i].dZf - m_Points[j].dZi) ; float dDh = float( m_Points[i].dHf - m_Points[j].dHi) ; float dDv = float( m_Points[i].dVf - m_Points[j].dVi) ; - unsigned nDist = GetDistance( dDx, dDy, dDz, dDh, dDv) ; + unsigned nDist = min( GetDistance( dDx, dDy, dDz, dDh, dDv), MAXDIST) ; m_Dists[ Index( i, j)] = nDist ; // verifico se nuovo minimo di linea if ( nDist < nRowMinDist) nRowMinDist = nDist ; } else - m_Dists[ Index( i, j)] = UINT_MAX ; + m_Dists[ Index( i, j)] = MAXDIST ; } // aggiorno il totale delle minime distanze m_nTotMin += nRowMinDist ;