<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://prob.hhu.de/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Joy+Clark</id>
	<title>ProB Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://prob.hhu.de/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Joy+Clark"/>
	<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Special:Contributions/Joy_Clark"/>
	<updated>2026-05-27T08:11:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2877</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2877"/>
		<updated>2015-05-05T08:20:08Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
This page was updated in May of 2015 to reflect changes made to the ProB 2.0 API.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;trace = animations.getCurrentTrace()&amp;lt;/code&amp;gt; into the Groovy console. This accesses the current animation and saves it in the &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = trace.getStateSpace()&amp;lt;/code&amp;gt; to save a reference to the state space that is associated with &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored. Information about the state space is stored in State objects which can be queried to inspect information about any given state. These State objects are cached and can be accessed via their string identifier. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStateSpace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can I access the current state from an animation?&#039;&#039;&#039;&lt;br /&gt;
 state = trace.getCurrentState()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Does the state that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 state.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 state.eval(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = state.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of this list?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions().first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these Transition objects&#039;&#039;&#039;&lt;br /&gt;
 trans = state.getOutTransitions()[1] &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the transition?&#039;&#039;&#039; &lt;br /&gt;
 n = trans.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 params = trans.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(trans.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;state.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state, and the detail information from the Transition object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,state,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   state.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForGivenStates(t.getTransitionList().collect { it.getSource()},[f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForGivenStates takes a list of states and a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2876</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2876"/>
		<updated>2015-05-05T08:18:47Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Evaluation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;trace = animations.getCurrentTrace()&amp;lt;/code&amp;gt; into the Groovy console. This accesses the current animation and saves it in the &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = trace.getStateSpace()&amp;lt;/code&amp;gt; to save a reference to the state space that is associated with &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored. Information about the state space is stored in State objects which can be queried to inspect information about any given state. These State objects are cached and can be accessed via their string identifier. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStateSpace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can I access the current state from an animation?&#039;&#039;&#039;&lt;br /&gt;
 state = trace.getCurrentState()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Does the state that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 state.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 state.eval(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = state.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of this list?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions().first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these Transition objects&#039;&#039;&#039;&lt;br /&gt;
 trans = state.getOutTransitions()[1] &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the transition?&#039;&#039;&#039; &lt;br /&gt;
 n = trans.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 params = trans.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(trans.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;state.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state, and the detail information from the Transition object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,state,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   state.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForGivenStates(t.getTransitionList().collect { it.getSource()},[f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForGivenStates takes a list of states and a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2875</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2875"/>
		<updated>2015-05-05T08:14:12Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Traces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;trace = animations.getCurrentTrace()&amp;lt;/code&amp;gt; into the Groovy console. This accesses the current animation and saves it in the &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = trace.getStateSpace()&amp;lt;/code&amp;gt; to save a reference to the state space that is associated with &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored. Information about the state space is stored in State objects which can be queried to inspect information about any given state. These State objects are cached and can be accessed via their string identifier. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStateSpace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can I access the current state from an animation?&#039;&#039;&#039;&lt;br /&gt;
 state = trace.getCurrentState()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Does the state that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 state.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 state.eval(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = state.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of this list?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions().first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these Transition objects&#039;&#039;&#039;&lt;br /&gt;
 trans = state.getOutTransitions()[1] &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the transition?&#039;&#039;&#039; &lt;br /&gt;
 n = trans.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 params = trans.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(trans.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;state.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state, and the detail information from the Transition object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,state,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   state.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForEveryState([f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForEveryState takes a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. To evaluate a list of formulas for a subset, there is another method  evaluateForGivenStates. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2874</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2874"/>
		<updated>2015-05-05T08:13:16Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* The State Space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;trace = animations.getCurrentTrace()&amp;lt;/code&amp;gt; into the Groovy console. This accesses the current animation and saves it in the &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = trace.getStateSpace()&amp;lt;/code&amp;gt; to save a reference to the state space that is associated with &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored. Information about the state space is stored in State objects which can be queried to inspect information about any given state. These State objects are cached and can be accessed via their string identifier. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStateSpace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can I access the current state from an animation?&#039;&#039;&#039;&lt;br /&gt;
 state = trace.getCurrentState()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Does the state that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 state.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 state.eval(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = state.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of this list?&#039;&#039;&#039; &lt;br /&gt;
 state.getOutTransitions().first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these Transition objects&#039;&#039;&#039;&lt;br /&gt;
 trans = state.getOutTransitions()[1] &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the transition?&#039;&#039;&#039; &lt;br /&gt;
 n = trans.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 params = trans.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(trans.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;state.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state, and the detail information from the Transition object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,state,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   state.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first().getId()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForEveryState([f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForEveryState takes a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. To evaluate a list of formulas for a subset, there is another method  evaluateForGivenStates. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2873</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2873"/>
		<updated>2015-05-05T08:01:24Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Preparation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;trace = animations.getCurrentTrace()&amp;lt;/code&amp;gt; into the Groovy console. This accesses the current animation and saves it in the &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = trace.getStateSpace()&amp;lt;/code&amp;gt; to save a reference to the state space that is associated with &amp;lt;code&amp;gt;trace&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored. Information about the state space is stored in State objects which can be queried to inspect information about any given state. These State objects are cached and can be accessed via their string identifier. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStateSpace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantKo() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states where the invariant holds?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of object is the result? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of objects are contained in the set? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().first().getClass() &lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Let&#039;s explore StateIds.&#039;&#039;&#039; &lt;br /&gt;
 x = s.getInvariantOk().first() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 x.value(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = x.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of the hashset?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x).first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these OpInfo objects&#039;&#039;&#039;&lt;br /&gt;
 o = (s.getOutEdges(x) as List)[1] &lt;br /&gt;
&lt;br /&gt;
Groovy allows us to transform a Set into a list using the Groovy [http://silvanolte.com/blog/2011/03/11/the-groovy-as-keyword/ as] keyword.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the operation?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(o.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;x.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state space, and the detail information from the OpInfo object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,x,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   x.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first().getId()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForEveryState([f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForEveryState takes a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. To evaluate a list of formulas for a subset, there is another method  evaluateForGivenStates. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2872</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2872"/>
		<updated>2015-05-05T07:59:52Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* The State Space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = animations.getCurrentTrace() as StateSpace&amp;lt;/code&amp;gt; into the Groovy console. &amp;lt;code&amp;gt;animations.getCurrentTrace()&amp;lt;/code&amp;gt; accesses the current animation and &amp;lt;code&amp;gt;as StateSpace&amp;lt;/code&amp;gt; accesses the current state space associated with the current animation.&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored. Information about the state space is stored in State objects which can be queried to inspect information about any given state. These State objects are cached and can be accessed via their string identifier. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStateSpace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantKo() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states where the invariant holds?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of object is the result? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of objects are contained in the set? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().first().getClass() &lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Let&#039;s explore StateIds.&#039;&#039;&#039; &lt;br /&gt;
 x = s.getInvariantOk().first() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 x.value(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = x.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of the hashset?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x).first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these OpInfo objects&#039;&#039;&#039;&lt;br /&gt;
 o = (s.getOutEdges(x) as List)[1] &lt;br /&gt;
&lt;br /&gt;
Groovy allows us to transform a Set into a list using the Groovy [http://silvanolte.com/blog/2011/03/11/the-groovy-as-keyword/ as] keyword.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the operation?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(o.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;x.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state space, and the detail information from the OpInfo object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,x,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   x.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first().getId()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForEveryState([f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForEveryState takes a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. To evaluate a list of formulas for a subset, there is another method  evaluateForGivenStates. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2871</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=2871"/>
		<updated>2015-05-05T07:48:54Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Preparation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade &amp;quot;latest&amp;quot;&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = animations.getCurrentTrace() as StateSpace&amp;lt;/code&amp;gt; into the Groovy console. &amp;lt;code&amp;gt;animations.getCurrentTrace()&amp;lt;/code&amp;gt; accesses the current animation and &amp;lt;code&amp;gt;as StateSpace&amp;lt;/code&amp;gt; accesses the current state space associated with the current animation.&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
== The State Space ==&lt;br /&gt;
The state space represents the whole currently known world for an animation. It is lazily explored, i.e., the knowledge always increases. The class is based on a Graph from the [http://jung.sourceforge.net/ JUNG] framework. However, we hide methods that can remove information from the graph. The StateSpace class also provides notification mechanism to inform clients about important changes, such as the exploration of new states. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStatespace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantKo() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states where the invariant holds?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of object is the result? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of objects are contained in the set? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().first().getClass() &lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Let&#039;s explore StateIds.&#039;&#039;&#039; &lt;br /&gt;
 x = s.getInvariantOk().first() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 x.value(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = x.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of the hashset?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x).first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these OpInfo objects&#039;&#039;&#039;&lt;br /&gt;
 o = (s.getOutEdges(x) as List)[1] &lt;br /&gt;
&lt;br /&gt;
Groovy allows us to transform a Set into a list using the Groovy [http://silvanolte.com/blog/2011/03/11/the-groovy-as-keyword/ as] keyword.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the operation?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(o.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;x.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state space, and the detail information from the OpInfo object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,x,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   x.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run new File(&amp;quot;myAwesomeScript.groovy&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Traces ==&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first().getId()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   def nt = t; &lt;br /&gt;
   n.times {  nt = nt.anyEvent() }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
== Evaluation ==&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForEveryState([f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForEveryState takes a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. To evaluate a list of formulas for a subset, there is another method  evaluateForGivenStates. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I want to have it extra sweet! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
== Constraint solver ==&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getValue()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getValue()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
&lt;br /&gt;
== Notification and UI Access ==&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2426</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2426"/>
		<updated>2014-11-05T15:08:58Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to run a groovy script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
localhost:PORTNR/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
You can also load Event B models into the API via the eventb_load command in the Api object. The eventb_load command accepts .bcm and .bcc files.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to specify it with the name of the event to be executed and predicates to specify how the parameters for the event are to be allocated. Specifying no predicate will assume a predicate of &amp;quot;TRUE=TRUE&amp;quot; for the given event.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.execute(&amp;quot;new&amp;quot;,&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If executing the event in a groovy environment (console or script), the event will be recognized as a method on the Trace class. This means that you can execute the event &amp;quot;new&amp;quot; as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you know the id that has been allocated by the ProB kernel to a given transition, this can be added via the &amp;quot;add&amp;quot; method. This will search the outgoing transitions from the current state and attempts to find one with a matching id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
If you know the name and parameters combination for a specific transition, you can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.addTransitionWith(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.evalCurrent(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.evalCurrent(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
The Trace class can also attempt to identify the correct parser for the formula in question. This means that for an EventBModel the EventB parser will be used, and for a ClassicalBModel, the ClassicalB parser will be used. In this case, calling the evalCurrent method with a String parameter will parse the String formula with the parser associated with the current formalism being animated. In this case&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
will identify which model type is being animated and choose the appropriate parser.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace from the root state is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run new File(pathToScript/script.groovy) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2425</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2425"/>
		<updated>2014-11-05T15:08:28Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to convert between the main abstractions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
localhost:PORTNR/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
You can also load Event B models into the API via the eventb_load command in the Api object. The eventb_load command accepts .bcm and .bcc files.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to specify it with the name of the event to be executed and predicates to specify how the parameters for the event are to be allocated. Specifying no predicate will assume a predicate of &amp;quot;TRUE=TRUE&amp;quot; for the given event.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.execute(&amp;quot;new&amp;quot;,&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If executing the event in a groovy environment (console or script), the event will be recognized as a method on the Trace class. This means that you can execute the event &amp;quot;new&amp;quot; as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you know the id that has been allocated by the ProB kernel to a given transition, this can be added via the &amp;quot;add&amp;quot; method. This will search the outgoing transitions from the current state and attempts to find one with a matching id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
If you know the name and parameters combination for a specific transition, you can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.addTransitionWith(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.evalCurrent(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.evalCurrent(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
The Trace class can also attempt to identify the correct parser for the formula in question. This means that for an EventBModel the EventB parser will be used, and for a ClassicalBModel, the ClassicalB parser will be used. In this case, calling the evalCurrent method with a String parameter will parse the String formula with the parser associated with the current formalism being animated. In this case&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
will identify which model type is being animated and choose the appropriate parser.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace from the root state is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2424</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2424"/>
		<updated>2014-11-05T15:08:03Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to carry out evaluations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
localhost:PORTNR/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
You can also load Event B models into the API via the eventb_load command in the Api object. The eventb_load command accepts .bcm and .bcc files.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to specify it with the name of the event to be executed and predicates to specify how the parameters for the event are to be allocated. Specifying no predicate will assume a predicate of &amp;quot;TRUE=TRUE&amp;quot; for the given event.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.execute(&amp;quot;new&amp;quot;,&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If executing the event in a groovy environment (console or script), the event will be recognized as a method on the Trace class. This means that you can execute the event &amp;quot;new&amp;quot; as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you know the id that has been allocated by the ProB kernel to a given transition, this can be added via the &amp;quot;add&amp;quot; method. This will search the outgoing transitions from the current state and attempts to find one with a matching id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
If you know the name and parameters combination for a specific transition, you can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.addTransitionWith(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.evalCurrent(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.evalCurrent(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
The Trace class can also attempt to identify the correct parser for the formula in question. This means that for an EventBModel the EventB parser will be used, and for a ClassicalBModel, the ClassicalB parser will be used. In this case, calling the evalCurrent method with a String parameter will parse the String formula with the parser associated with the current formalism being animated. In this case&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
will identify which model type is being animated and choose the appropriate parser.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2423</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2423"/>
		<updated>2014-11-05T15:04:08Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* In The Console */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
localhost:PORTNR/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
You can also load Event B models into the API via the eventb_load command in the Api object. The eventb_load command accepts .bcm and .bcc files.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to specify it with the name of the event to be executed and predicates to specify how the parameters for the event are to be allocated. Specifying no predicate will assume a predicate of &amp;quot;TRUE=TRUE&amp;quot; for the given event.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.execute(&amp;quot;new&amp;quot;,&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If executing the event in a groovy environment (console or script), the event will be recognized as a method on the Trace class. This means that you can execute the event &amp;quot;new&amp;quot; as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you know the id that has been allocated by the ProB kernel to a given transition, this can be added via the &amp;quot;add&amp;quot; method. This will search the outgoing transitions from the current state and attempts to find one with a matching id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
If you know the name and parameters combination for a specific transition, you can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.addTransitionWith(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2422</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2422"/>
		<updated>2014-11-05T14:56:37Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Event B */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
localhost:PORTNR/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
You can also load Event B models into the API via the eventb_load command in the Api object. The eventb_load command accepts .bcm and .bcc files.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2421</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2421"/>
		<updated>2014-11-05T14:55:30Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Open the ProB API from Source/JAR file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
localhost:PORTNR/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2420</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=2420"/>
		<updated>2014-11-05T14:54:23Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to open the Groovy Shell */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Open the ProB API from Source/JAR file ==&lt;br /&gt;
&lt;br /&gt;
In order to access the console from source or from a JAR file, start the application with the parameters -s (short for --shell) and -local (which specifies that you are running the application from a local computer). This will start a web server at a given port (the default is 8080, but it increments the port number if a port is already active). The shell can then be accessed at the following address:&lt;br /&gt;
&lt;br /&gt;
http://localhost:8080/sessions/GroovyConsoleSession&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console using the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2419</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2419"/>
		<updated>2014-11-05T14:47:58Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* StateSpace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The original ProB plug-in for Rodin introduced one basic abstraction: developers can create Java commands specifying calculations that are to be made by the ProB CLI binary. The result that is calculated by ProB can then be interpreted and manipulated by the developer. Each Java command corresponds to one prolog instruction in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
We have maintained the abstractions of the commands in order to communicate with the ProB kernel. However, as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms. We have also implemented a Model abstraction for CSP-M specifications, but it is currently not possible to access any static information about the model. TLA+ specifications can be represented in the API as Classical B models.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace. For performance reasons, not all states in the state space are saved indefinitely. The states in the StateSpace are saved as State objects, which then hold the information about the outgoing transitions and formulas of interest that have been evaluated for the given state. In the StateSpace, these objects are cached in an LRU cache so that if not accessed for a given period of time, the garbage collector can clean them up.&lt;br /&gt;
&lt;br /&gt;
== Trace ==&lt;br /&gt;
&lt;br /&gt;
For some tools, the StateSpace abstraction may be sufficient. But when it comes to animation and the concept of a &amp;quot;current state&amp;quot;, a further abstraction becomes necessary. The Trace provides this abstraction.&lt;br /&gt;
&lt;br /&gt;
A Trace consists of a linked list of states which correspond to a path through the StateSpace. There is also a pointer in the list which identifies the current state. The Trace behaves like a browser history; it is possible to move forward and backward within the current trace.&lt;br /&gt;
&lt;br /&gt;
A Trace corresponds to exactly one trace within the animation. Each Trace is associated with exactly one StateSpace, but we can have many different Trace objects on top of a single StateSpace.&lt;br /&gt;
&lt;br /&gt;
The Trace is immutable. This means that whenever an animation step is performed (forward, backward, or simply adding a transition to the trace) a new Trace is returned.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2418</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2418"/>
		<updated>2014-11-05T14:40:15Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The original ProB plug-in for Rodin introduced one basic abstraction: developers can create Java commands specifying calculations that are to be made by the ProB CLI binary. The result that is calculated by ProB can then be interpreted and manipulated by the developer. Each Java command corresponds to one prolog instruction in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
We have maintained the abstractions of the commands in order to communicate with the ProB kernel. However, as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms. We have also implemented a Model abstraction for CSP-M specifications, but it is currently not possible to access any static information about the model. TLA+ specifications can be represented in the API as Classical B models.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
It is actually implemented as a graph (using the JGraphT library), so there are built in graph functions and support for graphical representations. In the graph, the vertices are states and the edges are events (including solutions and choices for local variables and non-deterministic assignments).&lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace that has not yet been explored, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace.&lt;br /&gt;
&lt;br /&gt;
The StateSpace object is actually mutable, but it is always growing. No data ever gets replaced by any new data.&lt;br /&gt;
&lt;br /&gt;
== Trace ==&lt;br /&gt;
&lt;br /&gt;
For some tools, the StateSpace abstraction may be sufficient. But when it comes to animation and the concept of a &amp;quot;current state&amp;quot;, a further abstraction becomes necessary. The Trace provides this abstraction.&lt;br /&gt;
&lt;br /&gt;
A Trace consists of a linked list of states which correspond to a path through the StateSpace. There is also a pointer in the list which identifies the current state. The Trace behaves like a browser history; it is possible to move forward and backward within the current trace.&lt;br /&gt;
&lt;br /&gt;
A Trace corresponds to exactly one trace within the animation. Each Trace is associated with exactly one StateSpace, but we can have many different Trace objects on top of a single StateSpace.&lt;br /&gt;
&lt;br /&gt;
The Trace is immutable. This means that whenever an animation step is performed (forward, backward, or simply adding a transition to the trace) a new Trace is returned.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2417</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2417"/>
		<updated>2014-11-05T14:38:21Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The original ProB plug-in for Rodin introduced one basic abstraction: developers can create Java commands specifying calculations that are to be made by the ProB CLI binary. The result that is calculated by ProB can then be interpreted and manipulated by the developer. Each Java command corresponds to one prolog instruction in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
We have maintained the abstractions of the commands in order to communicate with the ProB kernel. However, as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
It is actually implemented as a graph (using the JGraphT library), so there are built in graph functions and support for graphical representations. In the graph, the vertices are states and the edges are events (including solutions and choices for local variables and non-deterministic assignments).&lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace that has not yet been explored, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace.&lt;br /&gt;
&lt;br /&gt;
The StateSpace object is actually mutable, but it is always growing. No data ever gets replaced by any new data.&lt;br /&gt;
&lt;br /&gt;
== Trace ==&lt;br /&gt;
&lt;br /&gt;
For some tools, the StateSpace abstraction may be sufficient. But when it comes to animation and the concept of a &amp;quot;current state&amp;quot;, a further abstraction becomes necessary. The Trace provides this abstraction.&lt;br /&gt;
&lt;br /&gt;
A Trace consists of a linked list of states which correspond to a path through the StateSpace. There is also a pointer in the list which identifies the current state. The Trace behaves like a browser history; it is possible to move forward and backward within the current trace.&lt;br /&gt;
&lt;br /&gt;
A Trace corresponds to exactly one trace within the animation. Each Trace is associated with exactly one StateSpace, but we can have many different Trace objects on top of a single StateSpace.&lt;br /&gt;
&lt;br /&gt;
The Trace is immutable. This means that whenever an animation step is performed (forward, backward, or simply adding a transition to the trace) a new Trace is returned.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2416</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=2416"/>
		<updated>2014-11-05T14:34:09Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The original ProB plug-in for Rodin introduced one basic abstraction: developers can create Java commands specifying calculations that are to be made by the ProB CLI binary. The result that is calculated by ProB can then be interpreted and manipulated by the developer. Each Java command corresponds to one prolog instruction in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
It is actually implemented as a graph (using the JGraphT library), so there are built in graph functions and support for graphical representations. In the graph, the vertices are states and the edges are events (including solutions and choices for local variables and non-deterministic assignments).&lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace that has not yet been explored, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace.&lt;br /&gt;
&lt;br /&gt;
The StateSpace object is actually mutable, but it is always growing. No data ever gets replaced by any new data.&lt;br /&gt;
&lt;br /&gt;
== Trace ==&lt;br /&gt;
&lt;br /&gt;
For some tools, the StateSpace abstraction may be sufficient. But when it comes to animation and the concept of a &amp;quot;current state&amp;quot;, a further abstraction becomes necessary. The Trace provides this abstraction.&lt;br /&gt;
&lt;br /&gt;
A Trace consists of a linked list of states which correspond to a path through the StateSpace. There is also a pointer in the list which identifies the current state. The Trace behaves like a browser history; it is possible to move forward and backward within the current trace.&lt;br /&gt;
&lt;br /&gt;
A Trace corresponds to exactly one trace within the animation. Each Trace is associated with exactly one StateSpace, but we can have many different Trace objects on top of a single StateSpace.&lt;br /&gt;
&lt;br /&gt;
The Trace is immutable. This means that whenever an animation step is performed (forward, backward, or simply adding a transition to the trace) a new Trace is returned.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=2415</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=2415"/>
		<updated>2014-11-05T14:31:35Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Basic Design Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:ProB Java API]]&lt;br /&gt;
[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of our main design goals was that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
The basic programmatic abstractions that are available in the ProB 2.0 API are the Model, Trace, and StateSpace abstractions. The Model provides all the static information about the model that is currently being checked or animated. The StateSpace provides the corresponding label transition system for the Model. The Trace represents exactly one trace throughout the StateSpace. A more detailed description of the different is available [[Programmatic Abstractions in the ProB 2.0 API|here]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
A tutorial for the current features of ProB 2.0 is available [[ProB 2.0 Tutorial|here]].&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=1981</id>
		<title>Rodin User and Developer Workshop 2013 - Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Rodin_User_and_Developer_Workshop_2013_-_Tutorial&amp;diff=1981"/>
		<updated>2013-06-26T20:55:33Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* The model */  specify line as code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are the information we have shown you at the tutorial. If you want to follow this tutorial on your computer you will have to install ProB 2.0 and start an animation. For this tutorial we use a [[media:Scheduler_tutorial2013.zip|simple scheduler example]]. Maybe you have to clean the project after importing.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You will need a fresh copy of ProB 2.0 installed to your Rodin or the sourcecode.&lt;br /&gt;
&lt;br /&gt;
The update site for our builds is: http://nightly.cobra.cs.uni-duesseldorf.de/experimental/updatesite/&lt;br /&gt;
&lt;br /&gt;
The sourcecode repository and a description how to setup your Eclipse: https://github.com/bendisposto/prob2&lt;br /&gt;
&lt;br /&gt;
Please note that no matter which installation method you chose, you need to fetch the latest Prolog binaries. The easiest way is to type &#039;&#039;&#039;&amp;lt;code&amp;gt;upgrade latest&amp;lt;/code&amp;gt;&#039;&#039;&#039; into the ProB 2.0 Groovy console.&lt;br /&gt;
&lt;br /&gt;
In the following we will intermix some explanations with FAQ style code snippets. We assume that you execute all the code snippets. Some of the snippets rely on the previous execution of other snippets.&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# Import the Scheduler project.&lt;br /&gt;
# Start an animation for Scheduler0&lt;br /&gt;
# Perform some random animation steps&lt;br /&gt;
# Type &amp;lt;code&amp;gt;s = space_0&amp;lt;/code&amp;gt; into the Groovy console. space_0 has been created automatically when you loaded the scheduler. Subsequent loading wil result in space_1, space_2, etc.&lt;br /&gt;
&lt;br /&gt;
== The model ==&lt;br /&gt;
A model gives you access to the static properties of a Rodin development. Such as contexts, machines, constants, variables, invariants, events, etc. A model is a graph of components and their relationship. Except for Graph handling there are no shared methods between formalisms. The main difference between EventBModel and ClassicalBModel are the artifacts and relationships they can contain. An EventB Model consists of Machines and Contexts and the only relationships are refinement and sees.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we get the model for a given state space?&#039;&#039;&#039;&lt;br /&gt;
 m = s.getModel()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the Java type of m?&#039;&#039;&#039;&lt;br /&gt;
 m.getClass()&lt;br /&gt;
&lt;br /&gt;
An EventB model consists of machines and contexts. Machines allow to access variables, invariants, variants and events. Contexts give you access to axioms, constants and sets. Let&#039;s explore machines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we get access to the Scheduler0 machine?&#039;&#039;&#039;&lt;br /&gt;
 mch = m.getComponent(&amp;quot;Scheduler0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the invariants of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getInvariants()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the events of Scheduler0?&#039;&#039;&#039;&lt;br /&gt;
 mch.getEvents()&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we access the event named new?&#039;&#039;&#039;&lt;br /&gt;
 ne = mch.getEvent(&amp;quot;new&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the guard of new?&#039;&#039;&#039;&lt;br /&gt;
 ne.getGuards() &lt;br /&gt;
&lt;br /&gt;
The stae space represents the whole currently known world for an animation. It is lazily explored, i.e., the knowledge always increases. The class is based on a Graph from the [http://jung.sourceforge.net/ JUNG] framework. However, we hide methods that can remove information from the graph. The StateSpace class also provides notification mechanism to inform clients about important changes, such as the exploration of new states. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we retrieve the state space for a given model?&#039;&#039;&#039; &lt;br /&gt;
 s = m.getStatespace() &lt;br /&gt;
&lt;br /&gt;
In Rodin, you should try to explore the state until your trace contains the &amp;lt;code&amp;gt;massakr&amp;lt;/code&amp;gt; event. This event breaks the invariant of the system. Otherwise the next command will return an empty set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states that violate the invariant?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantKo() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are there some states where the invariant holds?&#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of object is the result? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What kind of objects are contained in the set? &#039;&#039;&#039;&lt;br /&gt;
 s.getInvariantOk().first().getClass() &lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Let&#039;s explore StateIds.&#039;&#039;&#039; &lt;br /&gt;
 x = s.getInvariantOk().first() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we get the value of a variable in that state?&#039;&#039;&#039; &lt;br /&gt;
 x.value(&amp;quot;active&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we randomly &amp;quot;execute&amp;quot; events?&#039;&#039;&#039; &lt;br /&gt;
 y = x.anyEvent() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we &amp;quot;execute&amp;quot; a specific event?&#039;&#039;&#039; &lt;br /&gt;
Yes we can! We will figure out how it is done in a moment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we find out which events are enabled?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the elements of the hashset?&#039;&#039;&#039; &lt;br /&gt;
 s.getOutEdges(x).first().getClass() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Now let&#039;s get one of these OpInfo objects&#039;&#039;&#039;&lt;br /&gt;
 o = (s.getOutEdges(x) as List)[1] &lt;br /&gt;
&lt;br /&gt;
Groovy allows us to transform a Set into a list using the Groovy [http://silvanolte.com/blog/2011/03/11/the-groovy-as-keyword/ as] keyword.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the name of the operation?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getName() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the actual parameters?&#039;&#039;&#039; &lt;br /&gt;
 n = o.getParams() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the formal parameter name?&#039;&#039;&#039; &lt;br /&gt;
 e = mch.getEvent(o.getName()) &lt;br /&gt;
&lt;br /&gt;
Finally we can &amp;quot;execute&amp;quot; the Event using the perform method of the StateId object. At this point you need to chose an event that you want to execute. It has to be enabled in the state, but you can provide additional guards to restrict the parameters. For instance if the event del is enabled and we want to delete process P2 the command is&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;x.perform(&amp;quot;del&amp;quot;,[&amp;quot;r=P2&amp;quot;])&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We try not to intertwine different aspects of the system. That is why we had to get the formal parameter from the model&#039;s representation, the enabled operations from the state space, and the detail information from the OpInfo object. This design principle was taken from Rich Hickey&#039;s [http://www.infoq.com/presentations/Simple-Made-Easy Simple made easy] talk. &lt;br /&gt;
&lt;br /&gt;
However, this doesn&#039;t prevent us (or you!) from adding convenience functions! &lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;How do I execute an event?&#039;&#039;&#039;&lt;br /&gt;
 def exec(mch,x,name,params) {&lt;br /&gt;
   formal_params = mch.getEvent(name).getParameters()&lt;br /&gt;
   pred = [formal_params,params].transpose()&lt;br /&gt;
    .collect { a,b -&amp;gt; a.toString() + &amp;quot;=&amp;quot; + b.toString() }&lt;br /&gt;
   x.perform(name,pred)&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
You can write your own set of convenience functions in a groovy file and run it at the beginning.&lt;br /&gt;
 run ~/myAwesomeScript.groovy    &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we track a trace of events?&#039;&#039;&#039; &lt;br /&gt;
 t = new Trace(s) &lt;br /&gt;
&lt;br /&gt;
A trace represents a path through the state space. It can move forward and backward through the Trace and can be extended with a new transition. Traces are immutable, yet creating new traces is efficient because of structural sharing.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the current state of the trace?&#039;&#039;&#039; &lt;br /&gt;
 t.getCurrentState() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What are the enabled events in the current state?&#039;&#039;&#039; &lt;br /&gt;
 t.getNextTransitions() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we &amp;quot;execute&amp;quot; an event?&#039;&#039;&#039; &lt;br /&gt;
 t = t.add(t.getNextTransitions().first().getId()) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we produce a random trace?&#039;&#039;&#039; &lt;br /&gt;
 def randTrace(t,n) { &lt;br /&gt;
   nt = t; &lt;br /&gt;
   for(int i=0; i &amp;lt; n; i++) {&lt;br /&gt;
      nt = nt.anyEvent(); &lt;br /&gt;
   }&lt;br /&gt;
   nt&lt;br /&gt;
 }  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Let&#039;s run it!&#039;&#039;&#039; &lt;br /&gt;
 randTrace(t,20) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can go back in time? &#039;&#039;&#039;&lt;br /&gt;
 t = t.back() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we go forward in time?&#039;&#039;&#039; &lt;br /&gt;
 t = t.forward() &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we go back in time, the trace keeps future states. If we change a decision in the past, the trace drops the future. It behaves in the same way your browser history does.&lt;br /&gt;
&lt;br /&gt;
Evaluation is done by passing an instance of the interface IEvalElement to an evaluator. Each formalism has its own descendant of IEvalElement. They apply a parser to a String&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we create an EventB formula?&#039;&#039;&#039; &lt;br /&gt;
 f1 = &amp;quot;active \\/ waiting&amp;quot; as EventB &lt;br /&gt;
&lt;br /&gt;
The escaping of the backslash is unfortunatly required because the formula is contained in a Java String. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And how do we create a classical B formula?&#039;&#039;&#039; &lt;br /&gt;
 f2 = &amp;quot;active \\/ waiting&amp;quot; as ClassicalB &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How can we evaluate the formulas for state x?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1) &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What have we received?&#039;&#039;&#039; &lt;br /&gt;
 x.eval(f1).getClass() &lt;br /&gt;
&lt;br /&gt;
ProB&#039;s Prolog engine does not make a difference between EventB and classical B. Only the parsers are different. Event B Formulas are parsed by Rodin. Classical B formulas are parsed by ProB&#039;s parser.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ok, we can evaluate a formula for a state. Anything else that evaluates formulas?&#039;&#039;&#039; &lt;br /&gt;
 t.eval(f1) &lt;br /&gt;
&lt;br /&gt;
Traces evaluate a formula for each state of the trace. They return a list of results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Anything else?&#039;&#039;&#039; &lt;br /&gt;
 s.evaluateForEveryState([f1, &amp;quot;waiting&amp;quot; as EventB]) &lt;br /&gt;
&lt;br /&gt;
evaluateForEveryState takes a list of formulas and evaluates them for each state of the statespace. This method is not called eval to prevent accidental evaluation. To evaluate a list of formulas for a subset, there is another method  evaluateForGivenStates. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we evaluate the guard of an event for a whole trace?&#039;&#039;&#039; &lt;br /&gt;
 g = mch.getEvent(&amp;quot;del&amp;quot;).getGuards()&lt;br /&gt;
 g = g.collect {it.toString()}.join(&amp;quot; &amp;amp; &amp;quot;)&lt;br /&gt;
 t.eval(g) &lt;br /&gt;
&lt;br /&gt;
I want to have it extra sweet! &lt;br /&gt;
 String.metaClass.and = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate+&amp;quot;) &amp;amp; (&amp;quot;+b + &amp;quot;)&amp;quot; }&lt;br /&gt;
 not = { &amp;quot;not(&amp;quot;+it+&amp;quot;)&amp;quot; }&lt;br /&gt;
 String.metaClass.implies = {b -&amp;gt; &amp;quot;(&amp;quot;+delegate +&amp;quot;) =&amp;gt; (&amp;quot; + b + &amp;quot;) &amp;quot;}&lt;br /&gt;
 conj = { it.collect{it.toString()}.inject {a,b -&amp;gt; a &amp;amp; b}}  &lt;br /&gt;
&lt;br /&gt;
This piece of code introduces four functions to simplify handling of formulas. &lt;br /&gt;
The first line overrides the &amp;amp; operator for Strings and allows us to conjoin two predicates as Strings, e.g., &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;4&amp;quot; &amp;amp; &amp;quot;x&amp;gt;y&amp;quot;&amp;lt;/code&amp;gt; evaluates to &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;4) &amp;amp; (x&amp;gt;y)&amp;quot;&amp;lt;/code&amp;gt;. The second line implements a function not that wraps a predicate into a negation. The third line adds an implies method to the class String. &amp;lt;code&amp;gt;&amp;quot;1&amp;lt;2&amp;quot;.implies(&amp;quot;3&amp;lt;4&amp;quot;)&amp;lt;/code&amp;gt; results in &amp;lt;code&amp;gt;&amp;quot;(1&amp;lt;2) =&amp;gt; (3&amp;lt;4)&amp;quot;&amp;lt;/code&amp;gt;. The last line converts a list of predicates into a conjunction. In Groovy collect means map and inject means reduce.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Evaluation is fine, but can I use ProB&#039;s solver?&#039;&#039;&#039; &lt;br /&gt;
 f4 = new EventB(&amp;quot;a = 1 &amp;amp; b = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getResult()&lt;br /&gt;
 &lt;br /&gt;
The state space in the example has two purposes. It is used to tell the typechecker  which constants and sets exist in the model. It also allows us to send commands to the Prolog core of ProB. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What do we get if the predicate is not solvable? &#039;&#039;&#039;&lt;br /&gt;
 f4 = new ClassicalB(&amp;quot;a = a - 1&amp;quot;)&lt;br /&gt;
 c4 = new CbcSolveCommand(f4)&lt;br /&gt;
 s.execute(c4)&lt;br /&gt;
 c4.getResult()&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;Can we get rid of that Java stuff please?&#039;&#039;&#039; &lt;br /&gt;
 def cbc_solve(space, formula) {&lt;br /&gt;
   e = new EventB(formula)&lt;br /&gt;
   c = new CbcSolveCommand(e)&lt;br /&gt;
   space.execute(c)&lt;br /&gt;
   c.getResult()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can we find out if one event can in principle be enabled, i.e., it is not dead code?&#039;&#039;&#039; &lt;br /&gt;
 i = conj(mch.getInvariants())&lt;br /&gt;
 g = conj(mch.getEvent(&amp;quot;del&amp;quot;).getGuards())&lt;br /&gt;
 cbc_solve(s, i &amp;amp; i.implies(g))&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Clients can register themself to receive a notification if an animation step occured, new states were discovered or the model has changed. The client has to implement one of the Listener interfaces from the de.prob.statespace package.&lt;br /&gt;
        &lt;br /&gt;
ProB 2.0 was built on top of the same commands as ProB 1.0. Most of the commands are usable with only minor changes. ProB 2.0 can be extended in the same way as ProB 1.0. &lt;br /&gt;
&lt;br /&gt;
To access the user interface, ProB 2.0 injects two special objects into the console, &amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;animations&amp;lt;/code&amp;gt; is an Instance of &amp;lt;code&amp;gt;AnimationSelector&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;Api&amp;lt;/code&amp;gt;. The selector maintains lists of Traces and State Spaces. The trace shown in the UI is marked as the current trace. The Api object is used to load models. Most likely we will rename this class and instance in the future to something more meaningful, e.g., loader.&lt;br /&gt;
        &lt;br /&gt;
&#039;&#039;&#039;Can I get the trace that is shown in the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.getCurrentTrace() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What traces are registered?&#039;&#039;&#039; &lt;br /&gt;
 animations.getTraces() &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Can I add a trace to the UI?&#039;&#039;&#039; &lt;br /&gt;
 animations.addNewAnimation(t)&lt;br /&gt;
&lt;br /&gt;
==Additional Resources==&lt;br /&gt;
&lt;br /&gt;
Further information can be found in the [[Developer_Manual|developer manual]].&lt;br /&gt;
&lt;br /&gt;
{{Feedback}}&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1980</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1980"/>
		<updated>2013-06-26T20:51:57Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to get started developing with ProB 2.0 */ fix broken links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [https://github.com/bendisposto/prob2 here] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE here]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1933</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1933"/>
		<updated>2013-06-04T12:14:55Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to carry out evaluations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the trace, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1932</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1932"/>
		<updated>2013-06-04T12:14:40Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* In The Console */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current trace. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1931</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1931"/>
		<updated>2013-06-04T12:14:27Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the trace should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1930</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1930"/>
		<updated>2013-06-04T12:13:39Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The Trace abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each Trace object is completely immutable. This means that when you change a trace, you are actually getting a new Trace back. This means that when you carry out an animation step, you always have to make sure that you save the Trace object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current trace, create a new trace, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the Trace class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a trace. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t = t.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting trace will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the trace, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a trace.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentTrace() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a trace saved into variable &amp;lt;tt&amp;gt;trace_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewAnimation(trace_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the trace will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the Trace and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; t.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(space_0[5],[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here. In order to evaluate a formula, you need to specify the StateId object that is associated with the desired id. To extract a StateId from a StateSpace, you can use the notation &amp;lt;tt&amp;gt;space[ID]&amp;lt;/tt&amp;gt; where ID is either a String or an integer representing the StateId that you want to view.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a Trace and a StateSpace and between a Trace and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = trace as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = StateSpace as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = model as Trace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = trace as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = trace as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a Trace, a new trace is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a trace ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a trace in a script so that the same trace can be recreated. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a Trace as an XML trace by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.save(trace_0,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the XML file &amp;lt;tt&amp;gt;fileName.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to load this trace back into the console, there are two options available. You can convert the XML file to a Groovy closure that will then take a Model object and return a Trace with all of the operations specified in the XML file. This can be triggered by calling the method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;TraceConverter.xmlToGroovy(&amp;quot;/pathToFile/fileName.xml&amp;quot;,&amp;quot;/pathToFile/groovyScript.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then run the produced Groovy script and execute the resulting closure to restore your Trace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;run /pathToFile/groovyScript.groovy&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = script_NUM(modelForThisTrace) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisTrace is the model for which the history should be executed.&lt;br /&gt;
&lt;br /&gt;
Another option is to simply restore the Trace directly from the TraceConverter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; trace = TraceConverter.restore(modelForThisTrace,&amp;quot;/pathToFile/fileName.xml&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a trace object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1929</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1929"/>
		<updated>2013-06-04T11:57:19Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The ProB 1.0 API takes advantage of one basic abstraction: developers can create Java commands that can be sent to the prolog kernel where something will be calculated. The result can then be used by the developer. Each Java command corresponds to one prolog command in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
It is actually implemented as a graph (using the JGraphT library), so there are built in graph functions and support for graphical representations. In the graph, the vertices are states and the edges are events (including solutions and choices for local variables and non-deterministic assignments).&lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace that has not yet been explored, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace.&lt;br /&gt;
&lt;br /&gt;
The StateSpace object is actually mutable, but it is always growing. No data ever gets replaced by any new data.&lt;br /&gt;
&lt;br /&gt;
== Trace ==&lt;br /&gt;
&lt;br /&gt;
For some tools, the StateSpace abstraction may be sufficient. But when it comes to animation and the concept of a &amp;quot;current state&amp;quot;, a further abstraction becomes necessary. The Trace provides this abstraction.&lt;br /&gt;
&lt;br /&gt;
A Trace consists of a linked list of states which correspond to a path through the StateSpace. There is also a pointer in the list which identifies the current state. The Trace behaves like a browser history; it is possible to move forward and backward within the current trace.&lt;br /&gt;
&lt;br /&gt;
A Trace corresponds to exactly one trace within the animation. Each Trace is associated with exactly one StateSpace, but we can have many different Trace objects on top of a single StateSpace.&lt;br /&gt;
&lt;br /&gt;
The Trace is immutable. This means that whenever an animation step is performed (forward, backward, or simply adding a transition to the trace) a new Trace is returned.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1928</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1928"/>
		<updated>2013-06-04T11:55:11Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Explanation of the basic programmatic abstractions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of the main goals that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
The basic programmatic abstractions that are available in the ProB 2.0 API are the Model, Trace, and StateSpace abstractions. The Model provides all the static information about the model that is currently being checked or animated. The StateSpace provides the corresponding label transition system for the Model. The Trace represents exactly one trace throughout the StateSpace. A more detailed description of the different is available [[Programmatic Abstractions in the ProB 2.0 API|here]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
A tutorial for the current features of ProB 2.0 is available [[ProB 2.0 Tutorial|here]].&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1927</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1927"/>
		<updated>2013-06-04T11:54:53Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Explanation of the basic programmatic abstractions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of the main goals that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
The basic programmatic abstractions that are available in the ProB 2.0 API are the Model, Trace, and StateSpace abstractions. The Model provides all the static information about the model that is currently being checked or animated. The StateSpace provides the corresponding label transition system for the Model. The Trace represents exactly one trace throughout the StateSpace. A more detailed description of the different is available in [[Programmatic Abstractions in the ProB 2.0 API|here]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
A tutorial for the current features of ProB 2.0 is available [[ProB 2.0 Tutorial|here]].&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1814</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1814"/>
		<updated>2012-11-30T14:07:16Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to animate with only the StateSpace abstraction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the History and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(&amp;quot;5&amp;quot;,[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a History and a StateSpace and between a History and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = history as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = StateSpace as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = model as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = history as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = history as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a History, a new history is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a history in a script so that the same history can be create. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a History as a script by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;HistoryConverter.save(history_0,&amp;quot;/pathToFile/scriptName.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the script &amp;lt;tt&amp;gt;scriptName.groovy&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To load this history back into the console, type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run /pathToFile/scriptName.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history_1 = script_NUM(modelForThisHistory) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisHistory is the model for which the history should be executed.&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;br /&gt;
&lt;br /&gt;
It is also possible to carry out animations without using a history object.&lt;br /&gt;
&lt;br /&gt;
To get the root vertex from StateSpace space_0, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = space_0.root &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from there, you can execute a chain of events. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; st = st.anyEvent(&amp;quot;new&amp;quot;).anyEvent().new(&amp;quot;pp=PID1&amp;quot;).new() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So you can execute anyEvent with the method anyEvent(filter), where filter can be a String name, or a List of names. You can also execute an event with name &amp;quot;name&amp;quot;, with the method name(predicate), where predicate is the predicate string intended to filter the solutions for the event. If there are no parameters, the predicate &amp;quot;TRUE = TRUE&amp;quot; will automatically be added.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1813</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1813"/>
		<updated>2012-11-30T13:53:39Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to run a groovy script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the History and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(&amp;quot;5&amp;quot;,[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a History and a StateSpace and between a History and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = history as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = StateSpace as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = model as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = history as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = history as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a History, a new history is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a history in a script so that the same history can be create. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a History as a script by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;HistoryConverter.save(history_0,&amp;quot;/pathToFile/scriptName.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the script &amp;lt;tt&amp;gt;scriptName.groovy&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To load this history back into the console, type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run /pathToFile/scriptName.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history_1 = script_NUM(modelForThisHistory) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisHistory is the model for which the history should be executed.&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
You can use the build in &amp;lt;tt&amp;gt;run&amp;lt;/tt&amp;gt; command to run a groovy script. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run pathToScript/script.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. Code completion is available for the run command.&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1812</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1812"/>
		<updated>2012-11-30T13:48:26Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to save a history */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the History and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(&amp;quot;5&amp;quot;,[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a History and a StateSpace and between a History and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = history as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = StateSpace as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = model as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = history as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = history as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a History, a new history is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a history in a script so that the same history can be create. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a History as a script by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;HistoryConverter.save(history_0,&amp;quot;/pathToFile/scriptName.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the script &amp;lt;tt&amp;gt;scriptName.groovy&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To load this history back into the console, type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; run /pathToFile/scriptName.groovy &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A script &amp;lt;tt&amp;gt;script_NUM&amp;lt;/tt&amp;gt; will be produced. Then enter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history_1 = script_NUM(modelForThisHistory) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
into the console, where modelForThisHistory is the model for which the history should be executed.&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1811</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1811"/>
		<updated>2012-11-30T13:45:29Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to save a history */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the History and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(&amp;quot;5&amp;quot;,[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a History and a StateSpace and between a History and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = history as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = StateSpace as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = model as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = history as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = history as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a History, a new history is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
ProB currently supports a mechanism to save a history in a script so that the same history can be create. We are currently working on some improvements to this mechanism, so expect it to change over the next period of time. Currently, it is possible to save a History as a script by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;HistoryConverter.save(history_0,&amp;quot;/pathToFile/scriptName.groovy&amp;quot;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will create the script &amp;lt;tt&amp;gt;scriptName.groovy&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1810</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1810"/>
		<updated>2012-11-30T13:42:17Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to convert between the main abstractions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the History and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(&amp;quot;5&amp;quot;,[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
There is a connection between all of the main abstractions. You can easily convert between them by using the &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
To convert between a Model and a StateSpace, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; eventb = statespace_0 as EventBModel &amp;lt;/tt&amp;gt; (if you are animating an Event B model) &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; classicalb = statespace_0 as ClassicalBModel &amp;lt;/tt&amp;gt; (if you are animating ClassicalB).&lt;br /&gt;
&lt;br /&gt;
The reverse translation is just as easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = model as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return the StateSpace associated with model.&lt;br /&gt;
&lt;br /&gt;
Conversion between a History and a StateSpace and between a History and Model are also simple. The following conversions are valid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space = history as StateSpace &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = StateSpace as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; history = model as History &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; model = history as EventBModel &amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt; model = history as ClassicalBModel &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only thing to mention is that every time you convert from a StateSpace or Model to a History, a new history is created.&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1809</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1809"/>
		<updated>2012-11-30T13:34:52Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to carry out evaluations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
It is very simple to evaluate strings in the groovy console. There is a build in eval method in both the History and the StateSpace. In the history, you just need to specify a string and the parser that is needed to parse the string. The two parsers currently available are &amp;lt;tt&amp;gt;ClassicalB&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EventB&amp;lt;/tt&amp;gt;.For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as EventB) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Event B parser and then will evaluate it at the current state. The following code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot; as ClassicalB) &amp;lt;/tt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
will parse &amp;quot;x:NAT&amp;quot; using the Classical B parser and then will evaluate it at the current state.&lt;br /&gt;
&lt;br /&gt;
Classical B is actually the default parser, so it would also be sufficient to write&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h.eval(&amp;quot;x:NAT&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to evaluate formulas on the SpaceSpace level. For instance, if &amp;lt;tt&amp;gt;space_0&amp;lt;/tt&amp;gt; is a StateSpace, you can evaluate a list of formulas by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; space_0.eval(&amp;quot;5&amp;quot;,[&amp;quot;x:NAT&amp;quot; as EventB,&amp;quot;y:NAT&amp;quot; as ClassicalB]) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the console. This will parse &amp;quot;x:NAT&amp;quot; with the Event B parser and &amp;quot;y:NAT&amp;quot; with the Classical B parser and then will evaluate them at the state with id 5. The parser is not implicit in the StateSpace, so it is important to specify it here.&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1808</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1808"/>
		<updated>2012-11-30T13:23:24Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to switch from UI to groovy console */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
There is an easy way to switch from the UI to the groovy console and back. It all happens using the &amp;quot;animations&amp;quot; global variable in the groovy console. What is important to remember, is that in this case, there is no distinction between an animation and a history.&lt;br /&gt;
&lt;br /&gt;
=== From UI to Console ===&lt;br /&gt;
&lt;br /&gt;
In the UI, switch to the &amp;lt;tt&amp;gt;Current Animations&amp;lt;/tt&amp;gt; view. Here you can view the different animations that are available. If the desired animation is not available, double click on it in this view and it will be set as the current animation. Now, to move this animation from the UI to the groovy console, simply type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; x = animations.getCurrentHistory() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the current animation will be loaded into the variable &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== From the Console to the UI ===&lt;br /&gt;
&lt;br /&gt;
If you have a history saved into variable &amp;lt;tt&amp;gt;history_0&amp;lt;/tt&amp;gt; in the groovy console, you can easily add it to the UI. Simply type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; animations.addNewHistory(history_0) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the groovy console and the history will automatically be added to the list of current animations and all of the views will be updated.&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1807</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1807"/>
		<updated>2012-11-30T13:12:57Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In The UI ===&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1806</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1806"/>
		<updated>2012-11-30T13:12:21Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to animate models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
The History abstraction is available to carry out animations. &lt;br /&gt;
&lt;br /&gt;
=== In The Console ===&lt;br /&gt;
&lt;br /&gt;
There are several different ways that a new transition can be added to the current history. The most important thing to remember is that each History object is completely immutable. This means that when you change a history, you are actually getting a new History back. This means that when you carry out an animation step, you always have to make sure that you save the history object that is returned. &lt;br /&gt;
&lt;br /&gt;
The simplest way to add a transition is to add it via operation id. For instance, if operation 0 is among the enabled operations for the current state, then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(0) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add operation 0 to the current history, create a new history, and return it.&lt;br /&gt;
&lt;br /&gt;
You can also add operations via operation name and a list of the parameters. For instance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.add(&amp;quot;new&amp;quot;,[&amp;quot;PID3&amp;quot;]) &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will add the transition new(PID3) to the trace.&lt;br /&gt;
&lt;br /&gt;
It is also possible to execute any event by executing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is also possible to execute any event with name &amp;quot;name&amp;quot;. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.anyEvent(&amp;quot;name&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute any event with the name &amp;quot;name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to execute an event by treating it as if it were a method in the history class. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new() &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
will execute the event new (by default, the first solution for &amp;quot;new&amp;quot; is chosen). It is also possible to add a predicate as a parameter to filter for a particular solution. For instance,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.new(&amp;quot;pp=PID1&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will execute new(PID1) as long as pp is the name of the parameter for new.&lt;br /&gt;
&lt;br /&gt;
It also possible to move backwards and forwards within a history. &lt;br /&gt;
&lt;br /&gt;
Move backwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.back() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move forwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; h = h.forward() &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== In The UI ==&lt;br /&gt;
&lt;br /&gt;
In order to animate a loaded model in the UI, double-click on an enabled event in the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view. Then, the resulting history will automatically be loaded into the different views and it can be further animated. To move backwards and forwards in the history, use the buttons in the upper right hand corner of the &amp;lt;tt&amp;gt;Events&amp;lt;/tt&amp;gt; view.&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1805</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1805"/>
		<updated>2012-11-30T12:44:07Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;br /&gt;
&lt;br /&gt;
== How to animate models ==&lt;br /&gt;
&lt;br /&gt;
== How to switch from UI to groovy console ==&lt;br /&gt;
&lt;br /&gt;
== How to carry out evaluations ==&lt;br /&gt;
&lt;br /&gt;
== How to convert between the main abstractions ==&lt;br /&gt;
&lt;br /&gt;
== How to save a history ==&lt;br /&gt;
&lt;br /&gt;
== How to run a groovy script ==&lt;br /&gt;
&lt;br /&gt;
== How to animate with only the StateSpace abstraction ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1804</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1804"/>
		<updated>2012-11-30T12:40:37Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* How to load a model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Event B === &lt;br /&gt;
&lt;br /&gt;
To load an Event B model into ProB, right click on the model and select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Start Animation / Model Checking &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from the context menu that drops down.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1803</id>
		<title>ProB Java API Tutorial</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_Java_API_Tutorial&amp;diff=1803"/>
		<updated>2012-11-30T12:30:34Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: Created page with &amp;#039;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some o…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ProB 2.0 is currently experimental. This means that the implementation may change during the course of development. However, we have reached the point in development where some of the features have reached a certain level of stability. Therefore, we are writing this tutorial to explain what those features are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to get started developing with ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
The source code for ProB 2.0 is available via GitHub. Click [[https://github.com/bendisposto/prob2|here]] to view the prob2 repository. There is also a short guide available there which will help getting Eclipse set up so that you can get started with the development. Our bugtracker is available [[http://jira.cobra.cs.uni-duesseldorf.de/browse/PROBCORE|here]]. There you can view the features that we are currently working on and can submit new feature requests.&lt;br /&gt;
&lt;br /&gt;
== How to open the Groovy Shell == &lt;br /&gt;
&lt;br /&gt;
The ProB Groovy shell is available in the Eclipse application. To open it, select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; Window &amp;gt; Show View &amp;gt; Other.. &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then select&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; ProB &amp;gt; Groovy Console &amp;lt;/tt&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and hit &amp;lt;tt&amp;gt; ok&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== How to load a model ==&lt;br /&gt;
&lt;br /&gt;
=== Classical B ===&lt;br /&gt;
&lt;br /&gt;
You can load a Classical B model into the groovy console in two ways. There is a built in &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; load /home/pathToFile/example.mch &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would load example.mch into the console (it will automatically save it into a variable named &amp;lt;tt&amp;gt;model_NUM&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;NUM&amp;lt;/tt&amp;gt; is a unique identifier). The nice thing about the load command is that it allows code completion. Code completion works the same as in a normal console. Hit &amp;lt;tt&amp;gt; &amp;lt;TAB&amp;gt; &amp;lt;/tt&amp;gt; to see the code completions that are available.&lt;br /&gt;
&lt;br /&gt;
If you are writing a script that you want to run in the console, you will want to use the &amp;lt;tt&amp;gt; api &amp;lt;/tt&amp;gt; variable that is available. There is a method &amp;lt;tt&amp;gt; b_load &amp;lt;/tt&amp;gt; that is available to load Classical B models. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt; m = api.b_load(&amp;quot;/home/pathToFile/example.mch&amp;quot;) &amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will load example.mch into the variable &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1802</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1802"/>
		<updated>2012-11-30T10:32:35Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Explanation of the basic programmatic abstractions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of the main goals that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
The basic programmatic abstractions that are available in the ProB 2.0 API are the Model, History, and StateSpace abstractions. The Model provides all the static information about the model that is currently being checked or animated. The StateSpace provides the corresponding label transition system for the Model. The History corresponds to exactly one trace throughout the StateSpace. A more detailed description of the different is available in [[Programmatic Abstractions in the ProB 2.0 API|here]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
A tutorial for the current features of ProB 2.0 is available [[ProB 2.0 Tutorial|here]].&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1801</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1801"/>
		<updated>2012-11-30T10:32:16Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Tutorial of the Current Features of ProB 2.0 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of the main goals that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
The basic programmatic abstractions that are available in the ProB 2.0 API are the Model, History, and StateSpace abstractions. The Model provides all the static information about the model that is currently being checked or animated. The StateSpace provides the corresponding label transition system for the Model. The History corresponds to exactly one trace throughout the StateSpace. A more detailed description of the different is available in the [[Programmatic Abstractions in the ProB 2.0 API]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
A tutorial for the current features of ProB 2.0 is available [[ProB 2.0 Tutorial|here]].&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1800</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1800"/>
		<updated>2012-11-30T10:23:12Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* History */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The ProB 1.0 API takes advantage of one basic abstraction: developers can create Java commands that can be sent to the prolog kernel where something will be calculated. The result can then be used by the developer. Each Java command corresponds to one prolog command in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
It is actually implemented as a graph (using the JGraphT library), so there are built in graph functions and support for graphical representations. In the graph, the vertices are states and the edges are events (including solutions and choices for local variables and non-deterministic assignments).&lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace that has not yet been explored, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace.&lt;br /&gt;
&lt;br /&gt;
The StateSpace object is actually mutable, but it is always growing. No data ever gets replaced by any new data.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
&lt;br /&gt;
For some tools, the StateSpace abstraction may be sufficient. But when it comes to animation and the concept of a &amp;quot;current state&amp;quot;, a further abstraction becomes necessary. The History provides this abstraction.&lt;br /&gt;
&lt;br /&gt;
The History consists of a linked list of states which correspond to a path through the StateSpace. There is also a pointer in the list which identifies the current state. The History behaves like a browser history; it is possible to move forward and backward within the current trace.&lt;br /&gt;
&lt;br /&gt;
And important concept to understand when considering the History is that the idea of a &amp;quot;history&amp;quot; is in this sense equivalent with the concept of an &amp;quot;animation&amp;quot;. A History corresponds to exactly one animation trace. Each History is associated with exactly one StateSpace, but we can have many different History objects on top of a single StateSpace.&lt;br /&gt;
&lt;br /&gt;
The History is immutable. This means that whenever an animation step is performed (forward, backward, or simply adding a transition to the trace) a new History is returned.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1799</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1799"/>
		<updated>2012-11-30T10:10:30Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* StateSpace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The ProB 1.0 API takes advantage of one basic abstraction: developers can create Java commands that can be sent to the prolog kernel where something will be calculated. The result can then be used by the developer. Each Java command corresponds to one prolog command in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
There is a one-to-one relationship between a StateSpace and a model. The StateSpace is the corresponding label transition system for a particular model. &lt;br /&gt;
It is actually implemented as a graph (using the JGraphT library), so there are built in graph functions and support for graphical representations. In the graph, the vertices are states and the edges are events (including solutions and choices for local variables and non-deterministic assignments).&lt;br /&gt;
&lt;br /&gt;
Conceptually, the state space is completely there and completely evaluated. When you access a state within the StateSpace that has not yet been explored, ProB will fetch the information from Prolog automatically and transparently. The only observation that can be made is that the fetching of some states takes longer than the ones that are already &amp;quot;cached&amp;quot; in the StateSpace.&lt;br /&gt;
&lt;br /&gt;
The StateSpace object is actually mutable, but it is always growing. No data ever gets replaced by any new data.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1798</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1798"/>
		<updated>2012-11-30T10:05:05Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The ProB 1.0 API takes advantage of one basic abstraction: developers can create Java commands that can be sent to the prolog kernel where something will be calculated. The result can then be used by the developer. Each Java command corresponds to one prolog command in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
The Model is an abstraction that provides static information about the current model that is being animated or checked. For Classical B and Event B, this includes all of the information about the refinement chain and all of the different components (Machines, Contexts, Invariants, Variables, etc.). &lt;br /&gt;
&lt;br /&gt;
This abstraction is available so that it is possible to have access to the static information about the model during an animation without having to contact ProB directly. &lt;br /&gt;
&lt;br /&gt;
Currently, the Model abstraction is implemented for the Classical B and Event B formalisms. But because we have implemented the abstraction with other formalisms in mind, it should not be difficult to implement new formalisms.&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1797</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1797"/>
		<updated>2012-11-30T09:48:41Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The ProB 1.0 API takes advantage of one basic abstraction: developers can create Java commands that can be sent to the prolog kernel where something will be calculated. The result can then be used by the developer. Each Java command corresponds to one prolog command in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering how the ProB core should be structured, we realized that many commands may be used over and over again in the same (or very similar) concepts. Therefore, we created the programmatic abstractions that will be described in the following sections.&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1796</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1796"/>
		<updated>2012-11-30T09:45:04Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
The ProB 1.0 API takes advantage of one basic abstraction: developers can create Java commands that can be sent to the prolog kernel where something will be calculated. The result can then be used by the developer. Each Java command corresponds to one prolog command in the ProB kernel.&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
The developer is still able to use commands in order to get information from the prolog kernel. But as we were considering the ProB model&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1795</id>
		<title>Programmatic Abstractions in the ProB 2.0 API</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=Programmatic_Abstractions_in_the_ProB_2.0_API&amp;diff=1795"/>
		<updated>2012-11-30T09:33:20Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: Created page with &amp;#039;__TOC__  == Model ==  == StateSpace ==  == History ==&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
&lt;br /&gt;
== StateSpace ==&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1794</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1794"/>
		<updated>2012-11-30T09:32:50Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Explanation of the basic programmatic abstractions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of the main goals that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
The basic programmatic abstractions that are available in the ProB 2.0 API are the Model, History, and StateSpace abstractions. The Model provides all the static information about the model that is currently being checked or animated. The StateSpace provides the corresponding label transition system for the Model. The History corresponds to exactly one trace throughout the StateSpace. A more detailed description of the different is available in the [[Programmatic Abstractions in the ProB 2.0 API]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
Something.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
	<entry>
		<id>https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1793</id>
		<title>ProB 2.0 Development</title>
		<link rel="alternate" type="text/html" href="https://prob.hhu.de/w/index.php?title=ProB_2.0_Development&amp;diff=1793"/>
		<updated>2012-11-30T09:07:03Z</updated>

		<summary type="html">&lt;p&gt;Joy Clark: /* Why Groovy? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Developer Manual]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Basic Design Principles ==&lt;br /&gt;
&lt;br /&gt;
One of the main goals that we wanted to build our UI on top of a programmatic API. Our goal was to bring the ProB 2.0 API into a scripting language and not to bring the scripting language into the API.&lt;br /&gt;
&lt;br /&gt;
We also attempted to apply functional programming techniques to our project wherever it was possible. This included trying to create small abstractions that could be composed in different ways. For example, we tried to avoid very large interfaces, but instead preferred to have small functions and methods that accomplish one single task. For this same reason, we tried to use immutable data structures wherever possible.&lt;br /&gt;
&lt;br /&gt;
The ProB API needs to deal with many different formalisms (i.e. Classical B, Event B, Z, CSP, etc.). For this reason, we constucted our data structures so that they can be easily adapted for other formalisms. &lt;br /&gt;
&lt;br /&gt;
While developing a particular feature, it is very helpful to be able to easily experiment and interact with the tool. For this reason, we have spent quite a bit of energy developing a developer friendly console for testing out features as they are being developed.&lt;br /&gt;
&lt;br /&gt;
=== Why Groovy? ===&lt;br /&gt;
&lt;br /&gt;
The scripting language that we chose is Groovy. It is a dynamically typed JVM language. Because of the seamless integration between Java and Groovy libraries, we can easily integrate any jar library into the ProB API, and the code that we produce can also be fully integrated into any other Java project. &lt;br /&gt;
&lt;br /&gt;
Groovy also has many features that make it an ideal scripting language. It provides closures which allow the definition of higher order functions. It is also possible to perform meta programming and thereby redefine or modify existing groovy or java class files. For example, in ProB 2.0, we redefined the java.lang.String class so that we can specify the correct Parser with which a string should be parsed.&lt;br /&gt;
&lt;br /&gt;
== Explanation of the basic programmatic abstractions ==&lt;br /&gt;
&lt;br /&gt;
Something.&lt;br /&gt;
&lt;br /&gt;
== Tutorial of the Current Features of ProB 2.0 ==&lt;br /&gt;
&lt;br /&gt;
Something.&lt;/div&gt;</summary>
		<author><name>Joy Clark</name></author>
	</entry>
</feed>