Example #1
0
        public static bool ConstructiveComparator(ConstructiveResult result, KnapsackReferenceSolution referenceSolution)
        {
            //Calculate and save epsilon
            var optimalPrice = referenceSolution.Price;
            var actualPrice  = result.Configuration.Price;

            if (Math.Max(actualPrice, optimalPrice) == 0)
            {
                result.Epsilon = 0;
            }
            else
            {
                result.Epsilon = (float)Math.Abs(actualPrice - optimalPrice) / Math.Max(actualPrice, optimalPrice);
            }

            if (result.Configuration.Price != referenceSolution.Price || result.Configuration.Weight > result.KnapsackInstance.KnapsackSize)
            {
                Console.WriteLine($"Permutation instance solution (id {result.KnapsackInstance.Id}) incorrect," +
                                  $" result: {OutputWriter.ItemVectorToString(result.Configuration.ItemVector)} (price {result.Configuration.Price})" +
                                  $" expected result: {OutputWriter.ItemVectorToString(referenceSolution.ItemVector)} (price {referenceSolution.Price})");
                return(false);
            }
            return(true);
        }
Example #2
0
 public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData)
 {
     return(OutputWriter.ItemVectorToString((IList <bool>)value));
 }