﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SoftMod.Framework.Solution;

namespace SoftMod.Framework.Modules.Comparator
{
    class SPEA2Comparator
    {
        /// <summary>
        /// SPEA2 fitness comparator class
        /// </summary>

        /// <summary>
        /// Compare two solutions for dominance using spea2 strength values
        /// </summary>
        public int Compare(Root solution_1, Root solution_2)
        {
            // Initialise auxilliary variables
            // Get fitness values for each solution
            double fitness_1 = (double)solution_1.getSolutionType().getExternalVariable("SPEA2 Strength");
            double fitness_2 = (double)solution_2.getSolutionType().getExternalVariable("SPEA2 Strength");
            // Return overall dominance
            if (fitness_1 == fitness_2)
            {
                // No one solution dominates the other
                return 0;
            }
            if (fitness_1 < fitness_2)
            {
                // Solution 1 dominates
                return -1;
            }
            // Solution 2 dominates
            return 1;
        }
    }
}
