private Zone(int id, string name, int maxOccupants) : this() { if (id == -1) { id = this.NextId(); } ID = id; Name = name; MaxOccupants = maxOccupants; _availableSpots = MaxOccupants; _occupiedSpots = new InWorkEvent[MaxOccupants]; }
public int OccupySpot(InWorkEvent item) { if (_availableSpots > 0) { for (int i = 0; i < MaxOccupants; i++) { if (_occupiedSpots[i] == null) { _occupiedSpots[i] = item; return _availableSpots--; } } } return -1; }
public int OccupySpot(InWorkEvent item) { if (_availableSpots > 0) { for (int i = 0; i < MaxOccupants; i++) { if (_occupiedSpots[i] == null) { _occupiedSpots[i] = item; return(_availableSpots--); } } } return(-1); }
public bool WorkCompleted(InWorkEvent item) { InWorkEvent found = null; for (int i = 0; i < MaxOccupants; i++) { if (_occupiedSpots[i] != null && _occupiedSpots[i].Owner.Job.ID == item.Owner.Job.ID) { found = _occupiedSpots[i]; _occupiedSpots[i] = null; _availableSpots++; break; } } return found != null; }
public bool WorkCompleted(InWorkEvent item) { InWorkEvent found = null; for (int i = 0; i < MaxOccupants; i++) { if (_occupiedSpots[i] != null && _occupiedSpots[i].Owner.Job.ID == item.Owner.Job.ID) { found = _occupiedSpots[i]; _occupiedSpots[i] = null; _availableSpots++; break; } } return(found != null); }
private void ProcessCompletionEvent(InWorkEvent inWorkEvent) { try { // put shift resources back into availability pool _shiftManager.CompleteJob(inWorkEvent.Shift, inWorkEvent.Owner); var completedJob = inWorkEvent.Owner.Job; // job is complete, update status _availableJobs.Complete(completedJob, inWorkEvent.End); // remove job from jobs needing to be processed _jobs.Remove(completedJob); _inWorkEvents.Remove(inWorkEvent); var zone = inWorkEvent.Owner.LocationZone; if (zone != null) { zone.Resource.WorkCompleted(inWorkEvent); } // check to see if the completing job has successors that are ready to be worked foreach (var job in completedJob.Successors.OrderBy(x => x.Duration)) { var ready = job.Predecessors.All(x => _availableJobs.ProcessedJobs.ContainsKey(x.ID)); if (ready) { _availableJobs.Enqueue(job); } } } catch (Exception ex) { string test = ex.Message; } }
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; }