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

namespace EvoBoat.EvoAlg.ZOProg
{
    public class ZO_WWOAlg<P, S> : COMB_WWOAlg<P, S, BoolVector, bool>
        where P : ZeroOneProgProblem<S>
        where S : VecSolution<BoolVector, bool>, new()
    {
        public ZO_WWOAlg() : base()
        { }

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

        public override double MoveP(S sol, int index, int d)
        {
            sol.Content[d] = !sol.Content[d];
            return 0;
        }

        public override S Reflect(S sol, int index)
        {
            bool[] arr = new bool[Problem.Dimension];
            for (int d = 0; d < Problem.Dimension; d++)
                arr[d] =  (Rand.Next() % 2 == 0) ? sol.Content[d] : best.Content[d];
            S sol1 = new S() { Content = arr };
            this.Evaluate(sol1);
            return sol1;
        }
    }
}
