EgtNumKernel 2.3k1 :
- in ShortestPath aumentato il numero max di punti consentiti.
This commit is contained in:
Binary file not shown.
@@ -16,7 +16,7 @@
|
||||
#include "ShortestPath.h"
|
||||
|
||||
/*-------------------------------------------------------------------------- */
|
||||
unsigned
|
||||
long long unsigned
|
||||
ShortestPath::FarNeighbor( void)
|
||||
{
|
||||
// abilito i collegamenti tra nodi diversi e disabilito gli auto-collegamenti
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
#include "ShortestPath.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
unsigned
|
||||
long long unsigned
|
||||
ShortestPath::Hybrid( NODE* pPath)
|
||||
{
|
||||
const int MAX_TRY = 2048 ;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "ShortestPath.h"
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
unsigned
|
||||
long long unsigned
|
||||
ShortestPath::NearNeighbor( void)
|
||||
{
|
||||
// abilito i collegamenti tra nodi diversi e disabilito gli auto-collegamenti
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
#include "ShortestPath.h"
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
unsigned
|
||||
long long unsigned
|
||||
ShortestPath::PointOpt( NODE* pPath)
|
||||
{
|
||||
// ciclo di tentativi di spostamento di un punto
|
||||
@@ -40,7 +40,7 @@ ShortestPath::PointOpt( NODE* pPath)
|
||||
ArcCost( pLast->nPos, pKth->pNext->nPos) ;
|
||||
if ( nTEST < nEXIST && ( nEXIST - nTEST) > nBestImprove) {
|
||||
nBestImprove = nEXIST - nTEST ;
|
||||
pBest = pKth ;
|
||||
pBest = pKth ;
|
||||
}
|
||||
}
|
||||
if ( nBestImprove == 0) {
|
||||
|
||||
+1
-1
@@ -232,6 +232,6 @@ ShortestPath::GetMinLength( double& dMinLen)
|
||||
if ( ! m_bSolved)
|
||||
return false ;
|
||||
// assegno risultato
|
||||
dMinLen = m_nMinCost ;
|
||||
dMinLen = ( double)m_nMinCost ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
+10
-14
@@ -15,10 +15,6 @@
|
||||
|
||||
#include "/EgtDev/Include/ENkShortestPath.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#define MAXDIST 1048576U // 2^20 per evitare overflow con int e 1024 somme
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
struct SpPoint {
|
||||
double dXi ;
|
||||
@@ -76,24 +72,24 @@ class ShortestPath : public IShortestPath
|
||||
void PreparePath( NODE* pPath) ;
|
||||
void SavePath( NODE* pPath) ;
|
||||
void RestorePath( NODE* pPath) ;
|
||||
unsigned TotalCost( NODE* pPath) ;
|
||||
long long unsigned TotalCost( NODE* pPath) ;
|
||||
void UpdateOrder( NODE* pPath) ;
|
||||
unsigned Index( unsigned i, unsigned j)
|
||||
{ return ( i * m_nNumPnts + j) ; }
|
||||
unsigned ArcCost( unsigned i, unsigned j)
|
||||
{ return m_Dists[ Index( i, j)] ; }
|
||||
unsigned NearNeighbor( void) ;
|
||||
long long unsigned NearNeighbor( void) ;
|
||||
unsigned CheapArc( unsigned i) ;
|
||||
unsigned FarNeighbor( void) ;
|
||||
long long unsigned FarNeighbor( void) ;
|
||||
unsigned HighArc( unsigned i) ;
|
||||
unsigned PointOpt( NODE* pPath) ;
|
||||
unsigned TwoOpt( NODE* pPath) ;
|
||||
unsigned Hybrid( NODE* pPath) ;
|
||||
long long unsigned PointOpt( NODE* pPath) ;
|
||||
long long unsigned TwoOpt( NODE* pPath) ;
|
||||
long long unsigned Hybrid( NODE* pPath) ;
|
||||
bool ZigZag( void) ;
|
||||
unsigned TotalCost( void) ;
|
||||
long long unsigned TotalCost( void) ;
|
||||
|
||||
private :
|
||||
static const int MAX_SPPS = 1024 ;
|
||||
static const int MAX_SPPS = 32766 ; // 2^15-2 per evitare problemi nell'allocazione di m_Dists a 32bit
|
||||
|
||||
private :
|
||||
int m_nType ;
|
||||
@@ -112,6 +108,6 @@ class ShortestPath : public IShortestPath
|
||||
bool* m_Available ;
|
||||
NODE* m_pMain ;
|
||||
NODE* m_pDupl ;
|
||||
unsigned m_nTotMin ;
|
||||
unsigned m_nMinCost ;
|
||||
long long unsigned m_nTotMin ;
|
||||
long long unsigned m_nMinCost ;
|
||||
} ;
|
||||
|
||||
+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) {
|
||||
|
||||
@@ -159,23 +159,23 @@ ShortestPath::ZigZag( void)
|
||||
|
||||
// ne calcolo il risultato
|
||||
m_nMinCost = TotalCost() ;
|
||||
string sOut = "-- ZigZag/OneWay : TotalCost = " + ToString( (int)m_nMinCost) ;
|
||||
string sOut = "-- ZigZag/OneWay : TotalCost = " + to_string( m_nMinCost) ;
|
||||
MY_LOG( sOut.c_str()) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
unsigned
|
||||
ShortestPath::TotalCost( void)
|
||||
long long unsigned
|
||||
ShortestPath::TotalCost( void)
|
||||
{
|
||||
unsigned nCost = 0 ;
|
||||
long long unsigned nCost = 0 ;
|
||||
// ciclo sui nodi
|
||||
for ( unsigned i = 1 ; i < m_nNumPnts ; ++ i) {
|
||||
double dDx = m_Points[m_nOrder[i]].dXi - m_Points[m_nOrder[i-1]].dXi ;
|
||||
double dDy = m_Points[m_nOrder[i]].dYi - m_Points[m_nOrder[i-1]].dYi ;
|
||||
double dDz = m_Points[m_nOrder[i]].dZi - m_Points[m_nOrder[i-1]].dZi ;
|
||||
nCost += unsigned( sqrt( dDx * dDx + dDy * dDy + dDz * dDz)) ;
|
||||
nCost += (long long unsigned)( sqrt( dDx * dDx + dDy * dDy + dDz * dDz)) ;
|
||||
}
|
||||
return nCost ;
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
#include "ShortestPath.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
unsigned
|
||||
long long unsigned
|
||||
ShortestPath::TwoOpt( NODE* pPath)
|
||||
{
|
||||
const int MAX_TRY = 2048 ;
|
||||
|
||||
Reference in New Issue
Block a user