using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EvoBoat.EvoAlg.BBO
{
    public class Num_BlendBBOAlg<S> : BlendBBOAlg<NumOptProblem<S>, S, Vector, double>
        where S : VecSolution<Vector, double>, new()
    {
        public Num_BlendBBOAlg() : base()
        { }
        
        public Num_BlendBBOAlg(NumOptProblem<S> problem, int seed = 0) : base(problem, seed)
        {
            this.Factory = new VectorSolutionFactory<NumOptProblem<S>, S>(problem);
        }

        public override void SetFactory()
        {
            if (Problem == null)
                throw new ArgumentNullException("Please assign the problem instance before set the factory");
            Factory = new VectorSolutionFactory<NumOptProblem<S>, S>(Problem);
        }

        public override double Blend(S sol1, S sol2, int d)
        {
            double a = Rand.NextDouble();
            return a * sol1.Content[d] + (1 - a) * sol2.Content[d];
        }

        public override S Mutate(S sol, int index)
        {
            return GA.Num_GA<S>.MutationFunc(this, sol, index);
        }
    }
}
