/* Stock model in Picat. From http://www.mai.liu.se/~olbur/kurser/NMAB18/labinfo_1.pdf (AMPL model, Swedish) ["Lager" is the Swedish word for "stock"] This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> TT = 3,% num time periods InitStock = 5, % initial stock C = [25, 36, 30], % production cost L = [4, 3, 5], % stock cost D = [10, 15,12], % demand U = [20, 16, 10], % production capacity % num manufactured units X = new_list(TT), X :: 0..1000, % num units in stock % Note: The indices are really 0..T so we have % to tweak at little below. Y = new_list(TT+1), % 0..T Y :: 0..1000, Z #= sum ([ C[T-1]*X[T-1] + L[T-1]*Y[T] : T in 2..TT+1]), foreach(T in 2..TT+1) Y[T-1] + X[T-1] #= D[T-1] + Y[T] end, Y[1] #= InitStock, foreach(T in 1..TT) X[T] #<= U[T] end, Vars = X ++ Y, solve($[min(Z)],Vars), println(z=Z), println(x=X), println(y=Y), nl. go => true.