using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EvoBoat.EvoAlg;
using EvoBoat.EvoAlg.BBO;

namespace EvoBoat.EvoAlg.IntDivision
{
    public class IntDiv_BlendBBOAlg<P,S> : BlendBBOAlg<P, S, IntVector, int>
        where P : IntDivisionProblem<S>
        where S : VecSolution<IntVector, int>, new()
    {
        public IntDiv_BlendBBOAlg() : base()
        { }

        public IntDiv_BlendBBOAlg(P problem, int seed = 0) : base(problem, seed)
        {
            this.Factory = new IntDivisionSolutionFactory<P, S>(problem);
        }

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

        public override int Blend(S sol1, S sol2, int d)
        {
            return (sol1.Content[d] < sol2.Content[d]) ? Rand.Next(sol1.Content[d], sol2.Content[d] + 1) : Rand.Next(sol2.Content[d], sol1.Content[d] + 1);
        }

        public override void Repair(S sol, int index, int d, int olde)
        {
            Problem.RepairAt(this, sol, d, sol.Content[d] - olde);
        }

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