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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
package run
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigSpecification
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileSpecification
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.IntervallNumber
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ModelEntry
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ObjectTypeScope
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.RuntimeEntry
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeSpecification
import hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor
import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor
import hu.bme.mit.inf.dslreasoner.application.execution.StandardOutputBasedScriptConsole
import java.io.File
import java.io.PrintWriter
import java.text.SimpleDateFormat
import java.util.Date
import org.apache.commons.cli.BasicParser
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.CommandLineParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Option
import org.apache.commons.cli.Options
import org.apache.commons.cli.ParseException
import org.eclipse.core.runtime.NullProgressMonitor
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigEntry
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.impl.ConfigEntryImpl
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.CustomEntry
class RunGeneratorConfig {
static var SIZE_LB = 20
static var SIZE_UB = -1
static var HOUSEHOLD = 0
static var RUNS = 10
static var MODELS = 10
static var RUNTIME = 1500
static var NUM_SOLVER = "z3"
static var DREAL_PATH = ""
// static var SCOPE_PROPAGATOR = "typeHierarchy"
static var DOMAIN = "FamilyTree" // "FamilyTree", "Satellite", "Taxation"
static val QUERIES = true
static val INITIAL = true
def static void main(String[] args) {
// MyChangeFactory.install()
// Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl)
// val workspace = new FileSystemWorkspace('''x/''', "")
// workspace.initAndClear
val options = new Options()
val lb = new Option("lb", "lowerBound", true, "generated model Lower bound")
options.addOption(lb)
val ub = new Option("ub", "upperBound", true, "generated model Upper bound")
options.addOption(ub)
val nr = new Option("nr", "numRuns", true, "number of runs")
options.addOption(nr)
val nm = new Option("nm", "numModels", true, "number of models")
options.addOption(nm)
val rt = new Option("rt", "runtime", true, "runtime limit")
options.addOption(rt)
val ns = new Option("ns", "numericSolver", true, "what numeric solver to use")
options.addOption(ns)
val drp = new Option("drp", "drealPath", true, "path to dreal executeable")
options.addOption(drp)
// val sp = new Option("sp", "scopePropagator", true, "scope Propagator")
// options.addOption(sp)
//
val d = new Option("d", "domain", true, "domain")
options.addOption(d)
val hh = new Option("hh", "household", true, "number of households")
options.addOption(hh)
val CommandLineParser parser = new BasicParser
val formatter = new HelpFormatter()
var CommandLine cmd
try {
cmd = parser.parse(options, args)
} catch (ParseException e) {
System.out.println(e.getMessage())
formatter.printHelp("utility-name", options)
System.exit(1)
}
val lbIn = cmd.getOptionValue("lowerBound")
if(lbIn !== null) SIZE_LB = Integer.parseInt(lbIn)
val ubIn = cmd.getOptionValue("upperBound")
if(ubIn !== null) SIZE_UB = Integer.parseInt(ubIn)
val nrIn = cmd.getOptionValue("numRuns")
if(nrIn !== null) RUNS = Integer.parseInt(nrIn)
val nmIn = cmd.getOptionValue("numModels")
if(nmIn !== null) MODELS = Integer.parseInt(nmIn)
val rtIn = cmd.getOptionValue("runtime")
if(rtIn !== null) RUNTIME = Integer.parseInt(rtIn)
val nsIn = cmd.getOptionValue("numericSolver")
if(nsIn !== null && nsIn.equals("dreal")) NUM_SOLVER = "dreal-local"
val drpIn = cmd.getOptionValue("drealPath")
if(drpIn !== null) DREAL_PATH = drpIn
// val spIn = cmd.getOptionValue("scopePropagator")
// if(spIn !== null ) SCOPE_PROPAGATOR = spIn
val dIn = cmd.getOptionValue("domain")
if(dIn !== null) DOMAIN = dIn
val hhIn = cmd.getOptionValue("household")
if(hhIn !== null) HOUSEHOLD = Integer.parseInt(hhIn)
val isTaxation = DOMAIN == "Taxation"
// Workspace setup
val Date date = new Date(System.currentTimeMillis)
val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm")
val formattedDate = format.format(date)
val executor = new ScriptExecutor(StandardOutputBasedScriptConsole.FACTORY)
val path = "config//generic" + DOMAIN + ".vsconfig"
var ConfigurationScript config = StandaloneScriptExecutor.loadScript(path)
// /////////////////////////
// BEGIN RUN
println(
"<<DOMAIN: " + DOMAIN +
", NumSolver=" + NUM_SOLVER +
// ", scopeProp=" + SCOPE_PROPAGATOR +
", SIZE=" + SIZE_LB + "to" + SIZE_UB +
", Runs=" + RUNS +
", ModelsPerRun=" + MODELS +
", Runtime=" + RUNTIME + ">>")
if (isTaxation) println("<<Households: " + HOUSEHOLD + ">>")
var naming = DOMAIN + "/size" + toStr(SIZE_LB) + "to" + toStr(SIZE_UB) +
"r" + RUNS +
"n" + MODELS +
"rt" + RUNTIME +
"ns" + NUM_SOLVER
if (isTaxation) naming = naming + "hh" + HOUSEHOLD
val outputPath = "measurements/" + "models/" + naming + "_" + formattedDate
val debugPath = "measurements/" + "debug/" + naming + "_" + formattedDate
val logPath = debugPath + "/log.txt"
val statsPath = "measurements/" + "stats/" + naming + "stats_" + formattedDate + ".csv"
// Basic Adjustments
val genTask = config.commands.get(1) as GenerationTask
if(!QUERIES) genTask.patterns = null
if(!INITIAL) genTask.partialModel = null
genTask.runs = RUNS
genTask.number = MODELS
// Size
val scopeSpec = genTask.scope as ScopeSpecification
val objScope = scopeSpec.scopes.get(0) as ObjectTypeScope
val interval = objScope.number as IntervallNumber
interval.min = SIZE_LB
if (SIZE_UB == -1)
interval.maxUnlimited = true
else {
interval.maxUnlimited = false
interval.maxNumber = SIZE_UB
}
if (isTaxation) {
if (HOUSEHOLD > 0) {
val pms = genTask.partialModel as PartialModelSpecification
val me = pms.entry.get(0) as ModelEntry
val fs = me.path as FileSpecification
val modelPath = "inputs/Resource" + HOUSEHOLD + "hh.xmi"
val modelFile = new File(modelPath)
if (!modelFile.exists) {
val writer = new PrintWriter(modelFile)
try {
writer.println('''
<?xml version="1.0" encoding="UTF-8"?>
<TaxCardWithRoot:Resource
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:TaxCardWithRoot="http:///TaxCardWithRoot.ecore"
xsi:schemaLocation="http:///TaxCardWithRoot.ecore ../../case.study.pledge.model/model/TaxationWithRoot.ecore">
«FOR i : 0 ..< HOUSEHOLD»
<contains/>
«ENDFOR»
</TaxCardWithRoot:Resource>
''')
} finally {
writer.close
}
}
fs.path = modelPath
println("<<Using " + fs.path + " as initial model>>")
} else {
scopeSpec.scopes.remove(1)
}
}
// workspace.writeModel(config, '''x.xmi''')
// Config
val configScope = genTask.config as ConfigSpecification
val runtimeEntry = configScope.entries.get(0) as RuntimeEntry
runtimeEntry.millisecLimit = RUNTIME
val numSolverEntry = configScope.entries.get(1) as CustomEntry
numSolverEntry.value = NUM_SOLVER
val drealPathEntry = configScope.entries.get(2) as CustomEntry
drealPathEntry.value = DREAL_PATH
// val scopePropEntry = configScope.entries.get(3) as CustomEntry
// scopePropEntry.value = SCOPE_PROPAGATOR
// Output locations
val debug = genTask.debugFolder as FileSpecification
debug.path = debugPath
val output = genTask.tagetFolder as FileSpecification
output.path = outputPath
val log = genTask.targetLogFile as FileSpecification
log.path = logPath
val stats = genTask.targetStatisticsFile as FileSpecification
stats.path = statsPath
// Run Generator
println()
executor.executeScript(config, new NullProgressMonitor)
println()
}
static def String toStr(int i) {
var toAdd = ""
if(i < 100 && i != -1) toAdd = "0"
return toAdd + i
}
}
|