summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-07-04 08:21:01 -0700
committerJon Bratseth <bratseth@verizonmedia.com>2019-07-04 08:21:01 -0700
commitb3f2b0a851315f4a6830d286f81443050eb4c4e4 (patch)
tree62d0715319f52af51096d4876f9c9d96e6126498
parent97f7d89a3b769d6e23fb367d6c96b5cfa8bae700 (diff)
Cleanup comments
-rw-r--r--model-integration/src/main/java/ai/vespa/rankingexpression/importer/DimensionRenamer.java39
-rw-r--r--model-integration/src/main/java/ai/vespa/rankingexpression/importer/NamingConstraintSolver.java19
2 files changed, 29 insertions, 29 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 5bbcd3a7265..0f1e0077fa2 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
@@ -61,31 +61,12 @@ public class DimensionRenamer {
constraints.put(arc.opposite(), constraint.opposite()); // make constraint graph symmetric
}
- /**
- * Retrieve resulting name of a dimension after solving for constraints, or empty if no
- * solution is found yet, or this dimension was not added before finding a solution.
- */
- public Optional<String> dimensionNameOf(String name) {
- if ( renames == null || ! renames.containsKey(name))
- return Optional.empty();
- return Optional.of(String.format("%s%d", dimensionPrefix, renames.get(name)));
+ void solve() {
+ log.log(Level.FINE, () -> "Rename problem:\n" + constraintsToString(constraints));
+ renames = solve(100000);
+ log.log(Level.FINE, () -> "Rename solution:\n" + renamesToString(renames));
}
- /**
- * Perform iterative arc consistency until we have found a solution. After
- * an initial iteration, the variables (dimensions) will have multiple
- * valid values. Find a single valid assignment by iteratively locking one
- * dimension after another, and running the arc consistency algorithm
- * multiple times.
- *
- * This requires having constraints that result in an absolute ordering:
- * equal, lessThan and greaterThan do that, but adding notEqual does
- * not typically result in a guaranteed ordering. If that is needed, the
- * algorithm below needs to be adapted with a backtracking (tree) search
- * to find solutions.
- *
- * @return the solution in the form of the renames to perform
- */
private Map<String, Integer> solve(int maxIterations) {
Map<String, Integer> solution = NamingConstraintSolver.solve(dimensions, constraints, maxIterations);
if ( solution == null) {
@@ -141,10 +122,14 @@ public class DimensionRenamer {
return removed;
}
- void solve() {
- log.log(Level.FINE, () -> "Rename problem:\n" + constraintsToString(constraints));
- renames = solve(100000);
- log.log(Level.FINE, () -> "Rename solution:\n" + renamesToString(renames));
+ /**
+ * Retrieve resulting name of a dimension after solving for constraints, or empty if no
+ * solution is found yet, or this dimension was not added before finding a solution.
+ */
+ public Optional<String> dimensionNameOf(String name) {
+ if ( renames == null || ! renames.containsKey(name))
+ return Optional.empty();
+ return Optional.of(String.format("%s%d", dimensionPrefix, renames.get(name)));
}
private static String renamesToString(Map<String, Integer> renames) {
diff --git a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/NamingConstraintSolver.java b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/NamingConstraintSolver.java
index 3b1b9ce1715..21cc6b27dad 100644
--- a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/NamingConstraintSolver.java
+++ b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/NamingConstraintSolver.java
@@ -43,7 +43,22 @@ class NamingConstraintSolver {
return all;
}
- /** Try the solve the constraint problem given in the arguments, and put the result in renames */
+ /**
+ * Try the solve the constraint problem given in the arguments, and put the result in renames.
+ *
+ * This is done by performing iterative arc consistency until we have found a solution.
+ * After an initial iteration, the dimensions will have multiple
+ * valid values. Find a single valid assignment by iteratively locking one
+ * dimension after another, and running the arc consistency algorithm
+ * multiple times.
+ *
+ * This requires having constraints that result in an absolute ordering:
+ * equal, lessThan and greaterThan do that, but not necessarily notEqual
+ * If that is needed, the algorithm needs to be adapted with a backtracking
+ * (tree) search
+ *
+ * @return the solution in the form of the renames to perform
+ */
private Map<String, Integer> trySolve() {
// TODO: Evaluate possible improved efficiency by using a heuristic such as min-conflicts
@@ -55,7 +70,7 @@ class NamingConstraintSolver {
values.sort(Integer::compare);
possibleAssignments.replace(dimension, values.get(0));
}
- solution.put(dimension, possibleAssignments.get(dimension).get(0));
+ solution.put(dimension, possibleAssignments.get(dimension).get(0)); // Pick the first available solution
if (iterations > maxIterations) return null;
}
return solution;