Search in sources :

Example 1 with ClassicalB

use of de.prob.animator.domainobjects.ClassicalB in project prob2 by bendisposto.

the class ConstructTraceCommand method writeCommand.

/**
 * This method is called when the command is prepared for sending. The
 * method is called by the Animator class, most likely it is not interesting
 * for other classes.
 *
 * @see de.prob.animator.command.AbstractCommand#writeCommand(de.prob.prolog.output.IPrologTermOutput)
 */
@Override
public void writeCommand(final IPrologTermOutput pto) {
    pto.openTerm(PROLOG_COMMAND_NAME).printAtomOrNumber(stateId.getId());
    pto.openList();
    for (String n : name) {
        pto.printAtom(n);
    }
    pto.closeList();
    final ASTProlog prolog = new ASTProlog(pto, null);
    pto.openList();
    for (ClassicalB cb : evalElement) {
        cb.getAst().apply(prolog);
    }
    pto.closeList();
    pto.openList();
    for (Integer n : executionNumber) {
        pto.printNumber(n);
    }
    pto.closeList();
    pto.printVariable(RESULT_VARIABLE);
    pto.printVariable(ERRORS_VARIABLE);
    pto.closeTerm();
}
Also used : ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) ClassicalB(de.prob.animator.domainobjects.ClassicalB)

Example 2 with ClassicalB

use of de.prob.animator.domainobjects.ClassicalB in project prob2 by bendisposto.

the class EvaluateFormulasCommandTest method testWriteCommand.

@Test
public void testWriteCommand() throws Exception {
    IEvalElement element = new ClassicalB("1<3", FormulaExpand.EXPAND);
    StructuredPrologOutput prologTermOutput = new StructuredPrologOutput();
    EvaluateFormulaCommand command = new EvaluateFormulaCommand(element, "root");
    command.writeCommand(prologTermOutput);
    prologTermOutput.fullstop().flush();
    Collection<PrologTerm> sentences = prologTermOutput.getSentences();
    PrologTerm t = sentences.iterator().next();
    assertNotNull(t);
    assertTrue(t instanceof CompoundPrologTerm);
    assertEquals("evaluate_formula", t.getFunctor());
    assertEquals(3, t.getArity());
    PrologTerm t1 = t.getArgument(1);
    assertEquals("root", t1.getFunctor());
    PrologTerm t2 = t.getArgument(2);
    assertEquals("eval", t2.getFunctor());
    PrologTerm t3 = t.getArgument(3);
    assertEquals("Res", t3.getFunctor());
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) IEvalElement(de.prob.animator.domainobjects.IEvalElement) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 3 with ClassicalB

use of de.prob.animator.domainobjects.ClassicalB in project prob2 by bendisposto.

the class EvaluateFormulasCommandTest method testProcessResult.

@Test
public void testProcessResult() throws Exception {
    IEvalElement element = new ClassicalB("1<3", FormulaExpand.EXPAND);
    final CompoundPrologTerm lpt = mk_result("true");
    ISimplifiedROMap<String, PrologTerm> m1 = new ISimplifiedROMap<String, PrologTerm>() {

        @Override
        public PrologTerm get(final String key) {
            return lpt;
        }
    };
    EvaluateFormulaCommand command = new EvaluateFormulaCommand(element, "root");
    command.processResult(m1);
    AbstractEvalResult value = command.getValue();
    assertEquals(((EvalResult) value).getValue(), "true");
    assertEquals(((EvalResult) value).getSolutions().get("a"), "3");
}
Also used : EvalResult(de.prob.animator.domainobjects.EvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB) ISimplifiedROMap(de.prob.parser.ISimplifiedROMap) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 4 with ClassicalB

use of de.prob.animator.domainobjects.ClassicalB in project prob2 by bendisposto.

the class UnsatMinimalCoreCommand method processResult.

@Override
public void processResult(ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm compoundTerm = BindingGenerator.getCompoundTerm(bindings.get(RESULT_VARIABLE), 0);
    String code = compoundTerm.getFunctor();
    if (pred instanceof EventB) {
        core = new EventB(code, FormulaExpand.EXPAND);
    } else {
        core = new ClassicalB(code, FormulaExpand.EXPAND);
    }
}
Also used : EventB(de.prob.animator.domainobjects.EventB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB)

Example 5 with ClassicalB

use of de.prob.animator.domainobjects.ClassicalB in project prob2 by bendisposto.

the class PrimePredicateCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm compoundTerm = BindingGenerator.getCompoundTerm(bindings.get(PRIMED_PREDICATE_VARIABLE), 0);
    String code = compoundTerm.getFunctor();
    if (evalElement instanceof EventB) {
        result = new EventB(code, FormulaExpand.EXPAND);
    } else {
        result = new ClassicalB(code, FormulaExpand.EXPAND);
    }
}
Also used : EventB(de.prob.animator.domainobjects.EventB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB)

Aggregations

ClassicalB (de.prob.animator.domainobjects.ClassicalB)9 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)6 EventB (de.prob.animator.domainobjects.EventB)4 IEvalElement (de.prob.animator.domainobjects.IEvalElement)2 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)2 PrologTerm (de.prob.prolog.term.PrologTerm)2 Test (org.junit.Test)2 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)1 GetOperationByPredicateCommand (de.prob.animator.command.GetOperationByPredicateCommand)1 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)1 EvalResult (de.prob.animator.domainobjects.EvalResult)1 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)1 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)1