亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gajava.txt

?? 這是一個應用遺傳算法解決的函數優化問題
?? TXT
?? 第 1 頁 / 共 5 頁
字號:
-import java.sql.*;
import java.util.*;
import java.math.*;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;

public class GA
{
    //數據庫鏈接設置
    String dbmsdriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    String dbURL = "jdbc:microsoft:sqlserver://csy:1433;DatabaseName=GA_DATA";
 public Connection con = null;
 Statement stmt = null;
    String sqlstr;

 public String[]population = new String[40]; //存放父代種群
    public String[]childrenpopulation = new String[40]; //存放子代種群
    public double[]farray = new double[40]; //存放個體的適應度
    //存放個體適應度的和,最優函數值,雜交概率
    public double sumf, bestresult, mutationprobability,precision;
    public String bestroot; //存放最優解對應的二進制串
 
    //二進制轉換為十進制
    public int BiToDec(String BiString)
    {
        int i, strlen, coefficient, result;
        strlen = BiString.length();
        coefficient = 1;
        result = 0;
        for (i = strlen - 1; i >= 0; i--)
        {
            if (BiString.substring(i, i + 1).equalsIgnoreCase("1"))
                result = result + coefficient;
            coefficient = coefficient * 2;
        }
        return result;
    }
    //計算個體適應度
    public double EvaluateIndividaul(String BiString)
    {
        double result;
        Integer dec;
        dec = BiToDec(BiString);
        //result =  - 1+dec.doubleValue() * c.doubleValue() / d.doubleValue();
        result =  - 1 + dec.doubleValue() * precision;  
  result = result * Math.sin(10 * 3.14159265358979 * result) + 2.0;
        return result;
    }
    //初始化種群
    public void innitial()
    {
  //鏈接數據庫
  try
  {
   Class.forName(dbmsdriver).newInstance();
   con = DriverManager.getConnection(dbURL, "sa", "wq");
   stmt = con.createStatement();
  }
  catch (Exception ex)
  {
   System.out.println(ex.getMessage());
  }
  
  Integer c, d;
  c = 3;//自變量區間寬度:2-(-1)=3
  d = 4194304;//2^22;
  precision = c.doubleValue() / d.doubleValue();//精度
  mutationprobability = 0.001;//設定編譯概率
        String individaul = "";
        Random ran = new Random();
        for (int i = 0; i < 40; i++)
        {
            for (int j = 0; j < 22; j++)
            {
                if (ran.nextBoolean())
                    individaul += '1';
                else
                    individaul += '0';
            }
            population[i] = individaul;
            individaul = "";
        }
    }
    //計算種群適應度
    public void Evaluate()
    {
        sumf = 0;
        bestresult = 0;
        for (int i = 0; i < 40; i++)
        {
            farray[i] = EvaluateIndividaul(population[i]);
            sumf = sumf + farray[i];
            //記錄最優個體
   if (farray[i] >= bestresult)
            {
                bestresult = farray[i];
                bestroot = population[i];
            }
        }
    }
    //選擇操作,使用輪盤賭選擇法
    public void Select()
    {
        double SelectProbability, Pi;
        for (int i = 0; i < 40; i++)
        {
            Random ran = new Random();
            SelectProbability = ran.nextDouble(); //選擇概率
            Pi = 0;
            for (int j = 0; j < 40; j++)
            {
                Pi = Pi + farray[j] / sumf;
                if (SelectProbability < Pi)
                {
                    childrenpopulation[i] = population[j];
                    break;
                }
            }
        }
    }
    //雜交操作
    public void Crossover()
    {
        int i, crossoverpos;
        String parent1, parent2;
        String temp1, temp2;

        for (i = 0; i < 40; i = i + 2)
        {
            parent1 = childrenpopulation[i];
            parent2 = childrenpopulation[i + 1];

            Random ran = new Random();
            crossoverpos = ran.nextInt(22);
            if (crossoverpos == 0 || crossoverpos == 22)
                ;
            else
            {
                temp1 = parent1.substring(0, crossoverpos) 
      + parent2.substring(crossoverpos);
                temp2 = parent2.substring(0, crossoverpos) 
      + parent1.substring(crossoverpos);
                childrenpopulation[i] = temp1;
                childrenpopulation[i + 1] = temp2;
            }
        }
    }
    //變異操作
    public void Mutation()
    {
        int mutationpos;
        for (int i = 0; i < 40; i++)
        {
            Random ran = new Random();
            if (mutationprobability > ran.nextDouble())
            {
                mutationpos = ran.nextInt(22);
                if (mutationpos != 0)
                {
                    if (childrenpopulation[i].substring(mutationpos,mutationpos + 1).equalsIgnoreCase("1"))
                        childrenpopulation[i] = childrenpopulation[i].substring(0, mutationpos) 
       + "0" +childrenpopulation[i].substring(mutationpos + 1);
                    else
                        childrenpopulation[i] = childrenpopulation[i].substring(0, mutationpos) 
       + "1" +childrenpopulation[i].substring(mutationpos + 1);
                }
            }
        }
    }

 //把個體寫入數據庫,以分析個體的變化
 public void SavePopulation(int k, int j)
 { 
  try
  {
    for (int i = 0; i < 40; i++)
   {
    sqlstr ="INSERT INTO [POPULATION]([SelectMethod],[TestCount],[GENERATION], [INDIVIDAUL_INDEX],[BISTR])" 
      + " values('roulette wheel selection'," 
      + Integer.toString(k) + "," 
      + Integer.toString(j) + "," 
      + Integer.toString(i) + "," 
      + "'" + population[i] + "')";
                 stmt.executeUpdate(sqlstr);
             }
  }
     catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
 }
 
 //把最優解寫入數據庫
 public void SaveBestValue(int k,int j)
 {
  double dbestroot;
  Integer a;
  a = BiToDec(bestroot);
  //dbestroot =  - 1+a.doubleValue() * b.doubleValue() / c.doubleValue();
  dbestroot =  - 1+a.doubleValue() * precision;
  try
  {
   sqlstr =
    "INSERT INTO [TESTDATA]([SelectMethod],[TestCount],[GenerationCount], [MaxValue],[BestRoot])" 
    + " values('roulette wheel selection'," 
    + Integer.toString(k) + ',' 
    + Integer.toString(j) + ',' 
    + Double.toString(bestresult) + ','
    + Double.toString(dbestroot) + ")";
   stmt.executeUpdate(sqlstr); 
  }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
 }
 
 public void ClostDBConn()
 {
  try
  {
   con.close();
  }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        } 
 
 }

 //主函數
    public static void main(String[]args)
    {
  //實驗次數
  for (int k = 0; k < 1000; k++)
  {
   GA gatest = new GA();
   gatest.innitial();
   //每次實驗的最大代數
   for (int j = 0; j < 50; j++)
   {
    gatest.Evaluate();
    gatest.Select();
    gatest.Crossover();
    gatest.Mutation();

    gatest.SavePopulation(k,j);//保存群體信息

    //把產生的子代付給父代,為下一輪準備
    for (int i = 0; i < 40; i++)
    {
     gatest.population[i] = gatest.childrenpopulation[i];
    }

    gatest.SaveBestValue(k,j);//保存最優解信息

    //顯示進度
    System.out.print(k);
    System.out.print("次實驗|");
    System.out.print(j);
    System.out.println("代");
   } //每次實驗代數
   gatest.ClostDBConn();//關閉數據庫鏈接
  } //實驗次數  
    } //main
    //耗時38分9秒
}













我用java寫的遺傳算法的嚴重問題,程序沒錯,但不知道為什么結果總和預想的不同,實在是困惑,請幫忙啊!!!! 
發表于: 2007-2-6 下午8:33         回復  
 
源程序如下:

import java.io.IOException;
import java.io.File;
import java.io.FileReader;
import java.io.*;

public class GeneticAlgorithm {

/*
         A. M:群體大小。一般取為20~100;
         B. T:遺傳運算終止進化代數。一般取為100~500;
         C. Pc:交叉概率。一般取為0.4~0.99;
         D. Pm:變異概率。一般取為0.0001~0.1。
     */
/* Change any of these parameters to match your needs */

static int POPSIZE = 5; /* population size */
static int MAXGENS = 5; /* max. number of generations */
static int NVARS = 3; /* no. of problem variables */
static float PXOVER = 0.8f; /* probability of crossover */
static float PMUTATION = 0.3f; /* probability of mutation */

int E = 6; 
int T = 120; 
int generation; /* current generation no. */
int cur_best; /* best individual */
//FILE * galog; /* an output file */


    BufferedReader infile;
    FileReader in;
    BufferedWriter outfile;
    FileWriter out;

    Genotype population[];
    Genotype newpopulation[];
    
int p[][][] = { { {0, 1, 1}, {0, 0, 0}, {0, 1, 1}, {0, 0, 0}
}, { {1, 0, 0}, {0, 0, 0}, {1, 0, 0}, {0, 0, 0}
}, { {0, 0, 0}, {0, 1, 1}, {0, 0, 0}, {0, 1, 1}
}, { {0, 0, 0}, {1, 0, 0}, {0, 0, 0}, {1, 0, 0}
}
};

double a[][][] = { { {10, 1, 1}, {10, 2, 4}, {1, 2.3, 1}, {3, 5, 1}
}, { {1, 3, 0.8}, {2, 3, 1.5}, {1, 1, 2}, {2, 0.7, 4}
}, { {2.5, 1.2, 3.4}, {10, 1, 1}, {1, 0.8, 13}, {1.9, 1, 1}
}, { {0.4, 3, 2.3}, {1, 2.1, 4}, {3.2, 1, 0.5}, {1, 1.4, 1.6}
}
};

double u[][][] = { { {2, 1, 1}, {3, 2, 4}, {1, 2.3, 1}, {3, 2, 1}
}, { {1, 3, 0.8}, {2, 3, 1.5}, {1, 1, 0.9}, {2, 0.7, 4}
}, { {0.7, 1.2, 3.4}, {0.5, 1, 1}, {1, 0.8, 0.9}, {1.9, 1, 1}
}, { {0.4, 3, 2.3}, {1, 2.1, 4}, {0.4, 1, 0.3}, {1, 1.4, 0.8}
}
};

double s[][][] = { { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}
}, { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}
}, { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}
}, { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}
}, { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}
}
};

    GeneticAlgorithm() {
      
        population = new Genotype[POPSIZE + 1]; /* population */
        newpopulation = new Genotype[POPSIZE + 1]; /* new population; */
for (int i = 0; i <= POPSIZE; i++) {
            population[i] = new Genotype();
            newpopulation[i] = new Genotype();
}
}

class Genotype /* genotype (GT), a member of the population */
{
double gene[];
double fitness;
double upper[];
double lower[];
double cfitness;
double rfitness;
        Genotype() {
            gene = new double[NVARS]; /* a string of variables */
            fitness = 0; /* GT's fitness */
            upper = new double[NVARS]; 
            lower = new double[NVARS]; /* GT's variables lower bound */
            rfitness = 0; 
            cfitness = 0; 
}
}
/***************************************************************/
/* Initialization function: Initializes the values of genes    */
/* within the variables bounds. It also initializes (to zero)  */
/* all fitness values for each member of the population. It    */
/* reads upper and lower bounds of each variable from the      */
/* input file `gadata.txt'. It randomly generates values       */
/* between these bounds for each gene of each genotype in the  */
/* population. The format of the input file `gadata.txt' is    */
/* var1_lower_bound var1_upper bound                           */
/* var2_lower_bound var2_upper bound ...                       */
/***************************************************************/

void initialize() {
        String str;
        String parts[];
try {
            in = new FileReader("gadata.txt");
            infile = new BufferedReader(in);
int i, j;
double lbound, ubound;
while ((str = infile.readLine()) != null) {
                parts = str.split(" ");
for (i = 0; i < NVARS; i++) {
                    lbound = Double.parseDouble(parts[0]);
                    ubound = Double.parseDouble(parts[1]);

for (j = 0; j < POPSIZE; j++) {
                        population[j].fitness = 0;
                        population[j].rfitness = 0;
                        population[j].cfitness = 0;
                        population[j].lower[i] = lbound;
                        population[j].upper[i] = ubound;
                        population[j].gene[i] = randval(population[j].lower[i],

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
激情综合一区二区三区| 日本一区二区三区四区| 中文字幕国产精品一区二区| 91丨porny丨首页| 蜜臀av在线播放一区二区三区| ●精品国产综合乱码久久久久| 一本久久a久久免费精品不卡| 亚洲色图.com| 国产精品久久久久久久久久免费看 | 激情五月婷婷综合网| 国产盗摄女厕一区二区三区| 色综合色综合色综合色综合色综合 | 久久精品在线免费观看| 亚洲桃色在线一区| 青娱乐精品视频| 99国产精品国产精品毛片| 欧美日韩的一区二区| 7777精品伊人久久久大香线蕉超级流畅 | 国产日韩亚洲欧美综合| 艳妇臀荡乳欲伦亚洲一区| 激情亚洲综合在线| 欧美天堂一区二区三区| 精品剧情v国产在线观看在线| 国产精品国产三级国产普通话99 | 热久久久久久久| 成人高清免费观看| 亚洲精品亚洲人成人网 | 日韩va欧美va亚洲va久久| 大桥未久av一区二区三区中文| 欧美日韩和欧美的一区二区| 中文字幕第一区综合| 日韩影视精彩在线| 91免费在线看| 国产精品毛片无遮挡高清| 美女免费视频一区| 欧美美女激情18p| 亚洲免费观看高清完整版在线 | 国产亚洲欧美一级| 免费成人深夜小野草| 在线一区二区观看| 亚洲国产成人午夜在线一区| 蜜臀a∨国产成人精品| 色噜噜狠狠色综合中国| 中文字幕在线不卡视频| 国产一区二区视频在线播放| 欧美一激情一区二区三区| 一级中文字幕一区二区| 91看片淫黄大片一级| 国产精品久久久久久久久久久免费看| 久久se精品一区二区| 欧美精品久久天天躁| 亚洲一区二区三区四区五区中文| 波多野结衣中文一区| 亚洲国产精品成人久久综合一区| 国产一区日韩二区欧美三区| 精品区一区二区| 精品在线免费视频| 欧美成人精品福利| 日本成人在线一区| 91超碰这里只有精品国产| 午夜精品一区在线观看| 国产精品国模大尺度视频| 国产盗摄女厕一区二区三区| 国产香蕉久久精品综合网| 成人激情视频网站| 中文字幕精品三区| 99视频一区二区| 亚洲免费毛片网站| 欧美无砖专区一中文字| 五月天激情综合| 日韩一区二区三区高清免费看看| 卡一卡二国产精品| 欧美一区二区三区在线| 日韩黄色在线观看| 欧美tickling挠脚心丨vk| 国产美女视频91| 国产精品美女一区二区在线观看| 99麻豆久久久国产精品免费优播| 亚洲免费观看高清完整版在线观看| 欧美三级午夜理伦三级中视频| 亚洲国产成人高清精品| 日韩欧美一区在线观看| 成人免费高清在线| 亚洲国产欧美在线人成| 2021中文字幕一区亚洲| 成人国产视频在线观看| 自拍偷拍亚洲欧美日韩| 欧美一区国产二区| 国产69精品久久久久777| 亚洲欧美另类小说视频| 欧美一区二区精品| www.久久精品| 热久久免费视频| 国产精品全国免费观看高清 | 91美女福利视频| 五月婷婷欧美视频| 中文一区一区三区高中清不卡| 精品视频1区2区3区| 国产一区二区三区免费在线观看| ●精品国产综合乱码久久久久 | 亚洲综合一区二区精品导航| 69av一区二区三区| 国产精品69毛片高清亚洲| 亚洲一区电影777| 国产精品无遮挡| 亚洲青青青在线视频| 久久久久成人黄色影片| 欧美精品日日鲁夜夜添| 日韩国产欧美三级| 亚洲毛片av在线| 国产日本欧美一区二区| 69堂国产成人免费视频| 色综合久久综合中文综合网| 国产精品一区二区久久精品爱涩| 亚洲精品成人精品456| 亚洲精品一区二区在线观看| 欧美高清你懂得| 色综合激情五月| av激情综合网| 韩国av一区二区三区在线观看| 亚洲高清免费观看高清完整版在线观看| 国产欧美一区在线| 日韩一卡二卡三卡| 欧美主播一区二区三区| 91丨国产丨九色丨pron| 国产在线不卡视频| 蜜桃视频第一区免费观看| 日韩精品五月天| 日韩高清在线不卡| 日韩精品欧美成人高清一区二区| 一区二区三区在线免费播放| 一区二区不卡在线播放 | 久久成人免费电影| 狠狠色狠狠色综合系列| 成人午夜视频网站| 97精品久久久久中文字幕| 欧美私模裸体表演在线观看| 欧美日韩高清在线播放| 精品国产乱码久久久久久蜜臀 | 国产精品资源网| 99视频在线精品| 6080国产精品一区二区| www久久精品| 亚洲同性gay激情无套| 亚洲小说欧美激情另类| 免费成人在线影院| 成人福利视频网站| 欧美色图12p| 久久久久久黄色| 一区二区三区四区精品在线视频| 97久久精品人人做人人爽| 欧美性做爰猛烈叫床潮| 精品剧情在线观看| 亚洲女厕所小便bbb| 美腿丝袜一区二区三区| 99久久777色| 欧美一级日韩免费不卡| 国产精品区一区二区三| 日韩不卡一区二区三区| 国产精品夜夜嗨| 欧美日韩精品欧美日韩精品一综合| 欧美mv和日韩mv国产网站| 亚洲精品久久久久久国产精华液| 蜜桃视频一区二区| 色嗨嗨av一区二区三区| 久久香蕉国产线看观看99| 亚洲一区二区黄色| 成人免费高清视频| 91精品欧美一区二区三区综合在| 中文字幕一区二区三区四区不卡| 日韩二区三区四区| 99re这里都是精品| 2020日本不卡一区二区视频| 亚洲国产精品欧美一二99| 不卡的av电影| 久久精品在这里| 青青草国产成人av片免费| 国产精品久久久久久久久图文区 | 狠狠网亚洲精品| 欧美剧在线免费观看网站| 亚洲欧洲在线观看av| 国产一区二区导航在线播放| 欧美乱熟臀69xxxxxx| 亚洲精品成a人| caoporm超碰国产精品| 国产午夜精品久久久久久免费视 | 一区二区三区电影在线播| 国产成人免费在线视频| 日韩美女主播在线视频一区二区三区 | 午夜激情一区二区| 日本福利一区二区| 亚洲天堂成人网| thepron国产精品| 国产精品丝袜一区| 国产成人精品免费在线| 久久精品视频在线看| 国产精品一区二区男女羞羞无遮挡| 日韩欧美电影一区| 精品一区二区在线观看| 日韩欧美三级在线|