EgtNumKernel 2.3k1 :
- in ShortestPath aumentato il numero max di punti consentiti.
This commit is contained in:
+22
-22
@@ -81,11 +81,11 @@ ShortestPath::Tsp( void)
|
||||
PreparePath( m_pDupl) ;
|
||||
|
||||
// inizializzo minimo costo
|
||||
m_nMinCost = INT_MAX ;
|
||||
m_nMinCost = LLONG_MAX ;
|
||||
|
||||
// ---- applico algoritmo NearNeighbor con miglioramenti aggiuntivi ----
|
||||
unsigned nMinNN = NearNeighbor() ;
|
||||
string sOut = "-- NearNeighbor : TotalCost = " + ToString( (int)nMinNN) ;
|
||||
long long unsigned nMinNN = NearNeighbor() ;
|
||||
string sOut = "-- NearNeighbor : TotalCost = " + to_string( nMinNN) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
// se migliora, salvo l'ordinamento
|
||||
if ( nMinNN < m_nMinCost) {
|
||||
@@ -111,8 +111,8 @@ ShortestPath::Tsp( void)
|
||||
pCurr = pCurr->pPrev ;
|
||||
}
|
||||
// ne calcolo il risultato
|
||||
unsigned nMinInv = TotalCost( m_pMain) ;
|
||||
string sOut = "-- Inverted NN : TotalCost = " + ToString( (int)nMinInv) ;
|
||||
long long unsigned nMinInv = TotalCost( m_pMain) ;
|
||||
string sOut = "-- Inverted NN : TotalCost = " + to_string( nMinInv) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
// se migliora, salvo l'ordinamento
|
||||
if ( nMinInv < m_nMinCost) {
|
||||
@@ -132,8 +132,8 @@ ShortestPath::Tsp( void)
|
||||
const double COEFF_FARNEIG = 1.4 ;
|
||||
const int MIN_PNTS_FARNEIG = 128 ;
|
||||
if ( m_nMinCost > COEFF_FARNEIG * m_nTotMin || m_nNumPnts < MIN_PNTS_FARNEIG) {
|
||||
unsigned nMinFN = FarNeighbor() ;
|
||||
string sOut = "-- FarNeighbor : TotalCost = " + ToString( (int)nMinFN) ;
|
||||
long long unsigned nMinFN = FarNeighbor() ;
|
||||
string sOut = "-- FarNeighbor : TotalCost = " + to_string( nMinFN) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
// se migliora, salvo l'ordinamento
|
||||
if ( nMinFN < m_nMinCost) {
|
||||
@@ -158,8 +158,8 @@ ShortestPath::CalculateImprovements( NODE* pPath)
|
||||
{
|
||||
// Ottimizzazione con movimento di singolo punto
|
||||
RestorePath( pPath) ;
|
||||
unsigned nPntOpt = PointOpt( pPath) ;
|
||||
string sOut = " PointOpt : TotalCost = " + ToString( (int)nPntOpt) ;
|
||||
long long unsigned nPntOpt = PointOpt( pPath) ;
|
||||
string sOut = " PointOpt : TotalCost = " + to_string( nPntOpt) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
// se migliora, salvo l'ordinamento
|
||||
if ( nPntOpt < m_nMinCost) {
|
||||
@@ -172,8 +172,8 @@ ShortestPath::CalculateImprovements( NODE* pPath)
|
||||
const int MAX_NODES_2OPT = 768 ;
|
||||
if ( m_nNumPnts <= MAX_NODES_2OPT) {
|
||||
RestorePath( pPath) ;
|
||||
unsigned nTwoOpt = TwoOpt( pPath) ;
|
||||
string sOut = " TwoOpt : TotalCost = " + ToString( (int)nTwoOpt) ;
|
||||
long long unsigned nTwoOpt = TwoOpt( pPath) ;
|
||||
string sOut = " TwoOpt : TotalCost = " + to_string( nTwoOpt) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
// se migliora, salvo l'ordinamento
|
||||
if ( nTwoOpt < m_nMinCost) {
|
||||
@@ -187,8 +187,8 @@ ShortestPath::CalculateImprovements( NODE* pPath)
|
||||
const int MAX_NODES_HYBRID = 512 ;
|
||||
if ( m_nNumPnts <= MAX_NODES_HYBRID) {
|
||||
RestorePath( pPath) ;
|
||||
unsigned nHybOpt = Hybrid( pPath) ;
|
||||
string sOut = " Hybrid : TotalCost = " + ToString( (int)nHybOpt) ;
|
||||
long long unsigned nHybOpt = Hybrid( pPath) ;
|
||||
string sOut = " Hybrid : TotalCost = " + to_string( nHybOpt) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
// se migliora, salvo l'ordinamento
|
||||
if ( nHybOpt < m_nMinCost) {
|
||||
@@ -297,7 +297,7 @@ ShortestPath::CalcDistances( void)
|
||||
nDist = 0 ;
|
||||
break ;
|
||||
}
|
||||
m_Dists[ Index( m_nNumPnts - 1, i)] = min( nDist, MAXDIST) ;
|
||||
m_Dists[ Index( m_nNumPnts - 1, i)] = nDist ;
|
||||
// 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)] = min( nDist, MAXDIST) ;
|
||||
m_Dists[ Index( i, m_nNumPnts - 1)] = nDist ;
|
||||
}
|
||||
// punto su diagonale principale
|
||||
m_Dists[ Index( m_nNumPnts - 1, m_nNumPnts - 1)] = MAXDIST ;
|
||||
m_Dists[ Index( m_nNumPnts - 1, m_nNumPnts - 1)] = UINT_MAX ;
|
||||
// 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 = min( GetDistance( dDx, dDy, dDz, dDh, dDv), MAXDIST) ;
|
||||
unsigned nDist = GetDistance( dDx, dDy, dDz, dDh, dDv) ;
|
||||
m_Dists[ Index( i, j)] = nDist ;
|
||||
// verifico se nuovo minimo di linea
|
||||
if ( nDist < nRowMinDist)
|
||||
nRowMinDist = nDist ;
|
||||
}
|
||||
else
|
||||
m_Dists[ Index( i, j)] = MAXDIST ;
|
||||
m_Dists[ Index( i, j)] = UINT_MAX ;
|
||||
}
|
||||
// aggiorno il totale delle minime distanze
|
||||
m_nTotMin += nRowMinDist ;
|
||||
@@ -368,7 +368,7 @@ ShortestPath::CalcDistances( void)
|
||||
// nel caso di percorso aperto senza vincoli, il numero delle distanze è uno meno di quello dei veri nodi
|
||||
if ( m_nType == SP_OPEN &&
|
||||
m_ObStart.nF == OB_NONE && m_ObEnd.nF == OB_NONE)
|
||||
m_nTotMin = (unsigned) ( m_nTotMin / (double) nLimit * ( nLimit - 1)) ;
|
||||
m_nTotMin = (long long unsigned) ( m_nTotMin / (double) nLimit * ( nLimit - 1)) ;
|
||||
|
||||
// stampe di debug
|
||||
#if 0
|
||||
@@ -381,7 +381,7 @@ ShortestPath::CalcDistances( void)
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
}
|
||||
#endif
|
||||
string sOut = "MinCost = " + ToString( int( m_nTotMin)) ;
|
||||
string sOut = "MinCost = " + to_string( m_nTotMin) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
}
|
||||
|
||||
@@ -424,14 +424,14 @@ ShortestPath::RestorePath( NODE* pPath)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
unsigned
|
||||
long long unsigned
|
||||
ShortestPath::TotalCost( NODE* pPath)
|
||||
{
|
||||
// ci devono essere almeno due nodi
|
||||
if ( pPath == nullptr || pPath->pNext == nullptr)
|
||||
return 0 ;
|
||||
// lunghezza del primo arco
|
||||
unsigned nCost = ArcCost( pPath->nPos, pPath->pNext->nPos) ;
|
||||
long long unsigned nCost = ArcCost( pPath->nPos, pPath->pNext->nPos) ;
|
||||
// ciclo sui nodi successivi (calcolo la lunghezza degli archi che li uniscono)
|
||||
NODE* pCurr = pPath->pNext ;
|
||||
while ( pCurr != pPath) {
|
||||
|
||||
Reference in New Issue
Block a user