Ejemplo n.º 1
0
        public IActionResult Index()
        {
            IAssignTask nn       = new NearestNeighborAlgorithm();
            var         nnResult = nn.AssignTo(Mock.Candidates, Mock.Targets[0]);

            IAssignTask rr       = new RoundRobinAlgorithm();
            var         rrResult = rr.AssignTo(Mock.Candidates, Mock.Targets[1], 3);

            //List<Data.Candidate> mockCandidates =
            //    new List<Data.Candidate>(Mock.Candidates
            //    .Select(c => new Data.Candidate
            //    {
            //        Load = c.Load,
            //        Latitude = c.Location.Latitude,
            //        Longitude = c.Location.Longitude
            //    }));
            //string[] nameCandidates = { "Abdul", "Bambang", "Chairul", "Deni", "Edo" };
            //int[] travelCandidates = { 1520, 300, 610, 1280, 490 };

            //for (int i = 0; i < mockCandidates.Count ; i++)
            //{
            //    mockCandidates[i].Name = nameCandidates[i];
            //    mockCandidates[i].TotalTravel = travelCandidates[i];

            //    var candidate = _dataBusiness.ModifyCandidate(mockCandidates[i]);
            //}

            //List<Data.Target> mockTargets =
            //    new List<Data.Target>(Mock.Targets
            //    .Select(t => new Data.Target
            //    {
            //        Latitude = t.Location.Latitude,
            //        Longitude = t.Location.Longitude,
            //    }));
            //string[] nameTargets = { "Ujang", "Udin" };

            //for (int i = 0; i < mockTargets.Count; i++)
            //{
            //    mockTargets[i].Name = nameTargets[i];

            //    var target = _dataBusiness.ModifyTarget(mockTargets[i]);
            //}

            var candidates = _dataBusiness.GetCandidates();
            var targets    = _dataBusiness.GetTargets();

            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult Simulation()
        {
            #if DEBUG
            // var stopWatch = Stopwatch.StartNew();

            // //Seed target
            // for (int i = 0; i < 50; i++)
            // {
            //     var location = Helpers.GeneratorHelper.GenerateNearbyLocation(-6.8986037, 107.6225108, 10000);
            //     var target = new Data.Target
            //     {
            //         Name = Helpers.GeneratorHelper.GenerateName(7),
            //         Latitude = location.Latitude,
            //         Longitude = location.Longitude
            //     };
            //     _dataBusiness.ModifyTarget(target);
            // }

            // //Seed candidate
            // for (int i = 0; i < 1000; i++)
            // {
            //     var load = Helpers.GeneratorHelper.GenerateLoad(0, 20);
            //     var location = Helpers.GeneratorHelper.GenerateNearbyLocation(-6.8986037, 107.6225108, 10000);
            //     var candidate = new Data.Candidate
            //     {
            //         Name = Helpers.GeneratorHelper.GenerateName(7),
            //         Latitude = location.Latitude,
            //         Longitude = location.Longitude,
            //         Load = load,
            //         TotalTravel = Helpers.GeneratorHelper.GenerateTotalTravel(load)
            //     };
            //     _dataBusiness.ModifyCandidate(candidate);
            // }

            // //Delete candidate in database
            // _dataBusiness.DeleteCandidates(_dataBusiness.GetCandidates().TakeLast(500));

            // stopWatch.Stop();
            // var elapsedTime = stopWatch.Elapsed;

            // var writed = await _dataBusiness.CreateJsonFile($"Percobaan isi target", _dataBusiness.GetTargets());

            // //Clean database
            // _ = _dataBusiness.DeleteTargets(_dataBusiness.GetTargets().Take(2));
            // _ = _dataBusiness.DeleteCandidates(_dataBusiness.GetCandidates().Take(7));
            // var modif = _dataBusiness.GetCandidates().Where(x => x.IsAssigned);
            // foreach (var item in modif)
            // {
            //     item.IsAssigned = false;
            //     _ = _dataBusiness.ModifyCandidate(item);
            // }
            // _ = _dataBusiness.DeleteTransactions(_dataBusiness.GetTransactions());
            #endif

            return(View(new SimulationViewModel()
            {
                TargetTable = _dataBusiness.GetTargets()
                              .Select(x => new TargetViewModel
                {
                    Id = x.TargetId,
                    Name = x.Name,
                    Latitude = x.Latitude,
                    Longitude = x.Longitude
                })
                              .ToList(),
                CandidateTable = new List <CandidateViewModel>(),
                TransactionHistory = _dataBusiness.GetTransactionHistories(),
                SelectedCandidate = new TransactionHistoryViewModel()
            }));
        }