1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker f2a1c4e389 Squashed 'software/mza/' content from commit f970a59b17
git-subtree-dir: software/mza
git-subtree-split: f970a59b177c13ca3dd8aaef8cc6681d83b7e813
2021-07-11 16:34:30 +10:00

74 lines
1.8 KiB
MiniZinc

% RUNS ON mzn20_fd
% RUNS ON mzn-fzn_fd
% RUNS ON mzn20_fd_linear
% RUNS ON mzn20_mip
%------------------------------------------------------------------------------%
% trucking.mzn
% Jakob Puchinger
% December 2007
% vim: ft=zinc ts=4 sw=4 et tw=0
% Original model comes from Peters Student Tim
% There are N Trucks which have to can be used in every time period,
% Each truck can transport a given Load of material.
% Each truck has an associated cost.
% In each time period a demand has to be fulfilled.
% Truck1 and Truck2 have some further constraints, disallowing
% them to be used more than once in consecutive or two consecutive time periods.
% The goal is to minimise the cost
%------------------------------------------------------------------------------%
% Time Periods
int: T;
% Trucks
int: N;
1..N: Truck1;
1..N: Truck2;
array[1..T] of int: Demand;
array[1..N] of int: Cost;
array[1..N] of int: Loads;
array[1..N, 1..T] of var 0..1: x;
constraint
forall(t in 1..T)(
sum(i in 1..N)( Loads[i] * x[i,t]) >= Demand[t]
);
constraint
forall(tau in 1..T-2)(
sum(t in tau..tau+2)( x[Truck1, t] ) <= 1
);
constraint
forall(tau in 1..T-1)(
sum(t in tau..tau+1)( x[Truck2, t] ) <= 1
);
solve minimize
sum(i in 1..N)(sum(t in 1..T )( Cost[i] * x[i,t] ));
% required for showing the objective function
var int: obj;
constraint
obj = sum(i in 1..N)(sum(t in 1..T )( Cost[i] * x[i,t] ));
output
[ "Cost = ", show( obj ), "\n" ] ++
[ "X = \n\t" ] ++
[ show(x[i, t]) ++ if t = T then "\n\t" else " " endif |
i in 1..N, t in 1..T ] ++
[ "\n" ];
%------------------------------------------------------------------------------%
% Data
T = 6;
N = 4;
Cost = [30, 27, 23, 20];
Loads = [20, 18, 15, 13];
Demand = [27, 11, 14, 19, 25, 22];
Truck1 = 3;
Truck2 = 4;