CSC 421/621, Fall 2022, Assignment 5
handed out Oct. 26, due Nov. 16 at 11:59pm on Canvas Problem 1 (Standard ML) [40 marks]
Remember our good friend from Assignments a and 2? The store management problem? Well, in case you forgot, it is repeated below! This time, guess what? You have to write a program to solve it, but in Standard ML.
Note about problems 1: Inputting data to a program may be difficult in Standard ML. You can try, but if you are having trouble with that, you can feel free to hardcode the data in those languages (but build dynamic data structures as if the data was continuously coming). You will not lose points for hardcoding the input.
Problem 2 (Standard ML versus Scheme) [10 marks]
Standard ML (or SML or, simply, ML) is a functional language, just like Scheme. However, it has many features that Scheme doesn’t have. Based on your experience writing the same program in Scheme and in ML, please contrast the two languages. Which one do you prefer? Why?
Detailed description of the programming problem:
The manager of a store needs to keep track of the people who interact with the business—employees and customers. Three types of information are stored about each person: the person’s ID, Salary, and Year of Birth. Please note that Salary refers to either the employee’s salary (earned in the store) or the customer’s salary (earned outside the store). Aside from these three pieces of information common to all people, employees have one more piece of information stored about them: the number of days of missed work. Similarly, customers have a list of purchases associated with them, which lists the purchase number and the total price of the purchase. Finally, the store’s monthly operating expenses (costs of renting the premises, purchasing the inventory, and other costs) is also given.
The purpose of the program is to extract specific information from the database:
• Whether the store is in the black (profit) or in the red (deficit)
if ([(∑ Customers’ purchases) – (∑ Employees’ salaries + Overhead)] > 0) then black else red
• Whether age1 and salary2 are factors in:
o The way customers spend money.
-
Age/Salary
Low
High
Young
Avg(expenses of younger
Avg(expenses of younger
customers with low
customers with high
salaries)
salaries)
Old
Avg(expenses of older
Avg(expenses of younger
customers with low
customers with high
salaries)
salaries)
-
The number of missed days of work.3
-
Young (> 1982) or Old (<= 1982)
-
Low (< $8,000/month) or High (>= $8,000/month)
-
Output the average spending and average missed days for each of the 4 age/salary combinations
-
Age/Salary
Low
High
Young
Avg(missed days of work
Avg(missed days of work
of younger employees
of younger customers with
with low salaries)
high salaries)
Old
Avg(missed days of work
Avg(missed days of work
of older customers with
of younger customers with
low salaries)
high salaries)
-
The names of:
-
The greatest spender!
Name of the customer whose sum of purchases exceeds every other customer’s.
-
The greatest work skipper!
Name of the employees who missed the greatest number of days
Please test your programs on the following input, which represents a month of activity:
Overhead (at the beginning of the month): $20,000
Employees:
Ann: ID: 1; YOB: 2000; Salary: $3,000/month; Missed_Days: 20 Bob: ID: 2; YOB: 1970; Salary: $10,000/month; Missed_Days: 25 Cathy: ID: 3; YOB: 1960; Salary: $8,000/month; Missed_Days: 5 Darren: ID: 4; YOB: 1995; Salary: $5,000/month; Missed_Days: 12 Customers:
Eva: ID: 5; YOB: 1984; Salary: $12,000/month; Purchases: [(Purchase_numb: 1; Price: $600),
(Purchase_numb: 6, Price: $1200), (Purchase_numb: 12; Price: $370)]
Florence: ID: 6; YOB: 1968; Salary: $4,000/month; Purchases: [(Purchase_numb: 2; Price: $900),
(Purchase_numb: 3, Price: $2000)]
Gerrald: ID: 7; YOB: 2001; Salary: $0/month; Purchases: [(Purchase_numb: 4; Price: $1200),
(Purchase_numb: 8, Price: $900), (Purchase_numb: 10; Price: $420)]
Henri: ID: 8; YOB: 1973; Salary: $2,000/month; Purchases: [(Purchase_numb: 5; Price: $3200)]
Isabelle: ID: 9; YOB: 1980; Salary: $9,000/month; Purchases: [(Purchase_numb: 7; Price: $850),
(Purchase_numb: 9, Price: $720), (Purchase_numb: 11; Price: $330)]
John: ID: 10; YOB: 1965; Salary: $11,000/month; Purchases: [(Purchase_numb: 7; Price: $850),
(Purchase_numb: 13, Price: $720), (Purchase_numb: 14; Price: $330)]
The purpose of this question is to introduce you to the R statistical programming language, with a particular emphasis on data modeling and analysis. This will be done, once again, in the context of a retail store, but the problem is different from the one you are already familiar with. We will focus on a store that sells three categories of items: toys, air conditioners and other home appliances. The question is divided in three parts. In the first part, you will use R to simulate the sales of these three categories of items according to the descriptions given for each, below. In the second part, you will use R to create an automatic ordering system that will trigger an order once the stock of each category of items falls below a given level. In the third part, you will generate an analysis of the sales, using various graphic tools available in R.
Part 1:
You are asked to generate a matrix listing the sales of each category of items on a monthly basis for a year. Your generation process needs to be general enough to be used over several numbers of years. E.g.:
2012 Sales |
January |
February |
March |
April |
… |
… |
… |
… |
December |
A/C |
3 |
7 |
2 |
1 |
… |
… |
… |
… |
… |
Appliances |
36 |
19 |
28 |
8 |
… |
… |
… |
… |
… |
Toys |
25 |
16 |
31 |
35 |
… |
… |
… |
… |
63 |
The sales of each category of items will be simulated using a Poisson distribution. However, seasonal and population information will be used to introduce monthly variations. We now describe the data distribution of each category of items.
Air conditioners:
From October to May, included, an average of 5 air conditioners are sold each month; in June, the number rises to 30; in July, to 45; in August, to 50; and in September, it falls back to 30. Use these averages in the Poisson distribution to generate the data randomly.
Home appliances:
In every year of our simulation, we simulate the average number of home appliances purchased each month using a uniform distribution in the range 10 to 40. These averages are used to generate the monthly number of sales, which are subsequently used in the Poisson distribution to generate random sales numbers.
Toys:
In the neighborhood around the store, the number of birthdays per month of kids aged 5 to 11 fluctuates according to a normal distribution centered at 30, with variance 9. Generate random numbers according to that distribution to simulate the number of toys bought on a regular basis at the store. Add a uniformly generated number between 100 and 200 to simulate the number of toys bought in November, and a uniformly generated number between 300 and 400 to simulate the number of toys bought in December, in preparation for Christmas.
Part 2:
Assume the following initial as well as minimum stock holdings for the different categories of goods:
Air conditioners:
January |
February |
March |
April |
May |
June |
July |
August |
September |
October |
10 |
10 |
10 |
10 |
10 |
30 |
50 |
50 |
30 |
10 |
November |
December |
||||||||
10 |
10 |
January |
February |
March |
April |
May |
June |
July |
August |
September |
October |
|
40 |
40 |
40 |
40 |
40 |
40 |
40 |
40 |
40 |
40 |
|
November |
December |
|||||||||
40 |
40 |
|||||||||
Toys: |
||||||||||
January |
February |
March |
April |
May |
June |
July |
August |
September |
October |
|
40 |
40 |
40 |
40 |
40 |
40 |
40 |
40 |
40 |
40 |
|
November |
December |
|||||||||
400 |
400 |
At the end of each month, calculate the new number of items in each category in stock and automatically generate an order to ensure that your stocks reach the minimum required in each category. Please make sure that you do not sell more merchandise than is actually available in stock. Assume that as soon as your order comes out, the stocks are filled again.
Please, run your simulation for one year and print the orders that were automatically filed at the end of each month.
Part 3:
Please, run your simulation for 3 years and plot the following figures:
-
Average your data over three years on a monthly basis, category by category. Plot the histogram for each category of items of these averages. Draw the density lines for these histograms.
-
On the same graph, plot the average sales of each category of items for each year. The x-axis will have three values: year1, year2, year3; the y-axis will record the total sales over year1, year2 and year3 of air conditioners, home appliances and toys, respectively. This means that the three line graphs in the figure should each have three points. Please label your graph appropriately.
-
Draw 12 pie charts showing the proportions of sales of each category of items on a monthly basis for year2. Label each chart appropriately (the month and year it represents should be clearly indicated, along with the category represented by each shaded area.
-
Draw three bar plots (one for each category of items) showing the sales of this category on a monthly basis. Each month should be represented by 3 bars: one for year1, one for year2 and one for year3. (i.e., there will be 12 groups of three bars (i.e., 36 bars)) on each graph
Write a report documenting what you have learned from the different graphs you have plotted.
Write lines of R code to answer the following questions:
-
For year 1 of your simulation, indicate what the greatest number of home appliances sold in a month was, and indicate the month when that happened.
-
For year 2 of your simulation, indicate the number of months where more than 50 toys were sold. What were these months and how many toys were cumulatively sold on these months.