private ArrayList<YoVariable<?>> getSimpleRobotRegExpVariables(String[] varNames, String[] regularExpressions, Robot robotModel) { ArrayList<YoVariable<?>> currentlyMatched = robotModel.getAllVariables(); YoVariableList tempList = new YoVariableList("temp"); for (int i = 0; i < currentlyMatched.size(); i++) { YoVariable var = currentlyMatched.get(i); tempList.addVariable(var); } return tempList.getMatchingVariables(varNames, regularExpressions); }
private YoVariableList createYoVariableList(String name, YoVariable<?>[] yoVariables) { YoVariableList yoVariableList = new YoVariableList(name); yoVariableList.addVariables(yoVariables); return yoVariableList; }
private void putVariablesInIndexMap() { for (int i = 0; i < allVariables.size(); i++) { YoVariable<?> v = allVariables.getVariable(i); allVariablesIndexMap.put(v, i); System.out.println(i + " " + v.getFullNameWithNameSpace()); } }
public void addVariables(YoVariableList controlVars) { ArrayList<YoVariable<?>> variables = controlVars.getVariables(); this.addVariables(variables); }
@Test// timeout = 30000 public void testWritingAndReadingALongStateFile() throws IOException { File fileOne = new File("fileOne.state"); if (fileOne.exists()) fileOne.delete(); long seed = 1776L; int numberOfVariables = 2000; // 12000 for when testing long files for efficiency; Random random = new Random(seed); ArrayList<YoVariable<?>> variables = createALargeNumberOfVariables(random, numberOfVariables); YoVariableList originalVarList = new YoVariableList("originalVarList"); originalVarList.addVariables(variables); writeALongStateFile(fileOne, variables); DataFileReader dataFileReader = new DataFileReader(fileOne); YoVariableList newVarList = new YoVariableList("newVarList"); boolean createMissingVariables = true; boolean printErrorForMissingVariables = false; YoVariableRegistry registry = new YoVariableRegistry("root"); dataFileReader.readState(newVarList, createMissingVariables, printErrorForMissingVariables, registry); assertEquals(originalVarList.size(), newVarList.size()); for (int i = 0; i < originalVarList.size(); i++) { YoVariable<?> originalVariable = originalVarList.getVariable(i); YoVariable<?> newVariable = newVarList.getVariable(originalVariable.getName()); assertFalse(originalVariable == newVariable); assertEquals(originalVariable.getValueAsDouble(), newVariable.getValueAsDouble(), 1e-7); } fileOne.delete(); }
YoVariableList varList = new YoVariableList("foo_" + count); varList.addVariable(foo);
public void convertData() throws IOException { File binaryFile = new File(binaryFilename); File asciiFile = new File(asciiFilename); int bufferSize = 16000; DataFileReader reader = new DataFileReader(binaryFile); YoVariableList newVars = new YoVariableList("Converter"); DataBuffer dataBuffer = new DataBuffer(bufferSize); YoVariableRegistry rootRegistry = new YoVariableRegistry("root"); reader.readData(newVars, rootRegistry, dataBuffer); DataFileWriter dataFileWriter = new DataFileWriter(asciiFile); boolean binary = false; boolean compress = false; ArrayList<YoVariable<?>> varsToWrite = newVars.getVariables(); dataFileWriter.writeData("ConvertedData", 0.001, dataBuffer, varsToWrite, binary, compress); }
public void addVariables(YoVariable<?>[] variables) { for (int i = 0; i < variables.length; i++) { this.addVariable(variables[i]); } }
@Override public void doAllRegistriesAndVariables(String[] registryNames, String[][] variableNames, float[][] initialValues) { if (registryNames.length != variableNames.length) throw new RuntimeException("registryNames.length != variableNames.length"); if (registryNames.length != initialValues.length) throw new RuntimeException("registryNames.length != initialValues.length"); doAllRegistries(registryNames, variableNames); allVariables = new YoVariableList("All Variables"); for (int i=0; i<variableNames.length; i++) { addVariables(variableNames[i].length, variableNames[i], initialValues[i]); } putVariablesInIndexMap(); // verifyRegistriesAndVariableListsAreConsistent(registryNames, variableNames); doneReceivingAllRegistriesAndVariables = true; }
public synchronized boolean hasVariableWithName(String name) { if (getVariable(name) != null) { return true; } return false; }
private void createVarListsIncludingChildren(HashMap<String, YoVariableList> allVarLists) { // Add mine: YoVariableList myVarList = this.createVarList(); if (allVarLists.containsKey(myVarList.getName())) { YoVariableList varList = allVarLists.get(myVarList.getName()); varList.addVariables(myVarList); } else { allVarLists.put(myVarList.getName(), myVarList); } // Add all the children recursively: for (YoVariableRegistry child : children) { child.createVarListsIncludingChildren(allVarLists); } }
Random random = new Random(seed); ArrayList<YoVariable<?>> variables = createALargeNumberOfVariables(random, numberOfVariables); YoVariableList originalVarList = new YoVariableList("originalVarList"); originalVarList.addVariables(variables); YoVariableList newVarList = new YoVariableList("newVarList"); YoVariableRegistry registry = new YoVariableRegistry("rootRegistry"); dataFileReader.readData(newVarList, registry, newDataBuffer); assertEquals(originalVarList.size(), newVarList.size()); for (int i = 0; i < originalVarList.size(); i++) YoVariable<?> originalVariable = originalVarList.getVariable(i); YoVariable<?> newVariable = newVarList.getVariable(originalVariable.getName());
public void addVariables(ArrayList<YoVariable<?>> list) { for (YoVariable<?> variable : list) { this.addVariable(variable); } }
private void testDataWriteReadIsTheSame(DataBuffer dataBuffer, ArrayList<YoVariable<?>> allVariables, boolean binary, boolean compress, boolean spreadsheetFormatted, Robot robot) throws IOException, URISyntaxException { String filename = TEST_DIRECTORY + "testFile.data"; if (spreadsheetFormatted) filename = filename + ".csv"; if (compress) filename = filename + ".gz"; URL resource = getClass().getClassLoader().getResource(filename); File testFile = new File(resource.getFile()); String model = "testModel"; double recordDT = 0.001; DataFileWriter dataFileWriter = new DataFileWriter(testFile); if (spreadsheetFormatted) { dataFileWriter.writeSpreadsheetFormattedData(dataBuffer, allVariables); } else { dataFileWriter.writeData(model, recordDT, dataBuffer, allVariables, binary, compress, robot); } DataFileReader dataFileReader = new DataFileReader(testFile); DataBuffer readBackBuffer = new DataBuffer(dataBuffer.getBufferSize()); YoVariableRegistry readBackRegistry = new YoVariableRegistry("rootRegistry"); YoVariableList newVars = new YoVariableList("newVars"); dataFileReader.readData(newVars, readBackRegistry, readBackBuffer); boolean dataIsEqual = readBackBuffer.checkIfDataIsEqual(dataBuffer, 1e-7); assertTrue(dataIsEqual); }
YoVariable<?> var = getVariable(name);
public ArrayList<YoVariable<?>> getVars(String[] varNames, String[] regularExpressions) { YoVariableList tempList = new YoVariableList("temp"); for (int i = 0; i < entries.size(); i++) { YoVariable<?> var = (entries.get(i)).getVariable(); tempList.addVariable(var); } return tempList.getMatchingVariables(varNames, regularExpressions); }
public YoVariableList createVarList() { YoVariableList ret = new YoVariableList(this.nameSpace.getName()); ret.addVariables(controlVars); return ret; }
private void updateLogVarsCount() { logVarsCount = 0; int numberToIterate = allVariables.size(); for (int i=0; i<numberToIterate; i++) { YoVariable<?> var = allVariables.getVariable(i); if (var.getYoVariableRegistry().isLogged()) logVarsCount++; } }
private void addVariableAndSetInitialValue(float initialValue, String fullVariableName, YoVariable<?> variable) { System.out.println("Found var: " + fullVariableName); allVariables.addVariable(variable); variable.setValueFromDouble(initialValue); }
private void addVariables(int nvars, String[] vars, float[] vals) { for (int i = 0; i < nvars; i++) { // System.out.println("Looking for var " + vars[i]); String fullVariableName = vars[i]; YoVariable<?> v = rootRegistry.getVariable(fullVariableName); if (allVariables.getVariable(fullVariableName) != null) { System.err.println("Robot has repeat variable names! Already registered " + fullVariableName); System.err.flush(); System.exit(-1); } if (v != null) { addVariableAndSetInitialValue(vals[i], fullVariableName, v); } else { createAndAddVariableAndSetInitialValue(vals[i], fullVariableName); } } }