cleanup is_run_from_ipython()
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from ortools.sat.python import cp_model
|
||||
from ortools.sat.python import visualization
|
||||
|
||||
|
||||
def BuildPairs(rows, cols):
|
||||
@@ -130,12 +131,12 @@ def SolveHidato(puzzle, index):
|
||||
|
||||
r = len(puzzle)
|
||||
c = len(puzzle[0])
|
||||
|
||||
print('')
|
||||
print('----- Solving problem %i -----' % index)
|
||||
print('')
|
||||
print(('Initial game (%i x %i)' % (r, c)))
|
||||
PrintMatrix(puzzle)
|
||||
if not visualization.run_from_ipython():
|
||||
print('')
|
||||
print('----- Solving problem %i -----' % index)
|
||||
print('')
|
||||
print(('Initial game (%i x %i)' % (r, c)))
|
||||
PrintMatrix(puzzle)
|
||||
|
||||
#
|
||||
# declare variables
|
||||
@@ -170,11 +171,24 @@ def SolveHidato(puzzle, index):
|
||||
status = solver.Solve(model)
|
||||
|
||||
if status == cp_model.MODEL_SAT:
|
||||
PrintSolution([solver.Value(x) for x in positions], r, c,)
|
||||
print('Statistics')
|
||||
print(' - conflicts : %i' % solver.NumConflicts())
|
||||
print(' - branches : %i' % solver.NumBranches())
|
||||
print(' - wall time : %f ms' % solver.WallTime())
|
||||
if visualization.run_from_ipython():
|
||||
output = visualization.SvgWrapper(10, r, 40.0)
|
||||
for i in range(len(positions)):
|
||||
val = solver.Value(positions[i])
|
||||
x = val % c
|
||||
y = val // c
|
||||
color = 'white' if puzzle[y][x] == 0 else 'lightgreen'
|
||||
value = solver.Value(positions[i])
|
||||
output.AddRectangle(x, r - y - 1, 1, 1, color, 'black', str(i + 1))
|
||||
|
||||
output.AddTitle('Puzzle %i solved in %f s' % (index, solver.WallTime()))
|
||||
output.Display()
|
||||
else:
|
||||
PrintSolution([solver.Value(x) for x in positions], r, c,)
|
||||
print('Statistics')
|
||||
print(' - conflicts : %i' % solver.NumConflicts())
|
||||
print(' - branches : %i' % solver.NumBranches())
|
||||
print(' - wall time : %f ms' % solver.WallTime())
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user