# Assignment 5 - FSP and Java 1.The log-flume ride at a theme park operates as follows. This sequence is repeated forever. Once the log is empty it cleaned.

## Presentation on theme: "Assignment 5 - FSP and Java 1.The log-flume ride at a theme park operates as follows. This sequence is repeated forever. Once the log is empty it cleaned."— Presentation transcript:

Assignment 5 - FSP and Java 1.The log-flume ride at a theme park operates as follows. This sequence is repeated forever. Once the log is empty it cleaned before riders can embark. Riders then embark one by one until the log is full. The ride takes place and the log goes around the water track. When the ride is over the riders disembark one by one. A sample trace is shown below to illustrate. Here the log has 2 seats and four potential riders, r[1..4].

Assignment 5 - FSP and Java Complete the following FSP model of the log-flume ride for a log with 2 seats and four potential riders. set RIDERS = {r[1..4]} const SEATS = 2 LOG = (clean -> ride -> LOG). PASSENGER = (embark -> disembark -> PASSENGER). CONTROL = (..). ||LOGFLUME = (LOG ||RIDERS:PASSENGER ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}).

Assignment 5 - FSP and Java set RIDERS = {r[1..4]} const SEATS = 2 LOG = (clean -> ride -> LOG). PASSENGER = (embark -> disembark -> PASSENGER). CONTROL = (clean -> ENTER[0]), ENTER [i:0..SEATS]= ( when (i ENTER[i+1] | when (i==SEATS) ride -> EXIT), EXIT = EXIT[SEATS], EXIT[i:1..SEATS] = ( when (i>1) disembark -> EXIT[i-1] | when (i==1) disembark -> CONTROL). ||LOGFLUME = (LOG || RIDERS:PASSENGER ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}). 1.Solution

Assignment 5 - FSP and Java 2. Complete the Java template below thereby implementing the FSP model developed in (1). A sample output from the program is shown below:

Assignment 5 - FSP and Java 2.Solution class Control { private int seats=2; private int spaces=2; private boolean rideFinished=false; private boolean cleaned=false; public synchronized void embark(int id){ while (spaces==0 || !cleaned) try {wait();} catch(InterruptedException e){} spaces--; System.out.println("rider."+id+" enters log "); notifyAll(); }

Assignment 5 - FSP and Java 2.Solution public synchronized void disembark(int id){ while (!rideFinished) try {wait();} catch(InterruptedException e){} spaces++; rideFinished=true; System.out.println("rider."+id+" exits log"); notifyAll(); } public synchronized void clean(){ while (spaces!=seats) try {wait();} catch(InterruptedException e){} cleaned=true; rideFinished=false; System.out.println("\nLog cleaned"); notifyAll(); }

Assignment 5 - FSP and Java 2.Solution public synchronized void ride(){ while (spaces!=0) try {wait();} catch(InterruptedException e){} rideFinished=true; cleaned=false; System.out.println("Ride finished"); notifyAll(); }

Assignment 5 - FSP and Java 4. To restore order on the log-flume ride the management installs a ticket machine that issues tickets to passengers. Tickets are numbered in the range 1..MT. When ticket MT has been issued the next ticket to be issued is ticket number 1. The log-flume controller only allows passengers to enter in ticket number order. Complete the following FSP model and show that even when their entry priority is low meek passengers will still get a ride.

Assignment 5 - FSP and Java set Bold = {bold[1..2]} set Meek = {meek[1..2]} set RIDERS = {Bold, Meek} const SEATS = 2 const MT=4 range T = 1..MT LOG = (clean -> ride -> LOG). PASSENGER = (ticket[t:T] -> embark[t] -> disembark -> PASSENGER). TICKET =.. CONTROL = (..). ||LOGFLUME = (LOG ||RIDERS:PASSENGER || RIDERS::TICKET ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}) >>{Meek.embark[T]}. progress BOLD = {Bold.embark[T]} progress MEEK = {Meek.embark[T]} 4. continued

Assignment 5 - FSP and Java set Bold = {bold[1..2]} set Meek = {meek[1..2]} set RIDERS = {Bold, Meek} const SEATS = 2 const MT=4 range T = 1..MT LOG = (clean -> ride -> LOG). PASSENGER = (ticket[t:T] -> embark[t] -> disembark -> PASSENGER). TICKET=TICKET[1], TICKET[t:T]=(ticket[t] -> TICKET[t%MT+1]). 4. Solution

Assignment 5 - FSP and Java CONTROL = (clean -> ENTER[0][1]), ENTER [i:0..SEATS][t:T]= ( when (i ENTER[i+1][t%MT+1] | when (i==SEATS) ride -> EXIT[SEATS][t]), EXIT[i:1..SEATS][t:T] = ( when (i>1) disembark -> EXIT[i-1][t] | when (i==1) disembark -> clean -> ENTER[0][t]). ||LOGFLUME = (LOG ||RIDERS:PASSENGER || RIDERS::TICKET ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.cle an}) >>{Meek.embark[T]}. progress BOLD = {Bold.embark[T]} progress MEEK = {Meek.embark[T]} 4. Solution

Download ppt "Assignment 5 - FSP and Java 1.The log-flume ride at a theme park operates as follows. This sequence is repeated forever. Once the log is empty it cleaned."

Similar presentations