-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain8.java
More file actions
39 lines (32 loc) · 1.29 KB
/
Main8.java
File metadata and controls
39 lines (32 loc) · 1.29 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
import java.util.List;
import java.util.Scanner;
import java.util.stream.Stream;
import java.util.stream.Collectors;
import java.util.function.Supplier;
import java.util.Random;
import cs2030.util.Pair;
import cs2030.simulator.Simulate8;
class Main8 {
private static final Random rngRest = new Random(3);
private static final Random rngRestPeriod = new Random(4);
static double genRestPeriod() {
return -Math.log(rngRestPeriod.nextDouble()) / 0.1;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Pair<Double, Supplier<Double>>> inputTimes;
int numOfServers = sc.nextInt();
int numOfSelfChecks = sc.nextInt();
int qmax = sc.nextInt();
int numOfCustomers = sc.nextInt();
double probRest = sc.nextDouble();
inputTimes = Stream.<Pair<Double, Supplier<Double>>>generate(() ->
Pair.of(sc.nextDouble(), () -> sc.nextDouble()))
.limit(numOfCustomers)
.collect(Collectors.toUnmodifiableList());
Supplier<Double> restTimes = () ->
rngRest.nextDouble() < probRest ? genRestPeriod() : 0.0;
Simulate8 sim = new Simulate8(numOfServers, numOfSelfChecks, inputTimes, qmax, restTimes);
System.out.println(sim.run());
}
}