Hi Jane,
I did a quick test, and it seems indeed that the compiler has trouble with the div operator in preconditions. I never use any of Brahms’ math operators in preconditions, since dealing with assignments and evaluations in a precondition is problematic. You can do things easily in the body of a workframe. Here is a simple solution (I use an integer division):
/**
* @author sierhuis
* @version $Revision:$ $Date:$ $Author:$
*/
agent DivTest memberof SystemGroup {
attributes:
int x;
int y;
int z;
initial_beliefs:
(current.x = 10);
(current.y = 4);
(current.z = 2);
workframes:
workframe wf_divTest
{
repeat: true;
when ((current.z = 2))
do {
println("BEFORE: ");
printBelief(current, "z", "attribute");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
conclude((current.x = current.x + 1));
conclude((current.y = current.y + 1));
conclude((current.z = current.x / current.y));
println("AFTER: ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
printBelief(current, "z", "attribute");
}
}
}
Here is another solution (without z as a belief) :
/**
* @author sierhuis
* @version $Revision:$ $Date:$ $Author:$
*/
agent DivTest memberof SystemGroup {
attributes:
int x;
int y;
initial_beliefs:
(current.x = 10);
(current.y = 4);
workframes:
workframe wf_divTest
{
repeat: true;
variables:
forone(int) x;
forone(int) y;
forone(int) z;
when ((x = current.x) and
(y = current.y) and
(z = x / y) and
(z = 2))
do {
println("BEFORE: ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute”);
println_n(“z = %1”, z);
conclude((current.x = current.x + 1));
conclude((current.y = current.y + 1));
println("AFTER: ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
println_n(“z = %1”, z);
}
}
}
Maarten Sierhuis, Ph.D.
Founder & CTO, Ejenta