Python optimization library Pulp

Purpose

Python Practical Data Analysis After reading 100 knocks, I became interested in Pulp, an optimization library, so I also used it as a memorandum.

What you want to achieve

I want to easily perform optimization using variables that take integers Of course, if you use a For statement for brute force, you can easily apply it, or you can search by shaking the parameters one by one, but it takes time and it is troublesome to set constraint conditions.

Libraries to use Pulp and ortoolpy

From the console in Anaconda conda install -c conda-forge pulp pip install ortoolpy Can be installed with

sample

sample.py


from pulp import LpVariable,lpSum,value
from ortoolpy import model_max,addvars,addvals

m=model_max()
v1={"x":LpVariable("vx",lowBound=0,cat='Integer'),
 "y":LpVariable("vy",lowBound=0,cat='Integer')}
m+=lpSum(v1["x"]+v1["y"])
m+=lpSum(v1["x"]*2+v1["y"])<=10
m+=lpSum(v1["x"]+v1["y"]*2)<=7
m.solve()

for k,x in v1.items():
    print(k,value(x))
print(value(m.objective))
x 4.0
y 1.0
5.0

Recommended Posts

Python optimization library Pulp
Python 3.6 email library
Python in optimization
Python ast library
Python Library notes
Mathematical Optimization Modeler (PuLP) Cheat Sheet (Python)
Production planning optimization using linear programming (Python + PuLP)
Install python external library
Aim python library master (48) autopep8
Aim python library master (36) json2html
Aim python library master (49) psidialogs
Aim python library master (26) easyxml
Aim python library master (29) table_printer
Aim python library master (55) namespaces
Aim python library master (46) browserplus
Python Evolutionary Computation Library Deap (3)
Aim python library master (30) chronyk
Aim python library master (3) workalendar
Aim python library master (42) speedrecorder
Aim python library master (37) slimurl
Recommendation of binpacking library of python
Aim python library master (44) pynetviz
Aim python library master (8) rolex
Aim python library master (52) marktime
Aim python library master (21) hy
Windows10: Install python dlib library
Aim python library master (13) easydev
Aim python library master (20) pyyaml
Aim python library master (34) concurrent
Aim python library master (40) wordsegmentation
Aim python library master (43) cpmoptimize
Aim python library master (58) faker
Aim python library master (11) nlist
Aim python library master (38) beautiful_print
Aim python library master (65) geopy
Aim python library master (2) vincenty
Aim python library master (59) logbook
Aim python library master (10) timeit
Aim python library master (0) Links
Aim python library master (66) youtube-dl
Overriding library functions in Python
Aim python library master (22) htmltag
Aim python library master (67) httpie
Aim python library master (45) xlsxwriter
Aim python library master (9) WebHelpers
Aim python library master (32) sql
Memorandum @ Python OR Seminar: Pulp
Aim python library master (60) colourettu
Aim python library master (64) pretty_cron
Aim python library master (56) colorthief
Aim python library master (61) nested-lookup
Aim python library master (17) rangeparser
Aim python library master (47) deckor
Aim python library master (25) orderedset
Aim python library master (62) glances
Aim python library master (12) excel
Python Evolutionary Computation Library Deap (2)
Aim python library master (24) combi
Solve optimization problems in Python
Aim python library master (63) easygui
Aim python library master (19) riemann