set D := {1, 2, 3, 4};
param d :=
1 80
2 70
3 120
4 150
5 100;
param a := 1; # Cost per napkin for cleaning
param b := 2; # Cost per napkin for buying new napkins
param c := 0.5; # Cost per day for storing clean napkins
param stock_init := 100; # Initial number of napkins in stock
param D := {1, 2, 3, 4};; # Number of napkins needed each day
param a; # Cost per napkin for cleaning
param b; # Cost per napkin for buying new napkins
param c; # Cost per day for storing clean napkins
param stock_init; # Initial number of napkins in stock
var Buy{1..n} integer >= 0; # Number of napkins bought each day
var Clean{1..n} integer >= 0; # Number of napkins cleaned each day
var Stock{0..n} integer >= 0; # Number of napkins in stock at the end of each day
minimize sum(i in 1..n, a*Clean[i] + b*Buy[i] + c*Stock[i]);
subject to NapkinBalance{i in 1..n}:
Stock[i-1] + Buy[i] + Clean[i] = d[i] + Stock[i];
subject to StockInit: Stock[0] = stock_init;
solve;
for i in 1..n do
printf "Day %d: Buy %d, Clean %d, Stock %d\n", i, Buy[i], Clean[i], Stock[i];
endfor;
This .dat and .mod file is not giving me the desired output. I do not know if the mod file is the issue or the dat file. I am trying to find the optimal solution based on these conditions. For each of the next 5 days you know how many napkins you’ll need: 80, 70, 120, 150, 100, respectively. Each morning when delivering your napkins, you can pick up the used ones (what you delivered previous day). If you send those (or some of those) for a cleaning (for $a/napkin) than they can be used as new ones at the next morning delivery. You can also buy new napkins at $b/napkin any given day, before you make the deliveries for that day. You can also keep clean (new) napkins in your stock for $c/day/napkin for following days. Initially you have 100 napkins in stock.
I was expecting the optimal solution, based on those constraints
There are multiple errors in the model but it is not far from solving the problem. The main issues were the following:
set D := {1, 2, 3, 4};, but it is not used anywhere.n. You needparam n;.minimize Cost: ...;).data;section.Clean[i]so it could take any value and would be the cheapest option.Solving the model below:
you should get the following optimal solution: