bestfit

package
v0.0.0-...-80c8c53 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FitnessClassic

func FitnessClassic(leftSpace, itemCost, _ int) float64

FitnessClassic is a fitness function defined by classic best-fit algorithm for classic bin packing problem. It defines the fitness as a left space after element assignment.

func FitnessWithBucketLeftSpacePreferringBigItems

func FitnessWithBucketLeftSpacePreferringBigItems(
	leftSpace, itemCost, bucketSize int) float64

FitnessWithBucketLeftSpacePreferringBigItems is a fitness function that takes into account free space after assignment and free space before assignment. The more space before the assignment and less space after the assignment the better. It prefers big items that leave as little space as possible after assignment.

func FitnessWithBucketLeftSpacePreferringLittleSpaceBeforeAndAfterAssignment

func FitnessWithBucketLeftSpacePreferringLittleSpaceBeforeAndAfterAssignment(
	leftSpace, itemCost, bucketSize int) float64

FitnessWithBucketLeftSpacePreferringLittleSpaceBeforeAndAfterAssignment is a fitness function that takes into account free space after assignment and free space before assignment. The less space before the assignment and less space after the assignment the better. It prefers almost full buckets and items that leave as little space as possible after assignment.

func FitnessWithBucketLeftSpacePreferringLittleSpaceBeforeAndAfterAssignmentPunishPerfectlyFittedItems

func FitnessWithBucketLeftSpacePreferringLittleSpaceBeforeAndAfterAssignmentPunishPerfectlyFittedItems(
	leftSpace, itemCost, bucketSize int) float64

FitnessWithBucketLeftSpacePreferringLittleSpaceBeforeAndAfterAssignmentPunishPerfectlyFittedItems is a fitness function that takes into account free space after assignment and free space before assignment. The less space before the assignment and less space after the assignment the better. It prefers almost full buckets and items that leave as little space as possible after assignment. It punishes perfectly fitted items by giving them the fitness of infinity.

func FitnessWithBucketLeftSpacePreferringSmallItems

func FitnessWithBucketLeftSpacePreferringSmallItems(
	leftSpace, itemCost, bucketSize int) float64

FitnessWithBucketLeftSpacePreferringSmallItems is a fitness function that takes into account free space after assignment and free space before assignment. The less space before the assignment and most space after the assignment the better. It prefers small items that leave as much space as possible after assignment. If item is perfectly fitted it returns 0.

func FitnessWithBucketLeftSpacePreferringSmallItemsPunishPerfectlyFittedItems

func FitnessWithBucketLeftSpacePreferringSmallItemsPunishPerfectlyFittedItems(
	leftSpace, itemCost, bucketSize int) float64

FitnessWithBucketLeftSpacePreferringSmallItemsPunishPerfectlyFittedItems is a fitness function that takes into account free space after assignment and free space before assignment. The less space before the assignment and most space after the assignment the better. It prefers small items that leave as much space as possible after assignment. It punishes perfectly fitted items by giving them the fitness of infinity.

func FitnessWithBucketSize

func FitnessWithBucketSize(leftSpace, itemCost, bucketSize int) float64

FitnessWithBucketSize is a fitness function that takes into account the size of a bucket, computing relative free space after assignment to overall bucket size. The less space after assignment and the bucket is bigger the better. It prefers big buckets and well-fitted items.

Types

type BestFit

type BestFit struct {
	FitnessFunc FitnessFunc
}

BestFit is an optimizer that implements the best-fit algorithm expanded to solve the bin packing problem with heterogeneous bins and items with different sizes that depend on the bin choice. The algorithm uses FitnessFunc to choose "best" bucket. Unfortunately, due to the extended problem, it is not possible to implement best-fit using a balanced binary tree, therefore the implementation works in O(v*n) time.

func (BestFit) Optimize

func (b BestFit) Optimize(ctx context.Context, data *data.Data) (*optimizer.Result, error)

type FitnessFunc

type FitnessFunc func(leftSpace, itemCost, bucketSize int) float64

FitnessFunc defines what means "best" assignment. The lower the value of FitnessFunc the better the assignment would be. It returns a negative value for an item that cannot be assigned to the given bucket, and a positive value if the item can be assigned and leave some space in it.

Jump to

Keyboard shortcuts

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