Here is my dat file
data
param n := 5;
param demand :=
1 80
2 70
3 120
4 150
5 100;
param cost_cleaning := 0.50; # Set the actual cleaning cost here
param cost_new := 0.75; # Set the actual cost of buying new napkins here
param cost_stock := 0.10; # Set the actual cost of storing napkins here
here is my mod file
param n; # Number of days
set Days := 5;
param demand{Days};
param cost_cleaning;
param cost_new;
param cost_stock;
param initial_stock := 100; # Initial stock of napkins
var x{Days} >= 0; # Number of napkins bought on each day
var y{Days} >= 0; # Number of napkins cleaned on each day
var s{Days} >= 0; # Number of napkins kept in stock after each day
# Objective function: Minimize the total cost
minimize TotalCost:
cost_new * sum {d in Days} x[d] +
cost_cleaning * sum {d in Days} y[d] +
cost_stock * sum {d in Days} s[d];
subject to DemandConstraint {d in Days}:
s[d] + initial_stock + x[d] = demand[d] + y[d];
# The number of napkins in stock cannot be negative
s.t. NonNegativeStock {d in Days}:
s[d] >= 0;
# Variables representing buying and cleaning cannot be negative
s.t. NonNegativeBuys {d in Days}:
x[d] >= 0;
s.t. NonNegativeCleaning {d in Days}:
y[d] >= 0;
# Solve the LP model
data SAHC-hw4.dat;
option solver cplex;
solve;
display x;
display y;
display s;
display TotalCost;
i keep getting this error
n is already defined
context: param >>> n; <<< # Number of days
ampl:
please help me ASAP
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/7eda80b1-8a04-4142-94bd-b1bd11c2a2efn%40googlegroups.com.
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
Mod file
param d{1..n}; # 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;
I am still not getting the desired result and I do not know what is going wrongsyntax error
context: >>> param <<< demand{DAYS}; # Demand for napkins on each day
ampl:
Here is my mod file:
reset;
set Days # Define the set of days
param demand{DAYS}; # Demand for napkins on each day
param cost_cleaning; # Cost per napkin for cleaning
param cost_purchase; # Cost per napkin for purchasing
param cost_stock; # Cost per napkin for stock
param initial_stock; # Initial stock of napkins
var buy{DAYS} >= 0; # Number of napkins to purchase on each day
var clean{DAYS} >= 0; # Number of napkins to send for cleaning on each day
var stock{DAYS} >= 0; # Number of napkins to stock for each day
minimize TotalCost:
sum {d in DAYS} cost_cleaning * clean[d] + cost_purchase * buy[d] + cost_stock * stock[d];
subject to StockBalance {d in DAYS}:
stock[d] = (initial_stock + buy[d] - clean[d]) - demand[d];
option solver cplex;
data SAHC-hw4.dat;
solve;
display buy;
display clean;
display stock;
Here is my dat file:
set DAYS := 1 2 3 4 5;
param demand :=
1 80
2 70
3 120
4 150
5 100;
param cost_cleaning := a; # Replace with the actual cost per napkin for cleaning
param cost_purchase := b; # Replace with the actual cost per napkin for purchasing
param cost_stock := c; # Replace with the actual cost per napkin for stock
param initial_stock := 100; can you please help me so that i can solve the napkin problem?