Ejemplo n.º 1
0
 public TestResult(double averageError, double maxError, double averageTime, double maxTime, int n, GeneratorSetup generatorSetup)
 {
     AverageError   = averageError;
     MaxError       = maxError;
     AverageTime    = averageTime;
     MaxTime        = maxTime;
     N              = n;
     GeneratorSetup = generatorSetup;
 }
Ejemplo n.º 2
0
 private static void GenerateRatioCapacityToWeightSum(ICollection <GeneratorSetup> list)
 {
     for (var f = 0.1f; f <= 1.0f; f += 0.05f)
     {
         GeneratorSetup gen = new GeneratorSetup();
         gen.GeneratorName            = MethodBase.GetCurrentMethod().Name;
         gen.RatioCapacityToWeightSum = f;
         list.Add(gen);
     }
 }
Ejemplo n.º 3
0
 private static void GenerateExponent(ICollection <GeneratorSetup> list)
 {
     for (var f = 0.01f; f <= 3.0f; f += 0.05f)
     {
         GeneratorSetup gen = new GeneratorSetup();
         gen.GeneratorName = MethodBase.GetCurrentMethod().Name;
         gen.Exponent      = f;
         list.Add(gen);
     }
 }
Ejemplo n.º 4
0
 private static void GenerateMaxCost(ICollection <GeneratorSetup> list)
 {
     for (var i = 100; i <= 5100; i += 500)
     {
         GeneratorSetup gen = new GeneratorSetup();
         gen.GeneratorName = MethodBase.GetCurrentMethod().Name;
         gen.MaxCost       = i;
         list.Add(gen);
     }
 }
Ejemplo n.º 5
0
 public GeneratorSetup(GeneratorSetup orig)
 {
     StartingId               = orig.StartingId;
     ItemCount                = orig.ItemCount;
     InstanceCount            = orig.InstanceCount;
     RatioCapacityToWeightSum = orig.RatioCapacityToWeightSum;
     MaxWeight                = orig.MaxWeight;
     MaxCost       = orig.MaxCost;
     Exponent      = orig.Exponent;
     EqualThings   = orig.EqualThings;
     LessThings    = orig.LessThings;
     GeneratorName = orig.GeneratorName;
 }
Ejemplo n.º 6
0
        public ResultPrinter(List <TestResult> testResults, Algorithm algorithm)
        {
            _testResults = testResults;
            _algorithm   = algorithm;

            GeneratorSetup generatorSetup = null;

            if (_testResults.Count > 0)
            {
                generatorSetup = _testResults[0].GeneratorSetup;
            }

            if (File.Exists(GetFileName(null)))
            {
                File.Delete(GetFileName(null));
            }
        }
Ejemplo n.º 7
0
        public Test(StreamReader streamReader, GeneratorSetup generatorSetup)
        {
            KnapsackReader knapsackReader = new KnapsackReader(streamReader);

            _generatorSetup = generatorSetup;

            Knapsack knapsack;

            do
            {
                knapsack = knapsackReader.ReadKnapsack();

                if (knapsack != null)
                {
                    _knapsacks.Add(knapsack);
                }
            } while (knapsack != null);
        }
Ejemplo n.º 8
0
        private static void GenerateLessEqualGreater(ICollection <GeneratorSetup> list)
        {
            var genL = new GeneratorSetup();
            var genE = new GeneratorSetup();
            var genG = new GeneratorSetup();

            genL.LessThings  = true;
            genL.EqualThings = false;

            genE.EqualThings = true;

            genG.LessThings  = false;
            genG.EqualThings = false;

            list.Add(genL);
            list.Add(genE);
            list.Add(genG);

            genL.GeneratorName = MethodBase.GetCurrentMethod().Name;
            genE.GeneratorName = MethodBase.GetCurrentMethod().Name;
            genG.GeneratorName = MethodBase.GetCurrentMethod().Name;
        }
Ejemplo n.º 9
0
        private StreamReader GenerateTest(GeneratorSetup generatorSetup)
        {
            StringBuilder outputBuilder = new StringBuilder();
            string        output        = "";

            using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
                using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
                {
                    using (Process process = new Process())
                    {
                        process.StartInfo.FileName               = "../../knapgen.exe";
                        process.StartInfo.UseShellExecute        = false;
                        process.EnableRaisingEvents              = true;
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.RedirectStandardError  = true;
                        process.StartInfo.Arguments              =
                            $"-I {generatorSetup.StartingId}" +
                            $" -n {generatorSetup.ItemCount}" +
                            $" -N {generatorSetup.InstanceCount}" +
                            $" -m {generatorSetup.RatioCapacityToWeightSum}" +
                            $" -W {generatorSetup.MaxWeight}" +
                            $" -C {generatorSetup.MaxCost}" +
                            $" -k {generatorSetup.Exponent}" +
                            $" -d {(generatorSetup.EqualThings ? 0 : (generatorSetup.LessThings ? -1 : 1))}";

                        try
                        {
                            process.OutputDataReceived += (sender, e) =>
                            {
                                if (e.Data != null)
                                {
                                    outputBuilder.AppendLine(e.Data);
                                }
                            };
                            process.ErrorDataReceived += (sender, e) =>
                            {
                                if (e.Data != null)
                                {
                                    // outputBuilder.AppendLine(e.Data);
                                }
                            };

                            process.Start();

                            process.BeginOutputReadLine();
                            process.BeginErrorReadLine();

                            process.WaitForExit();

                            output = outputBuilder.ToString();
                        }
                        finally
                        {
                            outputWaitHandle.WaitOne(1);
                            errorWaitHandle.WaitOne(1);
                        }
                    }
                }

            return(new StreamReader(GenerateStreamFromString(output)));
        }