GAMA-Platform

GAMA-Platform

  • Documentation
  • Tutorials
  • Download
  • Contribute
  • Blog

›Global Species

Home

  • GAMA

Introduction

  • Introduction

Changes from 1.6.1 to 1.8

  • New-Version-Changes

Moving to 1.9

  • Next-Version-Goals

Platform

  • Platform
  • Installation and Launching
  • Installation

    • Installation
    • Launching GAMA
    • Headless Mode
    • Updating GAMA
    • Installing Plugins
    • Troubleshooting
  • Workspace, Projects and Models
  • Navigating in the Workspace

    • Navigating in the Workspace
    • Changing Workspace
    • Importing Models
  • Editing models
  • GAML Editor (Generalities)

    • The GAML Editor - Generalities
    • GAML Editor tools
    • Validation of Models
  • Running Experiments
  • Launching Experiments

    • Launching Experiments from the User Interface
    • Experiments User Interface
    • Controls of experiments
    • Parameters View
    • Inspectors and monitors
    • Displays
    • Batch Specific UI
    • Errors View
  • Preferences

Learn GAML step by step

  • Learn GAML Step by Step
  • Introduction

    • Introduction
    • Start with GAML
    • Organization of a model
    • Basic programming concepts in GAML
  • Manipulate basic species
  • Global Species

    • The global species
    • Regular species
    • Defining actions and behaviors
    • Interaction between agents
    • Attaching Skills
    • Inheritance

    Defining Advanced Species

    • Defining advanced species
    • Grid Species
    • Graph Species
    • Mirror species
    • Multi-level architecture

    Defining GUI Experiment

    • Defining GUI Experiment
    • Defining Parameters
    • Defining displays (Generalities)
    • Defining Charts
    • Defining 3D Displays
    • Defining monitors and inspectors
    • Defining export files
    • Defining user interaction

    Exploring Models

    • Exploring Models
    • Run Several Simulations
    • Defining Batch Experiments
    • Exploration Methods

    Optimizing Model Section

    • Optimizing Models
    • Runtime Concepts
    • Optimizing Models

    Multi-Paradigm Modeling

    • Multi-Paradigm Modeling
    • Control Architectures
    • Using Equations

Recipes

  • Recipes
  • Manipulate OSM Datas
  • Implementing diffusion
  • Using Database Access
  • CallingR
  • Using FIPA ACL
  • Using GAMAnalyzer
  • Using BEN (simple_bdi)
  • Advanced Driving Skill
  • Manipulate Dates
  • Implementing light
  • Using Comodel
  • Save and Restore simulations
  • Using network
  • Editing Headless mode for dummies
  • The Graphical Editor
  • Using Git from GAMA to version and share models
  • Writing Unit Tests in GAML
  • FAQ (Frequently Asked Questions)
  • Known issues

GAML References

  • GAML References
  • Built-in Species

    • Built-in Species
    • The 'agent' built-in species (Under Construction)
    • The 'model' built-in species (Under Construction)
    • The 'experiment' built-in species (Under Construction)
  • Built-in Skills
  • Built-in Architectures
  • Statements
  • Types
  • File Types
  • Expressions

    • Expressions
    • Literals
    • Units and constants
    • Pseudo-variables
    • Variables and Attributes
    • Operators (A to A)
    • Operators (B to C)
    • Operators (D to H)
    • Operators (I to M)
    • Operators (N to R)
    • Operators (S to Z)
  • Exhaustive list of GAMA Keywords

Pedagogical materials

  • Some pedagogical materials

Extensions

  • Extensions
  • Developing Extensions
  • Installing the GIT version

    • Installing the GIT version
    • Architecture of GAMA
    • Developing Plugins
    • Developing a New Skill
    • Developing Statements
    • Developing Operators
    • Developing Types
    • Developing Species
    • Developing architecture
    • Index of annotations

Developing GAMA

  • Get into the GAMA Java API
  • Introduction-To-Gama-Java-API
  • IScope interface
  • Product your own release of GAMA
  • Documentation
  • How to write the Website Content

Scientific References

  • References

Projects using GAMA

  • Projects

Training Session

  • Training Session
    • Introduction

Events

  • References

Older versions

  • Versions of GAMA

Inheritance

As for many object-oriented programming languages, inheritance can be used in GAML. It is used to structure better your code when you have some complex models. It is, for example, useful when you have defined two different species with many attributes and behaviors in common: you can factorize everything in common in a parent species, and let in the child species only the differences between these 2 species. Notice that a behavior an action defined in a parent species can be redefined in a children species, in order to code a difference in terms of behavior, or simply execute the action of the parent and complete it with some other statements.

Index

  • Mother species / child species
  • Virtual actions
  • Get all the subspecies from a species

Mother species/child species

To make a species inherit from a mother species, you have to add the facet parent, and specify the mother species.

species mother_species { }

species child_species parent: mother_species { }

Thus, all the attributes, actions and reflex of the mother species are inherited to the child species.

species mother_species {
    int attribute_A;
    action action_A {}
}

species child_species parent: mother_species {
    init {
    attribute_A <- 5;
    do action_A;
    }
}

If the mother species has a particular skill, its children will inherit all the attributes and actions.

species mother_species skills:[moving] { }

species child_species parent:mother_species {
    init {
    speed <- 2.0;
    }
    reflex update {
    do wander;
    }
}

You can redefine an action or a reflex by declaring an action or a reflex with the same name.

In the redefined action, it is common to call the action of the mother species with some specific parameters or to add more computations. To this purpose, you need to use:

  • invoke instead of do to call an action (procedure) of the mother species.
  • super.action_name() to call an action (function) of the mother species.
species animal {
    int age <- 0;
    
    action grow {
    age <- age + 1;
    }
    
    int get_age {
    return age;
    }
}

species cat parent: animal {
    action grow {
    invoke grow();   // call the action growth of the mother species animal
    write "I am a cat and I grow up";
    }
    
    int get_age {
    return super.get_age() * 7;  // call the action get_age from the mother species animal
                                     // 1 year is 7 year for cats
    }
}

Virtual action

You have also the possibility to declare a virtual action in the mother species, which means an action without implementation, by using the facet virtual. Note that, when using virtual facet, the statement has to start by action and not a return type. If the action is expecting to return a value you need to add the type facet:

action virtual_action virtual: true;

action vistual_action_with_return_value virtual: true type: any_type;

When you declare an action as virtual in a species, this species becomes abstract, which means you cannot instantiate agent from it. All the children of this species have to implement this virtual action.

species virtual_mother_species {
    action my_action virtual:true;
}

species child_species parent: virtual_mother_species {
    action my_action {
    // some statements
    }
}

Get all the subspecies from a species

If you declare a mother species, you create a child agent, then mother will return the population of agents mother and not the population of agents child, as it is shown in the following example:

global {
    init {
        create child number: 2;
        create mother number: 1;
    }
    reflex update {
        write length(mother); // will write 1 and not 3
    }
}

species mother {}

species child parent: mother {}

We remind you that subspecies is a built-in attribute of the agent. Using this attribute, you can easily get all the subspecies agents of the mother species by writing the following GAML function:

global
{
    init {
        create child number: 2;
        create mother number: 1;
    }
    reflex update {
        write length(get_all_instances(mother)); // will write 3 (1+2)
    }
    list<agent> get_all_instances(species<agent> spec) {
        return spec.population +  spec.subspecies accumulate (get_all_instances(each));
    }
}

species mother {}

species child parent: mother {}

The operator of_generic_species can also be used to filter a list of agents and get all the agents of a given species or of its children species. As a consequence, in the previous example, to count all the agents of mother and child species you can only write:

write length(agents of_generic_species mother);
← Attaching SkillsDefining advanced species →
  • Index
  • Mother species/child species
  • Virtual action
  • Get all the subspecies from a species
GAMA-Platform
Networks
GitHub Facebook Twitter LinkedIn Youtube Blog RSS
Mailing list
For Users
gama-platform@googlegroups.com
For Developers
gama-dev@googlegroups.com
License

Copyright (C) - 2019 GAMA-Platform.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license is included here, in the repository of the wiki content.