Coder Social home page Coder Social logo

rust-lp-modeler's Introduction

lp-modeler

MIT license Build Status Build status

A linear programming modeler written in Rust. This api helps to write LP model and use solver such as CBC, Gurobi, lp_solve, ...

This library is inspired by coin-or PuLP which provide such an API for python 2.x.

Usage

Dev in progress.

This version provide this DSL to make a LP Model :

use lp_modeler::problem::{LpObjective, Problem, LpProblem};
use lp_modeler::operations::{LpOperations};
use lp_modeler::variables::LpInteger;
use lp_modeler::solvers::{SolverTrait, CbcSolver};

let ref a = LpInteger::new("a");
let ref b = LpInteger::new("b");
let ref c = LpInteger::new("c");

let mut problem = LpProblem::new("One Problem", LpObjective::Maximize);

// Maximize 10*a + 20*b
problem += 10.0 * a + 20.0 * b;

// 500*a + 1200*b + 1500*c <= 10000
problem += (500*a + 1200*b + 1500*c).le(10000);
// a <= b
problem += (a).le(b);

let solver = CbcSolver::new();

match solver.run(&problem) {
Ok((status, res)) => {
    println!("Status {:?}", status);
        for (name, value) in res.iter() {
            println!("value of {} = {}", name, value);
        }
    },
    Err(msg) => println!("{}", msg),
}

This version are tested with Coinor-Cbc and Gurobi.

It is possible to export the model into the lp file format.

problem.write_lp("problem.lp") 

will produce :

\ One Problem

Maximize
  10 a + 20 b

Subject To
  c1: 500 a + 1200 b <= 10000
  c2: a - b <= 0

Generals
  a c b 

End

With this file, you can directly use it with a solver supporting lp file format :

  • open source solvers :
    • lp_solve
    • glpk
    • cbc
  • commercial solvers :
    • Gurobi
    • Cplex

Limitation

  • Use with CBC, Gurobi or GLPK for now
  • 'complex' algebra operations such as commutative and distributivity are under development

New features

0.3.1

  • Add distributive property (ex: 3 * (a + b + 2) = 3*a + 3*b + 6)
  • Add trivial rules (ex: 3 * a * 0 = 0 or 3 + 0 = 3)
  • Add commutative property to simplify some computations
  • Support for GLPK

0.3.0

  • Functional lib with simple algebra properties

Contributors

Todo

  • Config for lp_solve and CPLEX

Further work

  • it would be great to use some constraint for binary variable like
    • a && b which is the constraint a + b = 2
    • a || b which is the constraint a + b >= 1
    • a <=> b which is the constraint a = b
    • a => b which is the constraint a <= b
    • All these cases is easy with two constraints but more complex with expressions
    • ...

rust-lp-modeler's People

Contributors

jcavat avatar tvincent2 avatar

Watchers

 avatar  avatar

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.