• No results found

Improving Configuration Technologies for IoT Scenarios

3.2. Cluster-Specific Heuristics for Constraint Solving

3.2.2. The Proposed Method

. . .

. . .

Figure 3.2.: The depth-first backtrack search tree to solve CSPprewithout heuristics

However, in our proposed approach we aim to learn variable and value ordering heuristics based on historical dynamic constraints. These are the dynamic constraints which are added on top of the same graph coloring problem in the past. For example, a historical dynamic constraint set (CREQ) can hold a former teacher’s available days and hours for teaching a course.

In Table 3.6, we have six sets of historical dynamic constraints (CREQ1..CREQ6) which are used to learn variable and value ordering heuristics to solve the working example. Each set of historical dy-namic constraints contains several constraints. For example, CREQ1consists of four dynamic constraints as c6: V1 = blue, c7: V2 = {red, blue, green}, c8: V3 = {red, blue, green}, and c9: V4 = green.

Table 3.6.: Six Sets of Historical Dynamic Constraints CREQ1 CREQ2 CREQ3 CREQ4 CREQ5 CREQ6

c6 V1 blue red blue red red red

c7 V1 - blue - blue - green

c8 V1 - - -

-c9 V1 green - red - blue

-3.2.2. The Proposed Method

Our proposed method CLUSTER AND LEARNimproves runtime efficiency of solution searching for pre-coloring extension problems. It is a novel variable and value ordering heuristics learning method based on historical dynamic constraints based on the same graph coloring problem.

In an offline phase, it uses a k-means clustering algorithm to cluster sets of historical dynamic constraints.

After clustering, again in an offline phase, it applies supervised learning based on a genetic algorithm (Whitley, 1994) to learn the variable and value ordering heuristics for each cluster. After completing

learning in an offline phase, it starts working in an online phase. When a precoloring extension problem (based on the same graph coloring problem of sets of historical dynamic constraints) is needed to be solved, CLUSTER AND LEARNfinds the closest cluster to the new set of dynamic constraints and employs the corresponding learned heuristics of this cluster. These steps are described based on the working example in the following subsections.

Clustering Dynamic Constraints

In an offline phase, we cluster sets of historical dynamic constraints. We have employed clustering to quickly estimate accurate heuristics in the online phase during solving a precoloring extension problem.

Otherwise, we would have to compare the new precoloring extension problem with all historical precolor-ing extension problems to find the most similar one. This would take a very long time when the historical problems dataset gets bigger. Moreover, by using cluster-specific heuristics, we also optimize the per-formance of heuristics by finding a common heuristic which works well for each cluster member (each precoloring extension problem in a cluster). Therefore, we expect that a cluster-specific heuristic works also well for a similar precoloring extension problem to this cluster.

We have preferred to use a well known clustering algorithm k-means clustering (see Formula 4.2) (Lloyd, 1982; MacQueen et al., 1967) because of the structure of our dataset. We have colors as values and decided to take the distances of each different colors as 1. This means, only the difference is meaningful, rather than the values.

In our working example, we have six past dynamic constraints as shown in Table 3.6. Constraints start with c6 because there are already defined five knowledge base constraints in the precoloring extension problem in Table 3.5. Distances between two sets of historical dynamic constraints are calculated based on euclidean distance as shown in Formula 4.3.

Since we have colors as values in graph coloring problems, we assume the distance between two different precolored variables is 1, the distance between one precolored, one non-precolored variable is 2, and rest is 0. For example, the distance between the two sets of historical dynamic constraints CREQ1and CREQ2is calculated according to Formula 4.3 as follows:

We cluster these past six dynamic constraints, by applying k-means clustering which minimizes the total distances between CREQs(see Formula 4.2). In this working example, we set the number of clusters (k) to 2 (to keep the example small and understandable). After applying k-means clustering (k=2 and distance measure is euclidean distance), we obtain the following two clusters; Cluster-1: {CREQ1, CREQ3, CREQ5} and Cluster-2: {CREQ2, CREQ4, CREQ6}.

Learning CLH

After clustering past dynamic constraint sets, again in an offline phase, we run a genetic algorithm sep-arately on each cluster to learn best fitting variable and value ordering heuristics for solving precoloring problems in a cluster. Runtime is our performance indicator which represents the time spent by the CSP solver to find a configuration. To improve the runtime performance of CSP solving, we calculate CLUSTER ANDLEARNheuristics (CLH) which minimize the total runtime of CSP solving of problems in a cluster.

As observed in the nature, genetic algorithms use fitness functions to find a best fitting individual out of

3.2. Cluster-Specific Heuristics for Constraint Solving

a population (survival of the fittest). In our case, a population consists of generated individuals which are candidate heuristics. The runtime performances of candidate heuristics are tested on past sets of historical dynamic constraints on top of a graph coloring problem. Our fitness function in Formula 3.2 minimizes the total runtime to find solutions for all CSPs (precoloring extension problems based on same graph coloring problem and different dynamic constraint sets) in a cluster.

min(

n i=1

runtime(Solve(CSPi)) (3.2)

In our working example, learned heuristics combinations for cluster-1 are CLHvar1and CLHval1whereas for cluster-2 they are CLHvar2and CLHval2as shown in Table 3.7.

Table 3.7.: CLUSTER ANDLEARNheuristics (CLH)

Cluster-1: {CREQ1, CREQ3, CREQ5} Cluster-2: {CREQ2, CREQ4, CREQ6} CLHvar1: V2, V4, V1, V3 CLHvar2: V2, V1, V4, V3

CLHval1:

V1 : {blue, red, green}, V2 : {red, blue, green}, V3 : {blue, green, red}, V4 : {red, blue, green}

CLHval2:

V1 : {red, blue, green}, V2 : {red, blue, green}, V3 : {blue, green, red}, V4 : {blue, green, red}

Solving with CLH

CLHheuristics are learned for each cluster in the offline phase using sets of historical dynamic constraints (past CREQs). After this offline phase, a CSP solver can solve new precoloring extension problems (based on the same graph coloring problem with historical problems) in the online phase with the help of these learned heuristics. First, we find the most similar cluster to the new precoloring extension problem’s dynamic constraints. Then we directly employ the heuristics of the most similar cluster for solving the new precoloring extension problem.

In our working example, CSPpre has the dynamic constraints set which holds one constraint CREQ = {c6: V1 = blue}. First, we find the closest cluster to CSPpre using the euclidean distance Formula 4.3.

The closest cluster that we find is Cluster − 1 and we apply the Cluster − 1’s variable and value ordering heuristics to solve CSPpre.

In the following two backtrack search trees (see Fig. 3.3), we show the CSP solver’s search space (so the number of consistency checks which increases parallel with the runtime), first using only CLHvar1and then combining CLHvar1with CLHval1. As shown in the first backtracking search tree in Fig. 3.3-(a), when CLHvar1is applied to solve the CSPwe, map coloring problem’s search is completed with seven consistency checks. The found solution is {V1=blue, V2=red, V3=green, V4=red}. The number of applied consistency checks is same with the search without heuristics (see Fig. 3.2). Thus, for CSPpre, variable ordering heuristics did not help to decrease the search space. However, it decreases the search space of CSPCREQ2.

V2

Figure 3.3.: Depth-first backtrack search trees to solve CSPprewith heuristics

As shown in the second backtracking search tree in Fig. 3.3-(b), when CLHvar1is applied together with and CLHval1, search results in five nodes (consistency checks) which is better than no heuristics and also using only CLHvar1. Due to the applied variable ordering, the first row of the tree is composed of the possibilities of V2, then respectively V4, V1 and V3. The order of values tried for each variable is based on the value ordering heuristics. For example, for V3 the first tried value is blue whereas for V2 it is red.

Since the search space is the smallest, the execution time of the CSP solver is also the shortest when cluster specific variable and value ordering heuristics are applied together.