diff --git a/Add-ons/Cormas-logMovementOffromto.st b/Add-ons/Cormas-logMovementOffromto.st new file mode 100644 index 0000000000000000000000000000000000000000..7386ef7a4a772497427f0a949ea7a6de6119328e --- /dev/null +++ b/Add-ons/Cormas-logMovementOffromto.st @@ -0,0 +1,20 @@ +<?xml version="1.0"?> + +<st-source> +<time-stamp>From VisualWorks® NonCommercial, 7.6 of lundi 3 mars 2008 on mercredi 6 novembre 2019 at 1:37:51</time-stamp> + + +<methods> +<class-id>CormasNS.Kernel.Cormas</class-id> <category>simulation</category> + +<body package="Cormas" selector="logMovementOf:from:to:">logMovementOf: anAgentLocation from: srcSpatialEntity to: dstSpatialEntity + "Log the movement of an agent from a spatial entity to another entity" + self useExternalVisualization ifTrue: [ + xmlModel sendMoveToExternalVisualizerOf: anAgentLocation from: srcSpatialEntity to: dstSpatialEntity. + ]. + self exportPlaybackLog ifTrue: [ + xmlModel writeMoveToPlaybackLogOf: anAgentLocation from: srcSpatialEntity to: dstSpatialEntity. + ].</body> +</methods> + +</st-source> diff --git a/DESCRIPTION b/DESCRIPTION index 2f7487e74dbd9433d8d90217983e8f21240a80cb..04b78be464b6f66745f6775c57125bd9988bf615 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,14 @@ Package: RCormas -Title: What the Package Does (One Line, Title Case) +Title: Connexion between R and Cormas Agent Based Models Version: 0.0.0.9000 Authors@R: - person(given = "First", - family = "Last", + person(given = "Bruno", + family = "Bonté", role = c("aut", "cre"), - email = "first.last@example.com", + email = "bruno.bonte@irstea.fr", comment = structure("YOUR-ORCID-ID", .Names = "ORCID")) -Description: What the package does (one paragraph). -License: What license it uses +Description: Connection between R cran statistical analysis software and Cormas Software package. +License: MIT Encoding: UTF-8 LazyData: true RoxygenNote: 6.1.1 diff --git a/R/cormas-func.R b/R/cormas-func.R index 475109122600c2689ecef54c29fc324f7d08f87e..955be1c7808e3e30bf6f3299ffb3b13ca1178a55 100755 --- a/R/cormas-func.R +++ b/R/cormas-func.R @@ -16,9 +16,9 @@ # DataTransfR.st # Root.Smalltalk.CormasNS.Kernel.Entity-rTransfer.st -#Then Cormas needs to be open +#Then Cormas needs to be open -#Then you need open the R cormas connection: +#Then you need open the R cormas connection: #Simulation>analysis>R cormas>start webservice @@ -48,18 +48,16 @@ requestHead <- "<SOAP-ENV:Envelope xmlns:ns=\"urn:vwservices\" xmlns:SOAP-ENV=\" requestTail <- "</SOAP-ENV:Body> </SOAP-ENV:Envelope>" - #' formatRequest function #' Format a http request content that will be understood by cormasWS #' formatRequest #' Only used by the askCormas function -#' +#' #' @param functionName : A string with an identifier of the cormas function (not the exact name) #' @param argNames : A collection of strings with an identifier of the arguments of the cormas function (not the exact name) #' @param argValues : A collection of strings of numbers with an identifier of the arguments of the cormas function (not the exact name) #' @return : The anwser recieved from Cormas formated according to the httr package - formatRequest <- function(functionName, argNames, argValues){ request <- paste0(requestHead, "<ns:",functionName,">") args <- mapply(includeArg,argNames,argValues) @@ -80,7 +78,7 @@ return <- (paste0("<ns:",name,">",value,"</ns:",name,">")) } #' askCormas function -#' Send a http request to cormas +#' Send a http request to cormas #' send a request to cormas using the formatRequest function #' @param functionName a string specifying the cormas function identifier #' @param argNames a collection of string specifying the identifiers of arguments of the function @@ -94,7 +92,6 @@ return(list(request,result)) } - # R-CORMAS USERS FUNCTIONS ------------------------------------------------ #Functions that the user of the package can use @@ -104,6 +101,7 @@ return(list(request,result)) #' @param modelName a string specifying the name of the cormas model (model folder) #' @param parcelFile a string specifying name of the file to open without extension #' @return in a list the request formated in xml and the answer recieved from cormas +#' @examples r <- openModel("ECEC") # opens cormas model openModel <- function(modelName,parcelFile=paste0(modelName,".pcl")){ return(askCormas("LoadModelFromParcelName", @@ -112,9 +110,10 @@ return(askCormas("LoadModelFromParcelName", } #' setInit function -#' Choose the init function for the next simulation +#' Choose the init function for the next simulation #' @param initMethod a string specifying the name the init method to use #' @return in a list the request formated in xml and the answer recieved from cormas +#' @examples r <- setInit("homogeneousEnv") #set the init method "homogeneousEnv" (for Cormas model) setInit <- function(initMethod = "init"){ return(askCormas("SetInit", @@ -235,16 +234,16 @@ return(askCormas("SetStringAttributeOfClassValue", #' @return the answer recieved from cormas as text (shold be "done" if it worked) setAttributesOfEntities <- function(attributeName, className, entitiesIds, values){ - #This method uses a special feature of the method CormasWS>>setAttribute:ofClass:value: + #This method uses a special feature of the method CormasWS>>setAttribute:ofClass:value: #designed to set values of attribute "attributeName" of all entities of class "className" answer <- askCormas("SetAttributeOfClassValue", argNames = c("attName", "className", "value"), - argValues = c(paste(className, - attributeName, - paste(as.character(entitiesIds),collapse = ","), - paste(values,collapse = ","), - sep = ";"), - "DataTransfRSet", + argValues = c(paste(className, + attributeName, + paste(as.character(entitiesIds),collapse = ","), + paste(values,collapse = ","), + sep = ";"), + "DataTransfRSet", 0))[[2]] stringRes <- xml_text(xml_find_all(content(answer),xpath=".//ns:result")) return(stringRes) @@ -256,16 +255,16 @@ setAttributesOfEntities <- function(attributeName, className, entitiesIds, value #' @param attributeName an string specifying the name of the attribute #' @param className an string specifying the class of the attribute #' @param num a boolean specifying if you are wating for numeric or string values -#' @return a dataframe with a column id with ids of entities +#' @return a dataframe with a column id with ids of entities #' and a column with the name of the requested attribute getAttributesOfEntities <- function(attributeName, className, num = T){ - #This method uses a special feature of the method CormasWS>>setAttribute:ofClass:value: + #This method uses a special feature of the method CormasWS>>setAttribute:ofClass:value: #designed to get values of attribute "attributeName" of all entities of class "className" answer <- askCormas("SetAttributeOfClassValue", argNames = c("attName", "className", "value"), - argValues = c(paste(className, attributeName, " ", " ", sep=";"), - "DataTransfRGet", + argValues = c(paste(className, attributeName, " ", " ", sep=";"), + "DataTransfRGet", 0))[[2]] stringRes <- xml_text(xml_find_all(content(answer),xpath=".//ns:result")) idsValues <- strsplit(stringRes, split = ";")[[1]] @@ -287,19 +286,19 @@ getAttributesOfEntities <- function(attributeName, className, num = T){ openViwualWorks <- function(GUI = T) { if(GUI) { system(paste0("$VISUALWORKS", - "/bin/linux86/visual ", + "/bin/linux86/visual ", "$VISUALWORKS", "/cormas/cormasMac-com-work.im > ", - " $VISUALWORKS", + " $VISUALWORKS", "/cormas/r-cormas.log &")) } else { system(paste0("$VISUALWORKS", - "/bin/linux86/visual ", + "/bin/linux86/visual ", "$VISUALWORKS", "/cormas/cormasMac-com-work.im", " -headless > ", - " $VISUALWORKS", + " $VISUALWORKS", "/cormas/r-cormas.log &")) } }