Generate multidict using for loop in Gurobi
AnsweredI would like to generate multidict in Gurobi.
inputs:
from gurobipy import *
number_of_vehicles = 2
vehicles_origin = [4, 6]
vehicles_destination = [3, 0]
total_time_vehicle = [35, 27]
I would like to add this input to multidict in Gurobi using for loop.
output:
truck, starting_node, destination_nodes, time =
multidict({0:[4,3,(35)],1:[6,0,(27)]})
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
The multidict function generates multiple dictionaries out of a single larger dictionary data. You can construct the dictionaries via \(\texttt{for}\)-loops
from gurobipy import *
number_of_vehicles = 2
vehicles_origin = [4, 6]
vehicles_destination = [3, 0]
total_time_vehicle = [35, 27]
truck = [i for i in range(number_of_vehicles)]
starting_node = {}
destination_nodes = {}
time = {}
for i in truck:
starting_node[i] = vehicles_origin[i]
destination_nodes[i] = vehicles_destination[i]
time[i] = total_time_vehicle[i]If you insist on using the multidict function, you can pre-construct the larger dictionary
multi = {}
for i in range(number_of_vehicles):
l = [vehicles_origin[i],vehicles_destination[i],total_time_vehicle[i]]
multi[i] = l
truck, starting_node, destination_nodes, time = multidict(multi)Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments