Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created December 24, 2018 10:35
Show Gist options
  • Save kylemcdonald/28a0ae178e79ea06ff99e15f050468a0 to your computer and use it in GitHub Desktop.
Save kylemcdonald/28a0ae178e79ea06ff99e15f050468a0 to your computer and use it in GitHub Desktop.
Auction algorithm using numba.
from numba import jit
import numpy as np
index_dtype = np.int32
cost_dtype = np.int32
@jit(nopython=True)
def auction(a, eps=1):
n = len(a)
p = np.zeros(n, dtype=cost_dtype)
for eps_scaling in [10000,1000,100,10,1]:
eps_scaled = eps_scaling * eps
o = -np.ones(n, dtype=index_dtype)
q = list(range(n))
while len(q):
i = q.pop()
j = 0
v = 0
w = 0
for jc in range(n):
value = a[i,jc] - p[jc]
if value > w:
if value <= v:
w = value
else:
w = v
v = value
j = jc
if o[j] > -1:
q.append(o[j])
o[j] = i
gamma = (v - w) + eps_scaled
p[j] += gamma
return o
n = 10000
max_entry = 1000000
a = np.random.randint(low=0, high=max_entry, size=(n, n), dtype=cost_dtype)
sol = auction(a) # 1.8 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment