How to generate graph of a mathematical model?
I’ve already tried using PyPlot, and I still could not.
using JuMP, Cbc
m = Model(solver = CbcSolver())
#Declaração das variáveis
@defVar(m, x1 >= 0)
@defVar(m, x2 >= 0)
#Função Objetivo
@setObjective(m, Max, 3x1 + 5x2)
#Restrições
@addConstraint(m, 1x1 + 0x2 <= 4)
@addConstraint(m, 0x1 + 2x2 <= 12)
@addConstraint(m, 3x1 + 2x2 <= 18)
#Leitura do modelo
print(m)
#Resolução e visualização dos resultados
status = solve(m) # solves the model
println("Objective value: ", getObjectiveValue(m))
println("x1 = ", getValue(x1))
println("x2 = ", getValue(x2))
nilshg
2
What exactly are you trying to plot? Can you show your PyPlot code and any error messages you’re receiving?
I would like to plot the constraints of the mathematical model, which would be
x1 = 4
2x2 = 12
3x1 + 2x2 = 18
I no longer have the PyPlot code.
I don’t think there is an automatic way to print the constraints.
I did it by hand, here is an example: http://abelsiqueira.github.io/disciplinas/cm116/2018/Otimização.ipynb
nilshg
6
Something like this?
using Plots
plot([-1.5*x + 9 for x ∈ range(0,0.1,10)], label = "3x_1 + 2x_2 = 18", xlabel = "x_1", ylabel = "x_2")
vline!([4], label = "x_1 <= 4")
hline!([6], label = "x_2 <= 6")
Unfortunately I could not open the link.