Nature-Inspired Algorithms for Solving Weighted Constraint
Satisfaction Problems
Mehdi Bidar and Malek Mouhoub
a
Department of Computer Science, University of Regina, Regina, Canada
Keywords:
Constraint Satisfaction Problems (CSPs), Nature-Inspired Techniques, Soft Constraints, Combinatorial
Optimization.
Abstract:
Several applications such as timetabling, scheduling and resource allocation, can be represented as a Con-
straint Satisfaction Problem (CSP). Solving a CSP consists in finding a complete assignment of values to
variables satisfying all the constraints. In many real-life scenarios (including over-constrained problems),
some constraints (called soft constraints) can be violated according to some penalty function. In this regard,
the Weighted CSP (WCSP) can be used as an extension of the CSP where each constraint comes with a cost
function. Solving a WCSP consists in finding an optimal solution minimizing the total costs related to all
constraints. Searching for an optimal solution to a WCSP is usually dealt with classical complete methods
like backtracking and bucket elimination techniques. However, since WCSPs are NP-hard, complete methods
will require exponential time cost. Therefore, approximation methods such as metaheuristics are appropriate
alternatives as they are capable of providing a good compromise between the quality of the solution and the
corresponding running time. We study the applicability of several nature-inspired techniques including; Parti-
cle Swarm Optimization (PSO), Firefly, Genetic Algorithms (GAs), Artificial Bee Colony (ABC), Mushroom
Reproduction Optimization (MRO), Harmony Search (HS) and Focus Group (FG). While these methods do
not guarantee the optimality of the solution returned, they are in general successful in returning a good solution
in a desirable time cost. This statement has been demonstrated through the experimental results we conducted
on randomly generated WCSP instances following the known RB model. The latter has been adopted as it has
the ability to produce hard-to-solve random problem instances. The obtained results are promising and show
the potential of the considered nature-inspired techniques.
1 INTRODUCTION
A CSP consists of a set of variables, each defined over
a discrete and finite set of values, and a set of con-
straints restricting the values that the variables can
simultaneously take (Dechter and Cohen, 2003; Ku-
mar, 1992; Tsang, 2014). Solving a CSP consists
in finding a complete assignment of values to vari-
ables such that all the constraints are satisfied. A CSP
can be tackled using a systematic search technique,
i.e. backtracking. Due to the exponential time cost
of the backtrack search algorithm, constraint propa-
gation can be used to improve this running time in
practice. Another alternative is to use metaheuristics
as the latter are capable to trading running time for the
quality of the returned solution (Talbi, 2009; Glover
and Kochenberger, 2006; Blum and Roli, 2003; Bidar
et al., 2020b; Korani and Mouhoub, 2021; Abbasian
a
https://orcid.org/0000-0001-7381-1064
and Mouhoub, 2016).
For many real-world applications, we might need
to look for a good or a best solution satisfying all the
constraints while optimizing some objectives. This
has motivated the research community to develop ex-
tensions of CSPs taking into account penalties and
costs. The Weighted Constraint Satisfaction Problems
(WCSP) (Cooper et al., 2010; Lee and Leung, 2009)
is an example of such extended models. In a WCSP,
we consider two types of constraints: soft constraint
that can be violated with associated costs and hard
constraints that must be satisfied. Solving a WCSP
is about finding a solution that satisfies all the hard
constraints and minimizes the total cost related to soft
constraints.
Like for CSPs, WCSPs can also be tackled by sys-
tematic or approximation methods (Gallardo et al.,
2009; Bidar and Mouhoub, 2019b). In the case of
systematic search techniques, the most known ones
Bidar, M. and Mouhoub, M.
Nature-Inspired Algorithms for Solving Weighted Constraint Satisfaction Problems.
DOI: 10.5220/0011614900003393
In Proceedings of the 15th International Conference on Agents and Artificial Intelligence (ICAART 2023) - Volume 3, pages 63-72
ISBN: 978-989-758-623-1; ISSN: 2184-433X
Copyright
c
2023 by SCITEPRESS Science and Technology Publications, Lda. Under CC license (CC BY-NC-ND 4.0)
63
are a variant of backtracking, i.e. branch and bound
(Lawler and Wood, 1966), and bucket elimination
(Dechter and Cohen, 2003; Gallardo et al., 2009).
As for CSPs, systematic search methods come with
an exponential cost when solving WCSPs. To over-
come this diculty in practice, some heuristic search
techniques such as beam search and mini-buckets
have been introduced and added respectively to sys-
tematic search methods (Dechter and Cohen, 2003;
Gallardo et al., 2009). Despite the success of these
heuristics, there is still a challenge especially when
the problem size scales up. Like for CSPs, we can
rely on metaheuristics as an alternative to provide at
least near to optimal solutions to WCSP instances
within a reasonable time frame (Bidar et al., 2018a;
Bidar and Mouhoub, 2019a; Talbi, 2009). This has
motivated us to study the applicability of nature-
inspired techniques for solving WCSPs. More pre-
cisely, we consider the following methods: Particle
Swarm Optimization (PSO) (Kennedy and Eberhart,
1995; Bidar and Mouhoub, 2019a), Firefly Algorithm
(FA) (Wang et al., 2017; Yang, 2008; Bidar and
Mouhoub, 2019b), Genetic Algorithms (GAs) (Ab-
basian and Mouhoub, 2016), Artificial Bee Colony
algorithm (ABC) (Karaboga, 2005a), Mushroom Re-
production Optimization (MRO) (Bidar et al., 2018b;
Bidar et al., 2018a), Harmony Search (HS) (Geem
et al., 2001) and Focus Group (FG) (Fattahi et al.,
2018; Bidar et al., 2020a). The main reason to choos-
ing these algorithms is the fact that some have al-
ready been adapted to successfully solve CSPs (Bidar
et al., 2020a; Bidar and Mouhoub, 2019b; Bidar and
Mouhoub, 2019a). In addition, we aim for a vari-
ety of algorithms in terms of their respective source
of inspiration: swarm intelligence and social behav-
ior (PSO and ABC for foraging behavior and FA for
other behavior), biological evolution (GAs), organ-
ism structure (MRO), and physical/chemical process
(HS). Finally, these algorithms have been success-
fully applied to a wide range of optimization prob-
lems including feature selection, antenna design opti-
mization, scheduling and planning, classification and
clustering, resource allocation and vehicle routing. In
this regard, we propose a general methodology that al-
low a discretization of nature-inspired techniques. We
then show the adaptation of each of the algorithm we
consider. Finally, we report on the experiments we
have conducted to evaluate the dierent methods on
randomly generated WCSP instances. The latter have
been produced using a new variant of the RB model
(Xu and Li, 2000) that we have designed. The ratio-
nale for adopting the RB model is due to its ability to
randomly produce hard-to-solve problem instances.
Given the the Firefly Algorithm (FA) has already been
used to solve WCSPs (Bidar and Mouhoub, 2019b),
we will only consider this method in the comparative
experimentation section. Similarly, we use the same
CSP GA solving approach reported in (Abbasian and
Mouhoub, 2016) with the fitness function correspond-
ing to the total weight to minimize, rather than the
number of violated constraints.
2 PRELIMINARIES
A CSP is a tuple (X, D,C) where X is a set of vari-
ables, such that each variable X
i
X is defined on a
finite domain of values D
i
D, and C is a set of con-
straints restricting the values that the variables can si-
multaneously take. Solving a CSP consists in finding
a complete assignment of values to all the variables,
S = {X
1
= v
1
, X
2
= v
2
, . . ., X
n
= v
n
}, such that all the
constraints hold (Dechter and Cohen, 2003).
A WCSP is an extension of a CSP to deal with
soft constraints. More formally, a WCSP is defined
as a tuple t = (X, D,C, K) where the constraints in C
are soft constraints and K is a positive integer. Each
soft constraint c C corresponds to a cost function,
over a set of variables (its scope), returning a value in
{0, . . ., K}, for each instantiation (assignment of values
to the variables in its scope). In particular, c returns 0
when its instantiation is completely satisfactory, and
returns K when the instantiation is forbidden. Any
other value between 0 and K corresponds to a degree
of preference. Solving a WCSP consists of finding
a complete assignment minimizing the total sum of
all the costs related to all the constraints. In this re-
gard, a WCSP can be seen as an discrete combinato-
rial problem and is identified as NP-hard (Haddouch
et al., 2016; Cooper et al., 2010).
A binary WCSP is a special case of WCSPs where
the constraints involve at most 2 variables. Here, con-
straints can be unary or binary.
Unary constraints (cost functions) are defined as
follows. C
i
: a D
i
{0, .. ., K} where D
i
is the
domain of variable X
i
.
Binary cost functions are defined as follows. C
i j
:
(a, b) {0, . . ., K}, where a D
i
and b D
j
, D
i
and D
j
are respectively the domains of variables
X
i
and X
j
.
The total cost of a complete assignment S will
then be equal to the cost of T
(
S
)
defined as follows.
T
(
S
)
=
X
C
i j
C, {X
i
,X
j
}⊂X
C
i j
M X
C
iC, {X
i
}
X
C
i
(1)
where
L
is an operator defined through the fol-
lowing equation.
ICAART 2023 - 15th International Conference on Agents and Artificial Intelligence
64
a
M
b = min{K, a + b} (2)
An inconsistent assignment S corresponds to a to-
tal cost, T (S ) = K. A solution with the minimum to-
tal cost is the optimal solution (most preferred one).
Therefore, solving a WCSP consists in finding the so-
lution that minimizes the total cost, and is formulated
as follows.
Minimize
(
T
(
S
))
(3)
Here, S belongs to the set of potential solutions.
Example 1
Let us consider a WCSP with four variables, A, B,
C, and D, defined on the same domain D = {a, b, c,
d}. The constraints (excluding those with cost 0) are
listed as follows.
Hard Constraints: Each of these constraints is
defined as a set of forbidden tuples, each corre-
sponding to a cost function with a value equal to
K = 10. They are listed as follows.
(
A, B
)
(
b, b
)
,
(
b, c
)
,
(
d, d
)
,
(
c, c
)
, (c, d)
(
B,C
)
(
a, b
)
,
(
b, c
)
,
(
c, c
)
,
(
d, d
)
, (d, c)
(
C, D
)
(
a, a
)
,
(
a, b
)
,
(
b, b
)
,
(
b, d
)
,
(
d, d
)
, (d, b)
Soft Constraints: These correspond to all the
other unary and binary soft constraints.
Unary Constraints: C
i
C
a
= 1,C
b
= 3, C
c
=
2, C
d
= 4
Binary Constraints:
C
AB
C
(
a, a
)
= 3, C
(
a, b
)
= 1, C
(
b, d
)
=
1, C
(
d, c
)
= 5
C
BC
C
(
a, a
)
= 2, C
(
a, c
)
= 1, C
(
b, d
)
=
7, C
(
c, d
)
= 3
C
CD
C
(
a, c
)
= 1, C
(
c, c
)
= 9, C
(
c, d
)
= 6
Figure 1 shows the WCSP with all the constraints
listed in Example 1. Here, hard constraints are dis-
played in dash lines.
The following are potential solutions with their to-
tal cost functions.
1. S
1
=
[
a b d c
]
, Cost = 1+ 7 +0+ 1+ 3+4 +2 = 18
2. S
2
=
[
b d b a
]
, Cost = 1+ 0+0 +3+ 4 +3+ 1 = 12
One optimal solution, minimizing the total cost, is
presented as follows.
1. ch =
[
a a a c
]
, Cost = 3 + 2 + 0 + 1 + 1+ 1 + 2 = 10
Figure 1: The WCSP of Example 1.
3 RELATED WORK
In (Gallardo et al., 2009), Jose et al. proposed
a new method for solving WCSPs, using memetic
algorithms with bucket elimination. The authors
also investigated the combination of memetic algo-
rithms with other exact methods like branch-and-
bound and mini-buckets techniques. Based on the
experiments they conducted, the authors claimed
that their method outperforms the other existing ap-
proaches in terms of running time. Javier proposed
a new approach to maintain local consistency while
solving a WCSP (Larrosa and Schiex, 2003). Javier’s
approach was developed considering two main vari-
ants of the arc consistency algorithm: Directional Arc
Consistency (DAC) and Full Directional Arc Con-
sistency (FDAC). These two algorithms have been
introduced by Cooper for binary WCSPs. Javier’s
proposed approach was able to maintain either DAC
or FDAC while searching for a solution for a given
WCSP.
In (Delisle and Bacchus, 2013), the authors pre-
sented a new approach for solving WCSPs. The
WCSP is first converted into an ordinary CSP by con-
verting all soft constraints to hard constraints. Then,
the algorithm performs some constraint relaxations on
the problem and checks if the latter has a solution or
not. If there is no solution for the relaxed version
of the problem, the algorithm will compute a set of
forbidden tuples to rule out all the generated assign-
ments (solutions). From this set of tuples, the algo-
rithm forms a new relaxation and then checks again
if it has a solution. The main goal here is to find
the optimal relaxation which will result in incurring
a minimal cost. Therefore, any solution meeting the
requirements of this relaxation will be a solution to
the original WCSP. In (Larrosa and Schiex, 2003), the
authors introduced two new arc consistency enforcing
algorithms based on AC-2001/3.1 with improved time
Nature-Inspired Algorithms for Solving Weighted Constraint Satisfaction Problems
65
complexity O(e × d
3
) (e is the number of constraints
and d is the domain size) in comparison with the arc
consistency enforcing method which was proposed by
Schiex in (Schiex, 2000). The latter method has a
complexity O(e
2
× d
4
) for solving WCSPs. Then,
Javier introduced a stronger alternative for arc consis-
tency called AC
along with its enforcing algorithm
which has the complexity of O(n
2
×d
2
+ e× d
3
) where
n is the number of variables.
In (Lau, 2002), Lau proposed a new approach for
solving WCSPs based on semi-definite programming.
The main goal is to take the respective advantage of
complete and incomplete methods (guaranteeing the
optimal solution and faster running time). The main
feature of the proposed algorithm is its ability to find a
solution that has provable worst case bound in terms
of weight, comparing to the optimal solution. This
is in contrast with conventional incomplete methods
which have acceptable performance in practice but do
not guarantee to perform well in worst case situations.
4 DISCRETE REPRESENTATION
FOR WCSPs
In order to apply these techniques and the other meth-
ods we are considering to solve WCSPs, we propose a
unified approach for the discretization of any nature-
inspired method. Our discretization will include the
representation/definition of the potential solution, fit-
ness function and distance between two potential so-
lutions.
4.1 Potential Solution and Fitness
Function
As done with nature-inspired techniques for CSPs, we
represent a WCSP potential solution with a chromo-
some, where each entry corresponds to the value as-
signed to each variable. Table 1 shows a chromosome
corresponding to a potential solution of the WCSP
presented in Example 1.
Table 1: A chromosome representing a potential solution.
Variables X
1
X
2
X
3
X
4
Chromosome b d b a
The fitness function of a chromosome (potential
solution) corresponds to the total cost function T
(
S
)
.
For instance, the fitness function of the potential so-
lution depicted in Table 1 is equal to 12, as described
in Example 2.
4.2 Similarity and Distance Between
Potential Solutions
One important parameter needed by nature-inspired
techniques, especially when conducting exploitation,
is the similarity between two potential solutions. In
this regard, we employ the Hamming distance which
corresponds to the number of values that both solu-
tions do not share. The Hamming distance between
two solution S
i
and S
j
with n variables, d
H
(S
i
, S
j
),
is calculated, according to the fitness function, as fol-
lows.
d
H
S
i
, S
j
=
n
X
k=1
(S
i,k
, S
j,k
) (4)
In the above equation, S
i,k
and S
j,k
represent the
values assigned to the k
th
variable of S
i
and S
j
, re-
spectively. Basically, the Hamming distance corre-
sponds to the number of values that the two solutions
do not have in common. In this regard, the Hamming
distance between two identical solutions is equal to 0,
while the Hamming distance between two solutions
not having any value in common is equal to the num-
ber of variables, n. Table 2 shows the computation of
the Hamming distance for two potential solutions.
Table 2: The Hamming distance between two solutions.
Variables X
1
X
2
X
3
X
4
S
i
a b d c
S
j
a c d a
, values X X
d
H
= 1 + 1
As we will show in the next section, the Hamming
distance will be used to implement one of the opera-
tors required by the nature-inspired techniques we are
considering.
5 NATURE-INSPIRED
TECHNIQUES FOR WCSPs
5.1 Particle Swarm Optimization (PSO)
Particle swarm optimization (PSO) algorithm is one
of the most popular nature-inspired swarm-based op-
timization algorithms, developed based on the collec-
tive intelligent behavior of systems like fish school-
ing and birds flocking (Kennedy and Eberhart, 1995).
PSO has been proven to be very eective in deal-
ing with a wide range of combinatorial optimization
problems including continuous and discrete problems
(Poli et al., 2007; Bidar and Mouhoub, 2019a; Korani
ICAART 2023 - 15th International Conference on Agents and Artificial Intelligence
66
and Mouhoub, 2020). In PSO, every particle posi-
tion is influenced by its own best position, pbest, as
well as the best position made by other particles so far,
gbest. In (Bidar and Mouhoub, 2019a) a discrete ver-
sion of PSO (called Discrete PSO, or DPSO) has been
used to solve Dynamic CSPs (DCSPs). This specific
problem consists in solving CSPs when constraints
are added dynamically. We use a similar version of
DPSO in this paper with a new definition for the fit-
ness function. While this function has been defined
as the number of violated constraints in (Bidar and
Mouhoub, 2019a), we define it as the total cost func-
tion as described in the previous section. Otherwise,
we follow the same DPSO algorithm, including the
following equations defined respectively to update the
velocity and position of the dierent particles corre-
sponding to potential solutions (Bidar and Mouhoub,
2019a).
V
t+1
i
= w V
t
i
|{z}
exploration
c
1
r
1
(pbest
t
i
X
t
i
) c
2
r
2
(gbest
t
i
X
t
i
)
| {z }
exploitation
(5)
X
t+1
i
= X
t
i
V
t+1
i
, i = 1, .. ., n (6)
In DPSO (Bidar and Mouhoub, 2019a), exploita-
tion and exploration strategies (
ˇ
Crepin
ˇ
sek et al., 2013)
are controlled through the above two equations, us-
ing three controlling parameters, w, c
1
and c
2
. A
high value of w encourages more exploration, while a
low value favors exploitation (Nickabadi et al., 2011).
Similarly, low values of c
1
and c
2
allow for more ex-
ploration for promising areas, while high values for
these parameters favor more local intensification.
When using the operator , w determines the per-
centage of the variable values that will be passed from
V
t
i
to V
t+1
i
. The rest of V
t+1
i
values will be generated
randomly. Similarly, c
1
r
1
and c
2
r
2
correspond to the
percentage of values to keep from (pbest
t
i
X
t
i
) and
(gbest
t
i
X
t
i
), respectively. This operation is again en-
forced through . The operator allows the selection
of the values that are in pbest
t
i
(respectively gbest
t
i
)
and not in X
t
i
( can be seen as a set dierence opera-
tion).
5.2 Discrete MRO (DMRO)
The initial version of MRO (Bidar et al., 2020b) tack-
les continues optimization problems (X R
n
). To ap-
ply a discrete version of MRO to solve WCSPs, we
have used the definitions stated in the previous sec-
tion. MRO is biologically inspired by the natural re-
production and growth mechanisms of mushrooms.
A potential solution corresponds to either a parent
mushroom or a spore, and a population is a mix of
both. In the case of WCSPs, this population is initially
a set of randomly generated solutions. The search
process will then follow an exploration/exploitation
process and will be guided by the following equa-
tions respectively corresponding to local and global
movements. More precisely, a local movement cor-
responds to a local search with the goal to make lo-
cal improvements to potential solutions. This is done
by spreading spores by parent mushrooms in their re-
spective colonies. Equation 7 reflects this local move-
ment. This equation updates the new location of spore
j of colony (parent mushroom) i (X
i, j
). X
parent
i
is the
location of the parent i and Rand(0,1) generates a ran-
dom number in (0,1).
X
i, j
= X
parent
i
+ Rand(0, 1) (7)
The global movement follows the natural phenom-
ena of a wind factor. If the wind is blowing, spores
are moved to dierent parts of the problem space and
land in new locations. Next, spores grow and become
mature mushrooms. Equations (8) and (9) define the
global movement of the spores induced by wind.
X
i, j
= X
parent
i
+ Move
wind
j
(8)
Move
wind
j
= (X
i
X
k
) × (
Ave(i)
T
ave
)
m
×
Rand(δ, δ) × rs + Rand(r,r) (9)
Here, X
i
and X
k
are the parent solutions of the
colonies i and k, Ave(i) is the average of solutions
quality (fitness function) of colony i, T
ave
is the to-
tal average of all colonies, Rand(δ, δ) is a vector that
determines direction movement of the wind, rs (0, 1)
is the size of random step and Rand(r,r) is the ran-
dom movement of the spores to their neighboring ar-
eas with radius r.
5.3 Discrete Focus Group Optimization
Algorithm (DFGOA)
FGOA is inspired by the collaborative behavior of a
group’s members sharing their ideas on a given sub-
ject (Fattahi et al., 2018). This algorithm has been
initially proposed for continuous optimization prob-
lems. A discrete version of FGOA, called Discrete
FGOA (DFGOA), has been proposed to deal with
CSPs (Bidar et al., 2020b). In DFGOA, the search
process is guided by the impact factor parameter for
each potential solution based on its quality as shown
in equation 10.
Nature-Inspired Algorithms for Solving Weighted Constraint Satisfaction Problems
67
IF
t+1
(
i
)
= IF
t
(
i
)
+
nPop
X
j=1
((
rand
(
l
)
×
(
|F(S
(
i
)
) F(S
(
j
)
|
)
× IC
(
j
)
Nvar
)
m
)
(10)
Here, IF(i) is the impact factor of participant i
which will take an important role in the next steps to
aect the other participants’ solutions, IF
t+1
(
i
)
is the
new impact factor of participant i, nPop is the pop-
ulation size, Nvar is the number of variables of the
problem, rand(l) generates a random number in (0,1)
and F(S
i
) and F(S
j
) are the qualities of solutions i
and j respectively. IC( j), the impact coecient, is a
random number in (0,1) and is assigned to each so-
lution. In this regard, a set of nPop random numbers
is generated and based on the qualities of solutions
are assigned to each solution (the more quality a so-
lution is, the larger the value will be assigned to). In
a discrete problem space like for CSPs and WCSPs,
aecting a solution can be interpreted as replacing
its variables’ values with the corresponding variables’
values of the better solution with an appropriate prob-
ability, in order to avoid the immature convergence of
the algorithm. In this regard, this replacement is done
by considering IF() as the probability of this replace-
ment. We normalize the Impact Factor between 0 and
1 according to (11).
IF(i)
Normalized
= 1
F(s
(
i
)
)F(Bestsolution)
F(Worstsolution)F(Bestsolution)
(11)
Here, F(Bestsolution) and F(Worstsolution) are
the expected qualities of the best and the worst so-
lutions. In fact, the larger IF(i) is, the more chance
participant i (S
i
) has to impact the other participant’
solutions. This replacement is done according to (12).
Rep(S
i
, S
j
) =
S
j
(
k
)
S
i
(
k
)
i f S
j
(
k
)
, S
i
(
k
)
and rnd < IF
(
I
)
(12)
Rep
S
i
, S
j
is the replacement equation, rnd is a
random number in (0,1). The controlling parameter,
CP, is used to detect if the FGOA has been trapped
in local optimum solutions. This parameter through
(4) monitors the progress trend of the algorithm and
if for some iterations not enough progress has been
made by the algorithm, this parameter enables a ran-
domization method to diversify the solutions.
CP =
P
IN
i=INWS
(
GB
(
i
)
GB(i 1)
)
WS
(13)
Here, IN is the current iteration number, WS is the
window size, GB(i) is the global best solution in it-
eration i. The window size determines the number
of iterations to be considered to determine if accept-
able progress has been made by the algorithm. If CP
is less than the user-defined threshold value the al-
gorithm activates a new randomization method called
IF Randomization (IFR). IF Randomization method
is used for diversifying the solutions. According to
this method based on the Impact Factor (IF) of a solu-
tion, a variable values of a given solution is replaced
with another value which is randomly chosen from
its domain with probability (1-IF)
2
. The probability
(1 IF)
2
causes more quality solutions to be subject
of less changes in their variables values.
5.4 Discrete Harmony Search (DHS)
Algorithm
Harmony Search (HS) optimization algorithm is a
population based metaheuristic algorithm which was
developed by Geem et al. in 2001 (Geem et al., 2001)
based on improvisation process of jazz musicians.
Improvisation process stands for the attempt of a mu-
sician to find the best harmony that can be achieved
in practice (Degertekin, 2008). Three options can be
considered when a skilled musician aims at impro-
vising a music instrument, a) to play a memorized
piece of music exactly, b) to play a piece similar to
what he/she has in their memory and c) to play newly
composed notes (Yang, 2009). These three options
were considered as the main components of the HS al-
gorithm which were introduced as harmony memory,
pitch adjustment and random search to the algorithm
(Yang, 2009). The harmony memory has valuable
role in HS algorithm and that is to ensure that good
harmonies are considered when generating new so-
lutions. This component is controlled by a parameter
called harmony memory considering, HMCR [0, 1].
In fact this parameter determines the ratio of consid-
ering elite solutions (harmonies) in generating a new
solution. If this parameter is set to a small value, the
algorithm considers a small number of elite solutions,
which causes convergence to the optimal solution too
slowly. On the other hand if it is set to a large value,
the emphasis of the algorithm will be on using the
solutions in the memory and therefore other good so-
lutions are not explored. This does not lead to discov-
ering better solutions.
The next component is pitch adjustment which has
the same application as the mutation operator in ge-
netic algorithms and is defined as follows.
X
new
= X
old
+ BW (14)
ICAART 2023 - 15th International Conference on Agents and Artificial Intelligence
68
Here, X
old
is the solution (pitch) in the memory,
BW is the band width, is a random value in (0,1)
and X
new
is the new solution. This component gen-
erates solutions slightly dierent from those in the
memory by adding small random values to the so-
lutions in memory. The degree of pitch adjustment
can be controlled by pitch adjustment rate parameter
PAR. The low value of PAR together with the small
value of BW can reduce the exploration which results
in discovering a portion of the problem space instead
of the whole problem space.
The third component of the HS algorithm is ran-
domization. The main role of this component is to
encourage the diversity of the solutions. Randomiza-
tion ensures that all regions of the problem space are
accessible by the algorithm.
HS algorithm was developed to tackle continuous
optimization problems. In order to deal with WC-
SPs, HS features must be changed to suit the discrete
problem spaces, following our definitions in Section
4. The steps of converting the HS algorithm to its
discrete version (that we call Discrete HS or DHS)
are reported below. At the initialization step, the al-
gorithm randomly generates HMS (harmony search
size) solutions as the initial population. In this step,
potential solutions are generated by assigning random
values (from the variables domains) to CSP variables.
The next step is to redefine the pitch adjustment
equation presented in Equation 14. The new defini-
tion of the pitch adjustment is presented in Equation
15.
X
new
= (BW ) X
old
(15)
Through pitch adjustment, slight changes by
adding small random values are made in the current
solution in order to improve it. The new definition of
the pitch adjustment component has the same impact
on the current solutions. Through the new definition,
the variables’ values of the current solution will be
replaced by randomly picking values from variables’
domain in the hope to improves the current solution.
In Equation 15, we defined and as follows.
is the multiplier and BW is a probability value in
(0,1). In fact, this latter term determines the probabil-
ity of replacing the variables’ values of X
old
with new
values picked up randomly from variables domain.
applies these changes to X
old
.
The last component (randomization) encourages
diversity of solutions which ensures that a larger
search space will be considered. To boost the di-
versity of the solutions, we employ the GA mutation
operator. In this regard, dierent mutation operators
have been developed so far, including the following
three: Random Resetting Mutation (RRM), Scramble
Mutation (SM), and Inversion Mutation (IM).
5.5 Artificial Bee Colony (ABC)
Artificial Bee Colony optimization algorithm (ABC)
is a population based optimization algorithm which
simulates the foraging behavior of the real bee
colonies in the nature (Karaboga, 2005b; Mernik
et al., 2015). Agents of the ABC algorithm is divided
into three class of bees, recruited bees, onlooker bees
and scout bees and each class of bees shoulders re-
sponsibilities (Gao and Liu, 2012). Recruited bees
search the food sources around the location they have
in their memories and keep the onlooker bees updated
about the quality of the food sources they are visiting.
Onlooker bees based on the information are receiving
from recruited bees select the new food sources (the
most quality ones) and also search around the selected
food sources in the hope of discovering new and more
quality food sources. Scout bees are recruited bees
that abandoned their food source in order to discover
new food sources (Karaboga, 2005b). In order to ap-
ply the ABC algorithm for WCSPs, we need to adapt
it to discrete spaces, using the definitions reported in
Section 4. The initial population of bees is gener-
ated by assigning the random values from variables’
domain to the variables of the solutions. After the
generated solutions were assigned to recruited bees,
they try to locally improve the solutions by searching
neighboring areas of their solutions (food sources).
This search process is guided by the following equa-
tions, redefined for discrete spaces.
v
i j
= w (x
i j
g
i j
) (16)
where
g
i j
=
i j
(x
i j
x
k j
) (17)
v
i j
, x
i j
and g
i j
correspond to the j
th
variable value for
potential solutions v
i
, x
i
and g
i
, respectively. We have
redefined the operators and to deal with discrete
problems. The idea is that the algorithm randomly
selects a food source site k for each recruited bee in
its neighborhood. Then, the recruited bee needs to
move towards that new site x
k
. In discrete problem
spaces, moving from one solution to another corre-
sponds to sharing more identical values with that so-
lution. Operator identifies the variables of the first
solution that have dierent values from the one the
bee is going to move toward. After identifying the
variables with dierent values, these variables’ val-
ues will be replaced by the corresponding variables’
values of solution x
k
with probability
i j
(a value ran-
domly selected from [0,1]). The application of is
to replace the variables’ values of x
i
with those of x
k
considering the replacement probability
i
. Then,
compares x
i j
and g
i j
, for each j, to identify the dier-
ent variables. When the dierences have been identi-
fied, those dierent variables’ values will be replaced
Nature-Inspired Algorithms for Solving Weighted Constraint Satisfaction Problems
69
x
i
2 1 3 5 5 4 1 2 3 4
x
k
3 1 4 3 5 4 4 5 1 3
i
0.1 0.4 0.1 0.6 0.3 0.3 0.6 0.5 0.7 0.4
g
i
2 1 3 3 5 4 4 5 1 4
Figure 2: An example of calculating g
i
=
i j
N
x
i j
x
k j
.
by corresponding variables’ values of g
i
with prob-
ability w. Figure 2 shows an example of calculating
g
i j
=
i j
N
x
i j
x
k j
.
Finally, v
i
will be assessed according to the fitness
function. If it has higher quality than x
i
then it will
replace it. The improvement of developing every food
site is monitored using a given parameter. If for a
defined number of trials, the expected improvement
has not been achieved, the algorithm replaces that site
(solution) with a randomly generated site.
6 EXPERIMENTATION
To assess the performances of the nature-inspired
techniques considered in this paper, we have con-
ducted several comparative experiments on randomly
generated WCSP instances using a variant of the RB
model (Xu and Li, 2000). The original RB model
has been designed to produce random CSP instances,
based on the following four parameters: n, p, α and
r. Here, n is the number of variables, p (0 < p < 1)
determines the tightness of the constraints, and r and
α (0 < r, α < 1) are two positive constants used by the
model RB (Xu and Li, 2000). Using these four pa-
rameters, we have adapted the RB model to generate
a WCSP instance as follows.
1. d = n
α
is the domain size of each variable.
2. All the variables will be assigned the same domain
corresponding to the first d natural numbers (0 ...
d1).
3. Select without repetition t = r × n × ln (n) random
constraints. Each random constraint is formed by
selecting 2 of n variables (without repetition).
4. For each constraint, we uniformly select without
repetition q=p×d
2
incompatible pairs of values.
We then assign a large value (1000) to all the in-
compatible pairs. From the remaining pairs (the
compatible ones), we select a percentage of sc soft
constraints, and assign a random value to each of
them, from [1, . . ., 999]. The rest of the constraints
are hard constraints and will therefore each be as-
signed a value of 0.
According to (Xu and Li, 2000), the phase transi-
tion P
t
(borderline between solvable and non solvable
Table 3: The controlling parameters of the nature-inspired
techniques.
Figure 3: Solving WCPS instances with tightness between
0.45 and 0.65.
problems) is calculated as follows: P
t
= 1 e
α/r
. In
theory, if the constraints are all hard, solvable prob-
lems are generated with tightness p<P
t
. In our ex-
periments, we select the values for α and r such that
P
t
= 0.7. In this regard, we randomly generate WCSP
instances with 100 variables and a tightness p rang-
ing from 0.4 to 0.65 (the latter value corresponds to
the hardest problem to solve). We set sc to 0.3 which
means that 30% of randomly chosen hard constraints
will be converted to soft constraints. All methods
have been implemented using MATLAB R2013b and
all experiments have been performed on a PC with
Intel Core i7-6700K, with 4.00 GHz processor and 32
GB RAM.
Figure 3 reports on the comparative results of the
ICAART 2023 - 15th International Conference on Agents and Artificial Intelligence
70
experiments conducted on the nature-inspired tech-
niques we adapted in this paper, namely PSO, DMRO,
DFGOA, DHS and ABC. In addition, we use FA as
reported in (Bidar and Mouhoub, 2019b), the GA
approach in (Abbasian and Mouhoub, 2016), and
a branch and bound (B&B) algorithm (Lawler and
Wood, 1966) for comparative purposes. The latter
algorithm has been improved using constraint prop-
agation (Arc Consistency) before and during search,
following a forward check strategy (Dechter and Co-
hen, 2003). This will help reducing the size of the
search space by removing some of the inconsistent
values (according to hard constraints). The control-
ling parameters of the nature-inspired techniques are
tuned to their best, as shown in Table 3. The dierent
methods are compared in terms of the running time
(Y-axis in 3) needed to return the optimal solution,
for each tightness value (X-axis). Note that in all the
experiments conducted, all the methods were able to
return the optimal solution, before a given timeout.
The charts show the superiority of GAs, MTO, PSO
and DHS over ABC, FA and DFGOA. Due to its in-
herent exponential time cost, B&B performs poorly
comparing to all the other methods.
7 CONCLUSION AND FUTURE
WORK
This work investigate the applicability of the meta-
heuristics for solving WCSPs. In this regard, we
report on the adaptation of several known nature-
inspired techniques in order to tackle these discrete
optimization problems. To assess the performance of
our developed methods, we conducted several experi-
ments on WCSP instances, randomly generated using
a variant of the model RB. The results are promising
and demonstrate the fact that nature-inspired meth-
ods can be a good alternative for tackling these NP-
hard problems. In the near future, we plan to apply
our adapted nature-inspired techniques to solve those
real-world problems that can be represented as WC-
SPs. These applications include Nurse Scheduling
Problems (NSPs) (Said et al., 2021) and timetabling
(Hmer and Mouhoub, 2016). Given that most of these
real-world problems occur in an evolving environ-
ment where constraints can added or removed dynam-
ically, we will need to adapt our techniques to oper-
ate in an incremental manner (Bidar and Mouhoub,
2019a; Mouhoub, 2004).
REFERENCES
Abbasian, R. and Mouhoub, M. (2016). A new paral-
lel ga-based method for constraint satisfaction prob-
lems. Int. J. Comput. Intell. Appl., 15(3):1650017:1–
1650017:22.
Bidar, M., Kanan, H. R., Mouhoub, M., and Sadaoui,
S. (2018a). Mushroom reproduction optimization
(MRO): A novel nature-inspired evolutionary algo-
rithm. In 2018 IEEE Congress on Evolutionary Com-
putation, CEC 2018, Rio de Janeiro, Brazil, July 8-13,
2018, pages 1–10. IEEE.
Bidar, M., Kanan, H. R., Mouhoub, M., and Sadaoui,
S. (2018b). Mushroom reproduction optimization
(MRO): A novel nature-inspired evolutionary algo-
rithm. In 2018 IEEE Congress on Evolutionary Com-
putation, CEC 2018, Rio de Janeiro, Brazil, July 8-13,
2018, pages 1–10. IEEE.
Bidar, M. and Mouhoub, M. (2019a). Discrete particle
swarm optimization algorithm for dynamic constraint
satisfaction with minimal perturbation. In 2019 IEEE
International Conference on Systems, Man and Cy-
bernetics, SMC 2019, Bari, Italy, October 6-9, 2019,
pages 4353–4360. IEEE.
Bidar, M. and Mouhoub, M. (2019b). Solving weighted
constraint satisfaction problems using a new self-
adaptive discrete firefly algorithm. In 2019 IEEE In-
ternational Conference on Systems, Man and Cyber-
netics, SMC 2019, Bari, Italy, October 6-9, 2019,
pages 2198–2205. IEEE.
Bidar, M., Mouhoub, M., and Sadaoui, S. (2020a). Discrete
focus group optimization algorithm for solving con-
straint satisfaction problems. In Rocha, A. P., Steels,
L., and van den Herik, H. J., editors, Proceedings
of the 12th International Conference on Agents and
Artificial Intelligence, ICAART 2020, Volume 2, Val-
letta, Malta, February 22-24, 2020, pages 322–330.
SCITEPRESS.
Bidar, M., Mouhoub, M., Sadaoui, S., and Kanan, H. R.
(2020b). A novel nature-inspired technique based
on mushroom reproduction for constraint solving
and optimization. Int. J. Comput. Intell. Appl.,
19(2):2050010:1–2050010:21.
Blum, C. and Roli, A. (2003). Metaheuristics in combi-
natorial optimization: Overview and conceptual com-
parison. ACM computing surveys (CSUR), 35(3):268–
308.
Cooper, M. C., De Givry, S., S
´
anchez, M., Schiex, T., Zyt-
nicki, M., and Werner, T. (2010). Soft arc consistency
revisited. Artificial Intelligence, 174(7-8):449–478.
Dechter, R. and Cohen, D. (2003). Constraint processing.
Morgan Kaufmann.
Degertekin, S. O. (2008). Optimum design of steel frames
using harmony search algorithm. Structural and Mul-
tidisciplinary Optimization, 36(4):393–401.
Delisle, E. and Bacchus, F. (2013). Solving weighted csps
by successive relaxations. In Proceedings of the In-
ternational Conference on Principles and Practice
of Constraint Programming, CP’13, page 273–281,
Berlin, Heidelberg. Springer-Verlag.
Nature-Inspired Algorithms for Solving Weighted Constraint Satisfaction Problems
71
Fattahi, E., Bidar, M., and Kanan, H. R. (2018). Focus
group: An optimization algorithm inspired by human
behavior. International Journal of Computational In-
telligence and Applications, 17:1–27.
Gallardo, J. E., Cotta, C., and Fern
´
andez, A. J. (2009). Solv-
ing weighted constraint satisfaction problems with
memetic/exact hybrid algorithms. Journal of Artificial
Intelligence Research, 35:533–555.
Gao, W.-f. and Liu, S.-y. (2012). A modified artificial bee
colony algorithm. Computers & Operations Research,
39(3):687–697.
Geem, Z. W., Kim, J. H., and Loganathan, G. (2001). A new
heuristic optimization algorithm: Harmony search.
SIMULATION, 76(2):60–68.
Glover, F. W. and Kochenberger, G. A. (2006). Handbook of
metaheuristics, volume 57. Springer Science & Busi-
ness Media.
Haddouch, K., Elmoutaoukil, K., and Ettaouil, M. (2016).
Solving the weighted constraint satisfaction problems
via the neural network approach. Int. J. Interact. Mul-
tim. Artif. Intell., 4(1):56–60.
Hmer, A. and Mouhoub, M. (2016). A multi-phase hybrid
metaheuristics approach for the exam timetabling. In-
ternational Journal of Computational Intelligence and
Applications, 15(04):1650023.
Karaboga, D. (2005a). An idea based on honey bee swarm
for numerical optimization. In Technical report-tr06,
Erciyes university, engineering faculty, computer en-
gineering department.
Karaboga, D. (2005b). An idea based on honey bee swarm
for numerical optimization. Technical report-tr06,
Erciyes university, computer engineering department,
200:1–10.
Kennedy, J. and Eberhart, R. (1995). Particle swarm opti-
mization. In Proceedings of ICNN’95-International
Conference on Neural Networks, volume 4, pages
1942–1948. IEEE.
Korani, W. and Mouhoub, M. (2020). Discrete mother tree
optimization for the traveling salesman problem. In
Yang, H., Pasupa, K., Leung, A. C., Kwok, J. T.,
Chan, J. H., and King, I., editors, Neural Information
Processing - 27th International Conference, ICONIP
2020, Bangkok, Thailand, November 23-27, 2020,
Proceedings, Part II, volume 12533 of Lecture Notes
in Computer Science, pages 25–37. Springer.
Korani, W. and Mouhoub, M. (2021). Review on Nature-
Inspired Algorithms. SN Operations Research Forum,
2(3):1–26.
Kumar, V. (1992). Algorithms for constraint-satisfaction
problems: A survey. AI magazine, 13(1):32–32.
Larrosa, J. and Schiex, T. (2003). In the quest of the best
form of local consistency for weighted csp. In Pro-
ceedings of the 18th International Joint Conference on
Artificial Intelligence, IJCAI’03, page 239–244, San
Francisco, CA, USA. Morgan Kaufmann Publishers
Inc.
Lau, H. C. (2002). A new approach for weighted constraint
satisfaction. Constraints, 7(2):151–165.
Lawler, E. L. and Wood, D. E. (1966). Branch-and-bound
methods: A survey. Oper. Res., 14(4):699–719.
Lee, J. H. and Leung, K. L. (2009). Towards e-
cient consistency enforcement for global constraints
in weighted constraint satisfaction. In Twenty-First In-
ternational Joint Conference on Artificial Intelligence.
Mernik, M., Liu, S.-H., Karaboga, D., and
ˇ
Crepin
ˇ
sek, M.
(2015). On clarifying misconceptions when compar-
ing variants of the artificial bee colony algorithm by
oering a new implementation. Information Sciences,
291:115–127.
Mouhoub, M. (2004). Systematic versus non systematic
techniques for solving temporal constraints in a dy-
namic environment. AI Commun., 17(4):201–211.
Nickabadi, A., Ebadzadeh, M. M., and Safabakhsh, R.
(2011). A novel particle swarm optimization algo-
rithm with adaptive inertia weight. Applied soft com-
puting, 11(4):3658–3670.
Poli, R., Kennedy, J., and Blackwell, T. (2007). Particle
swarm optimization. Swarm intelligence, 1(1):33–57.
Said, A. B., Mohammed, E. A., and Mouhoub, M. (2021).
An implicit learning approach for solving the nurse
scheduling problem. In Mantoro, T., Lee, M., Ayu,
M. A., Wong, K. W., and Hidayanto, A. N., editors,
Neural Information Processing - 28th International
Conference, ICONIP 2021, Sanur, Bali, Indonesia,
December 8-12, 2021, Proceedings, Part II, volume
13109 of Lecture Notes in Computer Science, pages
145–157. Springer.
Schiex, T. (2000). Arc consistency for soft constraints. In
Proceedings of the 6th International Conference on
Principles and Practice of Constraint Programming,
CP ’02, page 411–424, Berlin, Heidelberg. Springer-
Verlag.
Talbi, E.-G. (2009). Metaheuristics: from design to imple-
mentation, volume 74. John Wiley & Sons.
Tsang, E. (2014). Foundations of constraint satisfaction:
the classic text. BoD–Books on Demand.
ˇ
Crepin
ˇ
sek, M., Liu, S.-H., and Mernik, M. (2013). Explo-
ration and exploitation in evolutionary algorithms: A
survey. ACM Comput. Surv., 45(3).
Wang, H., Wang, W., Zhou, X., Sun, H., Zhao, J., Yu, X.,
and Cui, Z. (2017). Firefly algorithm with neighbor-
hood attraction. Inf. Sci., 382(C):374–387.
Xu, K. and Li, W. (2000). Exact phase transitions in random
constraint satisfaction problems. Journal of Artificial
Intelligence Research, 12:93–103.
Yang, X.-S. (2008). Nature-Inspired Metaheuristic Algo-
rithms. Luniver Press.
Yang, X.-S. (2009). Harmony Search as a Metaheuristic
Algorithm, pages 1–14. Springer Berlin Heidelberg,
Berlin, Heidelberg.
ICAART 2023 - 15th International Conference on Agents and Artificial Intelligence
72