# -*- coding: utf-8 -*-
"""Created on Wed Jul 1 12:24:37 2020@author: AtticusYuan"""
from gurobipy import *
import numpy as np
import pandas as pd
import math
import random
import time
def read_txt_data(DataPath):
"""读取数据.读取Li & Lim's PDPTW benchmark 的txt文件格式的数据.参数----------arg1 : intarg1的具体描述arg2 : intarg2的具体描述返回值-------int返回值的具体描述参看--------otherfunc : 其它关联函数等...示例--------示例使用doctest格式, 在`>>>`后的代码可以被文档测试工具作为测试用例自动运行>>> a=[1,2,3]>>> print [x + 3 for x in a][4, 5, 6]"""
# 读取车辆信息
VehiclesInfo=pd.read_table(DataPath,nrows=1,names=['K','C','S'])
#print('VehiclesInfo:')
#print(VehiclesInfo)
Vehicles={}
for i in range(VehiclesInfo.iloc[0,0]):
Vehicles[i]=[VehiclesInfo.iloc[0,1],VehiclesInfo.iloc[0,2]] # 键i=车辆的序号,值为[车辆容量、速度]
#print(Vehicles)
# 读取Depot和任务信息
ColumnNames=['TaskNo','X','Y','Demand','ET','LT','ST','PI','DI']
TaskData=pd.read_table(DataPath,skiprows=[0],names=ColumnNames,index_col='TaskNo')
#print('TaskData:')
#print(TaskData)
# 提取Depot和取送货点(Customer)的位置坐标 Locations
nrows=TaskData.shape[0]
Locations={}
for i in range(nrows):
if i not in Locations.keys():
Locations[i]=[TaskData.iloc[i,0],TaskData.iloc[i,1]] # 键为depot或客户编号,值为相应的坐标(x,y)
#print('Locations:',Locations)
# 提取Depot和取送货点的Demand
Demand={}
for i in range(nrows):
if i not in Demand.keys():
Demand[i]=TaskData.iloc[i,2]
#print('Demand',Demand)
# 提取Depot和取送货点的最早和最晚取送货时间及时间窗
TimeWindow={}
EarliestTime=TaskData.sort_values(by='ET').iloc[0,3]
LatestTime=TaskData.sort_values(by='LT',ascending=False).iloc[0,4]
for i in range(nrows):
if i not in TimeWindow.keys():
TimeWindow[i]=[TaskData.iloc[i,3],TaskData.iloc[i,4]]
# print('TimeWindow',TimeWindow)
# print('EarliestTime:',EarliestTime)
# print('LatestTime:',LatestTime)
# 提取Depot和取送货点的服务时间ServiceTime
ServiceTime={}
for i in range(nrows):
if i not in ServiceTime.keys():
ServiceTime[i]=TaskData.iloc[i,5]
#print('ServiceTime',ServiceTime)
# 提取运输Request
# 对于取货任务,PICKUP索引为0,而同一行的DELIVERY索引给出相应送货任务的索引
Request={}
count = 0 # 记录运输需求的数量
for i in range(1,nrows-1):
if TaskData.iloc[i,6] == 0:
Request[count]=[i,TaskData.iloc[i,7]] # 将取送货点组合在一起,键为co