Aktif KonularAktif Konular  Forum Üyelerini GösterÜye Listesi  TakvimTakvim  Forumu AraArama  YardımYardım
  Kayıt OlKayıt Ol  GirişGiriş
C / C++ ve C++.NET
 C#nedir?com Forum : C/C++ : C / C++ ve C++.NET
Mesaj icon Konu: Genetik Algoritma(yardım) Yanıt Yaz Yeni Konu Gönder
   

Yazar Mesaj
ayom777
Newbie
Newbie


Kayıt Tarihi: 28 Mayıs 2009
Aktif Durum: Aktif Değil
Gönderilenler: 1
Alıntı ayom777 Cevaplabullet Konu: Genetik Algoritma(yardım)
    Gönderim Zamanı: 28 Mayıs 2009 Saat 12:01
Arkadaşlar Genetik algoritma için yazdığım kodda iki hatam var ama bulamıyorum yardımcı olursanız sevinirim. Hatalarım hata burda  1.Hata evpop (chrom *)' cannot return value.
2.Hata : ) expected.
 
Kod aşagıdadır...
 
Arkadaşlar genetik algoritma ile ilgili proje odevimde 2 hataya kadar indirdim Fonksiyon değer döndürmüyor.Lütfen Bakarmısınız???
Kod:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct chrom
{
short int bit [49];
int fit;
}chrom;
void evpop(chrom popcurrent [20]);
int x(chrom popcurrent);
int y  (int x);
void pickchroms(chrom popcurrent[20]);
void crossover(chrom popnext[20]);
void mutation(chrom popnext[20]);
void main()
{
int num;
int i,j;
enter: printf("\nplease enter the no. of iterations: ");
scanf("%d",&num);
chrom popcurrent[20];
chrom popnext[20];
if(num<1)
goto enter;
evpop(popcurrent);
for(i=0;i<num;i++)
{
printf("/ni=%d\n",i);
for(j=0;j<20;j++)
popnext[j]=popcurrent[j];
pickchroms(popnext);
crossover(popnext);
mutation(popnext);
for (j=0;j<20;j++)
popcurrent[j]=popnext[j];
}
printf("\npress any key to end ! ");
flushall();
getche();
}
void evpop(chrom popcurrent[20])
{
int i,j, value;
int random;
for(j=0;j<20;j++)
{
for(i=0;i<49;i++)
{
random=rand();
random=(random%2);
popcurrent[j].bit=random;
}
value=x(popcurrent[j]);
popcurrent[j].fit=y(x(popcurrent[j]));
printf("\n popcurrent[%d]=%d%d%d%d%d%d%d%d%d   fitness=%d",j,
popcurrent[j].bit[48], popcurrent[j].bit[47], popcurrent[j].bit[46],
popcurrent[j].bit[45], popcurrent[j].bit[44], popcurrent[j].bit[43],
popcurrent[j].bit[42], popcurrent[j].bit[41], popcurrent[j].bit[40],
popcurrent[j].bit[39],popcurrent[j].bit[38], popcurrent[j].bit[37],
popcurrent[j].bit[36], popcurrent[j].bit[35], popcurrent[j].bit[34],
popcurrent[j].bit[33], popcurrent[j].bit[32], popcurrent[j].bit[31],
popcurrent[j].bit[30], popcurrent[j].bit[29], popcurrent[j].bit[28],
popcurrent[j].bit[27], popcurrent[j].bit[26], popcurrent[j].bit[25],
popcurrent[j].bit[24], popcurrent[j].bit[23], popcurrent[j].bit[22],
popcurrent[j].bit[21], popcurrent[j].bit[20], popcurrent[j].bit[19],
popcurrent[j].bit[18], popcurrent[j].bit[16], popcurrent[j].bit[15],
popcurrent[j].bit[14],popcurrent[j].bit[13], popcurrent[j].bit[12],
popcurrent[j].bit[11], popcurrent[j].bit[10], popcurrent[j].bit[9],
popcurrent[j].bit[8], popcurrent[j].bit[7], popcurrent[j].bit[6],
popcurrent[j].bit[5], popcurrent[j].bit[4], popcurrent[j].bit[3],
popcurrent[j].bit[2], popcurrent[j].bit[1], popcurrent[j].bit[0],
value,popcurrent[j].fit);
}
return(0);
}
int x(chrom popcurrent)
{
int z;
z=(popcurrent.bit[0]*1)+(popcurrent.bit[1]*2)+(popcurrent.bit[2]*4)+
(popcurrent.bit[3]*8)+ (popcurrent.bit[4]*16) +(popcurrent.bit[5]*32) +
(popcurrent.bit[6]*64)+ (popcurrent.bit[7]*128) +(popcurrent.bit[8]*256)
+(popcurrent.bit[9]*512) +(popcurrent.bit[10]*1024) +(popcurrent.bit[11]*2048)
+(popcurrent.bit[12]*4096) +(popcurrent.bit[13]*8192)
+(popcurrent.bit[14]*16384) +(popcurrent.bit[15]*32768)
+(popcurrent.bit[16]*65536) +(popcurrent.bit[17]*131072)
+(popcurrent.bit[18]*262144) +(popcurrent.bit[19]*524288)
+(popcurrent.bit[20]*1048576) +(popcurrent.bit[21]*2097152)
+(popcurrent.bit[22]*4194304) +(popcurrent.bit[23]*8388608)
+(popcurrent.bit[24]*16777216) +(popcurrent.bit[25]*33554432);
if(popcurrent.bit[25]==1)
z=z*(-1);
z=z/10000;
return(z);

int t;
t=(popcurrent.bit[26]*1)+(popcurrent.bit[27]*2)+(popcurrent.bit[28]*4)+
(popcurrent.bit[29]*8)+ (popcurrent.bit[30]*16) +(popcurrent.bit[31]*32) +
(popcurrent.bit[32]*64)+ (popcurrent.bit[33]*128) +(popcurrent.bit[34]*256)+
(popcurrent.bit[35]*512) +(popcurrent.bit[36]*1024) +(popcurrent.bit[37]*2048)
+(popcurrent.bit[38]*4096) +(popcurrent.bit[39]*8192)
+(popcurrent.bit[40]*16384) +(popcurrent.bit[41]*32768)
+(popcurrent.bit[42]*65536) +(popcurrent.bit[43]*131072)
+(popcurrent.bit[44]*262144) +(popcurrent.bit[45]*524288)
+(popcurrent.bit[46]*1048576) +(popcurrent.bit[47]*2097152)
 +(popcurrent.bit[48]*4194304) +(popcurrent.bit[49]*8388608);
 if(popcurrent.bit[49]==1)
t=t*(-1);
t=t/10000;
return(t);
}
int sehir [25][25]={{2169.440,500.9570},{2516.6648,961.7451},
{2738.4365,1257.3323},
{1908.4565,1038.5508},{2097.9512,867.8691},{2219.1228,1058.5 159},
{1470.6812,380.7935}, {1017.5789,866.0049},{2136.3994,1103.6995},
{1554,8604,175.9971},{1567.1240,818.0894},
{233.7585,559.4814},{1841.8398,557.5859},{2504.5686,12.2551} ,
{1614.2637,1220.4280},
{1858.3076,209.7029},{2625.9639,1103.8071},{2583.7559,1030,7 925},
{579.5152,465.5835},
{2311.2280,1008.8391},{1796.4104,808.5042},{61.8462,877.5325 },
{251.3108,1546.1401},
{2348.9854,134.3997},{2491.4263,935.3845}};
int y(int z int t)
{

 int y;
   y=(t-z)*(t-z);
  return(y);
}
void pickchroms(chrom popcurrent[4])
{
 int i,j;
   chrom temp;
    for(i=0;i<19;i++)
       for(j=0;j<19;j++)
         {
              if(popcurrent[j+1].fit>popcurrent[j].fit)
                {
                  temp=popcurrent[j+1];
                  popcurrent[j+1]=popcurrent[j];
                  popcurrent[j]=temp;
                }
         }
      for(i=0;i<20;i++)
  printf("\nsorting:popnext[%d] fitness=%d",i,popcurrent.fit);
  printf("\n");
      flushall();
  return(0);
}

void crossover(chrom popnext[20])
{
 int random;
   int i;
   random=rand();
   random=((random%5)+1);
   for(i=0;i<random;i++)
     {
       popnext[2].bit=popnext[0].bit ;           ;
         popnext[3].bit=popnext[1].bit;
      }

 for(i=random;i<49;i++)             
 
     {
       popnext[2].bit=popnext[1].bit ;           ;
       popnext[3].bit=popnext[0].bit ;           ; 
      }   

      for(i=0;i<20;i++)
       popnext.fit=y(x(popnext));
        for(i=0;i<20;i++)
  printf(crossoverpopnext[%d]=%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%
  d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%      value=%d
  fitness = %d,i,popnext.bit[49],popnext.bit[48],popnext.bit[47],
  popnext.bit[46],popnext.bit[45],
  popnext.bit[44] ,popnext.bit[43] ,popnext.bit[42] ,
  popnext.bit[41] ,popnext.bit[40] ,popnext.bit[39] ,
  popnext.bit[38] ,popnext.bit[37] ,popnext.bit[36] ,
  popnext.bit[35] ,popnext.bit[34] ,popnext.bit[33] ,
  popnext.bit[32] ,popnext.bit[31] ,popnext.bit[30] ,
  popnext.bit[29],popnext.bit[28] ,popnext.bit[27] ,
  popnext.bit[26] ,popnext.bit[25] ,popnext.bit[24] ,
  popnext.bit[23] ,popnext.bit[22] ,popnext.bit[21] ,
  popnext.bit[20] ,popnext.bit[19] ,popnext.bit[18] ,
  popnext.bit[17] ,popnext.bit[16] ,popnext.bit[15] ,
  popnext.bit[14] ,popnext.bit[13] ,popnext.bit[12] ,
  popnext.bit[11] ,popnext.bit[10] ,popnext.bit[9] ,
  popnext.bit[8] ,popnext.bit[7] ,popnext.bit[6] ,
  popnext.bit[5] ,popnext.bit[4] ,popnext.bit[3] ,
  popnext.bit[2] ,popnext.bit[1],popnext.bit[0],x(popnext),
  popnext.fit);
            
   return(0);
   }                   
void mutation(chrom popnext[20])  
 {
 
   int random;
   int row,col,value;                                           
   random=rand()%50;                   
   if (random==25)  
   {
    col=rand()%6;                              
      row=rand()%4;                              
     
     if (popnext[row].bit[col]==0)         
      popnext[row].bit[col]=1 ;
    
      else if (popnext[row].bit[col]==1)      
           popnext[row].bit[col]=0;
        
       popnext[row].fit=y(x(popnext[row]));  

       value=x(popnext[row]);                
   }        

   return(0);
}               







}

IP
   

Yanıt Yaz Yeni Konu Gönder
Konuyu Yazdır Konuyu Yazdır

Forum Atla
Kapalı Foruma Yeni Konu Gönderme
Kapalı Forumdaki Konulara Cevap Yazma
Kapalı Forumda Cevapları Silme
Kapalı Forumdaki Cevapları Düzenleme
Kapalı Forumda Anket Açma
Kapalı Forumda Anketlerde Oy Kullanma

Bulletin Board Software by Web Wiz Forums version 8.03
Copyright ©2001-2006 Web Wiz Guide