Created
June 28, 2017 06:31
-
-
Save fetttobse/731d499953225c75b556d1c434bf8d29 to your computer and use it in GitHub Desktop.
blackboxTemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("RCurl"); | |
library("rgl"); | |
checkedPositions = matrix(ncol=3); | |
colnames(checkedPositions) = c("x","y","z"); | |
currentMinimum = NULL; | |
open3d(); | |
main = function(){ | |
startX=0.0; | |
startY=0.0; | |
startZ=getZ(0.0,0.0); | |
checkedPositions[1,1] <<- startX; | |
checkedPositions[1,2] <<- startY; | |
checkedPositions[1,3] <<- startZ; | |
currentMinimum <<- c(startX,startY,startZ); | |
print("I checked the following positions yet:"); | |
print(checkedPositions); | |
print("And this is the current minimum:"); | |
print(currentMinimum); | |
loopCtr = 1; | |
while(TRUE){ | |
Sys.sleep(61); | |
#This is where the algorithm hits, set currX/Y/etc by algorithm | |
currX=runif(0,1); | |
currY=runif(0,1); | |
addPoint(currX,currY); | |
clear3d(); | |
plot3d(checkedPositions,expand=0.2) | |
print(paste("This was loop no",loopCtr,sep=" ")); | |
loopCtr = loopCtr+1; | |
} | |
} | |
addPoint = function(x,y){ | |
z = getZ(x,y); | |
checkedPositions <<- rbind(checkedPositions,c(x,y,z)); | |
print(paste("I added a new point:",x,y,z,sep=" ")); | |
print("I checked the following positions yet:"); | |
checkMinimum(x,y,z); | |
print(checkedPositions); | |
print("And this is the current minimum:"); | |
print(currentMinimum); | |
} | |
getZ = function(x,y){ | |
x = as.numeric(x); | |
y = as.numeric(y); | |
url=paste("http://webtechlecture.appspot.com/blackbox?x=",x,"&y=",y,sep=""); | |
z = getURL(url); | |
z = as.double(z); | |
print(z); | |
return(z); | |
} | |
checkMinimum = function(x,y,z){ | |
if(z<currentMinimum[3]){ | |
currentMinimum <<- c(x,y,z); | |
} | |
return(); | |
} | |
#Start at main() | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment