Search in sources :

Example 1 with ArithmeticUtils

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;
}
Also used : IntStream(java.util.stream.IntStream) Optimize(com.microsoft.z3.Optimize) Context(com.microsoft.z3.Context) Formula(org.logicng.formulas.Formula) Assignment(org.logicng.datastructures.Assignment) MaxSATSolver(org.logicng.solvers.MaxSATSolver) RatNum(com.microsoft.z3.RatNum) ArrayList(java.util.ArrayList) Map(java.util.Map) FormulaFactory(org.logicng.formulas.FormulaFactory) BoolExpr(com.microsoft.z3.BoolExpr) Status(com.microsoft.z3.Status) DTree(com.ge.verdict.synthesis.dtree.DTree) ArithExpr(com.microsoft.z3.ArithExpr) LinkedHashSet(java.util.LinkedHashSet) DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) PrintWriter(java.io.PrintWriter) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) Model(com.microsoft.z3.Model) List(java.util.List) Fraction(org.apache.commons.math3.fraction.Fraction) ArithmeticUtils(org.apache.commons.math3.util.ArithmeticUtils) Pair(com.ge.verdict.synthesis.util.Pair) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Expr(com.microsoft.z3.Expr) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) ArithmeticUtils(org.apache.commons.math3.util.ArithmeticUtils) Fraction(org.apache.commons.math3.fraction.Fraction)

Aggregations

DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)1 ComponentDefense (com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense)1 DTree (com.ge.verdict.synthesis.dtree.DTree)1 Pair (com.ge.verdict.synthesis.util.Pair)1 ResultsInstance (com.ge.verdict.vdm.synthesis.ResultsInstance)1 ArithExpr (com.microsoft.z3.ArithExpr)1 BoolExpr (com.microsoft.z3.BoolExpr)1 Context (com.microsoft.z3.Context)1 Expr (com.microsoft.z3.Expr)1 Model (com.microsoft.z3.Model)1 Optimize (com.microsoft.z3.Optimize)1 RatNum (com.microsoft.z3.RatNum)1 Status (com.microsoft.z3.Status)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1