-
Notifications
You must be signed in to change notification settings - Fork 0
/
AGUnPunto.cs
38 lines (33 loc) · 1.05 KB
/
AGUnPunto.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prGenetico
{
class AGUnPunto:AlgoritmoGenetico
{
public AGUnPunto(int tP, int tI, int np, double pMut, IProblema pr):base(tP,tI,np,pMut,pr)
{
}
public override Cromosoma Recombinar(Cromosoma cr1, Cromosoma cr2)
{
if (cr1.Longitud != cr2.Longitud) { throw new Exception("Intenta recombinar cromosomas de distinta longitud"); }
else
{
Random rnd = new Random();
int punto = rnd.Next(cr1.Longitud);
Cromosoma nuevoCromosoma = new Cromosoma(cr1.Longitud, false);
for (int i = 0; i < punto; i++)
{
nuevoCromosoma[i] = cr1[i];
}
for (int i = punto; i < cr1.Longitud; i++)
{
nuevoCromosoma[i] = cr2[i];
}
return nuevoCromosoma;
}
}
}
}