|
13 | 13 | import java.beans.PropertyVetoException;
|
14 | 14 | import java.beans.VetoableChangeListener;
|
15 | 15 | import java.util.Arrays;
|
| 16 | +import java.util.LinkedHashMap; |
16 | 17 | import java.util.List;
|
17 | 18 | import java.util.Map;
|
18 | 19 |
|
|
34 | 35 | import cbit.vcell.geometry.Geometry;
|
35 | 36 | import cbit.vcell.geometry.GeometryOwner;
|
36 | 37 | import cbit.vcell.geometry.GeometrySpec;
|
| 38 | +import cbit.vcell.math.Constant; |
37 | 39 | import cbit.vcell.math.MathDescription;
|
38 | 40 | import cbit.vcell.model.VCMODL;
|
| 41 | +import cbit.vcell.parser.Expression; |
| 42 | +import cbit.vcell.parser.ExpressionException; |
| 43 | +import cbit.vcell.solver.MathOverrides; |
39 | 44 | import cbit.vcell.solver.OutputFunctionContext;
|
40 | 45 | import cbit.vcell.solver.Simulation;
|
41 | 46 | import cbit.vcell.solver.SimulationOwner;
|
@@ -229,8 +234,70 @@ public boolean contains(Simulation simulation) {
|
229 | 234 | return bFound;
|
230 | 235 | }
|
231 | 236 |
|
| 237 | +private final int MaxBatchSize = 199; |
| 238 | +public static final String ReservedBatchExtensionString = "_bat_"; |
232 | 239 | public Simulation createBatchSimulations(Simulation simulation, Map<Integer, Map<String, String>> batchInputDataMap) throws java.beans.PropertyVetoException {
|
233 |
| - throw new RuntimeException("This feature is not supported for MathModels."); |
| 240 | +// throw new RuntimeException("This feature is not supported for MathModels."); |
| 241 | + if(getMathDescription() == null) { |
| 242 | + throw new RuntimeException("Application " + getName() + " has no generated Math, cannot add simulation"); |
| 243 | + } |
| 244 | + if(simulation.getMathDescription() != getMathDescription()){ |
| 245 | + throw new IllegalArgumentException("cannot copy simulation '" + simulation.getName() + "', has different MathDescription than Application"); |
| 246 | + } |
| 247 | + |
| 248 | +// mathModel == this |
| 249 | + int batchSize = batchInputDataMap.size(); |
| 250 | + if(batchSize >= MaxBatchSize) { |
| 251 | + throw new RuntimeException("Batch size must be smaller than " + MaxBatchSize); |
| 252 | + } |
| 253 | + Simulation allSims[] = getSimulations(); |
| 254 | + for (int k = 0; k < batchSize; k++) { |
| 255 | + if(batchInputDataMap.get(k) == null) { |
| 256 | + // entry missing, perhaps parsing error |
| 257 | + System.out.println("List of overrides missing for batch simulation " + k + ". Check input data file."); |
| 258 | + } |
| 259 | + } |
| 260 | + |
| 261 | + // now we go through all those we have |
| 262 | + LinkedHashMap<Integer, Map<String, String>> batchInputLinkedMap = (LinkedHashMap<Integer, Map<String, String>>)batchInputDataMap; |
| 263 | + for(Integer i : batchInputLinkedMap.keySet()) { |
| 264 | + LinkedHashMap<String, String> overrideMap = (LinkedHashMap<String, String>)batchInputLinkedMap.get(i); |
| 265 | + |
| 266 | + String insert = ""; |
| 267 | + if(i<10) { |
| 268 | + insert = "00"; |
| 269 | + } else if(i<100) { |
| 270 | + insert = "0"; |
| 271 | + } |
| 272 | + String proposedName = simulation.getName() + ReservedBatchExtensionString + insert + i; |
| 273 | + boolean bFound = false; |
| 274 | + for (int j = 0; !bFound && j < allSims.length; j++) { |
| 275 | + // go through all existing simulations to make sure the name we want to use is not already taken |
| 276 | + if (allSims[j].getName().equals(proposedName)) { |
| 277 | + bFound = true; |
| 278 | + throw new RuntimeException("Batch file name already in use: " + proposedName); |
| 279 | + } |
| 280 | + } |
| 281 | + Simulation newSimulation = new Simulation(simulation); |
| 282 | + newSimulation.setName(proposedName); |
| 283 | + |
| 284 | + MathOverrides mo = new MathOverrides(newSimulation); |
| 285 | + for(String name : overrideMap.keySet()) { |
| 286 | + String value = overrideMap.get(name); |
| 287 | + try { |
| 288 | + Expression expression = new Expression(value); |
| 289 | + Constant constant = new Constant(name, expression); |
| 290 | + mo.putConstant(constant); |
| 291 | + } catch (ExpressionException e) { |
| 292 | + e.printStackTrace(); |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + newSimulation.setMathOverrides(mo); |
| 297 | + addSimulation(newSimulation); |
| 298 | + } |
| 299 | + return null; |
| 300 | + |
234 | 301 | }
|
235 | 302 | public void importBatchSimulations(Simulation simulation) throws java.beans.PropertyVetoException {
|
236 | 303 | throw new RuntimeException("This feature is not supported for MathModels.");
|
|
0 commit comments