import sys import itertools import poek as pk quicksum = pk.quicksum model = pk.model() n = int(sys.argv[1]) m = n dx = 1.0 / n T = 1.58 dt = T / n h2 = dx**2 a = 0.001 y = pk.variable((n + 1, m + 1), lb=0.0, ub=1.0) u = pk.variable(n + 1, lb=-1.0, ub=1.0) model.use(y) model.use(u) def yt(j, dx): return 0.5 * (1 - (j * dx) * (j * dx)) #obj model.add(0.25 * dx * ((y[m, 0] - yt(0, dx))**2 + 2 * quicksum( (y[m, j] - yt(j, dx))**2 for j in range(1, n)) + (y[m, n] - yt(n, dx))**2) + 0.25 * a * dt * (2 * quicksum(u[i]**2 for i in range(1, m)) + u[m]**2))
import sys import math import poek as pk N = 1000*int(sys.argv[1]) h = 1.0/N alpha = 350 model = pk.model() t = pk.variable(N+1, lb=-1, ub=1) u = pk.variable(N+1, initial=0.01) x = pk.variable(N+1, lb=-0.05, ub=0.05) model.use(t) model.use(u) model.use(x) for i in range(N+1): t[i].initial = 0.05*math.cos((i+1)*h) x[i].initial = 0.05*math.cos((i+1)*h) ex = 0 for i in range(N): ex += 0.5*h*(u[i+1]**2+u[i]**2) + 0.5*alpha*h*(pk.cos(t[i+1])+pk.cos(t[i])) model.add( ex ) for i in range(N): model.add( x[i+1] - x[i] - (0.5*h)*(pk.sin(t[i+1])+pk.sin(t[i])) == 0 ) for i in range(N):
import sys import random import itertools import poek as pk random.seed(1000) N = int(sys.argv[1])*1000 W = N/10.0 model = pk.model() w = {} v = {} for i in range(N): w[i] = random.uniform(0.0,1.0) v[i] = random.uniform(0.0,1.0) x = pk.variable(N, lb=0.0, ub=1.0) model.use(x) model.add( pk.quicksum(v[i]*x[i] for i in range(N)) ) model.add( pk.quicksum(w[i]*x[i] for i in range(N)) <= W ) opt = pk.solver('gurobi') opt.set_option('TimeLimit', 0) opt.solve(model)
import sys import itertools import poek as pk model = pk.model() N = int(sys.argv[1]) x = pk.variable((N, N), lb=0.0, ub=1.0, binary=True) model.use(x) # obj model.add(pk.affine_expression([x[i, j] for i in range(N) for j in range(N)])) # one per row for i in range(N): model.add(pk.affine_expression([x[i, j] for j in range(N)]) == 1) # one per column for j in range(N): model.add(pk.affine_expression([x[i, j] for i in range(N)]) == 1) # \diagonals_col for i in range(N - 1): model.add( x[0, i] + pk.affine_expression([x[j, i + j] for j in range(1, N - i)]) <= 1) # \diagonals_row for i in range(1, N - 1): model.add( x[i, 0] + pk.affine_expression([x[i + j, j]
import sys import itertools import poek as pk quicksum = pk.quicksum model = pk.model() F = int(sys.argv[1]) G = F G_ = G + 1 d = pk.variable() y = pk.variable((F, 2), lb=0.0, ub=1.0) z = pk.variable((G_, G_, F), binary=True) s = pk.variable((G_, G_, F), lb=0.0) r = pk.variable((G_, G_, F, 2)) model.use(d) model.use(y) model.use(z) model.use(s) model.use(r) #obj model.add(d) #assmt for i, j in itertools.product(range(G_), range(G_)): model.add(quicksum(z[i, j, f] for f in range(F)) == 1) M = 2 * 1.414
import poek as pk random.seed(1000) model = pk.model() N = int(sys.argv[1]) # Locations M = N # Customers P = int(sys.argv[2]) # Facilities d = {} for n in range(N): for m in range(M): d[n, m] = random.uniform(1.0, 2.0) x = pk.variable((N, M), lb=0.0, ub=1.0, initial=0.0) y = pk.variable(N, lb=0.0, ub=1.0, initial=0.0) model.use(x) model.use(y) # obj model.add(pk.quicksum(d[n, m] * x[n, m] for n in range(N) for m in range(M))) # single_x for m in range(M): model.add(pk.quicksum(x[n, m] for n in range(N)) == 1) # bound_y for n, m in itertools.product(range(N), range(M)): model.add(x[n, m] - y[n] <= 0)