?? tspcity.h
字號:
/*
*
* website: http://www.coolsoft-sd.com/
* contact: support@coolsoft-sd.com
*
*/
/*
* Genetic Algorithm Library
* Copyright (C) 2007-2008 Coolsoft Software Development
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#pragma once
#include <string>
#include <hash_map>
using namespace std;
using namespace stdext;
#define CITY_SIZE 14
class TspCity
{
private:
static int _nextId;
int _id;
wstring _name;
int _x;
int _y;
public:
TspCity(const wstring& name,
int x,
int y) : _name(name),
_x(x),
_y(y) { _id = ++_nextId; }
inline int GetID() const { return _id; }
inline int GetX() const { return _x; }
inline int GetY() const { return _y; }
float GetDistance(const TspCity& city) const;
inline const wstring& GetName() const { return _name; }
inline bool PointWithinCity(int x, int y) { return x >= _x - CITY_SIZE / 2 && x <= _x + CITY_SIZE / 2 && y >= _y - CITY_SIZE / 2 && y <= _y + CITY_SIZE / 2; }
void Draw(CDC& dc) const;
};
class TspCities
{
private:
static TspCities _instance;
hash_map<int, TspCity*> _cities;
public:
inline static TspCities& GetInstance() { return _instance; }
~TspCities() { Clear(); }
void AddCity(const wstring& name,
int x,
int y);
bool RemoveCity(int id);
void Clear();
void DrawCities(CDC& dc) const;
float GetDistance(int cityA, int cityB) const;
const TspCity* GetCityById(int id) const;
const TspCity* GetCityByPoint(int x,
int y) const;
void GetCities(vector<const TspCity*>& output) const;
inline int GetCount() const { return (int)_cities.size(); }
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -