Ejemplo n.º 1
0
        /// <inheritdoc/>
        public AlgorithmOutput FindSolution(AlgorithmInput input)
        {
            var machines = input.Machines.ToList();
            var jobs     = input.Jobs.OrderByDescending(x => x.Duration).ToList();

            var machinesHeap = new Heap <int, MachineJobs>(HeapType.Min, machines.Count);

            foreach (var machine in machines)
            {
                machinesHeap.Insert(new Structures.ComparableElement <int, MachineJobs> {
                    Key = 0, Value = new MachineJobs(machine)
                });
            }


            foreach (var job in jobs)
            {
                var leastLoaded = machinesHeap.Extract();
                leastLoaded.Value.AddJob(job);
                leastLoaded.Key = leastLoaded.Value.Makespan;
                machinesHeap.Insert(leastLoaded);
            }

            return(new AlgorithmOutput
            {
                Makespan = machinesHeap.Values.Max(x => x.Makespan),
                Assignments = machinesHeap.Values.Select(x => new { Assignments = x.Jobs.Select(y => new Assignment {
                        Job = y, Machine = x.Machine
                    }) }).SelectMany(x => x.Assignments)
            });
        }
Ejemplo n.º 2
0
        private double GetSystemScore(AlgorithmInput input, AlgorithmResult result)
        {
            var inputStatistics = Statistics.FromUnmanagedImage(input.Image);
            var outputStatistics = Statistics.FromUnmanagedImage(result.Image);

            double inputScore = inputStatistics.GetContrastMeasure();
            double resultScore = outputStatistics.GetContrastMeasure();

            double finalScore = resultScore/inputScore;
            return finalScore;
        }
Ejemplo n.º 3
0
        public void GreedyMaxCoverageTest(IEnumerable <int[]> sets, int count, int expected)
        {
            var algorithm = new GreedyMaxCoverageAlgorithm();
            var input     = new AlgorithmInput
            {
                Sets          = sets,
                UsedSetsCount = count
            };
            var output = algorithm.FindSolution(input);

            output.Count.Should().Be(expected);
        }
Ejemplo n.º 4
0
        private double GetSystemScore(AlgorithmInput input, AlgorithmResult result)
        {
            var inputStatistics  = Statistics.FromUnmanagedImage(input.Image);
            var outputStatistics = Statistics.FromUnmanagedImage(result.Image);

            double inputScore  = inputStatistics.GetContrastMeasure();
            double resultScore = outputStatistics.GetContrastMeasure();

            double finalScore = resultScore / inputScore;

            return(finalScore);
        }
Ejemplo n.º 5
0
        public void GrahamTest(int[] jobs, int machinesCount, int expectedMakespan)
        {
            var algorithm = new GrahamAlgorithm();
            var input     = new AlgorithmInput
            {
                Jobs = jobs.Select((x, index) => new Job {
                    Id = index + 1, Duration = x
                }),
                Machines = Enumerable.Range(0, machinesCount).Select((x, index) => new Machine {
                    Id = index
                })
            };
            var output = algorithm.FindSolution(input);

            output.Makespan.Should().Be(expectedMakespan);
        }
        public void ExecuteBeforeEveryTest()
        {
            _algorithmSequenceDataProvider = new AlgorithmSequenceDataProvider();

            _resultData = new AlgorithmInput()
            {
                SquadSize        = 2,
                AvgChecking      = 30,
                AvgShooting      = 66,
                AvgSkating       = 48,
                BenchSize        = 1,
                InitialDeviation = 0.75,
                NumberOfPlayers  = 5,
                NumberOfSquads   = 2
            };
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public AlgorithmOutput FindSolution(AlgorithmInput input)
        {
            var sets = input.Sets.ToList();

            if (sets.Count < input.UsedSetsCount)
            {
                throw new ArgumentException("Invalid UsedSetsCount value", nameof(input.UsedSetsCount));
            }

            var setElements = new HashSet <int>();
            var usedSets    = new List <int[]>();

            for (var i = 0; i < input.UsedSetsCount; ++i)
            {
                var bestSetIndex       = -1;
                var bestAddingElements = Array.Empty <int>();
                for (var j = 0; j < sets.Count; ++j)
                {
                    var set = sets[j];
                    var tempAddingElements = set.Where(x => !setElements.Contains(x)).ToArray();
                    if (tempAddingElements.Length <= bestAddingElements.Length)
                    {
                        continue;
                    }

                    bestAddingElements = tempAddingElements;
                    bestSetIndex       = j;
                }
                if (bestSetIndex == -1)
                {
                    break;
                }

                foreach (var adding in bestAddingElements)
                {
                    setElements.Add(adding);
                }
                usedSets.Add(sets[bestSetIndex]);
                sets.RemoveAt(bestSetIndex);
            }

            return(new AlgorithmOutput
            {
                Count = setElements.Count,
                UsedSets = usedSets
            });
        }
Ejemplo n.º 8
0
        public ActionResult HtmlInput(AlgorithmInput data)
        {
            _creator.InputData(data.GenerateAlgoritmInput());
            var antColonyAlgorithm = _creator.CreateAcAlgorithm();
            antColonyAlgorithm.Run();
            var result = antColonyAlgorithm.Result();
            using (var reader = new StreamReader(result))
            {
                ViewData["result"] = reader.ReadToEnd();
            }

            var dbModel = _creator.CreateDbModel();
            var dbResult = new AntColonyResult { Result = ViewData["result"].ToString() };
            _antColonyModelRep.Add(dbModel);
            dbModel = _antColonyModelRep.GetAll().Last();
            dbResult.ModelId = dbModel.ModelId;
            _antColonyResultRep.Add(dbResult);

            return View("Result");
        }
        public void ExecuteBeforeEveryTest()
        {
            _internalModelDataProvider = new AlgorithmInputProvider();
            _testlist = new List <SquadPlayer>()
            {
                new SquadPlayer()
                {
                    Id = "1", Name = "Sam Smith", Checking = 20, Shooting = 35, Skating = 50
                },
                new SquadPlayer()
                {
                    Id = "2", Name = "Sasa Trkulja", Checking = 50, Shooting = 90, Skating = 45
                },
                new SquadPlayer()
                {
                    Id = "3", Name = "Teddy Trkulja", Checking = 20, Shooting = 25, Skating = 50
                },
                new SquadPlayer()
                {
                    Id = "4", Name = "Adam Trkulja", Checking = 40, Shooting = 80, Skating = 25
                },
                new SquadPlayer()
                {
                    Id = "5", Name = "Sandra Trkulja", Checking = 20, Shooting = 100, Skating = 70
                }
            };

            _resultData = new AlgorithmInput()
            {
                SquadSize        = 2,
                AvgChecking      = 30,
                AvgShooting      = 66,
                AvgSkating       = 48,
                BenchSize        = 1,
                InitialDeviation = 0.75,
                NumberOfPlayers  = 5,
                NumberOfSquads   = 2
            };
        }
Ejemplo n.º 10
0
        private void SetAlgorithmInput()
        {
            algorithmInput = new AlgorithmInput
            {
                Time   = 10,
                People = new List <Person>()
            };

            for (int i = 0; i < 100; i++)
            {
                int from;
                int to;

                double eventP = r.NextDouble();
                if (eventP <= 0.25)
                {
                    from = 3;
                    while (true)
                    {
                        to = r.Next(0, 20);
                        if (to != from)
                        {
                            break;//保证to和from不同
                        }
                    }
                }
                else if (eventP <= 0.5)
                {
                    to = 3;
                    while (true)
                    {
                        from = r.Next(0, 20);
                        if (to != from)
                        {
                            break;//保证to和from不同
                        }
                    }
                }
                else
                {
                    from = r.Next(0, 20);
                    while (true)
                    {
                        to = r.Next(0, 20);
                        if (to != from)
                        {
                            break;//保证to和from不同
                        }
                    }
                }

                for (int j = 0; j < r.Next(1, 6); j++)
                {
                    Person p = new Person
                    {
                        from_floor    = from,
                        current_floor = from,
                        come_time     = i * 5 + 1,
                        to_floor      = to
                    };
                    algorithmInput.People.Add(p);
                    //algorithmInput.People[i * 3 + j] = p;
                }
            }
        }
        public void ProvideInternalModelDataInitialDeviationTest()
        {
            AlgorithmInput _internalModelData = _internalModelDataProvider.ProvideAlgorithmInput(2, _testlist);

            Assert.AreEqual(_resultData.InitialDeviation, _internalModelData.InitialDeviation);
        }
        public void ProvideInternalModelDataBenchSizeTest()
        {
            AlgorithmInput _internalModelData = _internalModelDataProvider.ProvideAlgorithmInput(2, _testlist);

            Assert.AreEqual(_resultData.BenchSize, _internalModelData.BenchSize);
        }
        public void ProvideInternalModelDataNumberOfPlayersTest()
        {
            AlgorithmInput _internalModelData = _internalModelDataProvider.ProvideAlgorithmInput(2, _testlist);

            Assert.AreEqual(_resultData.NumberOfPlayers, _internalModelData.NumberOfPlayers);
        }
        public void ProvideInternalModelDataAvgSkatingTest()
        {
            AlgorithmInput _internalModelData = _internalModelDataProvider.ProvideAlgorithmInput(2, _testlist);

            Assert.AreEqual(_resultData.AvgSkating, _internalModelData.AvgSkating);
        }
        public void ProvideInternalModelDataAvgAproxShoTest()
        {
            AlgorithmInput _internalModelData = _internalModelDataProvider.ProvideAlgorithmInput(2, _testlist);

            Assert.AreEqual(0, _internalModelData.AvgAproxSho);
        }
Ejemplo n.º 16
0
        public void ExecuteBeforeEveryTest()
        {
            testAlgorithmInput = new AlgorithmInput()
            {
                SquadSize        = 2,
                AvgChecking      = 64,
                AvgShooting      = 65,
                AvgSkating       = 78,
                BenchSize        = 1,
                InitialDeviation = 5,
                NumberOfPlayers  = 5,
                NumberOfSquads   = 2,
                AvgAproxChe      = -5,
                AvgAproxSho      = -5,
                AvgAproxSka      = -5
            };

            testPlayerList = new List <SquadPlayer>()
            {
                new SquadPlayer()
                {
                    Id = "1", Name = "Alex Carney", Checking = 92, Shooting = 98, Skating = 90
                },
                new SquadPlayer()
                {
                    Id = "2", Name = "Bob Smith", Checking = 50, Shooting = 60, Skating = 80
                },
                new SquadPlayer()
                {
                    Id = "3", Name = "Roy Talbot", Checking = 20, Shooting = 85, Skating = 60
                },
                new SquadPlayer()
                {
                    Id = "4", Name = "Jill White", Checking = 60, Shooting = 90, Skating = 70
                },
                new SquadPlayer()
                {
                    Id = "5", Name = "Jennifer Wu", Checking = 100, Shooting = 55, Skating = 94
                }
            };

            testAsdList = new List <AlgDynamicSequenceModel>()
            {
                new AlgDynamicSequenceModel()
                {
                    Average = 64, Deviation = 10, ItterationOrder = 0, Name = "Checking", AvgAprox = -5, SquadSize = 2
                },
                new AlgDynamicSequenceModel()
                {
                    Average = 65, Deviation = 10, ItterationOrder = 1, Name = "Shooting", AvgAprox = -5, SquadSize = 2
                },
                new AlgDynamicSequenceModel()
                {
                    Average = 78, Deviation = 10, ItterationOrder = 2, Name = "Skating", AvgAprox = -5, SquadSize = 2
                }
            };

            _squadsProvider = new SquadsProvider();
            testAlgorithmInput.SequenceData = testAsdList;
            testAlgorithmInput.AllPlayers   = testPlayerList;
        }