Sourcea
انواع سورس رایگان!
:Contact
info [ at ] sourcea . ir
برای درخواست سورس مد نظر خود با ایمیل پشتیبانی سایت در ارتباط باشید.
کلیه حقوق مادی و معنوی این سایت متعلق به سورسا می باشد
#include "stdafx.h"
#include "GAQueen.h"
//sourcea.ir
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CGAQueen::CGAQueen(int nPopulation,int nIteration,float Mutation,int iChBoard)
{
Clear();
srand( (unsigned)time( NULL ) );
Population=nPopulation;
Iteration=nIteration;
MutationRate=Mutation;
ChessBoradLenght=iChBoard;
}
CGAQueen::~CGAQueen()
{
}
int CGAQueen::CostFunc(int index)
{
int costValue=0;
int m,n;
int i,j;
for(i=0;i=0)
{
if(area[m][n]==1)
{
costValue++;
}
m++;
n--;
}
m=i+1;
n=j+1;
while(m=0 && n>=0)
{
if(area[m][n]==1)
{
costValue++;
}
m--;
n--;
}
m=i-1;
n=j+1;
while(m>=0 && nCostMatrix[i+1])
{
Temp=CostMatrix[i];
CostMatrix[i]=CostMatrix[i+1];
CostMatrix[i+1]=Temp;
for (int j=0;j
#if !defined(AFX_GAQUEEN_H__C26AE0A3_F9B4_426F_A324_B460CC7946CB__INCLUDED_)
#define AFX_GAQUEEN_H__C26AE0A3_F9B4_426F_A324_B460CC7946CB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
class CGAQueen
{
public:
CGAQueen(int nPopulation,int nIteration,float Mutation,int mChBoard);
virtual ~CGAQueen();
void Clear();// to clear chess board with 0 value
void InitialPopulation();// to create the first and initial randompopulation
void FillArea(int index);// to fill chess board with desired chromosome
int CostFunc(int index);// determine the cost of matrix[index][index]
void PopulationSort();// to sort population from the best to the worst
void GenerateCrossOverMatrix();// a way to create children from parent is CcrossOver
void Mating();// to create children from parents
void ApplyMutation();// to apply mating to sorted population from the second chromosome to last
int ChromosomeMatrix[30][1000];// Answer ( chromosome ) Matrix
int CostMatrix[1000];// to keep cost va;ue for each chromosome
int CrossOverMatrix[30][1000];// to keep cross over matrix for relative parents
int Population;
int Iteration;
float MutationRate ;
int ChessBoradLenght;
private:
int area[30][30];// This is the chess board matrix
};
#endif // !defined(AFX_GAQUEEN_H__C26AE0A3_F9B4_426F_A324_B460CC7946CB__INCLUDED_)
صورت سوال:
برنامه هشت وزیر در C++
این برنامه N وزیر را طوری در صفحه قرار میدهد که نتوانند یکدیگر را بزنند!
موفق باشید
A.J
انواع سورس رایگان!
:Contact
info [ at ] sourcea . ir
برای درخواست سورس مد نظر خود با ایمیل پشتیبانی سایت در ارتباط باشید.