Giter Club home page Giter Club logo

Comments (3)

albertsgrc avatar albertsgrc commented on August 15, 2024

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?

from node-or-tools.

emakarov avatar emakarov commented on August 15, 2024

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?

from node-or-tools.

emakarov avatar emakarov commented on August 15, 2024

@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

from node-or-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.