use of com.ge.verdict.synthesis.util.Pair in project VERDICT by ge-high-assurance.
the class CostModel method cost.
/**
* Evaluate the cost function on the given inputs.
*
* @param defense
* @param component
* @param dal
* @return
*/
public Fraction cost(String defense, String component, int dal) {
// If DAL is not specified, we default to using DAL to linearly scale cost
// System.out.println("Loading cost: " + defense + ", " + component + ", " + dal);
Fraction lookup = compDefDalModel.get(new Triple<>(component, defense, dal));
if (lookup != null) {
return lookup;
}
lookup = compDefModel.get(new Pair<>(component, defense));
if (lookup != null) {
return lookup.multiply(dal);
}
lookup = compDalModel.get(new Pair<>(component, dal));
if (lookup != null) {
return lookup;
}
lookup = defDalModel.get(new Pair<>(defense, dal));
if (lookup != null) {
return lookup;
}
lookup = compModel.get(component);
if (lookup != null) {
return lookup.multiply(dal);
}
lookup = defModel.get(defense);
if (lookup != null) {
return lookup.multiply(dal);
}
lookup = dalModel.get(dal);
if (lookup != null) {
return lookup;
}
return defaultModel.multiply(dal);
}
use of com.ge.verdict.synthesis.util.Pair 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