packme

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 3 Imported by: 0

README

GoDoc Reference Github Actions Coverage Status Go Report Card

PackMe

A 3D bin packing library in Go.

Packing implementations

All packing implementations comply to Packer interface.

  • Best-fit packer - A 3D bin packing implementation based on a paper by Dube, E., & Kanavathy L. (2006) titled Optimizing Three-Dimensional Bin Packing Through Simulation

Example

// Define box specifications
boxSpecs := []packme.BoxSpec{
    packme.NewBoxSpec("Box A", 1, packme.NewDimensions(30, 30, 30)),
    packme.NewBoxSpec("Box B", 1, packme.NewDimensions(5, 5, 40)),
    packme.NewBoxSpec("Box C", 1, packme.NewDimensions(20, 20, 30)),
}

// Define item specifications
itemSpecs := []packme.ItemSpec{
    packme.NewItemSpec("Item A1", 17, packme.NewDimensions(10, 10, 30)),
    packme.NewItemSpec("Item A2", 1, packme.NewDimensions(10, 10, 30)),
    packme.NewItemSpec("Tall Item", 1, packme.NewDimensions(5, 39.5, 5)),
    packme.NewItemSpec("Large Item", 1, packme.NewDimensions(50, 50, 100)),
}

// Create new instance of best-fit packer
packer := packme.NewBestFitPacker()

// Start packing!
packingScheme := packer.Pack(boxes, items)

// Print packing scheme
fmt.Println(packingScheme)

// Output:
// Box B items(1) dims(5x5x40) vol(1000)
// Tall Item dims(5x5x39.5) vol(987.5) pos(0,0,0) rot(h,l,w)
// 
// Box C items(4) dims(20x20x30) vol(12000)
// Item A1 dims(10x10x30) vol(3000) pos(0,0,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(10,0,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(0,10,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(10,10,0) rot(l,w,h)
//
// Box A items(9) dims(30x30x30) vol(27000)
// Item A1 dims(10x10x30) vol(3000) pos(0,0,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(10,0,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(20,0,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(0,10,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(10,10,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(20,10,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(0,20,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(10,20,0) rot(l,w,h)
// Item A1 dims(10x10x30) vol(3000) pos(20,20,0) rot(l,w,h)
//
// Not packed (6)
// Item A1 dims(10x30x10) vol(3000) pos(0,0,0) rot(l,h,w)
// Item A1 dims(10x30x10) vol(3000) pos(0,0,0) rot(l,h,w)
// Item A1 dims(10x30x10) vol(3000) pos(0,0,0) rot(l,h,w)
// Item A1 dims(10x30x10) vol(3000) pos(0,0,0) rot(l,h,w)
// Item A2 dims(10x30x10) vol(3000) pos(0,0,0) rot(l,h,w)
// Large Item dims(50x100x50) vol(250000) pos(0,0,0) rot(l,h,w)

Credits

Licence

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis

type Axis int
const (
	AxisX Axis = iota
	AxisY
	AxisZ
)

type BestFitPacker

type BestFitPacker struct{}

BestFitPacker is a packer implementation based on a paper by Dube, E., & Kanavathy, L. (2006)

func NewBestFitPacker

func NewBestFitPacker() BestFitPacker

func (BestFitPacker) Pack

func (bfp BestFitPacker) Pack(boxSpecs []BoxSpec, itemSpecs []ItemSpec) PackingScheme

type Box

type Box struct {
	// contains filtered or unexported fields
}

func NewBox

func NewBox(desc string, dims Dimensions) *Box

func (*Box) Desc

func (bx *Box) Desc() string

func (*Box) Dimensions

func (bx *Box) Dimensions() Dimensions

func (*Box) Items

func (bx *Box) Items() Items

func (*Box) String

func (bx *Box) String() string

func (*Box) Volume

func (bx *Box) Volume() float32

type BoxSpec

type BoxSpec struct {
	// contains filtered or unexported fields
}

func NewBoxSpec

func NewBoxSpec(desc string, qty int, dims Dimensions) BoxSpec

func (BoxSpec) Volume

func (bs BoxSpec) Volume() float32

type BoxSpecByVolume

type BoxSpecByVolume []BoxSpec

func (BoxSpecByVolume) Len

func (s BoxSpecByVolume) Len() int

func (BoxSpecByVolume) Less

func (s BoxSpecByVolume) Less(i, j int) bool

func (BoxSpecByVolume) Swap

func (s BoxSpecByVolume) Swap(i, j int)

type Boxes

type Boxes []*Box

func (Boxes) String

func (bxs Boxes) String() string

type Dimensions

type Dimensions [3]float32

Dimensions is the dimensions

func NewDimensions

func NewDimensions(length, width, height float32) Dimensions

func (Dimensions) Height

func (d Dimensions) Height() float32

func (Dimensions) Length

func (d Dimensions) Length() float32

func (Dimensions) String

func (d Dimensions) String() string

func (Dimensions) Width

func (d Dimensions) Width() float32

type Item

type Item struct {
	// contains filtered or unexported fields
}

func NewItem

func NewItem(desc string, dims Dimensions) *Item

func (*Item) Collision

func (i *Item) Collision(i2 *Item) bool

func (*Item) Desc

func (i *Item) Desc() string

func (*Item) Dimensions

func (i *Item) Dimensions() Dimensions

func (*Item) Height

func (i *Item) Height() float32

func (*Item) Length

func (i *Item) Length() float32

func (*Item) String

func (i *Item) String() string

func (*Item) Volume

func (i *Item) Volume() float32

func (*Item) Width

func (i *Item) Width() float32

type ItemSpec

type ItemSpec struct {
	// contains filtered or unexported fields
}

func NewItemSpec

func NewItemSpec(desc string, qty int, dims Dimensions) ItemSpec

func (ItemSpec) Volume

func (i ItemSpec) Volume() float32

type ItemSpecByVolume

type ItemSpecByVolume []ItemSpec

func (ItemSpecByVolume) Len

func (s ItemSpecByVolume) Len() int

func (ItemSpecByVolume) Less

func (s ItemSpecByVolume) Less(i, j int) bool

func (ItemSpecByVolume) Swap

func (s ItemSpecByVolume) Swap(i, j int)

type Items

type Items []*Item

func (Items) String

func (items Items) String() string

type Packer

type Packer interface {
	// Pack takes a box and item specs and returns a packing scheme
	Pack([]BoxSpec, []ItemSpec) PackingScheme
}

Packer is an interface that wraps the pack method

type PackingScheme

type PackingScheme struct {
	Boxes     Boxes
	NotPacked Items
}

func (PackingScheme) String

func (ps PackingScheme) String() string

type Point

type Point [3]float32

func NewPoint

func NewPoint(x, y, z float32) Point

func (Point) String

func (p Point) String() string

func (Point) X

func (p Point) X() float32

func (Point) Y

func (p Point) Y() float32

func (Point) Z

func (p Point) Z() float32

type Rotation

type Rotation int
const (
	// RotationLWH (l, w, h)
	RotationLWH Rotation = iota + 1
	// RotationWLH (w, l, h)
	RotationWLH
	// RotationWHL (w, h, l)
	RotationWHL
	// RotationHLW (h, l, w)
	RotationHLW
	// RotationHWL (h, w, l)
	RotationHWL
	// RotationLHW (l, h, w)
	RotationLHW
)

func (Rotation) String

func (r Rotation) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL