Code Monkey home page Code Monkey logo

clp's Introduction

clp

Go Reference 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 https://pkg.go.dev/github.com/lanl/clp.

Legal statement

Copyright © 2011, Triad National Security, LLC. All rights reserved.

This software was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of Energy/National Nuclear Security Administration. All rights in the program are reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration. The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so. NEITHER THE GOVERNMENT NOR TRIAD NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.

clp is provided under a BSD 3-clause license. See the LICENSE file for the full text.

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

Author

Scott Pakin, [email protected]

clp's People

Contributors

spakin avatar jonreiter avatar dprime avatar

Stargazers

Yusuke Saito avatar 鱼の乐 avatar Yuri Dias avatar Wito Chandra avatar Muz avatar Gábor Nagymajtényi avatar  avatar Nathan Yee avatar Jer avatar Phillip Epstein avatar Noah-Jerome Lotzer avatar Kobi Felton avatar Emanuel Freitas avatar Rodrigo Marques avatar Hossein Albakri avatar Will McGhee avatar  avatar Paul Saikko avatar Abhijith Gopakumar avatar sykzhong avatar  avatar DravenLu avatar  avatar Luis Alejandro Smith avatar Samuel Edley avatar Denis Titusov avatar Joel Pettersson avatar Jeffrey English avatar Eric Jacobsen avatar Jonathan Hendler avatar  avatar jyob avatar chenhua avatar Justin Cohler avatar  avatar Isaac Zhou avatar MISUMI Masaru avatar  avatar Venkata Sri Harsha P avatar Matthew Green avatar Joshua K avatar abdul dakkak avatar Harald Held avatar Doug Richardson avatar

Watchers

 avatar James Cloos avatar Harald Held avatar Jeffrey English avatar Nathan Delgado avatar  avatar  avatar

clp's Issues

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 Clp@master
./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.

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.

how changes lp problem?

Hi,
is it possible to get reduced cost?
And, changes the lp problem, such as add(delete) rows or columns?

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

signal arrived during cgo execution

ClpSimplex.cpp:3702: bool ClpSimplex::createRim(int, bool, int): Assertion `fabs(obj[i]) < 1.0e25' failed.
SIGABRT: abort
PC=0x7f0499a5be2c m=8 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1317 [syscall]:
runtime.cgocall(0xc0d57f0, 0xc006e0d668)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc006e0d640 sp=0xc006e0d608 pc=0x43553dc
github.com/lanl/clp._Cfunc_simplex_primal(0x7f044c001030, 0x0, 0x0)
        _cgo_gotypes.go:516 +0x4c fp=0xc006e0d668 sp=0xc006e0d640 pc=0xbd4d72c
github.com/lanl/clp.(*Simplex).Primal(...)
        /opt/tiger/compile_path/pkg/mod/github.com/lanl/[email protected]/simplex.go:236

What's the problem?

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

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.