<!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>Solving the Class Responsibility Assignment Case with UML-RSDS</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>K. Lano, S. Yassipour-Tehrani, S. Kolahdouz-Rahimi Dept. of Informatics, King's College London</institution>
          ,
          <addr-line>Strand, London</addr-line>
          ,
          <country country="UK">UK;</country>
          <institution>Dept. of Software Engineering, University of Isfahan</institution>
          ,
          <addr-line>Isfahan</addr-line>
          ,
          <country country="IR">Iran</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>This paper provides a solution to the class responsibility assignment case using UML-RSDS. We show how search-based software engineering techniques can be combined with traditional MT techniques to handle large search spaces. This case study [1] is an endogenous transformation which aims to optimally assign attributes and methods to classes to improve a measure, class-responsibility assignment (CRA-index), of class diagram quality. We provide a specification of the transformation in the UML-RSDS language [3, 4] using search-based software engineering techniques (SBSE) [2]. UML-RSDS is a model-based development language and toolset, which specifies systems in a platformindependent manner, and provides automated code generation from these specifications to executable implementations (in Java, C# and C++). Tools for analysis and verification are also provided. Specifications are expressed using the UML 2 standard language: class diagrams define data, use cases define the top-level services or functions of the system, and operations can be used to define detailed functionality. Expressions, constraints, pre and postconditions and invariants all use the standard OCL 2.4 notation of UML 2. For model transformations, the class diagram expresses the metamodels of the source and target models, and auxiliary data and functionalities can also be defined. Use cases define the transformations and their subtransformations: each use case has a set of pre and postconditions which define its intended functionality. The postconditions act as transformation rules. A use case can include others, and may have an activity to define its detailed behaviour.</p>
      </abstract>
      <kwd-group>
        <kwd>Class responsibility assignment</kwd>
        <kwd>Search-based software engineering</kwd>
        <kwd>UML-RSDS</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Copyright ⃝c by the paper's authors. Copying permitted for private and academic purposes.</p>
      <p>In: A. Garcia-Dominguez, F. Krikava and L. Rose (eds.): Proceedings of the 9th Transformation Tool Contest, Vienna, Austria,
08-07-2016</p>
      <p>The first part of the solution is an endogenous transformation (Figure 2) which (i) identifies the building
blocks and places these in separate classes: the createClasses transformation in Figure 2; (ii) refactors the class
model to reduce coupling: the refactor transformation; (iii) removes empty classes: the cleanup transformation.
Finally, the measures transformation displays the CRA-index and other measures of the intermediate solution.
These transformations are co-ordinated by the preprocess transformation. The metamodel is produced from the
Ecore metamodel provided.</p>
      <p>The rules (postconditions) for createClasses include creation of a default class, which contains all the methods
that are not linked to any other feature (their sets of functional and data dependencies are empty):</p>
      <sec id="sec-1-1">
        <title>UMLMethod:: dataDependency.size = 0 &amp; functionalDependency.size = 0 =&gt; UMLClass-&gt;exists( c | c.name = "Class0" &amp; self : c.encapsulates )</title>
        <p>and a rule to place a method (self ) into any class c which contains all of the attributes it depends on:</p>
      </sec>
      <sec id="sec-1-2">
        <title>UMLMethod:: dataDependency.size &gt; 0 &amp; c : UMLClass &amp; dataDependency &lt;: c.encapsulates@pre =&gt; self : c.encapsulates</title>
        <p>&lt;: denotes the subset relation. Other rules create classes for each ‘chunk’ of a method plus the attributes which
are exclusively or primarily depended on by that method.</p>
        <p>The refactor transformation moves methods m and attributes a from one class self to an alternative class c,
if there are more dependencies linking the feature to c than to self . Eg., for methods we have:</p>
      </sec>
      <sec id="sec-1-3">
        <title>UMLClass::</title>
        <p>m : encapsulates@pre &amp; m-&gt;oclIsKindOf(UMLMethod) &amp; c : UMLClass &amp;
depends = m.dataDependency-&gt;union(m.functionalDependency) &amp;
depends-&gt;intersection(c.encapsulates@pre)-&gt;size() &gt;</p>
        <p>depends-&gt;intersection(encapsulates@pre)-&gt;size() =&gt; m : c.encapsulates
Although this transformation may decrease the CRA-index, it generally reduces coupling.</p>
        <p>Finally, cleanup deletes empty classes:
UMLClass::
encapsulates.size = 0</p>
        <p>=&gt; self-&gt;isDeleted()</p>
        <p>The preprocess transformation co-ordinates the other transformations. It has no rules of its own, but it has an
activity to control the subordinate transformations, which preprocess accesses via ≪ include ≫ dependencies:
while Feature-&gt;exists(isEncapsulatedBy.size = 0)
do execute ( createClasses() ) ;
while UMLClass-&gt;exists( c | c.name /= "Class0" &amp; c.encapsulates.size = 1 )
do execute ( refactor() ) ;
execute ( cleanup() ) ;
execute ( measures() )
createClasses is iterated until all features are encapsulated in some class, then refactor is iterated until all normal
classes have at least 2 features.
3</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Genetic algorithm</title>
      <p>A general GA specification is provided in the UML-RSDS libraries (Figure 3). This can be reused and adapted for
specific problems, by providing a problem-specific definition of the tness function, the content of GATrait items
and values, and the functions determining which individuals survive, reproduce or mutate from one generation
to the next. Math is an external class providing access to the Java random() method.</p>
      <sec id="sec-2-1">
        <title>GeneticAlgorithm:: p : population &amp; GeneticAlgorithm.isElite(p) =&gt; p : elite</title>
      </sec>
      <sec id="sec-2-2">
        <title>GeneticAlgorithm::</title>
        <p>p : elite &amp; q : population &amp;
q.fitnessval &lt; p.fitnessval &amp; GeneticAlgorithm.isCombinable(p,q) =&gt;
p.combine(q) : recombined</p>
      </sec>
      <sec id="sec-2-3">
        <title>GeneticAlgorithm:: p : population &amp; GeneticAlgorithm.isMutatable(p) =&gt; p.mutate() : mutated</title>
      </sec>
      <sec id="sec-2-4">
        <title>Use Case, name: nextgeneration</title>
      </sec>
      <sec id="sec-2-5">
        <title>GeneticAlgorithm:: true =&gt; population = elite@pre-&gt;union(recombined@pre)-&gt;union(mutated@pre)</title>
      </sec>
      <sec id="sec-2-6">
        <title>GeneticAlgorithm:: true =&gt; elite = Set{} &amp; recombined = Set{} &amp; mutated = Set{}</title>
      </sec>
      <sec id="sec-2-7">
        <title>GeneticAlgorithm:: p : population =&gt; p.fitnessval = p.fitness()</title>
      </sec>
      <sec id="sec-2-8">
        <title>GeneticAlgorithm:: population.size &gt; 0 =&gt; GeneticAlgorithm.maxfitness = population-&gt;collect(fitnessval)-&gt;max()</title>
        <p>evolve deletes unfit individuals (eg., those with fitness below the median fitness level), preserves the best
individuals (those in the best 20%), and mutates and recombines individuals that meet the necessary criteria.
Mutation consists of incrementing or decrementing the value of a randomly selected trait. Crossover takes place
at a randomly-selected trait position. nextgeneration assembles the next population, and recalculates fitness for
all individuals, and identifies the top fitness value.</p>
        <p>To model the CRA problem in a GA, individuals represent possible assignments of features to classes, and
have traits t for each feature f in the model, and item is the name of the feature. The trait value is the index
number of the class to which the feature is assigned, ie.:</p>
        <p>
          t:value = UMLClass:allInstances→indexOf (f :isEncapsulatedBy:any)
The fitness value is the CRA-index, computed using the definitions of [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ]. This approach means that each
individual has a trait for every feature in the model, and this makes processing very slow for substantial models.
For larger instances of the CRA problem, a more compact representation of models as individuals would be
necessary, for example, by grouping features into chunks and defining one trait per chunk.
        </p>
        <p>
          The functions mmi and mai of [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ] are defined as follows:
ClassModel::
query static mmi(ci : UMLClass, cj : UMLClass) : int
pre: true
post:
result = ci.encapsulates-&gt;select( mi |
mi : UMLMethod )-&gt;collect( m |
        </p>
        <p>cj.encapsulates-&gt;intersection(m.functionalDependency)-&gt;size() )-&gt;sum()
ClassModel::
query static mai(ci : UMLClass, cj : UMLClass) : int
pre: true
post:
result = ci.encapsulates-&gt;select( mi |
mi : UMLMethod )-&gt;collect( m |</p>
        <p>cj.encapsulates-&gt;intersection(m.dataDependency)-&gt;size() )-&gt;sum()
Likewise, the coupling and cohesion ratios can be defined in OCL.</p>
        <p>The ga(iter : int ) use case performs initialise to initialise the population with 50 copies of the model produced
by preprocess, and 100 random individuals, then it iterates evolve and nextgeneration for iter times.</p>
        <p>In a final phase, an optimal individual gmax produced by the genetic algorithm is mapped to a class model
by the postprocess use case:</p>
      </sec>
      <sec id="sec-2-9">
        <title>GeneticAlgorithm::</title>
        <p>population.size &gt; 0 &amp; gmax = population-&gt;selectMaximals(fitnessval)-&gt;any() =&gt;
gmax.traits-&gt;forAll( t |</p>
      </sec>
      <sec id="sec-2-10">
        <title>UMLClass.allInstances-&gt;at(t.value) : Feature[t.item].isEncapsulatedBy )</title>
        <p>E [str ] is the instance of entity type E with primary key value str . Following this, cleanup may be needed to
remove any empty classes.
4</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Results</title>
      <p>CRA after
GA
3
2.75
0.6175
0.744
-8.1</p>
      <p>All solution artifacts are available at www.dcs.kcl.ac.uk/staff/kcl/umlcra. The specification is in the file
mm.txt, and the use cases and operations are listed in crausecases.txt and craoperations.txt. Solution models
are in cresult.xmi, dresult.xmi, etc.</p>
    </sec>
    <sec id="sec-4">
      <title>Conclusions References</title>
      <p>We have shown that a general-purpose genetic algorithm can be used in combination with MT to obtain good
results for the CRA problem. General recombination and mutation strategies are used, for example, mutation
simply moves one feature from one class to another. Improved results could probably be produced if specialised
operators were used, eg., moving a method would also require moving the attributes that it exclusively depends
upon. A significant aspect of our approach is that we have specified the GA and MT system components in the
same formalism (UML and OCL), rather than using hetrogeneous technologies.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>M.</given-names>
            <surname>Fleck</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Troya</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Wimmer</surname>
          </string-name>
          ,
          <source>The Class Responsibility Assignment Case</source>
          ,
          <string-name>
            <surname>TTC</surname>
          </string-name>
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>M.</given-names>
            <surname>Harman</surname>
          </string-name>
          ,
          <article-title>Search-based software engineering</article-title>
          ,
          <source>ICCS</source>
          <year>2006</year>
          , LNCS vol.
          <volume>3994</volume>
          , Springer-Verlag, pp.
          <volume>740</volume>
          {
          <issue>747</issue>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>K.</given-names>
            <surname>Lano</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Kolahdouz-Rahimi</surname>
          </string-name>
          ,
          <article-title>Constraint-based speci cation of model transformations</article-title>
          ,
          <source>Journal of Systems and Software</source>
          , vol.
          <volume>88</volume>
          , no.
          <issue>2</issue>
          ,
          <year>February 2013</year>
          , pp.
          <volume>412</volume>
          {
          <fpage>436</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <article-title>[4] The UML-RSDS toolset and manual</article-title>
          , http://www.dcs.kcl.ac.uk/staff/kcl/uml2web/umlrsds.pdf,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>