@Test public void testOperatorMultilineMultiinstance() { Multiset<Node> components = HashMultiset.create(); components.add(x); components.add(y); components.add(v); components.add(IntConst.of(1)); components.add(Library.GT); components.add(Library.GE); Map<AngelixLocation, Multiset<Node>> componentsMap = new HashMap<>(); componentsMap.put(loc1, components); componentsMap.put(loc2, components); AngelicForest angelicForest = null; try { InputStream is = this.getClass().getResourceAsStream("af4.json"); angelicForest = AngelicForest.parse(is); is.close(); } catch (IOException e) { e.printStackTrace(); } Map<AngelixLocation, Expression> original = new HashMap<>(); Map<Hole, Expression> args = new HashMap<>(); args.put((Hole) Library.GT.getLeft(), Expression.leaf(x)); args.put((Hole) Library.GT.getRight(), Expression.leaf(y)); original.put(loc1, Expression.app(Library.GT, args)); Map<Hole, Expression> args2 = new HashMap<>(); args2.put((Hole) Library.GT.getLeft(), Expression.leaf(v)); args2.put((Hole) Library.GT.getRight(), Expression.leaf(IntConst.of(1))); original.put(loc2, Expression.app(Library.GT, args2)); Optional<Map<AngelixLocation, Node>> result = synthesizer.repair(original, angelicForest, componentsMap, SynthesisLevel.OPERATORS); assertTrue(result.isPresent()); Assert.assertEquals(new GreaterOrEqual(x, y), result.get().get(loc1)); Assert.assertEquals(new GreaterOrEqual(v, IntConst.of(1)), result.get().get(loc2)); }
public Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original, AngelicForest angelicForest, Map<AngelixLocation, Multiset<Node>> components, SynthesisLevel level) { Set<AngelixLocation> locations = angelicForest.getAllLocations(); assert locations.stream().filter(loc -> !original.containsKey(loc)).count() == 0; List<Node> hard = new ArrayList<>(); List<Node> soft = new ArrayList<>(); TreeBoundedEncoder encoder = new TreeBoundedEncoder(); Map<AngelixLocation, Triple<Variable, Pair<List<Node>, List<Node>>, EncodingInfo>> encodings = new HashMap<>(); for (AngelixLocation loc : locations) { Shape shape = new RepairShape(original.get(loc), level); encodings.put(loc, encoder.encode(shape, components.get(loc))); } for (Map.Entry<AngelixTest, List<AngelicPath>> entry : angelicForest.getPaths().entrySet()) { AngelixTest test = entry.getKey(); List<AngelicPath> paths = entry.getValue(); List<Node> testClauses = new ArrayList<>(); for (AngelicPath path : paths) { Map<AngelixLocation, Map<Integer, Pair<Constant, Map<ProgramVariable, Constant>>>> angelicForLoc = path.getAngelicValues(); List<Node> pathClauses = new ArrayList<>(); for (AngelixLocation loc : locations) { List<Node> locationClauses = new ArrayList<>(); for (Map.Entry<Integer, Pair<Constant, Map<ProgramVariable, Constant>>> content : angelicForLoc.get(loc).entrySet()) { int instance = content.getKey(); List<Node> synthesisClauses = new ArrayList<>(encodings.get(loc).getMiddle().getLeft()); synthesisClauses.addAll(angelicConstraints(encodings.get(loc).getLeft(), content.getValue())); List<Node> instantiated = synthesisClauses.stream().map(n -> n.instantiate(instance)).collect(Collectors.toList()); locationClauses.addAll(instantiated); } List<Node> instantiated = locationClauses.stream().map(n -> n.instantiate(loc)).collect(Collectors.toList()); pathClauses.addAll(instantiated); } List<Node> instantiated = pathClauses.stream().map(n -> n.instantiate(test)).collect(Collectors.toList()); testClauses.add(Node.conjunction(instantiated)); } hard.add(Node.disjunction(testClauses)); } for (AngelixLocation location : locations) { soft.addAll(encodings.get(location).getMiddle().getRight()); } Optional<Map<Variable, Constant>> solverResult = solver.maxsat(hard, soft); if (solverResult.isPresent()) { Map<AngelixLocation, Node> result = new HashMap<>(); for (AngelixLocation loc : locations) { Map<Variable, Constant> relevant = relevantSubmodel(solverResult.get(), loc); Pair<Expression, Map<Parameter, Constant>> decoded = encoder.decode(relevant, encodings.get(loc).getLeft(), encodings.get(loc).getRight()); result.put(loc, decoded.getLeft().getSemantics(decoded.getRight())); } return Optional.of(result); } else { return Optional.empty(); } }
AngelixSynthesis { public Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original, AngelicForest angelicForest, Map<AngelixLocation, Multiset<Node>> components, SynthesisLevel level) { Set<AngelixLocation> locations = angelicForest.getAllLocations(); assert locations.stream().filter(loc -> !original.containsKey(loc)).count() == 0; List<Node> hard = new ArrayList<>(); List<Node> soft = new ArrayList<>(); TreeBoundedEncoder encoder = new TreeBoundedEncoder(); Map<AngelixLocation, Triple<Variable, Pair<List<Node>, List<Node>>, EncodingInfo>> encodings = new HashMap<>(); for (AngelixLocation loc : locations) { Shape shape = new RepairShape(original.get(loc), level); encodings.put(loc, encoder.encode(shape, components.get(loc))); } for (Map.Entry<AngelixTest, List<AngelicPath>> entry : angelicForest.getPaths().entrySet()) { AngelixTest test = entry.getKey(); List<AngelicPath> paths = entry.getValue(); List<Node> testClauses = new ArrayList<>(); for (AngelicPath path : paths) { Map<AngelixLocation, Map<Integer, Pair<Constant, Map<ProgramVariable, Constant>>>> angelicForLoc = path.getAngelicValues(); List<Node> pathClauses = new ArrayList<>(); for (AngelixLocation loc : locations) { List<Node> locationClauses = new ArrayList<>(); for (Map.Entry<Integer, Pair<Constant, Map<ProgramVariable, Constant>>> content : angelicForLoc.get(loc).entrySet()) { int instance = content.getKey(); List<Node> synthesisClauses = new ArrayList<>(encodings.get(loc).getMiddle().getLeft()); synthesisClauses.addAll(angelicConstraints(encodings.get(loc).getLeft(), content.getValue())); List<Node> instantiated = synthesisClauses.stream().map(n -> n.instantiate(instance)).collect(Collectors.toList()); locationClauses.addAll(instantiated); } List<Node> instantiated = locationClauses.stream().map(n -> n.instantiate(loc)).collect(Collectors.toList()); pathClauses.addAll(instantiated); } List<Node> instantiated = pathClauses.stream().map(n -> n.instantiate(test)).collect(Collectors.toList()); testClauses.add(Node.conjunction(instantiated)); } hard.add(Node.disjunction(testClauses)); } for (AngelixLocation location : locations) { soft.addAll(encodings.get(location).getMiddle().getRight()); } Optional<Map<Variable, Constant>> solverResult = solver.maxsat(hard, soft); if (solverResult.isPresent()) { Map<AngelixLocation, Node> result = new HashMap<>(); for (AngelixLocation loc : locations) { Map<Variable, Constant> relevant = relevantSubmodel(solverResult.get(), loc); Pair<Expression, Map<Parameter, Constant>> decoded = encoder.decode(relevant, encodings.get(loc).getLeft(), encodings.get(loc).getRight()); result.put(loc, decoded.getLeft().getSemantics(decoded.getRight())); } return Optional.of(result); } else { return Optional.empty(); } } }
AngelixSynthesis { public Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original, AngelicForest angelicForest, Map<AngelixLocation, Multiset<Node>> components, SynthesisLevel level) { Set<AngelixLocation> locations = angelicForest.getAllLocations(); assert locations.stream().filter(loc -> !original.containsKey(loc)).count() == 0; List<Node> hard = new ArrayList<>(); List<Node> soft = new ArrayList<>(); TreeBoundedEncoder encoder = new TreeBoundedEncoder(); Map<AngelixLocation, Triple<Variable, Pair<List<Node>, List<Node>>, EncodingInfo>> encodings = new HashMap<>(); for (AngelixLocation loc : locations) { Shape shape = new RepairShape(original.get(loc), level); encodings.put(loc, encoder.encode(shape, components.get(loc))); } for (Map.Entry<AngelixTest, List<AngelicPath>> entry : angelicForest.getPaths().entrySet()) { AngelixTest test = entry.getKey(); List<AngelicPath> paths = entry.getValue(); List<Node> testClauses = new ArrayList<>(); for (AngelicPath path : paths) { Map<AngelixLocation, Map<Integer, Pair<Constant, Map<ProgramVariable, Constant>>>> angelicForLoc = path.getAngelicValues(); List<Node> pathClauses = new ArrayList<>(); for (AngelixLocation loc : locations) { List<Node> locationClauses = new ArrayList<>(); for (Map.Entry<Integer, Pair<Constant, Map<ProgramVariable, Constant>>> content : angelicForLoc.get(loc).entrySet()) { int instance = content.getKey(); List<Node> synthesisClauses = new ArrayList<>(encodings.get(loc).getMiddle().getLeft()); synthesisClauses.addAll(angelicConstraints(encodings.get(loc).getLeft(), content.getValue())); List<Node> instantiated = synthesisClauses.stream().map(n -> n.instantiate(instance)).collect(Collectors.toList()); locationClauses.addAll(instantiated); } List<Node> instantiated = locationClauses.stream().map(n -> n.instantiate(loc)).collect(Collectors.toList()); pathClauses.addAll(instantiated); } List<Node> instantiated = pathClauses.stream().map(n -> n.instantiate(test)).collect(Collectors.toList()); testClauses.add(Node.conjunction(instantiated)); } hard.add(Node.disjunction(testClauses)); } for (AngelixLocation location : locations) { soft.addAll(encodings.get(location).getMiddle().getRight()); } Optional<Map<Variable, Constant>> solverResult = solver.maxsat(hard, soft); if (solverResult.isPresent()) { Map<AngelixLocation, Node> result = new HashMap<>(); for (AngelixLocation loc : locations) { Map<Variable, Constant> relevant = relevantSubmodel(solverResult.get(), loc); Pair<Expression, Map<Parameter, Constant>> decoded = encoder.decode(relevant, encodings.get(loc).getLeft(), encodings.get(loc).getRight()); result.put(loc, decoded.getLeft().getSemantics(decoded.getRight())); } return Optional.of(result); } else { return Optional.empty(); } } AngelixSynthesis(); }
AngelixSynthesis { public Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original, AngelicForest angelicForest, Map<AngelixLocation, Multiset<Node>> components, SynthesisLevel level) { Set<AngelixLocation> locations = angelicForest.getAllLocations(); assert locations.stream().filter(loc -> !original.containsKey(loc)).count() == 0; List<Node> hard = new ArrayList<>(); List<Node> soft = new ArrayList<>(); TreeBoundedEncoder encoder = new TreeBoundedEncoder(); Map<AngelixLocation, Triple<Variable, Pair<List<Node>, List<Node>>, EncodingInfo>> encodings = new HashMap<>(); for (AngelixLocation loc : locations) { Shape shape = new RepairShape(original.get(loc), level); encodings.put(loc, encoder.encode(shape, components.get(loc))); } for (Map.Entry<AngelixTest, List<AngelicPath>> entry : angelicForest.getPaths().entrySet()) { AngelixTest test = entry.getKey(); List<AngelicPath> paths = entry.getValue(); List<Node> testClauses = new ArrayList<>(); for (AngelicPath path : paths) { Map<AngelixLocation, Map<Integer, Pair<Constant, Map<ProgramVariable, Constant>>>> angelicForLoc = path.getAngelicValues(); List<Node> pathClauses = new ArrayList<>(); for (AngelixLocation loc : locations) { List<Node> locationClauses = new ArrayList<>(); for (Map.Entry<Integer, Pair<Constant, Map<ProgramVariable, Constant>>> content : angelicForLoc.get(loc).entrySet()) { int instance = content.getKey(); List<Node> synthesisClauses = new ArrayList<>(encodings.get(loc).getMiddle().getLeft()); synthesisClauses.addAll(angelicConstraints(encodings.get(loc).getLeft(), content.getValue())); List<Node> instantiated = synthesisClauses.stream().map(n -> n.instantiate(instance)).collect(Collectors.toList()); locationClauses.addAll(instantiated); } List<Node> instantiated = locationClauses.stream().map(n -> n.instantiate(loc)).collect(Collectors.toList()); pathClauses.addAll(instantiated); } List<Node> instantiated = pathClauses.stream().map(n -> n.instantiate(test)).collect(Collectors.toList()); testClauses.add(Node.conjunction(instantiated)); } hard.add(Node.disjunction(testClauses)); } for (AngelixLocation location : locations) { soft.addAll(encodings.get(location).getMiddle().getRight()); } Optional<Map<Variable, Constant>> solverResult = solver.maxsat(hard, soft); if (solverResult.isPresent()) { Map<AngelixLocation, Node> result = new HashMap<>(); for (AngelixLocation loc : locations) { Map<Variable, Constant> relevant = relevantSubmodel(solverResult.get(), loc); Pair<Expression, Map<Parameter, Constant>> decoded = encoder.decode(relevant, encodings.get(loc).getLeft(), encodings.get(loc).getRight()); result.put(loc, decoded.getLeft().getSemantics(decoded.getRight())); } return Optional.of(result); } else { return Optional.empty(); } } AngelixSynthesis(); Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original,
                                                       AngelicForest angelicForest,
                                                       Map<AngelixLocation, Multiset<Node>> components,
                                                       SynthesisLevel level); }
AngelixSynthesis { public Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original, AngelicForest angelicForest, Map<AngelixLocation, Multiset<Node>> components, SynthesisLevel level) { Set<AngelixLocation> locations = angelicForest.getAllLocations(); assert locations.stream().filter(loc -> !original.containsKey(loc)).count() == 0; List<Node> hard = new ArrayList<>(); List<Node> soft = new ArrayList<>(); TreeBoundedEncoder encoder = new TreeBoundedEncoder(); Map<AngelixLocation, Triple<Variable, Pair<List<Node>, List<Node>>, EncodingInfo>> encodings = new HashMap<>(); for (AngelixLocation loc : locations) { Shape shape = new RepairShape(original.get(loc), level); encodings.put(loc, encoder.encode(shape, components.get(loc))); } for (Map.Entry<AngelixTest, List<AngelicPath>> entry : angelicForest.getPaths().entrySet()) { AngelixTest test = entry.getKey(); List<AngelicPath> paths = entry.getValue(); List<Node> testClauses = new ArrayList<>(); for (AngelicPath path : paths) { Map<AngelixLocation, Map<Integer, Pair<Constant, Map<ProgramVariable, Constant>>>> angelicForLoc = path.getAngelicValues(); List<Node> pathClauses = new ArrayList<>(); for (AngelixLocation loc : locations) { List<Node> locationClauses = new ArrayList<>(); for (Map.Entry<Integer, Pair<Constant, Map<ProgramVariable, Constant>>> content : angelicForLoc.get(loc).entrySet()) { int instance = content.getKey(); List<Node> synthesisClauses = new ArrayList<>(encodings.get(loc).getMiddle().getLeft()); synthesisClauses.addAll(angelicConstraints(encodings.get(loc).getLeft(), content.getValue())); List<Node> instantiated = synthesisClauses.stream().map(n -> n.instantiate(instance)).collect(Collectors.toList()); locationClauses.addAll(instantiated); } List<Node> instantiated = locationClauses.stream().map(n -> n.instantiate(loc)).collect(Collectors.toList()); pathClauses.addAll(instantiated); } List<Node> instantiated = pathClauses.stream().map(n -> n.instantiate(test)).collect(Collectors.toList()); testClauses.add(Node.conjunction(instantiated)); } hard.add(Node.disjunction(testClauses)); } for (AngelixLocation location : locations) { soft.addAll(encodings.get(location).getMiddle().getRight()); } Optional<Map<Variable, Constant>> solverResult = solver.maxsat(hard, soft); if (solverResult.isPresent()) { Map<AngelixLocation, Node> result = new HashMap<>(); for (AngelixLocation loc : locations) { Map<Variable, Constant> relevant = relevantSubmodel(solverResult.get(), loc); Pair<Expression, Map<Parameter, Constant>> decoded = encoder.decode(relevant, encodings.get(loc).getLeft(), encodings.get(loc).getRight()); result.put(loc, decoded.getLeft().getSemantics(decoded.getRight())); } return Optional.of(result); } else { return Optional.empty(); } } AngelixSynthesis(); Optional<Map<AngelixLocation, Node>> repair(Map<AngelixLocation, Expression> original,
                                                       AngelicForest angelicForest,
                                                       Map<AngelixLocation, Multiset<Node>> components,
                                                       SynthesisLevel level);  }