资源简介
旅行商问题 遗传算法 贪婪基因重组 代码 c#
代码片段和文件信息
//////////////////////////////////////////////////////////////////////////////////////////////////
// File Name: Cities.cs
// Date: 06/01/2006
// Copyright (c) 2006 Michael LaLena. All rights reserved. (www.lalena.com)
// Permission to use copy modify and distribute this Program and its documentation
// if any for any purpose and without fee is hereby granted provided that:
// (i) you not charge any fee for the Program and the Program not be incorporated
// by you in any software or code for which compensation is expected or received;
// (ii) the copyright notice listed above appears in all copies;
// (iii) both the copyright notice and this Agreement appear in all supporting documentation; and
// (iv) the name of Michael LaLena or lalena.com not be used in advertising or publicity
// pertaining to distribution of the Program without specific written prior permission.
///////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Globalization;
namespace Tsp
{
///
/// This class contains the list of cities for this test.
/// Each city has a location and the distance information to every other city.
///
public class Cities : List
{
///
/// Determine the distances between each city.
///
/// When creating the initial population of tours this is a greater chance
/// that a nearby city will be chosen for a link. This is the number of nearby cities that will be considered close.
public void CalculateCityDistances( int numberOfCloseCities )
{
foreach (City city in this)
{
city.Distances.Clear();
for (int i = 0; i < Count; i++)
{
city.Distances.Add(Math.Sqrt(Math.Pow((double)(city.Location.X - this[i].Location.X) 2D) +
Math.Pow((double)(city.Location.Y - this[i].Location.Y) 2D)));
}
}
foreach (City city in this)
{
city.FindClosestCities(numberOfCloseCities);
}
}
///
/// Open the xml file that contains the list of cities.
///
/// Name of the xml file.
/// The city list.
/// fileName parameter is invalid.
/// xml File is not properly formatted.
public void OpenCityList(string fileName)
{
DataSet cityDS = new DataSet();
try
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 898 2006-06-03 12:13 tsp.sln
文件 3524 2006-09-02 14:01 tsp\Cities.cs
文件 1128 2006-06-06 08:17 tsp\Cities.xm
文件 4452 2006-09-02 13:55 tsp\City.cs
文件 2183 2006-07-27 19:41 tsp\li
文件 4492 2006-09-02 14:12 tsp\Population.cs
文件 1562 2006-07-27 19:41 tsp\Program.cs
目录 0 2006-06-10 14:00 tsp\Properties\
文件 1362 2006-07-16 22:45 tsp\Properties\AssemblyInfo.cs
文件 2833 2006-06-03 12:13 tsp\Properties\Resources.Designer.cs
文件 5612 2006-06-03 12:13 tsp\Properties\Resources.resx
文件 1086 2006-06-03 12:13 tsp\Properties\Settings.Designer.cs
文件 249 2006-06-03 12:13 tsp\Properties\Settings.settings
文件 19006 2006-07-27 19:41 tsp\Tour.cs
文件 9164 2006-09-02 14:12 tsp\Tsp.cs
文件 3668 2006-06-06 22:05 tsp\Tsp.csproj
文件 3653 2006-07-27 19:41 tsp\TspEventArgs.cs
文件 16220 2006-09-02 14:15 tsp\TspForm.cs
文件 27136 2006-09-02 14:10 tsp\TspForm.Designer.cs
文件 5814 2006-09-02 14:10 tsp\TspForm.resx
- 上一篇:C#利用fft实现快速卷积
- 下一篇:基于图的推荐
评论
共有 条评论