summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-07-03 07:33:04 -0700
committerJon Bratseth <bratseth@verizonmedia.com>2019-07-03 07:33:04 -0700
commitfdc6a48fe913de5f5a84c6eb42123543c1d2ee46 (patch)
treec4446b704201d8bae1a7bc916daa840d32dabbe7
parentc7083bfed93168d74091dcf09844cdd27d95a279 (diff)
refactor
-rw-r--r--model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java28
1 files changed, 17 insertions, 11 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 fc54dcac39a..0579af13154 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
@@ -92,17 +92,8 @@ public class DimensionRenamer {
if ( ! solved) {
renames.clear();
ListMap<Arc, Constraint> hardConstraints = new ListMap<>();
- boolean relaxed = false;
- for (var entry : constraints.entrySet()) {
- Arc arc = entry.getKey();
- for (Constraint constraint : entry.getValue()) {
- if ( ! constraint.isSoft())
- hardConstraints.put(arc, constraint);
- else
- relaxed = true;
- }
- }
- if (relaxed)
+ boolean anyRemoved = copyHard(constraints, hardConstraints);
+ if (anyRemoved)
solved = trySolve(variables, hardConstraints, maxIterations, renames);
if ( ! solved) {
throw new IllegalArgumentException("Could not find a dimension naming solution " +
@@ -118,6 +109,21 @@ public class DimensionRenamer {
return renames;
}
+ /** Removes soft constraints and returns whether something was removed */
+ private boolean copyHard(ListMap<Arc, Constraint> source, ListMap<Arc, Constraint> target) {
+ boolean removed = false;
+ for (var entry : source.entrySet()) {
+ Arc arc = entry.getKey();
+ for (Constraint constraint : entry.getValue()) {
+ if ( ! constraint.isSoft())
+ target.put(arc, constraint);
+ else
+ removed = true;
+ }
+ }
+ return removed;
+ }
+
/** Try the solve the constraint problem given in the arguments, and put the result in renames */
private static boolean trySolve(ListMap<String, Integer> inputVariables,
ListMap<Arc, Constraint> constraints,