{"id":596,"date":"2022-04-05T14:28:21","date_gmt":"2022-04-05T13:28:21","guid":{"rendered":"http:\/\/perf.unime.it\/magnet\/?page_id=596"},"modified":"2022-04-13T18:59:21","modified_gmt":"2022-04-13T17:59:21","slug":"model-creation","status":"publish","type":"page","link":"http:\/\/perf.unime.it\/magnet\/?page_id=596","title":{"rendered":"Model creation"},"content":{"rendered":"\n<p>An empty model has to be created as first step.<\/p>\n\n\n\n<pre id=\"NewModel\" class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>M3AM *m3am_NewModel(const char *label, SpaceDim dimension)<\/strong><\/code><\/pre>\n\n\n\n<p>The new created model is referenced throughout the reference returned by <code>m3am_NewModel<\/code> function. The string parameter <code>label<\/code> set the name of the model. Parameter <code>dimension<\/code> sets the space dimension of the space where the agents in the model will be deployed. The function returns a pointer to be used for referencing the model in all the other functions.<\/p>\n\n\n\n<p style=\"line-height:1.5\">The following code create an empty model over a 2D space:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-medium-font-size\"><code>#include \"magnet.h\"\n\nM3AM *myModel;\nmyModel=m3am_NewModel(\"My_Markovian_Agent_model\", 2);<\/code><\/pre>\n\n\n\n<p>When a new M3AM model has been instantiated all the other objects have to be created into the model. The following functions are used to this aim.<\/p>\n\n\n\n<p id=\"NewClass\"> <br><\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_NewClass(M3AM *model, char *label, NumStates states);<\/strong><\/code><\/pre>\n\n\n\n<p>The <code>m3am_NewClass<\/code> function add a new class in the model <code>model<\/code> with the name <code>label<\/code>. The number of states in the class is set to <code>states<\/code>. The error code <code>NOERR<\/code> is returned if the class is correctly created otherwise it evaluates to one of the codes in the error code table.                       <br>Probability of state 0 is set to 1.0 and the probabilities of all the other states are set to 0.0 when the class is created. The probability vector in the class is assumed the initial probability vector of Markovian agents belonging to the class.                       <br>Returned values are as in the following:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>EMEM<\/td><td>memory allocation error<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p id=\"AddInitProb\">\n                      <br>\n                    <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_AddInitProb(M3AM *model, const char *class_label, NumStates s, double val);<\/strong><\/code><\/pre>\n\n\n\n<p><code>m3am_AddInitProb<\/code> is used to set\/change the initial probability vector of a class by setting to <code>val<\/code> the probability of state <code>s<\/code>; the class is identified by name to <code>class_label<\/code>, in a properly defined models referred by <code>model<\/code>. It is user responsibility to guarantee that of all the values in the vector sum to 1.0<br>Returned values are as in the following :<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>ENOCL<\/td><td>the class name does not exist<\/td><\/tr><tr><td>EORANGE<\/td><td>probability vale out of range<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p id=\"AddLocTr\">\n                      <br>\n                    <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_AddLocTr(M3AM *model, const char *class_label, NumStates r, NumStates c, Rate val);<\/strong><\/code><\/pre>\n\n\n\n<p><code>m3am_AddLocTr<\/code> sets to <code>val<\/code> the transition rate from state <code>r<\/code> to state <code>c<\/code> of the Markovian agents in class <code>class_label<\/code> of the model referenced by <code>model<\/code>. Transition rates from a state to itself are forbidden (self loops are set with <code>AddSelfLoop<\/code>).                       <br>Returned values are as in the following :<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>EXIT_FAILURE<\/td><td>r is equal to c<\/td><\/tr><tr><td>ENOCL<\/td><td>class name does not exist<\/td><\/tr><tr><td>EORANGE<\/td><td>the rate value is negative<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p id=\"AddSelfLoop\">\n                      <br>\n                    <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_AddSelfLoop(M3AM *model, const char *class_label, NumStates s, Rate val);<\/strong><\/code><\/pre>\n\n\n\n<p><code>m3am_AddSelfLoop<\/code> adds the self loop rate associated to the state <code>s<\/code> of Markovian agents belonging to the class <code>class_label<\/code> in the model referenced by <code>model<\/code>. If a self loop rate has been defined before, it will be changed to <code>val<\/code>.<br>Returned values are as in the following:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>ENOCL<\/td><td>the class name does not exist<\/td><\/tr><tr><td>EORANGE<\/td><td>the rate value is negative<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p id=\"NewMSG\">\n                      <br>\n                    <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_NewMSG(M3AM *model, const char *message_label);<\/strong><\/code><\/pre>\n\n\n\n<p><code>m3am_NewMSG<\/code> adds a new message with name <code>message_label<\/code> to the model referenced by <code>model<\/code>. If the message is already defined in the model, it will return an error code.<br>Returned values are as in the following:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>EMEM<\/td><td>memory allocation error<\/td><\/tr><tr><td>ENOOP<\/td><td>operation not allowed; the message exists<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p id=\"AddMsgGenProb\">\n                      <br>\n                    <\/p>\n\n\n\n<pre id=\"MsgGenP\" class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_AddMsgGenProb(M3AM *model, const char *class_label, const char *message_label, NumStates r, NumStates c, Probability val);<\/strong><\/code><\/pre>\n\n\n\n<p><code>m3am_AddMsgGenProb<\/code> sets to <code>val<\/code> the probability that a Markovian agent belonging to the class <code>class_label<\/code> of the model referenced by <code>model<\/code> generates a message <code>message_label<\/code> when transiting from state <code>r<\/code> to state <code>c<\/code>. A valid probability value must be used. Probability values to generate messages when a Markovian agents outgoes from a state cannot exceed 1.0; this latter constrain is kept internally consistent, and if the <code>val<\/code> value brakes the internal consistency, an error will be returned and the value will not bet set. If either <code>class_label<\/code> class or <code>message_label<\/code> message are not defined an error code is returned.                       <br>Returned values are as in the following:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>EORANGE<\/td><td>probability value out of range<\/td><\/tr><tr><td>ENOPR<\/td><td>inconsistent probability value<\/td><\/tr><tr><td>ENOCL<\/td><td>class name does not exist<\/td><\/tr><tr><td>ENOMES<\/td><td>message name does not exist<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p id=\"AddMsgAccProb\">\n                      <br>\n                    <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:18px\"><code><strong>Error m3am_AddMsgAccProb(M3AM *model, const char *class_label, const char *message_label, NumStates r, NumStates c, double val);<\/strong><\/code><\/pre>\n\n\n\n<p><code>m3am_AddMsgAccProb<\/code> sets to <code>val<\/code> the probability that a Markovian agent belonging to the class <code>class_label<\/code> of the model referenced by <code>model<\/code> has a transition from state <code>r<\/code> to state <code>c<\/code> due to a perceived message <code>message_label<\/code>. A valid probability value must be used. Sum of all probabilities to have a transition from state <code>r<\/code> due to the same <code>message_label<\/code> cannot exceed 1.0; this latter constrain is kept internally consistent, and if the <code>val<\/code> value brakes the internal consistency, an error will be returned and the value will not bet set. Only values for <code>r <\/code>different from <code>c<\/code> make sense, thus an error code will be returned if an attempt to set it is done. If either <code>class_label<\/code> class or <code>message_label<\/code> message are not defined an error code is returned.<br>Returned values are as in the following:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td>NOERR<\/td><td>no error<\/td><\/tr><tr><td>EXIT_FAILURE<\/td><td>r is equal to c<\/td><\/tr><tr><td>EORANGE<\/td><td>probability value out of range<\/td><\/tr><tr><td>ENOPR<\/td><td>inconsistent probability value<\/td><\/tr><tr><td>ENOCL<\/td><td>class name does not exist<\/td><\/tr><tr><td>ENOMES<\/td><td>message name does not exist<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-a89b3969 wp-block-buttons-is-layout-flex\">\n\n\n\n\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-white-color has-cyan-bluish-gray-background-color has-text-color has-background\" href=\"http:\/\/perf.unime.it\/magnet\/?page_id=24\" style=\"border-radius:25px\">Prev<\/a><\/div>\n\n\n\n\n\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-white-color has-cyan-bluish-gray-background-color has-text-color has-background\" href=\"http:\/\/perf.unime.it\/magnet\/?page_id=604\" style=\"border-radius:25px\">Next<\/a><\/div>\n\n\n<\/div>\n\n\n\n<p><br>                     <\/p>\n","protected":false},"excerpt":{"rendered":"<p>An empty model has to be created as first step. The new created model is referenced throughout the reference returned by m3am_NewModel [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-596","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=\/wp\/v2\/pages\/596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=596"}],"version-history":[{"count":16,"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=\/wp\/v2\/pages\/596\/revisions"}],"predecessor-version":[{"id":746,"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=\/wp\/v2\/pages\/596\/revisions\/746"}],"wp:attachment":[{"href":"http:\/\/perf.unime.it\/magnet\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}