Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import facile
  2.  
  3. circuit = [facile.variable(0, Nv) for i in range(Nvmax + 1)]
  4.  
  5. facile.constraint(circuit[0] == 1)
  6.  
  7. for j in range(1, Nvmax + 1):
  8. for i in range(j):
  9. facile.constraint((circuit[j] == 0) | (circuit[i] != 0))
  10.  
  11. va = facile.array(Va)
  12. ov = facile.array(Ov)
  13. dv = facile.array(Dv)
  14.  
  15. c = facile.array(circuit)
  16. count_0 = sum([x == 0 for x in c])
  17. csts = circuit[1] == 0
  18. for city in set(Vh):
  19. origin = (va[ov[c[1]]] == city)
  20. destination = (va[dv[c[Nvmax - count_0]]] == city)
  21. # et hop, la contrainte!
  22. csts = csts | (origin & destination)
  23.  
  24. facile.constraint(csts)
  25.  
  26. td = facile.array(Td)
  27. ta = facile.array(Ta)
  28. dt = facile.array([item for sub in Dt for item in sub])
  29.  
  30. for k in range(1, Nvmax):
  31. same_city = va[dv[circuit[k]]] == va[ov[circuit[k+1]]]
  32. # Attention à la linéarisation des indices
  33. transfert = (td[circuit[k+1]] - ta[circuit[k]] >=
  34. dt[dv[circuit[k]] * (Na + 1) + ov[circuit[k+1]]])
  35. facile.constraint((same_city & transfert) | (circuit[k+1] == 0))
  36.  
  37. duration = Dda + ta[c[Nvmax - count_0]] - td[circuit[1]] <= Dmax
  38. facile.constraint(duration | (circuit[1] == 0))
  39.  
  40. circuits = facile.solve_all(circuit[1:])
  41. print (circuits)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement