Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Année universitaire: 2021-2022

Filières : 4éme G.Indus /GPMC


Module : Recherche opérationnelle

Département Génie Industriel Prof. A. Selmani

TP2: Recherche opérationnelle


1. Bar and Pie charts:

Source:
R. 1. https://matplotlib.org/3.5.0/gallery/lines_bars_and_markers/barchart.html
R. 2. https://www.geeksforgeeks.org/plot-a-pie-chart-in-python-using-matplotlib/
This example shows a how to create a grouped bar chart and how to annotate bars with labels.
import matplotlib.pyplot as plt
import numpy as np

labels = ['G1', 'G2', 'G3', 'G4', 'G5']


men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]

x = np.arange(len(labels)) # the label locations


width = 0.35 # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(x, labels)
ax.legend()

ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)
fig.tight_layout()
plt.show()

Result:
Année universitaire: 2021-2022
Filières : 4éme G.Indus /GPMC
Module : Recherche opérationnelle

Département Génie Industriel Prof. A. Selmani

1. Linear Programming & Discrete Optimization with PuLP

Source:
R. 3. https://fr.acervolima.com/python-programmation-lineaire-dans-la-pate-2/
R. 4. https://www.analyticsvidhya.com/blog/2022/03/linear-programming-discrete-
optimization-with-pulp/

To install: From terminal tape the following line:


• pip install pulp
import pulp as p

# Create a LP Minimization problem


Lp_prob = p.LpProblem('Problem', p.LpMinimize)

# Create problem Variables


x = p.LpVariable("x", lowBound = 0) # Create a variable x >= 0
y = p.LpVariable("y", lowBound = 0) # Create a variable y >= 0

# Objective Function
Lp_prob += 3 * x + 5 * y

# Constraints:
Lp_prob += 2 * x + 3 * y >= 12 , "C_1" # The constraint , constraint name
Lp_prob += -x + y <= 3 , "C_2" # The constraint , constraint name
Lp_prob += x >= 4 , "C_3" # The constraint , constraint name
Lp_prob += y <= 3 , "C_4" # The constraint , constraint name

status = Lp_prob.solve() # Solver


print("status",p.LpStatus[status]) # The solution status

# Printing the final solution


print("x=",p.value(x),"y=", p.value(y), "z=",p.value(Lp_prob.objective.value()))

#Printing the constraints


for name,constr in Lp_prob.constraints.items():
print(name,constr.value(),constr.constant)

Output:
x= 6.0 y= 0.0 z= 18.0
C_1 0.0 -12
C_2 -9.0 -3
C_3 2.0 -4
C_4 -3.0 -3
Année universitaire: 2021-2022
Filières : 4éme G.Indus /GPMC
Module : Recherche opérationnelle

Département Génie Industriel Prof. A. Selmani

Travail A faire:
En utilisant les références et les bibliothèques précédentes, créer deux programmes sous
Python pour résoudre les programmes linéaires: gestion des équipes (Exercice 6) et programme
de production (Exercice 7) comme indiqué sur les figures suivantes:

Figure 1:Gestion de équipes de travail.

Figure 2:Programme de production.

You might also like