Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check weight #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions bp3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type BinSlice []*Bin

func (bs BinSlice) Len() int { return len(bs) }
func (bs BinSlice) Less(i, j int) bool {
return bs[i].GetVolume() < bs[j].GetVolume()
return bs[i].GetVolume() < bs[j].GetVolume() || bs[i].Name < bs[j].Name
}
func (bs BinSlice) Swap(i, j int) {
bs[i], bs[j] = bs[j], bs[i]
Expand Down Expand Up @@ -71,6 +71,16 @@ func (b *Bin) GetMaxWeight() float64 {

// PutItem tries to put item into pivot p of bin b.
func (b *Bin) PutItem(item *Item, p Pivot) (fit bool) {
//Check weight first
var totalWeight float64
for _, ib := range b.Items {
totalWeight += ib.Weight
}
if totalWeight+item.Weight > b.MaxWeight {
fit = false
return
}

item.Position = p
for i := 0; i < 6; i++ {
item.RotationType = RotationType(i)
Expand Down Expand Up @@ -158,7 +168,7 @@ type ItemSlice []*Item

func (is ItemSlice) Len() int { return len(is) }
func (is ItemSlice) Less(i, j int) bool {
return is[i].GetVolume() > is[j].GetVolume()
return is[i].GetVolume() > is[j].GetVolume() || is[i].Name < is[j].Name
}
func (is ItemSlice) Swap(i, j int) {
is[i], is[j] = is[j], is[i]
Expand Down