aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/CpsMdeOptimiserMain.java
blob: c047f2558225227d06bd03c53a83300753d3ffea (plain) (blame)
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
package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo;

import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage;
import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem;
import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Pair;
import uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run;

@SuppressWarnings("all")
public class CpsMdeOptimiserMain {
  private static final String PROJECT_PATH = ".";
  
  private static final String PROBLEM_PATH = "model/problem.xmi";
  
  private static final String MOPT_PATH = "src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/cps.mopt";
  
  private CpsMdeOptimiserMain() {
    new IllegalStateException("This is a static utility class and should not be instantiated directly.");
  }
  
  public static void main(final String[] args) {
    try {
      Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
      XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl();
      _extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, _xMIResourceFactoryImpl);
      EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE);
      final CpsGenerator generator = new CpsGenerator(1, 4, 1);
      final CyberPhysicalSystem problem = generator.generateCpsProblem();
      Resource _eResource = problem.eResource();
      _eResource.setURI(URI.createFileURI(CpsMdeOptimiserMain.PROBLEM_PATH));
      problem.eResource().save(CollectionLiterals.<Object, Object>emptyMap());
      Pair<String, String> _mappedTo = Pair.<String, String>of("cps.ecore", CpsPackage.eNS_URI);
      CpsMdeOptimiserMain.fixupHenshinModel("model/cps.henshin", "model/cps_fixup.henshin", Collections.<String, String>unmodifiableMap(CollectionLiterals.<String, String>newHashMap(_mappedTo)));
      Run.main(new String[] { "-p", CpsMdeOptimiserMain.PROJECT_PATH, "-m", CpsMdeOptimiserMain.MOPT_PATH });
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  private static void fixupHenshinModel(final String originalPath, final String outputPath, final Map<String, String> remapMap) {
    try {
      FileReader _fileReader = new FileReader(originalPath);
      final BufferedReader reader = new BufferedReader(_fileReader);
      try {
        FileWriter _fileWriter = new FileWriter(outputPath);
        final BufferedWriter writer = new BufferedWriter(_fileWriter);
        try {
          String line = null;
          while (((line = reader.readLine()) != null)) {
            {
              Set<Map.Entry<String, String>> _entrySet = remapMap.entrySet();
              for (final Map.Entry<String, String> entry : _entrySet) {
                line = line.replace(entry.getKey(), entry.getValue());
              }
              writer.write(line);
              writer.write("\n");
            }
          }
        } finally {
          writer.close();
        }
      } finally {
        reader.close();
      }
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
}