diff options
Diffstat (limited to 'Tests/ca.mcgill.ecse.dslreasoner.vampire.test/src/ca/mcgill/ecse/dslreasoner/vampire/icse/YakinduTestAlloy.xtend')
-rw-r--r-- | Tests/ca.mcgill.ecse.dslreasoner.vampire.test/src/ca/mcgill/ecse/dslreasoner/vampire/icse/YakinduTestAlloy.xtend | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.vampire.test/src/ca/mcgill/ecse/dslreasoner/vampire/icse/YakinduTestAlloy.xtend b/Tests/ca.mcgill.ecse.dslreasoner.vampire.test/src/ca/mcgill/ecse/dslreasoner/vampire/icse/YakinduTestAlloy.xtend new file mode 100644 index 00000000..b0af3f64 --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.vampire.test/src/ca/mcgill/ecse/dslreasoner/vampire/icse/YakinduTestAlloy.xtend | |||
@@ -0,0 +1,190 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.vampire.icse | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.vampire.queries.Patterns | ||
4 | import ca.mcgill.ecse.dslreasoner.vampire.yakindumm.YakindummPackage | ||
5 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver | ||
6 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.IntStatisticEntry | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.StringStatisticEntry | ||
13 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
14 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | ||
15 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | ||
17 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
18 | import java.io.PrintWriter | ||
19 | import java.text.SimpleDateFormat | ||
20 | import java.util.Date | ||
21 | import org.eclipse.emf.ecore.resource.Resource | ||
22 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
23 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.impl.ModelResultImpl | ||
24 | |||
25 | class YakinduTestAlloy { | ||
26 | def static void main(String[] args) { | ||
27 | val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
28 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | ||
29 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | ||
30 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | ||
31 | |||
32 | // Workspace setup | ||
33 | val Date date = new Date(System.currentTimeMillis) | ||
34 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
35 | val formattedDate = format.format(date) | ||
36 | |||
37 | val inputs = new FileSystemWorkspace('''initialModels/''', "") | ||
38 | val dataWorkspace = new FileSystemWorkspace('''output/YakinduTest/''', "") | ||
39 | val workspace = new FileSystemWorkspace('''output/YakinduTest/''' + formattedDate + '''/''', "") | ||
40 | workspace.initAndClear | ||
41 | |||
42 | // Logicproblem writing setup | ||
43 | val reg = Resource.Factory.Registry.INSTANCE | ||
44 | val map = reg.extensionToFactoryMap | ||
45 | map.put("logicproblem", new XMIResourceFactoryImpl) | ||
46 | |||
47 | println("Input and output workspaces are created") | ||
48 | |||
49 | val metamodel = GeneralTest.loadMetamodel(YakindummPackage.eINSTANCE) | ||
50 | val partialModel = GeneralTest.loadPartialModel(inputs, "yakindu/Yakindu.xmi") | ||
51 | val queries = GeneralTest.loadQueries(metamodel, Patterns.instance) | ||
52 | // val metamodel = GeneralTest.loadMetamodel(FunctionalarchitecturePackage.eINSTANCE) | ||
53 | // val partialModel = GeneralTest.loadPartialModel(inputs, "FAM/FaModel.xmi") | ||
54 | // val queries = GeneralTest.loadQueries(metamodel, FamPatterns.instance) | ||
55 | // val queries = null | ||
56 | println("DSL loaded") | ||
57 | |||
58 | var SZ_TOP = 100 | ||
59 | var SZ_BOT = 100 | ||
60 | var INC = 20 | ||
61 | var REPS = 25 | ||
62 | |||
63 | val RUNTIME = 300 | ||
64 | |||
65 | var solverTimes = newArrayList | ||
66 | var transformationTimes = newArrayList | ||
67 | var LogicResult solution = null | ||
68 | var solver = "Alloy" | ||
69 | |||
70 | for (var k = 0; k < 1; k++) { | ||
71 | |||
72 | for (var i = SZ_BOT; i <= SZ_TOP; i += INC) { | ||
73 | var writer = new PrintWriter( | ||
74 | dataWorkspace.workspaceURI + "//_alloy" + i + "x" + REPS + "-" + formattedDate + ".csv") | ||
75 | writer.append("solver,size,TransformatonTime,sat?,kodkodTime,model?,modelTime\n") | ||
76 | |||
77 | val num = (i - SZ_BOT) / INC | ||
78 | println() | ||
79 | println("SOLVER: " + solver + ", SIZE=" + i) | ||
80 | println() | ||
81 | |||
82 | solverTimes.clear | ||
83 | transformationTimes.clear | ||
84 | for (var j = 0; j < REPS; j++) { | ||
85 | val Date date2 = new Date(System.currentTimeMillis) | ||
86 | val formattedDate2 = format.format(date2) | ||
87 | println(formattedDate2) | ||
88 | println("<<Run number " + j + ">> :") | ||
89 | |||
90 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, | ||
91 | new Ecore2LogicConfiguration()) | ||
92 | var modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | ||
93 | var validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelExtensionProblem, | ||
94 | new Viatra2LogicConfiguration) | ||
95 | |||
96 | var problem = modelGenerationProblem.output | ||
97 | // workspace.writeModel(problem, "Yakindu.logicproblem") | ||
98 | // println("Problem created") | ||
99 | // Start Time | ||
100 | var startTime = System.currentTimeMillis | ||
101 | |||
102 | var AlloySolver reasoner | ||
103 | // * | ||
104 | reasoner = new AlloySolver | ||
105 | |||
106 | // ///////////////////////////////////////////////////// | ||
107 | // Define Config File | ||
108 | val size = i | ||
109 | val inc = INC | ||
110 | val iter = j | ||
111 | val solverConfig = new AlloySolverConfiguration => [ | ||
112 | // add configuration things, in config file first | ||
113 | it.documentationLevel = DocumentationLevel::FULL | ||
114 | // it.iteration = iter | ||
115 | it.runtimeLimit = RUNTIME | ||
116 | // it.typeScopes.maxNewElements = size | ||
117 | it.typeScopes.minNewElements = size | ||
118 | it.typeScopes.maxNewElements = size | ||
119 | ] | ||
120 | solution = reasoner.solve(problem, solverConfig, workspace) | ||
121 | // print((solution as ModelResult).representation.get(0)) | ||
122 | // val soln = ((solution as ModelResult).representation.get(0) as VampireModel) | ||
123 | // println(soln.confirmations) | ||
124 | // println((solution as ModelResult).representation) | ||
125 | // modelFound = !soln.confirmations.filter [ | ||
126 | // class == VLSFiniteModelImpl | ||
127 | // ].isEmpty | ||
128 | // ADD TO CSV | ||
129 | writer.append(solver + ",") | ||
130 | writer.append(size + ",") | ||
131 | writer.append(solution.statistics.transformationTime / 1000.0 + ",") | ||
132 | |||
133 | // val satOut = (solution.statistics.entries.filter[name == "satOut"].get(0) as StringStatisticEntry). | ||
134 | // value | ||
135 | val kodKodTime = (solution.statistics.entries.filter[name == "Alloy2KodKodTransformationTime"]. | ||
136 | get(0) as IntStatisticEntry).value | ||
137 | // print(solution.class) | ||
138 | val modOut = if(solution.class == ModelResultImpl) "FiniteModel" else "no" | ||
139 | val mod = solution.statistics.entries.filter[name == "Answer0Time"] | ||
140 | var modTime = 0.0 | ||
141 | if (!mod.isEmpty) { | ||
142 | modTime = (mod.get(0) as IntStatisticEntry).value / 1000.0 | ||
143 | |||
144 | } | ||
145 | writer.append("-,") | ||
146 | writer.append(kodKodTime.toString + ",") | ||
147 | writer.append(modOut + ",") | ||
148 | writer.append(modTime.toString + "") | ||
149 | writer.append("\n") | ||
150 | |||
151 | println("->" + modOut + " ... " + modTime) | ||
152 | |||
153 | // Run Garbage Collector | ||
154 | val Runtime r = Runtime.getRuntime(); | ||
155 | r.gc(); | ||
156 | r.gc(); | ||
157 | r.gc(); | ||
158 | Thread.sleep(3000) | ||
159 | |||
160 | // print("(" + tTime + "/" + sTime + "s)..") | ||
161 | // solverTimes.add(sTime) | ||
162 | // transformationTimes.add(tTime) | ||
163 | // } else { | ||
164 | // writer.append("MNF" + ",") | ||
165 | //// print("MNF") | ||
166 | // } | ||
167 | // println("Problem solved") | ||
168 | // visualisation, see | ||
169 | // var interpretations = reasoner.getInterpretations(solution as ModelResult) | ||
170 | // for (interpretation : interpretations) { | ||
171 | // val model = logic2Ecore.transformInterpretation(interpretation, modelGenerationProblem.trace) | ||
172 | // workspace.writeModel(model, "model.xmi") | ||
173 | // } | ||
174 | // var totalTimeMin = (System.currentTimeMillis - startTime) / 60000 | ||
175 | // var totalTimeSec = ((System.currentTimeMillis - startTime) / 1000) % 60 | ||
176 | // println("Problem solved") | ||
177 | // println("Time was: " + totalTimeMin + ":" + totalTimeSec) | ||
178 | } | ||
179 | // println() | ||
180 | // var solverMed = solverTimes.sort.get(REPS / 2) | ||
181 | // var transformationMed = transformationTimes.sort.get(REPS / 2) | ||
182 | // writer.append(solverMed.toString + "," + transformationMed.toString) | ||
183 | writer.close | ||
184 | } | ||
185 | |||
186 | } | ||
187 | |||
188 | } | ||
189 | |||
190 | } | ||