Given free-time schedule in the form (a - b) i.e., from 'a' to 'b' of n people, print all time intervals where all n participants are available
Person1: (4 - 16), (18 - 23)
Person2: (2 - 14), (17 - 24)
Person3: (6 - 8), (12 - 20)
Person4: (10 - 22)
CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // Code your testbench here // or browse Examples class scheduler; int time_slots[23]; int fr_q[$]; int p1[24]; int p2[24]; int p3[24]; int p4[24]; function void free_time(); for(int i=0;i<24;i++) begin p1[i]= (i inside {[4:16]} || i inside {[18:23]} ) ? 1 : 0; p2[i]= (i inside {[2:14]} || i inside {[17:24]} ) ? 1 : 0; p3[i]= (i inside {[6:8] } || i inside {[12:20]} ) ? 1 : 0; p4[i]= (i inside {[10:22]} ) ? 1 : 0; end $display("P:%p",p1); for(int i=0;i<23;i++) begin if ( p1[i]&&p1[i+1] ) time_slots[i]++; if ( p2[i]&&p2[i+1] ) time_slots[i]++; if ( p3[i]&&p3[i+1] ) time_slots[i]++; if ( p4[i]&&p3[i+1] ) time_slots[i]++; end $display("Time slots:%p",time_slots); fr_q = time_slots.find_index with ( item == 4 ); $display("FR_Q:%p",fr_q); foreach ( fr_q[i] ) begin $display ("Free Slot at %0d-%0d",fr_q[i],fr_q[i]+1); end endfunction: free_time endclass: scheduler module top; scheduler s; initial begin s = new; s.free_time(); end endmodule |