Repository navigation
Expand file tree
/
Copy pathMutasyon.cs
More file actions
87 lines (76 loc) · 3.3 KB
/
Copy pathMutasyon.cs
File metadata and controls
87 lines (76 loc) · 3.3 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GenetikAlgoritma;
namespace GenetikAlgoritma
{
public abstract class Mutasyon
{
public Random rnd;
public double mutosyonKatsayisi;
public Mutasyon()
{
rnd = new Random();
}
public void setMutasyonKatsayi(double mutosyonKatsayisi)
{
this.mutosyonKatsayisi = mutosyonKatsayisi;
}
public static Mutasyon mutasyonYap(string mutasyonAdi)
{
switch (mutasyonAdi)
{
case "Toplama": return new Toplama();
case "Cikarma": return new Cikarma();
default: return null;
}
}
public abstract Kromozom mutasyon(Kromozom kromozom, Form1 form);
}
public class Toplama : Mutasyon
{
public Toplama()
{
}
override public Kromozom mutasyon(Kromozom kromozom, Form1 form)
{
Kromozom krm = new Kromozom();
Gen gen = new Gen();
int indis = rnd.Next(0, form.d_genAdeti); //Kromozomumuz 2 adet genden oluşacaktır onun için hangisi ile işlem yapacaksak onun indisini belirleriz.
gen = (Gen)kromozom.listGenler[indis].Clone();
krm = kromozom.getKromozom();
gen.genDeger += mutosyonKatsayisi;
if (gen.genDeger > form.fonksiyon.getUstSinir())
gen.genDeger = form.fonksiyon.getUstSinir() - rnd.NextDouble();
if (gen.genDeger < form.fonksiyon.getAltSinir())
gen.genDeger = form.fonksiyon.getAltSinir() + rnd.NextDouble();
krm.listGenler[indis].genDeger = gen.genDeger;
return krm;
}
}
public class Cikarma : Mutasyon
{
public Cikarma()
{
}
override public Kromozom mutasyon(Kromozom kromozom, Form1 form)
{
Kromozom krm = new Kromozom();
Gen gen = new Gen();
int indis = rnd.Next(0, form.d_genAdeti); //Kromozomumuz 2 adet genden oluşacaktır onun için hangisi ile işlem yapacaksak onun indisini belirleriz.
gen = (Gen)kromozom.listGenler[indis].Clone();
krm = kromozom.getKromozom();
gen.genDeger -= mutosyonKatsayisi;
if (gen.genDeger > form.fonksiyon.getUstSinir())
gen.genDeger = form.fonksiyon.getUstSinir() - rnd.NextDouble();
if (gen.genDeger < form.fonksiyon.getAltSinir())
gen.genDeger = form.fonksiyon.getAltSinir() + rnd.NextDouble();
krm.listGenler[indis].genDeger = gen.genDeger;
// MessageBox.Show("fonkMutasyonToplama" + krm.listGenler[indis].genDeger);
return krm;
}
}
}