Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.8 kB · 73 lines
at develop
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374% 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 Periodsint: T; % Trucksint: 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 functionvar 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" ];%------------------------------------------------------------------------------%% DataT = 6;N = 4;Cost = [30, 27, 23, 20];Loads = [20, 18, 15, 13];Demand = [27, 11, 14, 19, 25, 22];Truck1 = 3;Truck2 = 4;