-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of 2D Packing Node following Issue #11
- Loading branch information
1 parent
059174a
commit 4f7fa37
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
Miscellany/ContainerPacking/PackingService/PackRectangle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CromulentBisgetti.ContainerPacking.Entities; //added to interact with ContainerPacking | ||
using Autodesk.DesignScript.Runtime; | ||
|
||
namespace Miscellany.ContainerPacking | ||
{ | ||
/// <summary> | ||
/// PackingService | ||
/// </summary> | ||
public static partial class PackingService | ||
{ | ||
#region PackRectangle | ||
/// <summary> | ||
/// Packs in Two Dimensions, ignoring dim3 for the Items and Z for the Container | ||
/// </summary> | ||
/// <param name="container">Container</param> | ||
/// <param name="itemsToPack">Items to pack</param> | ||
/// <param name="algorithm">Algorithm ID</param> | ||
/// <returns name="packedItems">Items that were successfully packed</returns> | ||
/// <returns name="unpackedItems">Items that were not packed</returns> | ||
/// <returns name="isCompletePack">Are all items packed?</returns> | ||
/// <returns name="packTimeInMilliseconds">Total pack time</returns> | ||
/// <returns name="percentContainerVolumePacked">Percentage of the container that is packed</returns> | ||
/// <returns name="percentItemVolumePacked">Percentage of items packed</returns> | ||
/// <search> | ||
/// containerpacking | ||
/// </search> | ||
[MultiReturn(new[] { "packedItems", "unpackedItems", "isCompletePack", "packTimeInMilliseconds", "percentContainerVolumePacked", "percentItemVolumePacked" })] | ||
public static Dictionary<string, object> PackRectangle(Miscellany.ContainerPacking.Entities.Container container, List<Miscellany.ContainerPacking.Entities.Item> itemsToPack, int algorithm = 1) | ||
{ | ||
//Create CromulentBisgetti Container | ||
Container con = ContainerToCB(container); | ||
|
||
//Create CromulentBisgetti Items | ||
List<Item> items = new List<Item>(); | ||
foreach (Miscellany.ContainerPacking.Entities.Item i in itemsToPack) | ||
{ | ||
Item cbItem = ItemToCB(i); | ||
items.Add(cbItem); | ||
} | ||
|
||
//Create list with single container | ||
List<Container> containers = new List<Container> { con }; | ||
|
||
//Select algorithm using integer | ||
List<int> algorithms = new List<int> { algorithm }; | ||
|
||
//Get container packing result | ||
ContainerPackingResult containerPackingResult = CromulentBisgetti.ContainerPacking.PackingService.Pack(containers, items, algorithms).FirstOrDefault(); | ||
|
||
//Get the single algorthim packing result from the container packing result | ||
AlgorithmPackingResult algorithmPackingResult = containerPackingResult.AlgorithmPackingResults.FirstOrDefault(); | ||
bool IsCompletePack = algorithmPackingResult.IsCompletePack; | ||
int PackTimeInMilliseconds = Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds); //Max limit of int32 for milliseconds is596 hours | ||
double PercentContainerVolumePacked = Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentContainerVolumePacked); | ||
double PercentItemVolumePacked = Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentItemVolumePacked); | ||
//int BestFitOrientation = algorithmPackingResult.best | ||
|
||
//Convert CromulentBisgetti items to Miscellany Items | ||
//Packed Items | ||
List<Miscellany.ContainerPacking.Entities.Item> itemsPacked = new List<Miscellany.ContainerPacking.Entities.Item>(); | ||
foreach (Item i in algorithmPackingResult.PackedItems) | ||
{ | ||
Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i); | ||
itemsPacked.Add(mItem); | ||
} | ||
//Unpacked Items | ||
List<Miscellany.ContainerPacking.Entities.Item> itemsUnpacked = new List<Miscellany.ContainerPacking.Entities.Item>(); | ||
foreach (Item i in algorithmPackingResult.UnpackedItems) | ||
{ | ||
Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i); | ||
itemsUnpacked.Add(mItem); | ||
} | ||
|
||
//Return values | ||
var d = new Dictionary<string, object>(); | ||
d.Add("packedItems", itemsPacked); | ||
d.Add("unpackedItems", itemsUnpacked); | ||
d.Add("isCompletePack", IsCompletePack); | ||
d.Add("packTimeInMilliseconds", PackTimeInMilliseconds); | ||
d.Add("percentContainerVolumePacked", PercentContainerVolumePacked); | ||
d.Add("percentItemVolumePacked", PercentItemVolumePacked); | ||
d.Add("orientation", PercentItemVolumePacked); | ||
return d; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4f7fa37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! looking forward to the release
4f7fa37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Thomas, is this node ready to go? Do you have a link that would show me how to turn this code into a node with dynamo or do I require visual studio?
4f7fa37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jeremy, it isn't ready yet as I've been waylaid by other things but I will get back to it. Apologies for the delay. I spent some time refactoring the main code but I haven't released that properly yet
4f7fa37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. Look forward to it :)