use of org.apache.commons.math3.util.ArithmeticUtils in project VERDICT by ge-high-assurance.
the class VerdictSynthesis method normalizeCosts.
/**
* Calculates (and returns) lowest common denominator of all leaf costs, and sets the
* normalizedCost field in each leaf accordingly.
*
* @param pairs
* @return
* @deprecated use the multi-requirement approach instead
*/
@Deprecated
public static int normalizeCosts(Collection<ComponentDefense> pairs) {
int costLcd = pairs.stream().flatMap((ComponentDefense pair) -> IntStream.range(0, 10).map(dal -> pair.dalToRawCost(dal).getDenominator()).mapToObj(// kind of dumb but need to go
x -> x)).reduce(1, ArithmeticUtils::lcm);
for (ComponentDefense pair : pairs) {
int[] normCosts = new int[10];
for (int dal = 0; dal < 10; dal++) {
Fraction normalizedCost = pair.dalToRawCost(dal).multiply(costLcd);
if (normalizedCost.getDenominator() != 1) {
throw new RuntimeException();
}
normCosts[dal] = normalizedCost.getNumerator();
}
pair.normalizeCosts(normCosts);
}
return costLcd;
}
Aggregations