• 大小: 35.75 KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-09-08
  • 语言: C#
  • 标签: C#  遗传算法  

资源简介

应该是比较通用的,仅供参考。
应用程序里需要进行调用,大家看看就知道怎么用了。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;

namespace GeneticProgram
{
  public  class Individuality
    {
         byte[] genoCodes;// 基因编码字符(0 1 串形式)数组
        const float  PI=3.14159F;
      IndivualProps ip ;
        double fitness; //适应值
        double rfitness; //选择概率 relative fitness
        double cfitness; //累计概率 cumulative fitness

             //基因值(浮点数形式)数组
   public double[] genoValues;
        public bool Set_genoValues(int index double a)
        {
            if (genoValues == null) return false;
            if (index <= 0 || index > ip.varNumbers)
                return false;
            genoValues[index-1] = a;
            return true;

        }
        public bool Get_genoValues(int index ref double a)
        {
            if (genoValues == null) return false;
            if (index <= 0 || index > ip.varNumbers)
                return false;
            a = genoValues[index-1];
            return true;

        }
        

        public byte[] GenoCodes
        {
            get { return this.genoCodes; }
            set { this.genoCodes = value; }
        }
        
        public double Fitness
        {
            get { return this.fitness; }
            set { this.fitness = value; }
        }

        public double RFitness
        {
            get { return this.rfitness; }
            set { this.rfitness = value; }
        }

        public double CFitness
        {
            get { return this.cfitness; }
            set { this.cfitness = value; }
        }


        //=========以下是方法=================

        //构造函数===========
        public   Individuality(ref IndivualProps ip1 )
        {
           
            //初始适应值为零
            fitness = 0.0;
            rfitness = 0.0; 
            cfitness = 0.0;
            ip = ip1;
            genoValues = new double[ip.varNumbers ];
    

        }//构造函数结束
        public bool  Init()
        {
            //===================================================
            Random r = new Random();
            double temp = 0.0;
            //  FileHelper.AppendText(@“c:\GAExampleLog.txt“ “新基因开始 \r\n“);
            //随机赋予编码
            int sum = 0;
            for (int i = 0; i < ip.varNumbers; i++)
                sum += ip.eachGenoLength[i];
            ip.genoTotalLength = sum;
                genoCodes = new byte[ip.genoTotalLength];
            for (int i = 0; i < ip.genoTotalLength; i++)
            {
                temp = r.NextDouble();
                if (temp < 0.5) { genoCodes[i] = 0; }
                else { genoCodes[i] = 1; }

           }
            //初始基因值为零
             for (int i = 0; i < ip.varNumbers; i++)
            {
                genoValues[i] = 0.0;
            }
            CalcGenoValue();//计算基因值
             return true;
        }

    
        //深克隆一个已知个体
        public Individuality DeepClone()
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      24576  2008-12-16 10:32  GeneticProgram\GeneticProgram\GeneticProgram\bin\Debug\GeneticProgram.dll

     文件      44544  2008-12-16 10:32  GeneticProgram\GeneticProgram\GeneticProgram\bin\Debug\GeneticProgram.pdb

     文件       2057  2008-12-01 11:06  GeneticProgram\GeneticProgram\GeneticProgram\GeneticProgram.csproj

     文件       5156  2008-12-01 11:06  GeneticProgram\GeneticProgram\GeneticProgram\Individuality.cs

     文件        754  2008-12-01 11:06  GeneticProgram\GeneticProgram\GeneticProgram\IndivualProps.cs

     文件      24576  2008-12-16 10:32  GeneticProgram\GeneticProgram\GeneticProgram\obj\Debug\GeneticProgram.dll

     文件      44544  2008-12-16 10:32  GeneticProgram\GeneticProgram\GeneticProgram\obj\Debug\GeneticProgram.pdb

     文件        162  2009-03-04 13:45  GeneticProgram\GeneticProgram\GeneticProgram\obj\GeneticProgram.csproj.FileList.txt

     文件      12427  2008-12-16 10:32  GeneticProgram\GeneticProgram\GeneticProgram\Population.cs

     文件       1331  2008-12-01 11:06  GeneticProgram\GeneticProgram\GeneticProgram\Properties\AssemblyInfo.cs

     文件        931  2008-12-01 11:06  GeneticProgram\GeneticProgram\GeneticProgram.sln

    ..A..H.     19456  2009-03-04 13:49  GeneticProgram\GeneticProgram\GeneticProgram.suo

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram\obj\Debug\TempPE

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram\bin\Debug

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram\obj\Debug

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram\bin

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram\obj

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram\Properties

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram\GeneticProgram

     目录          0  2008-12-30 14:25  GeneticProgram\GeneticProgram

     目录          0  2008-12-31 13:18  GeneticProgram

----------- ---------  ---------- -----  ----

               180514                    21


评论

共有 条评论