Skip to end of metadata
Go to start of metadata

The Domain Model

The domain for the HVAC application consists of HeatPump, Vent, Thermometer, Floor, and TempuratureControl. We don't model the building that contains the floors directly since the rules do not depend on that abstraction. All of these abstractions are declared as interfaces, with implemenations provided by the sim package.

... TODO include a diagram like JIA figure 14.1 ...

Floor

Floor represents a single floor in the building. The Floor keeps track of its floor number, its Thermometer, HeatPump, and Vent.

org.drools.spring.examples.jiahvac.model.Floor.java

Thermometer

Thermometer is sensor that detects the tempurature of its floor. Its getReading method provides the current tempurature. Thermometer implements the JavaBeans property-change protocol methods which allows drools to detect changes to the tempurature and automatically update WorkingMemory with the new value. The simulator implements this interface and updates the Thermometer based on its heat transfer model.

org.drools.spring.examples.jiahvac.model.Thermometer.java

Vent

Vent controls the flow of heated or cooled onto the floor. A Vent can either be OPEN or CLOSED. Rules open and close the Vent according to the need to adjust the tempurature on a floor.

org.drools.spring.examples.jiahvac.model.Vent.java

HeatPump

HeatPump exchanges heat between floors and the outside of the building. A HeatPump can be either HEATING, COOLING, or OFF. A single HeatPump can serve multiple floors. Rules change the HeatPump state according to the need to adjust the tempurature on a floor.

org.drools.spring.examples.jiahvac.model.HeatPump.java

TempuratureControl

TempuratureControl sets the desired tempurature for the entire building, represented by the property setPoint. Rules use TempuratureControl to determine whether a floor is too hot or too cold. To keep the system from thrashing between cooling and heating, TempuratureControl uses the property guardAmount to define "guard lines" around the desired tempurature. The current tempurature must be above or below the setPoint by guardAmount before it will be considered too hold or too cold.

TempuratureControl exports two concepts: Whether a floor is cool or warm enough, and whether a floor is too cool or too hot. Cool enough or warm enough is when the tempurature has reached the setPoint but has not gone beyond the guardPoint. Too cool or tool hot is when the tempurature has gone beyond the setPoint by the guardAmount. As we will see in the next section, the rules use these two concepts decide how aggressive to be in attempting to adjust the tempurature on a floor.

... TODO should this next para be here or later when we describe the rules ...

In the current implementation, the values for setPoint and guardAmount are specified in hvac.properties and cannot be changed at runtime. TempuratureControl is not fact, but rather injected as a dependency into the rules. If we wanted to change setPoint or guardAmount at runtime, we would need to make TempuratureControl a fact so that rules fired upon the property change. But I have left it this way so I could demonstrate dependency injection into rules.

org.drools.spring.examples.jiahvac.model.TempuratureControl.java
Labels: