Преглед на файлове

Add heuristic column height to fragmentation score

Taddeus Kroes преди 6 години
родител
ревизия
5efb10b4e5
променени са 1 файла, в които са добавени 3 реда и са изтрити 1 реда
  1. 3 1
      strategy.py

+ 3 - 1
strategy.py

@@ -201,6 +201,7 @@ class State:
         """
         """
         Minimize the sum of dist(i,j) between all blocks i,j of the same color.
         Minimize the sum of dist(i,j) between all blocks i,j of the same color.
         Magnify vertical distances to avoid column stacking.
         Magnify vertical distances to avoid column stacking.
+        Add the vertical components of i and j to prioritize lower columns.
         """
         """
         def dist(i, j):
         def dist(i, j):
             yi, xi = divmod(i, COLUMNS)
             yi, xi = divmod(i, COLUMNS)
@@ -211,7 +212,8 @@ class State:
             if self.groups[i] == self.groups[j]:
             if self.groups[i] == self.groups[j]:
                 return abs(yj - yi)
                 return abs(yj - yi)
 
 
-            return abs(xj - xi) + abs(yj - yi) * 2 - 1
+            return abs(xj - xi) + abs(yj - yi) * 2 - 1 + \
+                   (self.nrows - yi) + (self.nrows - yj)
 
 
         colors = {}
         colors = {}
         for i, block in enumerate(self.blocks):
         for i, block in enumerate(self.blocks):