<commit_before>﻿using GeneticSharporithm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneticSharporithmProgram
{
    public class FitnessEvaluator : IFitnessEvaluator<string>
    {
        public string Target { get; private set; }

        public FitnessEvaluator(string target)
        {
            Target = target;
        }

        /// <summary>
        /// 1 is perfect match, 0 is perfect mismatch.
        /// 
        /// 
        /// </summary>
        public double ComputeFitness(string genes)
        {
            var evaluation = 0d;
            
            // assuming both genes and target have same length
            for(int i = 0; i < Target.Length; i++)
            {
                var targetValue = (int)Target[i];
                var geneValue = (int)genes[i];

                if(targetValue == geneValue)
                {
                    evaluation += 1;
                } else
                {
                    evaluation = 1d / (Math.Abs(targetValue - geneValue));
                }
            }

            return evaluation / Target.Length;
        }
    }
}<commit_msg>slightly changed evaluation<commit_after>﻿using GeneticSharporithm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneticSharporithmProgram
{
    public class FitnessEvaluator : IFitnessEvaluator<string>
    {
        public string Target { get; private set; }

        public FitnessEvaluator(string target)
        {
            Target = target;
        }

        /// <summary>
        /// 1 is perfect match, 0 is perfect mismatch.
        /// 
        /// 
        /// </summary>
        public double ComputeFitness(string genes)
        {
            var evaluation = 0d;
            
            // assuming both genes and target have same length
            for(int i = 0; i < Target.Length; i++)
            {
                var targetValue = (int)Target[i];
                var geneValue = (int)genes[i];

                if(targetValue == geneValue)
                {
                    evaluation += 1;
                } else
                {
                    evaluation = 1d / (1.5 * Math.Abs(targetValue - geneValue));
                }
            }

            return evaluation / Target.Length;
        }
    }
}
{'fraction_non_alphanumeric': 0.09105960264900662, 'fraction_numerical': 0.005794701986754967, 'mean_word_length': 1.369607843137255, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6950949', 'n_tokens_mistral': 655, 'n_tokens_neox': 604, 'n_words': 159}