-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenomeHandler.cs
74 lines (67 loc) · 2.82 KB
/
GenomeHandler.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace C_EcoSimApp
{
internal class GenomeHandler
{
internal static string RandomBits(int lenght, Random random)
{
string res = "";
for (int i = 0; i < lenght; i++)
{
int currbit = random.Next(0, 2);
currbit.ToString();
res += currbit.ToString();
}
return res;
}
internal static Genome GenerateGenome(int componentID_len, int floatACC_len, int components_len, int connections_len)
{
string wholegenome = "";
Random random = new Random();
//Components
List<Component> components = new List<Component>();
for (int i = 0;i<components_len; i++)
{
//component generation, could be improved by not initializing two components (see "*")
string ComponentID = RandomBits(componentID_len, random);
wholegenome += ComponentID;
List<string> ComponentStats = new List<string>();
for (int j = 0; j < 5; j++)
{
string currentstat = RandomBits(floatACC_len, random);
wholegenome += currentstat;
ComponentStats.Add(currentstat);
}
//*
Component strcomponent = new Component();
strcomponent.STRcomponent_ID = ComponentID;
strcomponent.STRcomponents_stats = ComponentStats;
//*
Component component = strcomponent.TranslateComponent();
components.Add(component);
}
//Connections
List<Connection> connections = new List<Connection>();
for (int i = 0;i<connections_len; i++)
{
string connectionStart = RandomBits(5, random);
string connectionEND = RandomBits(5, random);
string weight = RandomBits(floatACC_len,random);
string bias = RandomBits(floatACC_len, random);
//Small Option Start/End
string optionStart = RandomBits(1, random);
string optionEnd = RandomBits(1, random);
wholegenome += connectionStart + weight + bias + connectionEND + optionStart + optionEnd;
Connection connection = new Connection(connectionStart,connectionEND, weight, bias, optionStart, optionEnd);
connections.Add(connection);
}
Genome genome = new Genome(components, connections, wholegenome);
return genome;
}
}
}