예제 #1
0
        public void Load()
        {
            _results = new ScheduleResults();

            var data = Task<ScheduleResults>.Factory.StartNew(() => new PackageScheduler(_sessionSize, _talkSize).OrganizeSchedule(_results, _cancelToken), _cancelToken);

            var brute = new Task<ScheduleResults>(()=> new Solver(_sessionSize,_talkSize).Pack(_results,_cancelToken), TaskCreationOptions.LongRunning);

            brute.Start();

            _tasks = new Task[] { data, brute };
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="results"></param>
        /// <param name="cancelToken"></param>
        /// <returns></returns>
        public ScheduleResults OrganizeSchedule(ScheduleResults results, CancellationToken cancelToken)
        {
            IList<ResultContainer> containers = new List<ResultContainer>();
            while (_talkSize.Count > 0)
            {
                foreach (var containerSize in _sessionSize)
                {
                    if (cancelToken.IsCancellationRequested) return results;

                    var resultContainer = new ResultContainer { ContainerSize = containerSize };

                    int i;
                    bool firstPass = true;
                    for (i = 0; i < _talkSize.Count; )
                    {
                        if (cancelToken.IsCancellationRequested) return results;

                        int talk = _talkSize[i];
                        int sumScheduleSize = resultContainer.ScheduledSizes == null ? 0 : resultContainer.ScheduledSizes.Sum();

                        if ((resultContainer.ScheduledSizes == null || resultContainer.ScheduledSizes.Count <= 0 || (resultContainer.ScheduledSizes.Last() > talk || !firstPass))
                             && sumScheduleSize + talk <= containerSize)
                        {
                            resultContainer.ScheduledSizes.Add(talk);
                            _packedSchedule.Add(talk);
                            _talkSize.RemoveAt(i);

                            if (resultContainer.ScheduledSizes.Sum(x=>(int)x) == containerSize) i = _talkSize.Count; //int circuit inner for loop
                            continue;
                        }

                        i++;
                        //if we get to the end and we still have room enough for at least the smallest of our packages, then reset and go from
                        //largest to smallest, again.  until our smallest sized parcel remaining is bigger than the container delta.
                        if (i >= _talkSize.Count && sumScheduleSize < containerSize && containerSize - sumScheduleSize >= _talkSize.Last())
                        {
                            firstPass = false;
                            i = 0;
                        }
                    }

                    containers.Add(resultContainer);
                }
            }

            if (IsMoreOptimal(containers, results.CurrentBestResults))
            {
                results.CurrentBestResults = containers;
            }

            return results;
        }
예제 #3
0
 public ScheduleResults Pack(ScheduleResults results, CancellationToken cancelToken)
 {
     return results;
 }