Пример #1
0
    def _set_capacity_dimension_constraints(
            self, data: VehicleRoutingProblemInstance, routing: RoutingModel,
            manager: RoutingIndexManager):

        if data.courier_capacities is None:
            return

        def demand_callback(index):
            node = manager.IndexToNode(index)
            return data.node_demands[node]

        capacity_callback = routing.RegisterUnaryTransitCallback(
            demand_callback)

        routing.AddDimensionWithVehicleCapacity(
            capacity_callback,
            0,  # waiting time
            data.courier_capacities,  # maximum distance per vehicle
            False,  # Force start cumul to zero.
            self.CAPACITY_DIMENSION_NAME)

        capacity_dimension = routing.GetDimensionOrDie(
            self.CAPACITY_DIMENSION_NAME)

        for courier_idx, start_utilization in enumerate(
                data.start_utilizations):
            node_idx = routing.Start(courier_idx)
            self._set_constraint_on_var(
                node_idx,
                TimeWindowConstraint(node=node_idx,
                                     is_hard=True,
                                     from_time=start_utilization,
                                     to_time=start_utilization),
                capacity_dimension)
Пример #2
0
def add_capacity_constraints(routing: pywrapcp.RoutingModel, data: dict,
                             demand_callback):
    """
    Add capacity constraints.
    """
    routing.AddDimensionWithVehicleCapacity(
        evaluator=demand_callback,
        slack_max=0,  # null slack
        # vehicle maximum capacities
        vehicle_capacities=data['vehicle_capacities'],
        fix_start_cumul_to_zero=True,  # start cumul to zero
        name='Capacity',
    )
Пример #3
0
def add_capacity_constraints(routing: pywrapcp.RoutingModel, data: dict,
                             demand_callback):
    """
    Add capacity constraints.
    """
    demand_callback_index = routing.RegisterUnaryTransitCallback(demand_callback)
    routing.AddDimensionWithVehicleCapacity(
        demand_callback_index,
        slack_max=0,  # null slack
        # vehicle maximum capacities
        vehicle_capacities=data['vehicle_capacities'],
        fix_start_cumul_to_zero=True,  # start cumul to zero
        name='Capacity',
    )
Пример #4
0
    def apply(self, solver: RoutingModel):
        """Vehicle's occupation is restricted based on demand"""

        callback_index = solver.RegisterUnaryTransitCallback(self._callback)
        solver.AddDimensionWithVehicleCapacity(
            evaluator_index=callback_index,
            slack_max=0,
            vehicle_capacities=[
                vehicle.capacity
                for vehicle in self.problem.vehicles.values()
            ],
            fix_start_cumul_to_zero=True,
            name='capacity_constraint'
        )
Пример #5
0
def add_capacity_constraints(
    routing: RoutingModel,
    manager: RoutingIndexManager,
    data: dict,
    demand_callback_index: int,
) -> None:
    """
    Add capacity constraints.
    """

    routing.AddDimensionWithVehicleCapacity(
        demand_callback_index,
        slack_max=0,  # null capacity slack
        vehicle_capacities=data['vehicle_capacities'],  # vehicle maximum capacities
        fix_start_cumul_to_zero=True,  # start cumul to zero
        name='Capacity',
    )
    def apply(self, manager: pywrapcp.RoutingModel,
              routing: pywrapcp.RoutingModel, data_model: DataModel):
        def demand_callback(from_index):
            """Returns the demand of the node."""
            # Convert from routing variable Index to demands NodeIndex.
            from_node = manager.IndexToNode(from_index)
            return data_model.demands[from_node]

        demand_callback_index = routing.RegisterUnaryTransitCallback(
            demand_callback)
        routing.AddDimensionWithVehicleCapacity(
            demand_callback_index,
            0,  # null capacity slack
            data_model.vehicle_capacities,
            True,  # start cumul to zero
            'Capacity')

        return routing
Пример #7
0
def add_capacity_constraints(
    routing: RoutingModel,
    manager: RoutingIndexManager,
    data: dict,
    demand_callback_index: int,
) -> None:
    """
	Since the capacity constraints involve 
	the weight of the load a vehicle is carrying
	a quantity that accumulates over the route
	we need to create a dimension for capacities
	"""
    routing.AddDimensionWithVehicleCapacity(
        demand_callback_index,
        slack_max=0,  # null capacity slack
        vehicle_capacities=data[
            'vehicle_capacities'],  # vehicle maximum capacities
        fix_start_cumul_to_zero=True,  # start cumul to zero
        name='Capacity',
    )