Mixed Integer Nonlinear Programming
Integer Programming is a type of optimization problem where the variables are restricted to discrete whole number values. A Mixed-Integer Programming problem is when some of the variables are continuous and some are discrete. Mixed-Integer Nonlinear Programming (MINLP) also includes nonlinear equations and requires specialized MINLP solvers such as APOPT.
Binary (0 or 1) or the more general integer (select integer 0 to 10), or other discrete decision variables are frequently used in optimization. Examples of discrete variables include ON/OFF state (0 or 1 binary), selection of multiple options (0 to 5 integers), and other variables that are naturally integers.
At first glance it might seem solving a discrete variable problem would be easier than a continuous problem. After all, for a variable within a given range, a set of discrete values within the range is finite whereas the number of continuous values is infinite. When searching for an optimum, it seems it would be easier to search from a finite set rather than from an infinite set.
This is not the case, however. Solving discrete problems is harder than continuous problems. This is because of the combinatorial explosion that occurs in all but the smallest problems. For example if we have two variables which can each take 10 values, we have 10*10 = 100 possibilities. If we have 10 variables that can each take 10 values, we have 1010 possibilities. Even with the fastest computer, it would take a long time to evaluate all of these. There are numerical solvers such as APOPT and Bonmin that use methods such branch and bound and outer approximations to efficiently solve problems with binary, integer, or discrete variables.
Binary Variables
Integer or binary variables are defined in the APMonitor Modeling Language by appending a variable name with int. An binary decision variable is an integer variable with bounds between 0 and 1.
APMonitor Model File
! Binary decision variable (0 or 1) Variables int_b >=0 <=1
Python Gekko
Binary variables x1 and x2 problem are solved with Python GEKKO. The option integer=True is used to switch the variable from continuous to discrete form. The APOPT solver is required to solve problem with integer variables.
m = GEKKO() # create GEKKO model
# create binary variables
x1 = m.Var(integer=True,lb=0,ub=1)
x2 = m.Var(integer=True,lb=0,ub=1)
m.Minimize(4*x1**2-4*x2*x1**2+x2**2+x1**2-x1+1)
m.options.SOLVER = 1 # APOPT solver
m.solve()
print('x1: ' + str(x1.value[0]))
print('x2: ' + str(x2.value[0]))
Integer Variables
The range of upper and lower bounds can be increased or decreased to any range to create an integer variable.
APMonitor Model File
! Integer decision variable (-5 to 10) Variables int_v >=-5 <=10
Python Gekko
Integer variables x1 and x2 problem are solved with Python GEKKO. The option integer=True is used to switch the variable from continuous to discrete variables and the range is expanded from 0-1 to a wider range for both variables.
m = GEKKO() # create GEKKO model
# create integer variables
x1 = m.Var(integer=True,lb=-5,ub=10)
x2 = m.Var(integer=True,lb=-1,ub=2)
m.Minimize(4*x1**2-4*x2*x1**2+x2**2+x1**2-x1+1)
m.options.SOLVER = 1 # APOPT solver
m.solve()
print('x1: ' + str(x1.value[0]))
print('x2: ' + str(x2.value[0]))
Nonlinear programming solvers (such as IPOPT) may not return an integer solution because they are designed for continuous variables. Mixed Integer Nonlinear Programming solvers (such as APOPT) are equipped to solve for binary or integer variables. Select the appropriate solver option to either find an initial solution without integer variables or an integer solution. It is sometimes desirable to find a non-integer solution first because of the often significant reduction in computation time without the integer variables.
Discrete Variables
Discrete decision variables are those that have only certain levels or quantities that are acceptable at an optimal solution. Examples of discrete variables are binary (e.g. off/on or 0/1), integer (e.g. 4,5,6,7), or general discrete values that are not integer (e.g. 1/4 cm, 1/2 cm, 1 cm).
Python Gekko
Integer variable x1 and Special Ordered Set x2 variables are solved with Python GEKKO. The sos1 Gekko function is used to create the SOS1 variable.
m = GEKKO() # create GEKKO model
x1 = m.Var(integer=True,lb=-5,ub=10)
# create Special Ordered Set variable
x2 = m.sos1([0.5, 1.15, 2.6, 5.2])
m.Minimize(4*x1**2-4*x2*x1**2+x2**2+x1**2-x1+1)
m.options.SOLVER = 1 # APOPT solver
m.solve()
print('x1: ' + str(x1.value[0]))
print('x2: ' + str(x2.value[0]))