Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. # ajoute le cout du stand de départ de ce sentier, au cout pour traverser ce sentier
  2. def createE(theTasks, thePaths):
  3. myPaths = thePaths.copy()
  4. for iC in range(0, len(thePaths)):
  5. standNumber = myPaths[iC][0]
  6. newWay = (standNumber, myPaths[iC][1], myPaths[iC][2] + theTasks[standNumber - 1])
  7. myPaths[iC] = newWay
  8. return myPaths
  9. # initialise L comme dans les notes
  10. # attention ret[0] existe car les stands sont numérotés de 1 à N et pas de 0 à N -1
  11. def initL(length):
  12. ret = [0, 0]
  13. for iL in range(2, length + 1):
  14. ret.append(4000000)
  15. return ret
  16. # modifie L comme dans les notes
  17. def modifyL(thisl, ux, realCosts, notS):
  18. for iCL in range(0, len(realCosts)):
  19. if (realCosts[iCL][0] == ux and realCosts[iCL][1] in notS):
  20. luxi2 = thisl[ux] + realCosts[iCL][2]
  21. thisl[realCosts[iCL][1]] = min(thisl[realCosts[iCL][1]], luxi2)
  22. elif (realCosts[iCL][1] == ux and realCosts[iCL][0] in notS):
  23. luxi2 = thisl[ux] + realCosts[iCL][2]
  24. thisl[realCosts[iCL][0]] = min(thisl[realCosts[iCL][0]], luxi2)
  25. return thisl
  26. # modifie S comme dans les notes
  27. def modifyS(thisL, notS, S):
  28. minL = 4000000
  29. index = 0
  30. for iS in notS:
  31. if (thisL[iS] < minL):
  32. minL = thisL[iS]
  33. index = iS
  34. S.append(index)
  35. return S, index
  36. nStands = len(tasks)
  37.  
  38. l = initL(nStands)
  39. realCosts = createE(tasks, paths)
  40. ux = 1
  41. S = [1]
  42. All = list(range(1,nStands+1))
  43. notInS = list(set(All) - set(S))
  44. while(notInS):
  45. l = modifyL(l,ux,realCosts,notInS)
  46. S,ux = modifyS(l,notInS,S)
  47. notInS = list(set(All) - set(S))
  48. totLength = l[nStands] + tasks[nStands - 1]
  49. return totLength
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement