-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.c
118 lines (99 loc) · 2.1 KB
/
t.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<stdio.h>
#include<string.h>
int size_train=10;
char train[11][60];
int precon(char a[])
{
int c = 0 , i=0;
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='\0')
break;
else if(a[i+1]!='\0' && a[i]!='0') c++;
}
return c;
}
int dataRead(chrom data[] , chrom inp[], char path[]){ //data=encoded data, inp=decoded data
char ch ;
FILE *myfile = fopen( path, "r");
int cur = 0, i = 0,siz=0;
do{
ch = fgetc(myfile);
if(ch == '\n'){
siz++;
data[i].s[cur] = '\0';
inp[i].s[cur] = '\0';
data[i].fit = 0;
inp[i].fit = 0;
strcpy(data[i].s,encoding(data[i].s));
printf("%s\n",data[i].s);
i++;
cur = 0;
}else{
if(ch == ',')
continue;
if(ch =='*')
ch = '0';
data[i].s[cur] = ch;
inp[i].s[cur] = ch;
cur++;
}
}while(ch != EOF);
fclose(myfile);
return siz;
}
float fittness(char *s,int size_train)
{
char st[60];
char *b=st;
int i=0,pos=0,neg=0,clas=0,k=0,j=0;
float f1,f2,f3;
strcpy(st,s);
for(i=0;i<size_train;i++)
{
for(j=0;train[i][j]!='\0';j++)
{
if(st[j+1]=='\0' && train[i][j]==st[j])
{
pos++;
continue;
}
else if(st[j+1]=='\0' && train[i][j]!=st[j])
{
neg++;
continue;
}
else if(st[j]=='0')
continue;
else if(train[i][j]=='0')
continue;
else if(st[j]!='0' && train[i][j]!='0' && train[i][j]==st[j])
continue;
else if(st[j]!='0' && train[i][j]!='0' && train[i][j]!=st[j])
break;
}
for(j=0;train[i][j]!='\0';j++)
{
if(st[j+1]=='\0' && train[i][j]==st[j])
{
clas++;
continue;
}
}
}
k=precon(st);
f1=(float)pos-(float)neg;
f2=f1/(float)clas;
f3=f2+1/(float)k;
return f3;
}
int main()
{
char s[60];
scanf("%s",&s);
printf("%s\n",s);
int k=0;
k=precon(s);
printf("%d",k);
return 0;
}