SDC C-Project CF Review 프로그램
LYW
2021-07-08 630eb072cca33a7c633f6429a0b5a531d1b83268
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
 
#include <vector>
 
#define NO_PATH_DATA            -999999
#define PATH_DATA_TYPE_COUNT    2
 
struct SPathData
{
    SPathData(int nX=NO_PATH_DATA, int nY=NO_PATH_DATA, int nIdx=-1)
    {
        nIndex    = nIdx;
        nPosX    = nX;
        nPosY    = nY;
        memset(pDataType, 0, sizeof(int)*PATH_DATA_TYPE_COUNT);
    }
 
    void Reset()
    {
        nIndex = -1;
        nPosX = NO_PATH_DATA;
        nPosY = NO_PATH_DATA;
        memset(pDataType, 0, sizeof(int)*PATH_DATA_TYPE_COUNT);
    }
 
    bool operator == (const SPathData& rhs) const
    {
        for (int i=0; i<PATH_DATA_TYPE_COUNT; i++)
        {
            if (pDataType[i]!=rhs.pDataType[i])
            {
                return false;
            }
        }
        return true;
    }
 
    int nIndex;
    int nPosX;
    int nPosY;
    BOOL bSelected;
    int pDataType[PATH_DATA_TYPE_COUNT];        // Path Type (°æ·Î°¡ ¿©·¯°¡ÁöÀÏ °æ¿ì, ¿¹¸¦µé¾î Àü¸é Èĸ頸®ºä ½Ã)
};
typedef std::vector<SPathData>                    VectorPathData;
typedef std::vector<SPathData>::iterator        VectorPathDataIt;
typedef std::vector<SPathData>::const_iterator    constVectorPathDataIt;
 
typedef std::vector<int>                        VectorInteger;
typedef std::vector<int>::iterator                VectorIntegerIt;
typedef std::vector<int>::const_iterator        constVectorIntegerIt;
 
typedef std::vector<bool>                        VectorBoolean;
typedef std::vector<bool>::iterator                VectorBooleanIt;
typedef std::vector<bool>::const_iterator        constVectorBooleanIt;
 
class AFX_EXT_CLASS CGreedyTSP
{
public:
    CGreedyTSP(void);
    virtual ~CGreedyTSP(void);
    virtual void    Reset();
 
    // setter
    virtual void    SetPathData(const VectorPathData& vecPathData, const SPathData& ptStart);
    virtual void    SetPathData(const VectorPathData& vecPathData, const VectorInteger& vecPathResult);
 
    // getter
    int                    GetPathCount() const;
    int                    GetPathResult(int nIndex) const;
    const SPathData*    GetPathData(int nIndex) const;
    
    VectorInteger*        GetPathResult();    
    VectorPathData*        GetPathData();    
    double                GetPathResult(VectorInteger& vecPathResult);
    BOOL                GetPathData(VectorPathData& vecPathData);
    double                GetTotalDistance();
    double                GetTotalDistance(const VectorInteger& vecPathResult);
 
    // func
    virtual double    CalculateTSP();
    virtual BOOL    SortingPathResult();
    static double CalculateDistance(const POINT& pt1, const POINT &pt2);
    static double CalculateDistance(const SPathData& pt1, const SPathData &pt2);
    static double CalculateDistanceX(const POINT& pt1, const POINT &pt2);
    static double CalculateDistanceX(const SPathData& pt1, const SPathData &pt2);
    static double CalculateDistanceY(const POINT& pt1, const POINT &pt2);
    static double CalculateDistanceY(const SPathData& pt1, const SPathData &pt2);
 
 
protected:
    int        SelectPath(int nCurIdx);
    void    InitPathResult(const SPathData& ptStart);
 
    int                m_nStartIndex;
    SPathData        m_ptStart;
    double            m_dTotalDistance;
 
    // graph data
    int                m_nPathCount;
    double            **m_pPathGraph;
    
    // vector
    VectorPathData    m_vecPathData;
    VectorInteger    m_vecPathResult;
    VectorBoolean    m_vecPathAdded;    
    
    
};