<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.weizmann.ac.il/bp/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.weizmann.ac.il/bp/index.php?feed=atom&amp;namespace=0&amp;title=Special%3ANewPages</id>
		<title>BP Wiki - New pages [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.weizmann.ac.il/bp/index.php?feed=atom&amp;namespace=0&amp;title=Special%3ANewPages"/>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Special:NewPages"/>
		<updated>2026-06-13T17:47:03Z</updated>
		<subtitle>From BP Wiki</subtitle>
		<generator>MediaWiki 1.22.4</generator>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Dining_Philosophers</id>
		<title>Dining Philosophers</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Dining_Philosophers"/>
				<updated>2014-05-12T08:56:24Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* Dining Philosophers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Dining Philosophers =&lt;br /&gt;
In this example one can see (a) how multiple behaviors coexist independently of each other, with very simple rules for each and (b) how model-checking can help find conflicts and other desired and undesired properties.&lt;br /&gt;
&lt;br /&gt;
The example can be found in the BPJ project in the source package bp.state.unittest.ph .&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
&lt;br /&gt;
In the famous dining philosophers problem several philosophers are sitting at a circular table, and are either eating or thinking. At the center is a large bowl of spaghetti, which requires two forks to serve and to eat. A fork is placed in between each pair of adjacent philosophers. Each philosopher may only use the fork to her left and the fork to her right. When a philosopher finishes eating, she puts down the two forks and begins thinking again. Our present goal is to check whether deadlocks, or other starvation conditions, may occur under various philosopher behaviors.&lt;br /&gt;
&lt;br /&gt;
The problem is programmed/modeled behaviorally as follows: &lt;br /&gt;
== Events ==&lt;br /&gt;
The events are the picking up and the putting down of a given fork by a given philosopher (e.g., PickUp-F2-by-P2  or PutDown-F1-by-P2)&lt;br /&gt;
&lt;br /&gt;
== B-Threads ==&lt;br /&gt;
There is a b-thread for the behavior of each philosopher and a b-thread for each fork.  In the classical&lt;br /&gt;
version, each philosopher b-thread repeatedly requests the sequence of events representing her picking up the fork to her right, picking up the fork to her left, putting down the right-hand fork, and then putting down the left-hand one. Each fork's b-thread&lt;br /&gt;
repeatedly waits for an event of picking up the fork by either of its two adjacent philosophers and then blocks its picking up&lt;br /&gt;
(again)until the fork is put down.&lt;br /&gt;
&lt;br /&gt;
The application assists the model-checking search by labeling the four philosopher behavior states&lt;br /&gt;
T(thinking -- forks down), 1 (one fork up), E (eating -- two forks up) and F (finished eating -- one fork down).&lt;br /&gt;
&lt;br /&gt;
The fork b-thread states are D (down) and U (up).&lt;br /&gt;
&lt;br /&gt;
We use model-checking to look for violations of liveness properties, and&lt;br /&gt;
detect the deadlock conditions that are possible under this classical behavior.&lt;br /&gt;
&lt;br /&gt;
For example, a path to a deadlock state in the case of 3 philosophers is displayed as:&lt;br /&gt;
&lt;br /&gt;
 Verification failed:&lt;br /&gt;
 init-&amp;gt;[T, D, T, D, T, D]&lt;br /&gt;
 PickUp-F2-by-P2-&amp;gt;[T, D, T, D, 1, U]&lt;br /&gt;
 PickUp-F1-by-P1-&amp;gt;[T, D, 1, U, 1, U]&lt;br /&gt;
 PickUp-F0-by-P0-&amp;gt;[1, U, 1, U, 1, U]&lt;br /&gt;
 [1, U, 1, U, 1, U] is a deadlock state&lt;br /&gt;
&lt;br /&gt;
where each line of the form &amp;quot;&amp;lt;event&amp;gt; -&amp;gt; &amp;lt;State&amp;gt;&amp;quot; describes a composite states of the entire program along the path and the event whose triggering led the program to transition from the preceding state to the current.&lt;br /&gt;
&lt;br /&gt;
In the symmetry breaking approach one of the philosophers is left-handed, and thus first picks up the fork to her left, rather than the one to her right. As expected, this setup is then proven by model-checking to be deadlock-free, following checking of all possible states.&lt;br /&gt;
&lt;br /&gt;
For liveness testing, the philosophers behavior b-threads marks the non-eating states as hot, and the model-checker is then&lt;br /&gt;
able to detect the starvation conditions that are possible if fairness is weak.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Learning</id>
		<title>Learning</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Learning"/>
				<updated>2014-04-27T18:41:31Z</updated>
		
		<summary type="html">&lt;p&gt;BpAdmin: /* Reference Materials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Adaptive Behavioral Programming =&lt;br /&gt;
&lt;br /&gt;
We introduce a way to program adaptive reactive&lt;br /&gt;
systems, using behavioral programming.&lt;br /&gt;
Extending the semantics of BPJ with reinforcements&lt;br /&gt;
allows the programmer not only to specify what&lt;br /&gt;
the system should do or must not do, but also what it should&lt;br /&gt;
try to do, in an intuitive and incremental way. By integrating&lt;br /&gt;
behavioral programs with reinforcement learning methods,&lt;br /&gt;
the program can adapt to the environment, and try to achieve&lt;br /&gt;
the desired goals.&lt;br /&gt;
&lt;br /&gt;
== Reference Materials ==&lt;br /&gt;
* Paper: [http://www.wisdom.weizmann.ac.il/~harel/papers/Adaptive%20BP.pdf Adaptive Behavioral Programming]&lt;br /&gt;
* [http://www.wisdom.weizmann.ac.il/~bprogram/code/ReinforcementLearningBPJ.zip Code and examples]: &amp;lt;br/&amp;gt;&lt;br /&gt;
** A base version of BPJ.&lt;br /&gt;
** A Java library with extensions to BPJ for reinforcement learning. Import and add to the classpath.&lt;br /&gt;
** Example: A Salad cutting robot. The b-threads provide an incomplete specification for a simulated robot that needs to pick up vegetables, cut them and serve them to customers. Using reinforcement learning, the robot learns the correct order in which to execute these actions.&lt;br /&gt;
** Example: Tic Tac Toe, where the application learns how to play despite underspecification.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=BP_Blockly_User_Guide</id>
		<title>BP Blockly User Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=BP_Blockly_User_Guide"/>
				<updated>2014-04-16T14:30:23Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= BP Blockly User Guide =&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
BP in Google Blockly is an experimental platform set to illustrate visually the basic capabilities of behavioral programming.&lt;br /&gt;
&lt;br /&gt;
It is implemented in Blockly by introducing new programming blocks, and by using the co-routines (generators) facility of JavaScript.&lt;br /&gt;
Behavioral programs written in Blockly are translated into and executed as JavaScript programs.&lt;br /&gt;
&lt;br /&gt;
= Installation / Getting started =&lt;br /&gt;
* Install Firefox browser version 15.0.1 or later.&lt;br /&gt;
* For online use: open with FireFox the designated [http://www.b-prog.org/BP_Code/apps/BP  Blockly link]&lt;br /&gt;
* For offline/local use on your computer:&lt;br /&gt;
** Download the zip file containing the Blockly and JavaScript package from the download screen;&lt;br /&gt;
** Extract the zip file, preserving directory structure;&lt;br /&gt;
** Open with Firefox the file BP_Code\apps\BP\index.html;&lt;br /&gt;
* Look at example projects in the examples drop down, additional examples linked from this site, and the [http://bp-new-blockly.appspot.com/ tutorial]&lt;br /&gt;
&lt;br /&gt;
= User Interface =&lt;br /&gt;
&lt;br /&gt;
== Tabs ==&lt;br /&gt;
The BP Blockly interface introduces four tabs:&lt;br /&gt;
* Blocks: In this tab, on the left is the 'pallet' or menu of Blockly blocks to choose from, and on the right is the canvas where the application is developed.&lt;br /&gt;
* HTML: In this tab you program the HTML interfaces of your application, especially sensors and actuators.&lt;br /&gt;
* Project Blocks: In this tab you can define new application-specific blocks. For example, application specific events.&lt;br /&gt;
* JavaScript: This tab, shown in &amp;quot;debug&amp;quot; mode, shows the executable JavaScript generated from the Blockly code&lt;br /&gt;
* XML: This tab, shown in &amp;quot;debug&amp;quot; mode, shows the text file where the entire application is stored.&lt;br /&gt;
&lt;br /&gt;
== Navigation ==&lt;br /&gt;
* To scroll click and drag the canvas up or down, or use the scroll bar.&lt;br /&gt;
* Note that at initial loading parts of an application may be hidden and you may need to scroll up.&lt;br /&gt;
* Actions: Right click offers a popup menu&lt;br /&gt;
&lt;br /&gt;
= Programming =&lt;br /&gt;
* To create an application drag blocks onto the canvas&lt;br /&gt;
* To start the application click on the red &amp;quot;Play&amp;quot; button&lt;br /&gt;
* To provide HTML information, look at templates of existing projects and at [http://www.b-prog.org/pres/agere2012AuthorVersion.pdf  AGERE!2012 paper].&lt;br /&gt;
* Sensor example: for translating a button click into a behavioral event&lt;br /&gt;
 input value=&amp;quot;StartGame&amp;quot;&lt;br /&gt;
 type=&amp;quot;button&amp;quot;&lt;br /&gt;
 onclick=&amp;quot;startGame();&amp;quot;&lt;br /&gt;
 style=&amp;quot;position:relative;background-color:LightPink;&amp;quot;&lt;br /&gt;
* To create an actuator, code&lt;br /&gt;
 when_&amp;lt;eventName&amp;gt; = ... &amp;lt; mycode &amp;gt;&lt;br /&gt;
* Example actuator which changes a screen display:&lt;br /&gt;
  input value='Status:     Playing       '&lt;br /&gt;
  type=&amp;quot;button&amp;quot;&lt;br /&gt;
  when_DisplayWin =&amp;quot;value='Status: *** Successful*** ';alert(' !!! You Won   !!! ');&amp;quot;&lt;br /&gt;
  when_DisplayLose=&amp;quot;value='Status: !!! Game Lost !!! ';alert(' !!! Game Lost !!! ');&amp;quot;&lt;br /&gt;
  style=&amp;quot;position:relative;background-color:LightPink;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Your application is not required to have its own GUI and HTML – you can experiment with creating interwoven behavioral flow just with events&lt;br /&gt;
* B-thread priority:&lt;br /&gt;
** Round robin: All b-threads have same priority. Events that are requested and not blocked are chosen from the different b-threads in turn.&lt;br /&gt;
** Strict priority: All b-threads are ordered, as determined by their top down and left-to-right placement on the canvas (presently disabled).&lt;br /&gt;
* Loading an existing project: Click &amp;quot;Load project&amp;quot;, and browse and select an XML file where a project has been saved.&lt;br /&gt;
* Saving a project: Click &amp;quot;Save Project&amp;quot; and use standard browser functions to save the XML file. Close the extra tabs.&lt;br /&gt;
* Debugging and Event Logging:&lt;br /&gt;
** Use Firefox console native, or&lt;br /&gt;
** Use [ http://getfirebug.com/ Firebug tool]:&lt;br /&gt;
*** Start the application&lt;br /&gt;
*** In the application GUI screen – click on the firebug icon;&lt;br /&gt;
*** You may have to reload the application GUI screen;&lt;br /&gt;
*** In the firebug display click console tab;&lt;br /&gt;
*** In the console drop-down - make sure console is enabled;&lt;br /&gt;
*** Start the application&lt;br /&gt;
*** Watch the events in the console log.&lt;br /&gt;
* Do not edit the compiled JavaScript or XML file;&lt;br /&gt;
* Avoid spaces or periods in strings and variable names&lt;br /&gt;
* Sometimes the XML file may be corrupted. To avoid losing your data, save frequently in different file names and verify the file can be loaded.&lt;br /&gt;
&lt;br /&gt;
= BP Programming Blocks =&lt;br /&gt;
With BP you have in Blockly the following new programming blocks:&lt;br /&gt;
* B-thread: In the version of BP for Blockly there is no separate block for behavior threads. Each contiguous set of execution blocks forms a b-thread. You can add a comment to the b-thread, indicating its name or function, but this is not mandatory. An earlier version of BP there is a container block for a b-threads.&lt;br /&gt;
** However, the block called &amp;quot;instantiate with&amp;quot; enables the creation of multiple b-threads with different parameters. See example in the Tic-Tac-Toe game.&lt;br /&gt;
* Event: Defines a e behavioral event. The event name should be entered a string inside this event block.&lt;br /&gt;
* Request &amp;lt;event&amp;gt;:  Request an event. The event is requested and the program continues when the event is triggered.&lt;br /&gt;
* Wait for &amp;lt;event &amp;gt;: wait for and event. The program continues when the event is triggered.&lt;br /&gt;
* Blocking &amp;lt;event&amp;gt;: This container block, forbids the specified event until the code contained in it completes&lt;br /&gt;
* Break upon &amp;lt;event&amp;gt;: This container block executes the code contained in it, but the execution is interrupted if and when the specified event is triggered.&lt;br /&gt;
* b-Sync: This block is available in an earlier version of BP for Blockly, and it can specify requested, waited-for and blocked events.&lt;br /&gt;
* Application specific blocks: These blocks are defined by the user in the application blocks tab, and can then be used from the pallet. They can be used for events, lists and more. For example, to code an application event block, the easiest way is to copy and paste the following code changing the text &amp;quot;MYEVENT&amp;quot; to your event name (in four places).&lt;br /&gt;
&lt;br /&gt;
 custom.bp_event_MYEVENT = {&lt;br /&gt;
   helpUrl: 'http://www.example.com/',&lt;br /&gt;
   init: function() {&lt;br /&gt;
     this.setColour(290);&lt;br /&gt;
     this.appendDummyInput()&lt;br /&gt;
         .appendTitle(&amp;quot;MYEVENT&amp;quot;);&lt;br /&gt;
     this.setOutput(true, 'event');&lt;br /&gt;
     this.setTooltip('');&lt;br /&gt;
   }&lt;br /&gt;
 };&lt;br /&gt;
 Blockly.JavaScript.bp_event_MYEVENT = function () {&lt;br /&gt;
     return ['&amp;quot;MYEVENT&amp;quot;', Blockly.JavaScript.ORDER_NONE];&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
= Example: Alternating Taps =&lt;br /&gt;
&lt;br /&gt;
* When in BP for Blockly (under FireFox), click the drop-down menu and select &amp;quot;Hot and Cold&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This example contains three enabled b-threads and one disabled b-thread.&lt;br /&gt;
&lt;br /&gt;
* 1. Requesting the event addHot 10 times.&lt;br /&gt;
* 2. Requesting the event addCold 10 times.&lt;br /&gt;
* 3. Forcing the alternation of the two events by waiting for two occurrences of addHot event and blocking the addCold, and vice versa, in a loop.&lt;br /&gt;
&lt;br /&gt;
Experimenting:&lt;br /&gt;
* Try disabling the third b-thread. Both remaining b-threads will run and events will alternate, per the round robin scheduling in this version of BP for Blockly.&lt;br /&gt;
* Then try disabling the first b-thread. Only addCold events will be triggered.&lt;br /&gt;
* Then enable the third b-thread, and run the program again. No events will be triggered due the blocking of addCold.&lt;br /&gt;
* Click on the HTML tab and examine the HTML actuator code that displays the event text upon triggering of the events.  In another implementation this code could call a JavaScript method that actually opens a water tap for a few seconds.&lt;br /&gt;
* The 4th b-thread was loaded disabled. This is an &amp;quot;actuator&amp;quot; b-thread that reacts to the addHot and addCold events. In this case, by displaying a window with the event text. Again, this b-thread could call a JavaScript method that performs a desired action.&lt;br /&gt;
&lt;br /&gt;
= Example: The Rocket Landing Game Example =&lt;br /&gt;
&lt;br /&gt;
* Download the zipped version of BP Blockly.&lt;br /&gt;
* To load this example click &amp;quot;Load Project&amp;quot; and browse and select bp_code/apps/bp/examples/RocketLanding.xml.&lt;br /&gt;
&lt;br /&gt;
In this game the player attempts to land a rocket on a landing pad on the surface of a planet. The rocket moves downward at a fixed speed in the vertical direction. Using GUI buttons, the player can move the rocket north, south, east and west, with the goal of positioning it directly above the landing pad. The player can also press an Up button to create an exhaust burst that&lt;br /&gt;
suspends the rocket and prevents it from going down in the next time unit. The landing pad keeps moving on the ground either randomly or subject to an unknown plan. Four walls mark the sides of the playing area, and the rocket cannot move past them (but&lt;br /&gt;
does not crash when it touches them). The game is won when the rocket lands exactly on the landing pad, and is lost when it touches the ground without being fully on the pad. The rocket movement is in three dimensions and the view of the entire game scene can be manipulated (tilt, pan, etc.) in 3D.&lt;br /&gt;
&lt;br /&gt;
=== Sensor Events ===&lt;br /&gt;
&lt;br /&gt;
* BtnEast: User clicked East&lt;br /&gt;
* BtnWest: User clicked West&lt;br /&gt;
* BtnNorth: User clicked North&lt;br /&gt;
* BtnSouth: User clicked South&lt;br /&gt;
* TimeTick: A unit of time passed &lt;br /&gt;
* RocketTouchedEastWall: Rocket arrived at east wall&lt;br /&gt;
* RocketAwayFromEastWall: Rocket departed from east wall&lt;br /&gt;
* (Same for west, north and south) . . .&lt;br /&gt;
* TouchDown: Rocket touched launch pad and is aligned with it&lt;br /&gt;
* Missed: Rocket reached or passed launch pad without being aligned with it&lt;br /&gt;
&lt;br /&gt;
=== Actuator Events ===&lt;br /&gt;
* RocketWest: Request to redraw rocket 10 pixels further to the west&lt;br /&gt;
* RocketEast: Request to redraw rocket 10 pixels further to the east&lt;br /&gt;
* RocketNorth: Request to redraw rocket 10 pixels further to the north&lt;br /&gt;
* RocketSouth: Request to redraw rocket 10 pixels further to the south&lt;br /&gt;
* RocketDown: Request to redraw rocket 10 pixels down&lt;br /&gt;
* PadWest: The application wishes the pad to move 10 pixels further to the west&lt;br /&gt;
* PadEast: The application wishes the pad to move 10 pixels further to the east&lt;br /&gt;
* PadNorth: The application wishes the pad to move 10 pixels further to the north&lt;br /&gt;
* PadSouth: The application wishes the pad to move 10 pixels further to the south&lt;br /&gt;
* DisplayWin: The application determined that the player won&lt;br /&gt;
* DisplayLose: The application determined that the player lost&lt;br /&gt;
* GameOver: The application determined that the game should be stopped&lt;br /&gt;
&lt;br /&gt;
== The B-threads ==&lt;br /&gt;
&lt;br /&gt;
The b-threads in the application can be seen  on the canvas.&lt;br /&gt;
They react to:&lt;br /&gt;
* User pressing a button - request rocket move&lt;br /&gt;
* Time ticks - Rocket descending&lt;br /&gt;
* Time ticks - Landing pad moves&lt;br /&gt;
* Rocket reaching a wall - block movements&lt;br /&gt;
* Rocket departing from a wall - allow movements&lt;br /&gt;
* Rocket touching the ground - loss&lt;br /&gt;
* Rocket landing on the landing pad - win&lt;br /&gt;
* Etc.&lt;br /&gt;
&lt;br /&gt;
A key point to observe is that the behavior when rocket reaches the walls is independent and is by blocking of a move past the wall.&lt;br /&gt;
&lt;br /&gt;
= Additional Examples =&lt;br /&gt;
&lt;br /&gt;
The dropdown menu provides two additional examples&lt;br /&gt;
* A nullification game: See explanation in [http://www.wisdom.weizmann.ac.il/~bprogram/pres/agere2012AuthorVersion.pdf AGERE 2012 paper]&lt;br /&gt;
* A basic game of Tic-Tac-Toe: This example, with very basic strategies, demonstrates the instantiation of a b-thread according to a parameter list. For example, the application block &amp;quot;all Squares&amp;quot; represents a list of all possible squares, and a b-thread is instantiated for each one of these, waiting for a user click in this square, and requesting an X event in the same square.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Flight_of_a_flock_of_birds</id>
		<title>Flight of a flock of birds</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Flight_of_a_flock_of_birds"/>
				<updated>2014-04-15T11:56:45Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* Requirements - from each bird */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Simulating Flight of a Flock of Birds =&lt;br /&gt;
In this example we simulate the flight of a flock of birds, with each bird having a simple set of rules implemented as b-threads.&lt;br /&gt;
The example highlights&lt;br /&gt;
* Multi-agent activity&lt;br /&gt;
* Emergent group behaviors - emanating from individual agent behavior&lt;br /&gt;
* Implementation of animation with BPJ - and handling of associated design issues.&lt;br /&gt;
* [http://www.wisdom.weizmann.ac.il/~bprogram/videos/flock25Gather.avi  Movie: 25 birds gathering and flying]&lt;br /&gt;
* [http://www.wisdom.weizmann.ac.il/~bprogram/videos/flockScare.mp4 Movie: Birds disperse in reaction to a &amp;quot;scare&amp;quot; action]&lt;br /&gt;
&lt;br /&gt;
= Requirements - from each bird =&lt;br /&gt;
* Always try to move towards the center of the flock&lt;br /&gt;
* Always avoid colliding with other birds&lt;br /&gt;
* When getting close to a wall - change direction - in the same &amp;quot;reflection&amp;quot; angle&lt;br /&gt;
* When the &amp;quot;Scare&amp;quot; button is hit - fly away from the center of the flock.&lt;br /&gt;
&lt;br /&gt;
= Download =&lt;br /&gt;
# Click [[Media:Flock.zip | here]] to download the flock of birds example.&lt;br /&gt;
# Installation Instructions:&lt;br /&gt;
##Import the downloaded project to your workspace:&lt;br /&gt;
###From the 'File' menu choose 'Import'--&amp;amp;gt;'General'--&amp;amp;gt;'Existing Projects into Workspace'.&lt;br /&gt;
###Click the 'Next' button.&lt;br /&gt;
###Click the 'Select archive file' option and then click the 'Browse...' button to select the downloaded zip file.&lt;br /&gt;
###Click 'Finish'.&lt;br /&gt;
##The flock of birds example project is now part of your workspace.&lt;br /&gt;
##Refer to the readme.txt file for execution instructions.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Sudoku</id>
		<title>Sudoku</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Sudoku"/>
				<updated>2014-04-15T11:17:37Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* Playing b-threads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Sudoku =&lt;br /&gt;
In this example one can see two properties of behavioral programming&lt;br /&gt;
* How different heuristics and pieces of knowledge about the problem domain can be used separately to program an application&lt;br /&gt;
* How model-checking can be used to help find a desired scenario.&lt;br /&gt;
&lt;br /&gt;
= Requirements =&lt;br /&gt;
In the cells of a 9X9 grid which is also divided into 9 3X3 boxes, place the digits 1-9 such that in each row, column and box, each digit appears exactly once.&lt;br /&gt;
&lt;br /&gt;
= Events =&lt;br /&gt;
&lt;br /&gt;
* Move: A single event class with 9X9X9 = 721 instances, indicating the writing of a given digit in a given cell. The class has the following data fields:&lt;br /&gt;
&lt;br /&gt;
** number: the digit written in the cell  (1-9)&lt;br /&gt;
** row: The row  of the cell (1-9)&lt;br /&gt;
** col: the column of the cell  (1-9)&lt;br /&gt;
** boxrow: The row of the 3X3 box in which this cell resides (1-3)&lt;br /&gt;
** boxcol: the column of the 3X3 box in which this cell resides (1-3)&lt;br /&gt;
&lt;br /&gt;
When enough data is provided, the strategies below are sufficient for solving the game.&lt;br /&gt;
When not enough data is provided, model checking explores the different possibilities until a solution is found.&lt;br /&gt;
&lt;br /&gt;
== Playing b-threads ==&lt;br /&gt;
* MakeGivenMoves: This b-thread provides the opening input to the riddle - filling in the known cells.&lt;br /&gt;
* DefaultMove: Each of the 81 instances of this b-thread class, is associated with a cell, and requests all possible 9 digits. Once an event occurs, all other events for the cell are blocked.&lt;br /&gt;
* DetectWin: This b-thread simply counts until 81 events have been triggered. The correctness of the solution is guaranteed&lt;br /&gt;
* EliminateTwoInABox: This b-thread tries to write a number in a cell after  the same number was written in two other columns of this box. It does not check if the cell is occopied or if the digit was already written in the present column - this is provided by event-blocking in other b-threads.&lt;br /&gt;
* PlaceANumberInARow: With an instance for each digit and each row, this b-thread tries to place a particular digit in the row. It waits till there is only one place to put it, and then requests the corresponding event.&lt;br /&gt;
* PlaceANumberInAColumn: With an instance for each digit and each row, this b-thread tries to place a particular digit in the Column. It waits till there is only one place to put it,  and then requests the corresponding event.&lt;br /&gt;
* PlaceANumberInABox: With an instance for each digit and each place in the box, this b-thread tries to place a particular digit in the box. It waits till there is only one place to put it,  and then requests the corresponding event.&lt;br /&gt;
* EliminateEight: For each cell, an instance of this b-thread checks the possibilities for the cell, and eliminates possibilities as conflicting events occur elsewhere. When the number of remaining possibilities is one, the b-thread requests the remaining digit.&lt;br /&gt;
&lt;br /&gt;
== b-threads that support model-checking ==&lt;br /&gt;
PruneWhenNoSolution: This b-thread requests an event at a low priority. If it is triggered, it means that all move events are blocked, hence the game has failed. It then calls the model-checking API to prune the search.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Notes ==&lt;br /&gt;
* The b-thread DefaultMove could have been split into two. One that requests the default moves and terminates, and one that waits for any event in a cell and blocks all alternative digits in the cell. The present design works because a pending request of DefaultMove is unified with any granted request due to the stratgies/heuristics b-threads, as well as the GivenMoves b-thread.&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
# Click [[Media:Sudoku1.zip | here]] to download the sudoku example.&lt;br /&gt;
# Installation Instructions:&lt;br /&gt;
##Import the downloaded project to your workspace:&lt;br /&gt;
###From the 'File' menu choose 'Import'--&amp;amp;gt;'General'--&amp;amp;gt;'Existing Projects into Workspace'.&lt;br /&gt;
###Click the 'Next' button.&lt;br /&gt;
###Click the 'Select archive file' option and then click the 'Browse...' button to select the downloaded zip file.&lt;br /&gt;
###Click 'Finish'.&lt;br /&gt;
##The sudoku example project is now part of your workspace.&lt;br /&gt;
##Refer to the readme.txt file for execution instructions.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Water_Tap</id>
		<title>Water Tap</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Water_Tap"/>
				<updated>2014-04-15T10:02:09Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* Alternating Taps Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Alternating Taps Example =&lt;br /&gt;
&lt;br /&gt;
Below is the full source code of the alternating water taps example. It is part of the BPJ package. &lt;br /&gt;
&lt;br /&gt;
== Events ==&lt;br /&gt;
* addHot&lt;br /&gt;
* addCold&lt;br /&gt;
&lt;br /&gt;
== b-Threads ==&lt;br /&gt;
* addHotThreeTimes: requests addHot  3 times&lt;br /&gt;
* addColdThreeTimes:  requests addCold  3 times&lt;br /&gt;
* Interleave: Causes alternation between addHot and addCold events by blocking one while waiting for the other and vice versa.&lt;br /&gt;
&lt;br /&gt;
An additional b-thread DisplayEvents (commented out) indicate how one could use these events to drive external outputs, such as real water tap actuators.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
 public class AlternatingTaps implements BApplication {&lt;br /&gt;
   @SuppressWarnings(&amp;quot;serial&amp;quot;)&lt;br /&gt;
   static class TapEvent extends Event {&lt;br /&gt;
&lt;br /&gt;
      public TapEvent(String name) {&lt;br /&gt;
         this.setName(name);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   static TapEvent addHot = new TapEvent(&amp;quot;AddHot&amp;quot;);&lt;br /&gt;
   static TapEvent addCold = new TapEvent(&amp;quot;AddCold&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
   @SuppressWarnings(&amp;quot;serial&amp;quot;)&lt;br /&gt;
   public class AddHotThreeTimes extends BThread {&lt;br /&gt;
      public void runBThread() throws BPJException {&lt;br /&gt;
         for (int i = 1; i &amp;lt;= 3; i++) {&lt;br /&gt;
            bp.bSync(addHot, none, none);&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   @SuppressWarnings(&amp;quot;serial&amp;quot;)&lt;br /&gt;
   public class AddColdThreeTimes extends BThread {&lt;br /&gt;
      public void runBThread() throws BPJException {&lt;br /&gt;
         for (int i = 1; i &amp;lt;= 3; i++) {&lt;br /&gt;
            bp.bSync(addCold, none, none);&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   @SuppressWarnings(&amp;quot;serial&amp;quot;)&lt;br /&gt;
   public class Interleave extends BThread {&lt;br /&gt;
      public void runBThread() throws BPJException {&lt;br /&gt;
         while (true) {&lt;br /&gt;
            bp.bSync(none, addHot, addCold);&lt;br /&gt;
            bp.bSync(none, addCold, addHot);&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   @SuppressWarnings(&amp;quot;serial&amp;quot;)&lt;br /&gt;
   public class DisplayEvents extends BThread {&lt;br /&gt;
      public void runBThread() throws BPJException {&lt;br /&gt;
         while (true) {&lt;br /&gt;
            bp.bSync(none, all, none);&lt;br /&gt;
            System.out.println(&amp;quot;Physically turned water tap per event: &amp;quot; + bp.lastEvent);&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   public void runBApplication() {&lt;br /&gt;
      System.out.println(&amp;quot;runBApplication () at &amp;quot; + this);&lt;br /&gt;
      bp.add(new AddHotThreeTimes(), 1.0);&lt;br /&gt;
   //   bp.add(new DisplayEvents(), 2.0);&lt;br /&gt;
      bp.add(new AddColdThreeTimes(), 3.0);&lt;br /&gt;
      bp.add(new Interleave(), 4.0);&lt;br /&gt;
&lt;br /&gt;
      bp.startAll();&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   static public void main(String arg[]) {&lt;br /&gt;
      try {&lt;br /&gt;
&lt;br /&gt;
         BProgram.startBApplication(AlternatingTaps.class, &amp;quot;bp.unittest&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
      } catch (Exception e) {&lt;br /&gt;
         e.printStackTrace();&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Helicopter_flight_and_mission</id>
		<title>Helicopter flight and mission</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Helicopter_flight_and_mission"/>
				<updated>2014-04-07T08:33:45Z</updated>
		
		<summary type="html">&lt;p&gt;BpAdmin: /* Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Helicopter Flight Examples =&lt;br /&gt;
The examples below demonstrates the control of a toy helicopter - AR DRONE by Parrot Inc. &lt;br /&gt;
&lt;br /&gt;
= Basic Composite Behavior =&lt;br /&gt;
The following movies show flight of the helicopter, as well as simulation. The flight was generated by independent concurrent LSCs - where one directs the helicopter through a rectangular flight path without changing altitude, and another directs the helicopter to go up and down without changing its horizontal location. The result is a composite motion, traveling the prescribed path while going up and down.&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|nMTbQc_iq5Y|640}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|sMp8QTetobc|640}}&lt;br /&gt;
&lt;br /&gt;
= Detailed Example: Wall Painting =&lt;br /&gt;
In this example, the mission here is to paint a wall with different colors. This can be considered as an analogy to a photography mission where a particular area as to be covered.&lt;br /&gt;
&lt;br /&gt;
The example is implemented with a simulator. &lt;br /&gt;
&lt;br /&gt;
Below we describe the requirements and the associated b-threads, along with screen images and a movie of the helicopter behavior as it evolves with the addition of new b-threads.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements==&lt;br /&gt;
The requirements below were added incrementally, and b-threads were added to deal with each requirement. In the simulator - the painting of the wall is by drawing a line on the screen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*The helicopter should go up and down along the wall.&lt;br /&gt;
*When the helicopter reaches the ceiling or the floor it should move to the right&lt;br /&gt;
*Every fixed number of pixels the paint color should be changed&lt;br /&gt;
*Since the line drawn by the helicopter is thin, after every small vertical move, the helicopter should move right and left with horizontal brush strokes,  before moving vertically again.&lt;br /&gt;
*The helicopter may move from its present location due to wind.&lt;br /&gt;
*If the helicopter is moved by wind, it should return to its last known location.&lt;br /&gt;
&lt;br /&gt;
In the integration with LSC, two more requirements were added&lt;br /&gt;
*The amount of paint is limited. After a certain number of points is painted - the paint runs out.&lt;br /&gt;
*When paint of a certain color runs out, this color can no longer be used.&lt;br /&gt;
*When all paint colors run out, the helicopter must stop.&lt;br /&gt;
*Paint cans may be re-filled. This is simulated by a user clicking on a button on the screen.&lt;br /&gt;
&lt;br /&gt;
== Events ==&lt;br /&gt;
&lt;br /&gt;
== General control events ==&lt;br /&gt;
* BeginPainting: Start the painting process&lt;br /&gt;
* StopPainting: End the painting process&lt;br /&gt;
* MoveDown: Move down a fixed number of pixels.&lt;br /&gt;
* EndOfColUp: End painting wall going up&lt;br /&gt;
* DoColDownL Start painting wall going down&lt;br /&gt;
* EndOfColDown: End painting wall going up&lt;br /&gt;
* DoRowRight: Start painting wall going right&lt;br /&gt;
* EndOfRowRight: Stop moving right.&lt;br /&gt;
* ChangeColor: This is an event class of which there are four events, indicating a request to change the painting color to the corresponding one in the event name:&lt;br /&gt;
** eChangeColorBLACK&lt;br /&gt;
** eChangeColorRED&lt;br /&gt;
** eChangeColorBLUE&lt;br /&gt;
** eChangeColorGreen&lt;br /&gt;
* UpdateArrived: simulate information from a GPS with actual helicopter location&lt;br /&gt;
&lt;br /&gt;
=== Move Events ===&lt;br /&gt;
&lt;br /&gt;
The following events indicate the desire to move a fixed number of pixels in the desired direction. These events have a data field - indicating whether the movement is for a mission or for maintenance, which serves in correcting wind shifts.&lt;br /&gt;
&lt;br /&gt;
* MoveUp: Move down a fixed number of pixels&lt;br /&gt;
* MoveDown: Move down a fixed number of pixels&lt;br /&gt;
* MoveLeft: Move left a fixed number of pixels&lt;br /&gt;
* MoveRight: Move right a fixed number of pixels&lt;br /&gt;
&lt;br /&gt;
== BPJ b-threads ==&lt;br /&gt;
&lt;br /&gt;
=== General control b-threads ===&lt;br /&gt;
* DoColD2U: Controls coloring in the up direction;&lt;br /&gt;
* YAxis: Reports when helicopter reaches top or bottom end of wall (ceiling of floor)&lt;br /&gt;
* EndColUp: Handle reaching of ceiling. Stop moving vertically, start moving right.&lt;br /&gt;
* DoRowL2R: Left to right painting - waits for  DoRowRight and then repeatedly requests movement to the right until end of right movement is reached.&lt;br /&gt;
* XAxis: Monitor horizontal coordinates. Report reaching of right and left borders of wall, and report end of movement right to start a new column&lt;br /&gt;
* DoColU2D: Controls coloring in the up direction&lt;br /&gt;
* EndColDown: Handles reaching the floor - requests a movement to the right&lt;br /&gt;
* BrushMove: Move the brush right and left (horizontal moves) to create a thicker line and paint continuous area. This b-thread performs its actions between any two vertical moves.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Actuator b-threads ===&lt;br /&gt;
&lt;br /&gt;
The following b-threads wait for the corresponding move event and call the helicopter API (or the simulator) to cause the actual movement.&lt;br /&gt;
* MovingRight&lt;br /&gt;
* MovingLeft&lt;br /&gt;
* MovingDown&lt;br /&gt;
* MovingUp&lt;br /&gt;
&lt;br /&gt;
=== Color control b-threads ===&lt;br /&gt;
* ChangePaintingColor: Waits for the need to change color and changes the color randomly.&lt;br /&gt;
&lt;br /&gt;
=== Location correction b-threads ===&lt;br /&gt;
* FixWind: When a report comes in that the helicopter is not where it is supposed to be - stop painting movement and return to last known location.&lt;br /&gt;
&lt;br /&gt;
=== Environment Simulation ===&lt;br /&gt;
&lt;br /&gt;
* ColorControl: Counts movements and announces the need to change color.&lt;br /&gt;
* Wind: Every certain random number of steps, report a random location of the helicopter&lt;br /&gt;
&lt;br /&gt;
= Incremental Development Notes =&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|6cSqPGvRWw0|640}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With only basic movements and no color change b-threads: &lt;br /&gt;
&lt;br /&gt;
[[Image: Black - thin.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basic movements with color changes: &lt;br /&gt;
&lt;br /&gt;
[[Image: Color-thin.jpg]]&lt;br /&gt;
&lt;br /&gt;
Adding horizontal brush movements: &lt;br /&gt;
&lt;br /&gt;
[[Image: Color-thick.jpg]]&lt;br /&gt;
&lt;br /&gt;
Random movements due to wind, and return by horizontal movement and then vertical to last known location: &lt;br /&gt;
&lt;br /&gt;
[[Image: FixWind.jpg]]&lt;br /&gt;
&lt;br /&gt;
= LSC Integration =&lt;br /&gt;
&lt;br /&gt;
The BPJ-based system was then integrated with the LSC language via PlayGo.&lt;br /&gt;
For details how  to integrate a BPJ application with LSC see a separate section in this documentation.&lt;br /&gt;
&lt;br /&gt;
The following LSC (scenario) was added&lt;br /&gt;
&lt;br /&gt;
* PaintCanEmpty:  Waits for a certain number of movements with a given color and block subsequent changes to that color, simulating and empty can, until an event of PaintFilled arrives. This event is generated by the user clicking on a corresponding GUI Button.&lt;br /&gt;
&lt;br /&gt;
= Design Notes =&lt;br /&gt;
&lt;br /&gt;
The following design patterns and choices can be seen throughout the example.&lt;br /&gt;
&lt;br /&gt;
* Events can be distinguishes from each other by&lt;br /&gt;
** Class - different classes of events&lt;br /&gt;
** Name - multiple instances of an events of the same class distinguished by their name (e.g. the color change events).&lt;br /&gt;
** Data field - Two instances of events of the same class, with arbitrary names can be distinguished by a value in one of the event data fields (e.g. the maintenance vs. mission indicator in the move events).&lt;br /&gt;
&lt;br /&gt;
* One activity can interfere with another by using&lt;br /&gt;
** priority - (relative priority among b-thread)&lt;br /&gt;
** blocking the events of the other activity (which can be distinguished as described above)&lt;br /&gt;
&lt;br /&gt;
* Distinguishing internal and external events - those generated by the system/application and those generated by the environment (and which may be reported by sensors).&lt;br /&gt;
&lt;br /&gt;
** External events should not be blocked (enforced by convention only).&lt;br /&gt;
** When external events are produced by simulator, the concepts of Logical Execution Time should be enforced by convention, where all internal events reacting to the last external event should be processed before generating the next external event.&lt;br /&gt;
&lt;br /&gt;
= Download =&lt;br /&gt;
== Download the wall painting example ==&lt;br /&gt;
# Click [[Media:Helicopter.zip | here]] to download the wall painting example.&lt;br /&gt;
# Installation Instructions:&lt;br /&gt;
##Import the downloaded project to your workspace:&lt;br /&gt;
###From the 'File' menu choose 'Import'--&amp;amp;gt;'General'--&amp;amp;gt;'Existing Projects into Workspace'.&lt;br /&gt;
###Click the 'Next' button.&lt;br /&gt;
###Click the 'Select archive file' option and then click the 'Browse...' button to select the downloaded zip file.&lt;br /&gt;
###Click 'Finish'.&lt;br /&gt;
##The helicopter example projects are now part of your workspace.&lt;br /&gt;
### The example includes three projects:&lt;br /&gt;
#### BDrone - The main project that includes the b-threads that implement the drawing/scanning tasks.&lt;br /&gt;
#### HeliSim - A simple java-based simulator.&lt;br /&gt;
#### il.ac.wis.cs.rovtool.blender - A blender-based simulator.&lt;br /&gt;
##Refer to the BDrone/HowToRun.txt file for execution instructions.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Tic-Tac-Toe</id>
		<title>Tic-Tac-Toe</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Tic-Tac-Toe"/>
				<updated>2014-04-07T07:35:35Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* Verification Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= A behavioral program for the game of Tic-Tac-Toe =&lt;br /&gt;
&lt;br /&gt;
== Game Description ==&lt;br /&gt;
Two players, X and O, alternately mark squares on a 3X3 grid whose squares are identified by &amp;lt;row,column&amp;gt; pairs: &amp;lt;0,0&amp;gt;, &amp;lt;0,1&amp;gt;, ...,&amp;lt;2,2&amp;gt;. The winner is the player who manages to form a full horizontal, vertical or diagonal line with three of his/her marks.&lt;br /&gt;
If the entire grid becomes marked but no player has formed a line, the result is a draw.&lt;br /&gt;
&lt;br /&gt;
In our example, player X should be played by a human user, and player O is played by the application. Each move (marking of a square by a player) is represented by an event, X_&amp;lt;row,col&amp;gt; or O_&amp;lt;row,col&amp;gt;. Three additional events, XWin, OWin, and draw$, represent the respective victories and a draw.&lt;br /&gt;
&lt;br /&gt;
A play of the game may be described as a sequence of events. E.g., the sequence&lt;br /&gt;
X_&amp;lt;0,0&amp;gt;, O_&amp;lt;1,1&amp;gt;, X_&amp;lt;2,1&amp;gt;, O_&amp;lt;0,2&amp;gt;, X_&amp;lt;2,0&amp;gt;, O_&amp;lt;1,0&amp;gt;, X_&amp;lt;2,2&amp;gt;, XWin  describes a play in which X wins, and whose final configuration is:&lt;br /&gt;
&lt;br /&gt;
[[Image:TTT01.jpg ]]&lt;br /&gt;
&lt;br /&gt;
== b-Threads ==&lt;br /&gt;
Below are listed the b-threads of the application.&lt;br /&gt;
&lt;br /&gt;
=== Rules of the game ===&lt;br /&gt;
* SquareTaken: block further marking of a square already marked by X or O.&lt;br /&gt;
* EnforceTurns: alternately block O moves while waiting for X moves, and vice versa (we assume that X always plays first).&lt;br /&gt;
* DetectXWin: wait for placement of three X marks in a line and request XWin.&lt;br /&gt;
* DetectOWin: wait for placement of three O marks in a line and request OWin.&lt;br /&gt;
* DetectDraw: wait for nine moves and request draw event.&lt;br /&gt;
&lt;br /&gt;
=== Strategies ===&lt;br /&gt;
*DefaultMoves: a b-thread that repeatedly requests all nine possible O moves in the following order of center, corners and edges:  O_&amp;lt;1,1&amp;gt;,O_&amp;lt;0,0&amp;gt;,O_&amp;lt;0,2&amp;gt;,O_&amp;lt;2,0&amp;gt;,O_&amp;lt;2,2&amp;gt;, O_&amp;lt;0,1&amp;gt;,O_&amp;lt;1,0&amp;gt;,O_&amp;lt;1,2&amp;gt;,O_&amp;lt;2,1&amp;gt;.&lt;br /&gt;
*PreventThirdX: when two Xs are noticed in a line, add an O in that line (and prevent an immediate loss).&lt;br /&gt;
*AddThirdO: when two Os are located on a single line,  add a third O (and win).&lt;br /&gt;
*PreventXFork: when two Xs are noticed, in a corner and opposing edge such that X may force a win,  mark an O in the intersection corner of the potential fork, thus preventing its creation.&lt;br /&gt;
*PreventAnotherXFork: when the first two Xs are marked in two opposite corners  and the first O is marked at the center, request O_&amp;lt;0,1&amp;gt;. In the spirit of ``the best defense is a good offense'', this move creates an attack that forces X to play X_&amp;lt;2,1&amp;gt;, and seems to avoid the immediate fork threat.&lt;br /&gt;
*PreventYetAnotherXFork: when two Xs are noticed in two edge squares that are adjacent to a common corner, mark an O in that corner.&lt;br /&gt;
&lt;br /&gt;
== Other Classes ==&lt;br /&gt;
*ExternalApp: The main class of the application. Loads and starts the b-threads&lt;br /&gt;
*GUI: Manages the display&lt;br /&gt;
&lt;br /&gt;
== Design Notes ==&lt;br /&gt;
For some b-threads such as DefaultMoves there is a single instance. Other b-threads, such as AddThirdO are parametric, and there is a separate instance of the b-thread for each ordering of the three events in each row, column and diagonal. Thus, in the present design such b-threads do not maintain a copy of the board, but instead are simply waiting for very specific two events in a given order and responding with other events. Other designs are of course possible&amp;gt; for example a b-thread can be responsible for three events in any order, wait for any two in any order and then request the third. In another design a b-thread can maintain a copy of the board, wait for almost any event, keep track of board configuration changes, look for lines to complete, and request the corresponding move events.&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
# Click [[Media:TicTacToe.zip | here]] to download the tic-tac-toe example.&lt;br /&gt;
# Installation Instructions:&lt;br /&gt;
##Import the downloaded project to your workspace:&lt;br /&gt;
###From the 'File' menu choose 'Import'--&amp;amp;gt;'General'--&amp;amp;gt;'Existing Projects into Workspace'.&lt;br /&gt;
###Click the 'Next' button.&lt;br /&gt;
###Click the 'Select archive file' option and then click the 'Browse...' button to select the downloaded zip file.&lt;br /&gt;
###Click 'Finish'.&lt;br /&gt;
##The tic-tac-toe example project is now part of your workspace.&lt;br /&gt;
##Refer to the readme.txt file for execution instructions.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=BPJ_Programming_Examples</id>
		<title>BPJ Programming Examples</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=BPJ_Programming_Examples"/>
				<updated>2014-04-07T07:29:19Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* BPJ Programming Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= BPJ Programming Examples =&lt;br /&gt;
*[[Water Tap | Alternating Taps]]&lt;br /&gt;
*[[Tic-Tac-Toe | Tic-Tac-Toe]]&lt;br /&gt;
*[[Helicopter flight and mission | Helicopter flight and mission ]]&lt;br /&gt;
*[[Flight of a flock of birds | Simulating flight of a flock of birds]]&lt;br /&gt;
*[[Sudoku | Sudoku]]&lt;br /&gt;
*[[Dining Philosophers | Dining Philosophers]]&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=JavaFlow</id>
		<title>JavaFlow</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=JavaFlow"/>
				<updated>2014-01-16T11:35:03Z</updated>
		
		<summary type="html">&lt;p&gt;BpAdmin: /* Enabling your application for model checking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Enabling your application for model checking=&lt;br /&gt;
In addition to the controls described in earlier sections, there are certain constraints on how the application should be coded to enable model checking.&lt;br /&gt;
BPJ uses the package Javaflow to perform backtracking as needed for model checking. Depending on the run mode, BPJ instruments the application for Javaflow. As part of traversing all possible execution paths, BPJ model checking uses Javaflow for backtracking and saves and restores the thread’s stack using an object called &amp;quot;continuation&amp;quot;. The stack contains the non-static fields/variables from the b-thread class and the variables defined in-line in the runBThread method. Objects (which are not on the stack) are saved and restored by the BPJ model checking using serialization and deserialization of the continuation object. Serialization translates each field and each object pointed to from the continuation into a bit stream. Deserialization turns such bit streams into program objects and fully restores the state.&lt;br /&gt;
&lt;br /&gt;
= Programming Requirement 1=&lt;br /&gt;
When two pointers on the stack point to the same object, Javaflow deserialization creates two copies of the object, and the application that relied on the two being one object no longer works. Therefore,  do not use the operator &amp;quot;==&amp;quot; to compare objects that are part of the b-thread's state. Instead, use the equals() method.  A default equals() method based on object ids already exists for events.&lt;br /&gt;
&lt;br /&gt;
=Programming Requirement 2=&lt;br /&gt;
Serialization and desrialization may significantly slow the application. Therefore, if you have objects that do not change from one bt-state to another,  mark them as transient static (for the class or for the instance, as needed). Objects marked as transient are not processed by serialization and deserialization resets them to their initial value.&lt;br /&gt;
&lt;br /&gt;
=Programming Tip=&lt;br /&gt;
If all the objects pointed to from the stack can be transient as defined above, you  do not have to specify them as transient, and instead you can just specify static, and specify the run time parameter &amp;quot;–Dshallow=true&amp;quot; (the default&lt;br /&gt;
is &amp;quot;-Dshallow=false&amp;quot;). Then, the when BPJ uses Javaflow to save and restore the stack(s) it does not perform serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Dshallow.png | 600px | &amp;lt;span style=&amp;quot;color: rgb(0, 128, 128);&amp;quot;&amp;gt;&amp;lt;span style=&amp;quot;font-family: Tahoma;&amp;quot;&amp;gt; Object serialization&amp;lt;/span&amp;gt; &amp;lt;/span&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
Examine the code snippet below:&lt;br /&gt;
&lt;br /&gt;
   Integer x = new Integer(5);&lt;br /&gt;
   bSync(...)&lt;br /&gt;
   x++;&lt;br /&gt;
   bSync(...)&lt;br /&gt;
&lt;br /&gt;
If -Dshallow=true is specified, in the second visit to the second bSync (after backtracking to try an execution with a different choice of event in the first bSync) the value of X will be 7, because X was not restored. Solution:  Use int and not Integer - and then the variable is on the stack, and is always restored with backtracking, or use&lt;br /&gt;
-Dshallow=false, to force full serialization.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=BPmcAPI</id>
		<title>BPmcAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=BPmcAPI"/>
				<updated>2014-01-16T05:24:30Z</updated>
		
		<summary type="html">&lt;p&gt;BpAdmin: /* BPJ Model Checking API: Enabling your application for model-checking and controlling its verification */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Enabling your application for model-checking and controlling its verification =&lt;br /&gt;
&lt;br /&gt;
Before verifying an application, the application must be enabled for model checking.&lt;br /&gt;
This includes at least:&lt;br /&gt;
* Creating b-threads which simulate the environment, when applicable.&lt;br /&gt;
* Assigning names to states&lt;br /&gt;
* Determining alternative execution paths - by identifying equal priority b-threads and equal priority event requests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
B-threads can call the following API methods of the BProgram where the b-thread is added/registered&lt;br /&gt;
to control the model checking.&lt;br /&gt;
&lt;br /&gt;
Throughout, the term Next Verification State refers to the applictation's (composite) state at next synchronization point, when all b-threads are synchronized.&lt;br /&gt;
&lt;br /&gt;
== bSync(none,none,none)==&lt;br /&gt;
While in regular runs a b-thread can terminate, in a model-checking run a b-thread should not terminate. You should precede or replace the return from runBthread method with a call to bSync(none,none,none). In a regular run this call will cause normal terminatation of the b-thread but in a model checking run it will suspend the b-thread in a state prior to terminating and allow backtracking from this state.&lt;br /&gt;
&lt;br /&gt;
== labelNextVerificationState(&amp;lt;label&amp;gt;)==&lt;br /&gt;
This API calls provides a label for the next b-thread state and indirectly to the next composite system state.&lt;br /&gt;
&lt;br /&gt;
* It is the programmer's responsibility to disambiguate all relevant b-thread states of each relevant b-thread.&lt;br /&gt;
* The (composite) BP-state name is the concatenation all constituent bt-states.&lt;br /&gt;
* When BPJ model checking reaches a BP-state that was already fully checked – it backtracks.&lt;br /&gt;
* If a b-thread does not label its states – it is considered to have one state – and it does not increase the size of the Cartesian product. E.g. a b-thread that only counts events theoretically has infinitely many states. However, if this b-thread is known to never request or block events, it cannot affect the application flow, and if the counts do not matter in the counterexamples, there is no need to keep track of its exact state during back tracking.&lt;br /&gt;
* A b-thread that incorrectly gives the same label to different states, may cause incorrect model-checking results.&lt;br /&gt;
* Meaningful state names can help in debugging, but since since most b-threads are simple this is not critical. E.g., the states of a &amp;quot;linear&amp;quot; b-thread can be just numbered as 1/2/3 etc. The states of a b-thread can be labeled also based on the values of the variables that determine the state change.&lt;br /&gt;
* State names are local to the b-thread and must be unique only within a b-thread. The BPJ model checking infrastructure properly distinguishes state 1 of b-thread BT1, from state 1 of b-thread BT2.&lt;br /&gt;
&lt;br /&gt;
== markNextVerificationStateAsBad()==&lt;br /&gt;
Indicates detection by the b-thread of a violation of a safety property. Model checking stops and prints the sequence of events (the path) to this point as a counter example.&lt;br /&gt;
== markNextVerificationStateAsHot()==&lt;br /&gt;
This call is used for checking of liveness properties. States that are not marked as hot are considered cold. If  the model checking detects a cycle in the state graph that does not contain a cold state, it stops and prints the path to this cycle and the cycle as a counter example.&lt;br /&gt;
== pruneSearchNow()==&lt;br /&gt;
This forces backtracking immediately, possibly stopping other b-threads and possibly before the badness of the next state is determined. This call can be used by a b-thread to accelerate the model checking by eliminating states that weren't explored, but are known to lead to results that are known or are symmetric to other states, or are otherwise not relevant in the present run.&lt;br /&gt;
== pruneAtNextVerificationState()==&lt;br /&gt;
This call forces backtracking after all b-threads reach the next state and after its badness is determined.&lt;br /&gt;
&lt;br /&gt;
== setBThreadEpsilon(&amp;lt;double epsilon&amp;gt;) ==&lt;br /&gt;
This call defines nondeterminism between b-threads. By default all b-threads are strictly ordered according to distinct priorities. If this call is used to set the &amp;quot;epsilon&amp;quot; to a value greater than zero, any two b-threads whose priorities differ by less than this value, are considered to be of the same priority, for the purpose of nondeterministic execution, backtracking and exploration of alternative execution paths.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	<entry>
		<id>https://wiki.weizmann.ac.il/bp/index.php?title=Z3BP</id>
		<title>Z3BP</title>
		<link rel="alternate" type="text/html" href="https://wiki.weizmann.ac.il/bp/index.php?title=Z3BP"/>
				<updated>2014-01-16T05:01:05Z</updated>
		
		<summary type="html">&lt;p&gt;Assaf: /* Verifying your application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Verifying behavioral programs with the Z3 Theorem Prover / SMT Solver =&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
* See [http://www.wisdom.weizmann.ac.il/~bprogram/emsoft13 reference materials ]&lt;br /&gt;
* Required Environment: Windows 7, Eclipse.&lt;br /&gt;
* Install latest version of Z3 from Z3 Web Site (at the time of writing this page the version is 4.1). Note that the software is under a Microsoft Research folder.&lt;br /&gt;
* Install Python version 2.7.3 from Python web site. Presently the latest version of Z3 does not support the latest version of Python version. The following instructions assume that you have installed Python into C:\Python27\ on your computer.&lt;br /&gt;
* Install PyDev from Pydev web site as follows: find and copy the link for PyDev Eclipse plugin. Open Eclipse. Click &amp;quot;help&amp;quot; and &amp;quot;install new software&amp;quot;. Add the plugin location and install. During installation check and approve the certificate trust.&lt;br /&gt;
* Create a Z3 project. Eclipse -&amp;gt; &amp;quot;file&amp;quot; -&amp;gt; &amp;quot;import project&amp;quot; -&amp;gt;  &amp;quot;general&amp;quot; -&amp;gt;  &amp;quot;existing  project into workspace&amp;quot; (do not copy into workspace). The project will be marked red.&lt;br /&gt;
* Define Interpreter: In Eclipse, open PyDev perspective, right click on the project, select &amp;quot;properties&amp;quot; and then &amp;quot;python interpreter&amp;quot;. Define as   C:\Python27\python.exe.&lt;br /&gt;
* Define PYTHONPATH: In Eclipse: Select &amp;quot;Window&amp;quot; -&amp;gt; &amp;quot;Preferences&amp;quot; -&amp;gt; &amp;quot;PyDev&amp;quot; -&amp;gt; &amp;quot;Interpreter PYTHON&amp;quot;   -&amp;gt; &amp;quot;PYTHONPATH&amp;quot; -&amp;gt; &amp;quot;New Folder&amp;quot;. Add to  the Python path the Python folder within Z3, e.g., C:\Program Files (x86)\Microsoft Research\Z3-4.1\python.&lt;br /&gt;
* Define Windows Path: Add to windows system path variable the bin folder of z3 C:\Program Files (x86)\Microsoft Research\Z3-4.1\bin.&lt;br /&gt;
* Change appearance: In Eclipse, select &amp;quot;Window&amp;quot; -&amp;gt; &amp;quot;Preferences&amp;quot; -&amp;gt; &amp;quot;PyDev&amp;quot;  -&amp;gt; &amp;quot;Editor&amp;quot; (click on it)  -&amp;gt;  &amp;quot;Aptana themes&amp;quot; -&amp;gt; &amp;quot;Eclipse&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Verifying your application ==&lt;br /&gt;
* See Z3 information for Z3 syntax and its Python interface.&lt;br /&gt;
* See examples in the provided project how to define b-thread properties.&lt;br /&gt;
* Modify the example, introducing new b-thread properties, but preserving BP composition properties.&lt;br /&gt;
* Run the model.&lt;/div&gt;</summary>
		<author><name>Assaf</name></author>	</entry>

	</feed>