Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import pulp
  2. import numpy as np
  3. import pandas as pd
  4.  
  5. prob = pulp.LpProblem("max_latency_gain", pulp.LpMaximize)
  6.  
  7. V = 100 # nb_videos
  8. E = 10 # nb_endpoints
  9. R = 100 # nb_requests
  10. C = 10 # nb_cache_servers
  11. X = 100 # cache Serveur Capacity
  12.  
  13. # Problem Data
  14. R = np.zeros([V,C])
  15. Ld = np.zeros(E)
  16. L = np.zeros([C,E])
  17. S = np.zeros(V)
  18.  
  19. def var_array(pattern):
  20. """Creates a two-dimension array of variables created by function pattern(i, j).
  21. The array is transformed into an np.array.
  22. """
  23. array = [
  24. [
  25. pattern(i, j)
  26. for j in range(V)
  27. ] for i in range(C)
  28. ]
  29. return np.array(array)
  30.  
  31. # Optimization Variable
  32. m = var_array(lambda i, j: pulp.LpVariable("m_%d_%d" % (i, j), 0, 3))
  33.  
  34. # Objective function
  35. prob += sum([ sum([ sum([ R[j][e]*(Ld[e] - L[i][e]*m[i][j]) for j in range(V)]) for i in range(C)]) for e in range(E)])
  36.  
  37. # Constraints
  38. for i in range(C):
  39. prob += sum([ S[j]*m[i][j] for j in range(V)]) <= X # Cache Serveur Capacity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement