How to use early_start method in avocado

Best Python code snippet using avocado_python

main.py

Source:main.py Github

copy

Full Screen

1from tkinter import *2MAX_TIME = 503# NUM_WORKS4class Work:5 def __init__(self, name, duration=1, not_earlier=None, not_later=None):6 if not_later is None:7 not_later = list()8 if not_earlier is None:9 not_earlier = list()10 self.name = name11 self.duration = duration12 self.not_earlier = not_earlier13 self.not_later = not_later14 self.early_start = 015 self.late_start = 016 self.early_end = MAX_TIME17 self.late_end = MAX_TIME18 def to_string(self):19 return str('\033[36m{}:\n'20 'Duration = {}\n'21 'Not later than: {}\n'22 'Not earlier than: {}\n'23 'Early start = {}\n'24 'Late start = {}\n'25 'Early end = {}\n'26 'Late end = {};\n'.format(self.name, self.duration, [self.not_later[i].name for i in range(len(self.not_later))],27 [self.not_earlier[i].name for i in range(len(self.not_earlier))], self.early_start,28 self.late_start, self.early_end, self.late_end))29def init_works(num_works):30 start_work = list()31 for i in range(num_works):32 T = Work('Work ' + str(i+1))33 start_work.append(T)34 return start_work35def input_data_parser(num_works, lines):36 for i in range(num_works):37 duration_start = lines[i].find("-")38 start_out = lines[i].find(":")39 end_out = lines[i].find(">")40 start_in = end_out + 241 duration = lines[i][duration_start + 2: start_out]42 works[i].duration = int(duration)43 out_str = lines[i][start_out + 2: end_out - 2]44 if len(out_str) == 0:45 out_str_split = []46 else:47 out_str_split = out_str.split(" ")48 _out = list(map(int, out_str_split))49 for j in _out:50 works[i].not_earlier.append(works[j - 1])51 in_str = lines[i][start_in:]52 if len(in_str) == 0:53 in_str_split = []54 else:55 in_str_split = in_str.split(" ")56 _in = list(map(int, in_str_split))57 for j in _in:58 works[i].not_later.append(works[j - 1])59 # T1.not_earlier = [T3, T2]60 # T1.not_later = [T4]61 #62 # T2.not_earlier = [T3]63 # T2.not_later = [T4]64 #65 # T3.not_earlier = []66 # T3.not_later = [T5]67 #68 # T4.not_earlier = [T1, T2, T3]69 # T4.not_later = []70 #71 # # T5.not_earlier = [T1, T2, T3]72 # T6.not_earlier = [T5]73 # return [name, in_str[start_out + 2: end_out - 2], in_str[start_in:]]74def later_to_earlier():75 for work in works:76 if len(work.not_later) != 0:77 for late_work in work.not_later:78 if work not in late_work.not_earlier:79 late_work.not_earlier.append(work)80def earlier_to_later():81 for work in works:82 if len(work.not_earlier) != 0:83 for late_work in work.not_earlier:84 if work not in late_work.not_later:85 late_work.not_later.append(work)86def critical_path(cur_len, cur_nodes, work):87 current_len = 088 current_nodes = []89 for prev_work in work.not_earlier:90 # if flag:91 # work.early_start += max([work.not_earlier[i].duration for i in range(len(work.not_earlier))])92 # flag = False93 current_len = cur_len94 current_nodes = cur_nodes.copy()95 current_len += prev_work.duration96 current_nodes.append(prev_work)97 # tmp_nodes_in_path[cur_len] += (prev_work.name + "; ")98 if len(prev_work.not_earlier) == 0:99 paths.append(current_len)100 nodes_in_path[current_len] = current_nodes101 # nodes_in_path[cur_len] = tmp_nodes_in_path[cur_len]102 else:103 critical_path(current_len, current_nodes, prev_work)104def max_work(works):105 max_len = 0106 index = 0107 if len(works) == 0:108 return -1109 for i in range(len(works)):110 if works[i].duration > max_len:111 max_len = works[i].duration112 index = i113 return index114def leeway_helper_to(work, works_in, early_start, temp_nodes):115 temp_nodes.update(work.not_earlier)116 max_index = max_work(work.not_earlier)117 if max_index == -1:118 return works_in, early_start, temp_nodes119 early_start += work.not_earlier[max_index].duration120 works_in.append(work.not_earlier[max_index])121 works_in, early_start, temp_nodes = leeway_helper_to(work.not_earlier[max_index], works_in, early_start, temp_nodes)122 return works_in, early_start, temp_nodes123def leeway_helper_after(work, works_in, late_start, temp_nodes):124 temp_nodes.update(work.not_later)125 max_index = max_work(work.not_later)126 if max_index == -1:127 return works_in, late_start, temp_nodes128 late_start += work.not_later[max_index].duration129 works_in.append(work.not_later[max_index])130 works_in, late_start, temp_nodes = leeway_helper_after(work.not_later[max_index], works_in, late_start, temp_nodes)131 return works_in, late_start, temp_nodes132def leeway(work):133 temp_nodes = set(work.not_earlier.copy())134 works_in = list()135 early_start = 0136 works_in, early_start, temp_nodes = leeway_helper_to(work, works_in, early_start, temp_nodes)137 for tmp_work in temp_nodes:138 if tmp_work not in works_in:139 works_in.append(tmp_work)140 early_start += tmp_work.duration141 work.early_start = early_start142 temp_nodes = set(work.not_later.copy())143 works_in = list()144 late_start = 0145 works_in, late_start, temp_nodes = leeway_helper_after(work, works_in, late_start, temp_nodes)146 for tmp_work in temp_nodes:147 if tmp_work not in works_in:148 works_in.append(tmp_work)149 late_start += tmp_work.duration150 work.late_start = max_path - late_start - work.duration151 work.late_end = max_path152 work.early_end = work.early_start + work.duration153if __name__ == '__main__':154 with open('Configuration', 'r') as f:155 lines = f.read().splitlines()156 with open('Configuration', 'r') as f:157 num_works = sum(1 for _ in f)158 works = init_works(num_works)159 input_data_parser(num_works, lines)160 # works = list()161 # T1 = Work('Work 1', duration=3)162 # T2 = Work('Work 2', duration=8)163 # T3 = Work('Work 3', duration=7)164 # T4 = Work('Work 4', duration=10)165 # T5 = Work('Work 5', duration=2)166 # T6 = Work('Work 6', duration=1)167 # T1.not_earlier = [T3, T2]168 # T1.not_later = [T4]169 #170 # T2.not_earlier = [T3]171 # T2.not_later = [T4]172 #173 # T3.not_earlier = []174 # T3.not_later = [T5]175 #176 # T4.not_earlier = [T1, T2, T3]177 # T4.not_later = []178 #179 # # T5.not_earlier = [T1, T2, T3]180 # T6.not_earlier = [T5]181 # works.append(T1)182 # works.append(T2)183 # works.append(T3)184 # works.append(T4)185 # works.append(T5)186 # works.append(T6)187 paths = list()188 nodes_in_path = dict()189 cur_nodes = list()190 cur_len = 0191 later_to_earlier()192 earlier_to_later()193 for work in works:194 cur_len = work.duration195 cur_nodes.clear()196 cur_nodes.append(work)197 if len(work.not_earlier) != 0:198 critical_path(cur_len, cur_nodes, work)199 else:200 paths.append(cur_len)201 nodes_in_path[cur_len] = cur_nodes202 max_path = max(paths)203 for work in works:204 # if work not in nodes_in_path[max_path]:205 # if work not in nodes_in_path[max_path]:206 leeway(work)207 if work in nodes_in_path[max_path]:208 work.late_start = work.early_start209 work.late_end = work.early_end210 print(work.to_string())211 print("\033[30mCritial path: \033[33m")212 print("START -->", end=' ')213 for i in nodes_in_path[max_path][-1::-1]:214 print(i.name + " -->", end=' ')215 print('END')216 print("\033[32mCritial path len = " + str(max_path))217 root = Tk()218 c = Canvas(root, width=100 * num_works, height=100 * num_works, bg='white')219 c.pack()220 for i in range(len(nodes_in_path[max_path][-1::-1])):221 if i > 0:222 c.create_line(100 * i, 40, 100 * i + 10, 40)223 # else:224 # if len(nodes_in_path[max_path][-1::-1][i].not_later) > 1:225 # for j in range(len(nodes_in_path[max_path][-1::-1][i].not_later)):226 # k = nodes_in_path[max_path][-1::-1][i].not_later[j]227 # if k not in nodes_in_path[max_path]:228 # c.create_line(100 * i + 50, 60 * (j + 1), 100 * (i + 1) + 10, 40 * (j + 2))229 # c.create_rectangle(100 * (i + 1) + 10, 40 * (j + 2), 100 * (i + 1) + 100 * (i + 1), 40 + 40 * (j + 2))230 # c.create_text(55 + 100 * (i + 1), 30 * (j + 2), text=k.name)231 c.create_rectangle(10 + 100 * i, 10, 100 + 100 * i, 60)232 c.create_text(55 + 100 * i, 30, text=nodes_in_path[max_path][-1::-1][i].name)233 # c.create_rectangle(60, 80, 140, 190,234 #235 # fill='yellow',236 # outline='green',237 # width=3)238 # activedash=(5, 4))239 c.create_text(100 * num_works - 70, 100 * num_works - 30, text="Critical path = " + str(max(paths)))...

Full Screen

Full Screen

cpm.py

Source:cpm.py Github

copy

Full Screen

1maxCost = 02class Task:3 def __init__(self, name, cost, dependencies):4 self.name = name5 self.cost = cost6 self.dependencies = dependencies7 self.early_finish = -18 self.early_start = 09 self.latest_start = 010 self.latest_finish = 011 self.critical_cost = 012 def __repr__(self):13 critical_cond = "Yes" if self.early_start == self.latest_start else "No"14 to_string = f"{self.name}, {self.early_start}, {self.early_finish}, {self.latest_start}, " \15 f"{self.latest_finish}, {self.latest_start - self.early_start}, {critical_cond}"16 #to_string = f"{self.name}, {self.cost}"17 return to_string18 def __str__(self):19 critical_cond = "Yes" if self.early_start == self.latest_start else "No"20 to_string = f"{self.name}, {self.early_start}, {self.early_finish}, {self.latest_start}, " \21 f"{self.latest_finish}, {self.latest_start - self.early_start}, {critical_cond}"22 #to_string = f"{self.name}, {self.cost}"23 return to_string24 def set_latest(self):25 self.latest_start = maxCost - self.critical_cost26 self.latest_finish = self.latest_start + self.cost27 def to_string_array(self):28 critical_cond = "Yes" if self.early_start == self.latest_start else "No"29 to_string = f"{self.name}, {self.early_start}, {self.early_finish}, {self.latest_start}, " \30 f"{self.latest_finish}, {self.latest_start -self.early_start}, {critical_cond}"31 return to_string32 def is_dependent(self, task):33 if task in self.dependencies:34 return True35 for dep in self.dependencies:36 if dep.is_dependent(task):37 return True38 return False39def critical_path(tasks):40 completed = []41 remaining = tasks.copy()42 while len(remaining) != 0:43 progress = False44 for task in remaining:45 if set(task.dependencies).issubset(completed):46 critical = 047 for _task in task.dependencies:48 if _task.critical_cost > critical:49 critical = _task.critical_cost50 task.critical_cost = critical + task.cost51 completed.append(task)52 remaining.remove(task)53 progress = True54 if not progress:55 raise ValueError("Graf je cyklicky, dalsi vypocet neni mozny")56 max_cost(tasks)57 initial_nodes = initials(tasks)58 calculate_early(initial_nodes)59 ret = completed60 # sort by name61 ret.sort(key=lambda x: x.name)62 return ret63def calculate_early(initials):64 for initial in initials:65 initial.early_start = 066 initial.early_finish = initial.cost67 set_early(initial)68def set_early(initial):69 completion_time = initial.early_finish70 for task in initial.dependencies:71 if completion_time >= task.early_start:72 task.early_start = completion_time73 task.early_finish = completion_time + task.cost74 set_early(task)75def initials(tasks):76 remaining = tasks.copy()77 for task in tasks:78 for task_dep in task.dependencies:79 if task_dep in remaining:80 remaining.remove(task_dep)81 #print("Initial nodes:")82 #print(remaining)83 return remaining84def max_cost(tasks):85 max = -186 for task in tasks:87 if task.critical_cost > max:88 max = task.critical_cost89 global maxCost90 maxCost = max91 print("Critical path lenght (cost): {}".format(maxCost))92 for task in tasks:93 task.set_latest()94def print_cpm(tasks):95 for task in tasks:96 print(task.to_string_array())97def get_cpm_table(tasks):98 table = []99 for task in tasks:100 table.append(task.to_string_array().split(','))101 return table102def copm_cpm(actions):103 reversed_deps = actions.copy()104 for task in reversed_deps:105 task[1] = []106 for task_orig in actions:107 for task_dep in task_orig[1]:108 if task_dep is task[0]:109 task[1].append(task_orig[0])110 task_list = []111 for task in reversed(reversed_deps):112 dep_list = []113 if task[1]:114 for deps in task[1]:115 for x in task_list:116 if x[0] == deps:117 dep_list.append(x[1])118 task_list.append([task[0], Task(task[0], int(task[2]), dep_list)])119 task_list = [row[1] for row in task_list]120 result = critical_path(task_list)...

Full Screen

Full Screen

1.py

Source:1.py Github

copy

Full Screen

1from q13.shared import read_file2import math3def filter_inactive_buses(schedules):4 return [int(s) for s in schedules if s != 'x']5def find_earliest_bus(early_start, schedules):6 best_bus = None7 wait_time = 10000008 for s in schedules:9 if early_start // s == 0:10 best_bus = s11 wait_time = 012 break13 else:14 # If not a multiple of start time15 departure_time = math.ceil(early_start / s) * s16 s_wait_time = departure_time - early_start17 if s_wait_time < wait_time:18 wait_time = s_wait_time19 best_bus = s20 return best_bus, wait_time21def main():22 early_start, schedules = read_file()23 schedules = filter_inactive_buses(schedules)24 best_bus, wait_time = find_earliest_bus(early_start, schedules)25 print('Best bus: ', best_bus)26 print('Wait time: ', wait_time)27 print(best_bus * wait_time)28if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful