NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppGATests.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
27 // This application
28 
29 // This library
32 #include "helpers/FileHelpers.h"
33 // The C++ Standard Library
34 #include <iostream>
35 #include <exception>
36 
44 int main(int argc, char** argv)
45 {
46  std::cout << "AppGATests" << std::endl;
47 
48  /* Required for setting up learning file input/output. */
49  const std::string suffix((argc > 1) ? argv[1] : "default");
50 
51  std::string fileName = "Config.ini";
52  std::string path = "bmirletz/GATests/";
53 
54  NeuroEvolution testEvolution(suffix, fileName, path);
55 
56  std::string fullPath = FileHelpers::getResourcePath(path);
57 
58  configuration testConfigData;
59 
60  testConfigData.readFile(fullPath + fileName);
61  bool learning = testConfigData.getintvalue("learning");
62 
63  NeuroAdapter testAdapter;
64 
65  int numberOfInputs = testConfigData.getintvalue("numberOfStates");
66  int numberOfOutputs = testConfigData.getintvalue("numberOfActions");
67  std::vector<double> state(numberOfInputs, 1.0);
68  double goal = 1.0 * (double) numberOfOutputs;
69 
70 
71  int steps = 0;
72  while (steps < 30000)
73  {
74  testAdapter.initialize(&testEvolution,
75  learning,
76  testConfigData);
77 
78  std::vector<std::vector<double> > actions = testAdapter.step(0.0, state);
79  double score1 = 0.0;
80  for(std::size_t i = 0; i < actions.size(); i++)
81  {
82  for(std::size_t j = 0; j < actions[i].size(); j++)
83  {
84  score1 += actions[i][j];
85  }
86  }
87 
88  std::vector<double> scores;
89  scores.push_back(score1);
90  scores.push_back(0.0);
91 
92  testAdapter.endEpisode(scores);
93 
94  if (score1 == goal)
95  {
96  break;
97  }
98 
99  steps++;
100  }
101 
102  //Teardown is handled by delete, so that should be automatic
103  return 0;
104 }
void initialize(NeuroEvolution *evo, bool isLearning, configuration config)
A series of functions to assist with file input/output.
static std::string getResourcePath(std::string relPath)
Definition: FileHelpers.cpp:40
Defines a class NeuroAdapter to pass parameters from NeuroEvolution to a controller.
Top level class for NeuroEvolution.
int main(int argc, char **argv)
Definition: AppGATests.cpp:44