[AMPL 24814] Can someone please help me model this in AMPL?

Please help me with this assignment:

It is December 2023, and you are doing vacation work at Roofers SA PTY Limited, a South African industry specialising in the manufacturing of roof tiles. You have been assigned to optimise the production of their black ceramic roof tile product on one of their production lines. This product is sold in batches of 13 tiles, covering one square meter and weighing 48 kg.
Roofers SA can operate either a normal, 8-hour shift or an extended, 12-hour shift for a month at a time. An 8-hour shift costs R100 000 per month and can produce up to 6 000 batches per month. A 12-hour shift costs R150 000 per month and can produce up to 8 000 batches per month. The company can also choose not to produce any black ceramic tiles for a month, in which case there is no shift cost. (If the production line is not used for this product, it can be used by other teams to manufacture other products.) Raw materials for one batch cost R0.50. If production exceeds 7 000, an additional team needs to be deployed to help out at an additional cost of R30 000. If the company produces anything in a particular month, it must produce at least 2 000 batches.
Changing from an 8-hour shift in one month to a 12-hour shift in the next month costs an additional 000 in setup costs. Changing from a month where there was no production to a month where there is production incurs an additional R25 000 setup cost extra cost is incurred in changing from a 12-hour shift in one month to an 8-hour shift in the next month or changing from a month of production to no production in the following month. Currently, the production line for this product is operating a normal shift.
Holding stock is risky because it can get stolen and costs R2 per batch per month. Assume the cost of inventory for any particular month is related to the amount in stock at the end of that month. There are currently 850 batches in stock, and the inventory cost for the current stock does not need to be taken into consideration at the start of month 1. The amount in stock at the end of month 12 should be at least 3,000 units. The demand for the company’s product in each of the next 12 months is forecast to be as shown below:

Month 1: Demand is = 8 000
Month 2: Demand is = 6 500
Month 3: Demand is = 6 500
Month 4: Demand is = 2 100
Month 5: Demand is = 3 500
Month 6: Demand is = 6 500
Month 7: Demand is = 2 000
Month 8: Demand is = 6 800
Month 9: Demand is = 8 300
Month 10: Demand is = 8 000
Month 11: Demand is = 8 000
Month 12: Demand is = 2 000

Here is my attempt at modelling:

Define variables

var x{1…12} integer >= 0; # Number of batches produced in each month
var y binary; # 1 if an 8-hour shift is used in a month, 0 otherwise
var z binary; # 1 if a 12-hour shift is used in a month, 0 otherwise
var s binary; # 1 if no production is carried out in a month, 0 otherwise
var d{1…12} integer >= 0; # Demand for each month
var totalcost : integer;

Define constraints

subject to capacity {i in 1…12}: x[i] <= (6000y + 8000z); # Total number of batches produced in a month cannot exceed the maximum capacity of the production line
subject to team {i in 1…12}: x[i] <= 7000*(1-z) + (7000+3000s)(z); # If production exceeds 7000 batches per month, an additional team needs to be deployed at an additional cost of R30 000
subject to minimum {i in 1…12}: x[i] >= d[i]*(y+z+s); # The total number of batches produced in a month must be at least equal to the demand for that month
subject to stock {i in 1…11}: sum{j in 1…i} x[j] + 850 - sum{j in i+1…12} x[j] >= 3000; # The amount in stock at the end of month 12 should be at least 3000 units

Define objective function

minimize cost: totalcost;

data;

param d :=
1 8000
2 6500
3 6500
4 2100
5 3500
6 6500
7 2000
8 6800
9 8300
10 8000
11 8000
12 2000;

Calculate the objective function incrementally

let {
totalcost := sum (100000y + 150000z + (x[1]+850)2))12;
}
for {i in 2…12} {
let {
totalcost := (100000
y + 150000
z + (x[i]+850)2) + (15000abs(y-y[i-1]) + 25000sabs(z-z[i-1]) + (25000+25000*s)*abs(s-s[i-1]));
}
}

Solve the model

option solver cplex;
solve;

Display results

printf “Production schedule:\n”;
for {i in 1…12}
{
printf “Month %d: %d batches\n”, i, round(x[i]);
}
printf “Shift schedule:\n”;
printf “8-hour shift: %d months\n”, round(y);
printf “12-hour shift: %d months\n”, round(z);
printf “No production: %d months\n”, round(s);
printf “Total Cost: %d\n”, round(total_cost);

Since this is an assignment, I cannot tell you exactly how to model it in AMPL. I can just give you some hints:

You should define d as a param, not as a var, since d refers to known data (the demands).

You need to define your variables y, z, and s for each month, such as var y {1…12} binary.

Everywhere that you use y, z, or s, it must have a “subscript”; for example, in the constraint “capacity”, you would have x[i] <= (6000y[i] + 8000z[i]).

You cannot use “let” statements to define an objective function. You should write the expression for the objective function in the “minimize” statement. For example,

minimize cost: (100000*y[1] + 150000*z[1] + (x[1]+850)*2)*12 +
   sum {i in 2..12} 
      ((100000*y[i] + 150000*z[i] + (x[i]+850)*2) + 
      (15000*abs(y[i]-y[i-1])) + 
      (25000*s[i]*abs(z[i]-z[i-1])) + 
      (25000+25000*s[i]*abs(s[i]-s[i-1])));

I cannot tell you whether this is exactly the right expression for the objective, however. You will have to figure that out from the problem description.

Thank so much!