Hi I use JuMP and CPLEX solver to solve the optimization problem in time-space network. I write this code to the JuMP with the data. I tried to model network design model in time-space network.
using JuMP, CPLEX, DataFrames, CSV, GLPK
node = [11,12,13,14,15,16,41,42,51]
time = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168]
graph = DataFrames.DataFrame(
[
11 41 6 6 12 101.74 74.19 2380 1
11 41 6 12 18 101.74 74.19 2380 1
11 41 6 18 24 101.74 74.19 2380 1
11 41 6 24 30 101.74 74.19 2380 1
11 41 6 30 36 101.74 74.19 2380 1
11 41 6 36 42 101.74 74.19 2380 1
11 41 6 42 48 101.74 74.19 2380 1
11 41 6 48 54 101.74 74.19 2380 1
11 41 6 54 60 101.74 74.19 2380 1
11 41 6 60 66 101.74 74.19 2380 1
I skipped the data because of the row limitation to create this topic. However there are 2269 rows in total.
51 51 6 144 150 1 0 100 Inf
51 51 6 150 156 1 0 100 Inf
51 51 6 156 162 1 0 100 Inf
51 51 6 162 168 1 0 100 Inf
51 51 6 168 6 1 0 100 Inf
],
["origin", "destination", "time", "start", "finish", "distance", "fc", "vc", "cap"],
)
com = DataFrames.DataFrame(
[
11 12 490 6 30
11 13 52 36 84
11 14 5 54 126
11 15 52 66 144
11 16 233 78 138
12 11 3195 36 66
12 13 4128 24 72
12 14 343 12 42
12 15 2321 84 156
12 16 2739 18 48
13 11 1186 78 120
13 12 5032 24 72
13 14 924 24 54
13 15 5334 90 144
13 16 1286 60 108
14 11 68 6 54
14 12 206 84 126
14 13 332 36 90
14 15 283 30 54
14 16 69 84 114
15 11 966 48 84
15 12 4030 96 144
15 13 5815 30 78
15 14 653 60 120
15 16 1083 48 126
16 11 1083 6 60
16 12 2339 96 138
16 13 475 84 150
16 14 47 72 132
16 15 368 84 114
],
["origin", "destination", "demand", "arrive", "due"],
)
numlink = length(graph.origin)
numnode = length(node)
numcom = length(com.origin)
numtime = length(time)
demandori = Tuple((Int64(com.origin[i]),Int64(com.arrive[i])) for i in 1:numcom)
demanddes = Tuple((Int64(com.destination[i]),Int64(com.due[i])) for i in 1:numcom)
links = Tuple(((Int64(graph.origin[i]),Int64(graph.start[i])), (Int64(graph.destination[i]),Int64(graph.finish[i]))) for i in 1:numlink)
translinks = Tuple(((Int64(graph.origin[i]),Int64(graph.start[i])), (Int64(graph.destination[i]),Int64(graph.finish[i]))) for i in 1:numlink if graph.origin[i] != graph.destination[i])
nodes = Tuple((node[i], time[t]) for i in 1:numnode, t in 1:numtime)
udict = Dict((links[i]=>graph.cap[i]) for i in 1:numlink)
fcdict = Dict((links[i]=>graph.fc[i]) for i in 1:numlink)
vcdict = Dict((links[i]=>graph.vc[i]) for i in 1:numlink)
disdict = Dict((links[i]=>graph.distance[i]) for i in 1:numlink)
model = direct_model(CPLEX.Optimizer())
variables(model, begin
y[translink in translinks], Int
x[k in 1:numcom, link in links] >= 0
end)
objective(model, Min, sum(fcdict[translink]*y[translink] for translink in translinks) + sum(vcdict[link]*disdict[link]*x[k,link] for k in 1:numcom, link in links))
constraint(model, [k in 1:numcom, (i,t) in nodes; i==com.origin[k] && t==com.arrive[k]], sum(x[k,((ii,tt),(j,tp))] for ((ii,tt),(j,tp)) in links if ii==i && tt==t) - sum(x[k,((j,tp),(ii,tt))] for ((j,tp),(ii,tt)) in links if ii==i && tt==t) == com.demand[k])
constraint(model, [k in 1:numcom, (i,t) in nodes; i==com.destination[k] && t==com.due[k]], sum(x[k,((ii,tt),(j,tp))] for ((ii,tt),(j,tp)) in links if ii==i && tt==t) - sum(x[k,((j,tp),(ii,tt))] for ((j,tp),(ii,tt)) in links if ii==i && tt==t) == -com.demand[k])
constraint(model, [k in 1:numcom, (i,t) in nodes; (i,t)!=demandori[k] && (i,t)!=demanddes[k]], sum(x[k,((ii,tt),(j,tp))] for ((ii,tt),(j,tp)) in links if ii==i && tt==t) - sum(x[k,((j,tp),(ii,tt))] for ((j,tp),(ii,tt)) in links if ii==i && tt==t) == 0)
constraint(model, [translink in translinks], sum(x[k,translink] for k in 1:numcom) <= udict[translink]*y[translink])
#println(model)
optimize!(model)
println(solution_summary(model))
println(objective_value(model))
for translink in translinks
if value.(y[translink]) > 0
println("y $translink = ", value.(y[translink]))
end
end
for k in 1:numcom
for link in links
if value.(x[k,link]) > 0
println("x $k $link = ", value.(x[k,link]))
end
end
end
It needs very long time for CPLEX to display something (the log)/load the model/problem (around 30 minutes). But after the model/problem can be loaded, it solved in short time.
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de2ae
Tried aggregator 1 time.
Reduced MIP has 9576 rows, 70056 columns, and 198576 nonzeros.
Reduced MIP has 0 binaries, 2016 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.11 sec. (41.62 ticks)
Tried aggregator 1 time.
Detecting symmetries...
Reduced MIP has 9576 rows, 70056 columns, and 198576 nonzeros.
Reduced MIP has 0 binaries, 2016 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.13 sec. (69.18 ticks)
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 8 threads.
Root relaxation solution time = 0.20 sec. (105.24 ticks)
Root node processing (before b&c):
Real time = 0.73 sec. (366.76 ticks)
Parallel b&c, 8 threads:
Real time = 0.00 sec. (0.00 ticks)
Sync time (average) = 0.00 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.73 sec. (366.76 ticks)
1.213043 seconds (1.16 M allocations: 58.671 MiB, 36.04% compilation time)
CPLEX Error 1217: No solution exists.
CPLEX Error 1217: No solution exists.
* Solver : CPLEX
* Status
Result count : 1
Termination status : OPTIMAL
Message from the solver:
"integer optimal, tolerance"
* Candidate solution (result #1)
Primal status : FEASIBLE_POINT
Dual status : NO_SOLUTION
Objective value : 1.81111e+10
Objective bound : 1.81110e+10
Relative gap : 2.96865e-06
Dual objective value : 1.81110e+10
* Work counters
Solve time (sec) : 7.52000e-01
Simplex iterations : 0
Barrier iterations : 0
Node count : 0
Apologize for long code in the data. I just want to show how big the data I inputted to the JuMP and CPLEX. Hope anyone could help me with this problem. Thank you in advanced.