Class SubformulaReplacer
- java.lang.Object
-
- owl.ltl.visitors.SubformulaReplacer
-
- All Implemented Interfaces:
Function<owl.ltl.Formula,owl.ltl.Formula>,owl.ltl.visitors.Visitor<owl.ltl.Formula>
public class SubformulaReplacer extends Object implements owl.ltl.visitors.Visitor<owl.ltl.Formula>
Replaces every occurrence of a given sub-formula with another, throughout an LTL formula's syntax tree.This is the "splice" step used across AuRUS's genetic operators: after
SpecificationMutatorrewrites a randomly chosen sub-formulato_mutate(viaGeneralFormulaMutator,FormulaWeakeningorFormulaStrengthening) intomutated, the change is spliced back into the full assumption or guarantee withnew SubformulaReplacer(to_mutate, mutated).apply(original).SpecificationCrossoveruses it the same way to graft a fragment transplanted from one parent into the other.The pattern. Every
visitmethod below follows the same template: if the current node structurally equalssource(viaFormula.equals(java.lang.Object)), it is replaced wholesale bytarget; otherwise the visitor recurses into the node's children and rebuilds the same kind of node from the (possibly already-replaced) results. This is a bottom-up tree rebuild, not an in-place mutation —Formulas are immutable, so the entire path from the match up to the root is reconstructed.Replace by value, not by position. Matching is structural equality, not object identity or tree position: if
sourceoccurs more than once in the formula (e.g. the same sub-formula appearing under two different conjuncts), every occurrence is replaced in the same pass. This is consistent with how callers obtainsource— e.g.FormulaUtils.subformulas(Formula)returns aSet<Formula>, deduplicating structurally identical sub-formulas before one is chosen at random — but is worth keeping in mind: this class has no notion of "the occurrence at this specific tree position", only "occurrences equal to this formula".Part of the reference implementation of: Brizzio, Cordy, Papadakis, Sánchez, Aguirre, Degiovanni. "Automated Repair of Unrealisable LTL Specifications Guided by Model Counting", GECCO 2023 (doi:10.1145/3583131.3590454).
- Author:
- Matías Brizzio
- See Also:
SpecificationMutator,SpecificationCrossover,FormulaUtils
-
-
Constructor Summary
Constructors Constructor Description SubformulaReplacer(owl.ltl.Formula source, owl.ltl.Formula target)Creates a replacer that will substitute every occurrence ofsourcewithtarget.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description owl.ltl.Formulaapply(owl.ltl.Formula formula)Entry point: applies the replacement throughout the given formula.owl.ltl.Formulavisit(owl.ltl.Biconditional biconditional)Replaces if this node matchessource; otherwise recurses into both operands.owl.ltl.Formulavisit(owl.ltl.BooleanConstant booleanConstant)Replaces if this node matchessource; a boolean constant has no children to recurse into.owl.ltl.Formulavisit(owl.ltl.Conjunction conjunction)Replaces if this node matchessource; otherwise recurses into every conjunct.owl.ltl.Formulavisit(owl.ltl.Disjunction disjunction)Replaces if this node matchessource; otherwise recurses into every disjunct.owl.ltl.Formulavisit(owl.ltl.FOperator fOperator)Replaces if this node matchessource; otherwise recurses into the operand.owl.ltl.Formulavisit(owl.ltl.FrequencyG freq)Replaces if this node matchessource; otherwise recurses into the operand.owl.ltl.Formulavisit(owl.ltl.GOperator gOperator)Replaces if this node matchessource; otherwise recurses into the operand.owl.ltl.Formulavisit(owl.ltl.HOperator hOperator)Replaces if this node matchessource; otherwise recurses into the operand (past-time "historically").owl.ltl.Formulavisit(owl.ltl.Literal literal)Replaces if this literal matchessource; a literal has no children to recurse into.owl.ltl.Formulavisit(owl.ltl.MOperator mOperator)Replaces if this node matchessource; otherwise recurses into both operands ("strong release").owl.ltl.Formulavisit(owl.ltl.OOperator oOperator)Replaces if this node matchessource; otherwise recurses into the operand (past-time "once").owl.ltl.Formulavisit(owl.ltl.ROperator rOperator)Replaces if this node matchessource; otherwise recurses into both operands ("release").owl.ltl.Formulavisit(owl.ltl.SOperator sOperator)Replaces if this node matchessource; otherwise recurses into both operands (past-time "since").owl.ltl.Formulavisit(owl.ltl.TOperator tOperator)Replaces if this node matchessource; otherwise recurses into both operands (past-time "trigger").owl.ltl.Formulavisit(owl.ltl.UOperator uOperator)Replaces if this node matchessource; otherwise recurses into both operands ("until").owl.ltl.Formulavisit(owl.ltl.WOperator wOperator)Replaces if this node matchessource; otherwise recurses into both operands ("weak until").owl.ltl.Formulavisit(owl.ltl.XOperator xOperator)Replaces if this node matchessource; otherwise recurses into the operand ("next").owl.ltl.Formulavisit(owl.ltl.YOperator yOperator)Replaces if this node matchessource; otherwise recurses into the operand (past-time "yesterday").owl.ltl.Formulavisit(owl.ltl.ZOperator zOperator)Replaces if this node matchessource; otherwise recurses into the operand (past-time "weak yesterday").
-
-
-
Method Detail
-
apply
public owl.ltl.Formula apply(owl.ltl.Formula formula)
Entry point: applies the replacement throughout the given formula.
-
visit
public owl.ltl.Formula visit(owl.ltl.Biconditional biconditional)
Replaces if this node matchessource; otherwise recurses into both operands.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.BooleanConstant booleanConstant)
Replaces if this node matchessource; a boolean constant has no children to recurse into.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.Conjunction conjunction)
Replaces if this node matchessource; otherwise recurses into every conjunct.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.Disjunction disjunction)
Replaces if this node matchessource; otherwise recurses into every disjunct.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.FOperator fOperator)
Replaces if this node matchessource; otherwise recurses into the operand.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.FrequencyG freq)
Replaces if this node matchessource; otherwise recurses into the operand.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.GOperator gOperator)
Replaces if this node matchessource; otherwise recurses into the operand.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.HOperator hOperator)
Replaces if this node matchessource; otherwise recurses into the operand (past-time "historically").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.Literal literal)
Replaces if this literal matchessource; a literal has no children to recurse into.- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.MOperator mOperator)
Replaces if this node matchessource; otherwise recurses into both operands ("strong release").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.OOperator oOperator)
Replaces if this node matchessource; otherwise recurses into the operand (past-time "once").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.ROperator rOperator)
Replaces if this node matchessource; otherwise recurses into both operands ("release").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.SOperator sOperator)
Replaces if this node matchessource; otherwise recurses into both operands (past-time "since").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.TOperator tOperator)
Replaces if this node matchessource; otherwise recurses into both operands (past-time "trigger").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.UOperator uOperator)
Replaces if this node matchessource; otherwise recurses into both operands ("until").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.WOperator wOperator)
Replaces if this node matchessource; otherwise recurses into both operands ("weak until").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.XOperator xOperator)
Replaces if this node matchessource; otherwise recurses into the operand ("next").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.YOperator yOperator)
Replaces if this node matchessource; otherwise recurses into the operand (past-time "yesterday").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
visit
public owl.ltl.Formula visit(owl.ltl.ZOperator zOperator)
Replaces if this node matchessource; otherwise recurses into the operand (past-time "weak yesterday").- Specified by:
visitin interfaceowl.ltl.visitors.Visitor<owl.ltl.Formula>
-
-