public PackedBoxList DoVolumePacking() { var packedBoxes = new PackedBoxList(); //Keep going until everything packed while (_items.Count > 0) { var packedBoxesIteration = new List <PackedBox>(); //Loop through boxes starting with smallest, see what happens foreach (var box in _boxes) { var volumePacker = new VolumePacker(box, _items.Clone()); var packedBox = volumePacker.Pack(); if (packedBox.PackedItems.Count != 0) { packedBoxesIteration.Add(packedBox); //Have we found a single box that contains everything? if (packedBox.PackedItems.Count == _items.Count) { break; } } } // if any items is packed, then any chanses for this in next iteration if (packedBoxesIteration.Count == 0) { var ex = new ItemTooLargeException(); ex.Data.Add("item", _items.Top()); throw ex; } //Find best box of iteration, and remove packed items from unpacked list var bestBox = FindBestBoxFromIteration(packedBoxesIteration); foreach (var itemToRemove in bestBox.PackedItems) { _items.Remove(itemToRemove.Item); } packedBoxes.Insert(bestBox); } return(packedBoxes); }
public Schedule CreateScheduleFromEncoding(JSMEncoding solution, ItemList <Job> jobData) { ItemList <Permutation> jobSequenceMatrix = solution.JobSequenceMatrix; var jobs = (ItemList <Job>)jobData.Clone(); var resultingSchedule = new Schedule(jobs[0].Tasks.Count); //Reset scheduled tasks in result foreach (Job j in jobs) { foreach (Task t in j.Tasks) { t.IsScheduled = false; } } //GT-Algorithm //STEP 0 - Compute a list of "earliest operations" ItemList <Task> earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs); while (earliestTasksList.Count > 0) { //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time Task minimal = GTAlgorithmUtils.GetTaskWithMinimalEC(earliestTasksList, resultingSchedule); int conflictedResourceNr = minimal.ResourceNr; Resource conflictedResource = resultingSchedule.Resources[conflictedResourceNr]; //STEP 2 - Compute a conflict set of all operations that can be scheduled on the conflicted resource ItemList <Task> conflictSet = GTAlgorithmUtils.GetConflictSetForTask(minimal, earliestTasksList, jobs, resultingSchedule); //STEP 3 - Select a task from the conflict set int progressOnResource = conflictedResource.Tasks.Count; Task selectedTask = SelectTaskFromConflictSet(conflictedResourceNr, progressOnResource, conflictSet, jobSequenceMatrix); //STEP 4 - Add the selected task to the current schedule selectedTask.IsScheduled = true; double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(selectedTask, resultingSchedule); resultingSchedule.ScheduleTask(selectedTask.ResourceNr, startTime, selectedTask.Duration, selectedTask.JobNr); //STEP 5 - Back to STEP 1 earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs); } return(resultingSchedule); }
public Schedule CreateScheduleFromEncoding(JSMEncoding solution, ItemList<Job> jobData) { ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix; var jobs = (ItemList<Job>)jobData.Clone(); var resultingSchedule = new Schedule(jobs[0].Tasks.Count); //Reset scheduled tasks in result foreach (Job j in jobs) { foreach (Task t in j.Tasks) { t.IsScheduled = false; } } //GT-Algorithm //STEP 0 - Compute a list of "earliest operations" ItemList<Task> earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs); while (earliestTasksList.Count > 0) { //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time Task minimal = GTAlgorithmUtils.GetTaskWithMinimalEC(earliestTasksList, resultingSchedule); int conflictedResourceNr = minimal.ResourceNr; Resource conflictedResource = resultingSchedule.Resources[conflictedResourceNr]; //STEP 2 - Compute a conflict set of all operations that can be scheduled on the conflicted resource ItemList<Task> conflictSet = GTAlgorithmUtils.GetConflictSetForTask(minimal, earliestTasksList, jobs, resultingSchedule); //STEP 3 - Select a task from the conflict set int progressOnResource = conflictedResource.Tasks.Count; Task selectedTask = SelectTaskFromConflictSet(conflictedResourceNr, progressOnResource, conflictSet, jobSequenceMatrix); //STEP 4 - Add the selected task to the current schedule selectedTask.IsScheduled = true; double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(selectedTask, resultingSchedule); resultingSchedule.ScheduleTask(selectedTask.ResourceNr, startTime, selectedTask.Duration, selectedTask.JobNr); //STEP 5 - Back to STEP 1 earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs); } return resultingSchedule; }