diff --git a/__debug_bin1826320692.exe b/__debug_bin1534046176.exe similarity index 69% rename from __debug_bin1826320692.exe rename to __debug_bin1534046176.exe index ec6acd6..740f441 100644 Binary files a/__debug_bin1826320692.exe and b/__debug_bin1534046176.exe differ diff --git a/main.go b/main.go index f7cc335..b09301d 100644 --- a/main.go +++ b/main.go @@ -97,7 +97,6 @@ func optimizePacking(con Container, box Box) ([]Placement, string, int) { type candidate struct { layout []Placement count int - weight float64 strategy string } @@ -133,38 +132,40 @@ func optimizePacking(con Container, box Box) ([]Placement, string, int) { xCount = math.Floor(con.Length / r.Width) } - total := int(xCount * yCount * zCount) - totalWeight := float64(total) * box.Weight + totalByVolume := int(xCount * yCount * zCount) + maxCountByWeight := int(math.Floor(con.WeightLimit / box.Weight)) + actualCount := totalByVolume + if actualCount > maxCountByWeight { + actualCount = maxCountByWeight + } - if total > 0 { - fmt.Printf("Rotation: %v | Strategy: %s | Total: %d | Weight: %.2f kg\n", r, strategy, total, totalWeight) + if actualCount > 0 { candidates = append(candidates, candidate{ - layout: generateLayout(r, xCount, yCount, zCount, strategy), - count: total, - weight: totalWeight, + layout: generateLayout(r, xCount, yCount, zCount, strategy)[:actualCount], + count: actualCount, strategy: strategy, }) } } } - maxCountUnderLimit := 0 + if len(candidates) == 0 { + return nil, "", 0 + } + + maxCount := 0 var finalLayout []Placement var finalStrategy string for _, c := range candidates { - if c.count > maxCountUnderLimit && c.weight <= con.WeightLimit { - maxCountUnderLimit = c.count + if c.count > maxCount { + maxCount = c.count finalLayout = c.layout finalStrategy = c.strategy } } - if maxCountUnderLimit == 0 { - return candidates[0].layout, candidates[0].strategy, candidates[0].count - } - - return finalLayout, finalStrategy, maxCountUnderLimit + return finalLayout, finalStrategy, maxCount } func generateRotations(con Container, box Box) []Box {