本篇博客主要介绍Cplex在python环境的应用
Cplex简介
Cplex由IBM开发。使用Cplex可以将复杂的业务问题表现为数学规划(Mathematic Programming)模型。是用于线性规划、混合整数规划和二次规划的高性能数学规划解析器。
Cplex在Python中的使用
安装cplex库
pip install cplex
相关参数说明
下面是一个MIP的简单例子,结合例子来看。首先将问题的目标函数和约束定义好,再传入接口中,一些符号的定义均已注释
# -*- coding: utf-8 -*-
# The MIP problem solved in this example is:
# 问题描述
# Maximize x1 + 2 x2 + 3 x3 + x4
# Subject to
# - x1 + x2 + x3 + 10 x4 <= 20
# x1 - 3 x2 + x3 <= 30
# x2 - 3.5x4 = 0
# Bounds
# 0 <= x1 <= 40
# 0 <= x2
# 0 <= x3
# 2 <= x4 <= 3
# Integers
# x4
import cplex
from cplex.exceptions import CplexError
# data common to all populateby functions
my_obj = [1.0, 2.0, 3.0, 1.0] # 系数
my_ub = [40.0, cplex.infinity, cplex.infinity, 3.0]