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

namespace EvoBoat.EvoAlg.IntProg
{
    public class IP_DEAlg<P,S> : DEAlg<P, S, IntVector, int>
        where P : IntProgProblem<S>
        where S : VecSolution<IntVector, int>, new()
    {
        public IP_DEAlg() : base()
        { }

        public IP_DEAlg(P problem, int seed = 0) : base(problem, seed)
        {
            this.Factory = new IntVectorSolutionFactory<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 IntVectorSolutionFactory<P, S>(Problem);
        }

        public override double Difference(int pos1, int pos2)
        {
            return pos1 - pos2;
        }

        public override int Increase(int pos, double v)
        {
            return (int)Math.Round(pos + v);
        }

        public override void Repair(S sol, int index, int d, int oldv)
        {
            if (sol.Content[d] < Problem.Lowers[d] || sol.Content[d] >= Problem.Uppers[d])
                sol.Content[d] =  Rand.Next(Problem.Lowers[d], Problem.Uppers[d]);
        }
    }
}
