Skip to content

Instantly share code, notes, and snippets.

@sasamijp
Last active December 18, 2018 06:54
Show Gist options
  • Save sasamijp/2fe27df9932a8f7c9cb20ba129be736a to your computer and use it in GitHub Desktop.
Save sasamijp/2fe27df9932a8f7c9cb20ba129be736a to your computer and use it in GitHub Desktop.
n = 1000
values = [5+(i**2 % 111) for i in range(1, n+1)]
weights = [20+(i % 11) for i in range(1, n+1)]
W=800
print("maximize")
print("-", " + ".join(str(v)+" x("+str(i+1)+")" for i, v in enumerate(values)))
print("subject to")
print("c1:", " + ".join(str(w)+" x("+str(i+1)+")" for i, w in enumerate(weights)), "<=", str(W))
print("bounds")
print("binary")
print(" ".join("x("+str(i)+")" for i in range(1, n+1)))
print("end")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment