21 import java.io.FileInputStream;
22 import java.io.FileNotFoundException;
24 import ca.uqac.lif.cep.Connector;
25 import ca.uqac.lif.cep.GroupProcessor;
26 import ca.uqac.lif.cep.Pullable;
27 import static ca.uqac.lif.cep.Connector.BOTTOM;
28 import static ca.uqac.lif.cep.Connector.INPUT;
29 import static ca.uqac.lif.cep.Connector.OUTPUT;
30 import static ca.uqac.lif.cep.Connector.TOP;
31 import ca.uqac.lif.cep.Connector.ConnectorException;
32 import ca.uqac.lif.cep.functions.StreamVariable;
33 import ca.uqac.lif.cep.functions.Constant;
34 import ca.uqac.lif.cep.functions.Cumulate;
35 import ca.uqac.lif.cep.functions.CumulativeFunction;
36 import ca.uqac.lif.cep.functions.ApplyFunction;
37 import ca.uqac.lif.cep.functions.FunctionTree;
38 import ca.uqac.lif.cep.io.ReadLines;
39 import ca.uqac.lif.cep.util.Booleans;
40 import ca.uqac.lif.cep.util.Equals;
41 import ca.uqac.lif.cep.util.NthElement;
42 import ca.uqac.lif.cep.util.Numbers;
43 import ca.uqac.lif.cep.util.Strings;
44 import ca.uqac.lif.cep.tmf.Filter;
45 import ca.uqac.lif.cep.tmf.Fork;
46 import ca.uqac.lif.cep.tmf.Slice;
47 import ca.uqac.lif.cep.tmf.Trim;
64 @SuppressWarnings(
"unused")
68 static final int TIME = 0, NO_CYCLE = 1, DISTANCE = 2, PUISSANCE_ELEC = 3,
69 SOC_ELEC = 4, PUISSANCE_FUEL = 5, SOC_FUEL = 6, SPEED = 7;
72 static final int CBAT = 16021800;
74 public static void main(String[] args)
throws FileNotFoundException
77 String filename =
"simple.csv";
81 ReadLines reader =
new ReadLines(Engine.class.getResourceAsStream(filename));
84 Trim first_line =
new Trim(1);
85 Connector.connect(reader, first_line);
89 ApplyFunction array_feeder =
new ApplyFunction(
new Strings.SplitString(
";"));
90 Connector.connect(first_line, array_feeder);
93 Fork fork =
new Fork(2);
94 Connector.connect(array_feeder, fork);
98 GroupProcessor add_negative_pe =
new GroupProcessor(1, 1);
100 ApplyFunction get_pe =
new ApplyFunction(
new NthElement(PUISSANCE_ELEC));
101 Fork anp_fork =
new Fork(2);
102 Connector.connect(get_pe, anp_fork);
103 ApplyFunction is_negative =
new ApplyFunction(
104 new FunctionTree(Numbers.isLessThan,
107 Filter filter =
new Filter();
108 Connector.connect(anp_fork, 0, filter, TOP);
109 Connector.connect(anp_fork, 1, is_negative, INPUT);
110 Connector.connect(is_negative, OUTPUT, filter, BOTTOM);
111 Cumulate sum_of_negatives =
new Cumulate(
new CumulativeFunction<Number>(Numbers.addition));
112 Connector.connect(filter, sum_of_negatives);
113 ApplyFunction divide =
new ApplyFunction(
new FunctionTree(Numbers.division, StreamVariable.X,
new Constant(CBAT)));
114 Connector.connect(sum_of_negatives, divide);
115 add_negative_pe.addProcessors(get_pe, anp_fork, is_negative, filter, sum_of_negatives, divide);
116 add_negative_pe.associateInput(INPUT, get_pe, INPUT);
117 add_negative_pe.associateOutput(OUTPUT, divide, OUTPUT);
122 Slice slicer =
new Slice(
new NthElement(NO_CYCLE), add_negative_pe);
123 Connector.connect(fork, TOP, slicer, INPUT);
128 ApplyFunction get_cycle_nb =
new ApplyFunction(
new NthElement(NO_CYCLE));
129 Connector.connect(fork, BOTTOM, get_cycle_nb, INPUT);
130 Fork cycle_fork =
new Fork(2);
131 Connector.connect(get_cycle_nb, cycle_fork);
132 Trim cycle_trim =
new Trim(1);
133 Connector.connect(cycle_fork, BOTTOM, cycle_trim, INPUT);
134 ApplyFunction cycle_change =
new ApplyFunction(Equals.instance);
135 Connector.connect(cycle_fork, 0, cycle_change, TOP);
136 Connector.connect(cycle_trim, OUTPUT, cycle_change, BOTTOM);
137 ApplyFunction not =
new ApplyFunction(Booleans.not);
138 Connector.connect(cycle_change, not);
141 Filter out_if_cycle_changes =
new Filter();
142 Connector.connect(slicer, OUTPUT, out_if_cycle_changes, TOP);
143 Connector.connect(not, OUTPUT, out_if_cycle_changes, BOTTOM);
146 Pullable p = out_if_cycle_changes.getPullableOutput();
147 long start = System.currentTimeMillis();
153 System.out.println(o);
155 long end = System.currentTimeMillis();
156 System.out.println((end - start) / 1000);
Compute data about the execution of a hybrid car engine.