npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@revolugo/ortools

v1.0.4

Published

Nodejs bindings for or-tools

Downloads

4

Readme

@revolugo/ortools

Build Status Dependency Status MIT Licensed

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.

Supported features

The following OR-Tools C++ Library values, classes and methods are supported.

note : corresponding javascript class methods are camelCase-d (e.g. makeIntVar())

MPSolver

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()

MPVariable

Methods:
MPVariable::Name()
MPVariable::solution_value()

MPConstraint

Methods:
MPConstraint::SetCoefficient()

MPObjective

Methods:
MPObjective::SetCoefficient()
MPObjective::SetMaximization()
MPObjective::SetMinimization()
MPObjective::Value()

Installation

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:

  • Ubuntu 16.04, 18.04
  • CentOS 7
  • Debian 9
  • Mac OS X

Usage

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 }!`)
  }
})();