diff --git a/README.md b/README.md index fa93c74f4601fea03fe0568f60de357c2e504291..624216e7ce29353e524030130654512db2af7d39 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 64e64e03d7c066fdd91c4ab9ea3cc21d6c78410b..fef41f95322b3e48ca027c3c003687c95bcc78be 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 c3054f7c66258a4f2b660a1c4e8496e9df2d69ea..e3ced6bd22569d755026563dbcea32bb8f215519 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() {