Skip to content

Commit

Permalink
Merge f4d4ff4 into 7684e2b
Browse files Browse the repository at this point in the history
  • Loading branch information
TiloW committed May 5, 2015
2 parents 7684e2b + f4d4ff4 commit 2fc0d1b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/java/proof/exception/InvalidProofException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Tilo Wiedera
*
*/
public abstract class InvalidProofException extends Exception {
public class InvalidProofException extends Exception {

public InvalidProofException(String description) {
super(description);
Expand Down
46 changes: 27 additions & 19 deletions src/main/java/proof/validator/MainValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,43 @@ protected void onProgress(double progress) {}
public void validate(JSONObject object) throws InvalidProofException {
Graph graph = graphReader.read(object.getJSONObject("graph"));

BranchCoverageValidator coverageValidator = new BranchCoverageValidator(graph);
if (object.getJSONObject("solution").getBoolean("trivial")) {
if (graph.getClaimedLowerBound() > 1) {
throw new InvalidProofException("The claimed lower bound of "
+ graph.getClaimedLowerBound() + " is non-trivial.");
}
} else {

JSONArray leaves = object.getJSONObject("solution").getJSONArray("leaves");
BranchCoverageValidator coverageValidator = new BranchCoverageValidator(graph);

coverageValidator.validate(leaves);
JSONArray leaves = object.getJSONObject("solution").getJSONArray("leaves");

for (int i = 0; i < leaves.length(); i++) {
JSONObject leaf = leaves.getJSONObject(i);
JSONArray variables = leaf.getJSONArray("fixedVariables");
coverageValidator.validate(leaves);

CrossingReader crossingReader = new CrossingReader(graph);
Map<CrossingIndex, Boolean> vars = new HashMap<CrossingIndex, Boolean>();
for (int i = 0; i < leaves.length(); i++) {
JSONObject leaf = leaves.getJSONObject(i);
JSONArray variables = leaf.getJSONArray("fixedVariables");

for (int j = 0; j < variables.length(); j++) {
JSONObject variable = variables.getJSONObject(j);
CrossingReader crossingReader = new CrossingReader(graph);
Map<CrossingIndex, Boolean> vars = new HashMap<CrossingIndex, Boolean>();

CrossingIndex cross = crossingReader.read(variable.getJSONArray("crossing"));
for (int j = 0; j < variables.length(); j++) {
JSONObject variable = variables.getJSONObject(j);

vars.put(cross, variable.getInt("value") == 1);
}
CrossingIndex cross = crossingReader.read(variable.getJSONArray("crossing"));

ConstraintValidator constraintValidator = new ConstraintValidator(graph, vars);
JSONArray constraints = leaf.getJSONArray("constraints");
vars.put(cross, variable.getInt("value") == 1);
}

for (int j = 0; j < constraints.length(); j++) {
constraintValidator.validate(constraints.getJSONObject(j));
}
ConstraintValidator constraintValidator = new ConstraintValidator(graph, vars);
JSONArray constraints = leaf.getJSONArray("constraints");

onProgress((i + 1) / (double) leaves.length());
for (int j = 0; j < constraints.length(); j++) {
constraintValidator.validate(constraints.getJSONObject(j));
}

onProgress((i + 1) / (double) leaves.length());
}
}
}
}
73 changes: 73 additions & 0 deletions src/test/resources/log/job10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"graph": {
"claimedLowerBound": 1,
"edges": [
{
"cost": 1,
"id": 0,
"source": 0,
"target": 1
},
{
"cost": 1,
"id": 1,
"source": 1,
"target": 2
},
{
"cost": 1,
"id": 2,
"source": 0,
"target": 2
},
{
"cost": 1,
"id": 3,
"source": 2,
"target": 3
},
{
"cost": 1,
"id": 4,
"source": 1,
"target": 3
},
{
"cost": 1,
"id": 5,
"source": 0,
"target": 3
},
{
"cost": 1,
"id": 6,
"source": 3,
"target": 4
},
{
"cost": 1,
"id": 7,
"source": 2,
"target": 4
},
{
"cost": 1,
"id": 8,
"source": 1,
"target": 4
},
{
"cost": 1,
"id": 9,
"source": 0,
"target": 4
}
],
"numberOfNodes": 5
},
"solution": {
"leaves": [
],
"trivial": true
}
}

0 comments on commit 2fc0d1b

Please sign in to comment.