Class CostMatrix<T>
Object
CostMatrix<T>
- Type Parameters:
T
- element-type in lists
Stores costs between all possible pairings between elements from two lists.
Note that costs are often distances (symmetric) but not necessarily.
Internally, a matrix-like structure is used.
The two lists are referred to as first and second.
- Author:
- Owen Feehan
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CostMatrix
<T> create
(List<T> first, List<T> second, boolean symmetric, CheckedToDoubleBiFunction<T, T, CreateException> costCalculator) Creates by calculating the cost between elements.boolean
double
getCost
(int index1, int index2) Gets the cost from an element from the first-list to an element from the second-list.getFirst()
The first set of elements.double[][]
A two-dimensional array mapping the costs fromfirst
tosecond
.The second set of elements.int
hashCode()
int
The number of elements in the first list.int
The number of elements in the second list.toString()
-
Method Details
-
create
public static <T> CostMatrix<T> create(List<T> first, List<T> second, boolean symmetric, CheckedToDoubleBiFunction<T, T, throws CreateExceptionCreateException> costCalculator) Creates by calculating the cost between elements.All possible pairings are calculated involving an element from the first list and an element from the second list.
- Type Parameters:
T
- element-type in lists- Parameters:
first
- the collection of elements that forms the left-side of the cost calculation, indexed byindex1
in the matrix. It should have efficient random-access.second
- the collection of elements that forms the right-side of the cost calculation, indexed byindex2
in the matrix. It should have efficient random-access.symmetric
- if cost(a,b) = cost(b,a), then set this true, for quicker calculations.costCalculator
- calculates cost(a,b)- Returns:
- a newly created matrix
- Throws:
CreateException
- if either list is empty or a distance cannot be calculated between elements.
-
getCost
public double getCost(int index1, int index2) Gets the cost from an element from the first-list to an element from the second-list.- Parameters:
index1
- index of element in first listindex2
- index of element in second list- Returns:
- the cost.
-
sizeFirst
public int sizeFirst()The number of elements in the first list.- Returns:
- number of elements
-
sizeSecond
public int sizeSecond()The number of elements in the second list.- Returns:
- number of elements
-
getFirst
The first set of elements. -
getSecond
The second set of elements. -
getMatrix
public double[][] getMatrix()A two-dimensional array mapping the costs fromfirst
tosecond
. -
equals
-
hashCode
public int hashCode() -
toString
-