资源简介
将一段用C语言实现的求解下列方程:
f(x1,x2,x3)=x1^2-x1*x2+x3
在给定区间的最大值的遗传算法程序改成C#程序。
要求:
(1)、数据从文件读入,结果输出到另一文件;
(2) 实现多线程。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace myCWindowsProgram
{
class Chrosome
{
private const int NVARS = 3;
private double PMUTATION;
private double[] gene = new double[NVARS];
private double[] upper = new double[NVARS];
private double[] lower = new double[NVARS];
private double fitness;
private double rFitness;
private double cFitness;
private Random myRandom;
public Chrosome(double tempPMUTATION)
{
PMUTATION = tempPMUTATION;
myRandom = new Random(unchecked((int)DateTime.Now.Ticks));
}
public double Fitness
{
get { return fitness; }
set { fitness = value; }
}
public double RFitness
{
get { return rFitness; }
set { rFitness = value; }
}
public double CFitness
{
get { return cFitness; }
set { cFitness = value; }
}
public double GetIOneGen(int id)
{
return this.gene[id];
}
public void SetIOneGen(int iddouble tempGen)
{
this.gene[id] = tempGen;
}
public double GetIOneLower(int id)
{
return this.lower[id];
}
public void SetIOneLower(int id double tempLower)
{
this.lower[id] = tempLower;
}
public double GetIOneUpper(int id)
{
return this.upper[id];
}
public void SetIOneUpper(int id double tempUpper)
{
this.upper[id] = tempUpper;
}
/*********************************************************
* 参数:分别表示上下界
* 返回值:doule
* 功能:产生介于[lowhigh)的随机数
* *********************************************************/
public double RandValue(double low double high)
{
double val;
val = (double)myRandom.Next(0 1000);
val = val / 1000.0 * (high - low) + low;
return val;
}
/*********************************************************
* 参数:无
* 返回值:无
* 功能:单个染色体变异
* *********************************************************/
public void ChrosomeMution()
{
double lbound hboundx;
for (int i = 0; i < NVARS; i++)
{
x = myRandom.Next(0 1000) / 1000.0;
if (x < PMUTATION)
{
lbound = this.lower[i];
hbound = this.upper[i];
this.SetIOneGen(i RandValue(lbound hbound));
}
}
}
/*********************************************************
* 参数:无
* 返回值:无
* 功能:单个染色体评价适应度
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-04-14 18:17 myCWindowsProgram\
目录 0 2014-05-17 15:24 myCWindowsProgram\myCWindowsProgram\
文件 941 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram.sln
文件 45568 2014-05-17 15:35 myCWindowsProgram\myCWindowsProgram.v11.suo
文件 187 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram\App.config
目录 0 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram\bin\
目录 0 2014-05-17 15:25 myCWindowsProgram\myCWindowsProgram\bin\Debug\
文件 22 2014-04-13 19:38 myCWindowsProgram\myCWindowsProgram\bin\Debug\DataSet_One.txt
文件 24 2014-04-13 19:45 myCWindowsProgram\myCWindowsProgram\bin\Debug\DataSet_Three.txt
文件 18 2014-04-13 19:40 myCWindowsProgram\myCWindowsProgram\bin\Debug\DataSet_Two.txt
文件 26112 2014-05-17 15:25 myCWindowsProgram\myCWindowsProgram\bin\Debug\myCWindowsProgram.exe
文件 187 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram\bin\Debug\myCWindowsProgram.exe.config
文件 60928 2014-05-17 15:25 myCWindowsProgram\myCWindowsProgram\bin\Debug\myCWindowsProgram.pdb
文件 22984 2014-05-17 15:35 myCWindowsProgram\myCWindowsProgram\bin\Debug\myCWindowsProgram.vshost.exe
文件 187 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram\bin\Debug\myCWindowsProgram.vshost.exe.config
文件 490 2013-06-18 20:28 myCWindowsProgram\myCWindowsProgram\bin\Debug\myCWindowsProgram.vshost.exe.manifest
文件 6770 2014-05-17 15:33 myCWindowsProgram\myCWindowsProgram\bin\Debug\Result.txt
文件 70397 2014-05-17 15:35 myCWindowsProgram\myCWindowsProgram\bin\Debug\Write.txt
目录 0 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram\bin\Release\
文件 4699 2014-04-13 17:23 myCWindowsProgram\myCWindowsProgram\Chrosome.cs
文件 22 2014-04-13 19:38 myCWindowsProgram\myCWindowsProgram\DataSet_One.txt
文件 24 2014-04-13 19:45 myCWindowsProgram\myCWindowsProgram\DataSet_Three.txt
文件 18 2014-04-13 19:40 myCWindowsProgram\myCWindowsProgram\DataSet_Two.txt
文件 3913 2014-04-12 23:39 myCWindowsProgram\myCWindowsProgram\myCWindowsProgram.csproj
文件 6112 2014-04-15 16:09 myCWindowsProgram\myCWindowsProgram\MyWindows.cs
文件 27319 2014-05-17 15:25 myCWindowsProgram\myCWindowsProgram\MyWindows.Designer.cs
文件 5817 2014-04-13 19:46 myCWindowsProgram\myCWindowsProgram\MyWindows.resx
目录 0 2014-04-12 21:24 myCWindowsProgram\myCWindowsProgram\obj\
目录 0 2014-05-17 15:25 myCWindowsProgram\myCWindowsProgram\obj\Debug\
文件 1278 2014-04-12 22:00 myCWindowsProgram\myCWindowsProgram\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6959 2014-05-17 15:22 myCWindowsProgram\myCWindowsProgram\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此处省略21个文件信息
- 上一篇:dft.cpp
- 下一篇:基于属性重要度的约简算法
相关资源
- c#与西门子1500通讯
- c++调用C# COM 参数是结构体数组
- 基于OSG的三维河流的可视化研究——
- CTP上期技术平台API及C#封装更新到CT
- C#神思二代身份证读卡程序 demo
- C#调用百度地图获取经纬度
- 03 C#与C++dll互相传递字符串.rar
- c# 华大HD900身份证阅读器操作类
- 即时通讯开发源码终极版C#.NETC++都有
- c++可视化学生选课系统
- MFC可视化界面ping程序
- C#C++混合编程C#调用非托管C++类
- c#图书管理系统+详细数据库设计文档
- Visual Studio 2010 Express 学习版
- C++调用C#库例程
- VTK三维可视化读取RAW数据的c++源代码
- c#与STK开发
- OPC Data Access 3.00 Source Code
- C#/C++麦克风插拔检测
- SNL语言编译器GUI VC++ 2008版 MFC实现可
- 使用C#创建webservice服务,并使用服务
- MFC可视化_迷宫算法_最短路径
- CTP接口 C#封装版
- MFC计算器编程,可视化,含详细实现
- C++可视化MFC课设_五子棋带报告
- 基于UDP的简单可视化界面聊天程序c
- MFC校园导航图 可视化校园地图
- C# 版VNC、远程连接
- 求解一元四次方程(vbvcc#excelhtml)-
- 黄维通Visual C++面向对象与可视化程序
评论
共有 条评论