1,094 questions
-2
votes
1
answer
57
views
I want to fix a "int' object is not subscriptable" error [closed]
I'm using genetic algorithm for knapsack problem and when I wanted to debug it says : int' object is not subscriptable
it just pointed this 3 spots in the code and in the end it just said this is the ...
0
votes
0
answers
75
views
Why this code for 0/1 knapsack problem works for some examples?
Problem Statement
There are N items, numbered 1, 2, …, N.
For each item i (1 ≤ i ≤ N):
It has a weight w[i]
It has a value v[i]
Taro wants to choose some of these N items and carry them home in a ...
0
votes
1
answer
127
views
Knapsack 0/1 variation maximize the number of objects with independent weight restrictions
I'm trying to use dynamic programming to solve a knapsack variation, where you are given an array of containers, each of them having a weight, a resistance and an id, I need to find the tallest pile ...
0
votes
1
answer
83
views
Why does lp() linear solver in R find a better solution when given a smaller subset of options?
Given a set of 140 options, my goal is to select the set of options that minimize the objective function and acheive a constraint that weight must be > 5584 units.
Criteria 1 is the objective ...
6
votes
3
answers
373
views
Subset sum problem with selection constraint in large R dataset
I have a tibble:
sample_tibble <- tibble(
group = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4),
threshold = c(100, 100, 100, 100, 100, 80, 80, 80, 80, 80, 80, 150, 150, 150,...
0
votes
0
answers
84
views
Multiple knapsack total value optimization
Problem description:
A store has N boxes where sequences of bottles can be placed (a sequence can be empty), with each box having a bonus factor c_i and a weight l_i.
There are only K bottles ...
0
votes
0
answers
68
views
Unable to input and output properly when programming a Knapsack problem
I am trying to solve a Knapsack problem with a two-dimensional array on CodeBlocks, but after the program runs, I press the number on the keyboard, and the running terminal does not display the number ...
3
votes
1
answer
146
views
How can I reduce the time complexity of the solution my subset optimization problem?
I have a list of tuples (a, b) of two unrelated positive integers. I am trying to create another list based off of this that maximizes the sum of a, while staying above a threshold.
I also have two ...
4
votes
2
answers
175
views
Algorithm to minimize the number of printing plates when printing sheets of stickers
I am working on an algorithm for optimizing the costs of a printing company by solving a problem they face. The problem is similar to knapsack problem but with a twist, instead of minimizing the ...
0
votes
2
answers
182
views
knapsack problem - how to cut memory usage
You have 𝑛 items. Each object has a weight, the weight of the object numbered 𝑖 is equal to 𝑥_𝑖. You need to put them in a backpack that holds no more than 𝑆g. At the same time, you want the ...
0
votes
1
answer
149
views
Error: Version solving failed due to null safety in Dart Flutter project with flutter_tindercard dependency
hot to solve
give me a proper steps
The current Dart SDK version is 3.2.0. Because datingappmain depends on flutter_tindercard >=0.1.1 which doesn't support null safety, version solving failed. ...
0
votes
0
answers
104
views
Having trouble allocating memory in c programm
I have an assignment to solve a Knapsack problem from a set of dataset i'm given and one of the ways i have to do solve it with is branch and bound depth first
The program below works fine when given ...
-4
votes
3
answers
103
views
find number of unique durations given a list of durations and an upper bound
Lets say we are given a list of durations (5s, 10s, 10s, 15s, 15s, 15s, 25s, 30s....) and we want to find a list of unique durations that can be created using this list of single durations.
for ...
4
votes
1
answer
286
views
Knapsack Problem: Find Top-K Lower Profit Solutions
In the classic 0-1 knapsack problem, I am using the following (dynamic programming) algorithm to construct a "dp table":
def knapsack(weights, values, capacity):
n = len(weights)
...
1
vote
0
answers
50
views
Quite Hard DLX Optimizing JavaFX 3D Grid Manipulation for Performance
I'm working on a JavaFX project where I need to manage a 3D grid representing a Tetris-like game environment. My current implementation involves multiple nested loops and array manipulations, which I ...
0
votes
1
answer
76
views
The code for 0/1 Knapsack Problem is not working
This is the code I used:
class Solution
{
//Function to return max value that can be put in knapsack of capacity W.
static int knapSack(int W, int wt[], int val[], int n)
{
// ...
2
votes
1
answer
139
views
Knapsack Problem: bags have variable weights
Consider a list of weights and a list of bags with variable weights. I need an algorithm that finds the minimum number of bags needed to store all weights.
Simply sorting in decreasing order doesn't ...
0
votes
1
answer
134
views
Greedy Algorithm returning incorrect answer for Job Sequencing Problem
Person X can only work for atmost 10 hours in a day. Given two arrays consisting of wages and duration of work of jobs, what is the maximum amount X can earn in a day?
One of the test cases was:
wage ...
3
votes
1
answer
208
views
Spell casting - How to optimize damage per second : Variation of 0-1 Knapsack [closed]
I am trying to make an algorithm that finds the sequence of spell that maximizes the total damage.
I understood this situation as a 0-1 knapsack problem with cooldown for each item. However, I couldn'...
1
vote
0
answers
96
views
Get X and Y sizes of remaining surface area
I have bins that I'm packing components into, but have trouble with components of smaller sizes not "using" the available space in the current bin (so I am creating a new bin when it isn't ...
0
votes
3
answers
479
views
Solving the Fractional Knapsack problem using Binary Search
The Fractional Knapsack Problem revolves around selecting items from a given set to fit into a knapsack of limited capacity. Each item has a weight and a value associated with it, and the goal is to ...
2
votes
2
answers
675
views
Find optimal combination of items with 2 values
I have a list of 500 elements each with 2 values x (float value from 0-Infinity) and a y (float value from 0-1). I need to find the cheapest (lowest sum(x)) combination of 10 of these elements that ...
1
vote
0
answers
90
views
Time complexity increased by using memoization when I use map<pair<int,int>,int> to store the DP state
I was solving the CSES-Apple Division Problem. It was a dp sum difference minimization problem. We have to divide an array into two subsets whose sum difference is minimum.
I was using basic Recursion ...
-1
votes
1
answer
62
views
knapsack code is not working in python while submitting it in GFG
I am trying to solve GeeksforGeeks problem 0 - 1 Knapsack Problem
:
You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the ...
0
votes
0
answers
51
views
How to solve algo trading bug
Following a course on algorithmic trading on python. However, 20 minutes in, run a command and get this. Please help. tried everything the code i ran. Everything is updated and I have tried everything....
0
votes
0
answers
54
views
This is a solution to the simplest knapsack problem but the result weight always exceeds the permitted amount
I'm trying to fix this for a whole night but still the program doesn't work, and I felt like there's nothing wrong with it. The list taken is responsible for recording the objects that's being carried ...
1
vote
1
answer
176
views
Find a subset of a set of vectors such that the difference between the maximum and minimum element of the sum of the subset is minimal
The length of each vector is equal to 3. The number of vectors is no more than 300 and sum of the sum of all vectors is no more than 500.
Example:
For set of vectors: [0, 0, 1], [2, 3, 4], [0, 5, 0], [...
3
votes
1
answer
192
views
Searching Algorithm: Product Knapsack Problem with goal to find lowest product above a certain threshold?
I'm looking for people with some algorithmic knowledge who can help me out with this.
I'm currently programming a constrained tree search in java, where I want to have a certain amount of leaf nodes ...
0
votes
0
answers
34
views
Python knap sack problem with recursion tree
Hello I have 5 blanks on the Python code below
in bmax_val() and bfast_max() functions
I'm trying to draw recursion tree as a result but it's too difficult to solve this problem
I tried to put
indent =...
3
votes
1
answer
329
views
Comparison of BFS and DFS algorithm for the Knapsack problem
I am fairly new to python and I have a task which tells me to compare both algorithm time expended and space used in memory.
I have coded both algorithms and ran them both. I was able to measure the ...
1
vote
1
answer
113
views
a ortools problem,find min value of the Knapsack problem,but value is caculated by tensorflow model not constant coefficient
public List<Waste> main(List<Waste> nowStock) throws Exception {
Loader.loadNativeLibraries();
HashMap<@Nullable Integer, @Nullable Waste> iToWaste = Maps.newHashMap();
...
0
votes
2
answers
61
views
Number of ways I can have as least M itens chosen from L itens (L >= M), where the price of all chosen S itens can't be greater than Q
L = number of given itens 0 < L < 31
P[j] = price of item j
M = smaller quantity of items I must have
Q = Greater quantity which can be spent
Also, I can't have more than one item of each type.
...
0
votes
1
answer
46
views
in my android studio every button working but when i use flatbutton its not working so what can i do now?
enter image description here
please how can i use flat button now?
I am trying to solve this and expected that someone will help me here.
0
votes
0
answers
81
views
Struggling to find the flaw in my logic for Fractional Knapsack problem (Maximum Value of the Loot)
This problem has been asked before: the problem however I have been struggling for a while to debug where my logic is wrong because my algorithm fails on this unknown test case:
Failed case #7/13: ...
-1
votes
1
answer
330
views
Do dynamic programming and branch and bound give same result when solving 0/1 knapsack problem?
Hi I have a question about knapsack problem and it's algorithms.
I have built some code to solve 0/1 knapsack problem with Dynamic Programming and Branch and Bound.
The value and weight are randomly ...
3
votes
2
answers
458
views
Multiple knapsack problem with no solution but finding a way to remove item(s) that are preventing a solution
I am trying to find a way to have as few boxes as possible that fit bags of chemicals. A box cannot have weight more than 3.3 kg but have to be higher than 2.7 kg. I came across Google's OR tools but ...
0
votes
1
answer
36
views
shares of stack problem with js and dynamic programming
The problem receives an input like [[500, 5, 1], [450, 2, 1], [400, 5, 1]], where each row represents a buyer. Each buyer has a value in position 0, which represents the amount they are willing to pay ...
0
votes
0
answers
74
views
PHP Qty distribution with max value
I've been struggle on this problem over than 2 weeks, I've data like below :
Someone told me it's should knapsack or anything, but I don't know how to do.
Master Category
Category
Qty per Box
P
12
V
8
...
1
vote
1
answer
60
views
Why does rank 14 output at the end of the first if statement even though it says if(rank == 0)?
I am trying to use MPI to develop a parallel solution in C to the NP-Complete Knapsack problem. When I run the code, the printf statement at the end of the first if statement outputs as rank 14, not ...
0
votes
1
answer
289
views
Solving Knapsack Problem for large dataset using PULP library in Python
I have the below dataframe:
import itertools
import pandas as pd
import numpy as np
p1_values = np.arange(19, 29.1, 0.1)
p2_values = np.arange(23, 33.1, 0.1)
p3_values = np.arange(36, 46.1, 0.1)
...
0
votes
1
answer
85
views
Java Collection with multiple keys that refer to a different value that is also sortable (by key and index)
I had a lot of problems with my program recently, as I am not able to create a Collection which has duplicate keys at the same that refer to a different value. It's like an array in a List.
I already ...
3
votes
1
answer
115
views
Filling two fractional knapsacks using the same items
I have two knapsacks, let's call them knapsack A, and knapsack B, each knapsack has a max weight limit. We also have some item types that we can take with us. Each item type has a price, and two ...
0
votes
0
answers
209
views
Can I add variables to a 2D knapsack problem that can take multiple values?
this is my first question on stack overflow and I am quite new to OR, so bear with me.
I am trying to solve what could be considered a rectangular 2D knapsack problem with a twist. In order to solve ...
0
votes
1
answer
125
views
Knapsack dynamic programming - Why are below 2 codes (similar implementation) giving different answers for a test case?
I need to solve the below knapsack problem to maximize value while staying within the knapsack's weight W.
n is the number of items available
W is the weight capacity of knapsack
wt is the weight ...
0
votes
0
answers
49
views
How to create Chromosomes and Fitness function for this NP-Hard Genetic algorithm problem
Hi i am very new to genetic algorithm and i am stuck with this problem:
A move is provided for a student. He has to store his things in small plastic boxes in a cardboard box with a capacity of 2 ...
1
vote
2
answers
379
views
Knapsack problem: choose 5 elements among 100, weight <= 100, maximise total value
I have a data table containing n=100 elements :
Element
weight
value
A
24
80
B
43
77
C
51
72
D
38
70
E
27
65
F
7
58
..
..
..
And I would like to create an algorithm to get 5 elements where :
sum of ...
0
votes
1
answer
76
views
my knapsack code does not work in python 3 can anyone help what is the problem with my code?
def knapSack(W, wi, pi, i):
if i == 0 or W == 0:
return 0
if (wi[i-1] > W):
return knapSack(W, wi, pi, i-1)
else:
return max(
pi[n-1] + ...
0
votes
1
answer
114
views
I got wrong output for 0/1 knapsack problem in python using backtracking
I implemented the 0/1 knapsack problem with the backtracking technique, but I didn't get the expected result.
capacity : total knapsack capacity
cargo_number : the number of items
size : the weight ...
2
votes
1
answer
801
views
How to solve a Knapsack problem with extra constraints? (Or alternative algorithms)
Expanding upon a common dynamic programming solution for the knapsack problem:
def knapSack(W, wt, val, n):
results = []
K = [[0 for x in range(W + 1)] for x in range(n + 1)]
# Build tаble ...
-1
votes
1
answer
350
views
in knapsack problem, how do i know which items are taken?
i used dynamic programming to solve knapsack problem.
#include <iostream>
using namespace std;
#define number 4 // number of item type
typedef struct iteml
{
int itemw; // [weight of item]
...