Commit 99b2320f authored by René Schöne's avatar René Schöne
Browse files

Tested solution parsed.

parent 319c43f3
......@@ -7,3 +7,7 @@ coverage
/bin/
/build/
/out/
# files created by Main
model-serialized.txt
solution-serialized.txt
......@@ -2,16 +2,14 @@ package de.tudresden.inf.st.mquat;
import beaver.Parser;
import de.tudresden.inf.st.mquat.deserializer.ASTNodeDeserializer;
import de.tudresden.inf.st.mquat.generator.*;
import de.tudresden.inf.st.mquat.generator.ScenarioDescription;
import de.tudresden.inf.st.mquat.generator.ScenarioGenerator;
import de.tudresden.inf.st.mquat.jastadd.model.*;
import de.tudresden.inf.st.mquat.jastadd.parser.MquatParser;
import de.tudresden.inf.st.mquat.jastadd.scanner.MquatScanner;
import de.tudresden.inf.st.mquat.serializer.ASTNodeSerializer;
import de.tudresden.inf.st.mquat.serializer.JsonSerializer;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import java.io.*;
import java.net.URL;
......@@ -19,7 +17,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
......@@ -30,7 +27,7 @@ import java.util.Scanner;
@SuppressWarnings("unused")
public class Main {
public static final ScenarioDescription SCENARIO_DESCRIPTION = new ScenarioDescription(2, 2, 0, 0, 0, 2, 2, 1.5, 2, 2, 0);
private static final ScenarioDescription SCENARIO_DESCRIPTION = new ScenarioDescription(2, 2, 0, 0, 0, 2, 2, 1.5, 2, 2, 0);
private static File getAbsoluteFileForLoading(String fileName) throws FileNotFoundException {
URL expUrl = Main.class.getClassLoader().getResource(fileName);
......@@ -97,7 +94,7 @@ public class Main {
// required for the DrAST debugger
public static Object DrAST_root_node;
public static Optional<Root> loadModel(String fileName) {
private static Optional<Root> loadModel(String fileName) {
try {
Root root = load(fileName);
// required for the DrAST debugger
......@@ -110,6 +107,21 @@ public class Main {
return Optional.empty();
}
private static Optional<Solution> loadSolution(String fileName, Root model) {
try {
File file = getAbsoluteFileForLoading(fileName);
FileReader reader = new FileReader(file);
MquatScanner scanner = new MquatScanner(reader);
MquatParser parser = new MquatParser();
Solution result = (Solution) parser.parse(scanner, MquatParser.AltGoals.solution);
parser.resolveSolutionReferencesWith(model);
return Optional.of(result);
} catch (IOException | Parser.Exception e) {
e.printStackTrace();
}
return Optional.empty();
}
private static void checkParsedModel(Root parsedModel, File originalFile, MquatWriteSettings settings)
throws IOException, InterruptedException {
if (parsedModel == null) {
......@@ -140,14 +152,27 @@ public class Main {
return generatedModel;
}
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
Logger logger = LogManager.getLogger(Main.class);
logger.info("Starting base.Main");
String fileName = args.length > 0 ? args[0] : "model-handmade.txt";
String modelFileName = args.length > 0 ? args[0] : "model-handmade.txt";
String solutionFileName = args.length > 0 ? args[0] : "solution-handmade.txt";
// Configurator.setRootLevel(Level.TRACE);
Optional<Root> parsedModel = loadModel(fileName);
parsedModel.ifPresent(model -> JsonSerializer.write(model, "model-serialized.txt"));
Optional<Root> parsedModel = loadModel(modelFileName);
Root model;
if (parsedModel.isPresent()) {
model = parsedModel.get();
} else {
logger.error("Model was not parsed correctly!");
return;
}
JsonSerializer.write(model, "model-serialized.txt");
Optional<Solution> parsedSolution = loadSolution(solutionFileName, model);
if (parsedSolution.isPresent()) {
Solution solution = parsedSolution.get();
JsonSerializer.write(solution, "solution-serialized.txt");
}
// Root model = generateNewModel(new MquatWriteSettings(" "), false);
// JsonSerializer.write(model, "model-serialized.txt");
......
......@@ -3,10 +3,7 @@ package de.tudresden.inf.st.mquat.serializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import de.tudresden.inf.st.mquat.jastadd.model.ASTNode;
import de.tudresden.inf.st.mquat.jastadd.model.List;
import de.tudresden.inf.st.mquat.jastadd.model.Opt;
import de.tudresden.inf.st.mquat.jastadd.model.Root;
import de.tudresden.inf.st.mquat.jastadd.model.*;
import java.io.File;
import java.io.IOException;
......@@ -14,6 +11,14 @@ import java.io.IOException;
public class JsonSerializer {
public static void write(Root r, String fileName) {
writeAstNode(r, fileName);
}
public static void write(Solution s, String fileName) {
writeAstNode(s, fileName);
}
private static void writeAstNode(ASTNode a, String fileName) {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
......@@ -25,10 +30,9 @@ public class JsonSerializer {
mapper.registerModule(module);
try {
mapper.writeValue(new File(fileName), r);
mapper.writeValue(new File(fileName), a);
} catch (IOException e) {
e.printStackTrace();
}
}
}
solution {
request0 -> implementation_0i1 {
compute_resource_0 -> resource0 {
cpu_0 -> cpu0_0
ram_1 -> ram0
disk_1 -> disk0
network_1 -> network0
}
the_component_0c0 -> implementation_0c0i0 {
compute_resource_0 -> resource1 {
cpu_0 -> cpu1_0
ram_1 -> ram1
disk_1 -> disk1
network_1 -> network1
}
}
the_component_0c1 -> implementation_0c1i0 {
compute_resource_0 -> resource2 {
cpu_0 -> cpu2_0
ram_1 -> ram2
disk_1 -> disk2
network_1 -> network2
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment