Rapid Prototyping of Low-Complexity Orchestrator Targeting CyberPhysical Systems: The Smart-Thermostat Usecase

Recently, a new generation of systems with integrated computational and physical capabilities, also known as CyberPhysical Systems (CPSs), has been introduced. The control of these systems often results in very high-order models imposing great challenges to the analysis and design problems. In the context of this paper, a decision-making mechanism for these systems is proposed. Moreover, we introduce a virtual prototyping framework for the physical implementation and customization of these orchestrators. For evaluation purposes, the introduced solution is applied to design a low-cost smart thermostat in a microgrid environment. Experimental results highlight the superiority of introduced orchestrator, as it achieves comparable performance to state-of-the-art relevant decision-making approaches, but with considerable lower computational and storage complexities.

Trading price for buying/selling energy at time step t. α Trade-off between energy and thermal comfort optimization. AF Available funds for buying energy budget from the grid. PPD i (t, S i t ) PPD for building i at time step t. PPD lim Maximum acceptable PPD (based on ASHRAE standard [41], [42]). C est Estimated thermal comfort per thermal zone. C real Actual thermal comfort per thermal zone. E est Estimated energy consumption per thermal zone. E real Actual energy consumption per thermal zone.

I. INTRODUCTION
B UILDINGS are immensely energy demanding and are expected to consume even more in the near future. It has been estimated that the amount of energy consumed in European Union's (E.U.) buildings reaches around 40%-45% of the total energy consumption, where two-thirds of which is used in dwellings [1]. More thoroughly, HVAC is the largest contributor to a home's energy bills and carbon emissions. This is mainly due to the nonoptimal strategies for the building's cooling and heating services. Previous studies reported that about 20%-30% of the building's energy requirements could be reduced by turning off the HVAC system when residents are sleeping or away [2]. Although promising, such a benefit, however, is difficult to be achieved since building's residents do not adjust manually the thermostat several times a day. In addition, the programmable thermostats are too difficult to be used effectively for the majority of residents. For instance, it is typical households with programmable thermostats to have higher energy consumption on average than those with manual thermostat control because users program them incorrectly or disable them altogether [3]. As a result, the Environmental Protection Agency (EPA) suspended the Energy Star certification program for all programmable thermostats, effective December 31, 2009 [4].
These limitations are partially alleviated by a new generation of systems with tight integration between computational (cyber) and physical capabilities, also known as CPS. The new design paradigm interacts with, and expands the capabilities of, the physical world through monitoring, computation (i.e., distributed coordination), and communication mechanisms. By pooling the system's resources and capabilities together results to a new, more complex system which offers additional functionality and performance than simply the sum of the constituent subsystems. The CPS approach enables a better resolution of the physical world and therefore an advanced mechanism for detecting the occurrence of an event; hence, it is expected to play a key role in the development of next-generation autonomous systems, especially for the smart buildings and microgrids [2].
Although promising, the CPS technology faces a number of challenges and constraints mainly posed by the target application domain. For instance, the control of HVAC imposes sensors and processing nodes that monitor the system's dynamic parameters and evaluate multiple operating scenarios, respectively, in order to determine the optimal configuration of buildings' thermal zones.
Due to the problem's scalability (i.e., different sizes of microgrids), the CPS decision-making mechanisms exhibit increased requirements for data processing and storage. Furthermore, as the physical world is not entirely predictable, the CPS operation is not expected in a controlled environment; thus, the system orchestrator has to be robust enough to unexpected events at runtime.
Equally important to the development of an efficient decision-making algorithm is considered the task of hardware/software (HW/SW) codesign [5]. Toward this direction, there is a continuous demand both in academia and industry for providing higher flexibility during the service and product development phases. Such an approach strives for VP solutions capable of performing fast yet accurate cosimulation between HW and SW components [6].
In accordance with the previously mentioned challenges, this paper introduces a framework for the design, customization, and physical implementation of low-complexity decision-making mechanisms targeting to CPS platforms. For demonstration purposes, we apply the proposed framework for designing the control mechanism of HVAC systems (i.e., to determine at real time the optimal temperature setpoint per thermal zone) in a microgrid environment. For this purpose, a number of distributed suborchestrators (one per building's thermal zone) cooperate to compute the overall CPS optimal configuration. Experimental results highlight the superiority of introduced solution, as we achieve near to optimal (based on relevant state-of-the-art control algorithms) HVAC configuration, but with significantly lower computational and storage complexities. Consequently, the proposed framework delivers an orchestrator that can be sufficiently operated onto low-performance (and hence low-cost) embedded devices (i.e., field-programmable gate arrays).
The contributions of this paper as compared to the state-ofthe-art relevant approaches are summarized as follows.
1) We propose a novel online decision-making algorithm for the optimal configuration of CPS, such as the HVAC systems in the microgrid environment. The introduced solution is based on LR and Multiple-Choice Knapsack algorithms and exhibits remarkable lower computational and storage complexities without sacrificing the quality of derived results. 2) We introduce two fast and accurate models for estimating the residents' thermal comfort and HVAC's energy consumption. These models exhibit negligible complexity compared to relevant implementations without any quality degradation. 3) We adopt the objectives of the introduced decisionmaking algorithm with multiple operating modes. Regarding our case study, these modes: 1) balance energy consumption with residents' satisfaction; 2) minimize energy consumption while maintaining a satisfactory level of thermal comfort; and 3) maximize residents' satisfaction without exceeding the available energy budget. 4) Finally, we propose a framework for rapid prototyping of LSS orchestrators. This framework relies on a Hardware-in-the-Loop (HiL) technique to speed up the system's physical design. Such a technique enables among others shorter design times, which in turn alleviates the time-to-market pressure. The rest of this paper is organized as follows: Section II provides an overview of related work, while the employed case study is presented in Section III. The proposed decisionmaking algorithm and the software-supported framework for rapid prototyping are presented in Sections IV and V, respectively. A number of experimental results that evaluate the efficiency of the proposed solution for alternative operating scenario against state-of-the-art relevant implementations are provided in Section VI. Finally, conclusions are summarized in Section VII.

II. RELATED WORK
The problem of deciding upon the HVAC configuration is a well-established challenge that has been attracting the interest of many researchers over the years [7]- [10]. According to literature, there are two mainstream ways for the HVAC configuration. Specifically, the first category corresponds to systems that provide online decision-making [11], while the latter approach relies on MPC techniques [12]. The competitive advantages of each category have to be carefully analyzed in accordance with inherent characteristics posed by the target application domain.
More precisely, the online algorithms exhibit limited efficiency compared to MPC but they are reactive to realtime constraints (i.e., climatic conditions, occupants' behavior, etc.). Furthermore, online algorithms exhibit lower computational and storage complexities compared to the corresponding MPC solutions; thus, they are suitable for being executed On the other hand, MPC for nonlinear systems has been extensively analyzed and successfully applied to various domains during the recent decades [13], [14]. These solutions affect mainly controllers that were designed along with the system, where the typical "black-box" approach of on-line methods (e.g., based on machine learning techniques) is criticized [15].
Despite the significant progress made in optimal nonlinear control theory [16], [17] MPC algorithms are not, in general, applicable to LSS because of the computational difficulties associated with the dimensionality issues: in most cases, predictive control computations for nonlinear systems amount to numerically solving a nonconvex high-dimensional mathematical problem whose solution may require formidable computational power if a real-time (or near real-time) solution is required. Consequently, a significant effort per usecase is absolutely necessary to tackle the application-specific algorithm's design and customization challenges (e.g., through detailed experimental and mathematical analysis). Last but not least, MPC algorithms cannot support real-time decisions because their efficiency relies on moving forward in time to simulate the impact of alternative control strategies.
The increased computational complexity of MPC-based algorithms makes them affordable only to enterprise environments, e.g., as part of BEM systems. However, recently, there is an emerging need for solutions that are applicable to residential buildings as well. This necessity has already been identified by the industry, as it is portrayed by the expanding market of smart thermostats. Even though the market is still at its nascent stage, analysts expect it will grow exponentially, as consumers become aware of the advantages of sophisticated decision-making mechanisms for building's heating/cooling services [18]. 1 In order to manipulate the increased complexity of multiobjective optimization problems, researchers employ heuristic methods, such as stochastic dynamic programming [19] and genetic algorithms [20]. Furthermore, methods that rely on empirical models [21], simulation optimization [22], artificial neural networks (ANNs) [23], support vector machine (SVM) classifiers (ESL [24]), reinforcement learning [25], [26], eventbased optimization (EBO) [8], and fuzzy logic [27] have also studied. Although these solutions trades off the quality of decisions with the associated problem's complexity, they are rarely adopted because they impose excessive training phase.
Apart from the control algorithm itself, the emphasis is also given to the physical implementation and customization tasks. This trend strives for rapid prototyping solutions, such as the HiL [6] and virtual prototyping [33], where their proper combination addresses one of today's biggest challenges in physical codesign: to enable software development, debug, and validation before the hardware device becomes available. The rapid prototyping challenge becomes far more important by taking into consideration that the software aspects of an embedded system can account for 60%-80%, or more, of development cost. For instance, the International Technology Roadmap for Semiconductors (ITRS) reported that software development costs will increase, and will reach rough parity with hardware costs, even with the advent of multi-core software development tools [34].
The software tools that support physical design are also crucial for deriving an optimum solution. The existing simulation and/or emulation frameworks are built on the fundamental premise that models are freely interchangeable among vendors and have interoperability among them. In other words, this assumes that models can be written, or obtained from other vendors, while it is known a priori that they will be accepted by any vendor's tool for performing different steps of system design (e.g., system's analysis, simulation, performance tuning, etc.). Even though such a concept seems straightforward and promising, it has been proven completely elusive in the world of rapid prototyping, since the available solutions do not provide either model interoperability or independence among models and software tools. Consequently, the adoption of flows among vendors could be considered as a desired feature. Table I provides a qualitative comparison between the introduced decision-making algorithm and the mainstream ways for implementing control algorithms. According to this analysis, both the online and the proposed algorithms take into account constraints at runtime, but the proposed one exhibits lower computational and storage complexities. Note that the absence of lightweight decision-making solutions in relevant literature able to be executed onto embedded platforms is not due to neglect, but rather due to its difficulty. In addition, the plug and play functionality is also crucial for this type of products, as smart thermostats have to support the nonsupervised learning feature. In contrast to MPC and online methods, the proposed system's orchestrator consists of modular components (e.g., history windows, energy/thermal models, heuristic solver, etc.) which can be adapted even at runtime in order to respect the resident's requirements. Finally, regarding the hardware implementation, the proposed framework exhibits remarkable lower design complexity since it is not necessary to model the building's dynamics.

III. PROBLEM FORMULATION
The constant demand for energy efficiency, the deployment of renewable energy sources, and the onset of smart-grid technologies, foretell that in the near future an increased number of building facilities will become active participants in the energy market. From the systems' point of view, this will lead to autonomous microgrids with energy trading capabilities and flexibility in regard to shifting or reducing electrical loads as needed. Inline to this trend, the concept of a smart, or intelligent, the grid has been around for many years. The challenges posed by this concept may be addressed with the CPS technology. More precisely, by enabling realtime monitoring and reaction, it is possible for the system to constantly refined itself to an optimal state. A number of electric utilities, such as market-driven pricing, are already available even to the end users [1], [35], where instead of having a flat rate (24 h/day, 7 days/week) for electricity, variable pricing mechanisms exist allowing the cost per kilowatt-hour may change based on the day, time of day, or a more dynamic event, such as the weather conditions or the expected load requirements.
The template of our case study corresponds to a microgrid environment, similar to the one depicted in Fig. 1. More thoroughly, we consider that our microgrid is composed by three entities: 1) the supply side; 2) the demand side; and 3) the utilities. The supply and demand sides contain the available energy sources (e.g., solar, wind, biogas) and the cooling/heating systems found in buildings, respectively. Similarly, the utilities refer to the mechanisms that guarantee the optimal control of the system's components (supply and demand sides) in term of computing temperature set points per thermal zone. In order to tackle the decision-making task, a number of sensors acquire data related to the weather forecast (temperature, humidity, and solar radiation), building conditions (indoor temperature and humidity), as well as the residents' activity per thermal zone. Finally, the market utility performs the energy trading for buying/selling energy depending on the building's requirements and its available funds (AF).
Our experiment considers also the case where the studied microgrid is connected either directly to other microgrids or to the main grid. Due to technical requirements, the grid has to remain balanced at all times. Although critical, such an analysis is beyond the scopes of this work, however, in relevant literature, there are techniques that guarantee efficient building-to-microgrid, as well as microgrid-to-grid integration [36].

A. Problem Instantiation
The problem we tackle throughout this paper deals with the optimum decisions (i.e., control) of smart thermostats in order to enhance the residents' thermal comfort with the minimum possible energy consumption. The efficiency of the introduced framework is evaluated in a microgrid case study. Specifically, the target case study considers five buildings with multiple thermal zones (see Table II). These buildings were modeled in a detailed manner [37] at EnergyPlus suite [38], 2 while the weather and energy pricing data correspond to publicly available information collected in 2010 [35], [39]. For this experiment, we assume that people work within buildings only during their operating hours and the number of people per room varies during the day according to a pseudorandom distribution.
By appropriately configuring the temperature per thermal zone, it is possible to improve the residents' thermal comfort with a controllable energy consumption overhead compared to state-of-the-art offline controllers that exhibit remarkable higher computational and storage complexities. Assuming that a grid consisted of k buildings, the quality of the proposed solution is quantified with two orthogonal metrics, namely, the energy cost and the resident's thermal comfort level, as it is formulated in (1). Factors E G i (t, S i t ) and PPD i (t, S i t ) denote the energy purchased from the main-grid and the average thermal comfort, respectively, for building i during the time step t. Parameter S i t is a vector with temperature set points for the building i during time step t. Note that the building's energy cost per time step E G i (t, S i t ) differs from the total energy consumption E i (t, S i t ), since it takes also into consideration the power saving from PV panels (E PV (t)) and the energy from batteries (E B (t)). In addition, by definition, the PPD metric is improved whenever its value is reduced In order to consider these cases, the aforementioned energy cost is formulated in (2). More thoroughly, in case that the ith building's energy requirements (E i (t, S i t )) exceed the sum of energy provided by the PV panels (E PV i (t)) and the batteries' capacity (E B i (t)), the additional demand is met by purchasing energy from the main grid at the current trading price (P(t)). On the contrary, if the energy budget for the desired thermal comfort is available from renewable sources (E PV (t)), the spare energy is stored to batteries (up to their maximum capacity), while the rest is sold to the grid at the current trading price (based on P(t)) Even though the energy cost is easily quantified with metering devices, the residents' thermal comfort can only be estimated. Various approaches are available for this purpose. Regarding our case study, we employ the Fanger thermal comfort [40]. More thoroughly, this model relates environmental and physiological factors in conjunction with the thermal sensation in order to estimate the PPD people in a room. We have to mention that both the energy metering devices, as well as the PPD metric, are not applicable to the online control algorithms since they report results only for previous time steps (up to t − 1). To overcome this limitation, in Section IV-B, we propose two new models for estimating the impact of candidate temperature set points in HVAC's energy consumption and resident's thermal comfort, respectively.
Finally, the factor α in (1) defines the relative importance of optimizing either the energy cost or the thermal comfort objective. Since we tackle a multi-objective optimization problem, it is not feasible a solution that satisfies simultaneously all the objectives. 3 For instance, the improvement of the residents' thermal comfort usually imposes additional energy consumption for cooling/heating the corresponding thermal zone. Throughout this paper, we study three alternative operating scenarios.
1) Mode 1: Achieve a compromise between energy consumption ∀i (E G i (t, S i t )) and thermal comfort metrics ∀i (PPD i (t, S i t )). This operation mode considers that 0 < α < 1, while regarding our implementation we study the case where both energy consumption and resident's thermal comfort are of equal importance (α = 0.5). 2) Mode 2: Minimize energy consumption ∀i (E G i (t, S i t )) while respecting a minimum threshold for the PPD metric. According to the ASHRAE standard [41], [42], any PPD value in the range of 0%-10% is acceptable for residents. Hence, we consider that α = 1, while PPD is up to 10% (3). 3) Mode 3: Optimize thermal comfort (α = 0) without exceeding a predefined energy budget for the experiment's duration (mentioned as AF), as it is formulated by (4) Although the employed decision-making mechanism appears to exploit as much as possible the renewable power sources in order to minimize the amount of energy purchased from the grid, this is not always the case. The dynamic pricing and the energy storage capability further complicate the problem at hand, since the HVAC operation is performed with a lower cost rate. Consequently, we conclude that the problem cannot be considered trivial due to the intermittent behavior of the solar energy, the uncertain building' dynamics, as well as the constant requirement to meet a desired residents' thermal comfort level.

IV. PROPOSED SYSTEM ORCHESTRATOR
This section describes in detail the proposed low-complexity decision-making mechanism for the target CPS. Contrary to the relevant control algorithms, where their efficiency relies on analyzing an excessive amount of historical data, the proposed framework delivers close to optimal results by taking into account only a small subset of information. In addition, our approach computes temperature set points without applying any iterative and time-consuming simulation, while it also does not consider any prior modeling for building's and HVAC's dynamics; thus, it exhibits considerable lower computational complexity.
The introduced orchestrator consists of three steps as shown in Fig. 2. Initially, we manipulate the raw data from various sensors (e.g., indoor/outdoor temperature and humidity, solar radiation, occupants' activity, etc.). As we discuss later, the data manipulation is an enabler for our solution, since its efficiency dominates the overall framework's performance. Then, the energy and thermal comfort models are appropriately refined in order to approximate the building's dynamics. The refinement task is performed by an LR algorithm, where the weights are recalculated once per time step. Additional details about the data manipulation and the models' refinement tasks are provided in Sections IV-A and IV-B, respectively. Finally, we proceed to the decision-making itself, where the temperature set points per thermal zone are computed. Similar to the previous task, the temperature set points are computed iteratively once per time step. For this purpose, a modified version of Knapsack algorithm is employed. Apart from the historical data, the algorithm is fed with the selected operation mode (described at Section III-A), as well as a number of utilities that guide its aggressiveness to improve the energy consumption, the thermal comfort, or any combination between them. Additional details about the functionality of the proposed decision-making mechanism can be found in Section IV-C.

A. Efficient Manipulation of History Data
The first step in our methodology deals with data acquisition from various sensors. This data is temporarily stored in order to improve the accuracy of the employed models. Although one might expect that additional data improves the models' accuracy, this is not the case because it imposes constraints to the refinement procedure. Moreover, since the amount of data increases linearly with the execution time, data storage and processing are becoming challenging aspects, especially at the embedded domain. In order to overcome these drawbacks, our framework employs two complementary mechanisms, namely, the coarse-and fine-grain sliding windows, respectively. Fig. 3 depicts the functionality of sliding windows, which enable a more aggressive model's refinement. More thoroughly, instead of using the raw data acquired from sensors, the coarse-grain sliding window considers only data that refer  to the last x days. A further improvement is achieved with the fine-grain window, which selects a subset of this data referring to a specific time-slot per day (within the coarse-grain window). Thus, instead of manipulating the entire historical data, only a small subset is employed for the model's refinement task [24].
Both the number of previous days (coarse-grain window) and the amount of data per day (fine-grain window) are adaptive in order to balance the problem's scalability and the availability of hardware resources. Note that sliding windows are part of the introduced solution and not an optimization step, as otherwise the excessive amount of data leads to suboptimal solutions for the model's refinement problem.
The sizes of these windows are defined with a detailed exploration under typical weather and residents' activity. The results of this analysis are plotted in Fig. 4, where the vertical axis gives in a normalized manner the overall cost computed by (1). Based on this analysis, the optimal performance (minimization of total cost) is achieved for coarse-and fine-grain

B. Models Refinement
This section describes the procedure for refining the residents' thermal comfort and HVAC energy consumption models. Both of these models rely on a LR technique in order to compute the relationship between a dependent variable y and a number of explanatory variables. The input to this procedure is a subset of historical data, as they are retrieved from the fine-grain sliding window. In Sections IV-B1 and IV-B2, the technical details about this refinement procedure are applied periodically to the employed models.
1) Refine Thermal Comfort Model: Thermal comfort is a condition of mind that expresses satisfaction with the thermal environment. Since this metric depends among others on air temperature, humidity, radiant temperature, air velocity, metabolic rates, and clothing levels, while each person experiences these sensations a bit differently based on his/her physiology and state, thermal comfort is assessed by subjective evaluation.
For the scopes of this framework, we quantify the residents' satisfaction with a new thermal comfort model that correlates the impact of thermal zone's temperature to the PPD value computed by the widely adopted Fanger model [40]. The proposed model is a function of the thermal zone's temperature, since the rest parameters (e.g., metabolic rate, clothing, etc.) are difficult to be measured/controlled, and they are considered as constant for a relatively short period of time.
The outcome of this analysis for a winter day is plotted in Fig. 5. Although this information refers to the winter period, similar results are also reported during summer. Based on the experimental results, the reference solution (blue color curve) is approximated by the square function (red color curve) given in (5), where the T in parameter refers to the thermal zone's (indoor) temperature. For the majority of cases, the difference in temperature set points between consequent time steps is relatively small (typically less than 1 • C). Note that T in for time step t is assumed to be equal to the indoor temperature for time step t −1. 4 Hence, by refining iteratively the θ 1 and θ 2 4 The validity of this claim is proven by Figs. 5, 6, and 13. weights, we minimize the estimation error J for the quadratic optimization problem described by (6) and hence increase the model's accuracy Since the number of features is relative small (in our case they are 1, T in and T in 2 ), it is possible to calculate the weight vector θ c with the normal equation formulated by (7). The computational complexity of this method is O(n 2 × m), where m and n refer to the rows (number of historical data after applying the coarse-and fine-grain sliding windows) and the columns (number of features) of table X c , respectively We have to notice that the concept of sliding windows is enabler for the proposed thermal comfort model, as the majority of Fanger's factors (e.g., metabolic rate, clothing, etc.) are almost constant for the last few days (coarse-grain window), while the region's weather (e.g., humidity, solar radiation, etc.) and the residents'-related parameters (e.g., people per room, their activity, etc.) can be considered similar for a given time slot between consecutive days (fine-grain window).
The accuracy of the proposed thermal comfort model is evaluated against the corresponding results from the Fanger reference solution [40]. The results of this analysis (plotted in Fig. 6) indicate that the average error between these two models is about 0.02% for the entire year. Consequently, the proposed thermal comfort model can estimate accurately enough the PPD metric for the smart thermostat usecase.
2) Refine Energy Consumption Model: This section describes the proposed method for quantifying the impact of temperature set points at the HVAC's energy consumption. Since metering devices cannot be used for the purpose of this study (they measure already consumed energy) such a model is absolutely necessary. Our framework assumes that each smart thermostat constructs its own energy model in order to consider inherent parameters from the associated thermal zone. The data acquired by the building's sensors (input features) for our case includes.  (8), while its formulation with normal equations is presented in (9). At this notation, the θ e 0 . . . θ e 4 denote the weights that are recalculated during the model's refinement procedure, while T out , T in , R, and S refer to the environment temperature, the thermal zone temperature, the solar radiation, and the thermostat's set-point configuration, respectively. Future values for T out and R parameters at this equation are acquired from the weather station, whereas similar to the thermal comfort model the indoor temperature T in for time step t is assumed to be equal to the HVAC's configuration set point for the time step t − 1 5 where The proposed energy estimation model follows a linear approach, which is widely employed in relevant literature [9], [31], [43], [44]. This model was built in the assumption that energy consumption is a linear combination of the parameters 5 The validity of this claim is proven by Figs. 7, 8, and 13 depicted in (8). Toward this direction, two diagnostic plots (namely, the Q-Q and the Residuals-vs-Fit) are provided, as they are depicted in Fig. 7(a) and (b).
More precisely, based on the Q-Q plot, we conclude that the residuals of energy consumption model (blue color dots) are normally distributed. This trend is a prerequisite in order to construct a linear model [45], [46]. Similarly, the horizontal axis at the Residuals-vs-Fit graph [ Fig. 7(b)] gives the fit values of energy consumption, while the vertical one corresponds to the residuals. Since the values at this graph are almost equally distributed around the reference line (horizontal dotted line) and there are no patterns, we claim that our assumption about energy model's linearity is confirmed. Fig. 8 evaluates the accuracy of the proposed model as compared to the actual energy consumption reported from metering devices. According to this study, the proposed model exhibits an average error for the entire year about 2.5%, which is acceptable not only for the scopes of our analysis, but also as a general-purpose energy model for estimating the energy requirements imposed by different temperature set points in advance of applying these selections to the HVAC system.
The overall complexity of the proposed method is equal to O(n 2 e × m), where n e and m refer to the columns and rows of table X e , respectively. Hence, we might guarantee that regarding the selected window sizes, the associated complexity can be sufficiently handled by the majority of existing lowcost embedded devices. Additional details about this topic are discussed later in the Experimental Results section.

C. Decision-Making Algorithm (Knapsack)
Having the outcomes from the thermal comfort and energy consumption models, we proceed to the last phase of our framework, where the system's decisions are computed. This phase exhibits increased computational complexity (especially for the operating mode 3), where typical heuristic solvers (e.g., simulated annealing, game theory, tabu search, etc.) cannot be applied due to the limited amount of resources found in an embedded system.
In order to overcome the lack of processing and storage requirements, the functionality of system's orchestrator is addressed as a modified Multiple-Choice Knapsack Problem (MCKP) [47], [48]: "Given K classes of items  N 1 , N 2 , . . . , N K , where each item j ∈ N i is associated with a profit/value v i j and a weight w i j , the CPS's orchestrator aims to choose exactly one item from each class so that the total weight is less than, or equal, to a given capacity W and the total value is minimized." The problem's mathematical formulation is given by (10), while the objective for minimizing the total value is the main differentiation compared to conventional Knapsack problem At this notation, each class refers to a time step of the thermostat operation. Similarly, an item represents the temperature set point regarding the aforementioned time step, which in turn is associated with a PPD value and its energy cost. Table III summarizes the correspondences between the proposed MCKP algorithm and the problem's parameters for the three operating modes, as they were described in Section III-A. More thoroughly, the objective during Mode 1 operation is to minimize the overall cost function (1). Regarding Mode 2, the Knapsack algorithm aims to find a solution that minimizes energy consumption while respecting a minimum thermal comfort. Finally, Mode 3 aims to maximize thermal comfort (thus minimizing the PPD factor) without exceeding a predefined energy budget from the main grid (AF).  Fig. 9 visualizes the proposed version of the MCKP algorithm for the operating Mode 3. For demonstration purposes in this figure, we assume that each item (time step) corresponds to a day. Also, we highlight the parameters discussed in Table III, namely, the "classes" (time steps), "items" (set points), "item's value" (the PPD value per item), "item's weight" (the corresponding energy per item), as well as the "Knapsack's capacity" that refers to the available energy budget (AF). In order to maximize the efficiency of the proposed decision-making algorithm, thermostat's actions (temperature set points per thermal zone) are computed 1 week ahead. The procedure of decision-making is iteratively applied once per day in order to refine the aggressiveness of thermostat's selections based on the AF and the energy/thermal comfort improvements. Note that such an iterative approach maximizes the algorithm's efficiency because the weather forecast, and hence a number of parameters that affect thermal comfort and energy consumption metrics are more accurate for shorter time periods. For this purpose, data from the introduced fine-grain sliding window are employed.
The previously mentioned MCKP algorithm is an N P-hard problem. The proposed orchestrator initially solves the simplified linear MCKP problem and then expands the core solution based on dynamic programming and by adding the necessary classes [47]. In contrast to relevant state-of-the-art solvers, such as the dynamic programming [48] that exhibits pseudopolynomial time complexity, the solution discussed throughout this paper minimizes the problem's complexity by considering only a few items. More thoroughly, the computational complexity for the decision-making algorithm is O(n +W × N i ∈c n i ), where n is the number of total items, n i the number of items in class N i , and c is the core solution that contains only the classes and items that constitute the solution space retrieved from [47].

V. RAPID PROTOTYPING FRAMEWORK
In Section IV, we discussed in detail the proposed algorithm for deciding upon the system's configuration, whereas throughout this section we introduce a framework for supporting the physical design of CPS orchestrator with rapid prototyping techniques. By the term rapid prototyping, we refer to all those software-supported techniques that shrink the duration of physical implementation phase onto the target device.
More specifically, in the typical top-down approach, the control algorithm is designed without considering explicitly the specifications of hardware resources. The underlying assumption is that the computation and communication capabilities of these resources are sufficiently performing for any type of decision-making mechanism. However, with the advent of more complex control algorithms, the imposition of tighter requirements for higher performance, as well as the scalability aspect of CPS platforms, this assumption is no longer valid, especially for the low-cost embedded devices. Furthermore, various architectural parameters, including sensor accuracy and availability, communication channel reliability and processing power of embedded devices, may have a significant impact on the quality and cost of the final product (smart thermostat).
Inline to this trend, we propose the software-supported framework depicted in Fig. 10 to address the codesign and cosimulation tasks for a CPS orchestrator. The introduced framework also tackles the challenge for orchestrator's refinement in order to take benefit from inherent constraints/specifications posed by the target hardware platform and the employed usecase.
The design of a smart thermostat involves two main components, namely, the control algorithm that determines the system's actions based on the acquired inputs from building and weather sensors and the embedded platform that executes the control algorithm itself. Both of these fundamental components have to be designed simultaneously in a manner that maximizes performance metrics (i.e., system's efficiency to retrieve close to optimal solutions) with the minimum implementation cost (e.g., shorter design time, usage of lower performance processing cores, etc.).
Starting from a detailed model for the studied microgrid environment (e.g., building dynamics, renewable sources, etc.) and the local weather conditions, the proposed decisionmaking algorithm defines iteratively (once per time step) the optimal temperature set points per thermal zone, as it was discussed in Section IV. In order to quantify the efficiency of the aforementioned decisions, our solution relies on the EnergyPlus framework [37], [38] in conjunction to the associated toolboxes (i.e., BCVTB and Ptolemy II) for data transfer between software tools. We have to notice that this is a typical MPC approach, which is currently widely adopted for quantifying the efficiency of control algorithms. Although promising, this solution cannot be implemented onto an embedded platform (e.g., smart thermostat) because it imposes the excessive amount of computational and storage complexities, while it also preassumes that moves forward in time are viable to evaluate the impact of control decisions.
The implementation of decision-making mechanism employs a technique known as Hardware-in-the-Loop (HiL) simulation [6]. More precisely, HiL is a type of real-time simulation, which enables to test the controller's design by showing how the controller under design responds, in real time, to realistic virtual stimuli. In addition, the HiL simulation is useful to determine if the model of the physical plant (the smart thermostat in our case study) is valid. The competitive advantage of HiL simulation compared to conventional HW/SW system development relies on adding the complexity of the plant under control (thermal zones' temperatures) to the test platform through a mathematical representation of all related dynamic systems. Ideally, an embedded system would be tested against the real plant, but most of the time the real plant itself imposes limitations in terms of the scope of the testing.
The proposed rapid prototyping framework addresses this challenge with a codesign approach depicted in Fig. 10 that analyzes the interactions between the control algorithm and the embedded platform through a set of interface variables. More precisely, our framework enables the design of a decisionmaking algorithm that acquires data from multiple sensors and evaluates the impact of control decisions on various CPS performance metrics. For this purpose, a HiL simulation with real-time embedded processor (computer) as a virtual representation of the plant model and a software version of the introduced decision-making algorithm are employed. This approach includes the electrical emulation of sensors and actuators, which act as the interface between the plant and the embedded system under test. The value of each electrically Comparison among alternative thermostat's configuration approaches. emulated sensor is controlled by the plant simulation and is read by the embedded system under test through a feedback loop.

VI. EXPERIMENTAL RESULTS AND DISCUSSION
The experimental results section provides a number of quantitative comparisons that highlight the superiority of the introduced solution, as compared to relevant state-of-the-art approaches. Toward this direction, the proposed decisionmaking mechanism computes temperature set points for the microgrid case study discussed in Table II. The reference solutions to this analysis are: 1) the Ruled Based Configurations (RBCs) 6 ranging from 20 • C up to 27 • C; 2) the wellestablished Fmincon solver [49]; and 3) the former version of our decision-making algorithm based on SVM [24]. The experimentation for this analysis refers to a 52-week duration (winter, spring, summer, and autumn) in order to evaluate the stability of the proposed orchestrator.
In order to highlight that the proposed framework enables the design of efficient controllers, Fig. 11 quantifies the quality of decisions derived from the introduced decision-making algorithm as compared to the reference state-of-the-art relevant solutions. The vertical axis in this figure corresponds to the average cost improvement (according to (1)) achieved by the proposed orchestrator for the 52-week experiment, where both building's cooling and heating are considered.
More specifically, this analysis indicates that the proposed orchestrator exhibits superior performance against to the static RBCs, as it reduces the overall cost ranging from 11% (for RBC 23 • C) up to 168% (for RBC 27 • C). In addition to that, it achieves comparable performance to the previous version of our decision-making algorithm (mentioned as ESL) [24] and the Fmincon solver [49]. Note that the Fmincon solver computes the optimal temperature set points among the studied approaches because it explores exhaustively the design space; 6 RBC is the typical approach for thermostat configuration. The RBC configuration aims to achieve a constant temperature to the target thermal zone. The majority of commercially available thermostats are configured with consecutive RBCs that differ 0.5 • C or 1.0 • C. however, since it is an MPC approach it exhibits considerable higher computational and storage complexities.
To study in detail the quality of our framework's decisions, Fig. 12 plots the absolute difference between temperature set points computed from our proposed system's orchestrator compared to the reference solutions. In particular, the decisions from our orchestrator exhibits an average variation about 0.32 • C and 0.14 • C compared to the Fmincon and ESL solvers, respectively.
The previously mentioned results are retrieved for the selected sliding window sizes discussed in Section IV-A. In order to further validate the efficiency of this selection, we evaluate the accuracy of the proposed thermal comfort and energy consumption models. Since the accuracy of these models guides the decisions of our controller, such an analysis is upmost important. For this purpose, Fig. 13(a) and (b) plot the average value (among buildings' thermal zones) of rootmean-square error (RMSE) for the studied thermal comfort and energy consumption models. For demonstration purposes, in these charts, we highlight the corresponding values for the selected window sizes. Based on the analysis depicted in Fig. 13, we conclude that the selected window sizes for coarse-and fine-grain windows (as they were reported in Fig. 4) reduce the RMSE metric for both models. Consequently, such a selection leads to an acceptable solution for the proposed decision-making mechanism.

A. Evaluation of Mode's 2 Efficiency
This section quantifies the efficiency of the proposed orchestrator to minimize the energy cost while respecting a minimum threshold for PPD metric. For this purpose, apart from the system's inputs (i.e., weather data, residents' activity, etc.), we consider a statement from the ASHRAE standard that temperatures leading to PPD values up to 10% are acceptable by residents [41], [42]. Thus, the optimization objective for this experiment is to minimize the energy consumption (α = 1) under the respect of ASHRAE standard. Although such a statement usually is ignored by typical optimization functions (they emphasize solely on overall cost reduction), it enables considerable flexibility to the controller's selections, since the  further reduction of PPD's value imposes energy consumption for heating/cooling. In order to take into account this goal, the proposed orchestrator employs the operating Mode 2, where the computed temperature set points correspond to PPD values up to 10%. For this purpose, multiple set points per thermostat (thermal zone) are evaluated iteratively once per time step with the introduced energy consumption model. Fig. 14 evaluates the efficiency of this operating mode in term of energy consumption as compared to the corresponding selections from the operating Mode 1, the Fmincon, and ESL solvers. Based on these results, our orchestrator achieves an average reduction at energy consumption by 27% compared to rest solvers.
In order to depict that the proposed orchestrator respects the ASHRAE standard, Fig. 15 plots the PPD values for the previously mentioned controllers. For demonstration purposes, in this figure, we also highlight the 10% PPD threshold, as it is defined by the ASHRAE standard [41], [42]. This analysis indicates that the proposed Mode 1, the Fmincon solver, as well as the former version of our decision-making algorithm (ESL) exhibit comparable efficiency since they achieve average associated PPD values about 6.7%, 6.5%, and 6.8%, respectively. On the contrary, the introduced operating Mode 2 leads to a slightly increased PPD value (on average 9.3%), but it is still lower than the 10% threshold defined by the ASHRAE standard (except from a few spikes). Note that Mode 2 is not possible to respect always the ASHRAE standard due to various nonpredictable constraints, such as the building's dynamics and the weather forecast (e.g., solar radiation); thus, small fluctuations in this metric up to 2% are expected in order to enable the previously mentioned average improvement in energy consumption by 27%. According to the previous findings, we claim that our proposed decisionmaking algorithm can address more efficiently the goal of maintaining affordable indoor thermal conditions with the minimum possible energy cost, as compared to state-of-theart similar approaches.

B. Evaluation of Mode's 3 Efficiency
The third mode considers a case where the smart thermostat minimizes the PPD metric without exceeding the available energy budget (α = 0 at (1)). The aggressiveness of this optimization is defined by the AF parameter, which denotes the available energy budget from the main grid. As already discussed, if the energy from renewable sources is not enough to meet the residents' demand, additional electricity is purchased from the main-grid (by decreasing the value of AF parameter). Otherwise (i.e., when the availability of renewable sources exceeds the demand), the spare energy can be either stored in batteries or sold to the grid (by increasing the AF's value). The selection of the preferred strategy depends on the dynamic pricing, the batteries' capacity, as well as the estimated buildings' demand in the near future [50]. Both energy purchasing and selling from/to the grid are conducted according to dynamic pricing rates P(t).
The task of computing temperature set points for the previously mentioned problem is addressed with the Multiple-Choice Knapsack algorithm discussed in Section IV-C. Regarding our analysis, and without affecting the generality of the introduced solution, we consider that the reference value for the AF metric is defined by the Fmincon solver for the entire experiment's duration (52 weeks). Two instantiations of Mode 3 are evaluated throughout this section, where the initial energy budget (AF) is set to 80% (underestimate scenario) and 120% (overestimate scenario), respectively, of the corresponding energy budget required by the Fmincon solver.
In order to evaluate the efficiency of this mode, Fig. 16 plots the variation of PPD metric for the studied operating scenarios. These results indicate that the underestimated version of our algorithm [mentioned as "Mode 3 (80% of Fmincon)"] exhibits on average 28% higher PPD value compared to the reference solution, whereas the overestimated version ]"Mode 3 (120% of Fmincon)"] leads to an additional PPD reduction by 3% on average. Even though the Fmincon solver (reference solution) exhibits superior performance in this analysis, the proposed solution is also affordable from the residents, since there are only a few spikes where the PPD metric exceed the 10% threshold defined by ASHRAE standard. Note that the selected underestimate and overestimate scenarios are indicative, as at the run time the system's orchestrator is not aware about the efficiency of offline control algorithm (Fmincon solver).
Apart from the variation of PPD metric, we also expect energy savings from our orchestrator. Fig. 17 evaluates this topic for the aforementioned operating scenarios. The results indicate that the underestimated scenario achieves on average energy saving by 20% compared to the reference solution (Fmincon solver), whereas the overestimate scenario (120% of Fmincon) needs an additional energy budget equals to 14%. The goal of this experiment is to highlight that the proposed orchestrator respects the AF limit.

C. Evaluate Hardware Implementation
Finally, we provide a number of experimental results about the physical implementation task of the introduced system's orchestrator. For this purpose, the efficiency of alternative controllers discussed throughout this paper is quantified with the proposed HiL simulation discussed in Section V. For evaluation purposes, we evaluate the previously mentioned controllers to various architectures, including microcontrollers (ARMx STM32F103 at 72 MHz), embedded processors (ARM37x Cortex-A8 at 1 GHz, Intel Quarkx1000 at 400 MHz), and processing cores found in typical BEM systems (Intel i7-6700K at 4 GHz). Fig. 18 quantifies the number of execution cycles in order to compute temperature set points per thermal zone regarding the operating Mode 1. For this analysis, we consider that the underline device is a Beagleboard embedded processor (ARM37x Cortex-A8 at 1 GHz) and a BEM system (Intel i7-6700K at 4 GHz). A number of conclusions are derived from this analysis. More specifically, both the proposed and the ESL controllers exhibit similar performance with small fluctuation in execution time mainly due to the architectural differences found in the underline computational platforms. In addition, the proposed orchestrator exhibits significant lower complexity (about 8 orders of magnitude) compared to the Fmincon offline solver. This conclusion is also inline to the theoretical discussion about the complexity analysis found in Section IV. For the sake of completeness, we have to mention that Fmincon cannot be executed onto an embedded platform (low-cost device), as it imposes MATLAB-based simulations.  In order to study in more detail the execution time of our orchestrator, Table IV summarizes this metric for the three operating modes. These results highlight that our decisionmaking framework is able to compute a temperature set point per building's thermal zone in less than a second, even in the case where the target platform is a low-performance microcontroller (ARMx STM32F103 at 72 MHz). Furthermore, we have to mention that the additional execution time for Mode 3 is because temperature set points are computed for all the thermal zones a week ahead. Consequently, this analysis indicates that one low-cost platform can be used to control in optimal way indoor temperatures for multiple thermal zones, which is not feasible for the state-of-the-art Fmincon offline solver (due to the inherent computational complexity).

VII. CONCLUSION
A framework for the hardware implementation of low-cost orchestrators for CPSs, was introduced. For demonstration purposes, the framework was employed to control HVAC configuration in a microgrid environment. Toward this direction, novel models and algorithms were proposed and their implementation as a low-cost embedded system was evaluated. Experimental results for representative weather conditions shown the superiority of the proposed solution against state-ofthe-art relevant algorithms as it achieved comparable performance but with significantly lower computational and storage complexities.