T
- element-type in listspublic final class CostMatrix<T> extends Object
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.
Modifier and Type | Method and Description |
---|---|
static <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 |
equals(Object o) |
double |
getCost(int index1,
int index2)
Gets the cost from an element from the first-list to an element from the second-list.
|
List<T> |
getFirst()
The first set of elements.
|
double[][] |
getMatrix()
A two-dimensional array mapping the costs from
first to second . |
List<T> |
getSecond()
The second set of elements.
|
int |
hashCode() |
int |
sizeFirst()
The number of elements in the first list.
|
int |
sizeSecond()
The number of elements in the second list.
|
String |
toString() |
public static <T> CostMatrix<T> create(List<T> first, List<T> second, boolean symmetric, CheckedToDoubleBiFunction<T,T,CreateException> costCalculator) throws CreateException
All possible pairings are calculated involving an element from the first list and an element from the second list.
T
- element-type in listsfirst
- the collection of elements that forms the left-side of the cost calculation,
indexed by index1
in the matrix. It should have efficient random-access.second
- the collection of elements that forms the right-side of the cost calculation,
indexed by index2
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)CreateException
- if either list is empty or a distance cannot be calculated between
elements.public double getCost(int index1, int index2)
index1
- index of element in first listindex2
- index of element in second listpublic int sizeFirst()
public int sizeSecond()
public double[][] getMatrix()
first
to second
.Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.