Linear programming + hands-on of pulp

Overview of linear programming

Hands-on

problem

example1

table Article A Article B
Process 1 2 hours 2 hours
Process 2 3 hours 5 hours
Profit 4,000 yen 5,000 yen

Source code

Library import


from pulp import *

Problem-solving source code


#Generate problem object
prob = LpProblem(name='Integer programming exapmle1',sense=LpMaximize)

#Variable setting
x1 = LpVariable('x1',lowBound=0)
x2 = LpVariable('x2',lowBound=0)

#Setting the objective variable
prob += 4*x1 + 5*x2
#Constraint setting
prob += 2*x1 + 2*x2 <= 7,'ineq1'
prob += 3*x1 + 5*x2 <= 14,'ineq2'

#Problem output
print('-------Problem information output-------')
print(prob)

#Find a solution
prob.solve()

#How was it solved
print('-------Solution information-------')
print(LpStatus[prob.status])

#Optimal value output
print('-------Optimal value output-------')
print('Optimal Value ={}'.format(value(prob.objective)))
#Optimal solution output
print('-------Optimal solution output-------')
for val in prob.variables():
    print('{}={}'.format(val.name,value(val)))

result

-------Problem information output-------
Integer programming exapmle1:
MAXIMIZE
4*x1 + 5*x2 + 0
SUBJECT TO
ineq1: 2 x1 + 2 x2 <= 7

ineq2: 3 x1 + 5 x2 <= 14

VARIABLES
x1 Continuous
x2 Continuous

-------Solution information-------
Optimal
-------Optimal value output-------
Optimal Value =15.75
-------Optimal solution output-------
x1=1.75
x2=1.75

Summary

reference

Python in optimization

Recommended Posts

Linear programming + hands-on of pulp
Linear Programming with PuLP
[Mathematical optimization problem] Linear programming using PuLP
Production planning optimization using linear programming (Python + PuLP)
[Note] Beginning of programming
Features of programming languages [Memo]
Coordinator and integer linear programming
Story of trying competitive programming 2
The popularity of programming languages
Linear programming by Karmarkar's algorithm
1st month of programming learning
Getting started on how to solve linear programming problems with PuLP
List of Linear Programming (LP) solvers and modelers available in Python
[Python] [Table of Contents Links] Python Programming
Understanding memo of collective intelligence programming
Story of trying competitive programming Part 1
Learning history of programming transcendence beginners