Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -16,13 +16,13 @@ randomChar
|
|||
extension evoHelper
|
||||
{
|
||||
randomString()
|
||||
= 0.repeatTill(self).selectBy:(x => randomChar).summarize(new StringWriter());
|
||||
= 0.repeatTill(self).selectBy::(x => randomChar).summarize(new StringWriter());
|
||||
|
||||
fitnessOf(s)
|
||||
= self.zipBy(s, (a,b => a==b ? 1 : 0)).summarize(new Integer()).toInt();
|
||||
|
||||
mutate(p)
|
||||
= self.selectBy:(ch => rnd.nextReal() <= p ? randomChar : ch).summarize(new StringWriter());
|
||||
= self.selectBy::(ch => rnd.nextReal() <= p ? randomChar : ch).summarize(new StringWriter());
|
||||
}
|
||||
|
||||
class EvoAlgorithm : Enumerator
|
||||
|
|
@ -47,9 +47,9 @@ class EvoAlgorithm : Enumerator
|
|||
if (_target == _current)
|
||||
{ ^ false };
|
||||
|
||||
auto variants := Array.allocate(_variantCount).populate:(x => _current.mutate:P );
|
||||
auto variants := Array.allocate(_variantCount).populate::(x => _current.mutate(P) );
|
||||
|
||||
_current := variants.sort:(a,b => a.fitnessOf:Target > b.fitnessOf:Target ).at:0;
|
||||
_current := variants.sort::(a,b => a.fitnessOf(Target) > b.fitnessOf(Target) ).at(0);
|
||||
|
||||
^ true
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ class EvoAlgorithm : Enumerator
|
|||
public program()
|
||||
{
|
||||
var attempt := new Integer();
|
||||
EvoAlgorithm.new(Target,C).forEach:(current)
|
||||
EvoAlgorithm.new(Target,C).forEach::(current)
|
||||
{
|
||||
console
|
||||
.printPaddingLeft(10,"#",attempt.append(1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue