use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class RemoveCondacts method clockArrowsAndPres.
private Node clockArrowsAndPres(Node node, final IdExpr clock) {
final VarDecl init = new VarDecl(namePrefix + "init", NamedType.BOOL);
final List<Equation> preEquations = new ArrayList<>();
final List<VarDecl> preLocals = new ArrayList<>();
node = (Node) node.accept(new AstMapVisitor() {
private int counter = 0;
@Override
public Expr visit(BinaryExpr e) {
if (e.op == BinaryOp.ARROW) {
return new IfThenElseExpr(new IdExpr(init.id), e.left.accept(this), e.right.accept(this));
} else {
return super.visit(e);
}
}
@Override
public Expr visit(UnaryExpr e) {
if (e.op == UnaryOp.PRE) {
String state = namePrefix + "state" + counter++;
Type type = e.expr.accept(typeReconstructor);
preLocals.add(new VarDecl(state, type));
// state = if clock then expr else pre state
preEquations.add(new Equation(new IdExpr(state), new IfThenElseExpr(clock, e.expr.accept(this), new UnaryExpr(UnaryOp.PRE, new IdExpr(state)))));
return new UnaryExpr(UnaryOp.PRE, new IdExpr(state));
} else {
return super.visit(e);
}
}
});
NodeBuilder builder = new NodeBuilder(node);
builder.addLocals(preLocals);
builder.addLocal(init);
builder.addEquations(preEquations);
// init = true -> if pre clock then false else pre init
builder.addEquation(new Equation(new IdExpr(init.id), new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, new IfThenElseExpr(new UnaryExpr(UnaryOp.PRE, clock), new BoolExpr(false), new UnaryExpr(UnaryOp.PRE, new IdExpr(init.id))))));
return builder.build();
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class RemovePropertySatisficationRequirements method transform.
// private final static String assumeBaseId = "__ASSUME";
public static SimulationProgram transform(final SimulationProgram program) {
final SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(program.getLustreProgram());
lustreProgramBuilder.clearNodes();
for (final Node node : program.getLustreProgram().nodes) {
final NodeBuilder nodeBuilder = new NodeBuilder(new AstMapVisitor() {
@Override
public Node visit(final Node n) {
return super.visit(n);
}
@Override
public Equation visit(final Equation e) {
// Force the assumption conjunction to be true
if (e.lhs.size() == 1 && e.lhs.get(0).id.equals(assumptionConjunctionId)) {
return new Equation(new IdExpr(assumptionConjunctionId), new BoolExpr(true));
}
final Equation result = super.visit(e);
return result;
}
}.visit(node));
lustreProgramBuilder.addNode(nodeBuilder.build());
}
simulationProgramBuilder.setLustreProgram(lustreProgramBuilder.build());
return simulationProgramBuilder.build();
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class Main method testReal.
private static void testReal() throws IOException {
System.out.println("=============Real Test=============");
final Evaluator baseEvaluator = createEvaluator(INPUT_DIRECTORY + "symb_test_real.lus");
final Evaluator evaluator = new Evaluator(baseEvaluator, Arrays.asList(new BinaryExpr(new IdExpr("__SIM_PE___ASSUME0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE___ASSUME1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("in1"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(60))), new BinaryExpr(new IdExpr("in2"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(10)))));
testValue("in1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(60))));
testValue("in2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(10))));
testValue("out1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(30))));
testValue("out2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(20))));
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AGREESimulationState method createEvaluator.
private Evaluator createEvaluator(final Collection<Expr> constraints, final Set<SimulationProperty> disabledProperties) {
try {
final SimulationFrameResults lastFrameResults = frameInfos.size() == 0 ? null : frameInfos.get(frameInfos.size() - 1).getFrameResults();
final List<Expr> assertions = new ArrayList<Expr>();
FrameAssertionHelper.addNextFrameAssertions(simulationProgram, lastFrameResults, assertions);
assertions.addAll(constraints);
// Add assertions for property enablement variables
for (final SimulationProperty simProp : simulationProgram.getSimulationProperties()) {
if (simProp.getEnablementVariableId() != null) {
assertions.add(new BinaryExpr(new IdExpr(simProp.getEnablementVariableId()), BinaryOp.EQUAL, new BoolExpr(disabledProperties.contains(simProp) ? false : true)));
}
}
// Create the new evaluator
return new Evaluator(baseEvaluator, assertions);
} catch (EvaluationException ex) {
return null;
}
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method getMNSynchConstraint.
private Expr getMNSynchConstraint(MNSynchStatement sync) {
Set<String> nodeNames = new HashSet<>();
Expr clockAssertion = new BoolExpr(true);
for (int i = 0; i < sync.getComp1().size(); i++) {
Subcomponent maxComp = (Subcomponent) sync.getComp1().get(i);
Subcomponent minComp = (Subcomponent) sync.getComp2().get(i);
Expr maxClock = new IdExpr(maxComp.getName() + clockIDSuffix);
Expr minClock = new IdExpr(minComp.getName() + clockIDSuffix);
int max = Integer.valueOf(sync.getMax().get(i));
int min = Integer.valueOf(sync.getMin().get(i));
MNSynchronyElement elem = new MNSynchronyElement(maxClock, minClock, max, min);
String nodeName = "__calendar_node_" + elem.max + "_" + elem.min;
nodeName = getObjectLocationPrefix(sync) + nodeName;
if (!nodeNames.contains(nodeName)) {
nodeNames.add(nodeName);
Node calNode = AgreeCalendarUtils.getMNCalendar(nodeName, elem.max, elem.min);
addToNodeList(calNode);
}
NodeCallExpr nodeCall = new NodeCallExpr(nodeName, elem.maxClock, elem.minClock);
clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
nodeCall = new NodeCallExpr(nodeName, elem.minClock, elem.maxClock);
clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
}
return clockAssertion;
}
Aggregations