Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fairness - balance number of locations serviced per vehicle #1

Open
daniel-j-h opened this issue Apr 18, 2017 · 3 comments
Open

Fairness - balance number of locations serviced per vehicle #1

daniel-j-h opened this issue Apr 18, 2017 · 3 comments

Comments

@daniel-j-h
Copy link
Contributor

We want to be able to balance the number of locations serviced by each vehicle to be as even as possible. The use-case is for example drivers who are getting paid (at least partially) by number of deliveries.

This constraint should be behind a flag and optional.


Implementation: use the underlying solver to

  • Establish a vehicle vars <-> vehicle counts relationship via the Distribute constraint
  • Add a Deviation constraint for vehicle counts targeting the deviation var
  • Minimizing the deviation var

Roughly as follows:

std::vector<IntVar*> vehicleCounts;

for (auto vehicle = 0; vehicle < numVehicles; ++vehicle)
  vehicleCounts.push_back(solver->MakeIntVar(0, numNodes));

solver->AddConstraint(solver->MakeDistribute(vehicleVars, vehicleCounts));

auto* deviationVar = solver->MakeIntVar(0, numNodes * numNodes);

solver->AddConstraint(solver->MakeDeviation(vehicleCounts, deviationVar, numNodes));

model.AddVariableMinimizedByFinalizer(deviationVar);
@albertsgrc
Copy link

Hi @daniel-j-h,

I have tried implementing your solution and came up with the following code, very similar to yours:

// vehicleCounts[i] == # of nodes being serviced by vehicle i
std::vector<operations_research::IntVar*> vehicleCounts;
// vehicleVars[i] == vehicle attending node i
std::vector<operations_research::IntVar*> vehicleVars;

for (auto vehicle = 0; vehicle < numVehicles; ++vehicle) {
    vehicleCounts.push_back(solver->MakeIntVar(0, numNodes));
}

for (auto node = 0; node < numNodes; ++node) {
    vehicleVars.push_back(model.VehicleVar(model.NodeToIndex((NodeIndex)(node))));
}

// Definition of vehicleCounts
solver->AddConstraint(solver->MakeDistribute(vehicleVars, vehicleCounts));

// Holds deviation from ideally balanced route assignment
auto* deviationVar = solver->MakeIntVar(0, numNodes * numNodes);

// Definition of the deviation from the ideally balanced route assignment
solver->AddConstraint(solver->MakeDeviation(vehicleCounts, deviationVar, numNodes));

// Minimize the deviation
model.AddVariableMinimizedByFinalizer(deviationVar);

model.CloseModel();

I more or less understand the meaning of the constraints and how they work together with the minimisation rule to implement the balancing but I am clearly missing something, as the solutions are still unbalanced, with some vehicles being unused. Do you have any idea on how to get it working?

@emakarov
Copy link

hi all. I'm also interested in such model. But I'm not totally sure that proposed approach will work.
Because, AddVariableMinimizedByFinalizer is working "after" solution is found, not during the search process. In this case I assume it cannot change the solution dramatically.
What were the assumptions that such approach will lead to required distribution?

@emakarov
Copy link

@albertsgrc could you check whether following approach will work:

  1. You create a solution with your existing model, add deviationVar to the assignment (if its possible) and check its' value when solution is found
  2. By some technic, for example incrementally decreasing the Max value (horizon) for deviationVar domain, try to find another solution. And with several iterations compare solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants