diff --git a/gama.core/src/gama/core/metamodel/population/GamaPopulation.java b/gama.core/src/gama/core/metamodel/population/GamaPopulation.java index 8ac98e8158..305a9a1da8 100644 --- a/gama.core/src/gama/core/metamodel/population/GamaPopulation.java +++ b/gama.core/src/gama/core/metamodel/population/GamaPopulation.java @@ -288,7 +288,7 @@ public GamaPopulation(final IMacroAgent host, final ISpecies species) { /* * PATRICK TAILLANDIER: the problem of having the host here is that depending on the simulation the hashcode * will be different... and this hashcode is very important for the manipulation of GamaMap thus, having two - * different hashcodes depending on the simulation makes ensure the replication of simulation So I remove the + * different hashcodes depending on the simulation ensures the replication of simulation. So I remove the * host for the moment. */ /* diff --git a/gama.core/src/gama/gaml/operators/Maths.java b/gama.core/src/gama/gaml/operators/Maths.java index c880b85406..f217fe1d11 100644 --- a/gama.core/src/gama/gaml/operators/Maths.java +++ b/gama.core/src/gama/gaml/operators/Maths.java @@ -18,6 +18,7 @@ import gama.annotations.precompiler.GamlAnnotations.test; import gama.annotations.precompiler.GamlAnnotations.usage; import gama.core.common.interfaces.IKeyword; +import gama.core.runtime.GAMA; import gama.core.runtime.IScope; import gama.core.runtime.exceptions.GamaRuntimeException; import gama.core.util.matrix.IMatrix; @@ -752,7 +753,7 @@ public static Double fact(final Integer n) { equals = "1.0"), see = "exp") public static Double ln(final IScope scope, final Double x) { - if (x <= 0) throw GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs", scope); + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs", scope), false); // return Double.MAX_VALUE; // A compromise... return Math.log(x); } @@ -777,7 +778,7 @@ public static Double ln(final IScope scope, final Double x) { value = "ln(1)", equals = "0.0")) public static Double ln(final IScope scope, final Integer x) { - if (x <= 0) throw GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs", scope); + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs", scope), false); // return Double.MAX_VALUE; // A compromise... return Math.log(x); } @@ -805,7 +806,7 @@ public static Double ln(final IScope scope, final Integer x) { equals = "1.0"), see = "ln") public static Double log(final IScope scope, final Double x) { - if (x <= 0) throw GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs", scope); + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The log operator cannot accept negative or null inputs", scope), false); // return Double.MAX_VALUE; // A compromise... return Math.log10(x.doubleValue()); } @@ -830,11 +831,78 @@ public static Double log(final IScope scope, final Double x) { value = "log(1)", equals = "0.0")) public static Double log(final IScope scope, final Integer x) { - if (x <= 0) throw GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs", scope); + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The log operator cannot accept negative or null inputs", scope), false); // return Double.MAX_VALUE; // A compromise... return Math.log10(x); } + + @operator ( + value = "log", + can_be_const = true, + category = { IOperatorCategory.ARITHMETIC }, + concept = {}) + @doc ( + value = "returns the logarithm in base b of the operand.", + examples = @example ( + value = "log(100, 100)", + equals = "1.0")) + public static Double log(final IScope scope, final Integer x, final Integer b) { + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The log operator cannot accept negative or null inputs", scope), false); + // return Double.MAX_VALUE; // A compromise... + return Math.log(x)/Math.log(b); + } + + @operator ( + value = "log", + can_be_const = true, + category = { IOperatorCategory.ARITHMETIC }, + concept = {}) + @doc ( + value = "returns the logarithm in base b of the operand.", + examples = @example ( + value = "log(100, 100.0)", + equals = "1.0")) + public static Double log(final IScope scope, final Integer x, final Double b) { + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The log operator cannot accept negative or null inputs", scope), false); + // return Double.MAX_VALUE; // A compromise... + return Math.log(x)/Math.log(b); + } + + @operator ( + value = "log", + can_be_const = true, + category = { IOperatorCategory.ARITHMETIC }, + concept = {}) + @doc ( + value = "returns the logarithm in base b of the operand.", + examples = @example ( + value = "log(100.0, 100.0)", + equals = "1.0")) + public static Double log(final IScope scope, final Double x, final Double b) { + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The log operator cannot accept negative or null inputs", scope), false); + // return Double.MAX_VALUE; // A compromise... + return Math.log(x)/Math.log(b); + } + + + @operator ( + value = "log", + can_be_const = true, + category = { IOperatorCategory.ARITHMETIC }, + concept = {}) + @doc ( + value = "returns the logarithm in base b of the operand.", + examples = @example ( + value = "log(100.0, 100)", + equals = "1.0")) + public static Double log(final IScope scope, final Double x, final Integer b) { + if (x <= 0) GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning("The log operator cannot accept negative or null inputs", scope), false); + // return Double.MAX_VALUE; // A compromise... + return Math.log(x)/Math.log(b); + } + + /** * Negate. * @@ -848,7 +916,7 @@ public static Double log(final IScope scope, final Integer x) { category = { IOperatorCategory.ARITHMETIC }, concept = { IConcept.MATH, IConcept.ARITHMETIC }) @doc ( - value = "If it is used as an unary operator, it returns the opposite of the operand.", + value = "If it is used as a unary operator, it returns the opposite of the operand.", masterDoc = true) @test ("-(-90.0) = 90.0") public static Double negate(final Double x) { diff --git a/gama.library/models/Toy Models/Life/Life.gaml b/gama.library/models/Toy Models/Life/Life.gaml index c2c3ec7406..7d5b413de3 100644 --- a/gama.library/models/Toy Models/Life/Life.gaml +++ b/gama.library/models/Toy Models/Life/Life.gaml @@ -47,8 +47,22 @@ global torus: torus_environment { } //Write the description of the model in the console action description { - write - 'Description. The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is the best-known example of a cellular automaton. The game is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input from humans. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. Every cell interacts with its eight neighbors, which are the cells that are directly horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur: \n\t 1.Any live cell with fewer than two live neighbours dies, as if caused by underpopulation. \n\t 2.Any live cell with more than three live neighbours dies, as if by overcrowding. \n\t 3.Any live cell with two or three live neighbours lives on to the next generation. \n\t 4.Any dead cell with exactly three live neighbours becomes a live cell. The initial pattern constitutes the seed of the system. The first(generation) is created by applying the above rules simultaneously to every cell in the seed�births and deaths happen simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the one before). The rules continue to be applied repeatedly to create further generations.'; + write 'Description:' ; + write 'The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970.'; + write 'It is the best-known example of a cellular automaton.'; + write 'The game is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input from humans.'; + write 'One interacts with the Game of Life by creating an initial configuration and observing how it evolves.'; + write 'The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead.'; + write 'Every cell interacts with its eight neighbors, which are the cells that are directly horizontally, vertically, or diagonally adjacent.'; + write 'At each step in time, the following transitions occur:'; + write '\t 1.Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.'; + write '\t 2.Any live cell with more than three live neighbours dies, as if by overcrowding.'; + write '\t 3.Any live cell with two or three live neighbours lives on to the next generation.'; + write '\t 4.Any dead cell with exactly three live neighbours becomes a live cell.'; + write 'The initial pattern constitutes the seed of the system.'; + write 'The first generation is created by applying the above rules simultaneously to every cell in the seed; births and deaths happen simultaneously,'; + write 'and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the one before).'; + write 'The rules continue to be applied repeatedly to create further generations.'; } }