Title: | Multiple Knapsack Problem Solver |
---|---|
Description: | Package solves multiple knapsack optimisation problem. Given a set of items, each with volume and value, it will allocate them to knapsacks of a given size in a way that value of top N knapsacks is as large as possible. |
Authors: | Bulat Yapparov [aut, cre], MADE.com [cph] |
Maintainer: | Bulat Yapparov <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2024-11-23 03:31:30 UTC |
Source: | https://github.com/cran/mknapsack |
Combines items with MOQ greater than one to a single line that represents min amount that can be ordered
group_moq(units)
group_moq(units)
units |
data.table with following fields: sku, utility, volume, moq |
data.table with sku, utility, volume and units fields. first lines for each sku are grouped according to moq
Solves knapsack problem with the library defined in knapsack.solver option: - cbc (default) - uses rcbc package - lpsolve - uses lpSolve package
knapsack(profit, volume, moq = rep(0, length(profit)), cap = 65)
knapsack(profit, volume, moq = rep(0, length(profit)), cap = 65)
profit |
vector with profit for item |
volume |
vector of item sizes in cubic meters |
moq |
vector of flags where 1 means that row contans mininum order quantity (MOQ). Defaults to zero vector matching profit in length. |
cap |
size of the container in cubic meters |
vector with container numbers keeping the permutation of the original data
Gets containers based on the utility of individual items, their volume and container size
mknapsack(profit, volume, moq = rep(0, length(profit)), cap = 65, sold = rep(0, length(profit)))
mknapsack(profit, volume, moq = rep(0, length(profit)), cap = 65, sold = rep(0, length(profit)))
profit |
vector with profit for item |
volume |
vector of item sizes in cubic meters |
moq |
vector of flags where 1 means that row contans mininum order quantity (MOQ). Defaults to zero vector matching profit in length. |
cap |
size of the container in cubic meters |
sold |
vector with a number of items that were sold on demand |
vector with container numbers keeping the permutation of the original data
# Calculate the optimal containers summary for a sample dataset data(unitsbro) library(data.table) units.combined <- data.table(unitsbro) moq <- units.combined$moq profit <- units.combined$utility volume <- units.combined$volume res <- mknapsack(profit, volume, moq, 65) units.combined$container <- as.factor(res) #Aggregate solution to container containers <- units.combined[order(container), .(volume = sum(volume), profit = sum(profit)), by = container]
# Calculate the optimal containers summary for a sample dataset data(unitsbro) library(data.table) units.combined <- data.table(unitsbro) moq <- units.combined$moq profit <- units.combined$utility volume <- units.combined$volume res <- mknapsack(profit, volume, moq, 65) units.combined$container <- as.factor(res) #Aggregate solution to container containers <- units.combined[order(container), .(volume = sum(volume), profit = sum(profit)), by = container]
Creates matrix of moq constraints for the LP optimisation. It is assumed that there is only one moq position per SKU and data is sorted by sku, therefore SKU index can be calculated
moq_constraint(moq)
moq_constraint(moq)
moq |
flag that indicates that this position contains MOQ |
matrix that expesses the MOQ constraint: non-MOQ item cannot be put into container that does not contain MOQ item
Dataset contains line items with utility and volume and can be used for exploration of the package functionality.
unitsbro
unitsbro
A data frame with rows and variables
identifier for the product
proxy of the profit that this item delivers to the company if purchased
volume of the item, usually in cubic meters
number of untis that this line contains
If equals one, this line contains the minimum order quantity and shoudl be ordered prior to other lines of the same sku