Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

El-Shorouk Academy Acad.

Year :

Higher Institute for Computer & Term : First

Information Technology Year : 3rd

Department of Computer sciences

Instructor : Dr.farouk shaaban

Computer modeling & simulation

➔ Example No 3 :
➢ A news boy buys paper for 15 P.T. each and sells them for 25 P.T. each unsold
papers have no value in analyzing past sells it is found that three demand
distribution exist, depending on news events in the papers. A good
interesting news day yield to many potential customer, typical and poor days
yield to less interest. Historically 20% of days have been “poor”, 50%
“typical”, 30% “good”, The demand distributions are summarized :

Types of new days

Demand Poor Typical Good


40 0.05
50 0.2 0.03
60 0.41 0.07
70 0.26 0.28
80 0.08 0.3 0.02
90 0.25 0.15
100 0.07 0.28
110 0.24
120 0.12
130 0.09
140 0.06
150 0.04

➢ Simulate 10 days period and determine main daily profit, max profit, min
profit if he decides to buy 80 papers each day. Use the following R.N :-
09 65 69 66 57 64 84 24 92 22 49 50 61 01 45 48 48 45 52
35
?? Implement c# program to simulate this problem ??

Page 1 of 4

Types of new days

Demand Poor 00 --> 19 Typical 20 --> 69 Good 70 --> 99


40 0.05 00 --> 04
50 0.2 05 --> 24 0.03 00 --> 02
60 0.41 25 --> 65 0.07 03 --> 09
70 0.26 66 --> 91 0.28 10 --> 37
80 0.08 92 --> 99 0.3 38 --> 67 0.02 00 --> 01
90 0.25 68 --> 92 0.15 02 --> 16
100 0.07 93 --> 99 0.28 17 --> 44
110 0.24 45 --> 68
120 0.12 69 --> 80
130 0.09 81 --> 89
140 0.06 90 --> 95
150 0.04 96 --> 99

- Note : We have two digit random numbers that means that range of numbers 00 →99
- Poor take numbers from 00 → 19
- Typical take numbers from 20 → 69
- Good take numbers from 70 → 99
➔ 80 paper each day → Max buy 80 paper per day
➔ Note: we take 2 Random number first one to determine the type of new day , The
second one to determine demand “ how much he sell in that day “.

1st Day :
RN =09 → Poor
RN= 65 → demand = 60
Profit = 60*25 – 80*15 = 300 P.T

2nd Day :
RN= 69 → Typical
RN = 66 →demand = 80

Page 2 of 4
Profit = 80*25 – 80*15 = 800 P.T

3rd Day :
RN = 57 → Typical
RN = 64 → demand = 80
Profit = 80*25 – 80*15 = 800 P.T

4th Day :
RN= 84 → Good
RN =24 → demand = 100 = 80 → because max of buy is 80 paper each day
Profit = 80*25 – 80*15 = 800 P.T ; we calculate with demand 80 NOT 100.

5th Day :
RN= 92 → Good
RN = 22→ demand = 100 = 80 → because max of buy is 80 paper each day
Profit = 80*25 – 80*15 = 800 P.T ; we calculate with demand 80 NOT 100.

6th Day :
RN= 49 → Typical
RN =50 → demand = 80
Profit = 80*25 – 80*15 = 800 P.T

7th Day :
RN= 61 → Typical
RN= 01 → demand = 50
Profit = 50*25 – 80*15 = 50 P.T

8th Day :
RN = 45 → Typical
RN= 48 → demand = 80
Profit = 80*25 – 80*15 = 800 P.T

9th Day :
RN = 48 → Typical
RN= 45 → demand = 80
Profit = 80*25 – 80*15 = 800 P.T

10th Day :
RN= 52 → Typical
RN= 35 → demand = 70
Profit = 70*25 – 80*15 = 550 P.T

Page 3 of 4
• MIN profit we found it in 7th day which is 50 P.T
• MAX profit is 800 P.T
• Main daily profit
300+800+800+800+800+800+50+800+800+550/10=650 PT

Page 4 of 4
El-Shorouk Academy

Higher Institute for Computer & Term : First

Information Technology Year : 3rd

Department of Computer sciences

Instructor : Dr.farouk shaaban

Traffic lights

➢ Use the one-digit Random Number (6, 3, 5, 0, 8) to


generate random observations for:

a) The color of a traffic found by a randomly arriving car


when it is green 50% of the time, yellow 10% of the time,
and red 40% of the time.

?? Implement c# program to simulate this problem ??

Page 1 of 3
Answer

It is given that :-

The theoretical probability of :

Green 50% = 0.5

Yellow 10% = 0.1

Red 40% =0.4

Random numbers that are one-digit are from 0 -------> 9 [ten integer numbers].

• Then let the random numbers that indicate to green are five numbers (50%)
,say : 0-1-2-3-4
• the random number that indicate to yellow is one number which is: 5
• , and the random numbers that indicate to red are the remaining four numbers
which are: 6-7-8-9

G -----> 0, 1, 2, 3,4 0.5

Y -----> 5 0.1

R -----> 6, 7, 8, 9 0.4

Then:-

(6, 3, 5, 0, 8 ) -------Random observations---------> (R, G, Y, G, R )

Error = Theoretical Probability - Simulated Probability * 100


Theoretical Probability

Simulated Probability = no. of repeating / no. of trials.

Page 2 of 3
Simulated probability of Green = 2/5 = 0.4
Simulated probability of Red = 2/5 = 0.4
Simulated probability of yellow = 1/5 = 0.2

Error of Green = 0.5 – 0.4 * 100 = 20 %


0.5

Error of Yellow = 0.1 – 0.2 * 100 = 100 %


0.1

Error of Red = 0.4 – 0.4 * 100 = 0 %


0.4

Conclusion :-

• Error of Green is 20% which means that the simulated probability of RED
decreased by 20 % because the theoretical probability = 0.5 then after compute
simulated probability it become = 0.4 then it decreased ( 0.5 → 0.4 ) , means also the
simulated probability is less than the theoretical probability.

• Error of YELLOW is 100% which means that the simulated probability of RED
increased by 100 % because the theoretical probability = 0.1 then after compute
simulated probability it become = 0.2 then it increased ( 0.1 → 0.2 ) , means also the
simulated probability is greater than the theoretical probability.

• Error of Red is 0% which means that the simulated probability is EQUAL to


the theoretical probability.

Page 3 of 3

You might also like