-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximum.java
More file actions
43 lines (34 loc) · 1.23 KB
/
Maximum.java
File metadata and controls
43 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package javachr.examples;
import javachr.RuleApplicator;
import javachr.SimpleRuleApplicator;
import javachr.constraints.Constraint;
import javachr.rules.Rule;
import javachr.rules.Simpagation;
import java.util.List;
import java.util.Random;
import static javachr.examples.ExampleFactory.printDurationAndResult;
public class Maximum {
public static void main(String[] args) {
Random ran = new Random();
Integer[] array = new Integer[10000];
for (int i = 0; i < array.length; i++) {
array[i] = ran.nextInt(1000);
}
array[0] = 0;
Simpagation rule = new Simpagation(1, 1)
.guard((h1, h2) -> ((int) h1[0].get()) >= ((int) h2[0].get()));
List<Constraint<?>> result;
RuleApplicator solver = new SimpleRuleApplicator(rule);
// solver.setTracer(new CommandLineTracer(true));
long start = System.currentTimeMillis();
result = solver.execute(array);
long end = System.currentTimeMillis();
printDurationAndResult(start, end, result);
}
static Rule[] getRules(){
return new Rule[]{
new Simpagation(1, 1)
.guard((h1, h2) -> (int) h1[0].get() >= (int) h2[0].get())
};
}
}