/// <summary>
        /// Inserts a solution in the list
        /// The decision variables can be null if the solution is read from a file; in
        /// that case, the domination tests are omitted
        /// </summary>
        /// <param name="solution">The solution to be inserted.</param>
        /// <returns>true if the operation success, and false if the solution is dominated or if an identical individual exists.</returns>
        public override bool Add(Solution solution)
        {
            if (SolutionsList.Count == 0)
            {
                SolutionsList.Add(solution);
                return(true);
            }
            else
            {
                List <Solution> copyList = SolutionsList.ToList();
                foreach (Solution s in copyList)
                {
                    int flag = dominance.Compare(solution, s);

                    if (flag == -1)
                    {
                        // A solution in the list is dominated by the new one
                        SolutionsList.Remove(s);
                    }
                    else if (flag == 0)
                    {
                        // Non-dominated solutions
                    }
                    else if (flag == 1)
                    {                     // The new solution is dominated
                        return(false);
                    }
                }

                //At this point, the solution is inserted into the list
                SolutionsList.Add(solution);

                return(true);
            }
        }
        /// <summary>
        /// Adds a <code>Solution</code> to the archive. If the <code>Solution</code>
        /// is dominated by any member of the archive then it is discarded. If the
        /// <code>Solution</code> dominates some members of the archive, these are
        /// removed. If the archive is full and the <code>Solution</code> has to be
        /// inserted, one <code>Solution</code> of the most populated hypercube of
        /// the adaptive grid is removed.
        /// </summary>
        /// <param name="solution">The <code>Solution</code></param>
        /// <returns>true if the <code>Solution</code> has been inserted, false otherwise.</returns>
        public override bool Add(Solution solution)
        {
            var iterator = SolutionsList.ToList();

            foreach (var element in iterator)
            {
                int flag = dominance.Compare(solution, element);
                if (flag == -1)
                {                 // The Individual to insert dominates other
                    // individuals in  the archive
                    SolutionsList.Remove(element);
                    int location = Grid.Location(element);
                    if (Grid.GetLocationDensity(location) > 1)
                    {                                  //The hypercube contains
                        Grid.RemoveSolution(location); //more than one individual
                    }
                    else
                    {
                        Grid.UpdateGrid(this);
                    }
                }
                else if (flag == 1)
                {                  // An Individual into the file dominates the
                    // solution to insert
                    return(false); // The solution will not be inserted
                }
            }

            // At this point, the solution may be inserted
            if (Size() == 0)
            {             //The archive is empty
                SolutionsList.Add(solution);
                Grid.UpdateGrid(this);
                return(true);
            }

            if (Size() < maxSize)
            {                                    //The archive is not full
                Grid.UpdateGrid(solution, this); // Update the grid if applicable
                int loc;
                loc = Grid.Location(solution);   // Get the location of the solution
                Grid.AddSolution(loc);           // Increment the density of the hypercube
                SolutionsList.Add(solution);     // Add the solution to the list
                return(true);
            }

            // At this point, the solution has to be inserted and the archive is full
            Grid.UpdateGrid(solution, this);
            int loca = Grid.Location(solution);

            if (loca == Grid.MostPopulated)
            {                  // The solution is in the
                // most populated hypercube
                return(false); // Not inserted
            }
            else
            {
                // Remove an solution from most populated area
                iterator = SolutionsList.ToList();
                bool removed = false;

                foreach (var element in iterator)
                {
                    if (!removed)
                    {
                        int location2 = Grid.Location(element);
                        if (location2 == Grid.MostPopulated)
                        {
                            SolutionsList.Remove(element);
                            Grid.RemoveSolution(location2);
                        }
                    }
                }
                // A solution from most populated hypercube has been removed,
                // insert now the solution
                Grid.AddSolution(loca);
                SolutionsList.Add(solution);
            }
            return(true);
        }