遗传算法-实验 Hexagonal tortoise problem (Using C language)

本文介绍了通过遗传算法解决六边形乌龟问题,该问题由Choi Seok-jeong设计,目标是寻找使角数值之和相等的六边形排列。遗传算法包括编码、选择、交叉、变异和替换等步骤。实验结果显示,算法能逐渐收敛并输出正确结果,但存在局部最优和稳定性不足的问题,需要进一步优化。
摘要由CSDN通过智能技术生成

@ 初步算法,有待完善,仅供参考,转载请附原文链接。

遗传算法:龟纹图问题

1、Introduction

Jisuwimundo is a hexagonal tortoise problem designed by Chosun scholar Choi Seok-jeong. The tortoise is a shape in which hexagons are interlocked with each other. There is a condition that a ruler is placed so that the sum of the corner numbers of the hexagons is equal. In the case of an exponential return figure with a number of N, numbers from 1 to N are placed. The objective of the problem is that the exponential return problem is an algorithm that cannot be solved within polynomial (NP-hard). Therefore, there are effective genetic algorithms that search for limited space.

The characteristics of hexagonal tortoise problem:
1) Parameters for each corner of the hexagon;
2) The sum of each hexagon is equal.

The Figure 1.1 is the 3 × 3 hexagon tortoise.
Fig. 1.1.    3 × 3 hexagon tortoise structure

2、project process

a) System structure

Since this problem is NP-hard, it is solved using genetic algorithms. The overall system architecture is shown in Figure 2.1. First, create the population, then calculate the fitness, select the parents in the population, cross between the selected parents, and ensure the diversity of the population through mutation and substitution. Finally, the judgment is made by the termination condition. If the condition is met, it is terminated and output. If it is not met, the fitness assessment is repeated until the result appears.
在这里插入图片描述
This part of coding is shown in thiss:

int main(void)
{
   
	int seed;
	int i, j;

	seed = time(NULL);
	srand(seed);

	MakePopulation(valuesOfParents);
//	Show(valuesOfParents);
	Fitness();

	for(i = 0; i < 10000000; i++)
	{
   
		for(j = 0; j < CHILDRENNUM; j++)
		{
   
			parentOne = Selection();
			parentTwo = Selection();

			valuesOfChildren = pmxCrossOver(parentOne, parentTwo);

			valuesOfChildren.parent1 = parentOne;
			valuesOfChildren.parent2 = parentTwo;

			valuesOfChildren = MakeSixAngle(valuesOfChildren);
			valuesOfChildren = Mutation(valuesOfChildren);
			valuesOfChildren = MakeSixAngle(valuesOfChildren);

			children[j] = valuesOfChildren;
		}
		Replacement();
		Fitness();

		count++;
		Show(valuesOfChildren);
		if(valuesOfChildren.dispersion == 0)
		{
   
			printf("\n finished!  \n");
			ResultShow(valuesOfChildren);
			break;
		}
	}
	return 0;
}

b) Representation

In the implementation of the genetic algorithm, the first problem is to code the problem reasonably. Translate into digital problems. Here, a locus-based encoding method is adopted. This method is shown in the Figure 2.3.
在这里插入图片描述
This part of conding is shown:

//*********制造出不同的数字*****************//

turtle MakeNumber(void)
{
   
	int i, j;
	for(i = 0; i < NODENUM; i++)
	{
   
		valuesOfParents.nodes[i] = rand()%NODENUM + 1;	//产生0~nodenum个随机整数
		for(j = 0; j < i; j++)
		{
   	
			//*************是的所有节点具有不同的值*******************//
			if(valuesOfParents.nodes[i]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值