资源简介
使用python调用cplex的两个实例,适合初学者进行学习,语法清晰

代码片段和文件信息
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
“““
Created on Sat Sep 23 08:39:49 2017
@author: sheboke
“““
import cplex
problem = cplex.Cplex()
problem.objective.set_sense(problem.objective.sense.minimize)
names = [‘a‘‘b‘‘c‘‘d‘‘e‘‘f‘‘g‘‘h‘]
objective =[140.0100.080.09.013.015.08.0140.0]
lower_bounds=[0.00.00.00.00.00.00.00.0]
i=10
upper_bounds = [iiiiiiii]
problem.variables.add(obj = objective
lb =lower_bounds
ub = upper_bounds
names = names)
#将变量设置为整数
problem.variables.set_types([(‘a‘problem.variables.type.integer)
(‘b‘problem.variables.type.integer)
(‘c‘problem.variables.type.integer)
(‘d‘problem.variables.type.integer)
(‘e‘problem.variables.type.integer)
(‘f‘problem.variables.type.integer)
(‘g‘problem.variables.type.integer)
(‘h‘problem.variables.type.integer)])
constraint_names=[‘c1‘‘c2‘ ‘c3‘ ‘c4‘ ‘c5‘‘c6‘]
first_constraint = [[‘a‘‘b‘‘c‘‘d‘‘e‘‘f‘ ‘g‘‘h‘][5.06.05.00.50.70.10.13.0]]
second_constraint = [[0 1 2 3 4 5 6 7][3.05.02.00.50.20.10.25.0]]
third_constraint = [[0 1 2 3 4 5 6 7][1.03.00.00.30.00.30.04.0]]
fouth_constraint = [[0 1 2 3 4 5 6 7][6.01.04.00.10.90.60.13.0]]
fifth_constraint = [[0 1 2 3 4 5 6 7][4.01.02.00.10.11.30.25.0]]
sixth_constraint =[[0 1 2 3 4 5 6 7][2.01.00.00.00.00.40.34.0]]
constraints = [first_constraint second_constraintthird_constraintfouth_constraintfifth_constraintsixth_constraint]
rhs = [60.060.028.060.060.028.0]
#L是<=,G>=
constraint_senses =[‘G‘‘G‘‘G‘‘G‘‘G‘‘G‘]
problem.linear_constraints.add(lin_expr = constraints
senses = constraint_senses
rhs = rhs
names = constraint_names)
#将integer optimal设置为1%
problem.parameters.mip.tolerances.mipgap.set(0.01)
problem.solve()
print(problem.solution.get_objective_value())
print(problem.solution.get_values())
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 88585 2017-10-31 11:03 Cplex-master\Cplex.ipynb
文件 263 2017-10-31 11:03 Cplex-master\README.md
文件 2256 2017-10-31 11:03 Cplex-master\cplex1.py
文件 2509 2017-10-31 11:03 Cplex-master\cplex2.py
目录 0 2018-06-04 19:49 Cplex-master\
- 上一篇:朴素贝叶斯算法python底层代码
- 下一篇:Python爬虫爬取豆瓣电影
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论