20 import ca.uqac.lif.cep.fsm.FunctionTransition;
21 import ca.uqac.lif.cep.fsm.MooreMachine;
22 import ca.uqac.lif.cep.fsm.TransitionOtherwise;
23 import ca.uqac.lif.cep.functions.Constant;
24 import ca.uqac.lif.cep.functions.Function;
25 import ca.uqac.lif.cep.functions.FunctionTree;
26 import ca.uqac.lif.cep.functions.StreamVariable;
27 import ca.uqac.lif.cep.util.Numbers;
32 private static final int ST_0 = 0;
33 private static final int ST_1 = 1;
34 private static final int ST_2 = 2;
35 private static final int ST_3 = 3;
36 private static final int ST_4 = 4;
42 addTransition(ST_0,
new FunctionTransition(
43 withinRange(0, peak, interval),
47 new TransitionOtherwise(ST_0));
48 addTransition(ST_1,
new FunctionTransition(
49 withinRange(1, plateau, interval),
53 new TransitionOtherwise(ST_1));
54 addTransition(ST_2,
new FunctionTransition(
55 withinRange(1, drop, interval),
59 new TransitionOtherwise(ST_4));
60 addTransition(ST_3,
new FunctionTransition(
61 withinRange(0, peak, interval),
65 new TransitionOtherwise(ST_0));
66 addTransition(ST_4,
new FunctionTransition(
67 withinRange(1, drop, interval),
71 new TransitionOtherwise(ST_4));
73 addSymbol(ST_0,
new Constant(
"No change"));
74 addSymbol(ST_1,
new Constant(
"No change"));
75 addSymbol(ST_2,
new Constant(
"Appliance ON"));
76 addSymbol(ST_3,
new Constant (
"Appliance OFF"));
77 addSymbol(ST_4,
new Constant(
"No change"));
87 private static Function withinRange(
int component,
float value,
float interval)
89 StreamVariable var = StreamVariable.X;
92 var = StreamVariable.Y;
94 FunctionTree f =
new FunctionTree(Numbers.isLessThan,
95 new FunctionTree(Numbers.absoluteValue,
96 new FunctionTree(Numbers.subtraction,
98 new Constant(value))),
99 new Constant(interval));