Weighted Constraint Satisfaction for Smart Home Automation and Optimization

. Automation of the smart home binds together services of hardware and software to provide support for its human inhabitants. The rise of web technologies offers applicable concepts and technologies for service composition that can be exploited for automated planning of the smart home, which can be further enhanced by implementation based on service oriented architecture (SOA). SOA supports loose coupling and late binding of devices, enabling a more declarative approach in defining services and simplifying home configurations. One such declarative approach is to represent and solve automated planning through constraint satisfaction problem (CSP), which has the advantage of handling larger domains of home states. But CSP uses hard constraints and thus cannot perform optimization and handle contradictory goals and partial goal fulfillment, which are practical issues smart environments will face if humans are involved. This paper extends this approach to Weighted Constraint Satisfaction Problem (WCSP). Branch and bound depth first search is used, where its lower bound is estimated by bacterial memetic algorithm (BMA) on a relaxed version of the original optimization problem. Experiments up to 16-step planning of home services demonstrate the applicability and practicality of the approach, with the inclusion of local search for trivial service combinations in BMA that produces performance enhancements. Besides, this work aims to set the groundwork for further research in the field.


Introduction
As human lifestyle has become increasingly hectic, smart home starts to gain more prominence.Smart home is a viable solution to provide comfort for its human inhabitants, monitoring, and caregiving for the elderly.Demographic shifts towards elderly people for developed and some developing countries are a serious issue, where caregivers are in short supply relative to the population of the elderly, which is a serious issue in Japan as the elderly population is expected to reach 25.2% of the total population.Many of them will lose the ability to live independently [1,2].With the rising number of the elderly coupled by hectic lifestyle of the working class, the elderly cannot be provided with ample care that they need.Therefore, it is necessary for the home to provide support to handle mundane tasks and to ensure the continual welfare of its human inhabitants.
Smart homes need to provide services based on the devices that they are connected to.Given the available devices and initial state of the house, smart homes should coordinate their services in order to reach the maximum number of goals set from either human command or event triggered by generating an optimal sequence of plans.An optimum plan can mean a plan that minimizes energy consumption or maximizes comfort.For this paper, optimization is defined as minimizing a certain quantifiable cost.Besides that, the plan should also abide by constraints such as user preferences and physical limitations.An example of constraint related to user preference is the need for a room to be well lit when the user is in there while awake.An example for physical limitation constraint can be that the curtain needs to be open before the window can be swung open.
Researches related to web services and semantic web provide concepts and technologies that can support service discovery, the design and implementation of services, and providing machine understandable semantics for reasoning.The idea is adopted by ubiquitous and pervasive computing due to its ability to discover services and support for late binding of services.

Advances in Artificial Intelligence
Advancements in the web of things and web service technologies can shed light on service composition for building automation of the smart home.Similarities are quite significant, where both are dealing with high heterogeneity of objects, dynamic environment due to objects connection and disconnection from the system or due to contextual changes, and the need for integration and coordination of different objects to deliver complex services.Service oriented architecture (SOA) [3] complemented by automatic service composition provides the crucial approach in delivering what is required of home automation.SOA consists of independent but interoperable services that are loosely coupled, where each service only exposes its functionality to others, keeping the details of implementation hidden.
As argued by [4,5], the main focus of previous platforms of pervasive applications does not consider complex and intelligent functionalities involving higher levels of information.Dynamic composition of complex sequence of services under uncertainty is necessary.Currently, to enable higher functionalities, tedious procedural programming is required from the user side.Besides, certain applications require manipulation and reading of values, such as counting the number of times a person goes to the toilet.Reference [4] uses artificial intelligence method, namely, constraint programming, to handle such service composition task where variables of a wider domain are required in the planning process.It performs service composition through solving constraint satisfaction problem (CSP) and implements individual services by appropriate devices.Hard constraints are used, and therefore the approach cannot (or at least very inefficiently) support optimization and partial goal fulfillment.Partial fulfillment of goals is important because certain goals might contradict each other or because they might be too complicated to solve in one go.For this, solving via hard constraints will conclude that the goal is unsatisfiable instead of trying to fulfill as many goals as possible.
For example, a given mother is requesting the TV to switch to channel 1, whereas her daughter requests channel 2. These two goals contradict each other.Service composition via hard constraints will conclude that the goals are not satisfiable, instead of trying to fulfill one of their wishes (such as switching to channel 1 to fulfill the mother's wishes as the goal imposed by her is considered much more important compared to the daughter).Such problems can be solved with soft constraints by introducing weights.
This work is built on the previous work on Informationally Structured Space (ISS) [6] by providing it with automated planning and optimization.It aims to extend the smart home automated planning approach in [4] from using CSP to Weighted Constraint Satisfaction Problem (WCSP).WCSP endows constraints with weights, which transforms them into soft constraints where optimization can be implemented.Branch and bound with depth first search is applied to solve the planning problem represented as WCSP, where the lower bound is estimated via bacterial memetic algorithm (BMA).Memetic algorithms have been shown to be effective in handling weighted constraints that give good enough solutions [7].Test on various plan sequences and modifications shows the applicability of the approach in generating optimal plans in fulfilling the maximum number of goals.It lays the necessary groundwork and obtains implications for further development.This work will not cover the middleware implementation.Services are described by preconditions, effects, and properties, which resemble those of web services, such that they can be easily translated to current web service technologies.
This work is on high level planning.We like to consider smart devices such as the Google Nest that is capable of learning and adjusting as a composed service that we can call upon, or there are inferred results, which can be used by planning.This is likened to the automatic setup of surveillance system or robot navigation to a certain cabinet in a certain room.The former can be achieved through service composition via association with SWRL or SPARQL language [8].The latter can have a built-in path finding algorithm that works with high level planning, where high level planning has to ensure proper working environment for low-level functions [9].Theoretically, planning itself can handle all the tasks, including device association and low-level path finding.But, due to efficiency issue, it is considered that composed service and low-level tasks can be called upon as an actor of a particular planning operator.
The outline of the paper is as follows.Section 2 discusses the related works on home automation and service composition.The approach to solve planning problem through WCSP is presented in Section 3. Experiments are provided in Section 4 to demonstrate the applicability of the approach.Finally, the work is concluded in Section 5.

Background
The main focus of this paper is on home automation.Various home automation systems have been developed over time that employ the SOA architecture complemented by web technologies.
Home automation for inferring environment state is developed in [10].It uses DogOnt ontology [11] to determine environment states like whether a certain room is smoke-free and mosquito-free depending on which rooms are adjacent and whether certain doors or windows are open or not.This work shows that additional information of environments can be inferred by defining a set of rules.Although it does not include service composition, since it only deals with sensors, nevertheless, it provides insight into generating rules as goals for service composition to work on.
The work in [12] uses knowledge representation and automated reasoning to create a self-adapting framework for managing user profiles and device services.Rule matching need not be exact, where it allows potential or intersection matches, which is the case in most practical situations.It supports partial or disjoint matches, where requests and supplied resources have conflicting features and when no other matches are possible.Service composition is performed through constant running of concept abduction algorithm [13] and selecting services to cover missing features.But such service composition will not be applicable if complex sequence of service is needed.Situation is made worse under uncertainty.A more flexible system is developed in [14], where the case study is to maximize human comfort and energy efficiency.
Building automation adopting SOA and device profile for web service (DPWS) is proposed in [5].Context information is obtained for processing before being used to guide service composition, complemented by policy rules and composition plans.To handle dynamic changes during service composition, it uses service composition plans to describe users requirements by Composition Plan Description Language (CPDL).Similar to [12], service composition does not support construction of complex sequence of services, such as the case of robot query on users preferred activity before preparing the environment for such activity.
Kaldeli et al. [4,15] developed a home automation service composition based on SOA that is capable of complex composition of a sequence of services using constraint programming.Unlike previous methods, the system does not require manual construction of subplans.It handles context awareness and is able to deal with an uncertain situation by dynamic replanning.By using constraint programming, it can also handle variables with large domain efficiently.But the work employs hard constraints.It cannot fulfill partial goals as well as optimizing plans.
Home automation requires service composition to be functional.Here, we will review some service composition methods that are applied or are closely overlapping with the methods used in home automation.More detailed review on service composition can be obtained from [16].
In [17], OWLS-XPlan uses the semantic descriptions of atomic web services defined in OWL-S for planning purposes.Given the atomic services, the XPlan planning module will generate the sequence of services to fulfill a goal.In the work, an XML dialect of planning domain definition language (PDDL) is developed; thus, the system is PDDL compliant.Although the system obtains semantic descriptions in OWL-S, it is not utilized and semantic awareness is not achieved.Exact matching for service inputs and outputs is required from the planning module.This is the downside, as the most practical situation does not allow exact matching.
A framework developed in [18,19] converts web service composition tasks into planning problems expressed in PDDL.The framework will then convert the devised plan into an OWL-S composite process description.The framework translates atomic OWL-S processes to planning operators, from which it derives the set of actions to achieve goals.Contrary to [17], when no exact composite services can be found, semantic information is utilized to obtain composite services that best approximate the goal.
To deal with complex tasks and to reduce planning complexity, hierarchical task network (HTN) [20] is introduced.It uses method definitions in its planning domain description, which specifies how the complex tasks can be broken down into more manageable tasks [21,22].The planning problem can then be specified as a list of tasks to perform.The planner will then solve the problem by applying the breaking down of tasks to every task in the task list.This process continues until the tasks are reduced to their atomic planning operator constituents that correspond to a solution plan.The main disadvantage of this approach lies in the fact that the planning process requires that certain decomposition rules be specified due to its hierarchical nature.This means that it needs to be encoded in advance by an expert.The methods discussed thus far either require exact matchups between inputs, outputs, and variables or assume certain ontologies to handle heterogeneities or require specifications of user intention and procedural templates.Domain and goal modeling through CSP is developed to create a language that allows users to express goals without having to know about the details and interdependencies between services [4,15,23].Its domain representation is of similar concept to the Multivalued Planning Task (MPT) encoding [24].Besides, another advantage is that it is able to handle variables with large domain efficiently, which is quite prevalent in the field of autonomous home such as temperature value and user location.Although the CSP planner might be slower than some state-of-the-art methods [22,25,26], it can support complex goals and can handle variables with large domain efficiently.To be able to support optimization capability, constraints need to be endowed with weights, thus extending CSP to WCSP.

The Proposed System
A system to compose complex plans that are optimized is built based on WCSP.This section will first consider the domain description of the problem and how representing the planning problem as CSP and solving it help generate complex plans to achieve goals.The CSP approach described is based on the work of Kaldeli et al. [4].Subsequently, extension to WCSP through branch and bound method will be explained.

Planner Module.
This section introduces the planning/ implementation process devised for performing automated planning and execution under an uncertain situation.Figure 1 shows the flow chart of the planning and plans implementation process, which is central to the planning/implementation block of the ISS framework.With the services that come from devices connected to the ISS, the planner will plan a sequence of actions to be implemented to fulfill goals.
Variables are instances to record knowledge (termed as knowledge variable) or act as a switch pertaining to a corresponding object (termed as effect variable).An example of a knowledge variable is the variable that records room temperature.For effect variable, an example is a variable , which turns the TV on if it is of state 1.
An activity is a service that is being wrapped with appropriate parameters, effects, and preconditions.Examples are shown in Tables 1 and 2. At planning stage, information of devices associated with the activities is obscured from    the planner.Activity's role is to manipulate the values of the variables, which have correspondence with the physical world associated during variable binding.An activity contains preconditions and effects.Preconditions are conditions that need to be true before the activity can be executed.Effects are the changes that the activity makes when the activity is finished without any glitches or unforeseen circumstances.
The following is the explanation for the process flow shown in Figure 1.The system starts at state −1, where initialization is performed and connection is set up.At this stage, it is required that variables are already bound and activities are ready.The system will restart at stage −1 if there are changes to the number of variables and services due to device connection or disconnection or failure.After initialization, goal is obtained and planning is implemented.If a sequence of activities is found that can fulfill the goal, the system will proceed to stage 1.Otherwise, it will proceed to stage 4, indicating a failure.Stage 1 deals with getting the next activity in sequence to be executed.After the next activity is selected, it will proceed to stage 2, which is orchestration of activities.Before execution occurs, it needs to check whether the precondition is fulfilled, upon which, if not, it will proceed to stage 0 for replanning.If the precondition is fulfilled, activity is executed by sending command to the relevant devices.After the device finishes executing the activity, the system will proceed to stage 3. Connection loss or device failure is bound to happen, which will delay or stop executing the activity altogether.Given this situation, stage 2 has a timeout threshold, upon which if the threshold is reached, the system will assume that the current plan does not work and proceed to stage 0. Despite being not implemented yet, this event can be logged to record the number of failures a certain device faces.This can help determine the quality of service of the devices, such that it can be used as a weight when selecting services.Stage 3 checks for 2 things: whether there is any activity left for execution (if true, the system will proceed to stage 1 to get the next activity) and if there is none, it will check whether the goal is fulfilled or not.If the final goal is not fulfilled, then it will proceed to stage 4, otherwise, to stage 5, indicating a success.Given stage 4 or stage 5, the system will proceed to stage 6.Stage 6 records a log of past events, obtains a new goal, and proceeds to stage 0. Stage 0 is similar to stage −1 except that it does not need to perform initialization.[15].We denote  as variable set (list of variables). contains  variables, which consist of knowledge, effect, and response variables confined by their own domain.Response variables represent information that can only be obtained from objects, information that comes from sources not within .During planning stage, response variables remain the same throughout all planning sequences and represent an unknown value (thus, initialization constraint is imposed on them).From [15], the response variables can take on whatever value to facilitate constraint satisfaction during planning that employs an optimistic approach (values taken on by response variables are considered true).

Preliminaries. Domain description for activity planning is based on the work of
A state is a tuple of values to variables at a particular plan implementation sequence with index  that is denoted as   = ( 1  ,  2  , . . .,    ), where  1  ,  2  , . . .,    ∈   , confined by their domains denoted by  1 ,  2 , . . .,   .As there is a finite limit to the number of sequences per plan being planned denoted as , thus, 0 ≤  < .For the current work, domains of the variables remain unchanged over time.
is the set of activities, where  = (id(), precond(), effect()) ∈ .id() is the identifier of the activity.There is an additional activity in  that does nothing.It has no preconditions and effects, termed as Nop.
precond() is the precondition that needs to be met before the activity can be executed, such as the location being known as a precondition to implement the weather forecast web service.Precondition of an activity can be described as follows: where var ∈ , val is a constant, ⊙ ∈ {+,−} is a binary operator, • ∈ {=, <, >, ̸ =, ≤, ≥} is a relational operator, and Brel is a Boolean relation.
effect() is the changes that will be induced after the activity is completed.It emulates how the variables will change given the activity is run by its corresponding objects such that its logical formulation can be used to impose constraints on subsequent sequence of the plan for activity planning.It should be emphasized that the actual object manipulates variables during run-time after planning instead of the effect() formulation (which is only used for planning).Effect of an activity can be formulated as or a combination of the following: var +1 = val, var +1 = var  , and constants and  is the sum, subtraction, and Boolean operation.
Given the goals, which are represented as propositions, activity planning can be obtained to fulfill the goal by representing the problem as constraint satisfaction problem (CSP) and solve it [4,15].A constraint satisfaction problem is a triple CSP = ⟨, , ⟩, where  is a set of variables,  is the set of domains of the variables in , and  is a set of constraints over . consists of every state up to index , where  = { 1 ,  2 , . . .,   } ∪ { 1 ,  2 , . . .,  −1 } ∪ ,  is a set of response variables, and   ∈  is the chosen goal at sequence index .A solution to a CSP is an assignment of values to the variables in  such that the values fall within  and all constraints in  are satisfied, which is normally obtained from backtracking methods [27].
consists of constraints imposed by a chosen activity at  from activity preconditions and effects, law of inertia, initial and final variable state, and maintenance of achieved goal constraints.Initial variable state is just a constraint that dictates the values of all variables (obtained from object state module) before any planning.Final state constraint consists of the goal proposition that needs to hold at sequence index .

Constraints from activity preconditions:
(  = ) → precond () , where ∀ ∈ . ( Constraints from activity effects: where ∀ ∈ , where Fr is the law of inertia, which indicates that for every other variable var (excluding those from ) not affected by effects  (), var +1 = var  .
Maintenance of Achieved Goal Constraint.This constraint dictates that whenever a goal is achieved at sequence index  <    = Nop, where  <  < ( − 1) .
Maintenance of achieved goal constraint is just one of the goals specified in [15,23], though it is sufficient for the current work.
There are 3 types of variables during planning, which are knowledge, effect, and response variables.Knowledge variable stores a piece of information that can be referred to in the future.Associated with every knowledge variable is a flag that indicates whether the information is updated or not (in this paper, these are variables with subscript Known).Effect variables record the state objects are in.Every effect variable has a flag to indicate whether the state is changed or not (the variable is indicated by a subscript Changed).Response variables represent information that can only be obtained during run-time.Details on how these variables work can be found in [15,23].
To increase the speed of the constraint satisfaction solver, only activities that are relevant to the given goals are selected.This work employs the same method used by [28].Irrelevant activities to the goal are pruned out to reduce the search space.For every activity   , a list of other activities that has at least one effect that has the potential to satisfy one of the preconditions of   is found.Backward action chain is then computed.This chain of actions can be used to select the activities that are relevant to the imposed goal. act is denoted as the set of relevant activities.An interesting alternative is to use dependency graph as proposed in this work [29] or to divide all the activities into effects ontology to shortlist relevant activities [30].
CSP approach employs hard constraints, which are fed to a solver to obtain a sequence of  that are the activities that need to be implemented to fulfill the given goals.One example of state-of-the-art solver is Z3 SMT solver, which can efficiently obtain the plan given hard constraints [31].The plan will be solved by continually increasing  until the constraints are satisfied.Such solvers cannot handle soft constraints to perform optimization and partial fulfillment of goals, or at least not efficiently.
A Weighted Constraint Satisfaction Problem (WCSP) can be described as a tuple ⟨, , ⟩ [32], where  =  1 ,  2 , . . .,   ∪ ,  is the set of domains of the variables in , and  is a set of weighted constraints.One can think of  as  with all the constraints  having infinity as weight values Weight().The objective function is the sum of all functions in : The goal is to find the instantiation of all variables such that it minimizes the objective function.
Various approaches have been used to solve general WCSP, which includes search, clustering, and variable elimination as explained in this paper [33].Good heuristics used can also further hasten solving process [34].Our problem is specific to planning with domain description described previously.Therefore, internal structures can be exploited to build a solver that is specially tailored for plan composition via solving WCSP.Branch and bound with depth first search is used due to polynomial space complexity and the ability to handle constraints of high arity and wide domain, compared to methods like variable elimination [35] (though variable elimination can be combined with search to obtain a much better result [33]).Besides, using a relaxed condition of the former planning problem as shown in Section 3.5, lower bound can be easily obtained to prune the search graph.

Design of Automated Planner.
Given an initial state (or initial variable instantiations), an optimized plan means a plan that can fulfill the maximum number of goals with the least number of activities (or with the least cost given the sum of the costs for all activities), where the sequences of activities need to abide by their individual precondition and effects described in Section 3.2.
Goals are constraints for the final possible variable instantiations.For example, if the goal is  ∨ , then final state should be   = 1,   = 0 or   = 0,   = 1 or   = 1,   = 1.Weights associated with every goal are imposed as costs if the goal is not fulfilled in the final state.
Constraints imposed by activities are the preconditions and effects.An activity can only be implemented if its preconditions are met.For example, a TV can only change its channel given the precondition that the TV is on.At the same time, it is considered (at least in planning phase) that effects of activities will definitely change the subsequent state (e.g., the act of changing TV channel will result in a change to the preferred channel).Due to uncertainty, effects might not give the desirable response during actual execution.But this is not an issue given the dynamic planning framework described in Section 3.1, which supports replanning.That said, constraints from preconditions and effects are treated as hard constraints unlike goal imposed constraints.
Activities themselves also come with weights.But unlike weights for constraints, these weights are imposed when an activity is implemented.They act as costs for their respective activities.This is important as there are times when one prefers certain activities to others.For example, during late night, a person might prefer the dimmer light to be switched on instead of the brighter ones.Therefore, the action to switch on the brighter light imposes a higher cost than its dimmer counterparts.
It is assumed that weights are determined depending on situation and time.But this paper does not deal with weight settings.Our intention is that, given a set of constraints and weights, the system will try to generate a sequence of activities as plans that is optimum.In order to achieve that, it needs to minimize the following cost function: where (  ) is the weight for implementing activity   and (  ,   ) gives the cost given whether or not precondition for   is fulfilled by state  at sequence .Due to precondition being a hard constraint,  will return infinity if precondition is not met.Â ∘  0 =  −1 ∘  −2 ⋅ ⋅ ⋅  1 ∘  0 ∘  0 , which gives the final state   when activity  0 is implemented on state  0 , followed by  1 , and so on until finally  −1 .
() = ∑ ∈Goal Weight(, ), which gives the total cost imposed by nonfulfilled goals.Weight(, ) is different from (5) as it only considers variables at the final state sequence, whereas (5) considers variables of all sequences.
Case 2. Activity sequence is generatorON ⇒ lightON.Execution of the plan will result in final state ⟨1, 1, 0⟩.All preconditions are met; thus,  returns a total of 0. Total cost of activity is 5. Since goal 1 is not satisfied,  returns 4. Total cost is 9.
Case 3. Activity sequence is lightON.Since the initial state is ⟨0, 0, 0⟩, precondition is not met. returns ∞, rendering subsequent calculation trivial.Equation ( 6) tries to find a sequence of activities that is optimal.Due to the use of logical constraints, optimization becomes complicated.Direct search is intractable, aggravated by hard constraints and its weights from .
Equation ( 6) can be relaxed by eliminating  and, in turn, reformulated as goals.Problem reformulation is explained in Section 3.5.The relaxed optimization problem can then be used to calculate the lower bound for branch and bound via BMA explained in Section 3.6.
The planning representation as well as the heuristics used for optimization in this work assumes nonparallel encoding.

Branch and Bound Search.
Search tree represents the possible paths to reach potential solutions.For our planning problem, every layer of the tree is a particular sequence of activity, which in our case has a total of  layers.Every node is a particular state.Edges are the actions taken, which transform   to  +1 .Figure 2 shows an example of the search tree for planning.
Depth first search branch and bound works by choosing a path that gives the best estimated cost, where the best estimated cost of the nodes for every layer except the layer of the leaf nodes is estimated via a heuristic function , given its previous cost. estimates the best possible cost to reach the goal state by using the relaxed optimization problem, which combined with previous cost gives the lower bound.A potential solution is reached when the path reaches the leaf nodes.Total cost of every potential solution will be compared with the upper bound, upon which if lower, the upper bound will be updated.Branch and bound reduces the number of search paths by pruning branches of the respective nodes where their lower bound is higher than or equal to the upper bound.
coincides with pairs listed in the local search lookup table, where the lookup table is explained in Section 3.7.The activities are then sorted according to their lower bounds to determine which activity should be branched out further for evaluation.If UB is lower than or equal to an activity's lower bound, that branch and the subsequent branches in the sort list are all pruned out.
Currently, we assume goals to be the desirable final state.Sometimes, extended goals that dictate how a plan is arranged instead of the desirable final state are needed.For example, the generator should not be switched when any electrical appliances are turned on.Algorithm 1 can be extended to support extended goals by treating such goals as preconditions for activities, such that the part Preconditions for  are met and LSh Check() in Algorithm 1 can prune out inconsistent activities.The part can also be modified to support weighted extended goals such that unfulfilled extended goals will impose a higher cost on the activity.Extended goal is subject to future work.

Relaxing Optimization Problem.
To obtain a larger feasible region by removing restrictions, ( 6) is relaxed by converting the (•) component to goals, which gives

𝐺𝑐(•) varies from 𝐺𝑐(•) in the sense that it considers not only cost from fulfillment of goals, but also extra subgoals introduced by the conversion of 𝑃𝑐(•).
Conversion is done under the concept that whenever an effect of an activity takes place, its precondition has to be met.Therefore, subgoals are constructed in such a way that if a variable holds a certain value in the final state and that it is different from its initial value, it implies that one of the preconditions of activities which subject that particular variable to hold that value has to be true.Currently, only variables of Boolean type are considered for conversion.Other types such as integer and finite domain sorts are subject to future research.Conversion of variables is limited to 4 types of effects pertaining to the variable, which are  fl 0,  fl 1,  fl var, and  fl ¬var, where var is a variable.The first two types of conversion are shown in Algorithm 2. The third type is shown in Algorithm 3, whereas the fourth is shown in Algorithm 4. The number of generated subgoals is denoted by SG.Extra subgoals equipped with weights reduce the effective branching factor.Optimizing the relaxed problem thus gives a better lower bound.

Bacterial Memetic Algorithm
Optimization.Bacterial memetic algorithm (BMA) is applied for finding the optimal solution for the relaxed optimization problem discussed in Section 3.5.BMA is a population based stochastic optimization technique which effectively combines global and local search in order to find good quasi-optimal solution for the given problem [36].In the global search, BMA applies the bacterial operators, the bacterial mutation, and the gene transfer operation.The role of the bacterial mutation is the optimization of the bacteria's chromosome.The gene transfer  In case of evolutionary and memetic algorithms, we have to discuss the encoding method and the evaluation of the individuals (bacteria) as well.The encoding of the individual is a sequence with −1 indexes.The evaluation of the bacteria is calculated by BMA's task is to generate a sequence of activities Â (from a pool of activities from  act ) such that Cost is minimized.The operation of the BMA starts with the generation of a random initial population containing  ind individuals (see Algorithm 5).Every individual is a particular sequence Â.Next, until a stopping criterion is fulfilled (which is usually the number of generations,  gen ), we apply the bacterial mutation, gene transfer, and local search operators.Bacterial mutation creates  clones number of clones (copies) of an individual, which are then subjected to random changes in their genes (see Algorithm 6).The number of genes that are modified with this mutation is a parameter of the algorithm ( bm ).After the bacterial mutation, the gene transfer operation is applied at population level (see Algorithm 7).This means copying genes from better individuals to worse ones.For this reason, the population is split into two halves, according to the cost values.The number of gene transfers in one generation ( inf ), as well as the number of genes ( gt ) that get transferred with each operation, is determined by the parameters of the algorithm.The last operator in each generation is the local search, which performs reparation of all individuals, using a lookup table, which describes conflicting values in the neighborhood genes of the bacterial chromosome.
Bacterial memetic algorithm has been successfully applied to a wide range of problems.More details about the algorithm can be found in [36,37].

Local Search.
Combinations of activities that produce trivial effects should be avoided.Examples of such combinations are turning on and then off the lights and turning the light on two consecutive times.
In this work, we only assume combination of two.To obtain a list of such trivial pairs, all activities are paired with other activities, including themselves.Given an initial state, a pair of activities is considered trivial if the state after their execution is the same as the initial state.The list is generated according to the activities available before the search commences.
This list is used by BMA to perform local search and better reparation.The local search list is also used in branch and bound search through LSh Check.It determines whether branching out of a particular activity is redundant given the previous activity, thus reducing search space.

Experiments and Discussion
4.1.Setup.Smart home automation is built up from an assortment of devices that are loosely bounded, where they interoperate to provide services.Since they are loosely bound to each other, they do not know anything other than the activities they can provide themselves.Examples of such atomic activities are shown in Table 2. Preconditions and effects are shown as first-order logic (FOL) to save space.In actual implementation, the formulas are all grounded.
Activity Nop has weight wNop = 1.Every other activity has weight greater than that of Nop.This means activity Nop is preferred over others after the goal is achieved.Subgoals (not goals) have weight wSG = 1.Every goal (not subgoals) has weight = ×wNop+SG×wSG.This puts goals as having higher priority than activities and subgoal fulfillment.
Since the purpose of this paper is not on ways to set weights, but to come up with an optimized plan around predefined weights, weights are set for the purpose of experiments.The same case applies to goals.Goals' initial conditions and weights (termed configurations) are specially designed such that optimal plans consist of 4 to 16 steps of activities.These assortments of configurations will be randomly chosen given the number of steps of the optimal plan during test.
As an example, assume  = 10.Table 3 shows the activities in this example.All formulas are grounded.Boolean term is treated as an integer of 1 and 0.
Therefore, the optimal plan is 4 steps with optimal cost 24.
If instead the planner gives the following solution: From the tables,  gen of 8 and 10 has a more consistent result with increasing  ind .Besides, general performance is better compared to the lower  gen values.The downside is their time consumption in order to obtain the solution.For the subsequent tests,  gen = 10,  ind = 3, and  clones = 3.
From the tables, with  gen = 10 and  clones = 3, the performance is more consistent and nearer to the optimal solution. ind will remain at 3 due to time consumption constraint.search, (3) planning with LSh Check and without UB Refine and local search, (4) planning with both UB Refine and LSh Check but without local search, and (5) planning with UB Refine, LSh Check, and BMA local search.Modifications 1 to 4 can be seen as Bacterial Evolutionary Algorithm, while modification 5 is the bacterial memetic algorithm.Each modification is run 20 times.There is no time threshold; therefore, for every test run, the planner will proceed until full search is completed.Figure 3 shows the result on distance from optimum cost, with the tests planning time shown in Figure 4.

Planning
It can be observed that inclusion of UB Refine and LSh Check can help improve performance in terms of approaching the optimum cost, although LSh Check has a wider distribution compared to UB Refine if applied individually.With the inclusion of local search, the performance is further enhanced.
In terms of consumption time, as expected, the more the activities required, the slower the planning time.But the inclusion of local search greatly reduces planning time, as this may be due to the fact that BMA has a higher chance of obtaining good combinations given reparation from the local search.

Planning Performance with Time Threshold. Previous test
shows that time consumption is a significant issue, where planning time may reach several minutes.Increasing OPS further becomes impractical.
Alternatively, instead of waiting for the planner to finish, the best possible solution within a certain time limit can be used instead.This is likened to the planner generating the first few moves for execution, before proceeding further to eventually complete the whole process.
To test this idea, a time threshold of 1 minute is used to obtain plans of OPS from 10 to 16.If planning process does not end after 1 minute, the best solution is obtained instead.Experimental procedure is the same as in Section 4.3.Result of distance from optimal cost is shown in Figure 5. Consumption time is not examined as most of the planning process exceeds threshold time.
UB Refine and LSh Check do not fare so well by themselves.From time consumption result shown in Figure 4, both of them when applied individually require longer searches for OPS of 6 and 8. Cutting them short by introducing a time threshold of 1 minute forces the current best solution to be used, which is suboptimal.Combining them, coupled by the local search, enables the planner to obtain significantly better plans.Spread of distribution of performance is also reduced at significant magnitude, indicating a more consistent performance given local search is employed for gene reparation in BMA.
The performance test for Figure 5 is conducted with the assumption that the optimum plan is to be obtained given only 1 planning being done.The bad performance of the distribution is mainly due to unfulfilled goals (since goals impose the most weights).One planning is fairly restrictive, given that, in real life, planning and execution can be done sequentially.This means planning only needs to come up with partial plan to be executed, before proceeding to the next plan, until all goals are fulfilled, which is obviously more efficient.Such continuous planning is tested with 16 steps of optimal plan.Planning (and execution, which is just the manipulation of state variables) is run until no plans can be devised (which means all the activities in the −1 sequence of activities are Nop).Threshold is 1 minute for each planning process.Performance is shown in Table 6.As can be observed, the performance drastically increases.Single planning gives worse result compared to multiple planning because the former produces an incomplete plan.Given multiple implementations of the planner (with execution), it will approach the optimal solution.The bad result of modifications 1 and 3 is due to redundant activities contributing more costs.For other modifications, the main reason why they cannot reach 0% difference from optimum is due to goals that are related to conditions on integer (e.g., 3 ≤ 1 + 2 + 3 + 4, where there are specific activities to set 1 to 4 1 or 0 with different weights).As our current subgoals do not take integer into account, the planner does not know whether it is getting nearer or farther away from a solution related to integer.It only considers whether the constraint is fulfilled or not.In this case, it may choose activities with higher costs to fulfill the goal.Future work will involve generating subgoals for constraints involving integers to improve branching factor.

Comparison with CSP.
The use of hard constraints in the CSP planner [4] makes it very inefficient to handle overconstrained situations, where one needs to resort to partial goal fulfillment.Given problems that have contradicting goals, CSP planner will deem it unsolvable.WCSP planner directly assigns weights to the goals, where instead of satisfying constraints it works by maximizing the fulfillment of goals, which subsumes the former.Besides, with too many goals that cannot be solved at one go, WCSP can solve them through continuous planning and execution.It should be emphasized that this advantage holds only if each goal is solvable given the fixed planning horizon, as opposed to one goal that requires long complicated planning solution.For the latter, if the planning horizon is below minimum steps of actions to fulfill the goal, WCSP planner will produce an empty plan due to UB Refine eliminating all actions (which it deemed redundant).
Work in [4] also provides a fixed planning horizon, which introduces redundancy.Redundancy check is only partially realized through the use of constraints that maintain the state upon achieving the goal by imposing the no-action nop activity.A workaround is to continually increase the planning horizon until constraint consistency is achieved.For the proposed approach, optimization and upper bound minimization through UB Refine inherently prevent redundancy from occurring given fixed planning horizon.
Besides that, plan optimization is crucial as certain actions are preferable depending on context.For CSP planner, all actions are considered equal, and there is no direct way to encode preferences.As for WCSP, action preferences are encoded as costs, which will then be taken into account together with penalties of unfulfilled goals during optimization.
Despite the advantages, WCSP planner will be substantially slower compared to CSP planner due to it having to find a consistent plan and the fact that the plan needs to be optimized.Therefore, planning horizon should not be too large, while at the same time it should be sufficient to support reasonable number of steps to fulfill goals.A possible enhancement left as future work is to generate more goals that are the consequence of the original set of goals.For example, the goal  > 5 entails  > 4,  > 3,  > 2, and so forth.By including these entailments, planning horizon can be cut short, where complex plan can be continually generated.

Conclusion
An automated planner for the smart home that can deal with partial goal fulfillment and plan optimization is developed, where planning problem is solved as WCSP that is an extension of planning via CSP [4].
The planning problem itself is a mixture of soft and hard constraints.By exploiting the structure of the planning problem itself, it can be represented as a branch and bound search problem.Lower bound is calculated given a relaxed version of the original problem by exploiting the precondition and effects of the activities of the smart home.The relaxed optimization problem can be readily handled by evolutionary methods, such as the BMA in our case.BMA provides a lot of room for future research especially in the realm of its local search.
Results obtained from planning with and without time threshold demonstrate the applicability of our approach.Besides, the results also show the strength of applying local search for more efficient reparation of potential solutions in the BMA.
Yet, the work is still far from complete.At the moment, conversion of subgoals of the relaxed optimization problem only deals with Boolean data type.More efficient branching factor can be achieved if other data types are taken into account.Apart from that, faster searches and better heuristics should be devised to achieve better planning performance.Given the structure of the problem, search space can also be reduced by applying bucket elimination [38], where functions of low arity are eliminated before passing the constraint graph to search methods.
Reference [39] has argued that smart homes are developed mostly from the viewpoint of technical capabilities.It proposes to shift the smart home paradigm from technological capabilities to that which is centered around humans' need to enhance their living experience.The emphasis is that smart home should function in a way that tries to maximize the fulfillment of goals based on objects connected to it, instead of humans having to decide how the devices are going to serve them.Currently, smart devices that are able to learn and adapt their control are on the rise.Although this work does not involve machine learning or data mining to deliver services, relevancy can be drawn with such smart devices in that it may use their inferred results as knowledge variables.Given the right specification of ontology and functionalities, smart devices' abilities can be utilized with other devices to maximize goals.Such extensions will be made in future work.

Figure 1 :
Figure 1: Service composition and execution process flow.

Figure 3 :
Figure 3: Distance from optimum cost (in percentage) test result for planning without time threshold.Modifications from 1 to 5 (explained in Section 4.3) are indicated by colors blue, red, green, magenta, and black, respectively.The top of the box indicates the 3rd quartile, and the bottom of the box indicates the 1st quartile.The cross indicates the median.Line extension shows the minimum and maximum of the collected test samples.The same indicators apply to subsequent graph.

Figure 4 :
Figure 4: Planning time test result for planning without time threshold.

Figure 5 :
Figure 5: Distance from optimum cost (in percentage) test result for planning with time threshold of 1 minute.

Table 1 :
Example activities and their weights.

Table 2 :
Examples of relevant activities (as FOL).
changed fl 1 = val, val is a value where either val = 0 or 1;  0 is the initial value of ; store set to empty; if is not a response variable then for  = all activities do if Found  fl val in the  effects then = var; 0 is the initial value of ; store set to empty; if  is not a response variable then for  = all activities do if Found  fl 1 in the  effects then Add  precondition in store; = var; 0 is the initial value of ; store set to empty; for  = all activities do if  is not a response variable then if Found  fl ¬var in the  effects then Create  clones + 1 clones of bacterium;  segments ← / bm ; for  ← 1 to  segments do Select  bm yet unmutated random genes; for  ← 2 to  clones + 1 do Mutate the selected genes in clone  end for  ← 1 to  clones + 1 do for  ← 1 to  inf do Ascending order of the population according to (8); SourceBacterium ← Random(0, . . .,  ind /2 − 1) DestinationBacterium ← Random( ind /2, . . .,  ind ) Select random consecutive  gt genes; Transfer the selected genes from SourceBacterium to DestinationBacterium end Algorithm 7: Gene transfer.
Parameters for BMA are number of generations  gen , number of bacteria  ind , number of clones  clones , mutation segment length  bm , number of infections  inf , and infection segment length  gt .For speed and simplicity,  bm ,  inf , and  gt are all set to 1. Parameters  gen ,  ind , and  clones are selected via a test run with total sequence  of 10, with optimal solution having 4 activity sequences.UB Refine, LSh Check, and local search are not applied in this test.Table 4 shows the planning cost and Table 5 shows the training time for various values of  gen ,  ind , and  clones .Only the relevant parameter settings are shown in the tables.

Table 4 :
Planning cost for various  gen ,  ind , and  clones values.

Table 5 :
Planning time (seconds) for various  gen ,  ind , and  clones values.
Performance without Time Threshold.Planning test is performed with UB Refine, LSh Check, and BMA local search.As mentioned in Section 3.4, UB Refine will loop through the activity sequence and checks whether any activity's omission will produce better results.LSh Check will check whether branching out of an activity is redundant or not based on the local search lookup explained in Section 3.7.Total sequence  is set to 20.A set of goals is designed such that the number of activities of their optimal plan lies between 4 and 8. Test is performed on 4, 6, and 8 optimal plan sequences (OPS), where the designed goals are randomly selected.For each OPS, 5 sets of modifications are tested, which are (1) planning without UB Refine, LSh Check, and local search, (2) planning with UB Refine and without LSh Check and local

Table 6 :
Performance for continuous planning for modifications 1 to 5.