diff options
author | 2019-05-21 17:00:01 -0400 | |
---|---|---|
committer | 2019-05-21 17:00:01 -0400 | |
commit | fd3684b5440dacca0c4bf4be15930555a79e2100 (patch) | |
tree | 24120a5c7fdae1532529fa0c4687dc1078cd1cde /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java | |
parent | Interval hull aggregation operator (diff) | |
download | VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.tar.gz VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.tar.zst VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.zip |
VIATRA DSE and COIN-OR CBC implementations of CPS case study
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java new file mode 100644 index 00000000..d36cdccd --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java | |||
@@ -0,0 +1,77 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.cplex; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.cplex.CpsToLpTranslator; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator; | ||
7 | import java.io.BufferedReader; | ||
8 | import java.io.BufferedWriter; | ||
9 | import java.io.FileReader; | ||
10 | import java.io.FileWriter; | ||
11 | import java.util.Map; | ||
12 | import java.util.concurrent.TimeUnit; | ||
13 | import java.util.function.Consumer; | ||
14 | import org.eclipse.emf.ecore.EPackage; | ||
15 | import org.eclipse.emf.ecore.resource.Resource; | ||
16 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
17 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
18 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
19 | |||
20 | @SuppressWarnings("all") | ||
21 | public class CbcCpsMain { | ||
22 | private static final String PROBLEM_FILE = "problem.lp"; | ||
23 | |||
24 | private static final String SOLUTION_FILE = "solution.txt"; | ||
25 | |||
26 | private CbcCpsMain() { | ||
27 | new IllegalStateException("This is a static utility class and should not be instantiated directly."); | ||
28 | } | ||
29 | |||
30 | public static void main(final String[] args) { | ||
31 | try { | ||
32 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
33 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
34 | _extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, _xMIResourceFactoryImpl); | ||
35 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE); | ||
36 | final CpsGenerator generator = new CpsGenerator(1, 4, 1); | ||
37 | final CyberPhysicalSystem problem = generator.generateCpsProblem(); | ||
38 | final CpsToLpTranslator toLp = new CpsToLpTranslator(problem, 10, true); | ||
39 | final CharSequence lp = toLp.getLpProblem(); | ||
40 | FileWriter _fileWriter = new FileWriter(CbcCpsMain.PROBLEM_FILE); | ||
41 | final BufferedWriter writer = new BufferedWriter(_fileWriter); | ||
42 | try { | ||
43 | writer.append(lp); | ||
44 | } finally { | ||
45 | writer.close(); | ||
46 | } | ||
47 | final Process process = new ProcessBuilder().inheritIO().command("cbc", CbcCpsMain.PROBLEM_FILE, "solve", "solu", CbcCpsMain.SOLUTION_FILE).start(); | ||
48 | boolean _waitFor = process.waitFor(120, TimeUnit.SECONDS); | ||
49 | boolean _not = (!_waitFor); | ||
50 | if (_not) { | ||
51 | System.err.println("Timeout reached"); | ||
52 | process.destroyForcibly(); | ||
53 | System.exit((-1)); | ||
54 | } | ||
55 | int _exitValue = process.exitValue(); | ||
56 | boolean _notEquals = (_exitValue != 0); | ||
57 | if (_notEquals) { | ||
58 | int _exitValue_1 = process.exitValue(); | ||
59 | String _plus = ("Unexpected exit value " + Integer.valueOf(_exitValue_1)); | ||
60 | System.err.println(_plus); | ||
61 | System.exit((-1)); | ||
62 | } | ||
63 | FileReader _fileReader = new FileReader(CbcCpsMain.SOLUTION_FILE); | ||
64 | final BufferedReader reader = new BufferedReader(_fileReader); | ||
65 | try { | ||
66 | final Consumer<String> _function = (String it) -> { | ||
67 | InputOutput.<String>println(it); | ||
68 | }; | ||
69 | reader.lines().forEach(_function); | ||
70 | } finally { | ||
71 | reader.close(); | ||
72 | } | ||
73 | } catch (Throwable _e) { | ||
74 | throw Exceptions.sneakyThrow(_e); | ||
75 | } | ||
76 | } | ||
77 | } | ||