#include "stdafx.h" #include "GreedyTSP.h" #include #include CGreedyTSP::CGreedyTSP(void) { m_pPathGraph = NULL; Reset(); } CGreedyTSP::~CGreedyTSP(void) { Reset(); } void CGreedyTSP::Reset() { // vector m_vecPathData.clear(); m_vecPathResult.clear(); m_vecPathAdded.clear(); // graph if (m_pPathGraph) { for (int i=0; i=m_nPathCount) return -1; return m_vecPathResult[nIndex]; } const SPathData* CGreedyTSP::GetPathData(int nIndex) const { if (nIndex<0 || nIndex>=m_nPathCount) return NULL; return &(m_vecPathData[nIndex]); } VectorInteger* CGreedyTSP::GetPathResult() { return &m_vecPathResult; } VectorPathData* CGreedyTSP::GetPathData() { return &m_vecPathData; } double CGreedyTSP::GetPathResult(VectorInteger& vecPathResult) { vecPathResult.resize(m_nPathCount); for (int i=0; i m_pPathGraph[nCurIdx][i]) { dTempMin = m_pPathGraph[nCurIdx][i]; nMinIdx = i; } } if (nMinIdx==-1) { return -1; } // Ãß°¡‰çÀ½À» ÀúÀå. m_vecPathAdded[nMinIdx] = true; return nMinIdx; } void CGreedyTSP::InitPathResult(const SPathData& ptStart) { if (m_nPathCount<1) return; m_nStartIndex = -1; double dMinDist = DBL_MAX; double dTempDist = 0.0; for (int i=0; idTempDist) { m_nStartIndex = i; dMinDist = dTempDist; } } if (m_nStartIndex==-1) { return; } m_vecPathResult[0] = m_nStartIndex; // Ãß°¡‰çÀ½À» ÀúÀå. m_vecPathAdded[m_nStartIndex] = true; for (int i=1; idTempDist) { nStartIndex = i; dMinDist = dTempDist; } } for (int i=0; i