From 840ddab2e6e3b2e243960b9bea8ff7051963a4c2 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 4 Jul 2019 08:26:31 -0700 Subject: Refactor out solving without soft constraints --- .../importer/DimensionRenamer.java | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'model-integration') 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 solve(int maxIterations) { - Map solution = NamingConstraintSolver.solve(dimensions, constraints, maxIterations); + Map 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 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 solveWithOrWithoutSoftConstraints(int maxIterations) { + Map solution = NamingConstraintSolver.solve(dimensions, constraints, maxIterations); if ( solution == null) { ListMap 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; } -- cgit v1.2.3