knapsack-problem

0/1 Knapsack Dynamic Programming Optimazion, from 2D matrix to 1D matrix

若如初见. 提交于 2019-11-30 05:27:44
I need some clarification from wikipedia: Knapsack , on the part This solution will therefore run in O(nW) time and O(nW) space. Additionally, if we use only a 1-dimensional array m[W] to store the current optimal values and pass over this array i+1 times, rewriting from m[W] to m[1] every time, we get the same result for only O(W) space. I am having trouble understanding how to turn a 2D matrix into a 1D matrix to save space. In addition, to what does rewriting from m[W] to m[1] every time mean (or how does it work). Please provide some example. Say if I have the set {V,W} --> {(5,4),(6,5),(3

Strange but practical 2D bin packing optimization

做~自己de王妃 提交于 2019-11-30 05:04:06
I am trying to write an application that generates drawing for compartmentalized Panel. I have N cubicles (2D rectangles) (N <= 40). For each cubicle there is a minimum height (minHeight[i]) and minimum width (minWidth[i]) associated. The panel itself also has a MAXIMUM_HEIGHT constraint. These N cubicles have to be arranged in a column-wise grid such that the above constraints are met for each cubicle. Also, the width of each column is decided by the maximum of minWidths of each cubicle in that column. Also, the height of each column should be the same. This decides the height of the panel We

Solving task scheduling or bin-packing optimizations in R

本小妞迷上赌 提交于 2019-11-30 04:26:48
问题 I have an optimisation issue. It's about a product that contains 20 parts (the order of producing doesn't matter). I've got 3 similar machine that can produce all 20 parts. I've got the 20 parts represented in minutes (ie. it takes 3min to produce the first part and 75min to produce the second part, etc) ItemTime<-c(3,75,55,12,45,55,11,8,21,16,65,28,84,3,58,46,5,84,8,48) So to produce 1 product it takes 730 min. sum(ItemTime) The aim is to minimise the production of one product by allocating

Dynamic programming sum

丶灬走出姿态 提交于 2019-11-29 07:42:30
How would you use dynamic programming to find the list of positive integers in an array whose sum is closest to but not equal to some positive integer K? I'm a little stuck thinking about this. The usual phrasing for this is that you're looking for the value closest to, but not exceeding K. If you mean "less than K", it just means that your value of K is one greater than the usual. If you truly mean just "not equal to K", then you'd basically run through the algorithm twice, once finding the largest sum less than K, then again finding the smallest sum greater than K, then picking the one of

Strange but practical 2D bin packing optimization

落花浮王杯 提交于 2019-11-29 02:48:55
问题 I am trying to write an application that generates drawing for compartmentalized Panel. I have N cubicles (2D rectangles) (N <= 40). For each cubicle there is a minimum height (minHeight[i]) and minimum width (minWidth[i]) associated. The panel itself also has a MAXIMUM_HEIGHT constraint. These N cubicles have to be arranged in a column-wise grid such that the above constraints are met for each cubicle. Also, the width of each column is decided by the maximum of minWidths of each cubicle in

Knapsack with multiple bags and items having only weight

给你一囗甜甜゛ 提交于 2019-11-28 20:52:59
I am trying to solve this problem and I wanted to know if there are known existing algorithms / solutions to solve this. Problem: I have n bags and n items (which are either equal or different weights) to fill into these bag. Each of these bags have a certain weight limit and the n items needs to be put into these bags in such a way that I can use the maximum space in each of these bags. The bags are of equal size. Will also like to know how to solve with bags of unequal size too. Most of the solutions I read was trying to solve a 0/1 knapsack with a weight and value. Should I consider the

How to ensure Java threads run on different cores

谁说胖子不能爱 提交于 2019-11-28 20:46:55
I am writing a multi-threaded application in Java in order to improve performance over the sequential version. It is a parallel version of the dynamic programming solution to the 0/1 knapsack problem. I have an Intel Core 2 Duo with both Ubuntu and Windows 7 Professional on different partitions. I am running in Ubuntu. My problem is that the parallel version actually takes longer than the sequential version. I am thinking this may be because the threads are all being mapped to the same kernel thread or that they are being allocated to the same core. Is there a way I could ensure that each Java

Packing problem revisited

可紊 提交于 2019-11-28 05:49:36
问题 I'm developing a game and I found a problem that I have to solve to handle the layout of a component which resembles me a packing problem. To summarize what I need to do suppose I've got a space similar to the following one: +------------+---------+------------+ | 0 | 1 | 2 | | | | | | | | | | | | | +------------+---------+------------+ | 3 | 4 | 5 | | | | | | | | | +------------+---------+------------+ | 6 | 7 | 8 | | | | | | | | | | | | | +------------+---------+------------+ in which every

Multiple Constraint Knapsack Problem

半城伤御伤魂 提交于 2019-11-28 05:28:28
If there is more than one constraint (for example, both a volume limit and a weight limit, where the volume and weight of each item are not related), we get the multiply-constrained knapsack problem, multi-dimensional knapsack problem, or m-dimensional knapsack problem. How do I code this in the most optimized fashion? Well, one can develop a brute force recursive solution. May be branch and bound.. but essentially its exponential most of the time until you do some sort of memoization or use dynamic programming which again takes a huge amount of memory if not done well. The problem I am facing

0-1 Multidimensional Knapsack

℡╲_俬逩灬. 提交于 2019-11-28 04:46:30
问题 So I'm trying to generate an algorithm that will find the best combination of n items (in my case 4) that can only be placed in the knapsack once (0-1) with a maximum weight capacity. Summarized probably more effectively, I want to place no more than four unique items in my knapsack so that the their weights are less than some value W while maximizing their total value. My first attempt and assumption was to put a volume limit of 4 with all item volumes as 1 for a multidimensional knapsack