www.pudn.com > KSP.rar > QYDirectedPath.h


//  Revision History: 
// 
//  11/21/2006   Yan   Initial Version 
//  01/11/2008   Yan   Modified Version 
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//  Copyright Notice: 
// 
//  Copyright (c) 2006 Your Company Inc. 
// 
//  Warning: This computer program is protected by copyright law and  
//  international treaties.  Unauthorized reproduction or distribution 
//  of this program, or any portion of it, may result in severe civil and 
//  criminal penalties, and will be prosecuted to the maximum extent  
//  possible under the law. 
// 
// ____________________________________________________________________________ 
 
#ifndef _QYDIRECTEDPATH_H_ 
#define _QYDIRECTEDPATH_H_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include  
#include  
#include  
using namespace std; 
 
namespace asu_emit_qyan 
{	 
	class CQYDirectedPath   
	{		 
	public: 
		CQYDirectedPath(){}; 
		CQYDirectedPath(int pId, double pCost, const std::vector& pVertexList) 
			:m_nId(pId), m_dCost(pCost) 
		{ 
			m_vVertexList.assign(pVertexList.begin(), pVertexList.end()); 
		} 
		 
		virtual ~CQYDirectedPath(){}; 
		 
		// Getter and Setter 
		int GetId() const { return m_nId; } 
		void SetId(int val) { m_nId = val; } 
		 
		double GetCost() const { return m_dCost; } 
		void SetCost(double val) { m_dCost = val; } 
		 
		int GetLength() const { return m_vVertexList.size(); } 
		 
		std::vector GetVertexList() const { return m_vVertexList; } 
		void SetVertexList(std::vector val) { m_vVertexList = val; } 
		 
		int GetSourceNodeId() const { return m_nSourceNodeId; } 
		void SetSourceNodeId(int val) { m_nSourceNodeId = val; } 
		 
		int GetTerminalNodeId() const { return m_nTerminalNodeId; } 
		void SetTerminalNodeId(int val) { m_nTerminalNodeId = val; } 
		 
		// display the content 
		void PrintOut(std::ostream& out_stream) const 
		{ 
			string city[80]={	"anhui","anhua","anqing","beijing","baixue","changchun","ch_city","ci_city", 
								"cj_city","dh_city","di_city","dj_city","eh_city","ei_city","ej_city","fh_city", 
								"fi_city","fj_city","gh_city","gi_city","gj_city","hh_city","hi_city","hj_city", 
								"ih_city","ii_city","ij_city","jh_city","ji_city","jj_city","kh_city","ki_city", 
								"kj_city","lh_city","li_city","lj_city","mh_city","mi_city","mj_city","nh_city", 
								"ni_city","nj_city","oh_city","oi_city","oj_city","ph_city","pi_city","pj_city", 
								"qh_city","qi_city","qj_city","rh_city","ri_city","rj_city","sh_city","si_city", 
								"sj_city","th_city","ti_city","tj_city","uh_city","ui_city","uj_city","vh_city", 
								"vi_city","vj_city","wh_city","wi_city","wj_city","xh_city","xi_city","xj_city", 
								"yh_city","yi_city","yj_city","zh_city","zi_city","zj_city","zk_city","zl_city" 
							}; 
 
			int path[80]; 
			out_stream << "All Length: " << 10000*m_dCost << "Km  Cities: " << m_vVertexList.size() << std::endl; 
			std::copy(m_vVertexList.rbegin(), m_vVertexList.rend(), path); 
			for(int i=m_vVertexList.size()-1;i>0;i--) 
				out_stream<"; 
			out_stream<(out_stream, "<-")); 
			out_stream < m_vVertexList;  
		 
		// intermediate variables 
		int m_nSourceNodeId; 
		int m_nTerminalNodeId; 
 
		 
 
	public: 
		//// Comparator for paths: the smaller path has less cost. 
		class Comparator  
		{ 
		public: 
			// Lesson: the condition must be checked completely!!! 
			bool operator() (const CQYDirectedPath& s1, const CQYDirectedPath& s2) const  
			{ 
				if (s1.GetCost() == s2.GetCost()) 
				{ 
					return s1.GetLength() <= s2.GetLength(); // only considering '<' will cause problems!!! 
				} 
				return s1.GetCost() < s2.GetCost(); 
			} 
 
			// 
			bool operator() (const CQYDirectedPath* s1, const CQYDirectedPath* s2) const  
			{ 
				return operator()(*s1, *s2); 
			} 
		};  
	}; 
} 
 
#endif //_QYDIRECTEDPATH_H_