Go language bindings for the COIN-OR Linear Programming library

Related tags

Mathematics clp
Overview

clp

GoDoc Go project version Go Report Card

Description

The clp package provides a Go interface to the COIN-OR Linear Programming (CLP) library, part of the COIN-OR (COmputational INfrastructure for Operations Research) suite.

Linear programming (LP) is a method for maximizing or minimizing a linear expression subject to a set of constraints expressed as inequalities. As an example that's simple enough to solve by hand, what roll of three six-sided dice has the largest total value if no two dice are allowed have the same value and the difference in value between the first and second largest dice must be smaller than the difference in value between the second and third largest dice? From an LP standpoint, the objective function we need to maximize to answer that question is a + b + c, where each variable represents the value on one die. The first constraint is that each die be six sided:

  • 1 ≤ a ≤ 6
  • 1 ≤ b ≤ 6
  • 1 ≤ c ≤ 6

The second constraint is that the three dice all have different values. We specify this by imposing a total order, a > b > c, which we express as

  • 1 ≤ a - b ≤ ∞
  • 1 ≤ b - c ≤ ∞

The third constraint is that the difference in value between the first and second largest dice (ab) is smaller than the difference in value between the second and third largest dice (bc). To put this in a suitable format for LP, we rewrite ab < bc as

  • -∞ ≤ a - 2b + c ≤ -1

These constraints translate directly to Go using the clp package's API:

package main

import (
        "fmt"
        "github.com/lanl/clp"
        "math"
)

func main() {
        // Set up the optimization problem.
        pinf := math.Inf(1)
        ninf := math.Inf(-1)
        simp := clp.NewSimplex()
        simp.EasyLoadDenseProblem(
                //         A    B    C
                []float64{1.0, 1.0, 1.0},
                [][2]float64{
                        // LB UB
                        {1, 6}, // 1 ≤ a ≤ 6
                        {1, 6}, // 1 ≤ b ≤ 6
                        {1, 6}, // 1 ≤ c ≤ 6
                },
                [][]float64{
                        // LB  A    B    C    UB
                        {1.0, 1.0, -1.0, 0.0, pinf},  // 1 ≤ a - b ≤ ∞
                        {1.0, 0.0, 1.0, -1.0, pinf},  // 1 ≤ b - c ≤ ∞
                        {ninf, 1.0, -2.0, 1.0, -1.0}, // -∞ ≤ a - 2b + c ≤ -1
                })
        simp.SetOptimizationDirection(clp.Maximize)

        // Solve the optimization problem.
        simp.Primal(clp.NoValuesPass, clp.NoStartFinishOptions)
        soln := simp.PrimalColumnSolution()

        // Output the solution.
        fmt.Printf("Die 1 = %.0f\n", soln[0])
        fmt.Printf("Die 2 = %.0f\n", soln[1])
        fmt.Printf("Die 3 = %.0f\n", soln[2])
}

The output is the expected

Die 1 = 6
Die 2 = 5
Die 3 = 3

Installation

clp has been tested only on Linux. The package requires a CLP installation to build. To check if CLP is installed, ensure that the following command produces a list of libraries, typically along the lines of -lClp -lCoinUtils …, and, more importantly, issues no error messages:

pkg-config --libs clp

Once CLP installation is confirmed, you're ready to install the clp package. As clp has opted into the Go module system, installation is in fact unnecessary if your program or package has done likewise. Otherwise, install the clp package with go get:

go get github.com/lanl/clp

Documentation

Pre-built documentation for the clp API is available online at http://godoc.org/github.com/lanl/clp, courtesy of GoDoc.

License

clp is provided under a BSD-ish license with a "modifications must be indicated" clause. See the LICENSE file for the full text.

This package is part of the LANL Go Suite, LA-CC-11-056.

Author

Scott Pakin, [email protected]

Issues
  • clp-interface.cxx:1:10: fatal error: 'coin/ClpSimplex.hpp' file not found

    clp-interface.cxx:1:10: fatal error: 'coin/ClpSimplex.hpp' file not found

    Hello, I downloaded the latest distribution of clp using coinbrew and the following script:

    wget https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
    chmod u+x coinbrew
    ./coinbrew fetch [email protected]
    ./coinbrew build Clp
    

    I have tried to download on both mac and linux. I have run into the following issue with the import in clp-interface.cxx in both systems:

    clp-interface.cxx:1:31: fatal error: coin/ClpSimplex.hpp: No such file or directory
     #include <coin/ClpSimplex.hpp>
    

    Here is what I have tried in both systems.

    Linux

    The README says the library has only been tested in linux. To try to find the location of the clp library:

    pkg-config --libs clp
    -L/home/luissmith/dist/lib -lClp
    

    If I try to find the ClpSimplex.hpp file on the machine, these are the results:

    find ~/ -type f -name ClpSimplex.hpp
    /home/luissmith/Clp/src/ClpSimplex.hpp
    /home/luissmith/dist/include/coin-or/ClpSimplex.hpp
    

    Is the issue related to the path in one of the newer distributions of CLP? I am realizing the path here is .../coin-or/ClpSimplex.hpp, whereas in the clp-interface.cxx it is looking for coin/ClpSimplex.hpp?

    I also needed to export the package path:

    export LD_LIBRARY_PATH="/home/luissmith/dist/lib/"
    export PKG_CONFIG_PATH="/home/luissmith/dist/lib/pkgconfig/"
    

    If i type the command clp in command line, the response is:

    Coin LP version devel, build Jul 26 2020
    Clp takes input from arguments ( - switches to stdin)
    Enter ? for list of commands or help
    

    Mac

    To try to find the location of the clp library:

    pkg-config --libs clp
    -L/usr/local/Cellar/clp/1.17.3/lib -L/usr/local/Cellar/coinutils/2.11.3/lib -lClpSolver -lClp -lCoinUtils -lbz2 -lz -framework Accelerate -lm
    

    If I try to find the ClpSimplex.hpp file on the machine, these are the results:

    find ~/ -type f -name ClpSimplex.hpp
    /Users/luissmith//dist/include/coin-or/ClpSimplex.hpp
    /Users/luissmith//Clp/src/ClpSimplex.hpp
    

    Is the issue related to the path in one of the newer distributions of CLP? I am realizing the path here is .../coin-or/ClpSimplex.hpp, whereas in the clp-interface.cxx file it is looking for coin/ClpSimplex.hpp?

    If i type the command clp in command line, the response is:

    Coin LP version 1.17.3, build Jul 19 2020
    Clp takes input from arguments ( - switches to stdin)
    Enter ? for list of commands or help
    

    Feedback

    I would really appreciate any tips you have on debugging what might be going wrong. And please let me know if you need any more information from me. Thanks.

    opened by smithla02 6
  • added two new, faster methods to create and load Simplex models

    added two new, faster methods to create and load Simplex models

    The main goals for these changes were to remove all possible usages of the c-malloc where possible to reduce lock contention inside malloc. We run thousands of these models per second across many cores and that contention was ruining our performance as every single model build had to contend on a single malloc lock, which while thread safe, is not quick.

    There are now added methods on the Simplex object and the PackedMatrix object (BufferColumn() and accompanying consolodation methods) and a new LoadProblemEfficient method on Simplex. These new methods are dangerous in that they pass Go memory into C land, which allows for the possibility for C to corrupt the memory of the running Go program. This is a trade-off between performance and safety and for our particular use case, it's one we're happy with and that gives good results.

    The buffered version of the PackedMatrix performs well over 50% faster with far fewer memory allocations in a straight line test for a reasonably sized problem (width & height > 100)

    opened by dprime 3
  • godoc not displaying package documentation due to unrecognized LICENSE

    godoc not displaying package documentation due to unrecognized LICENSE

    Hi team! Thank you for this package, looks like just what I was looking for.

    The godoc site for the package says:

    Documentation not displayed due to license restrictions. See our license policy.

    Looks like this is because the license has non-standard wording, and godoc now has a policy to only display docs for allowed licenses. Usually I would love to submit a pull request to fix, but licensing is up to the releasing authors/org. Do you think it would be possible to perhaps switch to one of the standard BSD N-clause licenses (perhaps with the government contract attribution in the README)?

    opened by yonch 2
  • methods to get and set iteration and time limits

    methods to get and set iteration and time limits

    adds wrappers for set/get max iterations and max seconds. along with tests. the wrappers work on any clpmodel while the tests run on just the simplex object.

    opened by jonreiter 2
  • fix and test DualRowSolution

    fix and test DualRowSolution

    correct both primal and dual row solution slice lengths to be "number of rows" instead of columns. and add a simple test for dual row solution as a sensitivity.

    opened by jonreiter 1
  • add SetDimensions

    add SetDimensions

    Add PackedMatrix.SetDimensions with error checking.

    Simplex.LoadProblem was not bounds-checking the constraint and objective function slices. In cases where these slices were too long this ran off the end of unsafe.Pointer arrays. Without SetDimensions there was no way to add empty rows at the bottom of a packedmatrix to get these sizes/lengths in line.

    opened by jonreiter 1
  • add basic test for simplex primal tolerances

    add basic test for simplex primal tolerances

    I don't really have a better test in terms of behaviour we were fixing as the models are quite verbose and distilling them down to a test case is not easy. This test verifies the round trip into the C++ lib and that it's at least setting the correct value.

    opened by dprime 1
  • symbol(s) not found for architecture x86_64

    symbol(s) not found for architecture x86_64

    hi, i am trying to run "go get github.com...." to install clp on my M1 macbook. however, it returns the following info:

    github.com/lanl/clp

    ld: warning: ignoring file /opt/homebrew/Cellar/clp/1.17.6/lib/libClpSolver.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 ld: warning: ignoring file /opt/homebrew/Cellar/coinutils/2.11.3/lib/libCoinUtils.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 ld: warning: ignoring file /opt/homebrew/Cellar/clp/1.17.6/lib/libClp.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 Undefined symbols for architecture x86_64: "ClpSimplex::dualRanging(int, int const*, double*, int*, double*, int*, double*, double*)", referenced from: _dual_ranging in _x005.o "ClpSimplex::loadProblem(CoinPackedMatrix const&, double const*, double const*, double const*, double const*, double const*, double const*)", referenced from: _simplex_load_problem in _x005.o "ClpSimplex::primalRanging(int, int const*, double*, int*, double*, int*)", referenced from: _primal_ranging in _x005.o "ClpSimplex::reducedGradient(int)", referenced from: _simplex_red_grad in _x005.o "ClpSimplex::dual(int, int)", referenced from: _simplex_dual in _x005.o "ClpSimplex::primal(int, int)", referenced from: _simplex_primal in _x005.o "ClpSimplex::barrier(bool)", referenced from: _simplex_barrier in _x005.o "ClpSimplex::ClpSimplex(bool)", referenced from: _new_simplex_model in _x005.o "ClpSimplex::~ClpSimplex()", referenced from: _free_simplex_model in _x005.o "CoinPackedMatrix::deleteCols(int, int const*)", referenced from: _pm_delete_cols in _x005.o "CoinPackedMatrix::setDimensions(int, int)", referenced from: _set_dimensions in _x005.o "CoinPackedMatrix::reserve(int, int, bool)", referenced from: _reserve in _x005.o "CoinPackedMatrix::appendCol(int, int const*, double const*)", referenced from: _pm_append_col in _x005.o "CoinPackedMatrix::CoinPackedMatrix()", referenced from: _new_packed_matrix in _x005.o "CoinMessageHandler::setLogLevel(int)", referenced from: _new_simplex_model in _x005.o "ClpModel::setMaximumSeconds(double)", referenced from: _set_max_seconds in _x005.o "ClpModel::setPrimalTolerance(double)", referenced from: _simplex_primal_set_tolerance in _x005.o "ClpModel::setMaximumIterations(int)", referenced from: _set_max_iterations in _x005.o "ClpModel::setOptimizationDirection(double)", referenced from: _simplex_set_opt_dir in _x005.o "ClpModel::scaling(int)", referenced from: _simplex_scaling in _x005.o "ClpModel::writeMps(char const*, int, int, double) const", referenced from: _write_mps in _x005.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation).

    what should I do now? thanks in advance.

    opened by mengxianye 1
  • exit status 3221225781

    exit status 3221225781

    I get the following error when I run the example code in Windows 10:

    $ go run main.go 
    # pkg-config --cflags  -- clp
    pkg-config: exit status 3221225781
    

    Go version: go1.16.3 windows/amd64

    opened by solanu 14
Owner
Los Alamos National Laboratory
Los Alamos National Laboratory
Sparse matrix formats for linear algebra supporting scientific and machine learning applications

Sparse matrix formats Implementations of selected sparse matrix formats for linear algebra supporting scientific and machine learning applications. Co

James Bowman 132 Jun 21, 2022
cartconvert is a package providing a set of cartography functions for the Go programming language

cartconvert - a cartography package This is the home of the cartconvert project. You can find it online at http://cartconvert.allowed.org/ Cartconvert

Johann Höchtl 31 Apr 4, 2022
Go bindings for fftw3

Go bindings for FFTW v3.2.2 Maintained by Jonathan Wills: [email protected] Feel free to email me patches, suggestions or bugs. FFTW homepage: htt

null 38 Nov 22, 2020
Parses the Graphviz DOT language in golang

Parses the Graphviz DOT language and creates an interface, in golang, with which to easily create new and manipulate existing graphs which can be writ

Walter Schulze 484 Jun 25, 2022
GNU GSL Statistics library (v1.15, GPLv3) implemented in Go

Statistics Pure Go implementation of the GSL Statistics library. For the API overview see Godoc. Why create this repository when there is also "github

grd 77 Nov 23, 2021
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Montana Flynn 2.5k Jun 26, 2022
Go Library [DEPRECATED]

Tideland Go Library Description The Tideland Go Library contains a larger set of useful Google Go packages for different purposes. ATTENTION: The cell

Tideland 194 May 27, 2022
Go library that makes it easy to work with physical types, e.g. distances, velocities and angles.

Units Use at your own risk Note that this library is NOT production ready. If you want to use it anyway, contributions and bug reports are welcome! Br

Sindre Røkenes Myren 20 Feb 24, 2022
high performance fixed decimal place math library for Go

Summary A fixed place numeric library designed for performance. All numbers have a fixed 7 decimal places, and the maximum permitted value is +- 99999

robert engels 285 Jun 21, 2022
Nomad Coin - Nomad Coin study

nomad_Coin nomad_Coin study 노마드코인 스터디 Rough 상수 및 변수 ** 상수선언 const name string =

LeeYongKyu 0 Feb 2, 2022
Open-in-linear - A tool provides a shortcut to opening a linear issue in the desktop app or browser

This tool provides a shortcut to opening a linear issue in the desktop app or browser.

John Pedrie 1 Jan 25, 2022
Simply realtime chia log analyzer for chia coin (XCH) farmers

Chia log analyzer Simply realtime chia log analyzer Howto run on Linux Download binary from the releases assets (chia-log-analyzer.go-linux-amd64 ) Yo

null 69 Apr 5, 2022
A rest-api that works with golang as coin portfolio

Koinfolio A rest-api that works with golang as coin portfolio Technical Details Golang/Gin is used as application framework MongoDB is database Usage

Kürşad BİLGİN 2 Jun 1, 2022
"We will game" blockchain featuring the "Willgame coin".

We will game "We will game" blockchain featuring the "Willgame coin". Our vision is to become the number one design company for play to earn decentral

Willis Ayres 2 Jan 2, 2022
Floppa programming language inspired by the brainf*ck programming language. Created just for fun and you can convert your brainf*ck code to floppa code.

Floppa Programming Language Created just for fun. But if you want to contribute, why not? Floppa p.l. inspired by the brainf*ck programming language.

null 18 Apr 26, 2022
T# Programming Language. Something like Porth, Forth but written in Go. Stack-oriented programming language.

The T# Programming Language WARNING! THIS LANGUAGE IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! Something like Forth a

T# 92 Jun 29, 2022
Yayx programming language is begginer friendly programming language.

Yayx Yayx programming language is begginer friendly programming language. What have yayx: Easy syntax Dynamic types Can be compiled to outhers program

null 1 Dec 27, 2021
Yayx programming language is begginer friendly programming language.

Yayx Yayx programming language is begginer friendly programming language. What have yayx: Easy syntax Dynamic types Can be compiled to outhers program

Yayx Programming Language 7 May 20, 2022
tiny linear interpolation library for go (factored out from https://github.com/sgreben/yeetgif)

piecewiselinear A tiny library for linear interpolation. O(log(N)) per evaluation for N control points. import "github.com/sgreben/piecewiselinear" Ge

Sergey Grebenshchikov 22 Mar 5, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Alex Palaistras 862 Jun 26, 2022
Vulkan API bindings for Go programming language

Golang Bindings for Vulkan API Package vulkan provides Go bindings for Vulkan — a low-overhead, cross-platform 3D graphics and compute API. Updated Oc

null 632 Jun 28, 2022
Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language.

cdp Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language. The bindings are generated

Mathias Fredriksson 614 Jun 22, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Alex Palaistras 861 May 31, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Alex Palaistras 862 Jun 26, 2022
Machine Learning libraries for Go Lang - Linear regression, Logistic regression, etc.

package ml - Machine Learning Libraries ###import "github.com/alonsovidales/go_ml" Package ml provides some implementations of usefull machine learnin

Alonso Vidales 193 Jun 23, 2022
Go implementation of BLAS (Basic Linear Algebra Subprograms)

Go implementation of BLAS (Basic Linear Algebra Subprograms) Any function is implemented in generic Go and if it is justified, it is optimized for AMD

Michał Derkacz 147 Jun 2, 2022
Sparse matrix formats for linear algebra supporting scientific and machine learning applications

Sparse matrix formats Implementations of selected sparse matrix formats for linear algebra supporting scientific and machine learning applications. Co

James Bowman 132 Jun 21, 2022
Dorival Pedroso 1.7k Jun 16, 2022
Sparse matrix formats for linear algebra supporting scientific and machine learning applications

Sparse matrix formats Implementations of selected sparse matrix formats for linear algebra supporting scientific and machine learning applications. Co

James Bowman 131 Jun 27, 2022