Coder Social home page Coder Social logo

docplex's Introduction

DOcplex, IBM® Decision Optimization Modeling for Python

Welcome to the IBM® Decision Optimization CPLEX Modeling for Python. Licensed under the Apache License v2.0.

With this library, you can quickly and easily add the power of optimization to your application. You can model your problems by using the Python API and solve them on the cloud with the IBM® Decision Optimization on Cloud service or on your computer with IBM® ILOG CPLEX Optimization Studio.

This library is composed of 2 modules:

  • IBM® Decision Optimization CPLEX Optimizer Modeling for Python - with namespace docplex.mp
  • IBM® Decision Optimization CP Optimizer Modeling for Python - with namespace docplex.cp

Solving with CPLEX locally requires that IBM® ILOG CPLEX Optimization Studio V12.7.1 or V12.8 is installed on your machine.

Solving with the IBM® Decision Optimization on Cloud service requires that you register for an account and get the API key.

This library is numpy friendly.

Documentation

Examples

Installation

  • pip install docplex

docplex's People

Contributors

ctzhu avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

docplex's Issues

How to use Continuous Variables for IF-THEN constraints on DOCPLEX (Python)?

I'm using DOCPLEX to build up a Mixed Integer Linear Programming (MILP) problem which is then solved via CPLEX on Python. However, upon trying to solve the MILP problem using IF-THEN constraints, I receive the following error:

DOcplexException: Model.if_then(), nbBus40 >= 3.0 is not discrete

This is happening because I have declared nbbus40 variable to be continuous, as shown in the code below:

from docplex.mp.model import Model
mdl = Model(name='buses')
nbbus40 = mdl.continuous_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.add(mdl.if_then((nbbus40>=3),(nbbus30>=7)))
mdl.minimize(nbbus40*500 + nbbus30*400)
mdl.solve()
for v in mdl.iter_integer_vars():
print(v," = ",v.solution_value)

However, if I keep the nbbus40 variable as an integer, then I get the solution to the MILP problem, as shown below:

from docplex.mp.model import Model
mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.add(mdl.if_then((nbbus40>=3),(nbbus30>=7)))
mdl.minimize(nbbus40*500 + nbbus30*400)
mdl.solve()
for v in mdl.iter_integer_vars():
print(v," = ",v.solution_value)

RESULT:

nbBus40 = 0
nbBus30 = 10.0

How can I use the IF-THEN constraint in DOCPLEX for continuous variables?

invalid escape sequences

Your code presents some invalid escape sequences that are considered errors from python 11. Please check: https://docs.astral.sh/ruff/rules/invalid-escape-sequence/
A clear and concise description of the bug.

Steps To Reproduce
With CI workflow for analyzing the code, errors like:

E SyntaxError: invalid escape sequence '?'

rises in the comment lines

Expected Behavior
A clear and concise description of what you expected to happen.

Environment

  • for all the OS
  • for python in range 3.9 to 3.12

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.