示例#1
0
        private int ProcessJobs(int iteration)
        {
            while (_availableJobs.NotEmpty)
            {
                try
                {
                    iteration = GetIterationShiftResources(iteration);

                    var job = _availableJobs.Peek();
                    if (!AreResourcesAvailable(job, iteration))
                    {
                        if (job.FirstPossibleStart == -1)
                        {
                            job.FirstPossibleStart = iteration;
                        }
                        job.IterationAttempts++;

                        // incrememnt counter to next job expiratioin timepoint
                        if (_availableJobs.ProcessingJobs.Count == 0)
                        {
                            break;
                        }
                        return(_availableJobs.ProcessingJobs.Min(x => x.ScheduledEndTime) - 1);
                    }

                    job = _availableJobs.Dequeue(iteration);

                    _shiftManager.ScheduleJob(_currentShift, job);

                    var workers = new HashSet <IScheduledWorker>();
                    var tools   = new HashSet <IScheduledTool>();
                    var zone    = _zones.FirstOrDefault(x => x == job.Location);
                    if (zone == null)
                    {
                        zone = new Zone("NA", 100);
                    }

                    var exclusionZones = new HashSet <IScheduledZone>();

                    var scheduledZone  = new ScheduledZone(zone, iteration, job.ScheduledEndTime, job);
                    var inWorkInstance = new ScheduledJob(job, workers, tools, scheduledZone, exclusionZones, iteration);

                    // create a new entry in our timepoint event tracker
                    List <InWorkEvent> newEvents;
                    if (!_timepoints.TryGetValue(inWorkInstance.End, out newEvents))
                    {
                        newEvents = new List <InWorkEvent>();
                        _timepoints.Add(inWorkInstance.End, newEvents);
                    }

                    var inWorkEvent = new InWorkEvent(_currentShift, inWorkInstance);
                    newEvents.Add(inWorkEvent);
                    _inWorkEvents.Add(inWorkEvent);

                    if (zone != null)
                    {
                        zone.OccupySpot(inWorkEvent);
                    }
                }
                catch (Exception ex)
                {
                    string test = ex.Message;
                }
            }

            return(iteration);
        }