![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@revolugo/ortools
Advanced tools
A node.js wrapper for Google OR-Tools.
Current implementation only wraps integer programming necessary classes and methods. It exposes a Promise interface for the solver.solve()
method.
The following OR-Tools C++ Library values, classes and methods are supported.
note : corresponding javascript class methods are camelCase-d (e.g. makeIntVar()
)
Supported optimization problem type:
MPSolver::CBC_MIXED_INTEGER_PROGRAMMING
Methods:
MPSolver::Name()
MPSolver::NumVariables()
MPSolver::NumConstraints()
MPSolver::MakeIntVar()
MPSolver::MakeRowConstraint()
MPSolver::MakeMutableObjective()
MPSolver::Solve()
MPSolver::infinity()
MPSolver::wall_time()
MPSolver::iterations()
MPSolver::nodes()
Methods:
MPVariable::Name()
MPVariable::solution_value()
Methods:
MPConstraint::SetCoefficient()
Methods:
MPObjective::SetCoefficient()
MPObjective::SetMaximization()
MPObjective::SetMinimization()
MPObjective::Value()
npm install @revolugo/ortools --save
note: the package includes a script that detects your platform (OS/version) and downloads the right binaries and include files from Google OR-Tools repository releases. Building the module requires standard C/C++ build tools and zlib. Supported platforms are currently:
const ortools = require('@revolugo/ortools')
// Create the linear solver with the CBC backend.
const solver = new ortools.MPSolver('My solver', ortools.MPSolver.CBC_MIXED_INTEGER_PROGRAMMING)
// Create the variables x and y.
const x = solver.makeIntVar(0, solver.infinity(), 'x')
const y = solver.makeIntVar(0, solver.infinity(), 'y')
// Create a linear constraint, x + 7y <= 17.5.
const c0 = solver.makeRowConstraint(-solver.infinity(), 17.5)
c0.setCoefficient(x, 1)
c0.setCoefficient(y, 7)
// Create another linear constraint, x <= 3.5.
const c1 = solver.makeRowConstraint(-solver.infinity(), 3.5)
c1.setCoefficient(x, 1)
c1.setCoefficient(y, 0)
// Create the objective function, x + 10y.
const objective = solver.mutableObjective()
objective.setCoefficient(x, 1)
objective.setCoefficient(y, 10)
// We want the objective to be at a maximum value
objective.setMaximization()
// Try to find the best solution using solve()
// Returns mapped MPSolver::ResultStatus enum value
// ortools.MPSolver.RESULT_OPTIMAL
// ortools.MPSolver.RESULT_FEASIBLE
// ortools.MPSolver.RESULT_INFEASIBLE
// ortools.MPSolver.RESULT_UNBOUNDED
// ortools.MPSolver.RESULT_ABNORMAL
// ortools.MPSolver.RESULT_NOT_SOLVED
// ortools.MPSolver.RESULT_MODEL_INVALID
;(async () => {
const result = await solver.solve()
if (result === ortools.MPSolver.RESULT_OPTIMAL) {
console.log('Solution:')
console.log(`x = ${ x.solution_value() }`)
console.log(`y = ${ y.solution_value() }`)
console.log(`objective = ${ objective.value() }`)
}
else {
console.log(`Non optimal result ${ result }!`)
}
})();
FAQs
Nodejs bindings for or-tools
The npm package @revolugo/ortools receives a total of 0 weekly downloads. As such, @revolugo/ortools popularity was classified as not popular.
We found that @revolugo/ortools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.