<s> import string <EOL> import random <EOL> from prime import lcm <EOL> class TaskIns ( object ) : <EOL> def __init__ ( self , start , end , priority , name ) : <EOL> self . start = start <EOL> self . end = end <EOL> self . usage = <NUM_LIT:0> <EOL> self . priority = priority <EOL> self . name = name . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> self . id = int ( random . random ( ) * <NUM_LIT> ) <EOL> def use ( self , usage ) : <EOL> self . usage += usage <EOL> if self . usage >= self . end - self . start : <EOL> return True <EOL> return False <EOL> def __repr__ ( self ) : <EOL> return str ( self . name ) + "<STR_LIT:#>" + str ( self . id ) + "<STR_LIT>" + str ( self . start ) + "<STR_LIT>" + str ( self . priority ) + budget_text <EOL> def get_unique_name ( self ) : <EOL> return str ( self . name ) + "<STR_LIT:#>" + str ( self . id ) <EOL> class TaskType ( object ) : <EOL> def __init__ ( self , period , release , execution , deadline , name ) : <EOL> self . period = period <EOL> self . release = release <EOL> self . execution = execution <EOL> self . deadline = deadline <EOL> self . name = name <EOL> def priority_cmp ( one , other ) : <EOL> if one . priority < other . priority : <EOL> return - <NUM_LIT:1> <EOL> elif one . priority > other . priority : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def tasktype_cmp ( self , other ) : <EOL> if self . deadline < other . deadline : <EOL> return - <NUM_LIT:1> <EOL> if self . deadline > other . deadline : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> html_color = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> taskfile = open ( '<STR_LIT>' ) <EOL> lines = taskfile . readlines ( ) <EOL> task_types = [ ] <EOL> tasks = [ ] <EOL> hyperperiod = [ ] <EOL> for line in lines : <EOL> line = line . split ( '<STR_LIT:U+0020>' ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:4> ) : <EOL> line [ i ] = int ( line [ i ] ) <EOL> if len ( line ) == <NUM_LIT:5> : <EOL> name = line [ <NUM_LIT:4> ] <EOL> elif len ( line ) == <NUM_LIT:4> : <EOL> name = '<STR_LIT>' <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if int ( line [ <NUM_LIT:0> ] ) > <NUM_LIT:0> : <EOL> task_types . append ( TaskType ( period = line [ <NUM_LIT:0> ] , release = line [ <NUM_LIT:1> ] , execution = line [ <NUM_LIT:2> ] , deadline = line [ <NUM_LIT:3> ] , name = name ) ) <EOL> for task_type in task_types : <EOL> hyperperiod . append ( task_type . period ) <EOL> hyperperiod = lcm ( hyperperiod ) <EOL> task_types = sorted ( task_types , tasktype_cmp ) <EOL> for i in xrange ( <NUM_LIT:0> , hyperperiod ) : <EOL> for task_type in task_types : <EOL> if ( i - task_type . release ) % task_type . period == <NUM_LIT:0> and i >= task_type . release : <EOL> start = i <EOL> end = start + task_type . execution <EOL> priority = start + task_type . deadline <EOL> tasks . append ( TaskIns ( start = start , end = end , priority = priority , name = task_type . name ) ) <EOL> html = "<STR_LIT>" <EOL> utilization = <NUM_LIT:0> <EOL> for task_type in task_types : <EOL> utilization += float ( task_type . execution ) / float ( task_type . period ) <EOL> if utilization > <NUM_LIT:1> : <EOL> print '<STR_LIT>' <EOL> html += '<STR_LIT>' <EOL> clock_step = <NUM_LIT:1> <EOL> for i in xrange ( <NUM_LIT:0> , hyperperiod , clock_step ) : <EOL> possible = [ ] <EOL> for t in tasks : <EOL> if t . start <= i : <EOL> possible . append ( t ) <EOL> possible = sorted ( possible , priority_cmp ) <EOL> if len ( possible ) > <NUM_LIT:0> : <EOL> on_cpu = possible [ <NUM_LIT:0> ] <EOL> print on_cpu . get_unique_name ( ) , "<STR_LIT>" , <EOL> html += '<STR_LIT>' + html_color [ on_cpu . name ] + '<STR_LIT>' + on_cpu . get_unique_name ( ) + '<STR_LIT>' <EOL> if on_cpu . use ( clock_step ) : <EOL> tasks . remove ( on_cpu ) <EOL> html += '<STR_LIT>' + html_color [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> print "<STR_LIT>" , <EOL> else : <EOL> print '<STR_LIT>' <EOL> html += '<STR_LIT>' + html_color [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> print "<STR_LIT:\n>" <EOL> html += "<STR_LIT>" <EOL> for p in tasks : <EOL> print p . get_unique_name ( ) + "<STR_LIT>" <EOL> html += "<STR_LIT>" + p . get_unique_name ( ) + "<STR_LIT>" <EOL> html += "<STR_LIT>" <EOL> output = open ( '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> output . write ( html ) <EOL> output . close ( ) </s>
