#include<iostream>
#include"Mountain.h"
#include"GA.h"
#include<ctime>
using namespace std;
int main()
{
while (1)
{
cout << "请选择算法:" << endl;
cout << "1.爬山法" << endl;
cout << "2.遗传算法" << endl;
int n;
int num;
cin >> num;
switch (num)
{
case 1:
{
cout << "请输入皇后的数量:" << endl;
cin >> n;
map = new int*[n]; //指针初始化
temp_map = new int *[n];
for (int i = 0; i<n; i++)
{
map[i] = new int[n];
temp_map[i] = new int[n];
}
clock_t time1 = clock();
bool find = false;
while (!find)
{
start(n); //初始化棋盘
find = climb(n);
}
clock_t time2 = clock();
show(n);
cout << "时间开销为:" << '\t' << (double)(time2 - time1) << "ms" << endl;
break;
}
case 2:
{
cout << "请输入皇后的数量:" << endl;
cin >> n;
clock_t time2 = clock();
Genetic queens(n, n * 4); //初始化皇后数和种群中的状态数
queens.GeneticAlgorithm(); //入口函数
cout << "\n 花费了" << (double)(clock() - time2) << "ms" << endl;
break;
}
default:
{
cout << "输入错误,请重新输入!" << endl;
break;
}
}
}
}