Modeling Library Borrowing System and Testing with DEVSJAVA, Exams of Electrical and Electronics Engineering

The process of modeling a library borrowing system using devsjava, including the creation of atomic models for borrowers and observers, a librarybook model, and a booktest template for testing the librarybook implementation. The document also includes an example of a skier model and the use of observers to capture speed and distance. The goal is to create a test suite for any model that claims to correctly represent the required behavior.

Typology: Exams

Pre 2010

Uploaded on 08/26/2009

koofers-user-0zl
koofers-user-0zl 🇺🇸

4.5

(4)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 575 Final Exam Solutions
The exam consists of three problems, each worth 33 points. You may work in pairs.
There is no penalty for doing so. Each member of a team will receive the score of the
team.
Solutions are due December 5, 2003.
1. A library book is either on the shelf or not. If it is requested while the person
requesting has a borrowing privilege, and is on the shelf, then it is given to the borrower.
If it is requested and not on the shelf, the request is denied. Once borrowed, a schedule
of fines goes into effect as follows: If the book is returned within 30 days, a thank you
note is issued. If not returned within 30 days, a fine of 1 dollar a day starts accumulating.
There is a grace period of 15 days, so that if a book is returned within 45 days, the fine is
canceled but no thank you note is issued. After 45 days, the fine continues to accumulate
(and includes the grace period charges.). After 60 days have passed (from day of
borrowing) without return, however, the borrower’s library privilege is revoked.
Whenever the book is returned it goes back on the shelf within one day of its return. If a
fine is due, it continues to accumulate until paid (even if the book has been returned or
borrowing privilege revoked.)
One way this process can be modeled, but not the only way, is as a coupled model as
follows:
handle
request
&return
bookDue
Timer
payment
Due
Timer
handle
Payment
is started when the
book is borrowed and
continues ticking until
book is returned
is started when the
bookDuefTimer reaches 45
days, starts from 15 and
continues ticking until
payment is received or time
reaches 30 – when it
notifies the handlePayment
and then continues ticking
generates the
appropriate outputs
when either book is
requested or a book
is returned
generates appropriate
outputs when a payment
is received or
paymentDueTimer
reaces 60
request
return
pay
bookDue
denied
thankU
payDue
privilegeRevoked
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Modeling Library Borrowing System and Testing with DEVSJAVA and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

ECE 575 Final Exam Solutions The exam consists of three problems, each worth 33 points. You may work in pairs. There is no penalty for doing so. Each member of a team will receive the score of the team. Solutions are due December 5, 2003.

  1. A library book is either on the shelf or not. If it is requested while the person requesting has a borrowing privilege, and is on the shelf, then it is given to the borrower. If it is requested and not on the shelf, the request is denied. Once borrowed, a schedule of fines goes into effect as follows: If the book is returned within 30 days, a thank you note is issued. If not returned within 30 days, a fine of 1 dollar a day starts accumulating. There is a grace period of 15 days, so that if a book is returned within 45 days, the fine is canceled but no thank you note is issued. After 45 days, the fine continues to accumulate (and includes the grace period charges.). After 60 days have passed (from day of borrowing) without return, however, the borrower’s library privilege is revoked. Whenever the book is returned it goes back on the shelf within one day of its return. If a fine is due, it continues to accumulate until paid (even if the book has been returned or borrowing privilege revoked.) One way this process can be modeled, but not the only way, is as a coupled model as follows: handle request &return bookDue Timer payment Due Timer handle Payment is started when the book is borrowed and continues ticking until book is returned is started when the bookDuefTimer reaches 45 days, starts from 15 and continues ticking until payment is received or time reaches 30 – when it notifies the handlePayment and then continues ticking generates the appropriate outputs when either book is requested or a book is returned generates appropriate outputs when a payment is received or paymentDueTimer reaces 60 request return pay bookDue denied thankU payDue privilegeRevoked

Your task is not to construct this model, but to construct a test suite to test any model that claims to correctly represent the required behavior. The test suite is a collection of borrower models, each one able to interface with the book model and representing a different borrower behavior. Recall that ability to interface means that a borrower model has output ports that can be meaningfully coupled to input ports of the libraryBook model likewise, input ports that can receive inputs from libraryBook outputs (as shown below). request return pay libraryBook bookDue denied thankU payDue privilegeRevoked borrower request return pay bookDue denied thankU payDue privilegeRevoked For example, a punctualBorrower requests a borrowed book .and then returns it before the 30 day due date. At the other extreme, an inconsiderateBorrower never returns a borrowed book, never pays the fine, and even tries to borrow the book again. a) Define a ViewableAtomic model class, borrower , that has that has no features other than the input and output ports shown in the above figure. Each specific borrower class will extend this class and thus have the right interface. b) Define a ViewableDigraph model class, libraryBook , that has no features other than the input and output ports shown in the figure. A specific libraryBook class (e.g., that I might insert), will extend this class and thus have the right interface. c) Define a ViewableDigraph model class, bookTest , that has a constructor with no arguments, as well as a constructor that has two arguments, taking instances of libraryBook , and borrower , classes (or their extensions), respectively. Define the coupling shown in the above figure, between the pair of model instances added into bookTest from the constructor arguments. In the zero-argument constructor, set the arguments of the two-argument constructor to instances of the base clases, libraryBook and borrower. You should be able to see the models and couplings in SimView. The two-argument constructor of bookTest can be used to test a libraryBook implementation with any specific borrower atomic model.

public bookTest(libraryBook book, borrower bor){ super("bookTest: " + book.getName() + " and " + bor.getName()); this.add(book); this.add(bor); addCoupling(book, libraryBook.DENIED_PT, bor, borrower.DENIED_PT); addCoupling(book, libraryBook.BOOK_DUE_PT, bor, borrower.BOOK_DUE_PT); addCoupling(book, libraryBook.THANK_YOU_PT, bor, borrower.THANK_YOU_PT); addCoupling(book, libraryBook.PAY_DUE_PT, bor, borrower.PAY_DUE_PT); addCoupling(book, libraryBook.PRIVILEGE_REVOKED_PT, bor, borrower.PRIVILEGE_REVOKED_PT); addCoupling(bor, borrower.REQUEST_PT, book, libraryBook.REQUEST_PT); addCoupling(bor, borrower.RETURN_PT, book, libraryBook.RETURN_PT); addCoupling(bor, borrower.PAY_PT, book, libraryBook.PAY_PT); } } This template is instantiated by actual examples of libraryBook and borrower subclasses.

  1. The following figure shows experimental frame elements to observe, record, and display properties of motion in one dimension. They receive real values of speed and position (displacement) on corresponding input ports, vin and pin. These values are non- negative. We’ll need these components for the example below where a skier is speeds down a mountain slope and then stops somewhere in the flat plane at the bottom of the hill. The displacement is measured from the skier’s starting position with the the positive direction pointing down the slope. .As in slalom skiing, flags are placed at equal distances, q down the slope.

dv/dt = f(p,v)   p^ dp/dt = v f(p,v) v The instantaneous function, f in the above figure, is described as follows. f(p,v) = 0, if v < 0 (the acceleration is turned off as soon as the skier stops). For v>= 0, f(p,v) is only a function of p and it gives the acceleration that the skier experiences in each segment of the course. Segments are the regions between successive flags and are assumed to be straight lines of length, q, with specified slopes. This means that the acceleration can be assumed to be constant in each segment. In the first segment the slope is 0 and the acceleration is due to the skier’s use of his poles to start off. In the last segment that stretches to infinity, the acceleration is negative as the skier uses a constant friction force to stop. In each interior segment, the acceleration is positive (it depending on its slope, but we will not need to say how). a) If, as in the figure, the hill is represented by 7 segments, and the corresponding accelerations are a1, a2,…, a7, write the mathematical description of f(p,v): f(p,v) = 0 if v < 0 // this is needed to all the skier to stop without then reversing direction =a1 if 0 < p< q and v >= = a2 if q <= p< 2q and v >= = a3 if 2q <= p< 3q and v >= = a4 if 3q <= p< 4q and v >= = a5 if 4q <= p< 5q and v >= = a6 if 5q <= p< 6q and v >= = a7 if p >= 6q and v >=

b) Modify secondOrderSys and associated class files to model the skier using the above description, where the parameters, L (total length between first and last flags) and a1, a2, …, a7, are given through a constructor. c) Form a model-frame pair by coupling the obsExp of problem 2 with the coupled model in 3 b). Simulate the model with parameters L = 70, and a1 = 1, a2 = 3, a3 = 2, a4 = 3, a = 2, a6 = 1, a7 = -3. Then simulate again with the same parameters except for switching the values of a1 and a3 – this corresponds to the skier making a faster start and then using less acceleration later on so that his total energy input is the same. Do both simulations produce the same finish times as measured by the obsExp? If so, explain why. If not, which is faster and why? (Hint: look at the output of the speed observer.)  pf(p,v) v pin vin (^) speed observer time observer vout tout pin vin (^) distance observer pout pin L vout pout vin pin L tout pout vout From Robinson Cruso Marri and Deepak Bharadwaj: The model-frame pair is a coupling between exp frame expObs (prob 2) and the model coupledskier (prob 3b). This model was simulated with the given parameters with L= 70, a1=1, a2=3, a3=2, a4=3, a5=2, a6=1, a7=-3. The finish time observed with these parameters was t = 9.8s. The total distance measured by Dobs was 100.296. The model was again simulated with the new parameters where a1 and a3 were exchanged with L= 70, a1=2, a2=3, a3=1, a4=3, a5=2, a6=1, a7=-3. The finish time observed with these parameters was t = 8.2s. The total distance measured by Dobs was 100.326. The outputs of the Sobs in both cases are given below for analysis Distance Speed(a1=1,a3=2) Speed(a1=2,a3=1) 10 4.511 6. 20 8.976 10. 30 10.982 10.

Let’s use vT as the speed threshold. Assume that the skier reduces his accelerations so that his speed is always less than or equal to vT and he doesn’t fall. Then his finish time must equal or exceed L/ vT. We can first look at an ideal (but impossible case) and then look at an optimal strategy. If we assume that the skier is capable of instantaneously reaching speed vT, then we could construct a flat slope (0 acceleration) and the skier would travel the entire slope at speed vT and would complete the course in L/ vT seconds. In fact, we cannot instantaneously speed up. Assume that we must employ constant accelerations within segments as above. Consider the following strategy: We use a constant acceleration in the first segment to reach vT at the end of it. The average speed on this stretch will be vT /2 and the time to travel that distance will be (L/6)/( vT /2) or 2L/6 vT. The other 5 segments will use zero acceleration to keep the speed from exceeding vT /2 and they will each be traveled in time (L/6)/ vT or L/6 vT. The total time to travel all 6 segments would then be 7L/6 vT or (7/6)(L/ vT). This is the fastest travel time possible without a fall being detected. If we try to use a higher acceleration in the first segment, the velocity will reach the threshold and there is no way of keeping it from exceeding the threshold. This is only possible by reaching the threshold at the end of the first segment and then reducing the acceleration to zero at the beginning of the next segment. So we can call this the “push as hard as you can and then coast” strategy – and it corresponds to what skiers and bob-sleders do.