Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ajoute le cout du stand de départ de ce sentier, au cout pour traverser ce sentier
- def createE(theTasks, thePaths):
- myPaths = thePaths.copy()
- for iC in range(0, len(thePaths)):
- standNumber = myPaths[iC][0]
- newWay = (standNumber, myPaths[iC][1], myPaths[iC][2] + theTasks[standNumber - 1])
- myPaths[iC] = newWay
- return myPaths
- # initialise L comme dans les notes
- # attention ret[0] existe car les stands sont numérotés de 1 à N et pas de 0 à N -1
- def initL(length):
- ret = [0, 0]
- for iL in range(2, length + 1):
- ret.append(4000000)
- return ret
- # modifie L comme dans les notes
- def modifyL(thisl, ux, realCosts, notS):
- for iCL in range(0, len(realCosts)):
- if (realCosts[iCL][0] == ux and realCosts[iCL][1] in notS):
- luxi2 = thisl[ux] + realCosts[iCL][2]
- thisl[realCosts[iCL][1]] = min(thisl[realCosts[iCL][1]], luxi2)
- elif (realCosts[iCL][1] == ux and realCosts[iCL][0] in notS):
- luxi2 = thisl[ux] + realCosts[iCL][2]
- thisl[realCosts[iCL][0]] = min(thisl[realCosts[iCL][0]], luxi2)
- return thisl
- # modifie S comme dans les notes
- def modifyS(thisL, notS, S):
- minL = 4000000
- index = 0
- for iS in notS:
- if (thisL[iS] < minL):
- minL = thisL[iS]
- index = iS
- S.append(index)
- return S, index
- nStands = len(tasks)
- l = initL(nStands)
- realCosts = createE(tasks, paths)
- ux = 1
- S = [1]
- All = list(range(1,nStands+1))
- notInS = list(set(All) - set(S))
- while(notInS):
- l = modifyL(l,ux,realCosts,notInS)
- S,ux = modifyS(l,notInS,S)
- notInS = list(set(All) - set(S))
- totLength = l[nStands] + tasks[nStands - 1]
- return totLength
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement