Knapsack example

View: New views
1 Messages — Rating Filter:   Alert me  

Knapsack example

by Darkkarl :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, im running the knapsack sample and i want to add the profit vector,
like this:  
maximize   sum xi*pi      
subject to sum xi*wi  < V

V: Volume, total weight of the knapsack
wi: vector of volume/weights
pi: benefit/profit vector
xi: {0,1}

i don't want minimum number of items so i dont need :
//fitness -= computeItemNumberPenalty(MAX_BOUND, numberOfItems);

but i need to add the profit to the fitness
so i added to the main:
public double[] itemProfits = {
      5.2d, 4.8d, 2.5d, 600.0d, 225.0d, 44.75d, 9.36d, 150.7d, 185.9d,
      8.1d};

at the fitness:
fitness += getTotalProfit(a_subject);

and this:
double getTotalProfit(a_subject)
{
double profit = 0.0d;
 for (int i = 0; i < a_subject.size(); i++) {
      profit += KnapsackMain.itemProfits[i]*getGene(a_position).getAllele().intValue();
    }
}

but for some reason doesn't work
the process just hangs
any ideas, i think i miss something  

LightInTheBox - Buy quality products at wholesale price!