• No results found

5.4 The resulting TiC

5.4.3 Mapping between language concepts and NetLogo

In this section we describe how the XText grammar in general, and the AiC XText description in particular can be transformed to the NetLogo language.

Before moving to the actual implementation, we first explain how the transformation of each concept of the language will be transformed into NetLogo. In our language, the concepts manipulated are: Variables, actors, actions and levels. These are the concepts that will be transformed.

Variable

The domain specific AiC language has two types of variables: (1) global variables rep- resented by the word Variable which can be accessible by all agents and can be used anywhere in a model. If a variable is a global variable, there is only one value for the variable, and every agent can access it. (2) local variables represented by the word

iAttribute referenced locally in relation to the function used. The iAttribute variables

represent in our model the specific parameters that characterize the state of a rule. More precisely, they represent the set of values to be taken as inputs by the rule to facilitate its construction. For an actor, they can represent gender, age, number of people in the household, needs, purpose, ect. For an action they represent the variables to be used in the action for its execution. For a level, they represent the dimensions, the size of its population, ect.

The steps for transforming a variable of our language to NetLogo involves the following steps:

1. For global variables at the beginning of the program before any function declaration. Define their name in brackets preceded by the word "globals" before the brackets, each name being separated from each other by a space. Thus we have the following transformation:

---AiC Language---|---NetLogo language---

(’ModelVariable’ ’:’(Variable+=ID’,’)*)? −→ globals[ID1 ID2 ID3 .. IDn]

2. For local variable, define their name preceded by the word "let" and the name is followed by an initialization value which thereby gives the type of the variable. Thus we have the following transformation:

---AiC Language---|---NetLogo language---

(LevelID=EString)? ’(’(iAttribute+=ID)*’)’ −→ LevelID [ID1 ID2 ID3 .. IDn]

5.4. THE RESULTING TIC 63

Note that NetLogo does not give the variable’s type in its declaration. Thus the type of a variable is given by the type of value of the first initialization.

Level

As we presented in the analysis phase, a level is represented by a set of actors. In our transformation to NetLogo, this level may represent, as the case as a set of patch, agent or link followed by all its characteristics. Thus we have the following transformation:

---AiC Language---|---NetLogo language---

(LevelID=EString)?’(’(iAttribute+=ID)*’)’−→breed[Level LevelID]

Level-own[iAttribute]

Action

Concerning the Actions, we define according to each language concepts functions for creating and transforming these concepts in NetLogo. Thus the concept Action concern the dependant attributes of Actor will be transformed as the functions performed by an agent. Their transformation will be in the following steps:

1. For each concept, changed the attributes concept into local parameters

2. Then transformed each concept into function using as parameter attributes trans- formed previously.

3. Transforming the dependant attributes of actor in NetLogo functions.

Thus each of the actions will be transformed as a function requiring a quantity of resource type (Capitals) and return (produces) a value which will be qualified as the gain of the action. The actions in our model involve all the variables that precede the patterns "has-option" or "has-chose". Thus an action transformed into NetLogo will be represented as the function above.

to-report ActionID [iAttribute] ...

end

Actor

This concept is the key concept of our model. Because it is at the center of transformation. Thus, as shown in figure 5.4 of the agent metamodel schema in NetLogo, we will transform our AiC actor into a NetLogo agent while focusing on the different characteristics of the metamodel.

An actor is seen as an agent with a utility function linking his perceptions and actions to the environment. The AiC model also highlights the concepts of environment, perception, beliefs, interface and neighborhood. A perception is a cognitive event that occurs in the environment and that an actor or object may experience the impact. A belief represents all the information the agent holds about his environment. The interface represents the list of actions that the agent can perform. It is built on the feasible actions of the actors model. Indeed, the perceptions and beliefs of the agent are elaborated respectively from the options and motivations of the actor model. The neighborhood concept that is not explicitly present in the meta-model depends on the problem, the objectives and the behavior of the actors described by the actions of the PiC model.

The processing steps of transformation of Actor to NetLogo agent are:

Figure 5.4: Agent metamodel in NetLogo

’Actor’(ActorID=EString)−→ breed[Actor ActorID]

2. Transform the attributes of actor to the variable of concerned agent.

’Actor’(ActorID=EString)’(’iAttribute+=ID’)’−→ Actor-own [iAttribute]

3. Create the agent and initialize its various properties

create-actor size [initialize the iAttribute here]

In our model, we encapsulate this creation in a function in order to better take into account all the parameters and useful properties of the agent.

The rest of the properties that characterize the actor are transformed as follows:

• The property of the actor "has-option" is transformed as perception of the NetLogo agent.

• The property of the actor "influence" is transformed into the belief of the NetLogo agent.

• The property of the actor "has-chose" is transformed into an interface of the NetLogo agent.

Furthermore, note that the agent link will be use to create governance relationships between different levels and different classes of agents.

All these characteristics allow us to easily transform the AiC actor into a NetLogo agent according to the NetLogo agent metamodel.

5.4. THE RESULTING TIC 65

Algorithm 1 Agentification of Actor

1: function ActorAgentification (Actor b)

2: Variable: a

3: foreach a in a → b do

4: InitState(); 5: SetGoals();

6: CheckOptionList(); —- Using productionhas-option 7: ComputeUtility(); —- Using productioninfluences 8: SetCapital(); —- Using productioncan-use 9: ChoseAction(); —- Using productionhas-chose 10: Gain:=computeAction();

11: end for

12: return Gain;

13: endfunction

Transition and execution

This section describes the transformation of our model as presented in section 4.2. In the proposed model, the agent architecture is based on utility (Actor evaluates Profit with Score). Our agents seeking to maximize their profit by evaluating gains. The observer will allow other agents to assess at every step the consequences of their actions at the time. The algorithm 1 presents the different steps of the actor’s agentification. The transformation is done according to the programming model presented in section 4.2.

In Section 5.4.4 we show an example of NetLogo code generated from our language. This code generates the functions and procedures, the creation of agents, the initialization of the environment, the declaration of parameters and finally an implementation scheme of agents decision. However, it remains to complete the functions body based on the behavior that the user wants to give to the agent.