2 %> Transform a
transhipment problem into a problem in standard form. Section 22.1 of \cite Bier15-book
7 %> @author Michel Bierlaire
8 %> @date Sat Apr 11 11:48:27 2015
12 %> Transform a
transhipment problem with m nodes and n arcs into a problem in standard form
13 %> @param adj the adjacency matrix of the network (dim m x m)
14 %> @param cost the cost vector (dim n)
15 %> @param lb the vector of lower bounds (dim n)
16 %> @param ub the vector of upper bounds (dim n)
17 %> @param supply the vector of supply (dim m)
18 %> @
return [tadj,tcost,tsupply] transformed adjacency matrix, transformed cost, transformed supply
20 addpath(
"../chap21") ;
23 narcs = max(max(adj)) ;
24 if (columns(adj) != nnodes)
25 error(
"Adjacency matrix must be square") ;
27 if (length(cost) != narcs)
28 error(
"cost vector has incorrect size") ;
30 if (length(lb) != narcs)
31 error(
"lb vector has incorrect size") ;
34 if (length(ub) != narcs)
35 error(
"ub vector has incorrect size") ;
38 if (length(supply) != nnodes)
39 error(
"supply vector has incorrect size") ;
42 if (sum(supply) != 0.0)
43 error(
"Infeasible supply/demand vector. Must sum up to 0") ;
48 tadj = zeros(narcs+nnodes,narcs+nnodes) ;
49 tsupply = [supply ; zeros(narcs,1)] ;
50 tcost = [cost ; zeros(narcs,1)] ;
52 # transform first the lower bounds to 53 # zero using the change of variable 54 # where x is replaced by x - lb 61 # Insert the artificial nodes and 62 # artificial arcs for the slack 65 tadj(nnodes+m,j) = m ;
66 tadj(nnodes+m,i) = narcs + m ;
67 tsupply(nnodes+m) = ub(m) ;
function transhipment(in adj, in cost, in lb, in ub, in supply, in useGlpk)
Solve the transhipment problem with bound constraints.
function prepareNetwork(in adj)
Identifies the upstream and downstream nodes of each arc.