求数独的解
1 | from pulp import * |
定义一个矩阵choices[VALS, ROWS, COLS],如果choices_4_5_6=1意味着5行6列是4,choices_3_8_9=0,意味着8行9列不为3.choices = LpVariable.dicts("Choice", (VALS, ROWS, COLS), cat="Binary")
给定约束
1 | # 1,每一个格子只能有一个数字 |
起始的数字约束
1 | # The starting numbers are entered as constraints |
求解
1 | # The problem data is written to an .lp file |
1 | for r in ROWS: |