Skip to content

Pack constraint strange behavior #2087

@AntonisKl

Description

@AntonisKl

Hello, I want to use the Pack() function (https://developers.google.com/optimization/reference/python/constraint_solver/pywrapcp#pack_1) of the Routing solver.

I read the documentation and I wrote some code based on the basic VRP example (https://developers.google.com/optimization/routing/vrp#entire_program1) to test this function.

In the above VRP example, I just added the following code before the solver starts to search for a solution:

    solver = routing.solver()

    all_vars_to_pack = [solver.IntVar(0,2,"a"), solver.IntVar(0,2,"a")]

    for var in all_vars_to_pack:

        routing.AddToAssignment(var)

    pack_constraint = solver.Pack(all_vars_to_pack2)

    usage_vars = [solver.IntVar(4,4,"a"), solver.IntVar(4,4,"a")]

    for var in usage_vars:

        routing.AddToAssignment(var)

    pack_constraint.AddSumVariableWeightsLessOrEqualConstantDimension(usage_vars, [35])

    solver.Add(pack_constraint)

The problem is this: When the program is executed, I see that it packed both of the items (quantity 4+4=8) in the 2nd bin which is not feasible because the capacity of the 2nd bin is 5.

My questions are the following:

  1. Is there a way to avoid the mixing of items?

  2. Are there any examples of how to properly use the Pack class and Pack() function while trying to solve a VRP?

Metadata

Metadata

Assignees

Labels

BugLang: PythonPython wrapper issueSolver: RoutingUses the Routing library and the original CP solver

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions