微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

OR-tools:尽早到达

如何解决OR-tools:尽早到达

我正在尝试使用 Google OR-tools 解决 VRPTW,我希望车辆尽早到达客户处(但仍在时间窗口内)。目前我正在使用以下代码

    time = 'Time'
    routing.AddDimension(
       transit_callback_index,100000,# allow waiting time
       100000,# maximum time per vehicle
       False,# Don't force start cumul to zero.
       time)
    time_dimension = routing.GetDimensionorDie(time) 

    if "time_windows" in data:
                    for location_idx,time_window in enumerate(data['time_windows']):
                        if location_idx == data['depot']:
                            continue
                        index = manager.NodetoIndex(location_idx)
                        time_dimension.SetCumulVarSoftLowerBound(index,time_window[0],3000) # costs in case of early arrivals
                        time_dimension.SetCumulVarSoftUpperBound(index,time_window[1],4000) # costs in case of delays
                        # time_dimension.CumulVar(index).SetRange(time_window[0],time_window[1]) # In case of hard time-windows
    
    
                # Instantiate route start and end times to produce feasible times. Amd add vehicle costs plus minimize span vehicle is on the road
                for vehicle_id in range(data['num_vehicles']):
                    print(vehicle_id)
                    routing.AddVariableMinimizedByFinalizer(
                        time_dimension.CumulVar(routing.Start(vehicle_id)))
                    routing.AddVariableMinimizedByFinalizer(
                        time_dimension.CumulVar(routing.End(vehicle_id)))
                    routing.SetFixedcostOfVehicle(0 + vehicle_id * 50,vehicle_id)  # Add cost for vehicle
                    time_dimension.SetSpanCostCoefficientForVehicle(1000,vehicle_id)  # Minimize the span a vehicle is on the road

奇怪的是,如果我有超过 1 辆车(根据需要),路线确实会尽早开始。然而,对于一辆车,在时间窗口结束时为客户提供服务。一辆车出现这种情况的原因是什么,我该如何解决

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。