Commit 50e23de9 authored by Bonte Bruno's avatar Bonte Bruno
Browse files

add a new add-on to fix bug

parent 3544ecd2
No related merge requests found
Showing with 48 additions and 29 deletions
+48 -29
<?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>
Package: RCormas 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 Version: 0.0.0.9000
Authors@R: Authors@R:
person(given = "First", person(given = "Bruno",
family = "Last", family = "Bonté",
role = c("aut", "cre"), role = c("aut", "cre"),
email = "first.last@example.com", email = "bruno.bonte@irstea.fr",
comment = structure("YOUR-ORCID-ID", .Names = "ORCID")) comment = structure("YOUR-ORCID-ID", .Names = "ORCID"))
Description: What the package does (one paragraph). Description: Connection between R cran statistical analysis software and Cormas Software package.
License: What license it uses License: MIT
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: true
RoxygenNote: 6.1.1 RoxygenNote: 6.1.1
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
# DataTransfR.st # DataTransfR.st
# Root.Smalltalk.CormasNS.Kernel.Entity-rTransfer.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 #Simulation>analysis>R cormas>start webservice
...@@ -48,18 +48,16 @@ requestHead <- "<SOAP-ENV:Envelope xmlns:ns=\"urn:vwservices\" xmlns:SOAP-ENV=\" ...@@ -48,18 +48,16 @@ requestHead <- "<SOAP-ENV:Envelope xmlns:ns=\"urn:vwservices\" xmlns:SOAP-ENV=\"
requestTail <- "</SOAP-ENV:Body> </SOAP-ENV:Envelope>" requestTail <- "</SOAP-ENV:Body> </SOAP-ENV:Envelope>"
#' formatRequest function #' formatRequest function
#' Format a http request content that will be understood by cormasWS #' Format a http request content that will be understood by cormasWS
#' formatRequest #' formatRequest
#' Only used by the askCormas function #' Only used by the askCormas function
#' #'
#' @param functionName : A string with an identifier of the cormas function (not the exact name) #' @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 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) #' @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 #' @return : The anwser recieved from Cormas formated according to the httr package
formatRequest <- function(functionName, argNames, argValues){ formatRequest <- function(functionName, argNames, argValues){
request <- paste0(requestHead, "<ns:",functionName,">") request <- paste0(requestHead, "<ns:",functionName,">")
args <- mapply(includeArg,argNames,argValues) args <- mapply(includeArg,argNames,argValues)
...@@ -80,7 +78,7 @@ return <- (paste0("<ns:",name,">",value,"</ns:",name,">")) ...@@ -80,7 +78,7 @@ return <- (paste0("<ns:",name,">",value,"</ns:",name,">"))
} }
#' askCormas function #' askCormas function
#' Send a http request to cormas #' Send a http request to cormas
#' send a request to cormas using the formatRequest function #' send a request to cormas using the formatRequest function
#' @param functionName a string specifying the cormas function identifier #' @param functionName a string specifying the cormas function identifier
#' @param argNames a collection of string specifying the identifiers of arguments of the function #' @param argNames a collection of string specifying the identifiers of arguments of the function
...@@ -94,7 +92,6 @@ return(list(request,result)) ...@@ -94,7 +92,6 @@ return(list(request,result))
} }
# R-CORMAS USERS FUNCTIONS ------------------------------------------------ # R-CORMAS USERS FUNCTIONS ------------------------------------------------
#Functions that the user of the package can use #Functions that the user of the package can use
...@@ -104,6 +101,7 @@ return(list(request,result)) ...@@ -104,6 +101,7 @@ return(list(request,result))
#' @param modelName a string specifying the name of the cormas model (model folder) #' @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 #' @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 #' @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")){ openModel <- function(modelName,parcelFile=paste0(modelName,".pcl")){
return(askCormas("LoadModelFromParcelName", return(askCormas("LoadModelFromParcelName",
...@@ -112,9 +110,10 @@ return(askCormas("LoadModelFromParcelName", ...@@ -112,9 +110,10 @@ return(askCormas("LoadModelFromParcelName",
} }
#' setInit function #' 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 #' @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 #' @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"){ setInit <- function(initMethod = "init"){
return(askCormas("SetInit", return(askCormas("SetInit",
...@@ -235,16 +234,16 @@ return(askCormas("SetStringAttributeOfClassValue", ...@@ -235,16 +234,16 @@ return(askCormas("SetStringAttributeOfClassValue",
#' @return the answer recieved from cormas as text (shold be "done" if it worked) #' @return the answer recieved from cormas as text (shold be "done" if it worked)
setAttributesOfEntities <- function(attributeName, className, entitiesIds, values){ 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" #designed to set values of attribute "attributeName" of all entities of class "className"
answer <- askCormas("SetAttributeOfClassValue", answer <- askCormas("SetAttributeOfClassValue",
argNames = c("attName", "className", "value"), argNames = c("attName", "className", "value"),
argValues = c(paste(className, argValues = c(paste(className,
attributeName, attributeName,
paste(as.character(entitiesIds),collapse = ","), paste(as.character(entitiesIds),collapse = ","),
paste(values,collapse = ","), paste(values,collapse = ","),
sep = ";"), sep = ";"),
"DataTransfRSet", "DataTransfRSet",
0))[[2]] 0))[[2]]
stringRes <- xml_text(xml_find_all(content(answer),xpath=".//ns:result")) stringRes <- xml_text(xml_find_all(content(answer),xpath=".//ns:result"))
return(stringRes) return(stringRes)
...@@ -256,16 +255,16 @@ setAttributesOfEntities <- function(attributeName, className, entitiesIds, value ...@@ -256,16 +255,16 @@ setAttributesOfEntities <- function(attributeName, className, entitiesIds, value
#' @param attributeName an string specifying the name of the attribute #' @param attributeName an string specifying the name of the attribute
#' @param className an string specifying the class 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 #' @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 #' and a column with the name of the requested attribute
getAttributesOfEntities <- function(attributeName, className, num = T){ 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" #designed to get values of attribute "attributeName" of all entities of class "className"
answer <- askCormas("SetAttributeOfClassValue", answer <- askCormas("SetAttributeOfClassValue",
argNames = c("attName", "className", "value"), argNames = c("attName", "className", "value"),
argValues = c(paste(className, attributeName, " ", " ", sep=";"), argValues = c(paste(className, attributeName, " ", " ", sep=";"),
"DataTransfRGet", "DataTransfRGet",
0))[[2]] 0))[[2]]
stringRes <- xml_text(xml_find_all(content(answer),xpath=".//ns:result")) stringRes <- xml_text(xml_find_all(content(answer),xpath=".//ns:result"))
idsValues <- strsplit(stringRes, split = ";")[[1]] idsValues <- strsplit(stringRes, split = ";")[[1]]
...@@ -287,19 +286,19 @@ getAttributesOfEntities <- function(attributeName, className, num = T){ ...@@ -287,19 +286,19 @@ getAttributesOfEntities <- function(attributeName, className, num = T){
openViwualWorks <- function(GUI = T) { openViwualWorks <- function(GUI = T) {
if(GUI) { if(GUI) {
system(paste0("$VISUALWORKS", system(paste0("$VISUALWORKS",
"/bin/linux86/visual ", "/bin/linux86/visual ",
"$VISUALWORKS", "$VISUALWORKS",
"/cormas/cormasMac-com-work.im > ", "/cormas/cormasMac-com-work.im > ",
" $VISUALWORKS", " $VISUALWORKS",
"/cormas/r-cormas.log &")) "/cormas/r-cormas.log &"))
} }
else { else {
system(paste0("$VISUALWORKS", system(paste0("$VISUALWORKS",
"/bin/linux86/visual ", "/bin/linux86/visual ",
"$VISUALWORKS", "$VISUALWORKS",
"/cormas/cormasMac-com-work.im", "/cormas/cormasMac-com-work.im",
" -headless > ", " -headless > ",
" $VISUALWORKS", " $VISUALWORKS",
"/cormas/r-cormas.log &")) "/cormas/r-cormas.log &"))
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment