diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-07-04 08:26:31 -0700 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-07-04 08:26:31 -0700 |
commit | 840ddab2e6e3b2e243960b9bea8ff7051963a4c2 (patch) | |
tree | 5f9ecc21b873e3e23023a0a571c01265c88f544a /model-integration | |
parent | b3f2b0a851315f4a6830d286f81443050eb4c4e4 (diff) |
Refactor out solving without soft constraints
Diffstat (limited to 'model-integration')
-rw-r--r-- | model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java index 0f1e0077fa2..bf5d836b809 100644 --- a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java +++ b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java @@ -68,10 +68,10 @@ public class DimensionRenamer { } private Map<String, Integer> solve(int maxIterations) { - Map<String, Integer> solution = NamingConstraintSolver.solve(dimensions, constraints, maxIterations); + Map<String, Integer> solution = solveWithOrWithoutSoftConstraints(maxIterations); if ( solution == null) { IntermediateOperation operation = graph.operations().get("dense_out/MatMul"); - if (operation != null && operation instanceof MatMul) { + if (operation instanceof MatMul) { IntermediateOperation arg0 = operation.inputs().get(0); List<IntermediateOperation> inputs = new ArrayList<>(operation.inputs()); inputs.set(0, new Rename(arg0.modelName(), "Dot_ExpandDims_1", "renamed_0", arg0)); @@ -85,25 +85,24 @@ public class DimensionRenamer { addDimension("renamed_0"); newOperation.addDimensionNameConstraints(this); - solution = NamingConstraintSolver.solve(dimensions, constraints, maxIterations); + solution = solveWithOrWithoutSoftConstraints(maxIterations); } } if ( solution == null) { + throw new IllegalArgumentException("Could not find a dimension naming solution " + + "given constraints\n" + constraintsToString(constraints)); + } + return solution; + } + + private Map<String, Integer> solveWithOrWithoutSoftConstraints(int maxIterations) { + Map<String, Integer> solution = NamingConstraintSolver.solve(dimensions, constraints, maxIterations); + if ( solution == null) { ListMap<Arc, Constraint> hardConstraints = new ListMap<>(); boolean anyRemoved = copyHard(constraints, hardConstraints); if (anyRemoved) solution = NamingConstraintSolver.solve(dimensions, hardConstraints, maxIterations); - if ( solution == null) { - throw new IllegalArgumentException("Could not find a dimension naming solution " + - "given constraints\n" + constraintsToString(hardConstraints)); - } } - - // Todo: handle failure more gracefully: - // If a solution can't be found, look at the operation node in the arc - // with the most remaining constraints, and inject a rename operation. - // Then run this algorithm again. - return solution; } |