From b1272b645af8f01ae528c8f46787d89de58330fb Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Sat, 1 Jul 2017 19:22:21 +0000 Subject: [PATCH] EgtNumKernel 1.8f6 : - corretto TSP per limitare distanza entro valori max ammessi dall'algoritmo. --- EgtNumKernel.rc | Bin 11662 -> 11662 bytes ShortestPath.h | 2 +- ShortestPathTsp.cpp | 10 +++++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/EgtNumKernel.rc b/EgtNumKernel.rc index ca9885db00f4d419341e07120af98f64e8869e06..0a05743c36656ac4199af8746950deec05b9f33e 100644 GIT binary patch delta 102 zcmeB+?u*{=jg8T4^J+PHX67^o!^sDgbvOS~bYa}w#qGchlsL_2jV$5BxVb{u3A;pw LG*|-7s43h4*o+}g delta 102 zcmeB+?u*{=jg8TG^J+PHX69rD!^sDgbvOS~bYa}w#qGchlsL_2jV$5BxVb{u3A;pw LG*|-7s43h4)081L diff --git a/ShortestPath.h b/ShortestPath.h index 050ef00..1f06c8f 100644 --- a/ShortestPath.h +++ b/ShortestPath.h @@ -17,7 +17,7 @@ //---------------------------------------------------------------------------- -#define MAXCARD 1048576 // 2^20 per evitare overflow con int e 1024 somme +#define MAXDIST 1048576U // 2^20 per evitare overflow con int e 1024 somme //---------------------------------------------------------------------------- struct SpPoint { diff --git a/ShortestPathTsp.cpp b/ShortestPathTsp.cpp index 871ac3d..840a783 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)] = MAXCARD ; + 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)] = MAXCARD ; + m_Dists[ Index( i, j)] = MAXDIST ; } // aggiorno il totale delle minime distanze m_nTotMin += nRowMinDist ;