public final class KnapsackItem extends Object implements Comparable<KnapsackItem>
It implements comparable interface in such a away so that items can be sorted in decreasing efficiency. In case of equal efficiency then item which is heavier is preferred.
Modifier and Type | Field and Description |
---|---|
double |
efficiency
It stores information about the item efficiency - profit/weight.
|
int |
profit
It specifies the profit of a single instance of this item.
|
IntVar |
quantity
It is a finite domain variable specifying the possible quantity of that item.
|
int |
weight
It specifies the weight of a single instance of this item.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(KnapsackItem that)
Method used in the sorting of the items, we use profit and weight to know
the less efficient item without using division.
|
double |
getEfficiency()
It returns an efficiency of that item.
|
int |
getProfit()
It returns a profit of a single instance of that item.
|
IntVar |
getVariable()
t returns quantity variable associated with that item.
|
int |
getWeight()
It returns a weight of a single instance of that item.
|
String |
toString() |
public final IntVar quantity
public final int weight
public final int profit
public final double efficiency
public int compareTo(KnapsackItem that)
In connection with Arrays.sort() it will produce items from most efficient to least efficient breaking ties in the favor of the larger weight.
compareTo
in interface Comparable<KnapsackItem>
public final IntVar getVariable()
public final int getProfit()
public final int getWeight()
public final double getEfficiency()
Copyright © 2022. All rights reserved.