Está en la página 1de 13

EN PROGRAMACIÓN LINEAL

Pedro L. González R
pedroluis@us.es
v1. Octubre 2021
EJEMPLO BÁSICO

Importamos las librerías

Creamos una función para “ordenar la estructura”

Dentro de la función
- Seleccionamos el solver
- Definimos las variables
- Definimos las restricciones
- Invocamos al solver
- Mostramos los resultados
EJEMPLO BÁSICO (2)

Selección del solver (según tipo de problema)

Podemos utilizar los siguientes:


• GLOP, Google's in-house linear programming solver
• CLP (Coin-or linear programming) is an open-source linear programming solver
• CBC (Coin-or branch and cut) is an open-source mixed integer programming solver
• SCIP (Solving Constraint Integer Programs) is currently one of the fastest non-commercial
solvers for mixed integer programming (MIP) and mixed integer nonlinear programming
(MINLP).
• …
EJEMPLO BÁSICO (3)

Definimos las variables del problema

Cota superior Nombre de la


Tipo de variable (ub, upper bound) variable
NumVar (tipo flotante) Cota inferior
IntVar (tipo entero) (lb, lower bound)
Devolver el número de variables del modelo
EJEMPLO BÁSICO (4)

Definimos las restricciones del problema De manera alternativa añadiendo coeficientes


Cota inferior Cota superior

Método para añadir


restricciones
En el caso de restricciones ≤:
Devolver el número de restricciones del modelo 𝑟𝑖. 𝑢𝑏() equivale al RHS o termino de recursos 𝑏𝑖
𝑟𝑖 . 𝑙𝑏() será -inf si no se establece

En el caso de restricciones ≥ :
ri.lb() equivale al RHS o termino de recursos 𝑏𝑖
𝑟𝑖 . 𝑢𝑏() será +inf si no se establece
https://google.github.io/or-tools/python/ortools/linear_solver/pywraplp.html

EJEMPLO BÁSICO (5)

Definimos la Función objetivo


También se pueden definir los coeficientes con SetCoefficient(var, val)

No hace falta definir z como variable del problema.


Se puede añadir z directamente como expresión lineal del problema
OPTIMAL = 0 optimal.
Invocamos al solver FEASIBLE = 1 feasible, or stopped by limit.
INFEASIBLE = 2 proven infeasible.
Posibles estados: UNBOUNDED = 3 proven unbounded.
ABNORMAL = 4 abnormal, i.e., error of some kind.
NOT_SOLVED = 6 not been solved yet.

Almacenamos la salida en “status”, que contine información acerca


de la optimalidad de la solución, no acotación, etc
EJEMPLO BÁSICO (6)

Mostramos los resultados


Valor de la FO

Dependiendo de si se llega a
la solución óptima o no se
discriminan las acciones

OPTIMAL = 0 optimal.
FEASIBLE = 1 feasible, or stopped by limit.
INFEASIBLE = 2 proven infeasible.
UNBOUNDED = 3 proven unbounded.
ABNORMAL = 4 abnormal, i.e., error of some kind.
NOT_SOLVED = 6 not been solved yet.
ALGUNAS MEJORAS (1)

Datos “matriciales”
ALGUNAS MEJORAS (2)

Variables

FO
ALGUNAS MEJORAS (3)

Restricciones
ALGUNAS MEJORAS (4)

Resultados
ALGUNAS MEJORAS (5)

Coeficientes en forma tabular


Representación gráfica

ALGUNAS MEJORAS (6)

También podría gustarte