Java版本(比较详细,试过可用):
http://blog.csdn.net/google19890102/article/details/41247753
其中的变异操作:
/******** 变异操作 ***********/ public void Mutation()
{ double XTemp[][] = new double[NP][size]; double XMutationTemp[][] = new double[NP][size]; XTemp = this.getX(); Random r = new Random(); for (int i = 0; i < NP; i++)
{ int r1 = 0, r2 = 0, r3 = 0; while (r1 == i || r2 == i || r3 == i || r1 == r2 || r1 == r3 || r2 == r3)
{// 取r1,r2,r3 r1 = r.nextInt(NP); r2 = r.nextInt(NP); r3 = r.nextInt(NP); } for (int j = 0; j < size; j++)
{ XMutationTemp[i][j] = XTemp[r1][j] + F * (XTemp[r2][j] - XTemp[r3][j]); } } this.setXMutation(XMutationTemp); }
Python版本:
http://blog.csdn.net/hehainan_86/article/details/38685231
C/C++版本:
http://www.cnblogs.com/tsingke/p/5809453.html