Furnace Control

Main.FurnaceControl History

Hide minor edits - Show changes to output

March 28, 2023, at 07:36 PM by 10.35.117.248 -
Added lines 8-15:

Discrete decision variables are more challenging than continuous decision variables in optimal control problems because they introduce combinatorial complexity. In a continuous optimization problem, the decision variables can take on any value within a specified range, and the optimal solution can be found by solving a set of differential equations or optimization algorithms. However, in a discrete optimization problem, the decision variables can only take on a limited set of values, often with constraints on their combinations.

Discrete decision variables may arise in optimal control problems when a decision needs to be made among a finite set of alternatives or when the decision variables are constrained by a finite set of states. The combinatorial complexity introduced by discrete decision variables makes it challenging to find the optimal solution. The number of possible combinations of the decision variables increases rapidly with the number of variables and the size of the discrete set of values. This can make it difficult to evaluate all possible combinations and find the optimal solution in a reasonable amount of time. Techniques such as branch and bound solve faster than exhaustive search methods by exploring the solution space more efficiently and reducing the computational complexity of finding the optimal solution.

----

'''Model Predictive Control with Binary Variable'''
March 27, 2023, at 01:47 PM by 10.35.117.248 -
Changed lines 5-6 from:
%width=550px%Attach:furance_control.png
to:
(:html:)
<iframe width="560" height="315" src="https://www
.youtube.com/embed/nN__uAB8BD4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
(:htmlend:)

Added lines 64-65:

%width=550px%Attach:furance_control.png
March 27, 2023, at 01:20 PM by 10.35.117.248 -
Changed lines 34-36 from:
u.dcost = 0.1
u.status = 1
to:
u.DCOST = 0.1; u.STATUS = 1
Changed lines 38-41 from:
T.SPHI = 68
T.SPLO = 70
T.STATUS = 1
T.TR_INIT = 0
to:
T.SPHI = 68; T.SPLO = 70
T.STATUS = 1; T.TR_INIT = 0
March 24, 2023, at 05:29 PM by 10.35.117.248 -
Changed line 1 from:
(:title Home Heating Furnace Control:)
to:
(:title Furnace Control:)
March 24, 2023, at 05:25 PM by 10.35.117.248 -
Deleted lines 8-9:
'''Solution'''
Changed lines 30-33 from:
Kp = 60
taup = 120
T0 = 40
to:
Kp = 60; taup = 120; T0 = 40
Changed line 46 from:
 
to:
Changed lines 54-55 from:
plt.ylabel('T (degF)')
plt.legend()
to:
plt.ylabel('T (°F)'); plt.legend(), plt.grid()
Changed lines 57-59 from:
plt.ylabel('Heat (On/Off)')
plt.xlabel('Time (min)')
plt.legend()
to:
plt.ylabel('Heat (On/Off)'); plt.xlabel('Time (min)')
plt.legend(); plt.grid(); plt.tight_layout()
plt.savefig('furnace_control.png',dpi=300
)
March 24, 2023, at 05:11 PM by 10.35.117.248 -
Changed line 7 from:
Design a thermostat for a home that has a furnace with On/Off control. The home is initially unheated in 40 degF weather. When the heater is turned on, the temperature in the home reaches 63% of the steady state value in 120 minutes, starting from 40 degF. If left on indefinitely, the home would eventually reach 100 degF. Optimize the heater response for the first 2 1/2 hours starting from a cold home at 40 degF. The target range for the home is between 68 and 70 degF.
to:
Design a thermostat for a home that has a furnace with On/Off control. The home is initially unheated in 40°F weather. When the heater is turned on, the temperature in the home reaches 63% of the steady state value in 120 minutes, starting from 40°F. If left on indefinitely, the home eventually reaches 100°F. Optimize the heater response for the first 2 1/2 hours starting from a cold home at 40°F. The target range for the home is between 68 and 70°F.
March 24, 2023, at 05:09 PM by 10.35.117.248 -
Added lines 1-75:
(:title Home Heating Furnace Control:)
(:keywords home thermostat, Python, GEKKO, model predictive control, energy, on/off control:)
(:description Solve an optimal home furnace scheduling problem with Python Gekko to maintain desired temperature within a dead-band.:)

%width=550px%Attach:furance_control.png

Design a thermostat for a home that has a furnace with On/Off control. The home is initially unheated in 40 degF weather. When the heater is turned on, the temperature in the home reaches 63% of the steady state value in 120 minutes, starting from 40 degF. If left on indefinitely, the home would eventually reach 100 degF. Optimize the heater response for the first 2 1/2 hours starting from a cold home at 40 degF. The target range for the home is between 68 and 70 degF.

'''Solution'''

%width=550px%Attach:milp_thermostat.png

(:toggle hide python button show="Show Python GEKKO Source":)
(:div id=python:)
(:source lang=python:)
from gekko import GEKKO
import matplotlib.pyplot as plt

m = GEKKO() # create GEKKO model
m.time = [0,1,2,4,8,12,16,20,25,30,35,40,45,50,\
          55,60,65,70,75,80,85,90,95,100,105,110,\
          115,120,125,130,135,140,145,150]

# change solver options
m.solver_options = ['minlp_gap_tol 1.0e-2',\
                    'minlp_maximum_iterations 10000',\
                    'minlp_max_iter_with_int_sol 5000']
m.options.SOLVER = 1
m.options.IMODE = 6

# parameters
Kp = 60
taup = 120
T0 = 40

# create heater binary variable
u = m.MV(integer=True,lb=0,ub=1)
u.dcost = 0.1
u.status = 1

# controlled variable (temperature)
T = m.CV(value=T0)
T.SPHI = 68
T.SPLO = 70
T.STATUS = 1
T.TR_INIT = 0

# first order equation
m.Equation(taup * T.dt() == -(T-T0) + Kp * u)
 
m.solve() # solve MILP

# plot solution
plt.subplot(2,1,1)
plt.plot(m.time,T,'r-',label='Temperature')
plt.plot([0,m.time[-1]],[T.SPHI,T.SPHI],'k:',label=r'$T_{sphi}$')
plt.plot([0,m.time[-1]],[T.SPLO,T.SPLO],'k:',label=r'$T_{splo}$')
plt.ylabel('T (degF)')
plt.legend()
plt.subplot(2,1,2)
plt.plot(m.time,u,'b.-',label='Furnace (On/Off)')
plt.ylabel('Heat (On/Off)')
plt.xlabel('Time (min)')
plt.legend()
plt.show()
(:sourceend:)
(:divend:)

Attach:download.png [[Attach:thermostat_python_matlab.zip|Furnace Control Source Files (APM MATLAB)]] and [[https://youtu.be/2XC6mpop_j4|Video]]

----

%width=200px%Attach:gekko.png

The [[https://gekko.readthedocs.io/en/latest/|Gekko Optimization Suite]] is a machine learning and optimization package in Python for mixed-integer and differential algebraic equations. The GEKKO package is available in Python with '''pip install gekko'''. There are [[https://apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization|additional example problems]] for equation solving, optimization, regression, dynamic simulation, model predictive control, and machine learning. [[https://apmonitor.com/wiki/index.php/Main/APMonitorReferences|Cite Gekko Paper]]