savi.alg.knapsack
Class StateKnapsack

java.lang.Object
  extended by savi.alg.knapsack.StateKnapsack
All Implemented Interfaces:
java.lang.Cloneable, StateSkeleton

public class StateKnapsack
extends java.lang.Object
implements StateSkeleton

State representing knapsack problem.


Field Summary
protected  double currCost
          current cost
protected  double currWeight
          current weight
protected  Items items
          reference to available items
protected  int itmCount
          number of items in knapsack
protected  double maxWeight
          capacity (maximum knapsack weight)
protected  java.util.Random rnd
          random generator
protected  boolean[] sack
          represent items, if they in knapsack
 
Constructor Summary
StateKnapsack(Items items, double maxWeight)
          Creates a new instance of StateKnapsack
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this object.
 void findInitialState(double temp)
          Initialize state
 void findNextState(double temp)
          Finds next state of knapsack problem.
 double getActualCost()
          Count actual optimalization criterion.
 Items getItems()
          Return available items.
 boolean[] getKnapsack()
          Return true/false list of items representing content of knapsack
 double getRealCost()
          This method count current cost.
 int getSelectedItemsCount()
          Get count of items in knapsack.
 java.lang.String[] getSubmission()
          Return text representation of knapsack instance.
 double getWeight()
          Count weight of items in knapsack.
 double recountCost()
          Recount current cost.
 void setCapacity(double capacity)
          Set maximum weight of items in knapsack
 void setItems(Items items)
          Set available items.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

protected Items items
reference to available items


currCost

protected double currCost
current cost


currWeight

protected double currWeight
current weight


maxWeight

protected double maxWeight
capacity (maximum knapsack weight)


itmCount

protected int itmCount
number of items in knapsack


sack

protected boolean[] sack
represent items, if they in knapsack


rnd

protected java.util.Random rnd
random generator

Constructor Detail

StateKnapsack

public StateKnapsack(Items items,
                     double maxWeight)
Creates a new instance of StateKnapsack

Parameters:
items - items list
maxWeight - knapsack capacity
Method Detail

findInitialState

public void findInitialState(double temp)
Initialize state

Specified by:
findInitialState in interface StateSkeleton
Parameters:
temp - starting temperature

findNextState

public void findNextState(double temp)
Finds next state of knapsack problem.

Specified by:
findNextState in interface StateSkeleton
Parameters:
temp - current temperature

getRealCost

public double getRealCost()
This method count current cost.

Returns:
actual cost

getActualCost

public double getActualCost()
Count actual optimalization criterion.

Specified by:
getActualCost in interface StateSkeleton
Returns:
value of optimalization criterion

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Specified by:
clone in interface StateSkeleton
Overrides:
clone in class java.lang.Object
Returns:
deep copy of this object

recountCost

public double recountCost()
Recount current cost.

Returns:
actual cost

getSelectedItemsCount

public int getSelectedItemsCount()
Get count of items in knapsack.

Returns:
count of items in knapsack

getWeight

public double getWeight()
Count weight of items in knapsack.

Returns:
weight

getKnapsack

public boolean[] getKnapsack()
Return true/false list of items representing content of knapsack

Returns:
true/false list of items

getItems

public Items getItems()
Return available items.

Returns:
items

setCapacity

public void setCapacity(double capacity)
Set maximum weight of items in knapsack

Parameters:
capacity - capacity

setItems

public void setItems(Items items)
Set available items.

Parameters:
items - instance of class Items

getSubmission

public java.lang.String[] getSubmission()
Return text representation of knapsack instance.

Specified by:
getSubmission in interface StateSkeleton
Returns:
array of lines