savi.alg.knapsack
Class Items

java.lang.Object
  extended by savi.alg.knapsack.Items

public class Items
extends java.lang.Object

Class representing knapsack problem instance.


Field Summary
protected  int count
          number of items in this knapsack instance
protected  int idx
          internal iterator for addItem method
protected  double[][] items
          array with items; one item is pair of integers (int[2]) - weight and cost
 
Constructor Summary
Items(double[][] it)
          Creates a new instance of Items, set items
Items(int count)
          Creates a new instance of Items, creates empty array
 
Method Summary
protected  void addItem(double w, double c)
          Insert new item into the instance
 int getCount()
          Get current items count in knapsack instance
 double getItemCost(int item)
          Return cost of desired item.
 double getItemWeight(int item)
          Return weight of desired item.
 void randomItems(double wmax, double cmax)
          Randomly cretes items.
 void setItems(double[][] it)
          Set prepared items
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

protected int count
number of items in this knapsack instance


idx

protected int idx
internal iterator for addItem method


items

protected double[][] items
array with items; one item is pair of integers (int[2]) - weight and cost

Constructor Detail

Items

public Items(int count)
Creates a new instance of Items, creates empty array

Parameters:
count - maximum items

Items

public Items(double[][] it)
Creates a new instance of Items, set items

Parameters:
it - initialized items
Method Detail

setItems

public void setItems(double[][] it)
Set prepared items

Parameters:
it - items

addItem

protected void addItem(double w,
                       double c)
Insert new item into the instance

Parameters:
w - item weight
c - item cost

getCount

public int getCount()
Get current items count in knapsack instance

Returns:
number of items

randomItems

public void randomItems(double wmax,
                        double cmax)
Randomly cretes items.

Parameters:
wmax - maximum item weight
cmax - maximum item cost

getItemWeight

public double getItemWeight(int item)
Return weight of desired item.

Parameters:
item - item index
Returns:
item weight

getItemCost

public double getItemCost(int item)
Return cost of desired item.

Parameters:
item - item index
Returns:
item cost