1. Homepage
  2. Coding
  3. CISC422/CMPE422: Formal Methods in Software Engineering (Fall 2024) - Assignment 2: Class Modelling with Alloy

CISC422/CMPE422: Formal Methods in Software Engineering (Fall 2024) - Assignment 2: Class Modelling with Alloy

Get in Touch with Our Experts
Queens UniversityCISC422CMPE422Formal Methods in Software EngineeringClass Modelling with AlloyJavaPythonC++Javscript

CISC/CMPE 422: Formal Methods in Software Engineering (Fall 2024)
Assignment Writing Service

Assignment 2: Class Modelling with Alloy Assignment Writing Service

Software
Assignment Writing Service

This assignment uses Alloy, an analysis tool for class models developed by the Software Design Group at MIT. Alloy is publicly available for Windows, Linux and Mac OS and there is extensive documentation for it, including a book, a collection of sample models, and the Stack Assignment Writing Service

README
Overflow forum. You can find pointers to all of this on the Alloy webpage. There also is an online web interface and tutorial. Note that some of this material describes Alloy 6, while we will be using Alloy 5.1.0. The central difference is that Alloy 6 supports mutable signatures and the analysis of traces with respect to temporal operators. Nonetheless, the syntax of the Alloy language is very similar and, overall, the material should still be useful. Alloy 5.1.0 can be downloaded here. Installation and invocation are straightforward: Just store the .jar file somewhere and type java -jar <name>.jar in a terminal window where <name> is the name of the Alloy jar file. Otherwise, Alloy also is installed in CasLab. Assignment Writing Service

Learning Outcomes Assignment Writing Service

The purpose of this assignment is to give you Assignment Writing Service

practical experience with Assignment Writing Service

expressing objects and their relationships formally and declaratively using constraints expressed in first-order logic and a relational calculus, and Assignment Writing Service

reasoning about objects, their relationships and operations on them using constraint solving, and an increased understanding package and repository management. Assignment Writing Service

master Go to file t Go to file Assignment Writing Service

Context Assignment Writing Service

Many software systems (such as programming language or operating systems) support the notion of a package. A package is a piece of software that can be installed into the system to enhance its functionality. Packages may depend on or conflict with other packages. Conflicts may be due to technical (e.g., version incompatibilities) or non-technical (e.g., licence restrictions) reasons. Package managers facilitate installation or deinstallation of packages from some repository. A repository (sometimes also called distribution or registry) is typically a curated, internet-accessible collection of packages. The table below shows the most popular package managers and repositories for the Ubuntu Linux distribution and some common programming languages: Assignment Writing Service

Software system Assignment Writing Service

Ubuntu Python Java JavaScript C++ Assignment Writing Service

Package manager Assignment Writing Service

pip
maven
, gradle npm
vcpkg
Assignment Writing Service

Number of packages Assignment Writing Service

60,000 500,000 14 million 2.1 million 1,500 Assignment Writing Service

The management of repositories is challenging. Reasons include: Assignment Writing Service

The number of packages contained is often very large. Assignment Writing Service

Many packages are updated frequently updates due to bugs, vulnerabilities, and new features. Each such updates can create a different versions, possibly with 'breaking changes', i.e., changes that may require changes to any code that uses the updated package. Assignment Writing Service

Packages can be subject to intricate, complex dependencies, conflicts, incompatibilities or restrictions. Assignment Writing Service

Repo metadata (i.e., relevant information stored in the repository about packages and their relationships) can be incorrect and make parts of the repository inaccessible. E.g., according to [GXY+24] repo info of almost 30% of PyPI releases cannot be retrieved due to invalid metadata. Assignment Writing Service

This assignment is an introduction to the challenges of package management in general and repo management in particular. It uses class modeling in Alloy to explore some of the problems managers of repositories face and to provide answers to questions such as: Is it possible that a repo contains packages that cannot be installed? If so, under what circumstances and how could this be fixed? Is it possible that a repo becomes useless because none of its packages are installable? What exactly does it mean for two packages to be in conflict and what are the properties of this conflict relationship? How can the addition and removal of packages impact conflicts? Assignment Writing Service

For additional information on package and repository management (optional), please see: Assignment Writing Service

[Spi12] Spinellis. Package Management Systems. IEEE Software 29(2):84-86. 2012. https://ieeexplore.ieee.org/document/6155145 [GXY+24] Gao, Xu, Yang, Zhou. PyRadar: Towards Automatically Retrieving and Validating Source Code Repository Information for PyPI Assignment Writing Service

Packages. FSE'24. 2024. https://arxiv.org/abs/2404.16565
[XHG+23] Xu, He, Gao, Zhou. Understanding and Remediating Open-Source License Incompatibilities in the PyPI Ecosystem. ASE'23. 2023. Assignment Writing Service

https://arxiv.org/abs/2308.05942 Assignment Writing Service

[MBD+06] Mancinelli, Boender, Di Cosmo, Vouillon, Durak, Leroy, Treinen. Managing the Complexity of Large Free and Open Source Package-Based Software Distributions. ASE'06. 2006. https://ieeexplore.ieee.org/document/4019575 Assignment Writing Service

[JYZ+23] Jing, Yu, Zhang, Meng, Liu, Xue. Classifying Packages for Building Linux Distributions. COMPSAC'23. 2023. Assignment Writing Service

https://ieeexplore.ieee.org/document/10197038
[LDM20] Legay, Decan, Mens. On Package Freshness in Linux Distributions. ICSME'20. 2020. https://arxiv.org/abs/2007.16123 Assignment Writing Service

Questions File to Edit Assignment Writing Service

Please enter all your answers into the given file alloy/repoMgmnt_starterModel.als in the indicated places. Part I: Structure [64/128 points] Assignment Writing Service

Preparation Assignment Writing Service

We start with the class model below: Assignment Writing Service

pypi.org maven.apache.org npmjs.com vcpkg.io Assignment Writing Service

module RepoMgmnt sig Pkg {}
sig Repo { Assignment Writing Service

pkgs: set Pkg, imp: Pkg -> Pkg, confl: Pkg -> Pkg Assignment Writing Service

// packages contained in the repo
// repo metadata recording which package imports which other packages
// repo metadata recording which package conflicts with which other packages
Assignment Writing Service

}
fact MetaDataValidity { Assignment Writing Service

all r:Repo | all p:Pkg | p !in p.(r.confl) // // no r:Repo | no p:Pkg | p in p.(r.confl)
// all r:Repo | all p:Pkg | p->p !in r.confl
// all r:Repo | all p:Pkg | p !in conflicts[p,r]
Assignment Writing Service

all r:Repo | all p:Pkg | p !in p.(r.imp) // // all r:Repo | all p:Pkg | p !in imports[p,r]
all r:Repo | all p,q:Pkg | q in p.(r.confl) => p in q.(r.confl) // // all r:Repo | all p,q:Pkg | q in conflicts[p,r] => p in conflicts[q,r] // all r:Repo | r.confl = ~(r.confl) Assignment Writing Service

}
fun conflicts[p:Pkg,r:Repo] : set Pkg Assignment Writing Service

p.(r.confl) } Assignment Writing Service

fun imports[p:Pkg,r:Repo] : set Pkg { p.(r.imp) Assignment Writing Service

"no package conflicts with itself" (MDV1) // equivalent to above using De Morgan
// equivalent to above using tuple notation // equivalent to above using helper function "no package imports itself" (MDV2)
Assignment Writing Service

// equivalent to above using helper function "conflicts are symmetric" (MDV3)
// equivalent using helper function
// equivalent to above using relational inverse
Assignment Writing Service

{ //
// "the set of packages that 'p' imports in 'r'"
Assignment Writing Service

}
pred empty[r:Repo] { Assignment Writing Service

no r.pkgs } Assignment Writing Service

pred equal[r1,r2:Repo] { r1.pkgs = r2.pkgs r1.imp = r2.imp r1.confl = r2.confl Assignment Writing Service

} Assignment Writing Service

// "a repo is empty iff it contains no packages"
// "two repos are equal iff they have the same packages and metadata"
Assignment Writing Service

Elements of signatures Pkg and Repo will be called packages and repositories (or just repos), respectively. The model expresses that a repo r has three attributes pkgs , imp , and confl where r.pkgs is a possibly empty set of packages and r.imp and both are binary relations over packages. Given a repo r , r.pkgs represents the set of packages contained in r . I.e., we say that package p is in r if and only if (iff) atomic formula holds. The relations r.imp and represent metadata in r , keeping track of imports and conflicts, respectively. I.e., given two packages p and q , if the pair p->q is contained r.imp (i.e., formula holds or, equivalently, holds), then according to r 's metadata, package p imports package q . Similarly, if the pair p->q is contained Assignment Writing Service

(i.e., or, equivalently, holds), then according to r 's metadata, package p conflicts with package q. Assignment Writing Service

The purpose of the constraints in fact is to impose some 'common sense' restrictions on this metadata, i.e., ensure that this metadata has properties that we would expect it to have. For instance, the first constraint MDV1 prevents packages to conflict with themselves. I.e., given any repo r and any package p , without MDV1 there is nothing in the model that prevents the pair p->p from being an element in Assignment Writing Service

. Similarly, MDV2 says that a package cannot import itself. Finally, MDV3 expresses that the relation is symmetric, i.e., that if a (any) package p conflicts with package q in some (any) repo r , then q also conflicts p in r . Assignment Writing Service

When using 3-place relations such as confl and imp , we must be careful about the order in which relational composition is performed. E.g., represents the set of packages that package p conflicts with in repo r , while (which can be abbreviated to Assignment Writing Service

since the relational composition operator . associates to the left) is not type-correct, because p and r cannot be composed. We can make 3-place relations easier to work with using helper functions. E.g., function returns the set of packages that p conflicts with in r , allowing metadata constraint MDV1 can be re-written as Assignment Writing Service

all r:Repo | all p:Pkg | p !in p.(r.confl)
// all r:Repo | all p:Pkg | p !in conflicts[p,r]
Assignment Writing Service

// "no package conflicts with itself" (MDV1) // equivalent to above Assignment Writing Service

Similarly for MDV2 and helper function
Predicate holds for
r if and only if (iff) r does not contain any packages. Predicate captures what it Assignment Writing Service

means for two repos to be equal. They will be used in Question 2. Assignment Writing Service

One of the challenges with Alloy (and most other languages) is that the same thing can often be expressed in many different ways. The examples of equivalent versions given for constraints MDV1 , MDV2 and MDV3 illustrate that. For this assignment, as long as your formalization correctly captures the semantics of the property or constraint to be formalized you should be getting full marks, i.e., as long as your formalization is semantically equivalent to the formalization that we expect, the way the formalization is expressed does not matter. Assignment Writing Service

Note that some of these constraints can also be captured in a UML class diagram.
Finding satisfying instances (scenarios): We can explore the instances satisfying (the constraints in) a model using Alloy's run command: Assignment Writing Service

run P1a {} for 3 // satisfiable
run P1b {#Pkg=2 && some r1,r2:Repo | equal[r1,r2]} for 3 // satisfiable
run P1c {some r:Repo | some p,q:Pkg | q in conflicts[p,r] && !(p in conflicts[q,r])} for 3 // not satisfiable run P1d {#Repo>=4} for 3 // not satisfiable
run P1e {some r:Repo | r.pkgs = Pkg} for 3 // satisfiable Assignment Writing Service

"the set of packages that 'p' conflicts with in 'r Assignment Writing Service

MetaDataValidity Assignment Writing Service

imports[p:Pkg,r:Repo]:set Pkg Assignment Writing Service

#Pkg=2 && some r1,r2:Repo | equal[r1,r2] Assignment Writing Service

check P1f {all r:Repo | no p:Pkg | p in imports[p,r]} for 3 check P1g {all r:Repo | some r.pkgs} for 3
check P1h {Repo.pkgs in Pkg} for 3
check P1i {all r:Repo | r.pkgs = Pkg} for 2 but exactly 1 Repo Assignment Writing Service

// holds
// does not hold // holds
// does not hold
Assignment Writing Service

r:Repo | no p:Pkg | p in imports[p,r] Assignment Writing Service

Command P1a asks the analyzer to find instances that satisfy the constraints in the model in scope 3 (i.e., instances can contain at most 3 elements of each signature). Command P1b does the same, except that it additionally requires satisfying instances to also satisfy the constraint Assignment Writing Service

, i.e., contain exactly 2 packages and two repos that are equal. Command P1c fails to find any instances because the additional constraint that is the argument of the command contradicts MDV3 . Similarly for command P1d , where the Assignment Writing Service

scope constraint of 3 prevents the generation of instances with 4 or more signature elements. Command P1e asks for instances that satisfy all the constraints in the model, and also contain at least one repo r such that r contains all packages. Assignment Writing Service

Inspecting the generated instances for P1a , P1b , and P1e , we can see that the model above is currently does not fully capture all expected metadata constraints, i.e., the import and conflict relationships don't exhibit all the expected properties. For instance, the import and conflict metadata for some repo can actually refer to packages that are not contained in that repo. We will return to this observation later in Question Assignment Writing Service

Q1c .
Checking assertions: We can check if all instances satisfying the constraints in the model have some property P by using the Assignment Writing Service

command. Consider the following examples: Assignment Writing Service

Command P1f checks if the constraints in the model are strong enough to cause every satisfying instance to also satisfy the formula
(which captures the statement that
"for all repos, there is no package that imports itself in that repo"). Assignment Writing Service

Command P1g checks if all satisfying instances of the model contain at least one package. Command P1h checks if in all satisfying instances, the packages contained in all repos are all elements of the Pkg signature. Command P1i checks if in all satisfying instances, all repos contain all available packages. The first check ( P1f ) succeeds, i.e., Alloy does not find a counter example for the assertion in the given scope, suggesting that the constraints in the model indeed imply the assertion. The second check ( P1g ) fails, because the constraints in the model do not force every repo to contain at least one package. Assignment Writing Service

The fourth check ( P1i ) fails, because there are satisfying instances in which at least one repo does not contain all packages. One such instance is shown here together with the evaluator window showing what different expressions evaluate to in this instance. While the default visualization (which shows all attributes as arcs) is fine for small instances and simple models, it quickly becomes hard to read for large models and models attributes ranging over binary relations (such as imp and confl ). To mitigate that, the customization of the visualization is highly recommended. Please go here for more information. Assignment Writing Service

Question 1: Metadata validity [15 points] Assignment Writing Service

For each of the following two properties, complete the corresponding run commands to generate scenarios that satisfy the properties. Use the Alloy analyzer to enumerate the first few scenarios and check that they look as expected. Assignment Writing Service

Q1a [3 pts]: "There exist a repo that is empty, a repo that is non-empty and conflict-free, and a repo that is non-empty and not conflict- free". Assignment Writing Service

Q1b [3 pts]: "There exists a repo that contains 3 packages and at least one of them imports every other package in the repo".
Using provided predicates
empty and equal , complete assertion Q1c so that it captures the meaning of the statement below. Use the Assignment Writing Service

Alloy analyzer to see if the assertion holds.
Q1c [3 pts]: Empty repos are equal, i.e., "For all repos r1 and r2 , if r1 and r2 are both empty, then they are equal". Assignment Writing Service

The reason assertion Q1c fails is that the metadata for imports and conflicts can, as already observed above, mention packages that are not actually contained in the repository. For each of the following statements below, formalize them in Alloy and add them to the fact Assignment Writing Service

MetaDataValidity .
Q1d [3 pts]: "For all repos r , the import metadata r.imp does not mention any packages that are not contained in r ", i.e., "For all Assignment Writing Service

repos r , and all packages p and q , whenever p imports q in r , then both p and q are contained in r ".
Q1e [3 pts]: "For all repos r , the conflict metadata does not mention any packages that are not contained in r ", i.e., "For all Assignment Writing Service

repos r , and all packages p and q , whenever p conflicts with q in r , then both p and q are contained in r ".
These additional metadata validity constraints rule out the counter examples that made assertion
Q1c fail. Rerun the assertion check Q1c Assignment Writing Service

(for increasing scopes till 6) and convince yourself that the assertion now holds. Assignment Writing Service

Question 2: Subrepos [12 points] Assignment Writing Service

Given two repositories r1 and r2 , we say that r2 is a sub-repository of r1 if and only if (iff) Assignment Writing Service

i. the packages contained in r2 are also contained in r1 ,
ii. package
p1 imports p2 in r2 iff ( p1 imports p2 in r1 and p1 and p2 are contained in r2 ), and Assignment Writing Service

iii. package p1 conflicts with p2 in r2 iff ( p1 conflicts with p2 in r1 and p1 and p2 are contained in r2 ).
Q2a [3 pts]: Complete the predicate such that it holds precisely when r2 is a sub-repository of r1 as defined above. Use the run command Q2a to generate some instances and convince yourself that they look as expected. Assignment Writing Service

For each of the following statements, complete the corresponding assertion such that it captures the meaning of the statement. Assignment Writing Service

Q2b [3 pts]: "A (i.e., any) repo is empty iff all its subrepos are empty".
Q2c [3 pts]: "For any two repos r1 and r2 , if r1 is a subrepo of r2 and r2 is subrepo of r1 , then r1 and r2 are equal". This Assignment Writing Service

property is usually called anti-symmetry.
Q2d [3 pts]: "For any three repos r1 , r2 , and r3 , if r1 is a subrepo of r2 and r2 is subrepo of r3 , then r1 is also a subrepo of Assignment Writing Service

r3 ". This property is usually called transitivity.
Use the Alloy analyzer to check that all three assertions above hold (in increasing scopes up to 6).
Assignment Writing Service

Question 3: Installability and co-installability [31 points] Assignment Writing Service

The metadata information for a repo is not quite complete. We also need the notion of dependency. Given two packages p1 and p2 , we say that p1 depends on p2 iff Assignment Writing Service

i. p1 imports p2 , or
ii.
p1 imports some package that imports p2 , or Assignment Writing Service

iii. p1 imports some package that imports some package that imports p2 , or iv. ... Assignment Writing Service

I.e., there is a non-empty, finite sequence of imports relationships (i.e., edges) from p1 to p2 . Q3a [3 pts]: Remove the comment at the beginning of the line: Assignment Writing Service

Then, add a constraint to the fact in the indicated place such that for all repos r , the binary relation r.dep captures the notion of dependency defined above. I.e., given two packages p1 and p2 , p2 in p1.(r.dep) should hold iff in the Assignment Writing Service

sense above and both are contained in r . Use the run command (with, e.g., your constraint on dep works as expected. Assignment Writing Service

Given a package p and a repo r , we say that p is (individually) installable from r iff Assignment Writing Service

i. p is contained in r ,
ii. none of the packages that
p depends on (according to r 's metadata) conflict with p , and Assignment Writing Service

iii. none of the packages that p depends on (according to r 's metadata) conflict with each other. Assignment Writing Service

) to convince yourself that Assignment Writing Service

Q3b [4 pts]: Complete the predicate installable[p:Pkg,r:Repo] such that it holds precisely when p is installable from r as defined above. Use the run command to generate some relevant instances and convince yourself that your formalization of installability works as expected. Assignment Writing Service

For each of the following statements, complete the corresponding assertion with a formula that captures the meaning of the statement. Assignment Writing Service

Q3c [3 pts]: "For all repos r , if r has an uninstallable package, then r has conflicts (i.e., r is not conflict-free)". Q3d [3 pts]: "For all repos r , if r has conflicts, then there exists at least one package that is not installable from r ". Assignment Writing Service

Q3e [2 pts]: Use the Alloy analyzer to determine which of the two assertions above hold and which do not. Check the assertions in increasing scopes up to 8. Hint: Exactly one of the two assertions should hold. Assignment Writing Service

Given a set of packages P and a repo r , we say that P is co-installable (or jointly installable) from r iff Assignment Writing Service

i. all packages in P are contained in r ,
ii. none of the packages in
P conflict with each other, Assignment Writing Service

iii. none of the packages that some package in P depends on do not conflict with a package in P , and iv. none of the packages that any of the packages in P depend on conflict with each other. Assignment Writing Service

Q3f [4 pts]: Complete the predicate such that it holds precisely when P is co-installable from r as defined above. If you want, you can add a helper function to make working with the relation dep easier (just like we did for confl and imp above). Use the run command to generate some relevant instances and convince yourself that your formalization of co-installability works as expected. Assignment Writing Service

For each of the following statements, complete the corresponding assertion with a formula that captures the meaning of the statement. Assignment Writing Service

Q3g [3 pts]: "For all repos r , if all packages contained in r are (individually) installable from r , then the set of packages contained in r is co-installable from r ". Assignment Writing Service

Q3h [3 pts]: "For all repos r , if the set of packages contained in r are co-installable from r , then each of the packages in r is individually installable from r ".
Q3i [3 pts]: "For all repos r , the set of packages contained in r is co-installable from r iff r is conflict-free". Assignment Writing Service

// dep: Pkg -> Pkg // uncomment for Question 3 Assignment Writing Service

MetaDataValidity Assignment Writing Service

p1 depends on p2 Assignment Writing Service

run {some r:Repo | some r.dep} Assignment Writing Service

coInstallable[P:set Pkg,r:Repo] Assignment Writing Service

dependsOn[p:Pkg,r:Repo]:set Pkg Assignment Writing Service

Q3j [3 pts]: Use the Alloy analyzer to determine which of the three assertions above hold and which do not. Check the assertions in increasing scopes up to 8. Hint: Exactly two of the three assertions should hold. Assignment Writing Service

Question 4: Trimness [6 points] Assignment Writing Service

Q4a [3 pts]: We say that a repo r is trim iff the set of packages it contains is co-installable from r . Complete the predicate such that it holds precisely when r is trim as defined above. Intuitively, a trim repo is maximally useful, because any subset of its packages is installable.
Q4b [3 pts]: Complete the assertion Q4b with a formula that captures the meaning of the following statement: "All subrepos of a trim repository are also trim". Use the Alloy analyzer to check that the assertion holds in scopes up to 8. Assignment Writing Service

Part II: Operations [39/128 points] Question 5: Trimifying a repo [11 points] Assignment Writing Service

As we have seen, the non-trimness of some repo is due to conflicting dependencies. In the worst case, most or all of the packages in the repo cannot be accessed. This can be due to the dependencies and conflicts that packages really have, or it could be due to erroneous metadata (as observed in [GXY+24]). We now consider an operation that, intuitively, will produce a trim repo ( r2 ) from a possibly non-trim one ( r1 ) by removing packages. To maximize the utility of the resulting repo, trimify should minimize the number of packages removed. Assignment Writing Service

Q5a [3 pts]: Complete the predicate such that for all repos r1 and r2 trimify[r1,r2] holds iff a. r2 is a subrepo of r1 , Assignment Writing Service

b. r2 is trim, and
c.
r2 is the largest trim subrepo of r1 , i.e., there is no trim subrepo of r1 that contains more packages than r2 . Assignment Writing Service

Use the run command with different argument constraints (e.g., some r1,r2:Repo | !trim[r1] && trimify[r1,r2] ) to convince yourself that works correctly. Assignment Writing Service

What kind of operation is ? Which properties do we expect it to have, apart from the three properties above that make up its definition? Below, we will consider two properties: idempotency and uniqueness. For each of the two statements below, complete the corresponding assertion such that it captures the meaning of that statement. Assignment Writing Service

Q5b [3 pts]: Idempotency: Trimifying a trim repo leaves that repo unchanged, i.e., "for all repos r1 and r2 , if r1 is trim and r2 is the result of trimifying r1 , then r1 and r2 are equal". Assignment Writing Service

Q5c [3 pts]: Uniqueness: The result of trimify is uniquely determined, i.e., "for all repos r1 , r2 , and r3 , if r2 and r3 are both the result of trimifying r1 , then r2 and r3 are equal". Assignment Writing Service

Q5d [2 pts]: Use the Alloy analyzer to determine which of the two assertions above hold and which do not. Check the assertions in increasing scopes up to 8. Hint: Exactly one of the two assertions should hold. Assignment Writing Service

Question 6: Removing a package [13 points] Assignment Writing Service

The next operation we consider is the removal of a package from a repo. We want this removal to be sensitive to existing dependencies and metadata validity constraints. Assignment Writing Service

Q6a [4 pts]: Complete the predicate remPkg[r1:Repo,p:Pkg,r2:Repo] such that for all repos r1 and r2 and packages p , remPkg[r1,p,r2] holds iff Assignment Writing Service

i. p is contained in r1 ,
ii. no package in
r1 imports p , Assignment Writing Service

iii. r2 contains exactly all packages that r1 contains minus p ,
iv. the import metadata of
r2 coincides with that of r1 except that all imports involving p have been removed, and Assignment Writing Service

v. the conflict metadata of r2 coincides with that of r1 except that all conflicts involving p have been removed.
Use the
run command with different argument constraints (e.g., ) to convince yourself Assignment Writing Service

that remPkg works correctly.
Which emerging properties does
remPkg have? We will consider three. For each of the two statements below, complete the corresponding Assignment Writing Service

assertion such that it captures the meaning of that statement.
Q6b[3 pts]: Removal creates a subrepo, i.e., "for all repos r1 and r2 and packages p , if r2 is the result of removing p from r1 , Assignment Writing Service

then r2 is a subrepo of r1 ".
Q6c [3 pts]: Removal preserves trimness, i.e., "for all repos r1 and r2 and packages p , if r1 is trim and r2 is the result of removing Assignment Writing Service

p from r1 , then r2 is trim".
Q6d [3 pts]: "If removing a package makes a repo trim, then the repo has conflicts and all of these conflicts involve the package", i.e., for Assignment Writing Service

all repos r1 and r2 and packages p , if r1 is not trim and r2 is the result of removing p from r1 and r2 is trim, then r1 is not conflict-free and all its conflicts involve p . Assignment Writing Service

trimify[r1,r2:Repo] Assignment Writing Service

trimfy[r1,r2:Repo] Assignment Writing Service

some r1,r2:Repo | some p:Pkg | remPkg[r1,p,r2] Assignment Writing Service

some p:Pkg | trim[r1] && addPkg[r1,p,r2] && !trim[r2]) Assignment Writing Service

some r1,r2:Repo | Assignment Writing Service

Q6e [0 pts]: Use the Alloy analyzer to determine which of the three assertions above hold and which do not. Check the assertions in increasing scopes up to 8. Hint: All assertions should hold. Assignment Writing Service

Question 7: Adding a package [15 points] Assignment Writing Service

The next operation we consider is the addition of a package to a repo. If we use standard, implementation-level thinking, we would expect this add operation to carry 5 arguments: the repo r1 to which the package is to be added, the package p to be added, a list of packages in r1 that p imports, a list of packages in r1 that p conflicts with, and the resulting repo r2 . However, we will omit the third and fourth arguments, that is, our operation will only have three arguments: addPkg[r1:Repo,p:Pkg,r2:Repo] . How can this work? Which imports and conflicts will p have in r2 ? The point is that the result of the addition does not need to be uniquely determined, i.e., for specific r1 and p , there can be several result repos r2 such that holds. In other words, we will leave the addition underspecified and as a consequence, the addition turns into a non-deterministic operation that can have different results. If Assignment Writing Service

holds, we know that r2 contains p but we don't know if p has any imports or conflicts in r2 , and, if so, what exactly they are. Why do this? Because it is enough for our purposes and a predicate with 3 arguments is easier to work with than one with 5 arguments. Assignment Writing Service

Q7a [3 pts]: Complete the predicate holds iff Assignment Writing Service

a. p is not contained in r1 , b. p is contained in r2 , and Assignment Writing Service

such that for all repos r1 and r2 and packages p , Assignment Writing Service

c. the removal of p from r2 results in r1 .
Use the
run command with different argument constraints (e.g., some r1,r2:Repo | some p:Pkg | addPkg[r1,p,r2] or Assignment Writing Service

) to convince yourself that addPkg works correctly.
Which emerging properties does
addPkg have? We will consider three. For each of the three statements below, complete the Assignment Writing Service

corresponding assertion such that it captures the meaning of that statement. Assignment Writing Service

Q7b[3 pts]: Add and remove are inverses: Requirement 3 in Q7a means that addPkg and remPkg should be inverses of each other, i.e., "for all repos r1 and r2 and packages p , r2 is the result of adding p to r1 iff r1 is the result of removing p from r2 ". Assignment Writing Service

Q7c [3 pts]: Unique results, i.e., "for all repos r1 , r2 , and r3 and packages p , if r2 is the result of adding p to r1 and r3 is the result of adding p to r1 , then r2 and r3 are equal". Assignment Writing Service

Q7d [3 pts]: "Addition preserves conflicts", i.e., "for all repos r1 and r2 and packages p , if r2 is the result of adding p to r1 , then all conflicts in r1 also are conflicts in r2 and all conflicts in r2 not contained in r1 involve p ". Assignment Writing Service

Q7e [3 pts]: Use the Alloy analyzer to determine which of the three assertions above hold and which do not. Check the assertions in increasing scopes up to 8. Hint: Exactly two of the three assertions should hold. Assignment Writing Service

Part III: Executions [25/128 points] Assignment Writing Service

We will now explore how sequences of operations can be formalized in Alloy and how this formalization can be used to execute these sequences, check properties of executions, and generate test inputs. Assignment Writing Service

Preparation: Remove the comment at the beginning of line
// open util/ordering[Repo] // uncomment for Question 8 Assignment Writing Service

to impose the constraints of the module on elements of signature Repo , i.e., repositories. In every scenario found by Alloy, these constraints force the elements of Repo in the scenario to be linearly (totally) ordered. That is, for any two repos in the scenario, they will either be the same, or one will come before the other in the ordering. Also, a repo is either the last (first) in the ordering, or it has exactly one successor (predecessor). The elements of Repo in a scenario (if any) will be called Repo0 , Repo1 , Repo2 , ... (or, Repo$0 , Assignment Writing Service

Repo$1 , ... in Alloy's evaluator) with Repo0 always being the first element in the ordering and Repo1 being its successor. Also, the ordering module contains several useful functions (e.g., first , last , and next ) and predicates ( lt , lte , gt , and gte ). E.g., function first (from module ) will evaluate to the first element in the scenario (i.e., Repo0 ), if any. In contrast, function last denotes Assignment Writing Service

the last element, if any. next is the successor relation. E.g., assuming a scenario in which Repo0 and Repo1 exist, the expression Repo0.next will evaluate to Repo1 and (and ) will evaluate to Repo0 . Given a scenario, use the evaluator to Assignment Writing Service

experiment with these functions and predicates, and see models/util/ordering.als (from Alloy's .jar file, but included in the directory alloy/ of this assignment's repository for convenient reference) for more information. Assignment Writing Service

Question 8: Generating executions [16 points] Assignment Writing Service

To model executions, we need to express that, in all instances, the successor of a repo r is the result of applying remPkg or addPkg on r (we will not use in this part). To achieve this, we will use predicate . Assignment Writing Service

Q8a [3 pts]: Complete the predicate such that it holds iff for all repos r1 , unless r1 is last in the ordering, there exists a package p such that the successor of r1 in the ordering is the result of either removing p from r1 or adding p to r1 . Use the run command with different argument constraints (e.g., or ) to generate different executions and convince yourself that they look as expected. Assignment Writing Service

addPkg[r1,p,r2] Assignment Writing Service

addPkg[r1,p,r2] Assignment Writing Service

addPkg[r1,p,r2] Assignment Writing Service

addPkg[r1:Repo,p:Pkg,r2:Repo] Assignment Writing Service

legalExec[] empty[first] && legalExec[] Assignment Writing Service

Assignment Writing Service

Q8b [3 pts]: Complete the predicate such that it holds iff repo r contains at least one package that depends on n different packages. Use the run command with different argument constraints to generate different repos that satisfy and convince yourself that they look as expected. Assignment Writing Service

For each of the three statements below, complete the corresponding run command such that it generates executions described in the statement. Assignment Writing Service

Q8c [3 pts]: "There is a legal execution along which addition and removal alternate".
Q8d [3 pts]: "There is a legal execution along there exists exactly one package that is added but never removed". Q8e [3 pts]: "There is a legal execution along which there is a package that is removed at least 3 times". Assignment Writing Service

Use these run commands to convince yourself that they work as expected.
Q8f [1 pts]: What is the smallest scope in which your version of finds an instance? I.e., what is the smallest scope in which Assignment Writing Service

there is an instance that satisfies all constraints of the model and the additional constraint Q8e ? Question 9: Checking properties of executions [9 points] Assignment Writing Service

We now can check properties of executions. For each of the statements below, complete the corresponding assertion with a formula that captures that statement. Assignment Writing Service

Q9a [3 pts]: "Along all legal executions starting from an empty repo, a (i.e., any) repo is either empty or it contains at least one individually installable package". Assignment Writing Service

Q9b [3 pts]: "Along all legal executions, whenever a (i.e., any) package is removed twice, it has been added in between".
Q9c [3 pts]: "Every legal execution starting from an empty repo is such that the size of the last repo is the number of additions in the Assignment Writing Service

execution minus the number of removals". Use the built-in function minus[m,n:Int]:Int .
Q9d [0 pts]: Use the Alloy analyzer to determine which of the three assertions above hold and which do not. Check the assertions in Assignment Writing Service

increasing scopes up to 8. Hint: All assertions should hold. Assignment Writing Service

Part IV: Discussion [0 points] Assignment Writing Service

We see how constraint solving (with Alloy) can be used to describe relationships between objects and the possible impact of operations on them. Note how this requires a description of the relevant properties of the operations, rather than a description of their implementation. I.e., the executions were described declaratively, rather than operationally. Finding executions (i.e., executing) was achieved through constraint (satisfiability) solving. Note that descriptions of executions need not specify the initial state or which operation was applied when. As result, our formalization of executions can be used to, e.g., Assignment Writing Service

1. find test inputs that cause executions with certain properties (e.g., "find initial repos such that the use of exactly three removals results in a trim repo"), Assignment Writing Service

2. check properties (assertions) that all executions are expected to have, and 3. find counter examples, i.e., executions that cause some property to fail. Assignment Writing Service

Some test generation tools use declarative modeling and constraint solving. Assignment Writing Service

联系辅导老师!
私密保护
WeChat 微信
Queens University代写,CISC422代写,CMPE422代写,Formal Methods in Software Engineering代写,Class Modelling with Alloy代写,Java代写,Python代写,C++代写,Javscript代写,Queens University代编,CISC422代编,CMPE422代编,Formal Methods in Software Engineering代编,Class Modelling with Alloy代编,Java代编,Python代编,C++代编,Javscript代编,Queens University代考,CISC422代考,CMPE422代考,Formal Methods in Software Engineering代考,Class Modelling with Alloy代考,Java代考,Python代考,C++代考,Javscript代考,Queens University代做,CISC422代做,CMPE422代做,Formal Methods in Software Engineering代做,Class Modelling with Alloy代做,Java代做,Python代做,C++代做,Javscript代做,Queens Universityhelp,CISC422help,CMPE422help,Formal Methods in Software Engineeringhelp,Class Modelling with Alloyhelp,Javahelp,Pythonhelp,C++help,Javscripthelp,Queens University作业代写,CISC422作业代写,CMPE422作业代写,Formal Methods in Software Engineering作业代写,Class Modelling with Alloy作业代写,Java作业代写,Python作业代写,C++作业代写,Javscript作业代写,Queens University编程代写,CISC422编程代写,CMPE422编程代写,Formal Methods in Software Engineering编程代写,Class Modelling with Alloy编程代写,Java编程代写,Python编程代写,C++编程代写,Javscript编程代写,Queens University作业答案,CISC422作业答案,CMPE422作业答案,Formal Methods in Software Engineering作业答案,Class Modelling with Alloy作业答案,Java作业答案,Python作业答案,C++作业答案,Javscript作业答案,