From 8fd2165914642cc3775a45f7df8facb8d710df64 Mon Sep 17 00:00:00 2001 From: ahmadayman28 Date: Tue, 19 Nov 2024 01:54:53 +0200 Subject: [PATCH] Added code files --- ProcessSchedulingSimulator/.idea/.gitignore | 3 + ProcessSchedulingSimulator/.idea/misc.xml | 6 + ProcessSchedulingSimulator/.idea/modules.xml | 8 ++ .../ProcessSchedulingSimulator.iml | 11 ++ .../model/Process.class | Bin 0 -> 2312 bytes .../FirstComeFirstServeScheduler.class | Bin 0 -> 2370 bytes .../scheduler/PriorityScheduler.class | Bin 0 -> 3523 bytes .../scheduler/RoundRobinScheduler.class | Bin 0 -> 4275 bytes .../scheduler/Scheduler.class | Bin 0 -> 209 bytes .../scheduler/ShortestJobFirstScheduler.class | Bin 0 -> 3787 bytes .../simulation/SimulationMode.class | Bin 0 -> 1045 bytes .../simulation/Simulator.class | Bin 0 -> 2641 bytes .../ui/SimulatorUI.class | Bin 0 -> 3634 bytes .../src/model/Process.java | 93 +++++++++++++ .../FirstComeFirstServeScheduler.java | 24 ++++ .../src/scheduler/PriorityScheduler.java | 100 ++++++++++++++ .../src/scheduler/RoundRobinScheduler.java | 125 ++++++++++++++++++ .../src/scheduler/Scheduler.java | 9 ++ .../scheduler/ShortestJobFirstScheduler.java | 88 ++++++++++++ .../src/simulation/SimulationMode.java | 6 + .../src/simulation/Simulator.java | 52 ++++++++ .../src/ui/SimulatorUI.java | 110 +++++++++++++++ 22 files changed, 635 insertions(+) create mode 100644 ProcessSchedulingSimulator/.idea/.gitignore create mode 100644 ProcessSchedulingSimulator/.idea/misc.xml create mode 100644 ProcessSchedulingSimulator/.idea/modules.xml create mode 100644 ProcessSchedulingSimulator/ProcessSchedulingSimulator.iml create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/model/Process.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/FirstComeFirstServeScheduler.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/PriorityScheduler.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/RoundRobinScheduler.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/Scheduler.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/ShortestJobFirstScheduler.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/simulation/SimulationMode.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/simulation/Simulator.class create mode 100644 ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/ui/SimulatorUI.class create mode 100644 ProcessSchedulingSimulator/src/model/Process.java create mode 100644 ProcessSchedulingSimulator/src/scheduler/FirstComeFirstServeScheduler.java create mode 100644 ProcessSchedulingSimulator/src/scheduler/PriorityScheduler.java create mode 100644 ProcessSchedulingSimulator/src/scheduler/RoundRobinScheduler.java create mode 100644 ProcessSchedulingSimulator/src/scheduler/Scheduler.java create mode 100644 ProcessSchedulingSimulator/src/scheduler/ShortestJobFirstScheduler.java create mode 100644 ProcessSchedulingSimulator/src/simulation/SimulationMode.java create mode 100644 ProcessSchedulingSimulator/src/simulation/Simulator.java create mode 100644 ProcessSchedulingSimulator/src/ui/SimulatorUI.java diff --git a/ProcessSchedulingSimulator/.idea/.gitignore b/ProcessSchedulingSimulator/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/ProcessSchedulingSimulator/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/ProcessSchedulingSimulator/.idea/misc.xml b/ProcessSchedulingSimulator/.idea/misc.xml new file mode 100644 index 0000000..a346fd7 --- /dev/null +++ b/ProcessSchedulingSimulator/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProcessSchedulingSimulator/.idea/modules.xml b/ProcessSchedulingSimulator/.idea/modules.xml new file mode 100644 index 0000000..6ad0a8c --- /dev/null +++ b/ProcessSchedulingSimulator/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ProcessSchedulingSimulator/ProcessSchedulingSimulator.iml b/ProcessSchedulingSimulator/ProcessSchedulingSimulator.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/ProcessSchedulingSimulator/ProcessSchedulingSimulator.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/model/Process.class b/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/model/Process.class new file mode 100644 index 0000000000000000000000000000000000000000..72e0f48a15600833fbad307fcef0e687fb985f6b GIT binary patch literal 2312 zcmaKs-EJFI5Xb+=cKnrf>?W;Cny-?E;jP*?|)wZ1z-hF@<ll!+&o{Exc4lY9G)N* zhD2G<4q{ihT#3!dsO2{7Zoi{F9fa{U&vwf*TL(|gei(gTf2&)Eo?f>dCeGtYFjPm= zokD)gK6F}o-IClHVL2>G>It-F+n(z=X8)=7_U*P?OrxI1Lo8>oBIo$A!ov9}S-m6s zK-U7`;Aq#)mS;Q13O`mN#~CUHMxU6yc1ODl8@7FL*sn*_!c&h(20q+A?&}!!7ZLrS z5$e&zg(ezir?X{wx}L=&h4nD*@2vK+x_v!T_p&@IcUhcPxy%QOds%(Y1U7p;?KC>3 z>uNWH#|m%#CqHpvXRxj?`~Rx!=O9OTlO2{|FOBfcX67s*9qW(mP=91k`Xk$rV-Y-Y z%5u%v>(qoy4;eybqF`*TPO!wXPD^_Q{nAckisy?Y%EA6 z9;7e~GEa~j7l25XBm;}FAf;iDo3S9(c#zUCNR=SBE&!235|CT5AQQtNOR*rg<3T2d zLGBRb?gb!HBLebHEJ%46D!N-LK8(OC6hKA{1vj*WZ39|lQInfn{4+l+2YSIjcq!4 z?mG=SXa1~n=JCFt6>*+YkziWT)PUdzr^z8%y4j7pn@aVM z=)E)Cc%#ms^uqDl@eetEK4+7dO<+1+m`rxhc|V``Id9(c%U?S`0a(Tt3B)jDAZ}t9 zdjygX<(ACZ(y8TcZah?#Kw!_34&(*Te*p0(*N#MayUGxbJ#=&19bMo-OMDDHHp!Utq)vl&8ZAO!Xx! zbmUAog@XpBP0ZksK&qFnYeLj@>946r%*uN1YL8hHFXAx4IH7odH+F=Dyn(d9c*CtK zJ9o=-E6Vp1ID(@lUcx*JtEu3M=UH3QUbh-#gs}^wIF1trGA6QE=%co@?FXtsE4M`) z2inD3E+bn`PzpRH8+jf6q={2H{4m28swoKMOq{`4frAaXsa9O4B7@sjQ0K}Iq!aj> znnIy-8estpXE`;7dl|17c-6#fI4`g-q^3V5xoK(uwnI#v6N!e%mNljeCN64BCNW)Y zd48Y^PO*z}30%Umfj4w}To#xNQ-lEuPM~Uv=Qgat6%1SzIPO>Ks@k%Zm%C;$47)~! zi<0uTRH>^p@FvmrZ2wj8yjFM|0ux2cQERQnhVs_shD}MT=vJg%mY${e9br7ETcjsb z?8VwGZ=U_uwIqOOgX-4JXUid7VJBz|eXT*~(Pq0#6mupc-5oj$j8$5mr<{;H0a4(& z^@HASc7e|gcrOj)T4uKKQXngvtFqZCcC=*G92vCqpL2c?`?CRbF_X4zY*giZx9IsZ z0&|&xTm#!IamSi$$5`{6K%(Tfyb2FdpTXR2hA%E$3Fjag?`WOW#+%fzJevJ;TWJy2St+ z?eOlVye!+Tg*l!=jPrVh_vH}Zyj=Nwi@O}(g74vlA0WQvB8F>xYPEj8&8OKmz;zV3 z6S#qQXr-NhXRu+u)#45e;3>vtKVs>d(5^@7Scqw=ZHEttNqGNx&N3yg&H1Wllo7?r;ir33GTP>2%lr-9~8fG9smFU literal 0 HcmV?d00001 diff --git a/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/PriorityScheduler.class b/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/PriorityScheduler.class new file mode 100644 index 0000000000000000000000000000000000000000..a033f24dcf782d9ca797c90a6307c6cf97a0e373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U{8DnlYQ6mFtCD0`qc38Cx=4|pYRs0-8_FOLeyfNwn@?ibdxwmSU3NA`Fee9qIP0G zyPJEd?JP$NxQ)Wxfv5O+e;xz4%ogM-)%_6;;T_zGciD*i8izf~M@ZCV9H4wpF%wAH z8u{-9-o(@Kfdf%pg5FA_+LEqA?- z)A5jCY-0n#{u&5&V@VOh`{4f|w?b~|iN{t@@YFq2S9g|eJ=pQJ;TTyP zrn)24_c(U3l{1ehcP^halC+2co`4jhwRd>vEBL^rtvF0f{0&dwA8dF2 z2_64JVNGS=#+tS_0&P3+_dwfj{3Xz~7k>`4-Gx8l(_UVv0`yf@JC(}5eNE-vNZe$g zO$l@=rTyP9bM<{prtV4BMUUb$go@y^c!u|WrrfiX{tNgLz8pM#g->6ngKvA+SG?=1 Q_%5xJoc$htz&h>uH|0Ek{r~^~ literal 0 HcmV?d00001 diff --git a/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/RoundRobinScheduler.class b/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/scheduler/RoundRobinScheduler.class new file mode 100644 index 0000000000000000000000000000000000000000..8584824276055067ad46489e027b9a32728d6059 GIT binary patch literal 4275 zcmb_e{dW{+6@F&3yOV4tWD~NGEe1jxWH$j)vBlazB%}?j-4sYLSfVwP-60vWJG0Ep zMp9c_6-_HzKk7$YZ4s)a*jn4#rUZ{3kH?>^R*y%H{$&3RJs!d5otfR84H2!Hb22;c zo%`|L=ehU3@2{_3{yBg_ydFac4Kl(CB8WR?C+Qn$^!=heayq9!)6LqR`orB^kd7hb(Qf=ll<2jbvzdGRQj|tM>Asm)5reGXLB&>D$ ztdB`fOJWBFrdfxx?;<_X&PJIKTR19Vod6<0hOg9)2DG&!j0us!q=Ju$3>0RtuWZ?l z0J@!R)+WAwLcx?kFs7Z-a%D#wF)bmUR*(}l*R0#3&#* zV>sH3X35Z*Rjm~R4HzC~xv_-VXxhEy;N;Zu zob;NmE%3?hLz;#i*Ly@a^4cl#QlHd9s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~}BG zRY-_4C`YfG&BLSPgKm>ywe??4jgt~8lAM%kciQh}L>{`MLd61uyw%-ny=fW@#kX^^ zDM%wDV?o6tvJ6t+8MziiPSabb=9yV>Om|S}^iHk5S5uI~T^Y+NR&bAs&j3x=A5zIP z)A6m&2ZongguU;WlSwV&Fubwt4r>TQCJbwuKJVUC;SW;Wr%^DZTefSp{bA1nlP46fScO0@ zAeXj_7s!7O!qIXwx{Pfu9Zv&HIiv7R2!-en$qOt>-@#6VDFow0oI*Bk>rY?@<&d@) w($>EbD|=tKz}h*4z<3}AhJ1;K=TNw=>o%kUxgs@BLV^Bcp`Hq!5hjM}Z{RZ7DF6Tf literal 0 HcmV?d00001 diff --git a/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/simulation/Simulator.class b/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/simulation/Simulator.class new file mode 100644 index 0000000000000000000000000000000000000000..3de977870e645748deac2e0473bfbb3b2b82e080 GIT binary patch literal 2641 zcmaJ@T~iZR7=8{3*$|cwQLrdrRHP6p@sp~tRz*;3_>f>M*w!v#g_X^2+})t``@6Tj zY^O85b^38rr^=`^_NLRB_NEtgde#1rUbNHa?1m(uH8W?=d3WFQyzhD5=bV#Y|GobZ zzzKXBLk&U-!YXPJ5oo@qEo(_rvlfyQbJz5oClEPqScZ2(Ak^EJRS*@}>^l`b!%UuX z9Bn0SxLynjLUpKzs-QtdBbo%ZxJJHcYMx z(Spr%baRXPe9_c7sWn|Tl9{#F^ln9)f~_i^LAyZv;{h3a%%0Z;8pkKbuS`x2506bw zk7kDjwx|Es+s|UViVg|dSaFj`F?3;vg1CyE*tL$ZjOQ5Ef?t16#xnRl~wJ{u! z-hy|fs zGp84%ZlX9T&~edPvg{jHycB~h$2D_7GP0PD;RT$Q&_f%z49bz}%hqEUBMQ!{I47BJ zT(3CNtj*8Y;XGbakXA8<@%2?*aXmdxFT2Ri&>9rWu#@D%@)$$c@~IZ?rAZYRFeR`x zuPy0Aww2SoOU#cW*V8PIl}`3PMR9#qDkxch^^paXg3QCT>M?^^ z1(#L4f>-HWDMz^o)X~~oI+SGR?_z)F^<}x^GRA_Xc}0gCX6J^jc|4t`rcEx~-@U05 zDb_NOc~jc3^zmYTPIsoYIg^uH(soWWvzlW_yYw>bEgIyZ?Fls44$+!i-Q@A>(Per7^8g z%5ambd!>`Ad~kFM`3Fs0rNY{{HiE1x>9bi-F>;uNh)WTIv4qLbr3 zmTWebzSz!yTq*T=+O|E{bF{*k?k(E$Zc_wr#PBBGQt-AE;yVJ}6;cdq*8U8*6Npb0ElckA${`##thk6v&IbktVl4EiW$Dh4smU8f!G{8S9$Wd77Np=~ zfv%^!@|+G<&%?f+Hzg3_lb0I=UZYimD{Q>1{4uW!_O<-RyOht@X=OP>uf7eb4VT(D-cQOb|VcWvI-TagNOnbOx_g(Dy z0)wH!+FRI1yU(|K!qSe@?)UAsT4^`a-s{_u$Y5=2?Ki~8vdLeFt&^>v?I_z>t~bf` z?&nf(;Rvk*v<~@Jg4SVL&-+#fts^s?t2pMH4G-|bOv{U_IQ66CCggK7zzRr)KI2{g zC7J$;%zVu&`a9mLtJs12tkKWdgmupZ7(dgG~Kecv%OdhP#S!XFs2+M@4!42GGA0_w-+q-z5R*a($ J@DV;i`+rjCk%<5R literal 0 HcmV?d00001 diff --git a/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/ui/SimulatorUI.class b/ProcessSchedulingSimulator/out/production/ProcessSchedulingSimulator/ui/SimulatorUI.class new file mode 100644 index 0000000000000000000000000000000000000000..3967b8ac8fc8bc25031d768948a0e2c482de1b3c GIT binary patch literal 3634 zcmb7GYj7J^75=Uzd)LxBcAVOYlO|c`K_$nPaj% z0+B>=Mu94DN7*V?3WjGnc3(DVI&KUKBF%_HQ_!Me6Iul}Rjiu8bXuS})O1{d&df&3 z3^ijj+7)cka0fcp7?fQqduEY#I2D@Jk?~EnoW4odvc0V5nnrO*#a01*cz9SJot)OQ zxdk&{DOmQrzG|nOjG+tL73|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shKIHuSxMq!a(tqQl^ThmIH1*%~d1A%ZN+qPq4FmYfmji&oLap0VY8&T9D$+t&glah@Av~ z4-Vl$-YGLU!Z6*3X&hy!hIoq@=2<<05|iU8jN)n1`&pb|VA6OAC-D<%Tw{2yQ|q_L z;t#wUy-DpqF+6|9dHe;Bue5IN#>1!gZVdaI3WRO?)RL!`mSl;`j%?i|;X9E%+P0Pu+kFqlmwY76r$| ze=s24!vO`eLi`)8x5z?OL0nGB7;_xBMe;;zgPqOVJ5U<9@yqx@z#%%_z(3G(6LBWg zGa1JJQ?+aj%EKZlS>Rel-^ processes) { + if (SimulationMode.PREEMPTIVE.equals(SimulationMode.PREEMPTIVE)) { + preemptivePriorityScheduling(processes); + } else { + nonPreemptivePriorityScheduling(processes); + } + } + + // Non-preemptive Priority Scheduling + private void nonPreemptivePriorityScheduling(List processes) { + // Sort processes by arrival time first, and then by priority (lowest priority number = highest priority) + processes.sort(Comparator.comparingInt(Process::getArrivalTime) + .thenComparingInt(Process::getPriority)); + + int currentTime = 0; + List readyQueue = new ArrayList<>(); + int index = 0; + + while (index < processes.size() || !readyQueue.isEmpty()) { + // Add processes that have arrived to the ready queue + while (index < processes.size() && processes.get(index).getArrivalTime() <= currentTime) { + readyQueue.add(processes.get(index)); + index++; + } + + // If there are processes in the ready queue, execute the one with the highest priority (lowest priority number) + if (!readyQueue.isEmpty()) { + // Sort ready queue based on priority + readyQueue.sort(Comparator.comparingInt(Process::getPriority)); + + Process currentProcess = readyQueue.remove(0); // Get the highest priority process + + // Execute the process + System.out.println("Process " + currentProcess.getId() + " starts at time " + currentTime); + currentTime += currentProcess.getBurstTime(); // Simulate execution for the burst time + System.out.println("Process " + currentProcess.getId() + " ends at time " + currentTime); + } else { + // If no process is ready, increment time + currentTime++; + } + } + } + + // Preemptive Priority Scheduling (same as before) + private void preemptivePriorityScheduling(List processes) { + // Sort processes by arrival time initially + processes.sort(Comparator.comparingInt(Process::getArrivalTime)); + int currentTime = 0; + List readyQueue = new ArrayList<>(); + int index = 0; + Process runningProcess = null; + + while (index < processes.size() || !readyQueue.isEmpty() || runningProcess != null) { + // Add processes that have arrived to the ready queue + while (index < processes.size() && processes.get(index).getArrivalTime() <= currentTime) { + readyQueue.add(processes.get(index)); + System.out.println("Process " + processes.get(index).getId() + " enters ready queue at time " + currentTime); + index++; + } + + // If a process is running, check if it has completed + if (runningProcess != null && runningProcess.isCompleted()) { + System.out.println("Process " + runningProcess.getId() + " ends at time " + currentTime); + runningProcess = null; + } + + // Select the next process to execute if none is running + if (runningProcess == null && !readyQueue.isEmpty()) { + // Sort ready queue by priority (lower number = higher priority) + readyQueue.sort(Comparator.comparingInt(Process::getPriority)); + + // Select the process with the highest priority + runningProcess = readyQueue.remove(0); + + // Log the process starting execution + System.out.println("Process " + runningProcess.getId() + " starts at time " + currentTime); + } + + // Execute the running process for one unit of time + if (runningProcess != null) { + runningProcess.executeFor(1); + } + + // Increment the time step + currentTime++; + } + } +} \ No newline at end of file diff --git a/ProcessSchedulingSimulator/src/scheduler/RoundRobinScheduler.java b/ProcessSchedulingSimulator/src/scheduler/RoundRobinScheduler.java new file mode 100644 index 0000000..ab4607a --- /dev/null +++ b/ProcessSchedulingSimulator/src/scheduler/RoundRobinScheduler.java @@ -0,0 +1,125 @@ +package scheduler; + +import model.Process; +import simulation.SimulationMode; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class RoundRobinScheduler implements Scheduler { + + private int timeQuantum; // Time slice for round robin scheduling + + public RoundRobinScheduler(int timeQuantum) { + this.timeQuantum = timeQuantum; + } + + @Override + public void schedule(List processes) { + Queue queue = new LinkedList<>(); + int time = 0; + int index = 0; + + // Sort processes by arrival time + processes.sort((p1, p2) -> Integer.compare(p1.getArrivalTime(), p2.getArrivalTime())); + + while (index < processes.size() || !queue.isEmpty()) { + // Add all processes that have arrived by the current time to the queue + while (index < processes.size() && processes.get(index).getArrivalTime() <= time) { + queue.add(processes.get(index)); + index++; + } + + if (!queue.isEmpty()) { + Process current = queue.poll(); + + if (current.getRemainingTime() > 0) { + int executionTime = Math.min(current.getRemainingTime(), timeQuantum); + current.setRemainingTime(current.getRemainingTime() - executionTime); + time += executionTime; + + System.out.println("Process " + current.getId() + " executed for " + executionTime + " units at time " + time); + + // If the process is not finished, re-add it to the queue + if (current.getRemainingTime() > 0) { + queue.add(current); + } else { + System.out.println("Process " + current.getId() + " ends at time " + time); + } + } + } else { + // If no processes are ready to execute, increment time + time++; + } + } + } + + + // Non-preemptive Round Robin (just executes each process in turn) + private void nonPreemptiveRoundRobin(List processes) { + Queue queue = new LinkedList<>(); + int currentTime = 0; + + // Sort processes by arrival time + processes.sort((p1, p2) -> Integer.compare(p1.getArrivalTime(), p2.getArrivalTime())); + + int index = 0; + while (index < processes.size() || !queue.isEmpty()) { + // Add processes that have arrived to the ready queue + while (index < processes.size() && processes.get(index).getArrivalTime() <= currentTime) { + queue.add(processes.get(index)); + index++; + } + + if (!queue.isEmpty()) { + Process currentProcess = queue.poll(); + + // Execute the process for its entire burst time + System.out.println("Process " + currentProcess.getId() + " starts at time " + currentTime); + currentTime += currentProcess.getBurstTime(); + System.out.println("Process " + currentProcess.getId() + " ends at time " + currentTime); + } else { + currentTime++; // No process is ready, increment time + } + } + } + + // Preemptive Round Robin (interrupts processes based on time quantum) + private void preemptiveRoundRobin(List processes) { + Queue queue = new LinkedList<>(); + int currentTime = 0; + + // Sort processes by arrival time + processes.sort((p1, p2) -> Integer.compare(p1.getArrivalTime(), p2.getArrivalTime())); + + int index = 0; + while (index < processes.size() || !queue.isEmpty()) { + // Add processes that have arrived to the ready queue + while (index < processes.size() && processes.get(index).getArrivalTime() <= currentTime) { + queue.add(processes.get(index)); + index++; + } + + if (!queue.isEmpty()) { + Process currentProcess = queue.poll(); + + // Execute the process for one time quantum (if it doesn't complete) + int remainingTime = currentProcess.getRemainingTime(); + int timeSlice = Math.min(timeQuantum, remainingTime); + currentProcess.executeFor(timeSlice); + currentTime += timeSlice; + + System.out.println("Process " + currentProcess.getId() + " executed for " + timeSlice + " units at time " + currentTime); + + if (currentProcess.isCompleted()) { + System.out.println("Process " + currentProcess.getId() + " ends at time " + currentTime); + } else { + queue.add(currentProcess); // Re-add process to the queue if not completed + } + } else { + currentTime++; // No process is ready, increment time + } + } + } +} \ No newline at end of file diff --git a/ProcessSchedulingSimulator/src/scheduler/Scheduler.java b/ProcessSchedulingSimulator/src/scheduler/Scheduler.java new file mode 100644 index 0000000..843bd46 --- /dev/null +++ b/ProcessSchedulingSimulator/src/scheduler/Scheduler.java @@ -0,0 +1,9 @@ +package scheduler; + +import model.Process; +import java.util.List; + +public interface Scheduler { + // Method to schedule processes based on the selected algorithm + void schedule(List processes); +} diff --git a/ProcessSchedulingSimulator/src/scheduler/ShortestJobFirstScheduler.java b/ProcessSchedulingSimulator/src/scheduler/ShortestJobFirstScheduler.java new file mode 100644 index 0000000..458b4d1 --- /dev/null +++ b/ProcessSchedulingSimulator/src/scheduler/ShortestJobFirstScheduler.java @@ -0,0 +1,88 @@ +package scheduler; + +import model.Process; +import simulation.SimulationMode; + +import java.util.List; +import java.util.PriorityQueue; + +public class ShortestJobFirstScheduler implements Scheduler { + + @Override + public void schedule(List processes) { + if (SimulationMode.PREEMPTIVE.equals(SimulationMode.PREEMPTIVE)) { + preemptiveSJF(processes); + } else { + nonPreemptiveSJF(processes); + } + } + + // Non-preemptive Shortest Job First Scheduling + private void nonPreemptiveSJF(List processes) { + processes.sort((p1, p2) -> { + if (p1.getArrivalTime() != p2.getArrivalTime()) { + return Integer.compare(p1.getArrivalTime(), p2.getArrivalTime()); + } + return Integer.compare(p1.getBurstTime(), p2.getBurstTime()); + }); + + int currentTime = 0; + + for (Process process : processes) { + if (currentTime < process.getArrivalTime()) { + currentTime = process.getArrivalTime(); // Wait for process arrival + } + + System.out.println("Process " + process.getId() + " starts at time " + currentTime); + currentTime += process.getBurstTime(); // Execute the process + process.setRemainingTime(0); // Mark as completed + System.out.println("Process " + process.getId() + " ends at time " + currentTime); + } + } + + // Preemptive Shortest Job First Scheduling + private void preemptiveSJF(List processes) { + PriorityQueue pq = new PriorityQueue<>((p1, p2) -> { + if (p1.getRemainingTime() != p2.getRemainingTime()) { + return Integer.compare(p1.getRemainingTime(), p2.getRemainingTime()); + } + return Integer.compare(p1.getArrivalTime(), p2.getArrivalTime()); + }); + + int currentTime = 0; + int completedProcesses = 0; + int totalProcesses = processes.size(); + + while (completedProcesses < totalProcesses) { + // Add all processes that have arrived by the current time to the priority queue + for (Process process : processes) { + if (process.getArrivalTime() <= currentTime && !pq.contains(process) && !process.isCompleted()) { + pq.offer(process); + } + } + + if (!pq.isEmpty()) { + Process currentProcess = pq.poll(); // Get the process with the shortest remaining time + + // If process starts execution + if (currentProcess.getRemainingTime() == currentProcess.getBurstTime()) { + System.out.println("Process " + currentProcess.getId() + " starts at time " + currentTime); + } + + // Execute the process for 1 time unit + currentProcess.executeFor(1); + currentTime++; + + if (currentProcess.isCompleted()) { + System.out.println("Process " + currentProcess.getId() + " ends at time " + currentTime); + completedProcesses++; + } else { + pq.offer(currentProcess); // Re-add the process with updated remaining time + } + } else { + // If no process is ready, move forward in time + currentTime++; + } + } + } +} \ No newline at end of file diff --git a/ProcessSchedulingSimulator/src/simulation/SimulationMode.java b/ProcessSchedulingSimulator/src/simulation/SimulationMode.java new file mode 100644 index 0000000..9914cb6 --- /dev/null +++ b/ProcessSchedulingSimulator/src/simulation/SimulationMode.java @@ -0,0 +1,6 @@ +package simulation; + +public enum SimulationMode { + PREEMPTIVE, // Preemptive scheduling (e.g., Round Robin) + NON_PREEMPTIVE // Non-preemptive scheduling (e.g., FCFS, SJF, Priority) +} diff --git a/ProcessSchedulingSimulator/src/simulation/Simulator.java b/ProcessSchedulingSimulator/src/simulation/Simulator.java new file mode 100644 index 0000000..197fe89 --- /dev/null +++ b/ProcessSchedulingSimulator/src/simulation/Simulator.java @@ -0,0 +1,52 @@ +package simulation; + +import model.Process; +import scheduler.*; + +import java.util.ArrayList; +import java.util.List; + +public class Simulator { + + private List processes; + private Scheduler scheduler; + private SimulationMode simulationMode; + + public Simulator() { + this.processes = new ArrayList<>(); + this.scheduler = null; + this.simulationMode = SimulationMode.NON_PREEMPTIVE; // Default to non-preemptive mode + } + + public void selectScheduler(String algorithm, boolean isPreemptive, int timeQuantum) { + switch (algorithm) { + case "FCFS": + scheduler = new FirstComeFirstServeScheduler(); + break; + case "SJF": + scheduler = new ShortestJobFirstScheduler(); + break; + case "Priority": + scheduler = new PriorityScheduler(); + break; + case "RoundRobin": + scheduler = new RoundRobinScheduler(timeQuantum); + break; + default: + throw new IllegalArgumentException("Unknown scheduling algorithm"); + } + } + + public void setSimulationMode(SimulationMode mode) { + this.simulationMode = mode; + } + + public void addProcess(Process process) { + processes.add(process); + } + + public void runSimulation() { + System.out.println("Running simulation in " + simulationMode + " mode...\n"); + scheduler.schedule(processes); + } +} \ No newline at end of file diff --git a/ProcessSchedulingSimulator/src/ui/SimulatorUI.java b/ProcessSchedulingSimulator/src/ui/SimulatorUI.java new file mode 100644 index 0000000..9ce4c2c --- /dev/null +++ b/ProcessSchedulingSimulator/src/ui/SimulatorUI.java @@ -0,0 +1,110 @@ +package ui; + +import simulation.*; +import model.Process; + +import java.util.Random; +import java.util.Scanner; + +public class SimulatorUI { + + private Simulator simulator; // The simulator instance + + // Constructor to initialize the simulator + public SimulatorUI() { + this.simulator = new Simulator(); + } + + // Method to display the menu for user interaction + public void displayMenu() { + System.out.println("=== CPU Scheduling Simulator ==="); + System.out.println("1. Select Scheduling Algorithm"); + System.out.println("2. Set Simulation Mode (PREEMPTIVE or NON_PREEMPTIVE)"); + System.out.println("3. Set Number of Processes"); + System.out.println("4. Run Simulation"); + System.out.println("5. Exit"); + } + + // Method to generate a list of processes for the simulation + private void generateProcesses(int numberOfProcesses) { + Random random = new Random(); + for (int i = 0; i < numberOfProcesses; i++) { + int arrivalTime = random.nextInt(10); // Random arrival time (0-9) + int burstTime = random.nextInt(10) + 1; // Random burst time (1-10) + int priority = random.nextInt(5) + 1; // Random priority (1-5) + Process process = new Process(i + 1, arrivalTime, burstTime, priority); // Process ID starts from 1 + simulator.addProcess(process); + System.out.println("Generated Process: " + process); + } + } + + // Method to get user inputs for the simulation + public void getUserInputs() { + Scanner scanner = new Scanner(System.in); + boolean running = true; + + while (running) { + displayMenu(); + System.out.print("Please select an option (1-5): "); + int choice = scanner.nextInt(); + + switch (choice) { + case 1: + // Select Scheduling Algorithm + System.out.println("Select Scheduling Algorithm (FCFS, SJF, Priority, RoundRobin): "); + String algorithm = scanner.next(); + int timeQuantum = 0; + boolean isPreemptive = false; // Default to non-preemptive + + if ("RoundRobin".equals(algorithm)) { + // Ask for time quantum when RoundRobin is selected + System.out.print("Enter time quantum for Round Robin: "); + timeQuantum = scanner.nextInt(); + } + + // Call selectScheduler with all required parameters + simulator.selectScheduler(algorithm, isPreemptive, timeQuantum); + break; + + case 2: + // Set Simulation Mode (PREEMPTIVE or NON_PREEMPTIVE) + System.out.println("Select Simulation Mode (PREEMPTIVE or NON_PREEMPTIVE): "); + String mode = scanner.next().toUpperCase(); + if ("PREEMPTIVE".equals(mode)) { + simulator.setSimulationMode(SimulationMode.PREEMPTIVE); + } else { + simulator.setSimulationMode(SimulationMode.NON_PREEMPTIVE); + } + break; + + case 3: + // Set Number of Processes + System.out.print("Enter the number of processes: "); + int numberOfProcesses = scanner.nextInt(); + generateProcesses(numberOfProcesses); // Generate random processes + break; + + case 4: + // Run Simulation + simulator.runSimulation(); + break; + + case 5: + // Exit + System.out.println("Exiting simulation..."); + running = false; + break; + + default: + System.out.println("Invalid choice. Please try again."); + break; + } + } + } + + // Method to start the UI (entry point for the program) + public static void main(String[] args) { + SimulatorUI ui = new SimulatorUI(); + ui.getUserInputs(); + } +} \ No newline at end of file