1 Introduction
Classical constraint satisfaction problems (CSPs) [DBLP:books/daglib/0076790] represent an expressive and natural formalism useful to specify different types of reallife problems. A CSP can be described as a set of variables associated with a domain of values, and a set of constraints. A constraint is a limitation of the possible combinations of the values of some variables. So, solving a CSP consists in finding an assignment of values to all its variables guaranteeing that all constraints are satisfied.
Despite their applicability, the main limit suffered by CSPs is the ability of just stating if an assignment of certain values to the variables is allowed or not. This is indeed not enough to model scenarios where the knowledge is not either entirely available or not crisp. In these cases constraints are preferences and, when the problem is overconstrained, one would like to find a solution that is not so bad, i.e., the best solution according to the levels of preferences. For this reason, in [DBLP:conf/ijcai/BistarelliMR95, DBLP:journals/jacm/BistarelliMR97], the soft CSP framework has been proposed. It extends classical constraints by adding to the usual notion of CSP the concept of a structure representing the levels of satisfiability or the costs of a constraint. Such a structure is represented by a semiring, that is, a set with two operations: one (usually denoted by ) is used to generate an ordering over the levels, while the other one (denoted by ) is used to define how two levels can be combined and which level is the result of such a combination.
Constraint logic programming (CLP) [DBLP:conf/popl/JaffarL87] extends logic programming (LP) by embedding constraints in it: term equalities is replaced with constraints and the basic operation of LP languages, the unification, is replaced by constraint handling in a constraint system. It therefore inherits the declarative approach of LP, according to which the programmer specifies what to compute while disregarding how to compute it, by also offering efficient constraintsolving algorithms.
However, only classical constraints can be handled in the CLP framework. So, in [DBLP:journals/toplas/BistarelliR01], it has been extended to also handle soft constraints. This has led to a highlevel and flexible declarative programming formalism, called Soft CLP (SCLP), allowing to easily model and solve reallife problems involving constraints of different types. Roughly speaking, SCLP programs are logic programs where constraints are represented by predicates which are defined by clauses whose body is a value of the semiring modelling the levels of satisfiability or the costs of the constraints. The flexibility of the approach is due to the fact that the same framework can be used to handle different kinds of soft constraints by simply choosing different semirings. It can indeed be used to handle fuzzy, probabilistic, prioritized and optimization problems, as well as classical constraints.
In this paper, before presenting an application of the SCLP framework to the emobility, we provide a slightly more general and elegant presentation of the SCSP framework based on the notion of named semiring, as briefly presented in [BuscemiM07]. In particular, soft constraints are elements of the named semiring which, besides the additive and multiplicative operations useful to combine the constraints, is equipped by a permutation algebra and a hiding operator allowing an explicit handling of names. The permutation algebra indeed allows to characterize the support of each constraint, that is, the subset of variables on which the constraint really depends, while the hiding operator allows us to remove variables from the support of a constraint. Then, the SCLP framework can be seen as the general case of the SCSP one.
We propose the SCLP framework as a highlevel specification formalism useful to naturally model and also solve some emobility optimization problems. With emobility indeed new constraints must be considered: electric vehicles (EVs) have a limited range and they take long time to charge. So, it is needed to guarantee that throughout the user’s itinerary the EV never underruns a limit energy level and that the user always arrives in time to all his appointments.
We consider the EV travel optimization problem described in [VWPaper]. In it the user has a set of appointments and he makes a series of decisions about the sequences of trips from an appointment to another one, for example which route to take, if and where to charge the EV and so on. The aim is to find the optimal combination of travel choices which minimizes the users cost criteria. In [VWPaper], the authors propose a hierarchical presentation of the mobility framework, which they exploit to decompose the optimization problem in subproblems, and in particular, they study the journey level one. Here, beside it, we consider the optimization problem of the lower level, i.e., the one of the trip level. This last problem consists in finding the best trips in terms of travel time and energy consumption, while the former one consists in finding the optimal journey, that is, the optimal sequence of coupled trips, again in terms of the same criteria, guaranteeing that the user reaches each appointment in time and that the state of charge (SoC) of the EV never falls below a given threshold.
The trip level problem substantially coincides with the multicriteria version of the shortest path problem modelled in [DBLP:journals/tocl/BistarelliMRS10] as an SCLP program. So, starting from a slightly different specification of this problem, we propose an SCLP program modelling the journey problem. In order to also actually execute both the SCLP programs, we propose CIAO Prolog [ciaoreferencemanualtr], a system supporting constraint logic programming. We therefore explicitly implement the soft framework, by defining two predicates, the and the ones, which respectively model the additive and the multiplicative operations of the semiring.
This work arises from the research activity in the European project ASCENS (Autonomic Service Component ENSembles) aiming at studying formal models, languages, and programming tools, for the modelling and the development of autonomous, selfaware adaptive systems. Emobility is right one of the case studies of the project and our work represents a first answer to the need of a highlevel, declarative, executable specification language and of a powerful and flexible programming environment where emobility problems can be easily and naturally modelled and solved. We indeed show as the SCLP framework is able to satisfy all these requirements and it can thus be used as a support for rapid prototyping and exploratory programming for this kind of problems.
The paper is organized as follows. Section 2 introduces the SCSP framework as an instantiation of the named semiring framework. Section 3 briefly recalls the SCLP language and then Section 4 shows how the trip and journey optimization problems can be modelled and solved through (S)CLP programs. Finally, Section 5 concludes the paper by illustrating some open venues for further works.
2 Soft Constraints by means of Named Semirings
This section presents the soft CSP framework based on semiring [DBLP:conf/ijcai/BistarelliMR95, DBLP:journals/jacm/BistarelliMR97] as an instantiation of the more general framework based on named semiring [BuscemiM07].
The notion of named semiring is based on the ones of csemiring (c stands for constraint) and permutation algebra.
2.1 CSemiring
Definition 1 (csemiring)
A csemiring is a tuple such that:

is a set and ;

is a commutative, associative and idempotent operation, such that is its unit element and is its absorbing element;

is a commutative and associative operation, such that it distributes over , is its unit element, and is its absorbing element.
Thanks to the idempotence of the operator, the relation , defined as if , is a partial order. Intuitively, means that is better than or that implies .
It is possible to prove that: (i) the two operations and are monotone on ; (ii) is its minimum and its maximum; (iii) is a complete lattice and is its least upper bound^{1}^{1}1Actually, in order to prove this result, we must assume that the sum of an infinite number of elements exists.. Finally, if is idempotent then: (iv) distribute over ; (v) is a distributive lattice, and (vi) is its greatest lower bound.
2.2 Permutation Algebra
Here we briefly recall the notion of permutation algebra. We refer the reader to [DBLP:journals/lisp/GadducciMM06] for a detailed introduction.
In the following, we fix a chosen infinite, countable, totally ordered set of names, which we denote by .
Definition 2 (Permutations)
A name substitution is a function , while a permutation is a bijective name substitution. The set of all such permutations on is denoted by .
Definition 3 (Kernel)
Let be a permutation on . The kernel of is the set of the names that are changed by the permutation, formally, .
A permutation is finite if its kernel is finite.
From now on we consider only finite permutations.
In the following, we introduce the notion of permutation algebra. It consists of a pair composed of a carrier set and a description of how the elements of the carrier set are transformed by permutations.
Definition 4 (Permutation Algebras)
The permutation signature on is defined as the set of unary operators plus the two axioms and .
A permutation algebra consists of a carrier set and the set of the interpreted operations .
Definition 5 (Support)
Let be a permutation algebra and an element of its carrier set. The support of , , is the smallest set of names such that, given a permutation , if for all , then .
Intuitively, represents the free names of : indeed the permutations which do not modify them are not influent on .
Definition 6 (Finitely supported algebra)
A permutation algebra is finitelysupported if each element of its carrier has finite support.
2.3 Named cSemiring.
A named semiring [BuscemiM07] is a csemiring plus a finitelysupported permutation algebra and a hiding operator . The permutation algebra allows characterizing the finite set of free names of each element of the named semiring (represented by the support of ), while applied to makes the name local in .
Definition 7 (Fusion)
A (name) fusion is a total equivalence relation on with only finitely many nonsingular equivalence classes. We denote by the fusion with a unique nonsingular equivalence class consisting of and .
Definition 8 (Named csemiring)
A named csemiring is a tuple where:

for ;

is a csemiring;

is a finitesupport permutation algebra;

, for each name , is a unary operation;

for all and for all the following axioms hold:
(FUSE)  iff 
(HIDE)  if 
if if  
(PERM)  
if 
In the (FUSE) axiom, denotes where is replaced by .
2.4 The Named SCSP Framework
As briefly shown in [BuscemiM07], named csemirings can be suitably instantiated to model SCSPs.
Definition 9 (Constraints)
Let be a csemiring, a set of totally ordered names, and a finite domain of interpretation for . A soft constraint is a function , which associates a value of to each assignment of the names.
We define as the set of all soft constraints over , and .
Definition 10
Let be a csemiring, a set of totally ordered names, and a finite domain of interpretation for . Moreover, let be the set of all soft constraints over , and . We define the as the named csemiring , where fusions are defined as if and otherwise; ; ; ; with ; and for all .
The assignment is defined as usual: if and otherwise.
Note that, by definition, each constraint involves all the names in , but it really depends on the assignment of the names in , and intuitively, restricting means eliminating a name from the support of the constraint, by choosing the best value for it.
Definition 11 (Soft CSP)
A soft constraint satisfaction problem (SCSP) is a pair , where is a set of constraints and is a set of names.
Intuitively, represents the set of interface names of the constraint set .
Definition 12 (Solution)
Let be an SCSP. The solution of is the constraint , with .
Definition 13 (Best level)
Let be an SCSP. Then, the best level of consistency of is defined as the constraint , where .
Varying the semiring , on which the named semiring is based, several kinds of problems can be represented: we consider the semiring for classical CSPs; for fuzzy CSPs; and for optimization CSPs.
Example 1
Let be the SCSP with three names , which can take values in . We assume that only and are of interest, while the constraints model the fact that all names must take different values.
We consider the semiring , introduced above, and we define three constraints, one for each pair of names, , and , associating the worst semiring value to the assignments which give the same color to both the names of interest for the constraint. In particular, we associate to all the assignments giving the same color to both names, if at most one name takes the color red then we associate , otherwise we associate .
In Horn logic this problem can be expressed as the predicate below:
if then else if either or are red then else .
The predicate represents the constraint shown on the left of Fig. 1, where the names and represents the only names of the support. Note that in this representation we only show the assignment for the names of the support of the constraint. Therefore, each table entry actually represents different entries, one for each possible color of the names which are not in the support. The constraint representing the problem is then represented by the combination of three constraints. Indeed, , and respectively represent the three constraints , and , obtained by applying to the constraint represented by the permutations mapping the names of the support and to the names of interest of the three constraints. As said above, the relevant names of the problem are just and , thus the solution of the problem is obtained by combining the three constraints and restricting the scope of the name . It can be expressed as . The resulting constraint, represented by the predicate , is shown on the right of Fig. 1. Also in this case, we show the assignment of just the two names of the support. Each table entry is the minimum value among the ones of the solutions providing a different color for . In this case, the best level of solution is , the minimum over all the entries.



3 Soft Constraint Logic Programming
This section briefly introduces the soft constraint logic programming (SCLP). For a more detailed and complete introduction, we refer the reader to [DBLP:journals/toplas/BistarelliR01].
The SCLP framework extends the classical constraint logic programming to also handle SCSPs. We can say that an SCLP program over a certain csemiring is just a CLP program where constraints are defined over . In the following, we fix a semiring .
An SCLP program is hence a set of clauses composed of a head and a body, plus a goal. The head of a clause is simply an atom, while the body can be either a collection of atoms, or a csemiring value, or a special symbol , denoting that it is empty. In this two last cases clauses are called facts and define predicates representing constraints. When the body is empty, we interpret it as , the best element of the semiring. Atoms are ary predicate symbols followed by a tuple of terms, which can be either a constant or a variable or an nary function symbol followed by terms. Ground terms are terms without variables, and finally, a goal is a collection of atoms.
Example 2
As an example, consider the simple SCLP program on the left of Fig. 2, previously proposed in
[DBLP:journals/toplas/BistarelliR01].
We consider the semiring and the domain .
The program is composed of six clauses. The last two are facts and
the semiring values and , associated respectively with
the atoms and , mean that they respectively cost and units.
The set of the semiring contains all possible
costs, and the operations and allows us to minimize
the sum of the costs.
We consider as goal the atom :s(a)
: later on we will show its semantics.


Three equivalent semantics for the SCLP languages have been defined in [DBLP:journals/toplas/BistarelliR01]: the modeltheoretic, the fixpoint, and the operational one. These semantics are conservative extensions of the corresponding ones for logic programming: this means that by choosing the csemiring we get exactly the LP semantics.
Actually, we can see the SCLP framework as the general case of the SCSP one. As shown in Example 1, we can indeed express an SCSP program as a set of predicates representing the constraints together with a unique clause which represents the problem and combines all constraints. In the case of the SCLP, the main difference is that the depth of clause nesting is unlimited and the possible values of variables are elements of the Herbrand universe. So, the meaning of a predicate assigns a semiring value to all evaluations of variables and to the Herbrand domain. This is exactly what for example the fixpoint semantics of the SCLP language does.
In order to present the fixpoint semantics, we need to introduce the notion of interpretation and the operator, mapping interpretations into interpretations.
Definition 14 (Interpretation)
An interpretation consists of a domain , representing the Herbrand universe, together with a function which takes a predicate and an instantiation of its arguments (that is, a ground atom), and returns an element of the semiring: , where represents the set of nary predicates and is the set of the values of the semiring.
Since interpretations are functions from ground
atoms to semiring values, we consider programs
composed of clauses where the head and the body contain only ground atoms.
So, for example, in the SCLP program of Example 2,
the clause s(X) : p(X,Y)
is replaced with all its instantiations.
In particular, for each , we have three clauses s(d) : p(d,a)
,
s(d) : p(d,b)
, and s(d) : p(d,c)
.
Definition 15 ( Operator)
Let be an SCLP program and the set of all its interpretations. Moreover let be an interpretation and a ground atom, such that contains clauses defining the predicate in and the clause is of the shape . Then, we define the operator as . Whenever is a semiring value, its meaning is fixed in any interpretation and it is the semiring value itself.
Definition 16 (Partial Order of Interpretations)
Let be a program and the set of all its interpretations. We define the structure , where if for any ground atom , where is the order induced by the semiring.
Note that is a complete partial order and its glb coincides with the glb operation in the lattice (extended to interpretations). Since the function is monotone and continuous over this complete partial order, then has a least fixpoint and it can be obtained by computing , i.e., by applying to the bottom of the partial order of interpretations, and then repeatedly applying it until a fixpoint.
Example 3
Consider again the SCLP program in Fig. 2.
In the definition of the operator we have to consider the additive and multiplicative operations
of the semiring , that is, the and operations.
As in [DBLP:journals/toplas/BistarelliR01],
we start the computing of the semantics from the bottom of the partial order of interpretations, ,
which maps each semiring element into itself and each ground atom into .
The table on the right of Fig. 2 shows the value associated by the interpretations
to the most interesting ground atoms.
The interpretation represents the fixpoint of .
As an example, we show the computation for one of the most interesting case, the ground atom s(a)
,
which also corresponds to our goal.
We said that the clause s(X) : p(X,Y)
is considered equivalent to all its instantiations.
Therefore, .
4 The Electric Vehicle Travel Optimization Problem
This section presents the EV travel optimization problem, introduced in [VWPaper], and shows how it can be naturally modelled and solved in the SCLP framework.
General description of the problem.
A user has a set of appointments, each of them is in a location and has a starting time and a duration. The user makes a series of decisions regarding the sequences of trips from an appointment to another one. For example, he decides which route he wants to follow, where to park and if and how to charge the EV at the appointment location.
All possible combinations of travel choices form the choice set. A travel choice is optimal if it minimizes the user s cost criteria.
In particular, finding a single optimal trip consists in finding the best trips in terms of travel time and energy consumption. Finding instead the optimal journey, that is, the optimal sequence of coupled trips, consists in finding the best journeys not only in terms of travel time and energy consumption, but also in terms of other important criteria for the user, such as the charging cost, the number of charging events, etc. However, in finding the solution it needs to guarantee that the user reaches each appointment in time and that the state of charge (SoC) of the vehicle never falls below a predefined threshold.
In [VWPaper], the authors propose a hierarchical presentation of the emobility framework, which they exploit to decompose the optimization problem in suboptimization problems. In particular, they identify four levels of mobility: the component level, whose main tasks are the inter and intracomponent coordination; the trip level, whose main task is the time and energy optimal routing; the journey level, which handles sequences of trips together with charging and parking strategies; and the mobility level, which handles mobility services, such as, car and ride service.
Each level represents a different optimization problem and the results of the lower level will be inputs of the higher level. However, since, in general, the best solution of the lower level could be not optimal for the higher one, the results of the lower level could contains several solutions and not only the best one.
In the following, we consider only the trip level and the journey level optimization problems. In particular, we first present their formalization and then we show how we can model them in the SCLP framework.
Formalizations of the trip and journey level optimization problems.
The trip level optimization problem substantially coincides with the multicriteria shortest path problem. The road network is indeed represented by a directed graph , where each arc from a node to a node has associated a label , that is, a pair whose elements represent the costs, respectively in terms of time and energy consumption, of the arc from to .
So, given the road network , such as the one on the left of Fig. 3, a source node and a destination node , the problem consists in finding all the best paths between and in terms of time and energy consumption. Note that, since the costs of the arcs are elements of a partially ordered set, the solution can contain several paths, that is, all paths which are not dominated by others, but which have different incomparable costs. For example, if we want to know the best paths from to in the graph of Fig. 3, the solution will contain both the paths with cost and with cost . The former is indeed better in terms of time while the latter in terms of energy consumption.




Road Network  Appointments  Charging Stations 
As far as the journey level optimization problem is concerned, we use the formalization presented in [VWPaper]. Actually, we consider a simpler version of it, which avoids to consider car parks and the time that the users would take to go from either the car park or the charging station to the location of the appointment. Moreover, we consider only the time and energy consumption as cost criteria to be minimized. All these simplifications allows a slender and more readable presentation of the SCLP program modelling the problem.
Let be the set of the user’s appointments. In order to describe the problem, we use different time variables. All of them have the shape , where denotes the appointment, ( stands for drive and for appointment), and ( stands for start and for end).
Each appointments is defined by a location , a starting time , an end time and therefore a duration . In order to go from an appointment to the next one , the user leaves with an EV from the location at time and drive to location . The user travels along the route alternative (computed by the trip level problem), which consumes energy and hence reduces the SoC. Obviously, the chosen route must allow the user to arrive to destination with the SoC of his EV. We assume that the SoC always decreases during driving and increases during charging events^{2}^{2}2This is the typical behaviour of EVs, however, as explained in [VWPaper], in particular cases it might also increase during driving and decreases during charging.. The user arrives at and the appointment starts at . The user must arrive in time to the appointment, so it is required that . During the appointment, it is also possible to schedule a charging event if the SoC of the EV is not enough to continue the journey. We assume to have a set of charging stations. Each of them is simply defined by its name , the number of available charging spots , and the location where it is.
Therefore, given the road network , a set of appointments, as the ones described in the table in the middle of Fig. 3, and a set of charging stations, as the ones in the rightmost table of Fig. 3, the problem consists in finding all the best journeys through all the appointment locations in terms of time and energy consumption. As for the travel optimization problem, also here the solution can contain several journeys, that is, all the nondominated ones.
SCLP programs for the optimization problems.
In the following, we show how the SCLP framework can be used as a linguistic support and a highlevel and flexible programming environment where naturally modeling and solving the two optimization problems presented above.
As far as the trip level optimization problem, we propose a slightly different version of the model proposed in [DBLP:journals/tocl/BistarelliMRS10] for the multicriteria shortest path problem. So, as there, we consider an SCLP program over the csemiring denoted which, given a source node and a target node , allows us to obtain the set of the costs of all nondominated paths from to .
The semiring is obtained starting from a semiring , which in our case is the one modelling the costs associated to each edge, i.e, , where and are the and operations extended to pairs. Indeed, in general we want to minimize the sum of each cost, but, since we want to obtain all the non dominated paths, we consider .
Given a semiring , we define , where is the Hoare Power Domain of , that is, implies . These sets are isomorphic to those containing just the nondominated values, thus, in the following, we will use this more compact and efficient representation, where each element of will represent the costs of all nondominated paths from a node to another one. The top element of the semiring is the set (its compact form is {1}, which in our example is ; the bottom element is the empty set; is the formal union that takes two sets and gives their union; takes two sets and produces another one obtained by multiplying (using the multiplicative operation of the original semiring, in our case ) each element of the first set with each element of the second one.
Note that, in the partial order induced by the additive operation of this semiring, intuitively means that for each element of , there exists an element of which dominates it (in the partial order of the original semiring).
Following [DBLP:journals/tocl/BistarelliMRS10], in order to also really execute the SCLP program, we model the problem with a program in CIAO Prolog [ciaoreferencemanualtr], a system supporting CLP, by explicitly implementing the soft framework. The program is shown in Fig. 4.
:module(paths,_,_). :use_module(library(lists)). :use_module(library(aggregates)). minPair([T,E],[T1,E1]): T < T1, E < E1. times([T1,E1],[T2,E2],[T3,E3]): T3 = T1 + T2, E3 = E1 + E2. plus([],L,[]). plus([[P,T,E]RestL],L, [[P,T,E]BestPaths]): nondominated([T,E],L), plus(RestL,L,BestPaths). plus([[P,T,E]RestL],L,BestPaths): \+nondominated([T,E],L), plus(RestL,L,BestPaths). nondominated([T,E],[]). nondominated([T,E],[[P,T1,E1]L]): \+minPair([T1,E1],[T,E]), nondominated([T,E],L). 
edge(p,q,[2,4]). edge(q,t,[2,4]). edge(p,r,[2,7]). edge(r,s,[3,3]). edge(p,t,[3,9]). edge(r,q,[1,1]). edge(q,r,[1,1]). edge(s,t,[1,1]). edge(q,s,[4,8]). path(X,Y,[X,Y],_,[T,E],Lim): edge(X,Y,[T,E]), E =< Lim. path(X,Y,[XL],V,[T,E],Lim): edge(X,Z,[T1,E1]), nocontainsx(V,Z), path(Z,Y,L,[ZV],[T2,E2],Lim), times([T1,E1],[T2,E2],[T,E]), E =< Lim. paths(X,Y,Lim,BestPaths): findall([P,T,E],path(X,Y,P,[X],[T,E],Lim),ResL), plus(ResL,ResL,BestPaths). 
Here we consider the road network presented in Fig. 3, so we have a set of clauses modelling it. In particular, we have a set of facts modelling all the edges of the graph. Each fact has the shape , where represents the source node, represents the destination node and the pair represents the costs of the edge in term of time and energy. Note that, differently from what would happen in the pure SCLP framework, these facts (representing constraints) have the cost in the head of the clauses and not in the body. This is needed for implementing the soft framework, and in particular the two operations of the semiring.
Moreover, there are two clauses describing the structure of paths: the upper one models the base case, where a path is simply an edge, while the lower one represents the recursive case, where a path is an edge plus another path. The head of the path clauses has the following shape , where and are respectively the source and destination nodes, is the list needed to remember, at the end, all the visited nodes of the path in the ordering of the visit, is the list of the already visited nodes needed to avoid infinite recursion where there are graph loops, is used to remember the cost of the path in terms of time and energy, and finally, represents the maximum amount of energy that the EV can consume. It is used to retrieve only the paths with a total cost in terms of energy equal to or less than the passed value.
The and clauses are useful to model the soft framework. In particular, the first clause is useful to model the multiplicative operation of the semiring allowing us to compose the global costs of the edges together, time with time and energy with energy. The predicate instead mimics the additive operation and it is useful to find the best, i.e. nondominated, paths among all the possible solutions. The predicate is indeed used in the body of the clause, which collects all the paths from a given source node to a given destination node and returns the best solutions chosen with the help of the predicate. So, if we want to know the best paths, in the graph of Fig. 3, from to with a total cost in terms of energy consumption less than or equal to , we have to perform the CIAO query , where the variable will be instantiated with the list containing all the nondominated paths. In particular, for each of them, the list will contain the sequence of the nodes in the path and the total cost of the path in terms of time and energy. The output of the CIAO program for this query is shown in Fig. 5.
Now, by using the SCLP program modelling the travel optimization problem, we can also show the one modelling the journey level problem. Also in this case, as before, we consider the semiring and we propose a CIAO program, where we also model the soft framework. The CIAO program modelling the journey optimization problem is presented in Fig. 6.
:module(journey,_,_). :use_module(paths). plus([],L,[]). plus([[P,T,E,ChEv]RestL],L, [[P,T,E,ChEv]BestPaths]): nondominated([P,T,E],L), plus(RestL,L,BestPaths). plus([[P,T,E,ChEv]RestL],L, BestPaths): \+nondominated([P,T,E],L), plus(RestL,L,BestPaths). nondominated([P,T,E],[]). nondominated([P,T,E], [[P1,T1,E1,ChEv1]L]): \+minPair([T1,E1],[T,E]), nondominated([P,T,E], L). appointment(p,7,1). appointment(r,11,2). appointment(t,18,3). chargingStation(csp1,7,p). chargingStation(csr1,4,r). chargingStation(csr2,0,r). journeys(Places,EV,BestJourneies): findall([P,T,E,ChEv],journey(Places,P,ChEv,[T,E],SoC),ResL), plus(ResL,ResL,BestJourneies). 
journey([X,Y],[P],[],[T,E],SoC): appointment(X,Tx,Dx), appointment(Y,Ty,Dy), path(X,Y,P,[X],[T,E],SoC), timeSum(Tx,Dx,T,ArrT), ArrT=<Ty. journey([X,Y],[P],[[X,ID]],[T,E],SoC): appointment(X,Tx,Dx), appointment(Y,Ty,Dy), \+path(X,Y,P,[X],[T,E],SoC), chargingStation(ID,Spots,X),Spots>0, newSoC(SoC,Dx,NewSoC), path(X,Y,P,[X],[T,E],NewSoC), timeSum(Tx,Dx,T,ArrT), ArrT=<Ty. journey([X[YZ]],[PLP],ChEv,[T,E],SoC): appointment(X,Tx,Dx), appointment(Y,Ty,Dy), path(X,Y,P,[X],[T1,E1],SoC), timeSum(Tx,Dx,T1,ArrT), ArrT=<Ty, journey([YZ],LP,ChEv,[T2,E2],(SoCE1)), times([T1,E1],[T2,E2],[T,E]). journey([X[YZ]],[PLP],[[X,ID]ChEv],[T,E],SoC): appointment(X,Tx,Dx), appointment(Y,Ty,Dy), \+path(X,Y,P,[X],[T1,E1],SoC), chargingStation(ID,Spots,X), Spots>0, newSoC(SoC,Dx,NewSoC), path(X,Y,P,[X],[T1,E1],NewSoC), timeSum(Tx,Dx,T1,ArrT), ArrT=<Ty, journey([YZ],LP,ChEv,[T2,E2],(NewSoCE1)), times([T1,E1],[T2,E2],[T,E]). 
We have a set of facts modelling the user’s appointments and the charging stations. In particular, for each appointment , there is a clause , while for each charging station we have a clause
Moreover, there are four clauses describing the structure of journeys. The upper two represent the base case, while the other two represent the recursive case. The first clause models the case where a journey is simply a path with a cost in terms of energy less than or equal to the SoC of the EV. The second clause models the case where the SoC of the EV is not enough to do any path and so a charging event, incrementing the energy level, must be scheduled. The third clause represents the case where a journey is a path with a cost in terms of energy less than or equal to the SoC of the EV, plus another journey. Finally, the last clause models the recursive case where a charging event is needed. In all cases we check that the paths allow the user to arrive in time.
The head of the journey clauses has the shape , where is the list of the locations of the appointments, is the list needed to remember, at the end, all the paths of the journey in the correct ordering, is the list needed to remember all the charging events needed to complete the journey, represents the cost of the journey in terms of time and energy, and finally, represents the current energy level of the EV.
To make the program as readable as possible, we omit the predicates and , useful to respectively compute the new energy level of the EV after a charging event and the arriving time of the user to an appointment.
The clauses are useful to model the soft framework and they are very similar to the ones of the trip level problem. The only difference is that here we have to consider the charging events. Moreover, note that we reuse the predicate defined in the CIAO program in Fig. 4.
The clause collects all the journeys through a set of locations (the ones of the user’s appointments) and returns the best solutions chosen with the help of the predicate. So, if we want to know the best journeys, in the graph of Fig. 3, through the locations where the user has the appointments, with an EV having an energy level equal to , we have to perform the CIAO Prolog query , where are the locations of the appointments and the variable will be instantiated with the list containing all the nondominated journeys. In particular, for each of them, the list will contain the sequence of the paths of the journey, the total cost of the journey in terms of time and energy, and the list of the charging events, each of them described by the name of the charging station and its location. The output of the CIAO program for this query is shown in Fig. 7.
5 Conclusion
In this paper we proposed the SCLP framework as a highlevel declarative, executable specification notation to model in a natural way some aspects of the emobility optimization problem [VWPaper], consisting in coordinating electric vehicles in order to overcome both energetic and temporal constraints. In particular, we considered the trip and journey optimization subproblems, consisting in finding respectively the energy and timeoptimal route from one destination to another one, and the optimal sequence of coupled trips, in terms of the same criteria, guaranteeing that the user reaches each appointment in time. For both the optimization problems, we provided an SCLP program in CIAO Prolog, by explicitly implementing the soft framework, that is, the additive and the multiplicative operations of the chosen semiring. The former is a slight variant of the CIAO program proposed in [DBLP:journals/tocl/BistarelliMRS10, Section 4.4] to specify the multicriteria version of the shortest path problem. With respect to the program proposed there, here we implemented a different semiring, (also proposed in [DBLP:journals/tocl/BistarelliMRS10]), i.e., the one based on the Hoare Power Domain operator, which allowed us to obtain only the best (i.e. nondominated) routes in terms of time and energy consumption. We thus provided an implementation of the two operations of this semiring, by defining two predicates modelling them. The SCLP program modelling the journey optimization problem then uses the trip optimization problem results as inputs. It is also based on the same semiring that, in this case, allowed us to find the best journeys in terms of the two cost criteria.
As said above, the soft framework is explicitly implemented into each CIAO program: there is for example a different predicate in each optimization program we have proposed. However, it would be interesting to study a general way to embed the soft framework in Ciao Prolog. Trivially, one could provide a library offering a more general implementation of the operations of the semiring of each type of problem. Most interestingly, one could instead think to provide a metalevel implementing more efficiently the soft framework.
Differently from our solution, which allows us to obtain the set of all the optimal journeys, in the mathematical model proposed in [VWPaper] a form of approximation is introduced, by considering an aggregated cost function to be optimized. Their goal is indeed to minimize this cost function, which considers different cost criteria: besides the travel time and the consumed energy, they also take into account the charging cost, the number of charging events, etc. In modelling the problem, here we introduced a simplification by considering just the two main cost criteria, that allows us a slender presentation of the work. However, it is obvious that the SCLP programs can be easily modified to also take into account several other cost criteria. On the other side, we preferred not to introduce any approximation of the solution, by instead returning all optimal journeys considered equivalently feasible. However, since the use of partially ordered structures, as in our case, can in general lead to a potentially exponential number of undominated solutions, sometimes it becomes crucial to keep the number of configurations as low as possible through some form of approximation allowing us to adopt a total order. In this case, the right solution could be to adopt a function that composes all the criteria in a single one and then to choose the best tuple of costs according to the total ordering that the function induces [DBLP:journals/tocl/BistarelliMRS10, Section 6.1].
As said above, our aim is mainly to propose the SCLP framework as an expressive and natural specification language to model optimization problems. We indeed think that not only problems representing an extension of the one treated here can be modelled by adapting the solution we presented easily enough, but that in general our approach can be followed to model hierarchical optimization problems. All the SCLP programs we proposed are effective only when data of small size are considered. We are indeed conscious that the proposed encodings cannot be used to really solve the problem on practical cases, but on the other side, we think that CIAO represents a powerful system programming environment allowing us not only to write declarative specifications but also to reason about them.
It is therefore clear that here we do not take care of the performances of the proposed programs and that our aim is not to compare the performance with existing algorithms solving these problems. We indeed leave as future work the study of how to improve the performance of our programs. In [DBLP:journals/tocl/BistarelliMRS10, Section 8], the authors show some possible solutions that could be used towards this end, such as tabling and branchandbound techniques (implementable for example in ECLiPSe [DBLP:books/daglib/0018272]). We however would also like to study how our programs can take advantage of the use of dynamic programming techniques based, for example, on the perfect relaxation algorithm for CSPs [DBLP:conf/iclp/MontanariR91].
Finally, from a theoretical point of view, as future work, we plan to propose a more general framework based on named semiring, allowing us to give a unifying presentation of the SCSP and SCLP frameworks, providing an explicit handling of the names.
Comments
There are no comments yet.