<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>The Movie Database Case: Solutions using Maude and the Maude-based e-Motions tool</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Antonio Moreno-Delgado Francisco Dura ́n Dpto. Lenguajes y Ciencias de la Computacio ́n University of Ma ́laga</institution>
          ,
          <country country="ES">Spain</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2014</year>
      </pub-date>
      <abstract>
        <p>The paper presents solutions for the TTC 2014 Movie Database Case, both in the e-Motions DSML and in the rewriting-logic formal language Maude. The DSMLs defined in e-Motions are automatically transformed into Maude specifications, which are then used for simulation and analysis purposes. e-Motions is a general purpose language, in which real-time languages may be modeled, with full support for OCL and other advanced features. The fact that the solutions given directly in Maude lack the overhead included by e-Motions to deal with all those extra features not needed in the current case study, makes these solutions much more efficient, and able to deal with bigger problems.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <sec id="sec-1-1">
        <title>The e-Motions system documentation and several examples are available at http://atenea.lcc.</title>
        <p>uma.es/e-Motions. The Maude web site is at http://maude.cs.uiuc.edu. The solution sources
are at http://github.com/antmordel/TTC14eMotions.
e-Motions</p>
      </sec>
      <sec id="sec-1-2">
        <title>The definition of a DSML typically comprises three tasks: (i) the definition of its abstract syntax, (ii)</title>
        <p>the definition of its concrete syntax and (iii) the specification of its behavior. In e-Motions the abstract
syntax is defined by means of an Ecore metamodel, in which all the language concepts and the relations
between them are specified. The concrete syntax is provided by defining the so-called Graphical Concrete
Syntax (GCS). A GCS is a model (conforms the GCS metamodel) where an image is attached to each
concept defined in the abstract syntax. Then, the behavior of a DSML is specified using visual
graphtransformation rules. An e-Motions rule consists of a Left-Hand Side (LHS), a Right-Hand Side (RHS)
and zero or more Negative Application Conditions (NACs). The LHS defines a (sub)-graph matching,
optionally conditional. The RHS specifies a (sub)-graph replacement, which if the rule is applied, every
object in the LHS that is not in the RHS is deleted, new objects in the RHS that are not in the LHS are
created, and those objects whose attributes (or links) are changed are updated. NACs specify conditions
or (sub)-graphs such that if there is a matching, the rule cannot be fired.</p>
        <sec id="sec-1-2-1">
          <title>Rewriting Logic and Maude</title>
        </sec>
      </sec>
      <sec id="sec-1-3">
        <title>Rewriting logic (RL) [3] is a logic of change that can naturally deal with state and with highly</title>
        <p>nondeterministic concurrent computations. In RL, the state space of a distributed system is specified as
an algebraic data type in terms of an equational specification (S; E), where S is a signature of sorts (types)
and operations, and E is a set of equational axioms. The dynamics of a system in RL is then specified by
rewrite rules of the form t ! t0, where t and t0 are S-terms. This rewriting happens modulo the equations
E, describing in fact local transitions [t]E ! [t0]E . These rules describe the local, concurrent transitions
possible in the system, i.e. when a part of the system state fits the pattern t (modulo the equations E)
then it can change to a new local state fitting pattern t0. Notice the potential of this type of rewriting, and
the very high-level of abstraction at which systems may be specified, to perform, e.g., rewriting modulo
associativity or associativity-commutativity.</p>
      </sec>
      <sec id="sec-1-4">
        <title>Maude [1] is a wide spectrum programming language directly based on RL. Thus, Maude integrates</title>
        <p>an equational style of functional programming with RL computation. Maude also supports the modeling
of object-based systems by providing sorts representing the essential concepts of object, message, and
configuration. A configuration is a multiset of objects and messages (with the empty-syntax,
associativecommutative, union operator __) that represents a possible system state.</p>
      </sec>
      <sec id="sec-1-5">
        <title>Maude provides a whole formal environment where we can perform proofs of correctness of our solutions. Specifically, we have use the reachability analysis tool for performing checks on the correctness of our specification.</title>
        <p>2</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Solutions</title>
      <sec id="sec-2-1">
        <title>We present two solutions for the different tasks, one graphical solution using e-Motions, and another one using directly Maude. Each task is solved by defining respective DSMLs, which share their abstract and concrete syntaxes. The abstract syntax used is the one provided in [2] — we will see below that some of the tasks have required extensions of this common syntax. The main differences between the DSMLs</title>
        <p>defined for the different tasks is in their concrete behaviors describing what need to be done in each case,
that is, the rewrite rules defining the behavior depends on the concrete task and its solution.</p>
        <p>Although the expressiveness of e-Motions is very welcome in complex problems, thanks to its
capabilities to express problems visually, very intuitively, and in a language very close to the problem domain,
the overhead to be paid in cases like the ones at hand is too high. Specifically, the generality provided
by its support for OCL expressions and time requirements, makes that the Maude code generated by
the e-Motions tool is not as time performant as we would like. However, the general purpose
rewritemodulo engine at the core of Maude may also be used as a transformation language. Thus, together with
the e-Motions solution we present an optimized Maude solution for each task.</p>
      </sec>
      <sec id="sec-2-2">
        <title>As we will see below, the Maude version of the transformation closely follows the transformations</title>
        <p>provided in e-Motions, were all rewrite rules are instantaneous and expressions are solved directly by</p>
      </sec>
      <sec id="sec-2-3">
        <title>Maude built-in types instead of by the OCL interpreter. Indeed, for problems as simple as the ones at</title>
        <p>hand, we will see that the representation distance between Maude and e-Motions to the problem domain
would be very small, making both solutions very appropriate. Although a more in depth analysis of the
problem at hand would most probably have allowed us to even improve the numbers obtained, we have
preferred to keep the specification clear and intuitive.</p>
        <sec id="sec-2-3-1">
          <title>Task 1</title>
        </sec>
      </sec>
      <sec id="sec-2-4">
        <title>Task 1 comprises the generation of synthetic models (conforming the movie database metamodel [2])</title>
        <p>from an input parameter N 0. We first present an e-Motions solution and then a Maude solution.</p>
        <p>
          Firstly, following an e-Motions based approach, we define the abstract and concrete syntax and the
behavior of our so-called Task 1 DSML. Taking a parameter N as input model, Task 1 DSML generates a
model containing synthetic data. As it has been introduced in Sect. 1, the abstract syntax of a DSML is
given in e-Motions by means of an Ecore metamodel. Since we model the solution of the task as a model
that evolves until reaching its final solution, we take as metamodel the one provided in [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ], which we
call Movies MM, extended with a Parameter concept. The class Parameter has two integer attributes,
which represent positive graphs and negative graphs, respectively, for the generation following Henshin
graphs [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]. For the concrete syntax, Fig. 4 in Appendix A shows how an image has been attached to each
concept modeled in the Movies MM.
        </p>
      </sec>
      <sec id="sec-2-5">
        <title>The behavior of this Task 1 DSML is then given by means of two in-place transformation rules:</title>
        <p>createPositive and createNegative. Fig. 1(a) shows the createPositive rule, which takes an
object p of type Parameter, with nP attribute greater or equal than 0, and produces synthetic data
conforming to the Henshin rules. Fig. 1(b) shows the createNegative rule, which is analogously defined.</p>
      </sec>
      <sec id="sec-2-6">
        <title>Note that this solution is really close to the problem specification in [2]. Fig. 1, and Fig. 2 in the case</title>
        <p>
          description [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ], specifying the data generation, are almost the same. This demonstrates how close the
solution by e-Motions is to the problem domain, and how convenient its graphical facilities are.
        </p>
      </sec>
      <sec id="sec-2-7">
        <title>Our Maude-based solution for Task 1 consists of an object-based Maude specification, which matches</title>
        <p>very closely the e-Motions solution. See Appendix B) for the Maude specification of rule createPositive
and for a comparison of the number of rewrites and execution times for both solutions.</p>
        <sec id="sec-2-7-1">
          <title>Task 2</title>
        </sec>
      </sec>
      <sec id="sec-2-8">
        <title>Task 2 consists in finding all ‘couples’ from a given model, given that two persons are a ‘couple’ if</title>
        <p>
          they played together in at least three movies [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]. Couples are to be obtained from the model obtained in
        </p>
      </sec>
      <sec id="sec-2-9">
        <title>Task 1. 4</title>
        <p>(a) The createPositive rule.
(b) The createNegative rule.</p>
      </sec>
      <sec id="sec-2-10">
        <title>The e-Motions-based solution for this task is implemented with one single rule, createCouple,</title>
        <p>shown in Fig. 2. Person objects are shown using square shapes because Person is an abstract class and
it does not have attached image. The createCouple rule models the creation of a couple by taking two
persons and generating a couple with them. The rule has two conditions: a positive condition stating that
“the number of movies in the intersection between the movies of per1 and per2 is greater or equal than</p>
      </sec>
      <sec id="sec-2-11">
        <title>3”; and a negative condition, coupleHasNotBeenCreated, requiring that the couple does not exists yet.</title>
      </sec>
      <sec id="sec-2-12">
        <title>See Appendix C for an alternative specification of the e-Motions solution, in which we reduce the number of candidate matchings, Maude specifications of the solution, and a comparison of the results.</title>
        <sec id="sec-2-12-1">
          <title>Task 3</title>
        </sec>
      </sec>
      <sec id="sec-2-13">
        <title>Given a model with couples already created, Task 3 consists in calculating the average rating of</title>
        <p>shared movies for each of these couples.</p>
      </sec>
      <sec id="sec-2-14">
        <title>The e-Motions-based solution consists in one single rule, shown in Fig. 3, in which the average is calculated only once for each couple. Notice the use of an action in the NAC of the rule to state that the value has not already been calculated.</title>
      </sec>
      <sec id="sec-2-15">
        <title>See Appendix D for the Maude counterpart, and a comparison of the number of rewrites and execution times for the solutions.</title>
        <p>3</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Conclusions</title>
      <p>We have presented solutions for the TTC 2014 Movie Database Case both in the e-Motions DSML and
in the rewriting-logic formal language Maude.</p>
      <p>e-Motions provides a very rich set of features, that enables the formal and precise definition of
real-time DSMLs as models in a graphical and intuitive way. It makes use of an extension of in-place
model transformation with a model of timed behavior and a mechanism to state action properties. The
extension is defined in such a way that it avoids artificially modifying the DSML’s metamodel to include
time and action properties. Moreover, it supports attribute computations and ordered collections, which
are specified by means of OCL expressions. All these features makes the language very expressive, but
directly impact on performance.</p>
      <sec id="sec-3-1">
        <title>The Maude solutions presented are also very intuitive and simple. The fact that the solutions given directly in Maude lack the overhead included by e-Motions to deal with all those features it provides that are not needed in the current case study, makes the solutions given much more efficient, and able to deal with bigger problems.</title>
      </sec>
      <sec id="sec-3-2">
        <title>Acknowledgments. This work is partially funded by Projects TIN2012-35669 and TIN2011-23795.</title>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>A Figures</title>
      <p>(a) Actor.
(b) Actress.
(c) Movie.
(d) Couple.
(e) Parameter.</p>
    </sec>
    <sec id="sec-5">
      <title>Maude listings and results for Task 1</title>
      <sec id="sec-5-1">
        <title>As in the e-Motions solution for Task 1, the Maude solution has two rewrite rules: createPositive</title>
        <p>
          and createNegative. Listing 1 shows the createPositive Maude rule, which takes the message
createPositive(s(N:Nat)) and returns a configuration conforming the Henshin specification [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]. A
similar rule generates the negative cases. Notice that the Maude solution is very much like the e-Motions
solution. In fact, the former could be seen as the textual version of the latter.
        </p>
        <p>The execution performance for both solutions is shown in Table 1, which shows the number of
rewrites and execution times for both solutions. As explained above, the execution times for the Maude
specification obtained from the e-Motions definition grows very quickly. Notice that, although the
number of rewrites grows linearly with respect to N, the time is exponential due to the infrastructure to deal
with all the extra features in e-Motions. However, notice how the number of rewrites for the Maude
solution grows linearly as well, but in this case the execution times grow more slowly, being able to handle
problems of much bigger sizes.</p>
        <p>Listing 1: createPositive Maude rule.
rl [ createPositive ] :
createPositive (s(N ))
freshOid (N ')
=&gt;
createPositive (N)
&lt; N ' : Movie | rating: (10.0 * float (N )) &gt;
&lt; N ' + 1 : Movie | rating: (10.0 * float (N) + 1.0) &gt;
&lt; N ' + 2 : Movie | rating: (10.0 * float (N) + 2.0) &gt;
&lt; N ' + 3 : Movie | rating: (10.0 * float (N) + 3.0) &gt;
&lt; N ' + 4 : Movie | rating: (10.0 * float (N) + 4.0) &gt;
&lt; N ' + 5 : Actor | name: (" a" + string (10 * N , 10)) ,</p>
        <p>movies: (N ', N ' + 1, N ' + 2, N ' + 3) &gt;
&lt; N ' + 6 : Actor | name: (" a" + string (10 * N + 1, 10)) ,</p>
        <p>movies: (N ', N ' + 1, N ' + 2) &gt;
&lt; N ' + 7 : Actor | name: (" a" + string (10 * N + 2, 10)) ,</p>
        <p>movies: (N ' + 1, N ' + 2, N ' + 3) &gt;
&lt; N ' + 8 : Actress | name: (" a" + string (10 * N + 3, 10)) ,</p>
        <p>movies: (N ' + 1, N ' + 2, N ' + 3, N ' + 4) &gt;
&lt; N ' + 9 : Actress | name: (" a" + string (10 * N + 4, 10)) ,</p>
        <p>movies: (N ' + 1, N ' + 2, N ' + 3, N ' + 4) &gt;
freshOid (N ' + 10) .
e-Motions</p>
      </sec>
      <sec id="sec-5-2">
        <title>Maude</title>
      </sec>
      <sec id="sec-5-3">
        <title>Time (s) # Rewrites Time (s) # Rewrites 0.0 0.0</title>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>Maude listings and results for Task 2</title>
      <p>Although very intuitive and simple, the e-Motions solution presented in Section 2 for Task 2, is
computationally very expensive. Notice that the number of matchings in the LHS of the rule is quadratic on the
input size, leaving all the task to the evaluation of the conditions to accept or discard the couples. We
have implemented another solution in which we limit (although we do not reduce the problem
complexity) the number of matchings using a very simple algorithm: For each person, we iterate on the rest of
persons looking for couples. With this algorithm, the number of persons to match as candidate couples
decreases significantly.</p>
      <sec id="sec-6-1">
        <title>As for the Maude-based solution, we have specified both solutions. Both solutions match very closely their e-Motions counterparts. The Maude specification of the first alternative solution to Task 1 is shown in Listing 2. The rules takes two persons and creates a new couple if they share three movies and such couple has not been previously created. Some numbers for its execution are shown in Table 2.</title>
      </sec>
      <sec id="sec-6-2">
        <title>However, while for the Maude-based solution we get better results with the enhanced solution, for the e-Motions one we get even worse time executions. This is due to the high overhead included in e-Motions by each additional rule, since the enhanced solution has more rules that the naive one. 8</title>
      </sec>
      <sec id="sec-6-3">
        <title>Listing 2: createCouples Maude rule.</title>
        <p>crl [ findCouples ] :
{ freshOid (N) findCouples
&lt; O1 : V1:Person | movies : MS1 , Atts1 &gt;
&lt; O2 : V2:Person | movies : MS2 , Atts2 &gt;
Conf }
=&gt;
{ freshOid (s(N )) findCouples
&lt; O1 : V1:Person | movies : MS1 , Atts1 &gt;
&lt; O2 : V2:Person | movies : MS2 , Atts2 &gt;
&lt; N : Couple |
commonMovies : ( intersection (( MS1 ), ( MS2 ))) ,
p1 : O1 , p2 : O2 &gt;</p>
        <p>Conf }
if | intersection (( MS1 ), ( MS2 )) | &gt;= 3
/\ not coupleInConf (C , Conf ) .</p>
      </sec>
    </sec>
    <sec id="sec-7">
      <title>Maude listings and results for Task 3</title>
      <sec id="sec-7-1">
        <title>The Maude rule specifying the solution of this task is shown in Listing 3. The number of rewrites and</title>
        <p>execution times of the e-Motions solution for Task 3 in Section 2 for N = 2; 10 are shown in Table 4.</p>
      </sec>
      <sec id="sec-7-2">
        <title>Listing 3: Maude rule for Task 3 solution.</title>
        <p>=&gt;
}
{ &lt; M : Couple | commonMovies : MovieSet ,
avgRating : sumAllRatings ( MovieSet , C)</p>
        <p>/ float (| MovieSet |) ,</p>
        <p>Atts1 &gt;
couplesCalculated ((M , Couples ))</p>
        <p>C
}
if not (M in Couples ) .</p>
        <p>Table 5 shows the number of rewrites and execution times for the Maude solution for problems of
sizes 100, 200, 300, and 400.</p>
        <p>N Time (s) # Rewrites
2
0.0
2.1</p>
        <p>4,527
891,432</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>M.</given-names>
            <surname>Clavel</surname>
          </string-name>
          , F. Dura´n, S. Eker,
          <string-name>
            <given-names>P.</given-names>
            <surname>Lincoln</surname>
          </string-name>
          ,
          <string-name>
            <surname>N.</surname>
          </string-name>
          <article-title>Mart´ı-</article-title>
          <string-name>
            <surname>Oliet</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <string-name>
            <surname>Meseguer</surname>
          </string-name>
          &amp;
          <string-name>
            <surname>C. Talcott</surname>
          </string-name>
          (
          <year>2007</year>
          )
          <article-title>: All About Maude - A High-Performance Logical Framework LNCS</article-title>
          4350, Springer.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>T.</given-names>
            <surname>Horn</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Krause &amp; M. Ticky: The TTC 2014 Movie Database</surname>
          </string-name>
          <article-title>Case. Available at TTC14 web site</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J.</given-names>
            <surname>Meseguer</surname>
          </string-name>
          (
          <year>1992</year>
          )
          <article-title>: Conditioned Rewriting Logic as a Unifed Model of Concurrency</article-title>
          .
          <source>TCS</source>
          <volume>96</volume>
          (
          <issue>1</issue>
          ):
          <fpage>73</fpage>
          -
          <lpage>155</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>J. E.</given-names>
            <surname>Rivera</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Dura</surname>
          </string-name>
          <article-title>´n &amp; A</article-title>
          .
          <string-name>
            <surname>Vallecillo</surname>
          </string-name>
          (
          <year>2010</year>
          ):
          <article-title>On the Behavioral Semantics of Real-Time Domain Specific Visual Languages</article-title>
          . In: WRLA:
          <fpage>174</fpage>
          -
          <lpage>190</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>J. R.</given-names>
            <surname>Romero</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. E.</given-names>
            <surname>Rivera</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Dura</surname>
          </string-name>
          <article-title>´n &amp; A</article-title>
          .
          <string-name>
            <surname>Vallecillo</surname>
          </string-name>
          (
          <year>2007</year>
          )
          <article-title>: Formal and Tool Support for Model Driven Engineering with Maude</article-title>
          .
          <source>Journal of Object Technology</source>
          <volume>6</volume>
          (
          <issue>9</issue>
          ):
          <fpage>187</fpage>
          -
          <lpage>207</lpage>
          .
          <fpage>1</fpage>
          <volume>2 10 20 100 1000 2000 3000 4000 5000 6000 7000 8000 9000</volume>
          10000 11000 crl [ avgRating ] : { &lt; M : Couple | commonMovies : MovieSet , avgRating :
          <fpage>0</fpage>
          .0 ,
          <issue>Atts1</issue>
          &gt; couplesCalculated ( Couples ) C
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>