This repository was archived by the owner on Nov 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimulateXmi.java
More file actions
130 lines (102 loc) · 3.86 KB
/
SimulateXmi.java
File metadata and controls
130 lines (102 loc) · 3.86 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package test;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import tll.Component;
import tll.Item;
import tll.ItemHistoryEntry;
import tll.LocationHistoryEntry;
public class SimulateXmi extends Simulate {
public static void main(String[] args) throws IOException {
new SimulateXmi().run(args[0]);
}
@Override
protected Resource getResource(String modelName) throws IOException {
Resource resource = new ResourceSetImpl().createResource(URI.createFileURI("sim-results/" + modelName + ".xmi"));
return resource;
}
@Override
protected void configure(tll.System system) {
// system.getSimconfig().setEnableLogging(true);
// system.getSimconfig().setRecordHistory(true);
// system.getSimconfig().setStoreProcessedItems(true);
}
@Override
protected void query(tll.System system) {
System.out.println("Metamodel-based queries");
super.query(system);
}
@Override
protected Set<Item> query0(tll.System system, String machineId) {
// query all items which have been processed by m3
Set<Item> items = new HashSet<Item>();
// component to check
Component machine = system.getArea().get(0).getComponent().stream().filter(c -> machineId.equals(c.getId())).reduce((a, b) -> null).get();
for(Item i : system.getArea().get(0).getStore().getFinalItems()) {
for (LocationHistoryEntry lhe : i.getHLocation()) {
if(lhe.getEnd() != null) {
if(lhe.getHValue().equals(machine)) {
items.add((Item)lhe.eContainer());
}
}
}
}
return items;
}
@Override
protected Set<Component> query1(tll.System system, Timestamp instant) {
// query assigned component for one particular point in time
Set<Component> assignedComponents = new HashSet<Component>();
for(Item i : system.getArea().get(0).getStore().getFinalItems()) {
for (LocationHistoryEntry lhe : i.getHLocation()) {
if(lhe.getEnd() != null) {
if(lhe.getBegin().before(instant) && lhe.getEnd().after(instant)) {
assignedComponents.add(lhe.getHValue());
}
}
}
}
return assignedComponents;
}
@Override
protected Set<Component> query2(tll.System system, Timestamp instant1, Timestamp instant2) {
// query assigned components for one particular time span T1-T2
Set<Component> assignedComponents = new HashSet<>();
for(Item i : system.getArea().get(0).getStore().getFinalItems()) {
for (LocationHistoryEntry lhe : i.getHLocation()) {
if(lhe.getEnd() != null) {
if(lhe.getBegin().after(instant1) && lhe.getEnd().before(instant2)) {
assignedComponents.add(lhe.getHValue());
}
}
}
}
return assignedComponents;
}
@Override
protected float query3(tll.System system, String machineId) {
// component to check: retrieve the machine - should be parameter
Component machine = system.getArea().get(0).getComponent().stream().filter(c -> machineId.equals(c.getId())).reduce((a, b) -> null).get();
float withNull = 0;
float withItem = 0;
// int i = 0;
for (ItemHistoryEntry ihe : machine.getHHosts()) {
if(ihe.getEnd() == null) continue;
long lapse = ihe.getEnd().getTime() - ihe.getBegin().getTime();
// System.out.println(MessageFormat.format("{0,number,0000} {1} [{2,number,0000}ms]: {3,time,HH:mm:ss.SSS}-{4,time,HH:mm:ss.SSS}",
// i++, ihe.getHValue() != null ? "busy" : "free", lapse, ihe.getBegin(), ihe.getEnd()));
if (ihe.getHValue() != null) {
withItem += lapse;
} else {
withNull += lapse;
}
}
// compute the time spans of both sets.
// relate the time spans
return withItem / (withNull + withItem);
}
}