>Diagrama
>Modelo matemático
>restricciones
#------------Adquisicion de librerias------------#
library(ROI)
## ROI: R Optimization Infrastructure
## Registered solver plugins: nlminb, glpk.
## Default solver: auto.
library(ROI.plugin.glpk)
library(ompr)
## Warning: package 'ompr' was built under R version 4.1.1
library(ompr.roi)
## Warning: package 'ompr.roi' was built under R version 4.1.1
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.1.1
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#------------Modelacion------------#
modelo_dual=MIPModel()%>%
add_variable(y[i],i=1:7,type = "continuous")%>%
set_objective(y[5]-y[1],sense = "max")%>%
add_constraint(y[2]-y[1]<=5)%>%
add_constraint(y[3]-y[1]<=1)%>%
add_constraint(y[4]-y[2]<=7)%>%
add_constraint(y[5]-y[2]<=1)%>%
add_constraint(y[6]-y[2]<=6)%>%
add_constraint(y[2]-y[3]<=2)%>%
add_constraint(y[4]-y[3]<=6)%>%
add_constraint(y[5]-y[3]<=7)%>%
add_constraint(y[3]-y[4]<=7)%>%
add_constraint(y[6]-y[4]<=4)%>%
add_constraint(y[7]-y[4]<=6)%>%
add_constraint(y[4]-y[5]<=3)%>%
add_constraint(y[6]-y[5]<=5)%>%
add_constraint(y[7]-y[5]<=9)%>%
add_constraint(y[2]-y[6]<=7)%>%
add_constraint(y[7]-y[6]<=2)%>%
add_constraint(y[i]>=0,i=1:7)
solucion_dual=solve_model(modelo_dual,with_ROI(solver = "glpk",verbose=TRUE))
## <SOLVER MSG> ----
## GLPK Simplex Optimizer, v4.47
## 23 rows, 7 columns, 39 non-zeros
## * 0: obj = 0.000000000e+000 infeas = 0.000e+000 (0)
## * 4: obj = 4.000000000e+000 infeas = 0.000e+000 (0)
## OPTIMAL SOLUTION FOUND
## <!SOLVER MSG> ----
solucion_dual$objective_value
## [1] 4
get_solution(solucion_dual,y[i])
## variable i value
## 1 y 1 0
## 2 y 2 3
## 3 y 3 1
## 4 y 4 0
## 5 y 5 4
## 6 y 6 0
## 7 y 7 0
>los valores en verde son los aceptados en este ejercicio
>finish