From 7ffdacf1ceeee2c3067cb8ece3aa79ced0a46cac Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sat, 6 May 2023 13:16:56 -0700 Subject: [PATCH] change antidiagonal index (#344), remove nested double loop --- benchmarks/queens-pulp.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/benchmarks/queens-pulp.py b/benchmarks/queens-pulp.py index 0768dbff..cec52a96 100644 --- a/benchmarks/queens-pulp.py +++ b/benchmarks/queens-pulp.py @@ -41,13 +41,11 @@ def gen_model(n): # diagonal \ for p, k in enumerate(range(2 - n, n - 2 + 1)): - queens += lpSum(x[i][j] for i in range(n) for j in range(n) - if i - j == k) <= 1, 'diag1({})'.format(p) + queens += lpSum(x[k+j][j] for j in range(n) if 0 <= k + j < n) <= 1, 'diag1({})'.format(p) # diagonal / - for p, k in enumerate(range(3, n + n)): - queens += lpSum(x[i][j] for i in range(n) for j in range(n) - if i + j == k) <= 1, 'diag2({})'.format(p) + for p, k in enumerate(range(1, n + n - 2)): + queens += lpSum(x[i][k-j] for i in range(n) if 0 <= k-j < n) <= 1, 'diag2({})'.format(p) ed = time.time() execTime = ed-st