Skip to content

Commit

Permalink
Example solutions via IBM ILOG CPLEX 12.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-chien committed Dec 22, 2019
1 parent 1996ad7 commit f95a820
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/MOSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def solve_board(initial_board, max_solve_time=120000):
sum(objective_vars[:, j]) == sum(range(board_len+1)))

# Set constraint: nonet sums
constraint_nonet = []
# constraint_nonet = []
if board_len == 9:
solver.Add(
sum(sum(objective_vars[0:3, 0:3])) == sum(range(0, board_len + 1)))
Expand Down
23 changes: 20 additions & 3 deletions source/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
[0, 1, 0, 2, 0, 0, 4, 0, 0],
[3, 0, 0, 0, 0, 5, 0, 1, 0]
])
mb9_sol = solve_board(medium_board_9, max_solve_time=10800000)
mb9_sol = solve_board(medium_board_9, max_solve_time=10800000) # unfortunately, COIN CBC cannot solve this problem
print(mb9_sol['solution'])
with open("mb9.lp", "w") as text_file:
with open("mb9.lp", "w") as text_file: # therefore, export to lp, and solve with CPLEX
print(mb9_sol['lp_file'], file=text_file)

# 9x9 difficult board
Expand All @@ -49,4 +49,21 @@
db9_sol = solve_board(difficult_board_9, max_solve_time=1200000)
print(db9_sol['solution'])
with open("./lp_files/db9.lp", "w") as text_file:
print(db9_sol['lp_file'], file=text_file)
print(db9_sol['lp_file'], file=text_file)

# Evil board
evil_board_9 = np.array([
[1, 0, 6, 0, 0, 7, 0, 0, 3],
[9, 2, 0, 0, 3, 0, 0, 0, 0],
[0, 5, 0, 0, 8, 0, 0, 6, 0],
[0, 0, 0, 8, 0, 0, 0, 0, 6],
[0, 1, 0, 0, 0, 0, 0, 5, 0],
[5, 0, 0, 0, 0, 4, 0, 0, 0],
[0, 8, 0, 0, 9, 0, 0, 2, 0],
[0, 0, 0, 0, 2, 0, 0, 9, 4],
[6, 0, 0, 3, 0, 0, 7, 0, 8]
])
eb9_sol = solve_board(evil_board_9) # unfortunately, COIN CBC cannot solve this problem
print(eb9_sol['solution'])
with open("./lp_files/eb9.lp", "w") as text_file: # therefore, export to lp, and solve with CPLEX
print(eb9_sol['lp_file'], file=text_file)

0 comments on commit f95a820

Please sign in to comment.