diff --git a/irit.gama.feature.switchproject/.project b/irit.gama.feature.switchproject/.project deleted file mode 100644 index 44455199..00000000 --- a/irit.gama.feature.switchproject/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - irit.gama.feature.switchproject - - - - - - org.eclipse.pde.FeatureBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.pde.FeatureNature - - diff --git a/irit.gama.feature.switchproject/.settings/org.eclipse.core.resources.prefs b/irit.gama.feature.switchproject/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c02..00000000 --- a/irit.gama.feature.switchproject/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/irit.gama.feature.switchproject/.settings/org.eclipse.m2e.core.prefs b/irit.gama.feature.switchproject/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1..00000000 --- a/irit.gama.feature.switchproject/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/irit.gama.feature.switchproject/build.properties b/irit.gama.feature.switchproject/build.properties deleted file mode 100644 index 64f93a9f..00000000 --- a/irit.gama.feature.switchproject/build.properties +++ /dev/null @@ -1 +0,0 @@ -bin.includes = feature.xml diff --git a/irit.gama.feature.switchproject/feature.xml b/irit.gama.feature.switchproject/feature.xml deleted file mode 100644 index f00eeaa3..00000000 --- a/irit.gama.feature.switchproject/feature.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - [Enter Feature Description here.] - - - - [Enter Copyright Description here.] - - - - [Enter License Description here.] - - - - - diff --git a/irit.gama.feature.switchproject/pom.xml b/irit.gama.feature.switchproject/pom.xml deleted file mode 100644 index 1553d7f0..00000000 --- a/irit.gama.feature.switchproject/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ - - 4.0.0 - irit.gama - irit.gama.feature.switchproject - eclipse-feature - - msi.gama - msi.gama.experimental.parent - 1.9.2-SNAPSHOT - ../msi.gama.experimental.parent/ - - 1.0.0-SNAPSHOT - diff --git a/irit.gama.switchproject/.classpath b/irit.gama.switchproject/.classpath deleted file mode 100644 index e12039a5..00000000 --- a/irit.gama.switchproject/.classpath +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/irit.gama.switchproject/.factorypath b/irit.gama.switchproject/.factorypath deleted file mode 100644 index d9cd5ba5..00000000 --- a/irit.gama.switchproject/.factorypath +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/irit.gama.switchproject/.project b/irit.gama.switchproject/.project deleted file mode 100644 index 2858fe20..00000000 --- a/irit.gama.switchproject/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - irit.gama.switchproject - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/irit.gama.switchproject/.settings/org.eclipse.jdt.apt.core.prefs b/irit.gama.switchproject/.settings/org.eclipse.jdt.apt.core.prefs deleted file mode 100644 index 5d293658..00000000 --- a/irit.gama.switchproject/.settings/org.eclipse.jdt.apt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.apt.aptEnabled=true -org.eclipse.jdt.apt.genSrcDir=gaml -org.eclipse.jdt.apt.genTestSrcDir=.apt_generated_tests -org.eclipse.jdt.apt.reconcileEnabled=true diff --git a/irit.gama.switchproject/.settings/org.eclipse.jdt.core.prefs b/irit.gama.switchproject/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 072f301b..00000000 --- a/irit.gama.switchproject/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,16 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning -org.eclipse.jdt.core.compiler.processAnnotations=enabled -org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 diff --git a/irit.gama.switchproject/META-INF/MANIFEST.MF b/irit.gama.switchproject/META-INF/MANIFEST.MF deleted file mode 100644 index 8b97689e..00000000 --- a/irit.gama.switchproject/META-INF/MANIFEST.MF +++ /dev/null @@ -1,19 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: SwITCh Project -Bundle-SymbolicName: irit.gama.switchproject;singleton:=true -Bundle-Version: 1.0.0.qualifier -Automatic-Module-Name: irit.gama.switchproject -Bundle-RequiredExecutionEnvironment: JavaSE-17 -Require-Bundle: msi.gama.core, - msi.gama.ext -Export-Package: irit.gama.common.interfaces, - irit.gama.util.deque, - irit.gama.util.event_manager, - irit.gaml.architecure.event_manager, - irit.gaml.operators, - irit.gaml.skills.logging, - irit.gaml.skills.scheduling, - irit.gaml.skills.traffic, - irit.gaml.statements, - irit.gaml.types diff --git a/irit.gama.switchproject/build.properties b/irit.gama.switchproject/build.properties deleted file mode 100644 index f6d617de..00000000 --- a/irit.gama.switchproject/build.properties +++ /dev/null @@ -1,6 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - models/ diff --git a/irit.gama.switchproject/models/QueueEventManaged/.project b/irit.gama.switchproject/models/QueueEventManaged/.project deleted file mode 100644 index e7b6003e..00000000 --- a/irit.gama.switchproject/models/QueueEventManaged/.project +++ /dev/null @@ -1,19 +0,0 @@ - - - QueueEventManaged - switchproject plugin - - - - - org.eclipse.xtext.ui.shared.xtextBuilder - - - - - - org.eclipse.xtext.ui.shared.xtextNature - msi.gama.application.gamaNature - msi.gama.application.pluginNature - - diff --git a/irit.gama.switchproject/models/QueueEventManaged/models/Road.gaml b/irit.gama.switchproject/models/QueueEventManaged/models/Road.gaml deleted file mode 100644 index c161af3e..00000000 --- a/irit.gama.switchproject/models/QueueEventManaged/models/Road.gaml +++ /dev/null @@ -1,170 +0,0 @@ -/** -* Name: Queue -* Queue and event manager demo. -* Author: Jean-François Erdelyi -* Tags: -*/ -model Road - -/** - * Initialisation of the model - */ -global { -// Road and cars params - float road_width <- 3.5 #m const: true; - float road_height <- 30 #m const: true; - float car_width <- 1.5 #m const: true; - float car_height <- 4.0 #m const: true; - - // Shape of the world - geometry shape <- rectangle(road_width, road_height); - - // Temporal param - float step <- 1 #s; - date starting_date <- date([1970, 1, 1, 0, 0, 0]); - - // Cars generator rate (+1 => arithmetic error if value is 0) - int generate_frequency <- 2 update: rnd(1, 10) + 1; - - // Create manager and road - init { - create manager; - create queue_road; - } - - // Generate cars - reflex generate when: (cycle mod generate_frequency) = 0 { - ask (queue_road) { - do add_car(); - } - - } - -} - -/** - * Event manager species - */ -species manager control: event_manager { - - // Reflex to write the size of event queues - reflex write_size { - write "[" + name + "]::[write_size] manager size = " + size + " at " + (starting_date + time); - } - -} - -/** - * The car species with scheduling skill in order to use the action 'later' - */ -species car skills: [scheduling] { - // General aspect - geometry shape <- rectangle(car_width, car_height) at_location point(road_width / 2.0, road_height); - rgb color <- rnd_color(255); - - // The event manager used to schedule cars - agent event_manager <- manager[0]; - - // Last word and die - action die_in_peace (string last_word) { - write "Peace " + last_word; - ask queue_road[0] { - do change_locations; - } - - do later the_action: "die" at: (event_date + 1); - } - - // Default aspect - aspect default { - draw shape color: color; - } - -} - -/** - * The queue road species with scheduling skill in order to use the action 'later' - */ -species queue_road skills: [scheduling] { - // Capacity - int nb_car_max <- 5; - - // Representation of cars inside the road - queue cars_queue; - - // General aspect - geometry shape <- rectangle(road_width, road_height) at_location point(road_width / 2.0, road_height / 2.0); - - // Free flow travel time (fake) - int time_to_travel <- 10; - - // The event manager used to schedule road - agent event_manager <- manager[0]; - - // Pop car - action pop_car { - write "Pop car at: " + event_date; - - // Pop car - if (length(cars_queue) > 0) { - car c <- pop(cars_queue); - - // Die - ask c { - do later the_action: "die_in_peace" with_arguments: map("last_word"::"OK"); // at is null -> no - } - - } - - } - - // Change location of each cars - action change_locations { - int i <- 0; - loop c over: car { - c.location <- {road_width / 2.0, c.location.y - (car_height + (car_height / 2.0))}; - i <- i + 1; - } - - } - - // Add new car - action add_car { - if (length(cars_queue) < nb_car_max) { - // Create and get new car - create car returns: new_cars; - car new_car <- new_cars[0]; - - // Set location and time - new_car.location <- {road_width / 2.0, length(cars_queue) * (car_height + (car_height / 2.0)) + 0.5 + (car_height / 2.0)}; - date t <- starting_date + time + (time_to_travel); - - // Push car to queue - push item: new_car to: cars_queue; - - // Schedule pop - do later the_action: "pop_car" at: t; - } - - } - - // Default aspect - aspect default { - draw shape color: rgb(255 * (1 - (nb_car_max - length(cars_queue)) / nb_car_max), 0, 0); - } - -} - -/** - * Experiments - */ -experiment Road type: gui { - output { - display main_window type: opengl { - species queue_road; - species car; - } - - } - -} diff --git a/irit.gama.switchproject/models/QueueEventManaged/models/Test Simple.gaml b/irit.gama.switchproject/models/QueueEventManaged/models/Test Simple.gaml deleted file mode 100644 index 9927fafb..00000000 --- a/irit.gama.switchproject/models/QueueEventManaged/models/Test Simple.gaml +++ /dev/null @@ -1,57 +0,0 @@ -/** -* Name: TestSimple -* Based on the internal empty template. -* Author: benoitgaudou -* Tags: -*/ - - -model TestSimple - -global { - // Temporal param - float step <- 1 #s; - date starting_date <- date([1970, 1, 1, 0, 0, 0]); - - init { - create manager; - create people number: 2; - - ask people { - loop t from: 10 to: 100 step: 10 { - do later the_action: "info" at: starting_date + t#s refer_to: people(0) ; - } - } - } -} - -/** - * Event manager species - */ -species manager control: event_manager { - - // Reflex to write the size of event queues - reflex write_size { - write "[" + name + "]::[write_size] manager size = " + size + " at " + (starting_date + time); - } - -} - -/** - * The car species with scheduling skill in order to use the action 'later' - */ -species people skills: [scheduling] { - // The event manager used to schedule cars - agent event_manager <- manager[0]; - - action info { - write sample(self) + " - " + sample(current_date) + ' - ' + sample(cycle); - } -} - - -experiment name type: gui { - output { - - } -} \ No newline at end of file diff --git a/irit.gama.switchproject/models/Simple IDM/.project b/irit.gama.switchproject/models/Simple IDM/.project deleted file mode 100644 index b1a54726..00000000 --- a/irit.gama.switchproject/models/Simple IDM/.project +++ /dev/null @@ -1,19 +0,0 @@ - - - Simple IDM - switchproject plugin - - - - - org.eclipse.xtext.ui.shared.xtextBuilder - - - - - - org.eclipse.xtext.ui.shared.xtextNature - msi.gama.application.gamaNature - msi.gama.application.pluginNature - - diff --git a/irit.gama.switchproject/models/Simple IDM/includes/road.cpg b/irit.gama.switchproject/models/Simple IDM/includes/road.cpg deleted file mode 100644 index 3ad133c0..00000000 --- a/irit.gama.switchproject/models/Simple IDM/includes/road.cpg +++ /dev/null @@ -1 +0,0 @@ -UTF-8 \ No newline at end of file diff --git a/irit.gama.switchproject/models/Simple IDM/includes/road.dbf b/irit.gama.switchproject/models/Simple IDM/includes/road.dbf deleted file mode 100644 index c3e72bbc..00000000 Binary files a/irit.gama.switchproject/models/Simple IDM/includes/road.dbf and /dev/null differ diff --git a/irit.gama.switchproject/models/Simple IDM/includes/road.prj b/irit.gama.switchproject/models/Simple IDM/includes/road.prj deleted file mode 100644 index f45cbadf..00000000 --- a/irit.gama.switchproject/models/Simple IDM/includes/road.prj +++ /dev/null @@ -1 +0,0 @@ -GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] \ No newline at end of file diff --git a/irit.gama.switchproject/models/Simple IDM/includes/road.qix b/irit.gama.switchproject/models/Simple IDM/includes/road.qix deleted file mode 100644 index 760cc37b..00000000 Binary files a/irit.gama.switchproject/models/Simple IDM/includes/road.qix and /dev/null differ diff --git a/irit.gama.switchproject/models/Simple IDM/includes/road.shp b/irit.gama.switchproject/models/Simple IDM/includes/road.shp deleted file mode 100644 index df632411..00000000 Binary files a/irit.gama.switchproject/models/Simple IDM/includes/road.shp and /dev/null differ diff --git a/irit.gama.switchproject/models/Simple IDM/includes/road.shx b/irit.gama.switchproject/models/Simple IDM/includes/road.shx deleted file mode 100644 index b5efdb5d..00000000 Binary files a/irit.gama.switchproject/models/Simple IDM/includes/road.shx and /dev/null differ diff --git a/irit.gama.switchproject/models/Simple IDM/models/IDM Skill.gaml b/irit.gama.switchproject/models/Simple IDM/models/IDM Skill.gaml deleted file mode 100644 index 86feabf2..00000000 --- a/irit.gama.switchproject/models/Simple IDM/models/IDM Skill.gaml +++ /dev/null @@ -1,87 +0,0 @@ -model IDM - -// Car species using IDM skill -species car skills: [idm] { - // Default shape, length is an IDM parameter - geometry default_shape <- rectangle(length, 1.5); - // The car target - point the_target; - // The next car - car next_car <- nil; - - // Relfex move, using supersedes goto (from moving skill) - reflex move { - // Do goto to target, on the graph and follow the next car - do goto target: the_target on: the_graph follow: next_car; - - // If location is reached then kill the car - if location = the_target { - do die(); - } - - } - - // Default aspect, rotate the default shape in the right direction - aspect default { - // Rotate default shape - shape <- default_shape rotated_by heading at_location location; - draw shape color: #blue; - } - -} - -// Simple road species -species road { - aspect default { - draw shape color: #grey; - } - -} - -// The world -global { - // Generator frequency in cycle - int generate_frequency <- 20; - // Time step - float step <- 0.1; - // Last created car - car last_car <- nil; - - // Road shapefile - file road_shapefile <- file("../includes/road.shp"); - // The road graph - graph the_graph; - // World shape - geometry shape <- envelope(road_shapefile); - - - // Init the world - init { - // Create roads and the graph - create road from: road_shapefile; - the_graph <- as_edge_graph(road); - } - - // Car generator - reflex generate when: (cycle mod generate_frequency) = 0 { - // Create car start from the begining of the road and the target is the end of the road - create car { - location <- first(road[0].shape.points); - the_target <- last(road[0].shape.points); - next_car <- last_car; - last_car <- self; - } - } - -} - -// Experiment -experiment "IDM using IDM skill" { - output { - display "IDM skill" type: opengl { - species road; - species car; - } - - } -} diff --git a/irit.gama.switchproject/models/Simple IDM/models/IDM.gaml b/irit.gama.switchproject/models/Simple IDM/models/IDM.gaml deleted file mode 100644 index 8656f4d9..00000000 --- a/irit.gama.switchproject/models/Simple IDM/models/IDM.gaml +++ /dev/null @@ -1,110 +0,0 @@ -model IDM - -// Car species using moving skill: implement IDM -species car skills: [moving] { - // Default shape, length is an IDM parameter - geometry default_shape <- rectangle(lenght, 1.5); - // The car target - point the_target; - // The next car - car next_car <- nil; - - // IDM params - float lenght <- 5.0 #m; - float desired_speed <- 30.0 #m / #s; - float spacing <- 1.0 #m; - float reaction_time <- 1.5 #s; - float max_acceleration <- 4.0 #m / #s ^ 2; - float desired_deceleration <- 3.0 #m / #s ^ 2; - - // Dynamic params - float acceleration <- 0.0 min: -desired_deceleration max: max_acceleration #m / #s ^ 2; - float speed <- 0.0 #m / #s; - - // Move reflex - reflex move { - // Check if this is the first car or not - if next_car = nil or dead(next_car) { - // Compute acceleration - acceleration <- max_acceleration * (1 - ((speed / desired_speed) ^ 4.0)); - } else { - // Compute acceleration with the next car - float delta_speed <- next_car.speed - speed; - float actual_gap <- (self distance_to next_car using topology(the_graph)) - lenght; - float desired_minimum_gap <- spacing + (reaction_time * speed) - ((speed * delta_speed) / (2 * sqrt(max_acceleration * desired_deceleration))); - acceleration <- max_acceleration * (1 - ((speed / desired_speed) ^ 4.0) - ((desired_minimum_gap / actual_gap) ^ 2)); - } - - // Compute speed and goto - speed <- speed + (acceleration * step); - do goto on: the_graph target: the_target speed: speed; - if location = the_target { - do die(); - } - - } - - // Default aspect, rotate the default shape in the right direction - aspect default { - // Rotate default shape - shape <- default_shape rotated_by heading at_location location; - draw shape color: #blue; - } - -} - -// Simple road species -species road { - aspect default { - draw shape color: #grey; - } - -} - -// The world -global { - // Generator frequency in cycle - int generate_frequency <- 20; - // Time step - float step <- 0.1; - // Last created car - car last_car <- nil; - - // Road shapefile - file road_shapefile <- file("../includes/road.shp"); - // The road graph - graph the_graph; - // World shape - geometry shape <- envelope(road_shapefile); - - - // Init the world - init { - // Create roads and the graph - create road from: road_shapefile; - the_graph <- as_edge_graph(road); - } - - // Car generator - reflex generate when: (cycle mod generate_frequency) = 0 { - // Create car start from the begining of the road and the target is the end of the road - create car { - location <- first(road[0].shape.points); - the_target <- last(road[0].shape.points); - next_car <- last_car; - last_car <- self; - } - } - -} - -// Experiment -experiment "IDM using moving skill" { - output { - display "IDM moving skill" type: opengl { - species road; - species car; - } - - } -} diff --git a/irit.gama.switchproject/plugin.xml b/irit.gama.switchproject/plugin.xml deleted file mode 100644 index 5779e40e..00000000 --- a/irit.gama.switchproject/plugin.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - diff --git a/irit.gama.switchproject/pom.xml b/irit.gama.switchproject/pom.xml deleted file mode 100644 index dad53e9e..00000000 --- a/irit.gama.switchproject/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ - - 4.0.0 - irit.gama - irit.gama.switchproject - eclipse-plugin - - msi.gama - msi.gama.experimental.parent - 1.9.2-SNAPSHOT - ../msi.gama.experimental.parent/ - - 1.0.0-SNAPSHOT - \ No newline at end of file diff --git a/irit.gama.switchproject/src/irit/gama/common/interfaces/IKeywordIrit.java b/irit.gama.switchproject/src/irit/gama/common/interfaces/IKeywordIrit.java deleted file mode 100644 index 6eaee9d0..00000000 --- a/irit.gama.switchproject/src/irit/gama/common/interfaces/IKeywordIrit.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************************************* - * - * IKeywordIrit.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.common.interfaces; - -/** - * Keywords of IRIT - * - * @author Jean-François Erdelyi - */ -public interface IKeywordIrit { - - public static final String ID = "id"; - - /** - * Queue and stack keywords - */ - public static final String QUEUE = "queue"; - public static final String STACK = "stack"; - - public static final String QUEUE_OPERATOR = "Queue-related operators"; - public static final String STACK_OPERATOR = "Stack-related operators"; - - public static final int DEQUE_TYPE = 666; - public static final int QUEUE_TYPE = 667; - public static final int STACK_TYPE = 668; - - public static final String PUSH = "push"; - - /** - * Scheduling keywords - */ - public static final String EVENT_MANAGER = "event_manager"; - - public static final String EVENT = "event"; - public static final String EVENTS = "events"; - public static final String EVENT_DATE = "event_date"; - - public static final String THE_ACTION = "the_action"; - public static final String WITH_ARGUMENTS = "with_arguments"; - public static final String AT = "at"; - public static final String REFER_TO = "refer_to"; - public static final String CALLER = "caller"; - - public static final String SIZE_BY_AGENT = "size_by_agent"; - - public static final String SCHEDULING = "scheduling"; - - /** - * Logger keywords - */ - public static final String LOGGING = "logging"; - - public static final String FLUSH = "flush"; - public static final String LOGBOOK = "logbook"; - public static final String LOG_DATA = "log_data"; - public static final String FILE_NAME = "file_name"; - public static final String SECTION = "section"; - public static final String ENTRY = "entry"; - public static final String VALUE = "value"; - public static final String DATE = "date"; - public static final String X = "x"; - public static final String Y = "y"; - - /** - * IDM - */ - public static final String IDM = "idm"; - public static final String VEHICLE_LENGTH = "length"; - public static final String IDM_DESIRED_SPEED = "desired_speed"; - public static final String IDM_SPACING = "spacing"; - public static final String IDM_REACTION_TIME = "reaction_time"; - public static final String IDM_MAX_ACCELERATION = "max_acceleration"; - public static final String IDM_DESIRED_DECELERATION = "desired_deceleration"; - - public static final String IDM_ACCELERATION = "acceleration"; - public static final String IDM_DELTA_SPEED = "delta_speed"; - public static final String IDM_ACTUAL_GAP = "actual_gap"; - public static final String IDM_DESIRED_MINIMUM_GAP = "desired_minimum_gap"; - - /** - * Event Queue Road - */ - public static final String EVENT_QUEUE = "event_queue"; - public static final String BPR_ALPHA = "alpha"; - public static final String BPR_BETA = "beta"; - public static final String EVENT_QUEUE_VOLUME = "volume"; - public static final String EVENT_QUEUE_LENGTH = "length"; - - /** - * Roads - */ - public static final String ROAD = "road"; - public static final String ROAD_NODE = "road_node"; - public static final String ROADS_IN = "roads_in"; - public static final String ROADS_OUT = "roads_out"; - public final static String AGENTS = "all_agents"; - - public final static String ALL_ENTITIES = "all_entities"; - public final static String NODE_IN = "node_in"; - public final static String NODE_OUT = "node_out"; - public final static String MAXSPEED = "maxspeed"; - -} diff --git a/irit.gama.switchproject/src/irit/gama/util/deque/GamaDeque.java b/irit.gama.switchproject/src/irit/gama/util/deque/GamaDeque.java deleted file mode 100644 index 19e657cf..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/deque/GamaDeque.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************************************* - * - * GamaDeque.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.deque; - -import java.util.ArrayDeque; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import msi.gama.common.util.StringUtils; -import msi.gama.metamodel.shape.GamaPoint; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaListFactory; -import msi.gama.util.GamaMapFactory; -import msi.gama.util.IContainer; -import msi.gama.util.IList; -import msi.gama.util.IMap; -import msi.gama.util.matrix.IMatrix; -import msi.gaml.types.GamaIntegerType; -import msi.gaml.types.GamaMatrixType; -import msi.gaml.types.IContainerType; -import msi.gaml.types.IType; -import msi.gaml.types.Types; - -/** - * Deque used for Queue and Stack types - * - * @author Jean-François Erdelyi - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class GamaDeque extends ArrayDeque implements IContainer { - - // ############################################ - // Attributs - - /** - * The serializable class does not declare a static final serialVersionUID field - * of type long - */ - private static final long serialVersionUID = 1L; - - /** - * GAMA type - */ - protected IContainerType type; - - // ############################################ - // Constructors - - /** - * Default constructor - */ - public GamaDeque(IContainerType contentsType) { - super(); - type = contentsType; - } - - /** - * Constructor with values and type (List) - */ - public GamaDeque(IContainerType contentsType, List values) { - super(); - type = contentsType; - addAll(values); - } - - /** - * Constructor with values and type (array) - */ - public GamaDeque(IContainerType contentsType, T[] values) { - super(); - type = contentsType; - addAll(values); - } - - /** - * Constructor with values and type (Collection) - */ - public GamaDeque(IContainerType contentsType, Collection values) { - super(); - type = contentsType; - addAll(values); - } - - /** - * Copy constructor - */ - public GamaDeque(GamaDeque gq) { - super(gq.clone()); - type = gq.getGamlType(); - } - - // ############################################ - // Methods - - /** - * Add all values (List) - */ - private void addAll(List values) { - for (T v : values) { - add(v); - } - } - - /** - * Add all values (array) - */ - private void addAll(T[] values) { - for (T v : values) { - add(v); - } - } - - /** - * Build value - */ - public T buildValue(final IScope scope, final Object object) { - final IType ct = getGamlType().getContentType(); - return (T) ct.cast(scope, object, null, false); - } - - /** - * Build values - */ - public GamaDeque buildValues(final IScope scope, final IContainer objects) { - return (GamaDeque) getGamlType().cast(scope, objects, null, false); - } - - /** - * Build index - */ - public Integer buildIndex(final IScope scope, final Object object) { - return GamaIntegerType.staticCast(scope, object, null, false); - } - - // ############################################ - // Override: methods - - /** - * To string - */ - @Override - public String stringValue(IScope scope) throws GamaRuntimeException { - return serialize(false); - } - - /** - * Serialization (like a list) - */ - @Override - public String serialize(final boolean includingBuiltIn) { - final StringBuilder sb = new StringBuilder(size() * 10); - Object[] values = toArray(); - - sb.append('['); - for (int i = 0; i < size(); i++) { - if (i != 0) { - sb.append(','); - } - sb.append(StringUtils.toGaml(values[i], includingBuiltIn)); - } - sb.append(']'); - - return sb.toString(); - } - - /** - * Clone data - */ - @Override - public GamaDeque copy(IScope scope) throws GamaRuntimeException { - return new GamaDeque(this); - } - - /** - * Get GAMA type - */ - @Override - public IContainerType getGamlType() { - return type; - } - - /** - * Return true if the value exists in the collection - */ - @Override - public boolean contains(IScope scope, Object o) throws GamaRuntimeException { - return contains(o); - } - - /** - * Check if the "key" exists (index here) - */ - @Override - public boolean containsKey(IScope scope, Object o) throws GamaRuntimeException { - if (o instanceof Integer) { - final Integer i = (Integer) o; - return i >= 0 && i < this.size(); - } - return false; - } - - /** - * Get first value - */ - @Override - public T firstValue(IScope scope) throws GamaRuntimeException { - return getFirst(); - } - - /** - * Get last value - */ - @Override - public T lastValue(IScope scope) throws GamaRuntimeException { - return getLast(); - } - - /** - * Get random value - */ - @Override - public T anyValue(IScope scope) { - final int i = scope.getRandom().between(0, 1); - return i == 0 ? getFirst() : getLast(); - } - - /** - * Get the number of values - */ - @Override - public int length(IScope scope) { - return size(); - } - - /** - * True if the collection is empty - */ - @Override - public boolean isEmpty(IScope scope) { - return isEmpty(); - } - - // ############################################ - // Override: methods about values - - /** - * Get the list of values (is "equivalent" to toArray()) - */ - @Override - public IList listValue(IScope scope, IType contentType, boolean copy) { - // return GamaListFactory.wrap(contentType, toArray()); - List list = Arrays.asList(toArray()); - return (IList) GamaListFactory.wrap(contentType, list); - } - - /** - * Return iterable collection - */ - @Override - public Iterable iterable(IScope scope) { - return (Iterable) listValue(scope, Types.NO_TYPE, false); - } - - /** - * Reverse the collection: useless ? - */ - @Override - public IContainer reverse(IScope scope) throws GamaRuntimeException { - List list = Arrays.asList(toArray()); - Collections.reverse(list); - return new GamaDeque(type, list); - } - - /** - * Return a map from values: deque does not allow this - */ - @Override - public IMap mapValue(IScope scope, IType keyType, IType contentType, boolean copy) { - final IMap result = GamaMapFactory.create(keyType, contentType); - result.setAllValues(scope, toArray()); - return result; - } - - /** - * Return matrix from values - */ - @Override - public IMatrix matrixValue(IScope scope, IType contentType, boolean copy) { - return matrixValue(scope, contentType, null, copy); - } - - /** - * Return matrix from values with prefered size - */ - @Override - public IMatrix matrixValue(IScope scope, IType contentType, GamaPoint size, boolean copy) { - return GamaMatrixType.from(scope, listValue(scope, contentType, copy), contentType, size); - - } -} diff --git a/irit.gama.switchproject/src/irit/gama/util/deque/GamaQueue.java b/irit.gama.switchproject/src/irit/gama/util/deque/GamaQueue.java deleted file mode 100644 index 738b9b7d..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/deque/GamaQueue.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************************************* - * - * GamaQueue.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.deque; - -import java.util.Collection; - -import msi.gama.runtime.IScope; -import msi.gaml.types.IType; -import irit.gaml.operators.IDequeOperator; -import irit.gaml.types.TypesIrit; - -/** - * Queue type used by GAML type - * - * @author Jean-François Erdelyi - */ -public class GamaQueue extends GamaDeque implements IDequeOperator { - - // ############################################ - // Attributes - - /** - * The serializable class does not declare a static final serialVersionUID field - * of type long - */ - private static final long serialVersionUID = 1L; - - // ############################################ - // Constructors - - /** - * Constructor - */ - public GamaQueue(IType contentsType) { - super(TypesIrit.QUEUE.of(contentsType)); - } - - /** - * Constructor with data - */ - public GamaQueue(IType contentsType, T[] values) { - super(TypesIrit.QUEUE.of(contentsType), values); - } - - /** - * Constructor with data - */ - public GamaQueue(IType contentsType, Collection values) { - super(TypesIrit.QUEUE.of(contentsType), values); - } - - // ############################################ - // Override : IDequeOperator - - /** - * Pop data from queue (FIFO) - */ - @Override - public T pop(IScope scope) { - return pollFirst(); - } -} diff --git a/irit.gama.switchproject/src/irit/gama/util/deque/GamaStack.java b/irit.gama.switchproject/src/irit/gama/util/deque/GamaStack.java deleted file mode 100644 index fea9b39b..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/deque/GamaStack.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************************************* - * - * GamaStack.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.deque; - -import java.util.Collection; - -import msi.gama.runtime.IScope; -import msi.gaml.types.IType; -import irit.gaml.operators.IDequeOperator; -import irit.gaml.types.TypesIrit; - -/** - * Stack type used by GAML type - * - * @author Jean-François Erdelyi - */ -public class GamaStack extends GamaDeque implements IDequeOperator { - - // ############################################ - // Attributes - - /** - * The serializable class does not declare a static final serialVersionUID field - * of type long - */ - private static final long serialVersionUID = 1L; - - // ############################################ - // Constructors - - /** - * Constructor - */ - public GamaStack(IType contentsType) { - super(TypesIrit.STACK.of(contentsType)); - } - - /** - * Constructor with data - */ - public GamaStack(IType contentsType, T[] values) { - super(TypesIrit.STACK.of(contentsType), values); - } - - /** - * Constructor with data - */ - public GamaStack(IType contentsType, Collection values) { - super(TypesIrit.STACK.of(contentsType), values); - } - - // ############################################ - // Override : IDequeOperator - - /** - * Pop data from queue (LIFO) - */ - @Override - public T pop(IScope scope) { - return pollLast(); - } -} diff --git a/irit.gama.switchproject/src/irit/gama/util/event_manager/Event.java b/irit.gama.switchproject/src/irit/gama/util/event_manager/Event.java deleted file mode 100644 index 10904dcc..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/event_manager/Event.java +++ /dev/null @@ -1,322 +0,0 @@ -/******************************************************************************************************* - * - * Event.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.event_manager; - -import java.time.ZoneOffset; -import java.util.Comparator; -import java.util.UUID; - -import irit.gama.common.interfaces.IKeywordIrit; -import msi.gama.metamodel.agent.IAgent; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaDate; -import msi.gama.util.GamaMap; -import msi.gama.util.IList; -import msi.gaml.descriptions.ActionDescription; -import msi.gaml.species.ISpecies; -import msi.gaml.statements.Arguments; -import msi.gaml.statements.IStatement; -import msi.gaml.types.IType; - -/** - * Event used by the event manager - * - * @author Jean-François Erdelyi - */ -public class Event { - - // ############################################ - // Comparator - - /** - * Event comparator -> priority queue - */ - public static class EventComparator implements Comparator { - // Current scope - IScope scope; - - /** - * Random used if equals - */ - EventComparator(IScope scope) { - this.scope = scope; - } - - /* - @Override - public int compare(Event x, Event y) { - if (x.getDate().isSmallerThan(y.getDate(), true)) { - return -1; - } - if (x.getDate().isGreaterThan(y.getDate(), true)) { - return 1; - } - // In order to randomize if the event A and B are equals - return ((int) scope.getRandom().between(0, 1) < 1) ? -1 : 1; - } - */ - - public int compare(Event x, Event y) { - if (x.milli < y.milli) { - return -1; - } - if (x.milli > y.milli) { - return 1; - } - // In order to randomize if the event A and B are equals - return ((int) scope.getRandom().between(0, 1) < 1) ? -1 : 1; - } - } - - // ############################################ - // Attributes - - /** - * Message ID - */ - UUID id = null; - - /** - * The execution date - */ - private GamaDate date; - - /** - * The execution date (milli) - */ - private long milli; - - /** - * Simulation scope - */ - private IScope scope; - - /** - * Species - */ - private String species; - - /** - * Executer - */ - private IStatement.WithArgs action; - - /** - * Arguments - */ - private Arguments arguments; - - /** - * Referred agent - */ - private IAgent referredAgent; - - /** - * Caller agent - */ - private IAgent agent; - - /** - * Is alive - */ - private boolean isAlive; - - // ############################################ - // Constructor - - /** - * Create a new event with action and Arguments as map - */ - public Event(IScope scope, IAgent caller, ActionDescription action, final GamaMap args, - GamaDate date, IAgent referredAgent) { - - this.scope = scope.copy("Later"); - this.species = caller.getSpeciesName(); - this.agent = caller; - this.referredAgent = referredAgent; - this.isAlive = true; - this.id = UUID.randomUUID(); - - // Get arguments - arguments = action.createCompiledArgs().resolveAgainst(scope); - - // Convert arguments and insert it in the current scope - IList keys = args.getKeys(); - for (String key : keys) { - IType type = this.scope.getType(key); - final Object val = type.cast(this.scope, args.get(key), null, true); - this.scope.addVarWithValue(key, val); - } - - // Set action by name - setAction(action.getName()); - setDate(date); - } - - // ############################################ - // Methods - - /** - * Set date - */ - private void setDate(GamaDate date) throws GamaRuntimeException { - if (date != null) { - this.date = date.copy(scope); - this.milli = date.getLocalDateTime().atZone(ZoneOffset.UTC).toInstant().toEpochMilli(); - } else { - this.date = null; - this.milli = 0; - } - } - - /** - * Set Action - */ - private void setAction(String actionName) throws GamaRuntimeException { - // Get target species - final ISpecies species = getSpecies(); - if (species == null) { - throw GamaRuntimeException.error("Impossible to find a species to execute " + actionName, scope); - } - - // Get action - action = species.getAction(actionName); - if (action == null) { - throw GamaRuntimeException.error("Impossible to find action " + actionName + " in " + species, scope); - } - } - - /** - * Get arguments - */ - private Arguments getRuntimeArgs() throws GamaRuntimeException { - if (arguments == null) { - return null; - } - return arguments.resolveAgainst(scope); - } - - /** - * Get Species - */ - private ISpecies getSpecies() throws GamaRuntimeException { - return species != null ? scope.getModel().getSpecies(species) : scope.getAgent().getSpecies(); - } - - /** - * Get date - */ - public GamaDate getDate() { - return date; - } - - /** - * Get date - */ - public IScope getScope() { - return scope; - } - - /** - * Get date - */ - public long getMilli() { - return milli; - } - - /** - * Get caller - */ - public IAgent getAgent() { - return agent; - } - - /** - * Get id - */ - public UUID getId() { - return id; - } - - /** - * Is greater than the event e - */ - public boolean isGreaterThan(Event e) { - return milli > e.milli; - } - - /** - * True if the time of the next event is reached - */ - public boolean isTimeReached() { - return scope.getClock().getCurrentDate().isGreaterThan(date, false); - } - - /** - * Execute the action - */ - public boolean execute() { - if (!this.isAlive) { - return false; - } - /*DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss.SSS"); - - LocalDateTime dateTime = LocalDateTime.now(); - System.out.println("EXEC START " + dateTime.format(formatter));*/ - if (date == null) { - date = scope.getClock().getCurrentDate(); - } - scope.getAgent().setAttribute(IKeywordIrit.EVENT_DATE, date); - scope.getAgent().setAttribute(IKeywordIrit.REFER_TO, referredAgent); - /*Object res = scope.execute(action, getRuntimeArgs()).getValue(); - dateTime = LocalDateTime.now(); - System.out.println("EXEC END " + dateTime.format(formatter)); - - return res;*/ -// scope.execute(action, getRuntimeArgs()).getValue(); - if(referredAgent == null) { - scope.execute(action, getRuntimeArgs()).getValue(); - } else { - scope.execute(action, referredAgent, true, getRuntimeArgs()).getValue(); - } - - return true; - } - - /** - * Kill event - */ - public void kill() { - this.isAlive = false; - } - - /** - * To string - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - - sb.append(action.getName()); - sb.append(" of "); - sb.append(getAgent()); - sb.append(" with "); - // Bug in GAMA core -> Arguments toString() does not return the toString of each - // facet but the hash of the list - sb.append(arguments.toString()); - sb.append(" at "); - sb.append(date); - - return sb.toString(); - } -} diff --git a/irit.gama.switchproject/src/irit/gama/util/event_manager/EventManager.java b/irit.gama.switchproject/src/irit/gama/util/event_manager/EventManager.java deleted file mode 100644 index acd8345d..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/event_manager/EventManager.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************************************* - * - * EventManager.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.event_manager; - -import java.util.UUID; - -import irit.gama.util.event_manager.Event.EventComparator; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaDate; - -/** - * Fast event manager - */ -public class EventManager extends EventQueue { - - // ############################################ - // Attributes - - /** - * Serial - */ - private static final long serialVersionUID = 1L; - - /** - * If true execution is active - */ - private boolean executeActive = false; - - /** - * The last event executed - */ - private Event lastEvent = null; - - /** - * The last event executed - */ - private int queueSize = 0; - - // ############################################ - // Methods - - public EventManager(IScope scope) { - super(new EventComparator(scope)); - } - - /** - * Get queue size - */ - public int getQueueSize() { - return queueSize; - } - - /** - * Register with action and arguments as map (return event ID) - */ - public String register(IScope scope, Event event) throws GamaRuntimeException { - if (event.getAgent().dead()) { - return null; - } - - if (event.getDate() == null) { - event.execute(); - return null; - } else { - if (executeActive) { - // Causality check - if (lastEvent.isGreaterThan(event)) { - throw GamaRuntimeException.warning( - "Exec: Past is not allowed " + lastEvent.getDate() + " vs " + event.getDate(), scope); - } - } else { - // Causality check - GamaDate simDate = scope.getSimulation().getClock().getCurrentDate(); - if (simDate.isGreaterThan(event.getDate(), true)) { - throw GamaRuntimeException.warning("Past is not allowed " - + scope.getSimulation().getClock().getCurrentDate() + " vs " + event.getDate(), scope); - } - } - - // Add event - add(event); - eventMap.put(event.getId(), event); - queueSize++; - - return event.getId().toString(); - } - } - - /** - * Execute the next events - */ - public Object execute(IScope scope) throws GamaRuntimeException { - executeActive = true; - // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy - // HH:mm:ss.SSS"); - - // System.out.println("EXECUTE " + scope.getAgent().getName()); - // LocalDateTime dateTime = LocalDateTime.now(); - // System.out.println("EVENT START " + dateTime.format(formatter)); - - // int nbEvent = 0; - while ((size() > 0) && isTimeReached()) { - // Remove event - lastEvent = poll(); - eventMap.remove(lastEvent.getId()); - if (!lastEvent.getAgent().dead()) { - if (lastEvent.execute() == true) { - queueSize--; - } - } else { - queueSize--; - } - - // nbEvent++; - // LocalDateTime dateTimeEv = LocalDateTime.now(); - // System.out.println("EVENT " + lastEvent + " : " + - // dateTimeEv.format(formatter)); - } - // dateTime = LocalDateTime.now(); - /* - * if (nbEvent > 0) { long diff = ChronoUnit.MILLIS.between(dateTime, - * LocalDateTime.now()); System.out.println("EVENT END " + nbEvent + " : " + - * (diff / 1000.0)); System.out.println(); } - */ - executeActive = false; - return true; - } - - /** - * Clear - */ - public void kill(IScope scope, String id) { - // Get event by ID - Event e = eventMap.get(UUID.fromString(id)); - if(e != null) { - e.kill(); - } - queueSize--; - } -} diff --git a/irit.gama.switchproject/src/irit/gama/util/event_manager/EventQueue.java b/irit.gama.switchproject/src/irit/gama/util/event_manager/EventQueue.java deleted file mode 100644 index 4b96813f..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/event_manager/EventQueue.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************************************* - * - * EventQueue.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.event_manager; - -import java.util.HashMap; -import java.util.PriorityQueue; -import java.util.UUID; - -import irit.gama.util.event_manager.Event.EventComparator; - -/** - * Event queue used by the event manager - * - * @author Jean-François Erdelyi - */ -public class EventQueue extends PriorityQueue { - - // ############################################ - // Attributes - - /** - * The serializable class EventQueue does not declare a static final - * serialVersionUID field of type long - */ - private static final long serialVersionUID = 1L; - - /** - * Event map - */ - HashMap eventMap = new HashMap<>(); - - // ############################################ - // Methods - - /** - * Constructor with comparator - */ - public EventQueue(EventComparator eventComparator) { - super(eventComparator); - } - - /** - * Return true if the time of the next element is reached - */ - public boolean isTimeReached() { - return peek().isTimeReached(); - } -} diff --git a/irit.gama.switchproject/src/irit/gama/util/event_manager/EventQueueList.java b/irit.gama.switchproject/src/irit/gama/util/event_manager/EventQueueList.java deleted file mode 100644 index 6905d489..00000000 --- a/irit.gama.switchproject/src/irit/gama/util/event_manager/EventQueueList.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************************************* - * - * EventQueue.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gama.util.event_manager; - -import java.util.ArrayList; -import java.util.ListIterator; - -import irit.gama.util.event_manager.Event.EventComparator; - -/** - * Event queue used by the event manager - * - * @author Jean-François Erdelyi - */ -public class EventQueueList { - - // ############################################ - // Attributes - - // Event list - protected ArrayList eventList = new ArrayList<>(); - - // Event comparator - private EventComparator eventComparator; - - - // ############################################ - // Methods - - /** - * Constructor with comparator - */ - public EventQueueList(EventComparator eventComparator) { - this.eventComparator = eventComparator; - } - - /** - * Return true if the time of the next element is reached - */ - public boolean isTimeReached() { - return eventList.get(0).isTimeReached(); - } - - /** - * Add data - */ - public void add(Event e) { - int i = 0; - while(i < eventList.size() && eventComparator.compare(e, eventList.get(i)) > 0) { - i++; - } - eventList.add(i, e); - } - - /** - * Poll event - */ - public Event poll() { - Event e = eventList.get(0); - eventList.remove(0); - return e; - } - - /** - * Get iterator - */ - public ListIterator iterator() { - return eventList.listIterator(); - } - - /** - * Get size - */ - public int size() { - return eventList.size(); - } - - /** - * Get size - */ - public ArrayList data() { - return eventList; - } -} diff --git a/irit.gama.switchproject/src/irit/gaml/architecure/event_manager/EventManagerArchitecture.java b/irit.gama.switchproject/src/irit/gaml/architecure/event_manager/EventManagerArchitecture.java deleted file mode 100644 index f89452bc..00000000 --- a/irit.gama.switchproject/src/irit/gaml/architecure/event_manager/EventManagerArchitecture.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************************************* - * - * EventManagerArchitecture.java, in plugin irit.gaml.switchproject, is part of the source code - * of the GAMA modeling and simulation platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.architecure.event_manager; - -import irit.gama.common.interfaces.IKeywordIrit; -import irit.gama.util.event_manager.Event; -import irit.gama.util.event_manager.EventManager; -import msi.gama.common.interfaces.IKeyword; -import msi.gama.metamodel.agent.IAgent; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.getter; -import msi.gama.precompiler.GamlAnnotations.skill; -import msi.gama.precompiler.GamlAnnotations.variable; -import msi.gama.precompiler.GamlAnnotations.vars; -import msi.gama.precompiler.IConcept; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaDate; -import msi.gama.util.GamaMap; -import msi.gaml.architecture.reflex.ReflexArchitecture; -import msi.gaml.descriptions.ActionDescription; -import msi.gaml.types.IType; - -/** - * Event manager architecture - * - * @author Jean-François Erdelyi - */ -@vars({ @variable(name = IKeyword.SIZE, type = IType.INT, doc = @doc("Return the size of the all queues")) - }) -@skill(name = IKeywordIrit.EVENT_MANAGER, concept = { IConcept.BEHAVIOR, - IConcept.ARCHITECTURE }, doc = @doc("Event manager behavior")) -public class EventManagerArchitecture extends ReflexArchitecture { - - // ############################################ - // Getter and setter of architecture - - /** - * Get size - */ - @getter(IKeyword.SIZE) - public int getQueueSize(final IAgent agent) { - return getCurrentManagerIfExists(agent).getQueueSize(); - } - - // ############################################ - // Methods - - /** - * Execution (each step) - */ - @Override - public Object executeOn(final IScope scope) throws GamaRuntimeException { - super.executeOn(scope); - return executeCurrentManager(scope); - } - - /** - * Initialization - */ - @Override - public boolean init(final IScope scope) throws GamaRuntimeException { - final IAgent agent = getCurrentAgent(scope); - final EventManager manager = new EventManager(scope); - - agent.setAttribute(IKeywordIrit.EVENT_MANAGER, manager); - return true; - } - - /** - * Execute current manager - */ - protected Object executeCurrentManager(final IScope scope) throws GamaRuntimeException { - final IAgent agent = getCurrentAgent(scope); - if (scope.interrupted() || agent == null) { - return null; - } - - return getCurrentManagerIfExists(agent).execute(scope); - } - - /** - * Get current manager by agent - */ - protected EventManager getCurrentManager(final IAgent agent) throws GamaRuntimeException { - return (EventManager) agent.getAttribute(IKeywordIrit.EVENT_MANAGER); - } - - /** - * Get current manager by agent. throw exception if does not exists - */ - protected EventManager getCurrentManagerIfExists(final IAgent agent) throws GamaRuntimeException { - EventManager manager = getCurrentManager(agent); - if (manager == null) { - throw GamaRuntimeException.error("No event manager agent was detected", agent.getScope()); - } - return manager; - } - - /** - * Internal register (used by "scheduling" skill) - */ - public String register(final IScope scope, final IAgent caller, final ActionDescription action, - final GamaMap args, final GamaDate date, final IAgent referredAgent) - throws GamaRuntimeException { - - IAgent agent = (IAgent) getCurrentAgent(scope).getAttribute(IKeywordIrit.EVENT_MANAGER); - if (scope.interrupted() || agent == null) { - return null; - } - - return getCurrentManagerIfExists(agent).register(scope, - new Event(scope, caller, action, args, date, referredAgent)); - } - - /** - * Internal kill (used by "scheduling" skill) - */ - public Object kill(final IScope scope, final String id) throws GamaRuntimeException { - - IAgent agent = (IAgent) getCurrentAgent(scope).getAttribute(IKeywordIrit.EVENT_MANAGER); - if (scope.interrupted() || agent == null) { - return false; - } - - getCurrentManagerIfExists(agent).kill(scope, id); - return true; - } -} diff --git a/irit.gama.switchproject/src/irit/gaml/operators/IDequeOperator.java b/irit.gama.switchproject/src/irit/gaml/operators/IDequeOperator.java deleted file mode 100644 index 582fe726..00000000 --- a/irit.gama.switchproject/src/irit/gaml/operators/IDequeOperator.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************************************* - * - * IDequeOperator.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.operators; - -import irit.gama.common.interfaces.IKeywordIrit; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.example; -import msi.gama.precompiler.GamlAnnotations.operator; -import msi.gama.precompiler.GamlAnnotations.usage; -import msi.gama.precompiler.ITypeProvider; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; - -/** - * Deque interface used for Queue and Stack types - * - * @author Jean-François Erdelyi - */ -public interface IDequeOperator { - /** - * Pop operator must be redefined in queue and stack classes - */ - @operator(value = "pop", can_be_const = true, category = { IKeywordIrit.QUEUE_OPERATOR, - IKeywordIrit.STACK_OPERATOR }, type = ITypeProvider.CONTENT_TYPE_AT_INDEX - + 1, concept = { IKeywordIrit.QUEUE, IKeywordIrit.STACK }) - @doc(value = "retrieves and removes the first available element of this container, or returns null if this container is empty", masterDoc = true, comment = "the pop operator behavior depends on the nature of the operand", usages = { - @usage(value = "pop return and remove the first object of the container", examples = { - @example(value = "pop(stack([1, 2]))", equals = "2"), - @example(value = "pop(queue([1, 2]))", equals = "1") }) }) - T pop(IScope scope) throws GamaRuntimeException; -} diff --git a/irit.gama.switchproject/src/irit/gaml/operators/TrafficOperator.java b/irit.gama.switchproject/src/irit/gaml/operators/TrafficOperator.java deleted file mode 100644 index 7d4b696e..00000000 --- a/irit.gama.switchproject/src/irit/gaml/operators/TrafficOperator.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************************************* - * - * TrafficOperator.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and simulation - * platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.operators; - -import java.util.List; -import java.util.Map.Entry; - -import irit.gama.common.interfaces.IKeywordIrit; -import msi.gama.metamodel.agent.IAgent; -import msi.gama.metamodel.topology.graph.GamaSpatialGraph; -import msi.gama.metamodel.topology.graph._SpatialEdge; -import msi.gama.metamodel.topology.graph._SpatialVertex; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.example; -import msi.gama.precompiler.GamlAnnotations.no_test; -import msi.gama.precompiler.GamlAnnotations.operator; -import msi.gama.precompiler.IConcept; -import msi.gama.precompiler.ITypeProvider; -import msi.gama.runtime.IScope; -import msi.gama.util.IContainer; -import msi.gama.util.graph.IGraph; - -/** - * Traffic operator - * - * @author Jean-François Erdelyi - */ -public class TrafficOperator { - @operator( - value = "as_traffic_graph", - content_type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 2, - index_type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1, - concept = { IConcept.GRAPH, IConcept.TRANSPORT }) - @doc( - value = "creates a graph from the list/map of roads given as operand and connect the node to the road", - examples = { - @example( - value = "as_traffic_graph(roads, nodes): build a graph while using the road agents as roads and the node agents as nodes", - isExecutable = false) - }, - see = {"as_intersection_graph", "as_distance_graph", "as_edge_graph" }) - @no_test - @SuppressWarnings("unchecked") - public static IGraph asTrafficGraph(final IScope scope, final IContainer roads, final IContainer nodes) { - final IGraph graph = new GamaSpatialGraph(roads, nodes, scope); - - // Set in/out node of roads agents - for (final Entry entry : graph._internalEdgeMap().entrySet()) { - IAgent source = (IAgent) ((_SpatialEdge) entry.getValue()).getSource(); - if (source != null) { - ((IAgent) entry.getKey()).setAttribute(IKeywordIrit.NODE_IN, source); - } - - IAgent target = (IAgent) ((_SpatialEdge) entry.getValue()).getTarget(); - if (target != null) { - ((IAgent) entry.getKey()).setAttribute(IKeywordIrit.NODE_OUT, target); - } - } - - // Set in/out roads of nodes agents - for (final Entry entry : graph._internalVertexMap().entrySet()) { - for (final Object edge : ((_SpatialVertex) entry.getValue()).getInEdges()) { - ((List) ((IAgent) entry.getKey()).getAttribute(IKeywordIrit.ROADS_IN)).add((IAgent) edge); - } - - for (final Object edge : ((_SpatialVertex) entry.getValue()).getOutEdges()) { - ((List) ((IAgent) entry.getKey()).getAttribute(IKeywordIrit.ROADS_OUT)).add((IAgent) edge); - } - } - - return graph; - } -} diff --git a/irit.gama.switchproject/src/irit/gaml/skills/logging/LoggingSkill.java b/irit.gama.switchproject/src/irit/gaml/skills/logging/LoggingSkill.java deleted file mode 100644 index e491002d..00000000 --- a/irit.gama.switchproject/src/irit/gaml/skills/logging/LoggingSkill.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************************************* -* -* LoggerSkill.java, in plugin irit.gama.switchproject, -* is part of the source code of the GAMA modeling and simulation platform (v. 1.8.1) -* -* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners -* -* Visit https://github.com/gama-platform/gama for license information and contacts. -* -********************************************************************************************************/ - -package irit.gaml.skills.logging; - -import java.io.FileWriter; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.jfree.data.json.impl.JSONArray; -import org.jfree.data.json.impl.JSONObject; - -import irit.gama.common.interfaces.IKeywordIrit; -import msi.gama.common.util.FileUtils; -import msi.gama.metamodel.agent.IAgent; -import msi.gama.precompiler.GamlAnnotations.action; -import msi.gama.precompiler.GamlAnnotations.arg; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.example; -import msi.gama.precompiler.GamlAnnotations.getter; -import msi.gama.precompiler.GamlAnnotations.skill; -import msi.gama.precompiler.GamlAnnotations.variable; -import msi.gama.precompiler.GamlAnnotations.vars; -import msi.gama.precompiler.IConcept; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gaml.skills.Skill; -import msi.gaml.types.IType; - -/** - * Logger skill, add the capability to log data and write it into files - * - * @author Jean-François Erdelyi - */ -@SuppressWarnings("unchecked") -@vars({ @variable(name = IKeywordIrit.LOG_DATA, type = IType.NONE, doc = { @doc("Logbook data") }), }) -@skill(name = IKeywordIrit.LOGGING, concept = { IKeywordIrit.LOGGING, IConcept.SKILL }, internal = true) -public class LoggingSkill extends Skill { - - // ############################################ - // Getter and setter - - @getter(IKeywordIrit.LOG_DATA) - public Object getLogData(final IAgent agent) { - if (agent == null) { - return null; - } - return (JSONObject) agent.getAttribute(IKeywordIrit.LOG_DATA); - } - - // ############################################ - // Actions - - @action(name = "log_plot_1d", args = { - @arg(name = IKeywordIrit.SECTION, type = IType.STRING, optional = false, doc = @doc("The name of the section")), - @arg(name = IKeywordIrit.ENTRY, type = IType.STRING, optional = false, doc = @doc("The name of the entry")), - @arg(name = IKeywordIrit.X, type = IType.STRING, optional = false, doc = @doc("X data")) }, doc = @doc(examples = { - @example("do log_plot_2d section: name data: \"Mean speed\" x: my_date") }, value = "Write new line in logbook.")) - public Object logPlot1d(final IScope scope) throws GamaRuntimeException { - // Get data - String sectionName = (String) scope.getArg(IKeywordIrit.SECTION, IType.STRING); - String entryName = (String) scope.getArg(IKeywordIrit.ENTRY, IType.STRING); - String x = (String) scope.getArg(IKeywordIrit.X, IType.STRING); - - // Get date - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - Date date = new Date(System.currentTimeMillis()); - - // Put data - JSONObject data = new JSONObject(); - data.put("name", entryName); - data.put("type", "1d"); - data.put("date", formatter.format(date)); - data.put("x", x); - - // Write log - return log(scope, sectionName, data); - } - - @action(name = "log_plot_2d", args = { - @arg(name = IKeywordIrit.SECTION, type = IType.STRING, optional = false, doc = @doc("The name of the section")), - @arg(name = IKeywordIrit.ENTRY, type = IType.STRING, optional = false, doc = @doc("The name of the entry")), - @arg(name = IKeywordIrit.X, type = IType.STRING, optional = false, doc = @doc("X data")), - @arg(name = IKeywordIrit.Y, type = IType.STRING, optional = false, doc = @doc("Y data")) }, doc = @doc(examples = { - @example("do log_plot_2d section: name data: \"Mean speed\" x: my_date y: 30.2") }, value = "Write new line in logbook.")) - public Object logPlot2d(final IScope scope) throws GamaRuntimeException { - // Get data - String sectionName = (String) scope.getArg(IKeywordIrit.SECTION, IType.STRING); - String entryName = (String) scope.getArg(IKeywordIrit.ENTRY, IType.STRING); - String x = (String) scope.getArg(IKeywordIrit.X, IType.STRING); - String y = (String) scope.getArg(IKeywordIrit.Y, IType.STRING); - - // Get date - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - Date date = new Date(System.currentTimeMillis()); - - // Put data - JSONObject data = new JSONObject(); - data.put("name", entryName); - data.put("type", "2d"); - data.put("date", formatter.format(date)); - data.put("x", x); - data.put("y", y); - - // Write log - return log(scope, sectionName, data); - } - - @action(name = "write", args = { - @arg(name = IKeywordIrit.FILE_NAME, type = IType.STRING, optional = false, doc = @doc("File name")), - @arg(name = IKeywordIrit.FLUSH, type = IType.BOOL, optional = true, doc = @doc("Flush data if true")) }, doc = @doc(examples = { - @example("do write file_name: \"log.txt\" flush: true;") }, value = "Write data in file.")) - public Object write(final IScope scope) throws GamaRuntimeException { - // Get data from the scope - String fileName = (String) scope.getArg(IKeywordIrit.FILE_NAME, IType.STRING); - Boolean flush = (Boolean) scope.getArg(IKeywordIrit.FLUSH, IType.BOOL); - FileWriter fw = null; - IAgent agent = scope.getAgent(); - JSONObject jsonData = (JSONObject) agent.getAttribute(IKeywordIrit.LOG_DATA); - - // Not ok - if (jsonData == null) { - return false; - } - - // Write data - String path = FileUtils.constructAbsoluteFilePath(scope, fileName, false); - try { - fw = new FileWriter(path); - fw.write(jsonData.toJSONString()); - } catch (IOException e) { - throw GamaRuntimeException.error(e.getMessage(), scope); - } finally { - try { - if (fw != null) { - fw.flush(); - fw.close(); - } - } catch (IOException e) { - throw GamaRuntimeException.error(e.getMessage(), scope); - } - } - - // If "flush" then clear data - if (flush) { - jsonData.clear(); - } - - // Ok - return true; - } - - @action(name = "flush", doc = @doc(examples = { @example("do flush;") }, value = "Flush data.")) - public Object flush(final IScope scope) throws GamaRuntimeException { - IAgent agent = scope.getAgent(); - JSONObject jsonData = (JSONObject) agent.getAttribute(IKeywordIrit.LOG_DATA); - - // Clear data - jsonData.clear(); - - // Always true - return true; - } - - // ############################################ - // Internal behavior - - public Object log(final IScope scope, final String dataName, final JSONObject data) throws GamaRuntimeException { - IAgent agent = scope.getAgent(); - JSONObject jsonData = (JSONObject) agent.getAttribute(IKeywordIrit.LOG_DATA); - if (jsonData == null) { - jsonData = new JSONObject(); - agent.setAttribute(IKeywordIrit.LOG_DATA, jsonData); - } - - // Get map - JSONArray values = (JSONArray) jsonData.get(dataName); - - // If map is null then create a new one - if (values == null) { - values = new JSONArray(); - jsonData.put(dataName, values); - } - - return values.add(data); - } - -} diff --git a/irit.gama.switchproject/src/irit/gaml/skills/scheduling/SchedulingSkill.java b/irit.gama.switchproject/src/irit/gaml/skills/scheduling/SchedulingSkill.java deleted file mode 100644 index 01eaf3e6..00000000 --- a/irit.gama.switchproject/src/irit/gaml/skills/scheduling/SchedulingSkill.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************************************* - * - * SchedulingSkill.java, in plugin irit.gama.switchproject, - * is part of the source code of the GAMA modeling and simulation platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.skills.scheduling; - -import irit.gama.common.interfaces.IKeywordIrit; -import irit.gaml.architecure.event_manager.EventManagerArchitecture; -import msi.gama.metamodel.agent.IAgent; -import msi.gama.precompiler.GamlAnnotations.action; -import msi.gama.precompiler.GamlAnnotations.arg; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.example; -import msi.gama.precompiler.GamlAnnotations.getter; -import msi.gama.precompiler.GamlAnnotations.setter; -import msi.gama.precompiler.GamlAnnotations.skill; -import msi.gama.precompiler.GamlAnnotations.variable; -import msi.gama.precompiler.GamlAnnotations.vars; -import msi.gama.precompiler.IConcept; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaDate; -import msi.gama.util.GamaMap; -import msi.gaml.descriptions.ActionDescription; -import msi.gaml.skills.Skill; -import msi.gaml.types.IType; - -/** - * Scheduling skill - * - * @author Jean-François Erdelyi - */ -@vars({ @variable(name = IKeywordIrit.EVENT_MANAGER, type = IType.AGENT, doc = { - @doc("The event manager, must be defined in another species with \"control: event_manager\"") }), - @variable(name = IKeywordIrit.EVENT_DATE, type = IType.DATE, doc = { @doc("The date of the previous event") }), - @variable(name = IKeywordIrit.REFER_TO, type = IType.AGENT, doc = { - @doc("The agent to refer when the event is triggered") }) }) -@skill(name = IKeywordIrit.SCHEDULING, concept = { IKeywordIrit.SCHEDULING, IConcept.SKILL }, internal = true) -public class SchedulingSkill extends Skill { - - // ############################################ - // Getter and setter of skill - - @setter(IKeywordIrit.EVENT_MANAGER) - public void setEventManager(final IAgent agent, final IAgent manager) { - if (agent == null || manager == null) { - return; - } - agent.setAttribute(IKeywordIrit.EVENT_MANAGER, manager); - } - - @getter(IKeywordIrit.EVENT_MANAGER) - public IAgent getEventManager(final IAgent agent) { - if (agent == null) { - return null; - } - return (IAgent) agent.getAttribute(IKeywordIrit.EVENT_MANAGER); - } - - @getter(IKeywordIrit.EVENT_DATE) - public GamaDate getAt(final IAgent agent) { - if (agent == null) { - return null; - } - return (GamaDate) agent.getAttribute(IKeywordIrit.EVENT_DATE); - } - - @getter(IKeywordIrit.REFER_TO) - public IAgent getReferTo(final IAgent agent) { - if (agent == null) { - return null; - } - return (IAgent) agent.getAttribute(IKeywordIrit.REFER_TO); - } - - // ############################################ - // Action of architecture - - @action(name = "later", args = { - @arg(name = IKeywordIrit.THE_ACTION, type = IType.STRING, optional = false, doc = @doc("The name of an action or a primitive")), - @arg(name = IKeywordIrit.WITH_ARGUMENTS, type = IType.MAP, optional = true, doc = @doc("A map expression containing the parameters of the action")), - @arg(name = IKeywordIrit.AT, type = IType.DATE, optional = true, doc = @doc("Call date")), - @arg(name = IKeywordIrit.REFER_TO, type = IType.AGENT, optional = true, doc = @doc("The agent to refer")) }, doc = @doc(examples = { - @example("do later execute: my_action arguments: map((\"test\"::2)) date: starting_date") }, value = "Do action when the date is reached.")) - @SuppressWarnings("unchecked") - public String register(final IScope scope) throws GamaRuntimeException { - // Get date - GamaDate date = (GamaDate) scope.getArg(IKeywordIrit.AT, IType.DATE); - // Get caller - IAgent caller = scope.getAgent(); - // Get arguments - GamaMap args = (GamaMap) scope.getArg(IKeywordIrit.WITH_ARGUMENTS, IType.MAP); - // Get refer to agent - IAgent referredAgent = (IAgent) scope.getArg(IKeywordIrit.REFER_TO, IType.AGENT); - - // Get action - String actionName = (String) scope.getArg(IKeywordIrit.THE_ACTION, IType.STRING); - ActionDescription action; - if(referredAgent == null ) { - action = caller.getSpecies().getDescription().getAction(actionName); - } else { - action = referredAgent.getSpecies().getDescription().getAction(actionName); - } - - // Get manager - IAgent manager = (IAgent) scope.getAgent().getAttribute(IKeywordIrit.EVENT_MANAGER); - - if (manager == null) { - throw GamaRuntimeException.error("The manager must be defined if you have to use the action \"later\"", - scope); - } - - // Get skill and do register on it - EventManagerArchitecture eventSkill = (EventManagerArchitecture) manager.getSpecies().getArchitecture(); - if (eventSkill == null) { - throw GamaRuntimeException - .error("The manager must use the control \"event_manager\" to execute the action \"later\"", scope); - } - return eventSkill.register(scope, caller, action, args, date, referredAgent); - } - - - @action(name = "kill_event", args = { - @arg(name = IKeywordIrit.ID, type = IType.STRING, optional = false, doc = @doc("The event ID")) }, doc = @doc(examples = { - @example("do kill_event(\"123e4567-e89b-12d3-a456-426655440000\")") }, value = "Kill event.")) - public Object kill(final IScope scope) throws GamaRuntimeException { - // Get manager - IAgent manager = (IAgent) scope.getAgent().getAttribute(IKeywordIrit.EVENT_MANAGER); - - // Get arg - String id = (String) scope.getArg(IKeywordIrit.ID, IType.STRING); - - if (manager == null) { - throw GamaRuntimeException.error("The manager must be defined if you have to use the action \"later\"", - scope); - } - - // Get skill and do register on it - EventManagerArchitecture eventSkill = (EventManagerArchitecture) manager.getSpecies().getArchitecture(); - if (eventSkill == null) { - throw GamaRuntimeException - .error("The manager must use the control \"event_manager\" to execute the action \"later\"", scope); - } - return eventSkill.kill(scope, id); - } - -} diff --git a/irit.gama.switchproject/src/irit/gaml/skills/traffic/IdmSkill.java b/irit.gama.switchproject/src/irit/gaml/skills/traffic/IdmSkill.java deleted file mode 100644 index c8c3d110..00000000 --- a/irit.gama.switchproject/src/irit/gaml/skills/traffic/IdmSkill.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************************************* -* -* IdmSkill.java, in plugin irit.gama.switchproject, -* is part of the source code of the GAMA modeling and simulation platform (v. 1.8.1) -* -* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners -* -* Visit https://github.com/gama-platform/gama for license information and contacts. -* -********************************************************************************************************/ - -package irit.gaml.skills.traffic; - -import irit.gama.common.interfaces.IKeywordIrit; -import msi.gama.common.interfaces.IKeyword; -import msi.gama.metamodel.agent.IAgent; -import msi.gama.metamodel.topology.ITopology; -import msi.gama.precompiler.GamlAnnotations.action; -import msi.gama.precompiler.GamlAnnotations.arg; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.example; -import msi.gama.precompiler.GamlAnnotations.getter; -import msi.gama.precompiler.GamlAnnotations.setter; -import msi.gama.precompiler.GamlAnnotations.skill; -import msi.gama.precompiler.GamlAnnotations.variable; -import msi.gama.precompiler.GamlAnnotations.vars; -import msi.gama.precompiler.IConcept; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.path.IPath; -import msi.gaml.operators.Cast; -import msi.gaml.skills.MovingSkill; -import msi.gaml.types.IType; - -/** - * IDM skill, IDM implementation - * - * @author Jean-François Erdelyi - */ -@vars({ @variable(name = IKeywordIrit.IDM_DESIRED_SPEED, type = IType.FLOAT, init = "30.0", doc = { - @doc("The desired speed of the vehicle") }), - @variable(name = IKeywordIrit.IDM_SPACING, type = IType.FLOAT, init = "1.0", doc = { - @doc("The jam distance") }), - @variable(name = IKeywordIrit.IDM_REACTION_TIME, type = IType.FLOAT, init = "1.5", doc = { - @doc("The reaction time of the vehicle") }), - @variable(name = IKeywordIrit.IDM_MAX_ACCELERATION, type = IType.FLOAT, init = "4.0", doc = { - @doc("The maximum acceleration of the vehicle") }), - @variable(name = IKeywordIrit.IDM_DESIRED_DECELERATION, type = IType.FLOAT, init = "3.0", doc = { - @doc("The desired deceleration of the vehicle") }), - @variable(name = IKeywordIrit.IDM_ACCELERATION, type = IType.FLOAT, init = "0.0", doc = { - @doc("The acceleration of the vehicle") }), - @variable(name = IKeywordIrit.IDM_DELTA_SPEED, type = IType.FLOAT, init = "0.0", doc = { - @doc("The acceleration of the vehicle") }), - @variable(name = IKeywordIrit.IDM_ACTUAL_GAP, type = IType.FLOAT, init = "0.0", doc = { - @doc("The acceleration of the vehicle") }), - @variable(name = IKeywordIrit.IDM_DESIRED_MINIMUM_GAP, type = IType.FLOAT, init = "0.0", doc = { - @doc("The acceleration of the vehicle") }), - @variable(name = IKeywordIrit.VEHICLE_LENGTH, type = IType.FLOAT, init = "5.0", doc = { - @doc("The length of the vehicle") })}) -@skill(name = IKeywordIrit.IDM, concept = { IKeywordIrit.IDM, IConcept.SKILL }, internal = true) -public class IdmSkill extends MovingSkill { - - // ############################################ - // Getter - - @getter(IKeywordIrit.IDM_DESIRED_SPEED) - public double getDesiredSpeed(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_DESIRED_SPEED); - } - - @getter(IKeywordIrit.IDM_SPACING) - public double getSpacing(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_SPACING); - } - - @getter(IKeywordIrit.IDM_REACTION_TIME) - public double getReactionTime(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_REACTION_TIME); - } - - @getter(IKeywordIrit.IDM_MAX_ACCELERATION) - public double getMaxAcceleration(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_MAX_ACCELERATION); - } - - @getter(IKeywordIrit.IDM_DESIRED_DECELERATION) - public double getDesiredDeceleration(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_DESIRED_DECELERATION); - } - - @getter(IKeywordIrit.IDM_ACCELERATION) - public double getAcceleration(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_ACCELERATION); - } - - @getter(IKeywordIrit.IDM_DELTA_SPEED) - public double getDeltaSpeed(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_DELTA_SPEED); - } - - @getter(IKeywordIrit.IDM_ACTUAL_GAP) - public double getActualGap(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_ACTUAL_GAP); - } - - @getter(IKeywordIrit.IDM_DESIRED_MINIMUM_GAP) - public double getDesiredMinimumGap(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.IDM_DESIRED_MINIMUM_GAP); - } - - @getter(IKeywordIrit.VEHICLE_LENGTH) - public double getLength(final IAgent agent) { - if (agent == null) { - return 0.0; - } - return (double) agent.getAttribute(IKeywordIrit.VEHICLE_LENGTH); - } - - // ############################################ - // Setter - - @setter(IKeywordIrit.IDM_DESIRED_SPEED) - public void setDesiredSpeed(final IAgent agent, final double value) { - if (agent == null) { - return; - } - agent.setAttribute(IKeywordIrit.IDM_DESIRED_SPEED, value); - } - - @setter(IKeywordIrit.IDM_SPACING) - public void setSpacing(final IAgent agent, final double value) { - if (agent == null) { - return; - } - agent.setAttribute(IKeywordIrit.IDM_SPACING, value); - } - - @setter(IKeywordIrit.IDM_REACTION_TIME) - public void setReactionTime(final IAgent agent, final double value) { - if (agent == null) { - return; - } - agent.setAttribute(IKeywordIrit.IDM_REACTION_TIME, value); - } - - @setter(IKeywordIrit.IDM_MAX_ACCELERATION) - public void setMaxAcceleration(final IAgent agent, final double value) { - if (agent == null) { - return; - } - agent.setAttribute(IKeywordIrit.IDM_MAX_ACCELERATION, value); - } - - @setter(IKeywordIrit.IDM_DESIRED_DECELERATION) - public void setDesiredDeceleration(final IAgent agent, final double value) { - if (agent == null) { - return; - } - agent.setAttribute(IKeywordIrit.IDM_DESIRED_DECELERATION, value); - } - - @setter(IKeywordIrit.VEHICLE_LENGTH) - public void setLength(final IAgent agent, final double value) { - if (agent == null) { - return; - } - agent.setAttribute(IKeywordIrit.VEHICLE_LENGTH, value); - } - - - // ############################################ - // Actions - - @action(name = "goto", args = { - @arg(name = "target", type = IType.GEOMETRY, optional = false, doc = @doc("the location or entity towards which to move.")), - @arg(name = "on", type = IType.NONE, optional = true, doc = @doc("graph, topology, list of geometries or map of geometries that restrain this move")), - @arg(name = "follow", type = IType.AGENT, optional = true, doc = @doc("the agent to folow")), - @arg(name = "desired_speed", type = IType.FLOAT, optional = true, doc = @doc("the desired speed.")), }, doc = @doc(value = "moves the agent towards the target passed in the arguments.", returns = "optional: the path followed by the agent.", examples = { - @example("do goto target: (one_of road).location follow: next_car on: road_network;") })) - public IPath oneStep(final IScope scope) throws GamaRuntimeException { - // Get arguments - IAgent agent = scope.getAgent(); - IAgent follow = (IAgent) scope.getArg("follow", IType.AGENT); - if (scope.hasArg("desired_speed")) { - double desiredSpeed = (double) scope.getArg("desired_speed", IType.FLOAT); - agent.setAttribute(IKeywordIrit.IDM_DESIRED_SPEED, desiredSpeed); - } - - // Compute and set speed - agent.setAttribute(IKeyword.SPEED, idmOneStep(scope, agent, follow, getTopology(scope))); - - // Execute action goto - return primGoto(scope); - } - - // ############################################ - // Internal behavior - - /** - * Get topology from the scope - * - * @param scope the scope - * @return the topology - */ - protected ITopology getTopology(final IScope scope) { - final Object on = scope.getArg("on", IType.NONE); - final ITopology topo = Cast.asTopology(scope, on); - if (topo == null) { - return scope.getTopology(); - } - return topo; - } - - /** - * IDM one step compute acceleration and speed - * - * @param scope the scope - * @param follow the follow - * @param on the graph - * @return computed speed - */ - protected double idmOneStep(final IScope scope, final IAgent agent, final IAgent follow, final ITopology on) { - - // Get current agent data - double maxAcceleration = (double) agent.getAttribute(IKeywordIrit.IDM_MAX_ACCELERATION); - double desiredDeceleration = (double) agent.getAttribute(IKeywordIrit.IDM_DESIRED_DECELERATION); - double speed = (double) agent.getAttribute(IKeyword.SPEED); - double desiredSpeed = (double) agent.getAttribute(IKeywordIrit.IDM_DESIRED_SPEED); - if (follow == null || follow.dead()) { - // If the followed agent is dead or nil then this agent is supposed as the - // platoon leader - return computeAsLeader(scope, agent, desiredDeceleration, maxAcceleration, speed, desiredSpeed); - } - - // Check distance - double distanceBetween = on.distanceBetween(scope, agent, follow); - if (on.distanceBetween(scope, agent, follow) == Double.MAX_VALUE) { - // TODO MAX_VALUE = unreachable, maybe change computeAsLeader by euclidean - // distance ? - return computeAsLeader(scope, agent, desiredDeceleration, maxAcceleration, speed, desiredSpeed); - } - - // Get current agent data - double spacing = (double) agent.getAttribute(IKeywordIrit.IDM_SPACING); - double reactionTime = (double) agent.getAttribute(IKeywordIrit.IDM_REACTION_TIME); - double length = (double) agent.getAttribute(IKeywordIrit.VEHICLE_LENGTH); - - // Get followed data - double followedSpeed = (double) follow.getAttribute(IKeyword.SPEED); - double followedLength = (double) follow.getAttribute(IKeywordIrit.VEHICLE_LENGTH); - - // Computation - double deltaSpeed = followedSpeed - speed; - double actualGap = distanceBetween - ((length / 2.0) + (followedLength / 2.0)); - double desiredMinimumGap = spacing + (reactionTime * speed) - - ((speed * deltaSpeed) / (2.0 * Math.sqrt(maxAcceleration * desiredDeceleration))); - - double speedFactor = speed / desiredSpeed; - double gapFactor = desiredMinimumGap / actualGap; - double acceleration = maxAcceleration - * (1.0 - (speedFactor * speedFactor * speedFactor * speedFactor) - (gapFactor * gapFactor)); - - // Set values and return speed - return setValuesAndComputeSpeed(scope, agent, acceleration, desiredDeceleration, maxAcceleration, speed, - deltaSpeed, actualGap, desiredMinimumGap); - } - - /** - * Set values and compute speed - * - * @param scope the scope - * @param agent the agent - * @param acceleration computed acceleration - * @param desiredDeceleration max deceleration - * @param maxAcceleration max acceleration - * @param speed actual speed - * @param deltaSpeed delta speed between the current agent and the - * followed one - * @param actualGap delta location between the current agent and the - * followed one - * @param desiredMinimumGap desired minimum gap between the current agent and - * the followed one - * @return computed speed - */ - protected double setValuesAndComputeSpeed(final IScope scope, final IAgent agent, double acceleration, - final double desiredDeceleration, final double maxAcceleration, final double speed, final double deltaSpeed, - final double actualGap, final double desiredMinimumGap) { - if (acceleration < -desiredDeceleration) { - acceleration = -desiredDeceleration; - } else if (acceleration > maxAcceleration) { - acceleration = maxAcceleration; - } - agent.setAttribute(IKeywordIrit.IDM_DELTA_SPEED, deltaSpeed); - agent.setAttribute(IKeywordIrit.IDM_ACTUAL_GAP, actualGap); - agent.setAttribute(IKeywordIrit.IDM_DESIRED_MINIMUM_GAP, desiredMinimumGap); - agent.setAttribute(IKeywordIrit.IDM_ACCELERATION, acceleration); - return speed + (acceleration * scope.getClock().getStepInSeconds()); - } - - /** - * Compute acceleration as leader - * - * @param scope the scope - * @param agent the agent - * @param desiredDeceleration max deceleration - * @param maxAcceleration max acceleration - * @param speed actual speed - * @param desiredSpeed desired speed - * @return computed speed - */ - protected double computeAsLeader(final IScope scope, final IAgent agent, final double desiredDeceleration, - final double maxAcceleration, final double speed, final double desiredSpeed) { - double speedFactor = speed / desiredSpeed; - double acceleration = maxAcceleration * (1.0 - (speedFactor * speedFactor * speedFactor * speedFactor)); - return setValuesAndComputeSpeed(scope, agent, acceleration, desiredDeceleration, maxAcceleration, speed, 0.0, - 0.0, 0.0); - } - -} diff --git a/irit.gama.switchproject/src/irit/gaml/statements/PushStatement.java b/irit.gama.switchproject/src/irit/gaml/statements/PushStatement.java deleted file mode 100644 index 6df79c66..00000000 --- a/irit.gama.switchproject/src/irit/gaml/statements/PushStatement.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************************************* - * - * PushStatement.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and - * simulation platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.statements; - -import irit.gama.common.interfaces.IKeywordIrit; -import irit.gama.util.deque.GamaDeque; -import msi.gama.common.interfaces.IKeyword; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.example; -import msi.gama.precompiler.GamlAnnotations.facet; -import msi.gama.precompiler.GamlAnnotations.facets; -import msi.gama.precompiler.GamlAnnotations.inside; -import msi.gama.precompiler.GamlAnnotations.symbol; -import msi.gama.precompiler.GamlAnnotations.usage; -import msi.gama.precompiler.ISymbolKind; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gaml.descriptions.IDescription; -import msi.gaml.expressions.IExpression; -import msi.gaml.statements.AbstractStatement; -import msi.gaml.types.IType; - -/** - * Push statement used by Queue and Stack types - * - * @author Jean-François Erdelyi - */ -@symbol(name = IKeywordIrit.PUSH, kind = ISymbolKind.SINGLE_STATEMENT, with_sequence = false, concept = { - IKeywordIrit.STACK, IKeywordIrit.QUEUE }) -@inside(kinds = { ISymbolKind.BEHAVIOR, ISymbolKind.SEQUENCE_STATEMENT, ISymbolKind.LAYER }, symbols = IKeyword.CHART) -@doc(value = "Allows to add, i.e. to insert, a new element in a deque", usages = { - @usage(value = "The new element can be added either at the end of the deque", examples = { - @example(value = "push expr to: stack; // Add at the end", isExecutable = false), - @example(value = "push expr to: queue; // Add at the end", isExecutable = false) }) }) -@facets(value = { - @facet(name = IKeyword.ITEM, type = IType.NONE, optional = false, doc = { - @doc("any expression to add in the deque") }), - @facet(name = IKeyword.TO, type = { IKeywordIrit.STACK_TYPE, - IKeywordIrit.QUEUE_TYPE }, optional = false, doc = { - @doc("the stack or queue") }), }, omissible = IKeyword.ITEM) -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class PushStatement extends AbstractStatement { - - // ############################################ - // Attributs - - /** - * Expressions Item - */ - final IExpression itemExp; - - /** - * Expressions To - */ - final IExpression toExp; - - // ############################################ - // Constructor - - /** - * Push constructor - */ - public PushStatement(IDescription desc) { - super(desc); - - // Get facets - itemExp = getFacet(IKeyword.ITEM); - toExp = getFacet(IKeyword.TO); - - // Save data from facets - String toName = (toExp != null) ? toExp.literalValue() : null; - - // Set name - setName("push to " + toName); - } - - // ############################################ - // Methods - - /** - * Return object casted into GamaDeque if possible, null otherwise - */ - private GamaDeque identifyContainer(final IScope scope, final IExpression toExp) throws GamaRuntimeException { - final Object cont = toExp.value(scope); - if (cont instanceof GamaDeque) { - return (GamaDeque) cont; - } - return null; - } - - /** - * Main fonction - */ - @Override - protected Object privateExecuteIn(IScope scope) throws GamaRuntimeException { - // Cast dequeu if possible - GamaDeque to = identifyContainer(scope, toExp); - // Get value form facet - Object data = itemExp.value(scope); - - // Check if deque and data are not null and insert data - if (to != null && data != null) { - to.addLast(data); - } - return to; - } - -} diff --git a/irit.gama.switchproject/src/irit/gaml/types/GamaQueueType.java b/irit.gama.switchproject/src/irit/gaml/types/GamaQueueType.java deleted file mode 100644 index 98bc468f..00000000 --- a/irit.gama.switchproject/src/irit/gaml/types/GamaQueueType.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************************************* - * - * GamaQueueType.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and - * simulation platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.types; - -import java.awt.Color; -import java.util.Collection; - -import irit.gama.common.interfaces.IKeywordIrit; -import irit.gama.util.deque.GamaQueue; -import msi.gama.common.util.StringUtils; -import msi.gama.metamodel.shape.GamaPoint; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.type; -import msi.gama.precompiler.IConcept; -import msi.gama.precompiler.ISymbolKind; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaDate; -import msi.gama.util.IContainer; -import msi.gaml.expressions.IExpression; -import msi.gaml.types.GamaContainerType; -import msi.gaml.types.IType; -import msi.gaml.types.Types; - -/** - * Queue type in GAML - * - * @author Jean-François Erdelyi - */ -@SuppressWarnings("rawtypes") -@type(name = IKeywordIrit.QUEUE, id = IKeywordIrit.QUEUE_TYPE, wraps = { - GamaQueue.class }, kind = ISymbolKind.Variable.CONTAINER, doc = { - @doc("Queue") }, concept = { IConcept.TYPE, IConcept.CONTAINER, IKeywordIrit.QUEUE }) -public class GamaQueueType extends GamaContainerType { - - // ############################################ - // Constructor - - /** - * TEMPORY CONSTRUCTOR TODO REMOVE THIS - */ - public GamaQueueType() { - id = IKeywordIrit.QUEUE_TYPE; - name = IKeywordIrit.QUEUE; - parent = null; - parented = false; - plugin = "irit.gama.switchproject"; - support = GamaQueue.class; - varKind = ISymbolKind.Variable.CONTAINER; - } - - // ############################################ - // Methods - - /** - * Cast data into GamaQueue - */ - @Override - public GamaQueue cast(final IScope scope, final Object obj, final Object param, final IType keyType, - final IType contentsType, final boolean copy) throws GamaRuntimeException { - return staticCast(scope, obj, contentsType, copy); - } - - /** - * Static cast definition - */ - @SuppressWarnings("unchecked") - public static GamaQueue staticCast(final IScope scope, final Object obj, final IType ct, final boolean copy) - throws GamaRuntimeException { - final IType contentsType = ct == null ? Types.NO_TYPE : ct; - - if (obj == null) { - return new GamaQueue(contentsType); - } - - if (obj instanceof GamaDate) { - return new GamaQueue(contentsType, ((GamaDate) obj).listValue(scope, contentsType)); - } - - if (obj instanceof IContainer) { - return new GamaQueue(contentsType, ((IContainer) obj).listValue(scope, contentsType, true)); - } - - if (obj instanceof Collection) { - return new GamaQueue(contentsType, (Collection) obj); - } - - if (obj instanceof Color) { - final Color c = (Color) obj; - return new GamaQueue(contentsType, new Integer[] { c.getRed(), c.getGreen(), c.getBlue() }); - } - - if (obj instanceof GamaPoint) { - final GamaPoint point = (GamaPoint) obj; - return new GamaQueue(contentsType, new Double[] { point.x, point.y }); - } - - if (obj instanceof String) { - return new GamaQueue(contentsType, StringUtils.tokenize((String) obj)); - } - - return new GamaQueue(contentsType, new Object[] { obj }); - } - - /** - * Get default value - */ - @Override - public GamaQueue getDefault() { - return null; - } - - /** - * Get key type (integer -> index) - */ - @Override - public IType getKeyType() { - return Types.get(INT); - } - - /** - * Get content type - */ - @Override - public IType contentsTypeIfCasting(final IExpression expr) { - switch (expr.getGamlType().id()) { - case COLOR: - case DATE: - return Types.get(INT); - case POINT: - return Types.get(FLOAT); - } - return super.contentsTypeIfCasting(expr); - } - - /** - * True (the type can const cast) - */ - @Override - public boolean canCastToConst() { - return true; - } -} diff --git a/irit.gama.switchproject/src/irit/gaml/types/GamaStackType.java b/irit.gama.switchproject/src/irit/gaml/types/GamaStackType.java deleted file mode 100644 index 1bb401eb..00000000 --- a/irit.gama.switchproject/src/irit/gaml/types/GamaStackType.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************************************* - * - * GamaStackType.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and - * simulation platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.types; - -import java.awt.Color; -import java.util.Collection; - -import irit.gama.common.interfaces.IKeywordIrit; -import irit.gama.util.deque.GamaStack; -import msi.gama.common.util.StringUtils; -import msi.gama.metamodel.shape.GamaPoint; -import msi.gama.precompiler.GamlAnnotations.doc; -import msi.gama.precompiler.GamlAnnotations.type; -import msi.gama.precompiler.IConcept; -import msi.gama.precompiler.ISymbolKind; -import msi.gama.runtime.IScope; -import msi.gama.runtime.exceptions.GamaRuntimeException; -import msi.gama.util.GamaDate; -import msi.gama.util.IContainer; -import msi.gaml.expressions.IExpression; -import msi.gaml.types.GamaContainerType; -import msi.gaml.types.IType; -import msi.gaml.types.Types; - -/** - * Stack type in GAML - * - * @author Jean-François Erdelyi - */ -@SuppressWarnings("rawtypes") -@type(name = IKeywordIrit.STACK, id = IKeywordIrit.STACK_TYPE, wraps = { - GamaStack.class }, kind = ISymbolKind.Variable.CONTAINER, doc = { - @doc("Stack") }, concept = { IConcept.TYPE, IConcept.CONTAINER, IKeywordIrit.STACK }) -public class GamaStackType extends GamaContainerType { - - // ############################################ - // Constructor - - /** - * TEMPORY CONSTRUCTOR TODO REMOVE THIS - */ - public GamaStackType() { - id = IKeywordIrit.STACK_TYPE; - name = IKeywordIrit.STACK; - parent = null; - parented = false; - plugin = "irit.gama.switchproject"; - support = GamaStack.class; - varKind = ISymbolKind.Variable.CONTAINER; - } - - // ############################################ - // Methods - - /** - * Cast data into GamaFifo - */ - @Override - public GamaStack cast(final IScope scope, final Object obj, final Object param, final IType keyType, - final IType contentsType, final boolean copy) throws GamaRuntimeException { - return staticCast(scope, obj, contentsType, copy); - } - - /** - * Static cast definition - */ - @SuppressWarnings("unchecked") - public static GamaStack staticCast(final IScope scope, final Object obj, final IType ct, final boolean copy) - throws GamaRuntimeException { - final IType contentsType = ct == null ? Types.NO_TYPE : ct; - - if (obj == null) { - return new GamaStack(contentsType); - } - - if (obj instanceof GamaDate) { - return new GamaStack(contentsType, ((GamaDate) obj).listValue(scope, contentsType)); - } - - if (obj instanceof IContainer) { - return new GamaStack(contentsType, ((IContainer) obj).listValue(scope, contentsType, true)); - } - - if (obj instanceof Collection) { - return new GamaStack(contentsType, (Collection) obj); - } - - if (obj instanceof Color) { - final Color c = (Color) obj; - return new GamaStack(contentsType, new Integer[] { c.getRed(), c.getGreen(), c.getBlue() }); - } - - if (obj instanceof GamaPoint) { - final GamaPoint point = (GamaPoint) obj; - return new GamaStack(contentsType, new Double[] { point.x, point.y }); - } - - if (obj instanceof String) { - return new GamaStack(contentsType, StringUtils.tokenize((String) obj)); - } - - return new GamaStack(contentsType, new Object[] { obj }); - } - - /** - * Get default value - */ - @Override - public GamaStack getDefault() { - return null; - } - - /** - * Get key type (integer -> index) - */ - @Override - public IType getKeyType() { - return Types.get(INT); - } - - /** - * Get content type - */ - @Override - public IType contentsTypeIfCasting(final IExpression expr) { - switch (expr.getGamlType().id()) { - case COLOR: - case DATE: - return Types.get(INT); - case POINT: - return Types.get(FLOAT); - } - return super.contentsTypeIfCasting(expr); - } - - /** - * True (the type can const cast) - */ - @Override - public boolean canCastToConst() { - return true; - } -} diff --git a/irit.gama.switchproject/src/irit/gaml/types/TypesIrit.java b/irit.gama.switchproject/src/irit/gaml/types/TypesIrit.java deleted file mode 100644 index 92b43506..00000000 --- a/irit.gama.switchproject/src/irit/gaml/types/TypesIrit.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************************************* - * - * TypesIrit.java, in plugin irit.gama.switchproject, is part of the source code of the GAMA modeling and - * simulation platform (v. 1.8.1) - * - * (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners - * - * Visit https://github.com/gama-platform/gama for license information and contacts. - * - ********************************************************************************************************/ - -package irit.gaml.types; - -/** - * IRIT types instances - * - * @author Jean-François Erdelyi - */ -public class TypesIrit { - /** - * Tempory static types QUEUE - */ - public static GamaQueueType QUEUE = new irit.gaml.types.GamaQueueType(); - - /** - * Tempory static types STACK - */ - public static GamaStackType STACK = new irit.gaml.types.GamaStackType(); -}