From ecc0e58fa6c33d8126ca9eca1bd7d2f0821489c6 Mon Sep 17 00:00:00 2001 From: rschoene <rene.schoene@tu-dresden.de> Date: Mon, 29 Oct 2018 14:57:23 +0100 Subject: [PATCH] Describe, how to check a solution. --- README.md | 18 ++++++++++++++++++ .../src/main/jastadd/solution/Checking.jadd | 2 +- .../de/tudresden/inf/st/mquat/MainCheck.java | 5 +++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fa93c74..624216e 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,24 @@ To test your solver with the name `fancy-solver` along with the reference implem The value `total` is used to constrain the total number of models to be generated. Set this to `null` (the default) to generate all value for the defined parameter ranges. Refer to [`de.tudresden.inf.st.mquat.generator.ScenarioDescription`](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-base/src/main/java/de/tudresden/inf/st/mquat/generator/ScenarioDescription.java) for a description of the possible parameters. +## Checking a solution using Java methods + +The check, if a `Solution` object is valid, either call [`solution.valid()`](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-base/src/main/jastadd/solution/Checking.jrag#L3) returning a boolean, if the solution is valid, or call [`solution.explain`](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-base/src/main/jastadd/solution/Checking.jadd#L2) to print out if the solution is valid and violations, if there are any. +You may also look into the [code used for external tools](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-base/src/main/java/de/tudresden/inf/st/mquat/MainCheck.java) to see a minimal working example. + +### Checking a solution for external tools + +If you can not use Java method, we provided a Gradle task `checkSolution` expecting two paths to files: the problem description and the solution. +Alternatively, you can use the wrapper shell-script `checkSolution.sh` with the same parameters (problem description and its solution). + +In both cases, the output will be the following: + +- The read solution pretty-printed (to verify correct parsing) +- Whether the solution is valid, and the violations in the solution, if any. +- The objective value of the solution. + +Thus, the check will only check for validity and not for optimality as this would require solving the problem again. + ## Notes and Troubleshooting - Please use the gradle wrapper script, as different version of Gradle might not work with the setup diff --git a/jastadd-mquat-base/src/main/jastadd/solution/Checking.jadd b/jastadd-mquat-base/src/main/jastadd/solution/Checking.jadd index 64e64e0..fef41f9 100644 --- a/jastadd-mquat-base/src/main/jastadd/solution/Checking.jadd +++ b/jastadd-mquat-base/src/main/jastadd/solution/Checking.jadd @@ -2,7 +2,7 @@ aspect Checking { public void Solution.explain() { Set<Request> requestSet = new HashSet<>(); Map<Resource, Assignment> resourceSet = new HashMap<>(); - logger.info(this.toString()); + // logger.info(this.toString()); // check assignments for (Assignment assignment : allAssignments()) { if (!assignment.isValid()) { diff --git a/jastadd-mquat-base/src/main/java/de/tudresden/inf/st/mquat/MainCheck.java b/jastadd-mquat-base/src/main/java/de/tudresden/inf/st/mquat/MainCheck.java index c3054f7..e3ced6b 100644 --- a/jastadd-mquat-base/src/main/java/de/tudresden/inf/st/mquat/MainCheck.java +++ b/jastadd-mquat-base/src/main/java/de/tudresden/inf/st/mquat/MainCheck.java @@ -4,6 +4,7 @@ import beaver.Parser; import de.tudresden.inf.st.mquat.jastadd.model.*; import de.tudresden.inf.st.mquat.jastadd.scanner.MquatScanner; import de.tudresden.inf.st.mquat.utils.ParserUtils; +import org.apache.logging.log4j.LogManager; import java.io.BufferedReader; import java.io.IOException; @@ -38,8 +39,8 @@ public class MainCheck { System.out.println(out); boolean isValid = solution.isValid(); double objectiveValue = solution.computeObjective(); - System.out.println("Solution valid: " + Boolean.toString(isValid)); - System.out.println("Objective value: " + objectiveValue); + solution.explain(); + LogManager.getLogger(MainCheck.class).info("Objective value: " + objectiveValue); } private static void printUsage() { -- GitLab