Skip to content

A C++ library for LP and MIP modeling which abstracts away CPLEX and Gurobi.

License

Notifications You must be signed in to change notification settings

ctriley/optimystic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

optimystic

A C++ library for LP and MIP modeling which abstracts away CPLEX and Gurobi.

Getting Started

You will need either a copy of CPLEX or Gurobi, and the corresponding license file. Please see CPLEX or Gurobi for instructions. If you are an academic, both companies provide free academic licenses.

Prerequisites

You will need cmake and c++ compiler which supports c++14.

To install them on macOS, I recommend installing homebrew.

xcode-select --install
brew install cmake

For Ubuntu/Debian

apt install build-essential
apt install cmake

Example Model

The following is an example of the syntax required to build a CPLEX or Gurobi model. This example was taken from the Gurobi Documentation, found here

int main() {
    Model model = Model();
    model.setLogFile("miplog1.log");

    // Create variables
    auto x = model.addVar(0.0, 1.0, 1.0, SOLVER_BINARY, "x");
    auto y = model.addVar(0.0, 1.0, 1.0, SOLVER_BINARY, "y");
    auto z = model.addVar(0.0, 1.0, 2.0, SOLVER_BINARY, "z");

    // Add constraint: x + 2 y + 3 z <= 4
    std::vector<double> coeffs1 = {1.0, 2.0, 3.0};
    std::vector<std::shared_ptr<Variable>> variables1 = {x, y, z};
    model.addConstr(variables1, coeffs1, SOLVER_LESS_EQUAL, 4.0, "c0");

    // Add constraint: x + y >= 1
    std::vector<double> coeffs2 = {1.0, 1.0};
    std::vector<std::shared_ptr<Variable>> variables2 = {x, y};
    model.addConstr(variables2, coeffs2, SOLVER_GREATER_EQUAL, 1.0, "c1");

    // Optimize model
    model.setSense(SOLVER_MAXIMIZE);
    model.optimize();

    std::cout << "X value: " << x->getValue() << std::endl;
    std::cout << "Y value: " << y->getValue() << std::endl;
    std::cout << "Z value: " << z->getValue() << std::endl;

    std::cout << "Obj: " << model.getObjectiveValue() << std::endl;
}

Testing

mkdir build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
cd ..
./bin/optimystic-test

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • Connor Riley - Initial work - Website

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Antoine Legrain

About

A C++ library for LP and MIP modeling which abstracts away CPLEX and Gurobi.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published