

{"id":80,"date":"2020-03-11T11:21:01","date_gmt":"2020-03-11T10:21:01","guid":{"rendered":"https:\/\/project.inria.fr\/fiatlux\/?page_id=80"},"modified":"2020-04-13T13:54:42","modified_gmt":"2020-04-13T11:54:42","slug":"developer-guide","status":"publish","type":"page","link":"https:\/\/project.inria.fr\/fiatlux\/developer-guide\/","title":{"rendered":"Indications for developers"},"content":{"rendered":"<p>Download the indications in pdf: <a href=\"https:\/\/project.inria.fr\/fiatlux\/files\/2020\/04\/FiatLux_Developers_ENG.pdf\">Click here<\/a>.<\/p>\n<h1 id=\"use-case\">Use case<\/h1>\n<h2 id=\"creating-a-model\">Creating a model<\/h2>\n<h3 id=\"implementation-of-the-model\"><span class=\"collapseomatic \" id=\"id69f048c6b2da2\"  tabindex=\"0\" title=\"Implementation of the model&lt;\/h3&gt;\n&lt;p&gt;\"    >Implementation of the model<\/h3>\n<p><\/span><div id=\"target-id69f048c6b2da2\" class=\"collapseomatic_content \">\n<figure>\n<img decoding=\"async\" src=\"https:\/\/project.inria.fr\/fiatlux\/files\/2020\/04\/light.png\" id=\"fig:light\" alt=\"\" \/><figcaption>Structure : Implementation of a model (simplified)<span class=\"hide\" label=\"fig:light\"><\/span><\/figcaption><\/figure>\n<h6 id=\"section\"><\/h6>\n<p>At the start, you need to develop a class which will contain the model\u2019s methods. The package <code>models<\/code> are exclusively created for this and contain packages for each complex system type. Chose the most convenient package for your model. We recommend you create your own package in the ones you took for your model to clarify the hierarchy of the code\u2019s application but this\u2019s not obligatory.<\/p>\n<h6 id=\"section-1\"><\/h6>\n<p>The name of the class\u2019s model must be like <code>NameOfTheCellularAutomatonModel.java<\/code> with no space, uppercase for each word and finish with \u201c-Model\u201d. The class will need to extend the type of model\u2019s class. You will find this class in the <code>CAmodels<\/code> package. The most used one is <code>ClassicalModel<\/code> but there are the other\u2019s as well.<\/p>\n<h6 id=\"section-2\"><\/h6>\n<p>For every model you must define a name. It\u2019s important because this variable will serve as a unique reference to the model. Use the same rules than before without the \u201c-Model\u201d termination:<\/p>\n<pre data-frame=\"single\"><code>public static final String NAME = &quot;NameOfTheCellularAutomaton&quot;;<\/code><\/pre>\n<h4 id=\"classical-cellular-automatas-model-implementation\">Classical cellular automata\u2019s model implementation<\/h4>\n<h6 id=\"applylocalfunction\">ApplyLocalFunction<\/h6>\n<p><code>ClassicalModel<\/code> extends <code>CellularModel<\/code> and is the model this uses <code>OneRegisterIntCell<\/code>. <code>OneRegisterIntCell<\/code> is a cell\u2019s type whose state is defined by an integer. ClassicalModel implements the method <code>ApplyLocalFunction(OneRegisterIntCell in_Cell)<\/code> which returns an integer : the following state of the cell.<\/p>\n<h6 id=\"section-3\"><\/h6>\n<p>This is the first function you must define in your model. The object <code>OneRegisterIntCell<\/code> contains methods to read the neighbourhood state and the state of the cell itself. With this data you can implement in this function the update of the cells.<\/p>\n<pre data-frame=\"single\"><code>@Override\r\npublic int ApplyLocalFunction(OneRegisterIntCell in_Cell) {\r\n    \/\/ Your function ... \r\n    return intNextState;\r\n}<\/code><\/pre>\n<h6 id=\"getdefaultinitializer\">GetDefaultInitializer<\/h6>\n<p>The second method you must define is <code>GetDefaultInitializer()<\/code> where you will choose the initializer of your model. Just instantiate the one this you wish and return this instance.\n<\/p>\n<h6 id=\"section-4\"><\/h6>\n<p>In the case where you are modelling a binary cellular automaton this\u2019s all you will need. But if you want to implement more specific behavior, you must use different palettes and viewers.<\/p>\n<h5 id=\"palette\">Palette<\/h5>\n<h6 id=\"section-5\"><\/h6>\n<p>The color of the simulation is managed by <code>PaintToolKit<\/code>. Many colors stack are already in the application you can choose the one you want for your model by overwriting the <code>GetPalette()<\/code> method in your model. In this function you need to instantiate a color\u2019s stack with <code>PaintToolKit.GetThePaletteYouWant(parameters)<\/code> and define some color if you want (Particularly the 0 state if you want a rule special for it. For example turn it white like most of the cellular automata).<\/p>\n<h6 id=\"section-6\"><\/h6>\n<p>Here an example with the Rainbow palette but you can found others in the section <code>PaintToolKit<\/code>.<\/p>\n<pre data-frame=\"single\"><code>@Override\r\npublic PaintToolKit GetPalette() {\r\n    PaintToolKit palette= PaintToolKit.GetRainbow(256);\r\n    palette.SetColor(0, FLColor.c_black);\r\n    return palette;\r\n}<\/code><\/pre>\n<h4 id=\"use-the-model\">Use the model<\/h4>\n<h6 id=\"section-7\"><\/h6>\n<p>The model is now usable by command-line but if you want it to appear in the menu you need to register it in the tables of the app. For that, in the package <code>main<\/code>&gt;<code>tables<\/code> there is a class named <code>MODEL_TABLE<\/code> which list the different model you can use in the app. In the method <code>FillTable()<\/code> you have to add your model in the list with the command line with the others in the section you\u2019ll find the more appropriate:\n<\/p>\n<pre data-frame=\"single\"><code>AddList(NameOfTheCellularAutomatonModel.class);<\/code><\/pre>\n<h6 id=\"section-8\"><\/h6>\n<p>Your will find that the list is stratified by the method <code>AddSeparator()<\/code> which add a strait line in the menu as a separator. And by the line <code>m_modelType = MT.*TypeOfModel*<\/code> this one separate the list into other tabs in the menu. Choose the most convenient tabs and add separators if you wish in order to keep the menu tidy.<\/p>\n<\/div>\n<h1 id=\"structure\">Structure<\/h1>\n<h6 id=\"section-9\"><\/h6>\n<p>To implement a model, in addition to the rule to be developed as above, it is necessary to use viewer and initializer classes in order to be able to employ it in the software. The hierarchy of these classes is explained here.<\/p>\n<h3 id=\"viewer\"><span class=\"collapseomatic \" id=\"id69f048c6b2de0\"  tabindex=\"0\" title=\"Viewer&lt;\/h3&gt;\n&lt;p&gt;\"    >Viewer<\/h3>\n<p><\/span><div id=\"target-id69f048c6b2de0\" class=\"collapseomatic_content \">\n<figure>\n<img decoding=\"async\" src=\"https:\/\/project.inria.fr\/fiatlux\/files\/2020\/04\/viewers.jpg\" id=\"fig:viewers\" alt=\"\" \/><figcaption>Class diagram : Viewers hierarchy (simplified)<span class=\"hide\" label=\"fig:viewers\"><\/span><\/figcaption><\/figure>\n<h6 id=\"section-10\"><\/h6>\n<p>The <code>Viewers<\/code> objects manage the table of cells. This table contains all the cells of the simulation with their values and methods. It also manage the grid view of the simulations. Like the size of the cells, the distribution of the colors, the border of the cells or theirs specials effect visualization. There are four hierarchical levels presented here from the higher to the specifier.<\/p>\n<h4 id=\"automatonviewer\">AutomatonViewer<\/h4>\n<h6 id=\"section-11\"><\/h6>\n<p>The abstract class <code>AutomatonViewer<\/code> contains the most general methods about the display of the grid. It extends <code>JComponent<\/code><a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\" role=\"doc-noteref\"><sup>1<\/sup><\/a> it is the most elevated hierarchical level. It associates a palette to each viewer.<\/p>\n<h6 id=\"section-12\"><\/h6>\n<p>The abstract method <code>GetXYWindowsSize()<\/code> needs to be defined by inheritance. This method must return a couple of int which contains the size of the window\u2019s panel in pixels in the form of a <code>IntC<\/code>.<\/p>\n<h4 id=\"gridviewer\">GridViewer<\/h4>\n<h6 id=\"section-13\"><\/h6>\n<p>This abstract class defines the methods which display the components of the grid in the <code>paintComponent()<\/code>, which cannot be overwritten. The class also contains the variables about the grid:<\/p>\n<dl>\n<dt>m_XYsize:<\/dt>\n<dd>\n<p>the grid size (in number of cells).<\/p>\n<\/dd>\n<dt>m_CellDist:<\/dt>\n<dd>\n<p>an integer for the distance between two cells.<\/p>\n<\/dd>\n<dt>m_SquareSize:<\/dt>\n<dd>\n<p>an integer which represents the size of the cells.<\/p>\n<\/dd>\n<dt>m_square:<\/dt>\n<dd>\n<p>a two-dimensional table of java\u2019s Rectangle class<a href=\"#fn2\" class=\"footnote-ref\" id=\"fnref2\" role=\"doc-noteref\"><sup>2<\/sup><\/a> which will be used to draw the grid.<\/p>\n<\/dd>\n<\/dl>\n<h6 id=\"section-14\">\n<\/h6>\n<p>The constructor of the class requires two parameters:<\/p>\n<ul>\n<li>\n<p>A couple of int which contains the size of the cells, in pixels, in an <code>IntC<\/code>.<\/p>\n<\/li>\n<li>\n<p>The size of the grid in number of cells. An <code>IntC<\/code> or a <code>GridSystem<\/code> can be used.<\/p>\n<\/li>\n<\/ul>\n<h6 id=\"section-15\"><\/h6>\n<p>The abstract method <code>DrawSystemState()<\/code> must be defined in an inherited class in order to display the type of grid (the space of the automaton) and other objects into the simulation (for example the direction of the cell or the stability point).<\/p>\n<h4 id=\"regularautomationviewer\">RegularAutomationViewer<\/h4>\n<h6 id=\"section-16\"><\/h6>\n<p>Last abstract class of the hierarchy which implements the usage of the colours, a display of a grid system and the stability point in overriding the method <code>DrawSystemState()<\/code>. This class is used to be inherited by the regular cellular automata viewers which don\u2019t contain any particular rules. There is two abstract methods to define here: <code>GetCellColorNumXY()<\/code>, that must return an int for colour id within parameters two int which are the X and Y position of the cell. <code>IsStableXY()<\/code> must return a boolean: true if the state\u2019s cell is stable and will not be changed the next time step and false if the cell can be changed. With parameters two int X and Y again for position.<\/p>\n<h4 id=\"oneregisterautomatonviewer\">OneRegisterAutomatonViewer<\/h4>\n<h6 id=\"section-17\"><\/h6>\n<p>This class is used for the cellular automata of type <code>OneRegisterIntCellularAutomataModel<\/code>. It implements the MouseInteractive interface in order to update directly some cell by the viewer. <code>GetColorNumXY()<\/code> and <code>IsStableXY()<\/code> are defined.<\/p>\n<h4 id=\"multiregisterautomatonviewer\">MultiRegisterAutomatonViewer<\/h4>\n<h6 id=\"section-18\"><\/h6>\n<p>This abstract class is used for the cellular automata of type <code>MultiRegisterIntCellularAutomataModel<\/code>. It implements methods for the <code>MultiRegisterCell<\/code>\u2019s manage like <code>GetCell()<\/code>, <code>SetState()<\/code> A and B and <code>GetStateXY()<\/code> for the first and the second int (respectively named A and B).<\/p>\n<\/div>\n<h3 id=\"initializer\"><span class=\"collapseomatic \" id=\"id69f048c6b2df8\"  tabindex=\"0\" title=\"Initializer&lt;\/h3&gt;\n&lt;p&gt;\"    >Initializer<\/h3>\n<p><\/span><div id=\"target-id69f048c6b2df8\" class=\"collapseomatic_content \">\n<figure>\n<img decoding=\"async\" src=\"https:\/\/project.inria.fr\/fiatlux\/files\/2020\/04\/initializers.jpg\" id=\"fig:initializer\" alt=\"\" \/><figcaption>Class diagram : Initializers hierarchy (simplified)<span class=\"hide\" label=\"fig:initializer\"><\/span><\/figcaption><\/figure>\n<h6 id=\"section-19\"><\/h6>\n<h4 id=\"superinitializer\">SuperInitializer<\/h4>\n<h6 id=\"section-20\"><\/h6>\n<p><code>SuperInitializer<\/code> is the most elevated level of the initializers. It contains a signal managers\u2019 method <code>ReceiveSignal()<\/code>. Which essentially call the abstract function that need to be defined in the inherited class <code>SubInit()<\/code> and <code>PreInit ()<\/code>called in this order.<\/p>\n<h6 id=\"section-21\"><\/h6>\n<p>This methods are called in the order <code>PreInit()<\/code> and after <code>SubInit()<\/code>. The first one is used to prepare what you require before the initiation. The second one must contain the code of the proper initiation.<\/p>\n<h6 id=\"section-22\"><\/h6>\n<p>If needed the functions <code>sig_NextStep()<\/code> and <code>sigUpdate()<\/code> can be overridden.<\/p>\n<h4 id=\"arrayinitializer\">ArrayInitializer<\/h4>\n<h6 id=\"section-23\"><\/h6>\n<p><code>ArrayInitializer<\/code> is an abstract class than define <code>PreInit()<\/code> and verify if an error has occurred during the initiation. But most importantly, it defines the method <code>MainLinkTo()<\/code> which will link these two parameters: a <code>RegularDynArray<\/code> which represents the core of a cellular automaton. Literally only a one-dimensional table containing cells (link ref RegularDynArray to-do) and a topology (inherited from <code>SuperTopology<\/code>). With that function a table of cells and the strategy to read it will be linked.<\/p>\n<h6 id=\"section-24\"><\/h6>\n<p>This class also contains an abstract method to manage the array like <code>GetSize()<\/code>, <code>GetCell()<\/code> and <code>RandomPos()<\/code> which return, in order, the size of the table, the cell at the position given (in an int parameter) and an arbitrary position in the table.<\/p>\n<h4 id=\"oneregisterinitializer\">OneRegisterInitializer<\/h4>\n<h6 id=\"section-25\"><\/h6>\n<p>This abstract class is used for the cellular automata of type <code>OneRegisterIntCellularAutomataModel<\/code>. It defined the method <code>LinkTo()<\/code> and provides method to use the cell table like <code>ClearArray()<\/code>. It also implemented Get and Set method specific to 2D automata.<\/p>\n<h4 id=\"multiregisterintinitializer\">MultiRegisterIntInitializer<\/h4>\n<h6 id=\"section-26\"><\/h6>\n<p>This abstract class is used for the cellular automata of type <code>MultiRegisterIntCellularAutomataModel<\/code>. It doesn\u2019t define the method <code>LinkTo()<\/code>, so the method must be overridden if need to be used. The class implemented Get and Set method for the position I (an int parameter).<\/p>\n<\/div>\n<section class=\"footnotes\" role=\"doc-endnotes\">\n<hr \/>\n<ol>\n<li id=\"fn1\" role=\"doc-endnote\">\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JComponent.html\">https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JComponent.html<\/a><a href=\"#fnref1\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9\ufe0e<\/a><\/p>\n<\/li>\n<li id=\"fn2\" role=\"doc-endnote\">\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/Rectangle.html\">https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/Rectangle.html<\/a><a href=\"#fnref2\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9\ufe0e<\/a><\/p>\n<\/li>\n<\/ol>\n<\/section>\n<p><\/body><br \/>\n<\/html><br \/>","protected":false},"excerpt":{"rendered":"<p> <a class=\"continue-reading-link\" href=\"https:\/\/project.inria.fr\/fiatlux\/developer-guide\/\"><span><\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":1793,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-80","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/pages\/80","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/users\/1793"}],"replies":[{"embeddable":true,"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":9,"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/pages\/80\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/pages\/80\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/project.inria.fr\/fiatlux\/wp-json\/wp\/v2\/media?parent=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}