diff options
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 | 109 |
1 files changed, 0 insertions, 109 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 deleted file mode 100644 index a6ff0d0e..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.java +++ /dev/null | |||
@@ -1,109 +0,0 @@ | |||
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.Request; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.cplex.CpsToLpTranslator; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator; | ||
9 | import java.io.BufferedReader; | ||
10 | import java.io.BufferedWriter; | ||
11 | import java.io.FileReader; | ||
12 | import java.io.FileWriter; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | import java.util.concurrent.TimeUnit; | ||
16 | import java.util.regex.Matcher; | ||
17 | import java.util.regex.Pattern; | ||
18 | import org.eclipse.emf.ecore.EPackage; | ||
19 | import org.eclipse.emf.ecore.resource.Resource; | ||
20 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
21 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
22 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
23 | import org.eclipse.xtext.xbase.lib.Functions.Function2; | ||
24 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
25 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
26 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
27 | |||
28 | @SuppressWarnings("all") | ||
29 | public class CbcCpsMain { | ||
30 | private static final String PROBLEM_FILE = "problem.lp"; | ||
31 | |||
32 | private static final String SOLUTION_FILE = "solution.txt"; | ||
33 | |||
34 | private static final Pattern VALUE_REGEX = Pattern.compile("Optimal - objective value\\s*([0-9]+(\\.[0-9]+)?)"); | ||
35 | |||
36 | private CbcCpsMain() { | ||
37 | new IllegalStateException("This is a static utility class and should not be instantiated directly."); | ||
38 | } | ||
39 | |||
40 | public static void main(final String[] args) { | ||
41 | try { | ||
42 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
43 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
44 | _extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, _xMIResourceFactoryImpl); | ||
45 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE); | ||
46 | final CpsGenerator generator = new CpsGenerator(1, 4, 1); | ||
47 | final CyberPhysicalSystem problem = generator.generateCpsProblem(); | ||
48 | final CpsToLpTranslator toLp = new CpsToLpTranslator(problem, 10, true); | ||
49 | final CharSequence lp = toLp.getLpProblem(); | ||
50 | FileWriter _fileWriter = new FileWriter(CbcCpsMain.PROBLEM_FILE); | ||
51 | final BufferedWriter writer = new BufferedWriter(_fileWriter); | ||
52 | try { | ||
53 | writer.append(lp); | ||
54 | } finally { | ||
55 | writer.close(); | ||
56 | } | ||
57 | final Process process = new ProcessBuilder().inheritIO().command("cbc", CbcCpsMain.PROBLEM_FILE, "solve", "solu", CbcCpsMain.SOLUTION_FILE).start(); | ||
58 | boolean _waitFor = process.waitFor(120, TimeUnit.SECONDS); | ||
59 | boolean _not = (!_waitFor); | ||
60 | if (_not) { | ||
61 | System.err.println("Timeout reached"); | ||
62 | process.destroyForcibly(); | ||
63 | System.exit((-1)); | ||
64 | } | ||
65 | int _exitValue = process.exitValue(); | ||
66 | boolean _notEquals = (_exitValue != 0); | ||
67 | if (_notEquals) { | ||
68 | int _exitValue_1 = process.exitValue(); | ||
69 | String _plus = ("Unexpected exit value " + Integer.valueOf(_exitValue_1)); | ||
70 | System.err.println(_plus); | ||
71 | System.exit((-1)); | ||
72 | } | ||
73 | FileReader _fileReader = new FileReader(CbcCpsMain.SOLUTION_FILE); | ||
74 | final BufferedReader reader = new BufferedReader(_fileReader); | ||
75 | double value = Double.NaN; | ||
76 | try { | ||
77 | String line = null; | ||
78 | while (((line = reader.readLine()) != null)) { | ||
79 | { | ||
80 | InputOutput.<String>println(line); | ||
81 | final Matcher matcher = CbcCpsMain.VALUE_REGEX.matcher(line); | ||
82 | boolean _matches = matcher.matches(); | ||
83 | if (_matches) { | ||
84 | value = Double.parseDouble(matcher.group(1)); | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | } finally { | ||
89 | reader.close(); | ||
90 | } | ||
91 | final Function1<Request, List<Integer>> _function = (Request it) -> { | ||
92 | final Function1<Requirement, Integer> _function_1 = (Requirement it_1) -> { | ||
93 | return Integer.valueOf(it_1.getCount()); | ||
94 | }; | ||
95 | return ListExtensions.<Requirement, Integer>map(it.getRequirements(), _function_1); | ||
96 | }; | ||
97 | final Function2<Integer, Integer, Integer> _function_1 = (Integer p1, Integer p2) -> { | ||
98 | return Integer.valueOf(((p1).intValue() + (p2).intValue())); | ||
99 | }; | ||
100 | Integer _reduce = IterableExtensions.<Integer>reduce(IterableExtensions.<Request, Integer>flatMap(problem.getRequests(), _function), _function_1); | ||
101 | final int applicationCost = ((_reduce).intValue() * 5); | ||
102 | final double cost = (applicationCost + value); | ||
103 | InputOutput.println(); | ||
104 | InputOutput.<String>println(("Cost: " + Double.valueOf(cost))); | ||
105 | } catch (Throwable _e) { | ||
106 | throw Exceptions.sneakyThrow(_e); | ||
107 | } | ||
108 | } | ||
109 | } | ||