Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bisect
- def display(arr):
- print("="*40)
- x,y,z="Event","Task","No of days"
- print(x,"\t",y,"\t",z)
- print("="*40)
- for e,t,n in arr:
- print(e,"\t\t",t,"\t\t",n)
- for i in range(3):
- print()
- def compute_all_events(arr):
- if not arr:
- print("Total Time Taken will be 0")
- return
- l=arr[-1][0]
- sum=0
- for i in range(1,l+1):
- sum+=compute_finish_event(arr,i)
- print("Total time taken will be",sum)
- def show_longest_event(arr):
- if not arr:
- print("No events going on")
- n=arr[-1][0]
- fts=[None]*n
- for i in range(n):
- fts[i]=compute_finish_event(arr,i+1)
- i=0
- for j in range(n):
- if fts[j]>fts[i]:
- i=j
- print(fts)
- print("Longest Event",i+1)
- def compute_finish_event(arr,e):
- if not arr:
- return -1
- elif arr[-1][0]<e:
- return -1
- res=0
- for x,y,z in arr:
- if x==e:
- res=max(res,z)
- return res
- def verify(arr,x,y,z):
- if y<10 or y>30 or z>9 or z<0 or x<1 or x>5:
- return False
- for e,t,n in arr:
- if e==x and t==y:
- return False
- return True
- def add(arr,e,t,n):
- bisect.insort_right(arr,(e,t,n))
- def insert_task(arr):
- while True:
- print("Enter the new task information (event number, task number, number of days)")
- temp=input().split()
- if len(temp)<=2:
- print("Invalid insertion")
- continue
- else:
- e,t,n=map(int,temp)
- if verify(arr,e,t,n)==False:
- print("Invalid INsertion")
- continue
- else:
- add(arr,e,t,n)
- print("New Event added Successfully")
- return
- def plot(arr):
- n=len(arr)
- if not arr:
- print("No tasks Found")
- return
- print("-"*40)
- last=arr[-1][0]
- for i in range(1,last+1):
- m=compute_finish_event(arr,i)
- print("Event",i,"*"*m,m)
- print("-"*40)
- def generateData(arr):
- events=[1, 1, 1, 1, 2, 2, 3, 4, 5, 5, 5]
- tasks=[25, 22, 24, 16, 15, 22, 17, 14, 14, 11, 20]
- days=[1, 7, 6, 2, 3, 6, 5, 2, 4, 6, 7]
- for i in range(10):
- arr.append((events[i],tasks[i],days[i]))
- def main():
- cons=[]
- generateData(cons)
- while True:
- print("Critical Path Analysis")
- print("="*40)
- print("1- Display all Tasks")
- print("2- Find the event with longest duration")
- print("3- Compute the time to finish a given event")
- print("4- Compute project completion time")
- print("5- Plot events time chart")
- print("6- Add new task")
- print("7- Exit program")
- c=input()
- if not c.isdigit():
- print("Invalid Choice")
- continue
- c=int(c)
- if c>7 or c<=0:
- continue
- if c==1:
- display(cons)
- elif c==2:
- show_longest_event(cons)
- elif c==3:
- while True:
- t=int(input(("Enter the event number")))
- res=compute_finish_event(cons,t)
- if res==-1:
- print("Invalid Option")
- continue
- else:
- print("Project",t,"Completed in",res,"days")
- break
- elif c==4:
- compute_all_events(cons)
- elif c==5:
- plot(cons)
- elif c==6:
- insert_task(cons)
- else:
- yn=input("Are you sure you want to exit the application y/n")
- if yn=='y':
- print("GoodBye!")
- break
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement