Coder Social home page Coder Social logo

rplex's Introduction

RPLEX

Rust bindings for CPLEX, an IP/MIP/QP solver from IBM. Currently highly experimental but working for IP/MIP problems.

[dependencies]
rplex = {version = "0.2", git = "https://github.com/emallson/rplex.git"} 

You must have CPLEX installed for RPLEX to work. The build script attempts to locate CPLEX automatically (and should do so assuming you've installed it at the usual location on Linux). CPLEX is not necessary to run a binary compiled with RPLEX; static linking is used.

Documentation

!!Warning!!

There is an issue with the var! macro which has not been resolved where it cannot distinguish between var!(lb <= name) and var!(name <= ub) shorthands (see #3). These will eventually be removed, but I no longer have a copy of CPLEX available to use in supporting RPLEX.

Example

fn lpex1() {
    // create a CPLEX environment
    let env = Env::new().unwrap();
    // populate it with a problem
    let mut prob = Problem::new(&env, "lpex1").unwrap();
    // maximize the objective
    prob.set_objective_type(ObjectiveType::Maximize).unwrap();
    // create our variables
    let x1 = prob.add_variable(var!(0.0 <= "x1" <= 40.0 -> 1.0)).unwrap();
    let x2 = prob.add_variable(var!("x2" -> 2.0)).unwrap();
    let x3 = prob.add_variable(var!("x3" -> 3.0)).unwrap();
    println!("{} {} {}", x1, x2, x3);

    // add our constraints
    prob.add_constraint(con!("c1": 20.0 >= (-1.0) x1 + 1.0 x2 + 1.0 x3)).unwrap();
    prob.add_constraint(con!("c2": 30.0 >= 1.0 x1 + (-3.0) x2 + 1.0 x3)).unwrap();

    // solve the problem
    let sol = prob.solve().unwrap();
    println!("{:?}", sol);
    // values taken from the output of `lpex1.c`
    assert!(sol.objective == 202.5);
    assert!(sol.variables == vec![VariableValue::Continuous(40.0),
                                    VariableValue::Continuous(17.5),
                                    VariableValue::Continuous(42.5)]);
}

(Translated from the CPLEX example code lpex1.c. Taken from an actual test)

License

IBM, CPLEX and associated items are (c) IBM.

Copyright (c) 2016, J. David Smith All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

rplex's People

Contributors

arbaart avatar emallson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rplex's Issues

Variable multiplications in constraints

I seem to understand that it is not possible to multiply decision variables within a constraint (e.g., x * y >= 1).

Please correct me if I am wrong (by showing me how), or consider adding such a feature.

Variables with only an upper bound

On line 334 a var! with only an upper bound is turned into a var! with 0.0 as its lower bound but infinity as its upper bound, not the provided upper bound:
($name:tt <= $ub:tt -> $obj:tt) => (var!(0.0 <= $name <= INFINITY -> $obj));

Surely this should be:
($name:tt <= $ub:tt -> $obj:tt) => (var!(0.0 <= $name <=$ub -> $obj));

Print incumbent solutions

Hi Johnathan, thank you for this repo.

I would like to print each feasible solution found by CPLEX, until the optimal one. Generally, it can be done by implementing the incumbent callback, as demonstrated by the examples mipex4.c and ilomipex4.cpp that comes with CPLEX.

How can I do it in rplex?

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.