Created
April 1, 2025 12:38
-
-
Save okurka12/e261f2c3f9d201a3fb0049b01a314f05 to your computer and use it in GitHub Desktop.
GNU Octave - solve linear minimization/maximization problem using glpk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# solve linear minimization/maximization problem using glpk | |
# | |
# based on example from: | |
# https://octave.sourceforge.io/octave/function/glpk.html | |
################################################################################ | |
# objective function coefficients | |
c = [12000,9000]'; | |
# constraint coefficients | |
A = [-200, 100; | |
2.1, 0.9;]; | |
# right side values of constraints | |
b = [0,21]'; | |
# lower and upper bounds for the variables | |
lb = [0, 0]; | |
ub = []; | |
# constraint type | |
# F - A free (unbounded) constraint (the constraint is ignored). | |
# U - An upper bound inequality constraint | |
# S - An equality constraint | |
# L - A lower bound inequality constraint | |
ctype = "UU"; | |
# variable type | |
# I - integer | |
# C - continuous | |
vartype = "CC"; | |
# sense | |
# 1: minimization | |
# -1: maximization | |
s = -1; | |
# define the behavior of solver | |
param.msglev = 1; | |
param.itlim = 100; | |
################################################################################ | |
[x, f, status, extra] = glpk (c, A, b, lb, ub, ctype, vartype, s, param); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment