My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Operators14  
Operators(Modeling Guide)
Updated Mar 20, 2012 by benoit.g...@gmail.com

Table of Contents



Definition

An operator performs a function on one, two, or three operands. An operator that only requires one operand is called a unary operator. An operator that requires two operands is a binary operator. And finally, a ternary operator is one that requires three operands. The GAML programming language has only one ternary operator, ?:, which is a short-hand if-else statement.

Unary operators are written using aprefix parenthesized notation. Prefix notation means that the operator appears before its operand. Note that unary expressions should always beben parenthesized:

unary_operator (operand)

Most of binary operators can use two notations:

  • the fonctional notation, which used a prenthesized notation around the operands (this notation cannot be used with arithmetic and relational operators such as: +, -, /, , ^, =, !=, <, >, >=, <=... )
  • the infix notation, which means that the operator appears between its operands

binary_operator(op1, op2)

Or 

op1 binary_operator op2    

The ternary operator is also infix; each component of the operator appears between operands:

op1 ? op2 : op3

In addition to performing operations, operators are functional, i.e. they return a value. The return value and its type depend on the operator and the type of its operands. For example, the arithmetic operators, which perform basic arithmetic operations such as addition and subtraction, return numbers - the result of the arithmetic operation.

Moreover, operators are strictly functional, i.e. they have no side effects on their operands. For instance, the shuffle operator, which randomizes the positions of elements in a list, does not modify its list operand but returns a new shuffled list.

Top of the page

Operators by categories

Boolean operators

Casting operators

Comparison operators

Container operators (list, map, matrix)

File-related operators

Graph-related operators

List-related operators

  • accumulate list shuffle at + - collect with_max_of with_min_of of_species starts_with where

Mathematics operators

Matrix-related operators

Random operators

String-related operators

  • empty, first, is_number, last, length, reverse
  • max min shuffle at + - among collect copy_between count first_with last_with in index_of last_index_of max_of min_of with_max_of with_min_of sort_by starts_with where select > < >= <= tokenize

Spatial operators

Statistical opearators

frequency_of, geometric_mean, harmonic_mean, mean, mean_deviation, median, standard_deviation, variance

System

Top of the page

Unary operators

Unary operators take one and only one operand. The syntax is : operator (operand). The priority between operators is determined from right to left (i.e. in op1 op2 op3 operand, op3 is evaluated before op2 and op1).

!

  • Operand: a boolean expression.
  • Result: opposite boolean value.
  • Return type: bool.
  • Special cases: if the parameter is not boolean, it is casted to a boolean value.
  • see also: bool
! (true) → false.

Top of the page

- ( unary )

  • Operand: an int or a float.
  • Result: opposite int or float value.
  • Return type: int or float (depending on the type of the operand).
- (-56) → 56.

Top of the page

acos

  • Operand: an int or a float.
  • Result: the arccos of the operand (which has to be expressed in decimal degrees).
  • Return type: float.
  • see also: asin, atan.
acos (90) → 0.

Top of the page

abs

  • Operand: an int or a float.
  • Result: the absolute value of the operand.
  • Return type: a positive int or float depending on the type of the operand.
abs (200 * -1 + 0.5) → 200.5

Top of the page

agent (or species name)

  • Operand: an int, agent, point or string.
  • Result: casting of the operand to an agent (if species name is used, casting to an instance of species name).
  • Return type: agent (or species name).
  • Special cases:
    • if the operand is a point, returns the closest agent (resp. closest instance of species name) to that point (computed in the topology of the calling agent);
    • if the operand is a string, returns the agent (resp. instance of species name) with this name;
    • if the operand is an agent, returns the agent (resp. tries to cast this agent to species name and returns nil if the agent is instance of another species)
    • if the operand is an int, returns the agent (resp. instance of species name) with this unique index;
  • see also: of_species, species

Top of the page

agent_closest_to

  • Operand: a geometry or an agent.
  • Result: the closest agent to the operand
  • Return type: agent.
  • Comment: the distance is computed in the topology of the calling agent (the agent in which this operator is used), with the distance algorithm specific to the topology.

agent_closest_to(self) → return the closest agent to the agent applying the operator.

Top of the page

agents_inside

  • Operand: a geometry, an agent, a species, a list of geometries, a list of agents.
  • Result: the list of agents covered by the operand (casted as a geometry)
  • Return type: list of agents.
  • see also: agents_overlapping, geometry

agents_inside(self) → return the agents that are covered by the shape of the agent applying the operator.

Top of the page

agents_overlapping

  • Operand: a geometry, an agent, a species, a list of geometries, a list of agents.
  • Result: the list of agents intersecting the operand (casted as a geometry)
  • Return type: list of agents.
  • see also: agents_inside, geometry
agents_overlapping(self) → return the agents that intersect the shape of the agent applying the operator.

Top of the page

any

same signification as one_of operator.

Top of the page

any_location_in

  • Operand: a geometry.
  • Result: a point of this geometry chosen randomly.
  • Return type: point.
  • see also: any_point_in
let my_geometry type: geometry value: square(5);
let one_point type: point value: any_location_in([my_geometry]) → one_point will be a point of my_geometry, for example : {3,4.6}

Top of the page

any_point_in

same signification as any_location_in operator.

Top of the page

as_edge_graph

  • Operand: a list or a map
  • Result: creates a graph from the list/map of edges given as operand
  • Return type: a graph
  • Special cases:
    • if the operand is a list, the graph will be built with elements of the list as vertices
    • if the operand is a map, the graph will be built by creating edges from pairs of the map
  • see also: as_intersection_graph, as_distance_graph
as_edge_graph([{1,5}::{12,45},{12,45}::{34,56}])  → build a graph with these three vertices and two edges
as_edge_graph([{1,5},{12,45},{34,56}])  → build a graph with these three vertices

Top of the page

asin

  • Operand: an int or a float.
  • Result: the arcsin of the operand (which has to be expressed in decimal degrees).
  • Return type: float.
  • see also: acos, atan.
asin (90) → 1.

Top of the page

atan

  • Operand: an int or a float.
  • Result: the arctan of the operand (which has to be expressed in decimal degrees).
  • Return type: float.
  • see also: acos, asin.
atan (45) → 1.

Top of the page

binomial

  • Operand: a point {int,float}.
  • Result: a value from a random variable following a binomial distribution (with the number of experiments n in the left member as the operand and the success probability p in the right one).
  • Return type: int.
  • Comment: The binomial distribution is the discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability p, cf. Binomial distribution on Wikipedia.

poisson({15,0.6}) → a random positive integer 

Top of the page

bool

  • Operand: any type.
  • Result: casting of the operand to a boolean value.
  • Return type: bool.
  • Special cases:
  • if the operand is null, returns false
  • if the operand is an agent, returns true if the agent is not dead
    • if the operand is an int or a float, returns true if it is not equal to 0 (or 0.0).
  • if the operand is a file, bool is formally equivalent to exists.
  • if the operand is a container, bool is formally equivalent to not empty (a la Lisp).
  • if the operand is a string, returns true is the operand is "true"
  • Otherwise, returns false.
bool (0)         → false;
bool(-0.4)       → true;
bool ([1, 2, 3]) → true;

Top of the page

circle

  • Operand: a float
  • Result: building of a circle geometry which radius is equal to the operand
  • Return type: geometry
  • Comment: the centre of the circle is by default the location of the current in which has been called this operator
    • Special cases: returns a point if the operand is lower or equal to 0

circle(10) → returns a geometry as a circle of radius 10.

Top of the page

clean

  • Operand: a geometry
  • Result: removes pinch-offs, merges overlapping polygons
  • Return type: geometry

clean(my_geometry) → returns a cleansed version of my_geometry 

Top of the page

closest_point_to

  • Operand: an agent or a point.
  • Result: the point, closest to the operand, that can be reached by the agent.
  • Return type: point.
  • Special cases: returns nil if the argument cannot be reached by the agent, or if the agent is neither localized nor able to move. Uses the path finder if the environment is a GIS.
  • see also: next_point_towards, towards.
closest_point_to ({0,0}) → returns the point, closest to the origin, that can be reached by the agent.

Top of the page

collate

  • Operand: a list
  • Result: a new list containing interleaved elements of the operand
  • Return type: list
  • Comment: the operand list should be a list of list of elements. The result is a list of elements.
collate([["el11","el12","el13"],["el21","el22","el23"],["el31","el32","el33"]])
		→ ["el11","el21","el31","el12","el22","el32","el13","el23","el33"]

Top of the page

columns_list

  • Operand: a matrix
  • Result: returns a list of the columns of the matrix, with each column as a list of elements
  • Return type: list
  • see also rows_list

columns_list(matrix([["el11","el12","el13"],["el21","el22","el23"],["el31","el32","el33"]])
			→  [["el11","el12","el13"],["el21","el22","el23"],["el31","el32","el33"]]

Top of the page

cone

  • Operand: a point
  • Result: building of a cone geometry which min and max angles are given by the operand
  • Return type: geometry
  • Comment: the centre of the cone is by default the location of the current in which this operator has been called
    • Special cases: returns nil if the operand is nil

cone({0, 45}) → returns a geometry as a cone with min angle is 0 and max angle is 45 

Top of the page

container

  • Operand: any type
  • Result: casting of the operand to a container
  • Return type: container
  • Special cases:
  • if the operand is a container, returns itself
  • otherwise, returns the operand casted to a list
    • see also: list
    • container ("string") → [string]
      container (45.6)     → [45.6]

Top of the page

convex_hull

  • Operand: a geometry
  • Result: convex hull of the operand
  • Return type: geometry
convex_hull(my_geometry) → returns the convex hull of my_geometry 

Top of the page

copy

  • Operand: any
  • Result: a copy of the operand
  • Return type: operand type

Top of the page

cos

  • Operand: an int or a float.
  • Result: the cosinus of the operand (in decimal degrees).
  • Return type: float.
  • Special cases: the argument is casted to an int before being evaluated. Integers outside the range [0-359] are normalized.
  • see also: sin, tan.
cos (0) → 1.

Top of the page

dead

  • Operand: an agent.
  • Result: true if the agent is dead, false otherwise.
  • Return type: bool.
dead(agent_A) → true or false 

Top of the page

directed

  • Operand: a graph
  • Result: the operand graph becomes a directed graph
  • Return type: graph
  • Comment: the operator alters the operand graph, it does not create a new one.
  • see also: undirected

Top of the page

edges

  • Operand: a path.
  • Result: return the list of the edges in the path
  • Return type: list.
  • Special case: if the operand is null, edges returns an empty list
edges(path([{1,5},{12,45},{34,56}])) → returns the list of the two polylines composing this path

Top of the page

even

  • Operand: an int .
  • Result: true if the operand is even and false if it is odd.
  • Return type: a boolean.
  • Special cases: if the operand is equal to 0, it returns true.
even (3) → false.
even (-12) → true.

Top of the page

every

  • Operand: an int.
  • Result: true every operand time step, false otherwise
  • Return type: a boolean.
  • Comment: the value of the every operator depends deeply on the time step. It can be used to do something not every step.
  • reflex text_every {
    	if condition: every(2) {
    		do action: write with: [message::"the time step is even"];
    	else {
    		do action: write with: [message::"the time step is odd"];		
    	}
    	}
    }

Top of the page

empty

  • Operand: a container or a string.
  • Result: true if the operand is empty, false otherwise.
  • Return type: bool.
  • Special cases: the empty operator behavior depends on the nature of the operand,
    • if it is a color or a point, empty returns the false
    • if it is a list, empty returns true if there is no element in the list, and false otherwise
    • if it is a map, empty returns true if the map contains no key-value mappings, and false otherwise
    • if it is a pair, empty returns true if both the key and the value are null, and false otherwise
    • if it is a file, empty returns true if the content of the file (that is also a container) is empty, and false otherwise
    • if it is a graph, empty returns true if it contains no vertex and no edge, and false otherwise
    • if it is a matrix,
      • for a matrix of int, float or object, it will return true if all elements are respectively 0, 0.0 or null, and false otherwise
      • for a matrix of geometry, it will return true if the matrix contains no cell, and false otherwise
    • if it is a string, empty returns true if the string does not contain any character, and false otherwise
empty ([]) → true;
empty ('abced') → false;

Top of the page

exp

  • Operand: an int or a float.
  • Result: returns Euler's number e raised to the power of the operand.
  • Return type: float.
  • Special cases: the operand is casted to a float before being evaluated.
  • see also: ln.
exp (0) → 1.

Top of the page

fact

  • Operand: an int .
  • Result: the factorial of the operand.
  • Return type: an int.
  • Special cases: if the operand is less than 0, fact returns 0.
fact (4) → 24.

Top of the page

file

  • Operand: a string.
  • Result: opens a file in read only mode and tries to determine and store it in the contents attribute.
  • Return type: file.
  • Comment: The file should have a supported extension, cf. Types14 for supported file extensions.
  • Special cases: If the specified string does not refer to an existing file, an exception is risen when the variable is used.
let fileT type: file value: file("../includes/Stupid_Cell.Data");  
							// fileT represents the file "../includes/Stupid_Cell.Data"
                            // fileT.contents here contains a matrix storing all the data of the text file

Top of the page

first

  • Operand: a container, a string or a species.
  • Result: the first element of the operand
  • Return type: any
  • Special cases: the first operator behavior depends on the nature of the operand,
    • if it is a color, first returns the red component
    • if it is a list, first returns the first element of the list, or nil if the list is empty
    • if it is a map, first returns nil (the map do not keep track of the order of elements)
    • if it is a pair, first returns the key of the pair key::value
    • if it is a point, first returns the x-coordinate of a point
    • if it is a file, first returns the first element of the content of the file (that is also a container)
    • if it is a graph, first returns the first element in the list of vertexes
    • if it is a matrix, first returns the element at {0,0} in the matrix
      • for a matrix of int or float, it will return 0 if the matrix is empty
      • for a matrix of object or geometry, it will return null if the matrix is empty
    • if it is a string, first returns a string composed of its first character.
    • if it is a species, first returns the first element of the list of the agents in the species
  • see also: last.
first ('abce') → 'a';
first ([1, 2, 3]) → 1.
first ({10,12}) → 10.

Top of the page

flip

  • Operand: an int or a float (between 0 and 1).
  • Result: true or false given the probability represented by the operand.
  • Return type: bool.
  • Special cases: flip 0 always returns false, flip 1 true.
  • see also: rnd.
flip (0.66666) → 2/3 chances to return true.

Top of the page

float

  • Operand: any type.
  • Result: casting of the operand to a floating point value.
  • Return type: float.
  • Special cases:
    • if the operand is numarical value, returns its value as a floating point value
  • if the operand is a string, tries to convert its content to a floating point value;
  • if the operand is a boolean, returns 1.0 for true and 0.0 for false;
    • otherwise, returns 0.0
    • see also: int.
float ('234.0') → 234.0;
float ({12,23}) → 0.0;
float (true) → 1.0;
float (rgb ('black')) → 0.0;

Top of the page

folder

  • Operand: a string.
  • Result: opens an existing repository
  • Return type: file.
  • Special cases: If the specified string does not refer to an existing repository, an exception is risen.
  • see also: new_folder, file.
let dirT type: file value: folder("../includes/");   
							// dirT represents the repository "../includes/"
                            // dirT.contents here contains the list of the names of included files

Top of the page

gauss

  • Operand: a point {mean, standardDeviation}.
  • Result: a value from a normally distributed random variable with expected value (mean) and variance (standardDeviation). The probability density function of such a variable is a Gaussian.
  • Return type: float
  • Special cases: when standardDeviation value is 0.0, it always returns the mean value.
  • see also: truncated_gauss, poisson.
gauss({0,0.3}) → 0.22354;
gauss({0,0.3}) → -0.1357.

Top of the page

geometric_mean

  • Operand: a list.
  • Result: the geometric mean of the elements of the operand.
  • Return type: float.
  • Special cases: The operator casts all the numerical element of the list into float. The elements that are not numerical are discarded.
geometric_mean ([4.5, 3.5, 5.5, 7.0]) → 4.962326343467649

Top of the page

geometry

  • Operand: any type.
  • Result: casting of the operand to a geometry value.
  • Return type: geometry .
  • Special cases:
  • if the operand is a point, returns geometry composed by this point
  • if the operand is a species name, returns the union of the geometry of each element of the species
  • if the operand is pair, returns a geometry representing a link between each element of the pair casted as geometry
  • if the operand is a container,
    • if the elements of the container are all points, returns the polygon composed by these points
  • otherwise returns the union of the elements casted as geometry

Top of the page

harmonic_mean

  • Operand: a list.
  • Result: the harmonic mean of the elements of the operand.
  • Return type: float.
  • Special cases: The operator casts all the numerical element of the list into float. The elements that are not numerical are discarded.
harmonic_mean ([4.5, 3.5, 5.5, 7.0]) → 4.804159445407279

Top of the page

image

  • Operand: a string.
  • Result: opens a file that is a kind of image.
  • Return type: file.
  • Comment: The file should have an image extension, cf. Types14 for supported file extensions.
  • Special cases: If the specified string does not refer to an existing image file, an exception is risen.
  • see also: file, shapefile, properties, text.
let fileT type: file value: image("../includes/testImage.png");  // fileT represents the file "../includes/testShape.png"

Top of the page

int

  • Operand: any type.
  • Result: casting of the operand to an integer value.
  • Return type: int.
  • Special cases:
    • if the operand is a float, returns its value truncated (but not rounded);
    • if the operand is an agent, returns its unique index;
    • if the operand is a string, tries to convert its content to an integer value;
    • if the operand is a boolean, returns 1 for true and 0 for false;
    • if the operand is a color, returns its RGB value as an integer;
    • otherwise, returns 0

int ('234.3') → 234;
int ({12,23}) → 12;
int (true) → 1;
int (rgb ('black')) → 0;

Top of the page

intensity (deprecated)

  • Operand: a string.
  • Result: the intensity of the signal denoted by the operand at the agent's location.
  • Return type: float.
  • Special cases: returns 0.0 if the agent is not controlled by EMF, if the agent is not localized or if no grids have been defined as an environment.
intensity 'pheromone' → returns the intensity of the 'pheromone' signal on the grid cell where the agent is located.

Top of the page

is_image

  • Operand: a string.
  • Result: the operator tests whether the operand represents the name of a supported image file
  • Return type: bool.
  • Comment: cf. Types14 for supported (espacially image) file extensions.
  • see also: is_text, is_properties, is_shape.
is_image("../includes/Stupid_Cell.Data")    →  false;
is_image("../includes/test.png")            →  true; 
is_image("../includes/test.properties")     →  false;
is_image("../includes/test.shp")            →  false;    

Top of the page

is_number

  • Operand: a string.
  • Result: the operator tests whether the operand represents a numerical value
  • Return type: bool.
  • Comment: Note that the symbol . should be used for a float value (a string with , will not be considered as a numeric value). Symbols e and E are also accepted. A hexadecimal value should begin with #.
is_number("test")  	→  false;
is_number("123.56") →  true;	
is_number("-1.2e5") →  true;
is_number("1,2")    →  false;	
is_number("#12FA")  →  true;  

Top of the page

is_properties

  • Operand: a string.
  • Result: the operator tests whether the operand represents the name of a supported properties file
  • Return type: bool.
  • Comment: cf. Types14 for supported (espacially properties) file extensions.
  • see also: is_text, is_image, is_shape.
is_properties("../includes/Stupid_Cell.Data")    →  false;
is_properties("../includes/test.png")            →  false; 
is_properties("../includes/test.properties")     →  true;
is_properties("../includes/test.shp")            →  false;    

Top of the page

is_text

  • Operand: a string.
  • Result: the operator tests whether the operand represents the name of a supported text file
  • Return type: bool.
  • Comment: cf. Types14 for supported (espacially text) file extensions.
  • see also: is_properties, is_image, is_shape.
is_text("../includes/Stupid_Cell.Data")    →  true;
is_text("../includes/test.png")            →  false; 
is_text("../includes/test.properties")     →  false;
is_text("../includes/test.shp")            →  false;    

Top of the page

is_shape

  • Operand: a string.
  • Result: the operator tests whether the operand represents the name of a supported shapefile
  • Return type: bool.
  • Comment: cf. Types14 for supported (espacially shapefile) file extensions.
  • see also: is_properties, is_image, is_text.
is_shape("../includes/Stupid_Cell.Data")    →  false;
is_shape("../includes/test.png")            →  false; 
is_shape("../includes/test.properties")     →  false;
is_shape("../includes/test.shp")            →  true;    

Top of the page

last

  • Operand: a container, a string or a species.
  • Result: the last element of the operand
  • Return type: any
  • Special cases: the last operator behavior depends on the nature of the operand,
    • if it is a color, last returns the blue component
    • if it is a list, last returns the last element of the list, or nil if the list is empty
    • if it is a map, last returns nil (the map do not keep track of the order of elements)
    • if it is a pair, last returns the value of the pair key::value
    • if it is a point, last returns the y-coordinate of a point
    • if it is a file, last returns the last element of the content of the file (that is also a container)
    • if it is a graph, last returns the last element in the list of vertexes
    • if it is a matrix, last returns the element at {length-1,length-1} in the matrix
      • for a matrix of int or float, it will return 0 if the matrix is empty
      • for a matrix of object or geometry, it will return null if the matrix is empty
    • if it is a string, last returns a string composed of its last character, or an empty string if the operand is empty
    • if it is a species, last returns the last element of the list of the agents in the species
  • see also: first.
last ({10,12}) → 12.
last ('abce') → 'e'
last ([1, 2, 3]) → 3.

Top of the page

length

  • Operand: a container, a string or a species.
  • Result: the number of elements contained in the operand
  • Return type: int.
  • Special cases: the length operator behavior depends on the nature of the operand,
    • if it is a color, length always returns 3.
    • if it is a list or a map, length returns the number of elements in the list
    • if it is a point or a pair, length always return 2
    • if it is a graph, last returns the number of vertexes or of edges (depending on the way it was created)
    • if it is a matrix, length returns the number of cells
    • if it is a string, length returns the number of characters
    • if it is a species, length returns the number of elements in the list of the agents in the species
length ('I am an agent') → 13;
length ([12,13]) → 2.

Top of the page

line

same signification as polyline operator.

Top of the page

link

  • Operand: a pair
  • Result: create a link between the 2 elements of the pair
  • Return type: geometry
  • Comment: This operator returns a geometry representing a link between two geometries. The geometry of this link is the intersection of the two geometries when they intersect, and a line between their centroids when they do not.
  • Special cases:
    • if the operand is null, link returns a point {0,0}
    • if one of the elements of the pair is a list of geometries or a species, link will consider the union of the geometries or of the geometry of each agent of the species
link geom1::geom2 

Top of the page

list

  • Operand: any type.
  • Result: casting of the operand to a list.
  • Return type: list.
  • Special cases:
    • if the operand is a point or a pair, returns a list containing its components (two coordinates or the key and the value);
    • if the operand is a rgb color, returns a list containing its three integer components;
    • if the operand is a file, returns its contents as a list
    • if the operand is a matrix, returns a list containing its elements;
    • if the operand is a graph, returns the list of vetices or edges (depending on the graph)
    • if the operand is a species, return a list of its agents;
    • if the operand is a string, returns a list of strings, each containing one character;
    • otherwise returns a list containing the operand.
  • Comment: list always tries to cast the operand except if it is an int, a bool or a float; to create a list, instead, containing the operand (including another list), use the + operator on an empty list (like + 'abc').
list ('abc') → ['a', 'b', 'c'];
list (123) → '123';
list (['a', 23]) → ['a', 23];
list (rgb ('black')) → [0, 0, 0];

Top of the page

ln

  • Operand: an int or a float (greater than 0).
  • Result: Returns the natural logarithm (base e) of the operand.
  • Return type: float.
  • Special cases: an exception is raised if the operand is less than zero.
  • see also: exp.
  • ln(1) → 0.0

Top of the page

map

  • Operand: any type.
  • Result: casting of the operand to a map.
  • Return type: map.
  • Special cases:
    • if the operand is a color RRGGBB, returns a map with the three elements: "r"::RR, "g"::GG, "b"::BB
    • if the operand is a point, returns a map with two elements: "x":: x-ccordinate and "y":: y-coordinate
    • if the operand is pair, returns a map with this only element
    • if the operand is a species name, returns the map containing all the agents of the species as a pair nom_agent::agent
    • if the operand is a agent, returns a map containing all the attributes as a pair attribute_name::attribute_value
    • if the operand is a list, returns a map containing either elements of the list if it is a list of pairs, or pairs list.get(i)::list.get(i+1)
    • if the operand is a file, returns the content casted to map
    • if the operand is a graph, returns the a map with pairs edge_source::edge_target
    • otherwise returns a map containing only the pair operand::operand.
map (123) → [123::123];
map (rgb ('black')) → ["g"::0, "b"::0, "r"::0];
map({4,6})  →  ["x"::4.0,"y"::6.0]

Top of the page

matrix

  • Operand: any type.
  • Result: casting of the operand to a matrix.
  • Return type: matrix.
  • Special cases:
    • if the operand is a string, returns a matrix of string, each each line of the matrix corresponding to a line of the string; each line is tokenized and each token is put into a cell of the matrix
    • if the operand is a color, returns a matrix containing on the first row three cells containing the three components of the color
    • if the operand is a point or a key, returns a matrix containing on the first row two cells containing the two elements of the point (coordinates) or the pair (the key and the value)
    • if the operand is a file, returns its contents as a matrix
    • if the operand is a list, returns a flat matrix with elements of the list
    • otherwise returns a matrix containing the operand.
matrix ('abc rer r') → [['abc', 'rer', 'r']];
matrix (123) → [[123]];
matrix (['a', 23]) → [['a', 23]];
matrix (rgb ('black')) → [[0, 0, 0]];

Top of the page

max

  • Operand: a container.
  • Result: the maximum element found in the operand.
  • Return type: float, int or point (depending on the operand).
  • Special cases: the max operator behavior depends on the nature of the operand,
    • if it is a color, max returns the maximum of the three components
    • if it is a list,
      • a list of int or float: max returns the maximum of all the elements
      • a list of points: max returns the maximum of all points as a point (i.e. the point with the greatest coordinate on the x-axis, in case of equality the point with the greatest coordinate on the y-axis is chosen. If all the points are equal, the first one is returned. )
      • otherwise: max transforms all elements into float and returns the maximum of them
    • if it is a map, max returns the maximum among the list of all elements value
    • if it is a pair, max returns the maximum of the two elements of the pair if the first is comparable
    • if it is a point, max returns the maximum of the two coordinates
    • if it is a file, max returns the maximum of the content of the file (that is also a container)
    • if it is a graph, max returns the maximum of the list of the elements of the graph (that can be the list of edges or vertexes depending on the graph)
    • if it is a matrix,
      • a matrix of int, float or object, max returns the maximum of all the numerical elements (thus all elements for integer and float matrices)
      • a matrix of geometry, max returns the maximum of the list of the geometries
  • see also: min.
max ([100, 23.2, 34.5]) → 100.0.

Top of the page

mul

  • Operand: a container.
  • Result: the product of all the elements of the operand.
  • Return type: float.
  • Special cases: the mul operator behavior depends on the nature of the operand,
    • if it is a color, mul returns the product of the three components
    • if it is a list,
      • a list of int or float: mul returns the product of all the elements
      • a list of points: mul returns the product of all points as a point (each coordinate is the product of the corresponding coordinate of each element)
      • otherwise: mul transforms all elements into float and multiplies them
    • if it is a map, mul returns the product of the value of all elements
    • if it is a pair, mul returns the product of the two elements of the pair if they are integer or float, 0.0 otherwise
    • if it is a point, mul returns the product of the two coordinates
    • if it is a file, mul returns the product of the content of the file (that is also a container)
    • if it is a graph, mul returns the product of the list of the elements of the graph (that can be the list of edges or vertexes depending on the graph)
    • if it is a matrix,
      • a matrix of int, float or object, mul returns the product of all the numerical elements (thus all elements for integer and float matrices)
      • a matrix of geometry, mul returns the product of the list of the geometries
  • see also: sum.
mul ([100, 23.2, 34.5]) → 100.0.

Top of the page

mean

  • Operand: a container.
  • Result: the mean of all the elements of the operand.
  • Return type: float or point.
  • Comment: if the container contains points, the result will be a point.
    • Special cases: the elements of the operand are summed (see sum for more details about the sum of container elements ) and then the sum value is divided by the number of elements.
    • see also: sum.
mean ([4.5, 3.5, 5.5, 7.0]) → 5.125

Top of the page

mean_deviation

  • Operand: a list.
  • Result: the deviation from the mean of all the elements of the operand.
  • Return type: float.
  • Special cases: The operator casts all the numerical element of the list into float. The elements that are not numerical are discarded.
mean_deviation ([4.5, 3.5, 5.5, 7.0]) → 1.125

Top of the page

median

  • Operand: a list.
  • Result: the median of all the elements of the operand.
  • Return type: float.
  • Special cases: The operator casts all the numerical element of the list into float. The elements that are not numerical are discarded.
  • see also: mean.
median ([4.5, 3.5, 5.5, 7.0]) → 5.0

Top of the page

min

  • Operand: a container.
  • Result: the minimum element found in the operand.
  • Return type: float, int or point (depending on the operand).
  • Special cases: the min operator behavior depends on the nature of the operand,
    • if it is a color, min returns the minimum of the three components
    • if it is a list,
      • a list of int or float: min returns the minimum of all the elements
      • a list of points: min returns the minimum of all points as a point (i.e. the point with the smallest coordinate on the x-axis, in case of equality the point with the smallest coordinate on the y-axis is chosen. If all the points are equal, the first one is returned. )
      • otherwise: min transforms all elements into float and returns the minimum of them
    • if it is a map, min returns the minimum among the list of all elements value
    • if it is a pair, min returns the minimum of the two elements of the pair if the first is comparable
    • if it is a point, min returns the minimum of the two coordinates
    • if it is a file, min returns the minimum of the content of the file (that is also a container)
    • if it is a graph, min returns the minimum of the list of the elements of the graph (that can be the list of edges or vertexes depending on the graph)
    • if it is a matrix,
      • a matrix of int, float or object, min returns the minimum of all the numerical elements (thus all elements for integer and float matrices)
      • a matrix of geometry, min returns the minimum of the list of the geometries
  • see also: max.
min ([100, 23.2, 34.5]) → 23.2.

Top of the page

new_folder

  • Operand: a string.
  • Result: opens an existing repository or create a new folder if it does not exist.
  • Return type: file.
  • Special cases: If the specified string does not refer to an existing repository, the repository is created. If the string refers to an existing file, an exception is risen.
  • see also: folder, file.
let dirNewT type: file value: new_folder("../incl/");   // dirNewT represents the repository "../incl/"
                                                        // eventually creates the directory ../incl

Top of the page

norm

  • Operand: point.
  • Result: the norm of the vector with the coordinnates of the point operand.
  • Return type: float.
norm({3,4})   →  5.0

Top of the page

not

same signification as ! operator.

Top of the page

one_of

  • Operand: a container or species.
  • Result: a random element from the list.
  • Return type: any.
  • Special cases: returns nil if the list is empty.
  • Comment: In the case of a species, the operand is casted to a list before the expression is evaluated. Therefore, if foo is the name of a species, any foo will return a random agent from this species (see list).
any ([1,2,3]) → 1, 2, or 3.
one_of ([1,2,3]) → 1, 2, or 3.

// The species `bug` has previously be defined
one_of (bug) → bug3

let mat3 type:matrix value: matrix([["c11","c12","c13"],["c21","c22","c23"]]);
one_of(mat3) → "c11","c12","c13", "c21","c22" or "c23"

Top of the page

pair

  • Operand: any type.
  • Result: casting of the operand to a pair value.
  • Return type: pair.
  • Special cases:
  • if the operand is null, returns null
  • if the operand is a point, returns the pair x-coordinate::y-coordinate
  • if the operand is a particular kind of geometry, a link between geometry, returns the pair formed with these two geoemtries
    • if the operand is a map, returns the pair where the first element is the list of all the keys of the map and the second element is the list of all the values of the map
  • if the operand is a list, returns a pair with the two first element of the list used to built the pair
  • Otherwise, returns the pair string(operand)::operand
pair({3,5})   →  3::5
pair([6,7,8]) →  6::7
pair([2::6,5::8,12::45]) → [12,5,2]::[45,8,6]

Top of the page

path

  • Operand: list
  • Result: creates a path between all the elements of the operand
  • Return type: path
  • Comment: The path is created after transformation of each element of the list into the corresponding point.

path([{1,5},{12,45},{34,56}])  → a path from {1,5} to {12,45} through {34,56}
					→  ([polygon ([{1.0,5.0},{12.0,45.0}]),polygon ([{12.0,45.0},{34.0,56.0}])]) as path

Top of the page

point

  • Operand: any
  • Result: casting of the operand to a point value.
  • Return type: point.
  • Special cases:
  • if the operand is null, returns null
    • if the operand is an agent, returns its location
  • if the operand is a geometry, returns its centroid
  • if the operand is a list with at least two elements, returns a point with the two first elements of the list (casted to float)
  • if the operand is a map, returns the point with values associated respectively with keys "x" and "y"
  • if the operand is a pair, returns a point with the two elements of the pair (casted to float)
  • otherwise, returns a point {val,val} where val is the float value of the operand
  • point([12,123.45]) → {12.0, 123.45} 
    point(2)           → {2.0, 2.0}
    point(["t"::4,"x"::5,"y"::6])  → {5.0,6.0}

Top of the page

poisson

  • Operand: a float.
  • Result: a value from a random variable following a Poisson distribution (with the positive expected number of occurence lambda as operand).
  • Return type: int.
  • Comment: The Poisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time and/or space if these events occur with a known average rate and independently of the time since the last event, cf. Poisson distribution on Wikipedia.

poisson(3.5) → a random positive integer 

Top of the page

polygon

  • Operand: a list of points
  • Result: building of a polygon geometry from the given points
  • Return type: geometry
  • Special cases: if the operand is nil, returns the point geometry {0,0}; if the operand is composed of a single point, returns a point geometry; if the operand is composed of 2 points, returns a polyline geometry

polygon([{0,0}, {0,10}, {10,10}, {10,0}]) → returns a polygon geometry composed of the 4 points.

Top of the page

polyline

  • Operand: a list of points
  • Result: building of a polyline geometry from the given points
  • Return type: geometry
  • Special cases: if the operand is nil, returns the point geometry {0,0}; if the operand is composed of a single point, returns a point geometry.

polyline([{0,0}, {0,10}, {10,10}, {10,0}]) → returns a polyline geometry composed of the 4 points.

Top of the page

product

same signification as mul operator.

Top of the page

properties

  • Operand: a string.
  • Result: opens a file that is a kind of properties.
  • Return type: file.
  • Comment: The file should have a properties extension, cf. Types14 for supported file extensions.
  • Special cases: If the specified string does not refer to an existing propserites file, an exception is risen.
  • see also: file, shapefile, image, text.
let fileT type: file value: properties("../includes/testProperties.properties");  // fileT represents the properties file "../includes/testProperties.properties"

Top of the page

read

  • Operand: a file.
  • Result: marks the file so that only read operations are allowed.
  • Return type: file.
  • Comment: A file is created by default in read-only mode. The operator write can change the mode.
  • see also: file, write.
read(shapefile("../images/point_eau.shp"))  →  returns a file in read-only mode representing "../images/point_eau.shp"

Top of the page

rectangle

  • Operand: a point
  • Result: building of a rectangle geometry which side sizes are given by the operand
  • Return type: geometry
  • Comment: the centre of the rectangle is by default the location of the current in which has been called this operator
    • Special cases: returns a point if the operand is nil
  • See also: circle, square

rectangle({10, 5}) → returns a geometry as a rectangle with width = 10 and heigh = 5.

Top of the page

remove_duplicates

  • Operand: a list
  • Result: a list corresponding to the operand without the duplicate elements.
  • Return type: list
remove_duplicates ([10,12,10,14]) → [10, 12, 14].

Top of the page

reverse

  • Operand: a container or a string.
  • Result: the operand elements in the reversed order in a copy of the operand.
  • Return type: a container of the same type of the operand or a string.
  • Comment: the operand is not modified.
  • Special cases: the reverse operator behavior depends on the nature of the operand,
    • if it is a color (say RRGGBB), reverse returns a new color with the colors in the reversed order (BBGGRR)
    • if it is a list, reverse return a copy of the operand list with elements in the reversed order
    • if it is a map, reverse returns a copy of the operand map with each pair in the reversed order (i.e. all keys become values and values become keys)
    • if it is a pair, reverse returns a new pair in the reversed order (the old key is the new value and the old value is the new key)
    • if it is a point, reverse returns a new point with reversed coordonates
    • if it is a file, reverse returns a copy of the file with a reversed content
    • if it is a graph, reverse returns a copy of the graph (with all edges and vertexes), with all of the edges reversed
    • if it is a matrix, reverse returns a new matrix containing the transpose of the operand.
    • if it is a string, reverse returns a new string with caracters in the reversed order.
reverse ('abcd') → 'dcba';
reverse ({10,13}) → {13, 10};
reverse ([10,12,14]) → [14, 12, 10].
reverse ([k1::44, k2::32, k3::12])  → [12::k3,  32::k2, 44::k1]

Top of the page

rgb

  • Operand: any type.
  • Result: casting of the operand to a rgb color.
  • Return type: rgb.
  • Special cases:
    • if the operand is nil, returns white;
  • if the operand is a string, the allowed color names are the constants defined in the java.awt.Color class, i.e.: black, blue, cyan, darkGray, lightGray, gray, green, magenta, orange, pink, red, white, yellow. Otherwise tries to cast the string to an int and returns this color
    • if the operand is a list, the integer value associated to the three first elements of the list are used to define the three red (element 0 of the list), green (element 1 of the list) and blue (element 2 of the list) components of the color.
    • if the operand is a map, the red, green, blue compoenents take the value associated to the keys "r", "g", "b" in the map.
  • if the operand is a matrix, return the color of the matrix casted as a list
    • if the operand is a boolean, returns black for true and white for false;
    • if the operand is an integer value, the decimal integer is translated into a hexadecimal value: OxRRGGBB. The red (resp. green, blue) component of the color take the value RR (resp. GG, BB) translated in decimal.
rgb ('white') → white color;
rgb (#FFFFFF) → white color;
rgb ([0, 255,0]) → green color;
rgb ('255') → blue color;

Top of the page

rnd

  • Operand: an int or a float.
  • Result: a random integer in the interval [0, operand].
  • Return type: int.
  • Special cases: the argument is casted to an int before being evaluated.
  • see also: flip.
  • Comments : to obtain a probability between 0 and 1, use the expression (rnd n) / n, where n is used to indicate the precision;
rnd (2) → 0, 1 or 2
rnd (1000) / 1000 → a float between 0 and 1 with a precision of 0.001

Top of the page

round

  • Operand: an int or a float.
  • Result: the rounded value of the operand.
  • Return type: int.
  • Special cases: the argument is casted to a float before round is evaluated.
  • see also: int.
round (0.51) → 1;
round (100.2) → 100.

Top of the page

rows_list

  • Operand: a matrix
  • Result: returns a list of the rows of the matrix, with each row as a list of elements
  • Return type: list
  • see also: columns_list

rows_list(matrix([["el11","el12","el13"],["el21","el22","el23"],["el31","el32","el33"]])
			→  [["el11","el21","el31"],["el12","el22","el32"],["el13","el23","el33"]]

Top of the page

shapefile

  • Operand: a string.
  • Result: opens a file that a is a kind of shapefile.
  • Return type: file.
  • Comment: The file should have a shapefile extension, cf. Types14 for supported file extensions.
  • Special cases: If the specified string does not refer to an existing shapefile file, an exception is risen.
  • see also: file, properties, image, text.
let fileT type: file value: shapefile("../includes/testProperties.shp");  
				// fileT represents the shapefile file "../includes/testProperties.shp"

Top of the page

shuffle

  • Operand: a list, string, matrix or species.
  • Result: the elements of the operand in random order.
  • Return type: list, string or matrix.
  • Special cases: if the operand is empty, returns an empty list (or string, matrix);
  • see also: reverse.
shuffle ([12, 13, 14]) → [14,12,13];
shuffle ('abc') → 'bac'.
shuffle ([["c11","c12","c13"],["c21","c22","c23"]]) → [["c12","c21","c11"],["c13","c22","c23"]]
shuffle (bug) → shuffle the list of all agent of the `bug` species

Top of the page

sin

  • Operand: an int or a float.
  • Result: the sinus of the operand (in decimal degrees).
  • Return type: float.
  • Special cases: the argument is casted to an int before being evaluated. Integers outside the range [0-359] are normalized.
  • see also: cos, tan.
sin (0) → 0.

Top of the page

skeletonize

  • Operand: a geometry (polygon)
  • Result: the skeleton of the geometry
  • Return type: list of geometries
  • Comment: A skeleton of a geometry is a thin version of that geometry that is equidistant to its boundaries, cf. Skeleton for more details about skeleton.
let my_geometry type: geometry value: square(5);
let skeleton type: list of: geometry value: skeletonize(my_geometry);  → skeleton will be the skeleton of my_geometry

Top of the page

solid

  • Operand: a geometry (polygon)
  • Result: the geometry without its holes
  • Return type: geometry
  • see also: without_holes
let my_geometry type: geometry value: square(5) - square(3);
let solid_geom type: geometry value: solid(my_geometry);  
					→ solid_geometry will be a rectangle of side size equal to 5 (without holes) 

Top of the page

species

  • Operand: any.
  • Result: casting of the operand to a species.
  • Return type: species.
  • Special cases:
    • if the operand is nil, returns nil;
    • if the operand is an agent, returns its species;
    • if the operand is a string, returns the species with this name (nil if not found);
    • otherwise, returns nil
species (self) → the species of the agent;
species ('world') → the species named 'world';

Top of the page

species_of

same signification as species operator.

Top of the page

split_lines

  • Operand: a list of geometries (lines)
  • Result: computes the resulting after cutting the lines at their intersections
  • Return type: list of geometry

let line1 type: geometry value: line([{0,10}, {20,10}]);
let line2 type: geometry value: line([{10,0}, {10,20}]);
let lines type: list of: geometry value: split_lines([line1, line2]);  
			→ lines will be a list of four line geometries: line([{0,10}, {10,10}]), line([{10,10}, {20,10}]), line([{10,0}, {10,10}]) and line([{10,10}, {10,20}]).   

Top of the page

sqrt

  • Operand: an int or a float (greater than 0).
  • Result: Returns the square root of the operand.
  • Return type: float.
  • Special cases: an exception is raised if the operand is less than zero.
sqrt(4) → 2.0

Top of the page

square

  • Operand: a float
  • Result: building of a square geometry which side size is equal to the operand
  • Return type: geometry
  • Comment: the centre of the square is by default the location of the current in which this operator has been called
    • Special cases: returns a point if the operand is lower or equal than 0

square(10) → returns a geometry as a square of side size 10.

Top of the page

standard_deviation

  • Operand: a list.
  • Result: the standard deviation on the elements of the operand.
  • Return type: float.
  • Special cases: The operator casts all the numerical element of the list into float. The elements that are not numerical are discarded.
standard_deviation ([4.5, 3.5, 5.5, 7.0]) → 1.2930100540985752

Top of the page

string

  • Operand: any type.
  • Result: casting of the operand to a string.
  • Return type: string.
  • Special cases:
    • if the operand is nil, returns 'nil';
    • if the operand is an agent, returns its name;
    • if the operand is a string, returns the operand;
    • if the operand is an int or a float, returns their string representation (as in Java);
    • if the operand is a boolean, returns 'true' or 'false';
    • if the operand is a species, returns its name;
    • if the operand is a color, returns its litteral value if it has been created with one (i.e. 'black', 'green', etc.) or the string representation of its hexadecimal value.
    • if the operand is a container, returns its string representation;

string (rgb ('black')) → 'black';
string (12.34) → '12.34';
string (world) → 'world' if world is a species.

Top of the page

sum

  • Operand: a container.
  • Result: the sum of all the elements of the operand.
  • Return type: float.
  • Special cases: the sum operator behavior depends on the nature of the operand:
    • if it is a color, sum returns the sum of the three components
    • if it is a list:
      • a list of int or float: sum returns the sum of all the elements
      • a list of points: sum returns the sum of all points as a point (each coordinate is the sum of the corresponding coordinate of each element)
      • otherwise: sum transforms all elements into float and sums them
    • if it is a map, sum returns the sum of the value of all elements
    • if it is a pair, sum returns the sum of the two elements of the pair if they are integer or float, 0.0 otherwise
    • if it is a point, sum returns the sum of the two coordinates
    • if it is a file, sum returns the sum of the content of the file (that is also a container)
    • if it is a graph, sum returns the sum of the list of the elements of the graph (that can be the list of edges or vertexes depending on the graph)
    • if it is a matrix:
      • a matrix of int, float or object, sum returns the sum of all the numerical elements (i.e. all elements for integer and float matrices)
      • a matrix of geometry, sum returns the sum of the list of the geometries
  • see also: mul.
sum ([12,10, 3]) → 25.0.

Top of the page

tan

  • Operand: an int or a float.
  • Result: the trigonometic tangent of the operand (expressed in decimal degrees).
  • Return type: float.
  • Special cases: the argument is casted to an int before being evaluated. Integers outside the range [0-359] are normalized.
  • see also: sin, cos.
tan (180) → 0.

Top of the page

text

  • Operand: a string.
  • Result: opens a file that a is a kind of text.
  • Return type: file.
  • Comment: The file should have a text extension, cf. Types14 for supported file extensions.
  • Special cases: If the specified string does not refer to an existing text file, an exception is risen.
  • see also: file, properties, image, shapefile.
let fileT type: file value: te("xt../includes/Stupid_Cell.Data");  
						// fileT represents the text file "../includes/Stupid_Cell.Data"

Top of the page

TGauss

same signification as truncated_gauss operator.

Top of the page

to_java

  • Operand: any
  • Result: returns the GAML code associated to the operand
  • Return type: string
  • see also: to_gaml

Top of the page

to_gaml

  • Operand: any
  • Result: returns the Java code associated to the operand
  • Return type: string
  • see also: to_java

Top of the page

topology

  • Operand: any
  • Result: casting of the operand to a topology.
  • Return type: topology
  • Special cases:
    • if the operand is nil, returns nil
    • if the operand is a population, returns the topology of this population
    • if the operand is a species, returns the topology of the agents of this species (expression evaluated in the scope of the calling agent)
    • if the operand is a geometry, returns a continuous topology built from this geometry (with the the shape of the geometry)
    • if the operand is a container, returns a topology built from this topology
      • if the operand is a graph, returns a graph topolgy built on this graph
      • if the operand is a matrix of geometries, returns a grid topology from this matrix
    • otherwise, built a multiple topology
      • otherwise, returns the topology built from this operand casted to a geometry
  • see also geometry

Top of the page

towards

  • Operand: an agent or a point.
  • Result: the direction (in degrees) that the agent must follow to face the operand.
  • Return type: int.
  • Special cases: if the agent is not localized, returns 0;
  • see also: . next_point_towards
towards ({0, 0}) → an int between 0 and 359.

Top of the page

triangle

  • Operand: a float
  • Result: building of a triangle geometry which side size is given by the operand
  • Return type: geometry
  • Comment: the centre of the triangle is by default the location of the current in which this operator has been called
  • Special cases: returns a point if the operand is nil

triangle(5) → returns a geometry as a triangle with side_size = 5.

Top of the page

triangulate

  • Operand: a geometry (polygon)
  • Result: the Delaunay triangulation of the geometry
  • Return type: list of geometries
  • Comments: see Delaunay Triangulation for more details
let my_geometry type: geometry value: square(5);
let skeleton type: list of: geometry value: triangulate(my_geometry);  → list of triangle geometries resulting from the Delaunay triangulation of my_geometry

Top of the page

truncated_gauss

  • Operand: a list or a point {mean, standardDeviation}.
  • Result: a random value from a normally distributed random variable in the interval ]mean - standardDeviation; mean + standardDeviation[.
  • Return type: float.
  • Special cases: when truncated_gauss is called with an list of only one element mean, it will always return 0.0.
  • see also: gauss.
truncated_gauss ({0, 0.3}) → an float between -0.3 and 0.3.
truncated_gauss ([0.5, 0.0]) → 0.5 (always).

Top of the page

undirected

  • Operand: a graph
  • Result: the operand graph becomes an undirected graph
  • Return type: graph
  • Comment: the operator alters the operand graph, it does not create a new one.
  • see also: directed

Top of the page

unknown

  • Operand: any
  • Result: the operand
  • Return type: any
  • Comment: returns the operand without any casting

Top of the page

union

  • Operand: a list of geometry or a species.
  • Result: the geometry composed of the union of all the geometries of the list or of the geometries of all the agents of the species.
  • Return type: geometry.
  • Special cases:
    • when the operand is an empty list, it returns a null geometry
    • when the operand is a list of points and it forms a closed linestring, the corresponding polygon is built
union([{2,5},{7,21},{56,12},{2,5}])   → build the polygon from the 3 points

Top of the page

variance

  • Operand: a list.
  • Result: the variance of the elements of the operand.
  • Return type: float.
  • Special cases: The operator casts all the numerical element of the list into float. The elements that are not numerical are discarded.
  • Comment: see Variance for more details
  • see also: mean, median.
variance ([4.5, 3.5, 5.5, 7.0]) → 1.671875

Top of the page

without_holes

same signification as solid operator.

Top of the page

write

  • Operand: a file.
  • Result: marks the file so that read and write operations are allowed.
  • Return type: file.
  • Comment: A file is created by default in read-only mode.
  • see also: file, read.
write(shapefile("../images/point_eau.shp"))  →  returns a file in read-write mode representing "../images/point_eau.shp"

Top of the page

Binary operators

=

  • Left-hand operand: any expression.
  • Right-hand operand: any expression.
  • Result: true if both operands are equal, false otherwise.
  • Comments: this operator will return true if the two operands are identical (i.e., the same object) or equal. Comparisons between nil values are permitted. Note that floating point and integer values are always considered as different (i.e., 0.0 is not the same as 0).
  • see also: !=.
[1, 2, 3.0] = [1,2,3.0] → true;
int (3.0) = 3 → true;
rgb ('black') = rgb (#000000) → true;
float (1) = 1.0 → true;

Top of the page

!=

same signification as <> operator.

Top of the page

<>

  • Left-hand operand: any expression.
  • Right-hand operand: any expression.
  • Result: true if both operands are different, false otherwise.
  • Comments: this operator will return false if the two operands are identical (i.e., the same object) or equal. Comparisons between nil values are permitted. Note that floating point and integer values are always considered as different (i.e., 0.0 is not the same as 0).
  • see also: =.
[1, 2, 3.0] != [1,2,3.0] → false;
int (3.0) != 3 → false;
rgb ('black') != rgb (#000000) → false;
float (1) != 1.0 → false;

Top of the page

> >= < <=

  • Left-hand operand: any expression.
  • Right-hand operand: any expression.
  • Result: true if the left-hand operand is respectively greater than, less than, greater than or equal to, less than or equal to the right-hand operand. false otherwise.
  • Comments: these operator work with numbers (int and float) as well as strings, for which a lexicographic comparison is performed.
12 > 11.0 → true;
'zzz' > 'abc' → true;
int (12.0) < 12 → false;

Top of the page

@

same signification as at operator.

Top of the page

+

  • Left-hand operand: a list, string, matrix, point, int, float or a geometry.
  • Right-hand operand: a list, string, matrix, point, int, float or a geometry.
  • Result: the sum, union or concatenation of the two operands.
  • Special cases:
    • if left-operand is a geometry
    • if the right-operand is a geometry, see union
    • if the right-operand is a point, if the geometry is a point, returns the polyline with these two points, otherwise add the point at the end of the list of points of the geometry (if the new geometry is valid, in the case of a polygon)
    • geometry({10,10}) + {15,15}		     → polyline([{10.0;10.0},{15.0;15.0}])
      polyline([{10,10},{20,20}]) + {15,15}   → polyline([{10.0;10.0},{20.0;20.0},{15.0;15.0}])
      polygon([{10,10},{10,20},{20,20},{20,10}]) + {25,25}	→ polygon([{10.0;10.0},{10.0;20.0},{20.0;20.0},{20.0;10.0},{10.0;10.0}])
      polygon([{10,10},{10,20},{20,20},{20,10}]) + {5,5})   → polygon([{10.0;10.0},{10.0;20.0},{20.0;20.0},{20.0;10.0},{5.0;5.0},{10.0;10.0}])
  • If both operands are numbers, performs a normal arithmetic sum and returns a float if one of them is a float.
  • 1 + 1 → 2 
    1.0 + 1 → 2.0

If the left-hand operand is an int and the right-hand operand is not a number, casts the right-hand operand to an int.

1 + '34' → 35;

If the left-hand operand is a float and the right-hand operand is not a number, casts the right-hand operand to a float.

1.0 + '34' → 35.0;

If the left-hand operand is a string, casts the right-hand operand to a string and returns their concatenation.

'abc' + 'def' → 'abcdef';

If both operands are lists, returns their union.

[1, 2, 3] + [4, 5] → [1, 2, 3, 4, 5];
list ('abc') + list ('def') → ['a','b','c','d','e','f'];

If both operands are points, returns their sum.

{1, 2} + {4, 5} → {5, 7};

If the left-hand operand is a list and the right-hand operand is not a list, returns a new list with the right-hand operand added to the end of the left-hand operand. Matrices, points and strings are not considered as lists and will be added as individual elements.

[1,2,3] + 4 → [1,2,3,4];
['a','b','c'] + 'def' → ['a', 'b', 'c', 'def'];

  • Comments: Sum of matrices is not yet implemented but should be available sometime in the future with the same syntax.
  • see also: union

Top of the page

-

  • Left-hand operand: a geometry, list, matrix, point, int or float.
  • Right-hand operand: a geometry, list, matrix, point, int or float.
  • Result: the difference of the two operands.
  • Special cases:
    • if the left-operand is a geometry
      • if the right-operand is either a geometry, a list of agents or a species, returns the geometry resulting from de difference between both geometries (or between the left-operand geometry and the geometry of each agent of the list or of the species)
      • if the right-operand is a number, see reduced_by
    • If both operands are numbers, performs a normal arithmetic difference and returns a float if one of them is a float.
    • 1 - 1 → 0;
      1.0 - 1 → 0.0;

If the left-hand operand is an int and the right-hand operand is not a number, casts the right-hand operand to an int.

1 - '34' → -33;

If the left-hand operand is a float and the right-hand operand is not a number, casts the right-hand operand to a float.

1.0 - '34' → -33.0;

If both operands are lists, returns their difference (removes all the elements of the right-hand operand from the left-hand operand).

[1, 2, 3] - [3, 4, 5] → [1, 2];
list ('abc') - list ('abk') → ['c'];

If both operands are points, returns their difference.

{10, 20} - {4, 5} → {6, 15};

If the left-hand operand is a list and the right-hand operand is not a list, returns a new list with the right-hand operand removed from the left-hand operand.

[1,2,3] - 3 → [1,2];
  • Comments: Difference of matrices is not yet implemented but should be available sometime in the future with the same syntax.
Top of the page

  • Left-hand operand: a geometry, an int or float.
  • Right-hand operand: a geometry, an int or float.
  • Result: a float, equal to the product of the two operands or a geometry.
  • Comments: Product of matrices is not yet implemented but should be available sometime in the future with the same syntax.
  • Special cases:
    • if the left-operand is a geometry, see scaled_by

Top of the page

/

  • Left-hand operand: an int or float.
  • Right-hand operand: an int or float.
  • Result: a float, equal to the division of the left-hand operand by the rigth-hand operand.
  • Special cases: if the right-hand operand is equal to zero, raises no exception and returns the maximum value of float instead.
  • Comments: Division of matrices is not yet implemented but should be available sometime in the future with the same syntax.

Top of the page

^

  • Left-hand operand: a int or float expression
  • Right-hand operand: a int or float expression
  • Result: an int or float value, equal the left-hand operand raised to the power of the right-hand operand.
  • Special cases: if the right-hand operand is equal to 0, returns 1; if it is equal to 1, returns the left-hand operand.

Top of the page

<->

same signification as disjoint_from operator.

Top of the page

around

  • Left-hand operand: a float.
  • Right-hand operand: any type (the operand will be casted in a geometry)
  • Result: geometry resulting from the difference between a buffer around the right-operand casted in geometry at a distance left-operand (right-operand buffer left-operand) and the right-operand casted as geometry
  • Return type: geometry
  • Special cases: returns a circle geometry of radius right-operand if the left-operand is nil
  • see also: geometry, -, circle, buffer
let circle_geom type: geometry value: circle(5); 
let ring_geom type: geometry value:  10 around circle_geom → returns a the ring geometry between 5 and 10.

Top of the page

at

  • Left-hand operand: a list, string, matrix or point.
  • Right-hand operand: an integer or a point.
  • Result: the element of the left-hand operand located at the index specified by the right-hand operand.
  • Comments:
  • o strings, lists, and matrices are zero-based implementations, which means that the first index is 0 and the last one length-1. o at can be used in the left member of an assignment to assign a new value to one of the positions of a list, a matrix, a string, a point...
let my_list type: list of: int value: 12, 13, 14, 15;
let my_int type: int value: (my_list at 2) + 18; → my_int is equal to 32.
<let var="my_matrix" size={2,2}" />
<set var="my_matrix at {0,1}" value="42"/> → the element on the first column and second line is now 42. (the rest of the matrix is empty)
  • Special cases:
  • o if the left-hand operand is a string, a list, a point or a one-dimension matrix, and the index is less than 0 or greater than its length, returns nil. o if the left-hand operand is a two-dimensions matrix and the index is a point, the same rule applies for both dimensions. o if the left-hand operand is a one-dimension matrix, a list, a point or a string, and the index is a point, the x-coordinate of the point is used for the index. o if the left-hand operand is a string, returns a one-character string.
[1, 10, 3.0] @ 2 → 3.0;
'abcdef' at 0 → 'a';

Top of the page

div

  • Left-hand operand: a int or float.
  • Right-hand operand: a int or float.
  • Result: an int, equal to the truncation of the division of the left-hand operand by the rigth-hand operand.
  • Special cases: if the right-hand operand is equal to zero, raises no exception and returns the maximum value of int instead.

Top of the page

mod

  • Left-hand operand: a int or float.
  • Right-hand operand: a int or float.
  • Result: an int, equal to the remainder of the integer division of the left-hand operand by the rigth-hand operand.
  • Special cases: if the right-hand operand is equal to zero, raises no exception and returns the maximum value of int instead.

Top of the page

and

  • Left-hand operand: a boolean expression
  • Right-hand operand: a boolean expression
  • Result: a bool value, equal to the logical and between the left-hand operand and the rigth-hand operand.
  • Comments: both operands are always casted to bool before applying the operator. Thus, an expression like 1 and 0 is accepted and returns false.
  • see also: bool, or.

Top of the page

or

  • Left-hand operand: a boolean expression
  • Right-hand operand: a boolean expression
  • Result: a bool value, equal to the logical or between the left-hand operand and the rigth-hand operand.
  • Comments: both operands are always casted to bool before applying the operator. Thus, an expression like 1 or 0 is accepted and returns true.
  • see also: bool, and.

Top of the page

accumulate

  • Left-hand operand: a list, point or string expression
  • Right-hand operand: any.
  • Result: a list containing all elements of left-hand expression and right-hand expression.
[1,2,3] accumulate [4,5,6] → [1,2,3,4,5,6]

Top of the page

among

  • Left-hand operand: a int expression
  • Right-hand operand: a list, string, point or matrix.
  • Result: a list of length the value of the left-hand operand, containing random elements from the right-hand operand.
  • Special cases: if the right-hand operand is empty, returns an empty list; if the left-hand operand is greater than the length of the right-hand operand, returns the right-hand operand.
3 among [1,2,3,4,5,6,7,8] → [3, 6, 7]

Top of the page

as_matrix

TO DO

at_location

same signification as translated_to operator.

Top of the page

buffer

TO DO

closest_point_to

TO DO

closest_points_with

TO DO

closest_to

TO DO

collect

  • Left-hand operand: a list, matrix, string or point.
  • Right-hand operand: an arbitrary expression.
  • Result: a list containing the result of the right-hand expressions applied to each of the elements of the left-hand operand.
  • Comments: the order of the elements is kept. In the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
[1,2,3,4] collect (each + 10) → [11, 12, 13, 14];
'abcd' collect (each > 'a') → [false, true, true, true];

Top of the page

contains_all

TO DO

contains_any

TO DO

contour_points_every

TO DO

copy_between

  • Left-hand operand: a list or a string
  • Right-hand operand: a point
  • Result: a string or a list containing the elements of the left-hand operand between the indexes provided by the x-coordinate (inclusive) and the y-coordinate (exclusive) of the right-hand operand.
  • Comments: the length of the resulting list or string is (second index - first index).
  • Special cases: if the first index is less than the second, returns an empty list or string; if the first index is less than 0, it is set to 0; if the second index is greater than the length of the left-hand operand, it is set to this length.
[1,2,3,4,5,6,7,8] copy_between {1,3} → [2,3];
'abcdefgh' between {2,5} → 'cde';

Top of the page

count

  • Left-hand operand: a list, string, matrix or point
  • Right-hand operand: a boolean expression
  • Result: an int, equal to the number of elements of the left-hand operand that make the right-hand operand evaluate to true.
  • Comments: in the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
[1,2,3,4,5,6,7,8] count (each > 3) → 5;
(list (species (self))) count ((first (each.location))> 30)  → all the agents of the same species whose x-coordinate is greater than 30.

Top of the page

crosses

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry
  • Result: a boolean, equal to true if the agent geometry crosses the geometry of the localized entity passed in parameter
  • Result type: boolean
  • Special cases:
    • if one of the operand is null, returns false
    • if one operand is a point, returns false
  • see also: intersects, <->

polyline([{10,10},{20,20}]) crosses polyline([{10,20},{20,10}])  →  true
polyline([{10,10},{20,20}]) crosses geometry({15,15})  →  false
polyline([{0,0},{25,25}]) crosses polygon([{10,10},{10,20},{20,20},{20,10}])  →  true

Top of the page

disjoint_from

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry
  • Result: a boolean, equal to true if the left-operand is disjoint from the right-operand
  • Result type: boolean
  • Special cases:
    • if one of the operand is null, returns true
    • if one operand is a point, returns false if the point is included in the geometry
  • see also: intersects, <>

polyline([{10,10},{20,20}]) disjoint_from polyline([{15,15},{25,25}])  →  false
polygon([{10,10},{10,20},{20,20},{20,10}]) disjoint_from polygon([{15,15},{15,25},{25,25},{25,15}])  →  false
polygon([{10,10},{10,20},{20,20},{20,10}]) disjoint_from geometry({15,15})  →  false
polygon([{10,10},{10,20},{20,20},{20,10}]) disjoint_from geometry({25,25})  →  true
polygon([{10,10},{10,20},{20,20},{20,10}]) disjoint_from polygon([{35,35},{35,45},{45,45},{45,35}])  →  true

Top of the page

distance_to

  • Left-hand operand: a point or an agent
  • Right-hand operand: a point or an agent
  • Result: a float, equal to the distance (in meters) between the two operands.
  • Comments: in case a GIS environment is part of the model, the pathfinder is used to compute the distance; otherwise the distance in straight line is returned.
  • Special cases: if one of the agents is not localized, returns 0.0.
((list (species (self))) - self) collect (each distance_to self) → collects the distances between self and all the agents of the same species.

Top of the page

enlarged_by

TO DO

Top of the page

first_with

  • Left-hand operand: a list, string, matrix or point
  • Right-hand operand: a boolean expression
  • Result: any value, equal to the first element of the left-hand operand that make the right-hand operand evaluate to true.
  • Comments: in the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
[1,2,3,4,5,6,7,8] first_with (each > 3) → 4;
(list species self) first_with ((first (each.location))> 30)  → the first agent of the same species whose x-coordinate is greater than 30.

Top of the page

group_by

TO DO

in

  • Left-hand operand: an expression or a list
  • Right-hand operand: a list, string, matrix or point
  • Result: if the left_hand operand is not a list, true if the left-hand operand is equal to one of the elements of the right-hand operand, otherwise false; if it is a list, returns true if all its elements are present in the right-hand operand, otherwise returns false;
3 in [1,2,3,4,5,6,7,8] → true;
[3, 10] in [1,2,3,4,5,6,7,8] → false;
'bc' in 'abcded' → true;
['a','b','cd'] in 'abcdef' → true;

Top of the page

index_of

  • see: last_index_of.

Top of the page

inside

TO DO

inter

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry, a point
  • Result: a geometry, equals the intersection between the two operands, or null if the intersection is empty.
  • Result type: geometry
  • Special cases:
    • if the right-hand operand or the left-hand operand is null, returns null.
    • if the right-hand operator is a point, returns a geometry containing this point if the left operator geometry covers the point, null otherwise.
polygon([{10,10},{10,20},{20,20},{20,10}]) inter polygon([{15,15},{15,25},{25,25},{25,15}])) 
                              → polygon([{15.0;20.0},{20.0;20.0},{20.0;15.0},{15.0;15.0},{15.0;20.0}])
polygon([{10,10},{10,20},{20,20},{20,10}]) inter {15,15}   → geometry({15.0;15.0})

Top of the page

intersection

same signification as inter operator.

Top of the page

intersects

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry, a point
  • Result: a boolean, equal to true if the left-operand intersects the right-operand
  • Result type: boolean
  • Comments: if the right-hand operand or the left-operand is not present, returns false.
square(5) intersects {10,10} → false

Top of the page

last_index_of

  • Left-hand operand: a list, string, matrix or point
  • Right-hand operand: an expression
  • Result: an int, equal to the index of the first (resp. last) occurence of the right-hand operand in the left-hand operand.
  • Comments: if the right-hand operand is not present, returns -1.
[1,2,3,4,5,6,7,8] index_of 3 → 2;
'abcdefgh' index_of 'bcf' → -1;

Top of the page

masked_by

  • Left-hand operand: any type (the operand will be casted in a geometry)
  • Right-hand operand: any type (the operand will be casted in a geometry)
  • Result: geometry representing the part of the right operand visible from the point of view of the agent using the operator while considering the obstacles defined by the left operand
  • Return type: geometry
perception_geom masked_by obstacle_geom → returns the geometry representing the part of perception_geom visible from the agent position considering the obstacle obstacle_geom

Top of the page

max_of

Top of the page

min_of

  • Left-hand operand: a list, string, matrix or point
  • Right-hand operand: an in or float expression
  • Result: an int or float, equal to the maximum (resp. minimum) value of the right-hand expression evaluated on each of the elements of the left-hand operand
  • Comments: in the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
[1,2,10,4,7,6,7,8] max_of (each * 100) → 1000;
(list (species (self))) min_of (first (each.location))  → the smallest x-coordinate of the agents of the same species as self.

Top of the page

neighbours_at

  • Left-hand operand: an agent
  • Right-hand operand: an int or float (expressing a distance in meters)
  • Result: a list, containing all the agents located in the circle of radius equal to the right-hand operand, and center the location of the left-hand operand.
  • Comments: if the left-hand operand is a grid cell, returns only grid cells of the same environment; if it is a regular agent, returns all the agents, whatever their species, save for grid cells.
  • Special cases: if the left-hand operand is a not localized agent, returns an empty list.

(self neighbours_at (10)) of_species (species (self)) → all the agents of the same species situated at a distance greater or equal to 10 of self.

Top of the page

of_generic_species

TO DO

of_species

  • Left-hand operand: a list (of agents)
  • Right-hand operand: a species expression
  • Result: a list, containing the agents of the left-hand operand whose species is that denoted by the right-hand operand.
  • Comments: in the right-hand operand, the keyword each can be used to represent, in turn, each of the elements. The expression agents of_species (species self) is equivalent to agents where (species each = species self); however, the advantage of using the first syntax is that the resulting list is correctly typed with the right species, whereas, in the second syntax, the parser cannot determine the species of the agents within the list (resulting in the need to cast it explicitely if it is to be used in an ask statement, for instance).
(self neighbours_at 10) of_species (species (self)) → all the neighbouring agents of the same species.

Top of the page

overlapping

TO DO

overlaps

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry
  • Result: a boolean, equal to true if the left-operand is not disjoint from the right-operand
  • Result type: boolean
  • Special cases:
    • if one of the operand is null, returns false
    • if one operand is a point, returns true if the point is included in the geometry
  • see also: intersects, <>, disjoint_from

polyline([{10,10},{20,20}]) overlaps polyline([{15,15},{25,25}])                                → true
polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps polygon([{15,15},{15,25},{25,25},{25,15}])  → true
polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps geometry({25,25})                           → true
polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps polygon([{35,35},{35,45},{45,45},{45,35}])  → false

polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps polyline([{10,10},{20,20}])                 → true
polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps geometry({15,15})                           → true
polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps polygon([{0,0},{0,30},{30,30}, {30,0}])     → true

polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps polygon([{15,15},{15,25},{25,25},{25,15}])  → true	
polygon([{10,10},{10,20},{20,20},{20,10}]) overlaps polygon([{10,20},{20,20},{20,30},{10,30}])  → true

Top of the page

partially_overlaps

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry
  • Result: a boolean, returns true if the left-operand geometry partially overlaps the right-operand geometry
  • Result type: boolean
  • Special case: if the right-hand operand is null, returns false.
  • Comments: if one geometry operand fully covers the other geometry operand, returns false (contrarily to the overlaps operator).
polyline([{10,10},{20,20}]) partially_overlaps polyline([{15,15},{25,25}])                                → true
polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps polygon([{15,15},{15,25},{25,25},{25,15}])  → true
polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps geometry({25,25})                           → true
polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps polygon([{35,35},{35,45},{45,45},{45,35}])  → false

polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps polyline([{10,10},{20,20}])                 → false
polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps geometry({15,15})                           → false
polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps polygon([{0,0},{0,30},{30,30}, {30,0}])     → false

polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps polygon([{15,15},{15,25},{25,25},{25,15}])  → true	
polygon([{10,10},{10,20},{20,20},{20,10}]) partially_overlaps polygon([{10,20},{20,20},{20,30},{10,30}])  → false

Top of the page

points_at

TO DO

reduced_by

TO DO

rotated_by

TO DO

select

  • see: where.

scaled_by

TO DO

Top of the page

simple_clustering_by_distance

TO DO

simple_clustering_by_envelope_distance

TO DO

simplification

TO DO

sort_by

  • Left-hand operand: a list, string, point, or matrix
  • Right-hand operand: an int, float or string expression.
  • Result: a list, containing the agents of the left-hand operand sorted in ascending order by the value of the right-hand operand when it is evaluated on them.
  • Comments: the left-hand operand is casted to a list before applying the operator. Therefore, a species value can be used directly to represent all the agents of this species. In the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
(self neighbours_at 10) sort_by (first (each.location)) → all the neighbouring agents, sorted by their x-coordinate.

Top of the page

starts_with

  • Left-hand operand: a string
  • Right-hand operand: a string
  • Result: true is the left-hand operand starts with the right-end operand.
  • Comments: equivalent to (left-hand_operand [[#index_of|index_of] right-hand_operand) = 0, but faster.

Top of the page

split_at

  • Left-hand operand: a geometry
  • Right-hand operand: a point
  • Result: a list of geometry,
    • if the left-operand is a ployline, the list contains two polylines, the two part of the left-operand slit at thea given right-operand point
    • if the right-operand is a multi-polyline, the list contains the two polylines resulting from the spliting of the polyline the closest to the point
  • Special cases:
    • if the left-operand is a point or a polygon, returns an empty list
  • Result type: list of geometry
polyline([{1,2},{4,6}]) split_at {7,6}  →  geometry([polyline([{1.0;2.0},{7.0;6.0}]),polyline([{7.0;6.0},{4.0;6.0}])])
circle(4) split_at {5,5}]  →  []

Top of the page

split_using

Top of the page

tokenize

  • Left-hand operand: a string
  • Right-hand operand: a string (delimiters)
  • Result: a list, containing the sub-strings (tokens) of the left-hand operand delimited by each of the characters of the right-hand operand.
  • Comments: delimiters themselves are excluded from the resulting list.
'to be or not to be, that is the question' split_using ' ,' → ['to','be','or','not,'to','be','that','is','the','question'].
'to be or not to be, that is the question' tokenize ' ,' → ['to','be','or','not,'to','be','that','is','the','question'].

Top of the page

touches

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry
  • Result: returns true if the left-operand geometry touches the right-operand geometry
  • Result type: boolean
  • Comment: returns true when the left-operand only touches the right-operand. When one geometry covers partially (or fully) the other one, it returns false.
polyline([{10,10},{20,20}]) touches geometry({15,15})  → false
polyline([{10,10},{20,20}]) touches geometry({10,10})  → true		
geometry({15,15}) touches geometry({15,15})            → false

polyline([{10,10},{20,20}]) touches polyline([{10,10},{5,5}])    → true 
polyline([{10,10},{20,20}]) touches polyline([{5,5},{15,15}])    → false
polyline([{10,10},{20,20}]) touches polyline([{15,15},{25,25}])  → false

polygon([{10,10},{10,20},{20,20},{20,10}]) touches polygon([{15,15},{15,25},{25,25},{25,15}])  → false
polygon([{10,10},{10,20},{20,20},{20,10}]) touches polygon([{10,20},{20,20},{20,30},{10,30}])  → true
polygon([{10,10},{10,20},{20,20},{20,10}]) touches polygon([{10,10},{0,10},{0,0},{10,0}])	   → true	 

polygon([{10,10},{10,20},{20,20},{20,10}]) touches geometry({15,15})   → false
polygon([{10,10},{10,20},{20,20},{20,10}]) touches geometry({10,15})   → true					

Top of the page

transformed_by

TO DO

translated_by

  • Left-hand operand: a geometry
  • Right-hand operand: a point
  • Result: applies a translation operation (vector (dx, dy)) to the geometry and returns the translated geoemtry
  • Return type: geometry.
  • see also: translated_to

geometry({10,10}) translated_by {5,5}	                       → geometry({15.0;15.0})
polyline([{10,10},{20,20}]) translated_by {5,5}                → polyline([{15.0;15.0},{25.0;25.0}])
polygon([{10,10},{10,20},{20,20},{20,10}]) translated_by {5,5} → polygon([{15.0;15.0},{15.0;25.0},{25.0;25.0},{25.0;15.0}])

Top of the page

translated_to

TO DO

union ( binary )

  • Left-hand operand: a geometry
  • Right-hand operand: a geometry
  • Result: the geometry composed of the union of the two operands.
  • Return type: geometry.
  • Special cases:
    • if both operands are null, returns null
    • if one of the two operands is null, return the not null operand
  • see also: union, +

polygon([{10,10},{10,20},{20,20},{20,10}]) union polygon([{15,15},{15,25},{25,25},{25,15}])  
    → polygon([{10.0;10.0},{10.0;20.0},{15.0;20.0},{15.0;25.0},{25.0;25.0},{25.0;15.0},{20.0;15.0},{20.0;10.0},{10.0;10.0}])

Top of the page

where

  • Left-hand operand: a list, string, matrix or point
  • Right-hand operand: a boolean expression
  • Result: a list containing all the elements of the left-hand operand that make the right-hand operand evaluate to true.
  • Comments: in the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
[1,2,3,4,5,6,7,8] select (each > 3) → [4, 5, 6, 7, 8];
(list species self) where ((first each.location)> 30)  → all the agents of the same species whose x-coordinate is greater than 30;
'abcdef' select (each < 'd') → ['a', 'b','c'].

Top of the page

with_max_of

  • see: with_min_of.

Top of the page

with_min_of

  • Left-hand operand: a list, string, matrix or point
  • Right-hand operand: an int, float or string expression
  • Result: a list containing the elements of the left-hand operand that maximize (resp. minimize) the value of the right-hand operand.
  • Comments: in the right-hand operand, the keyword each can be used to represent, in turn, each of the elements.
(list species self) with_max_of (each.var)  → all the agents of the same species whose variable var is equal to the current maximum value of var (equivalent to (list species self) where (each.var = max (list species self collect (each.var))) -- only faster and easier to write);
['abc', 'bcde', 'fgh', 'fffde'] with_min_of (each.length) → ['abc','fgh'].

Top of the page

with_precision

  • Left-hand operand: an int or float.
  • Right-hand operand: an int.
  • Result: round off the value of left-hand operand to the precision given by the value of right-hand operand.
12345.78943 with_precision 2 → 12345.79
123 with_precision 2 → 123.00

Top of the page

Ternary operators

? :

  • Left-hand operand: a boolean expression
  • Middle operand: an expression
  • Right-hand operand: an expression
  • Result: if the left-hand operand evaluates to true, returns the value of the middle operand, otherwise that of the right-hand operand
[10, 19, 43, 12, 7, 22] collect ((each > 20) ? 'above' : 'below') → ['below', 'below', 'above', 'below', 'below', 'above']

These functional tests can be combined together (here, the color variable takes three values with respect to the value of food, above 5, between 2 and 5, and below 2):

set color value:(food > 5) ? 'red' : ((food >= 2)? 'blue' : 'green');

Top of the page


Sign in to add a comment
Powered by Google Project Hosting