CommonPlacesTester.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::CommonPlacesTester
17 * @author Alexey Kozlov (kozlov at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
27 
28 #include <MemoryX/interface/components/CommonPlacesLearnerInterface.h>
29 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
30 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
31 
32 namespace memoryx
33 {
34 
36  {
37  public:
40  {
41  defineOptionalProperty<std::string>(
42  "TestToRun",
43  "LearnFromSnapshot",
44  "Name of test that should be executed (LearnFromSnapshot, LoadLTM)");
45  defineOptionalProperty<std::string>(
46  "SnapshotToLoad", "", "Name of snapshot to be loaded into WM on startup");
47  defineOptionalProperty<std::string>(
48  "SnapshotsToLearnFrom",
49  "",
50  "Comma-separated list of snapshot to be processed by CommonPlacesLearner");
51  defineOptionalProperty<bool>(
52  "LoadToWM",
53  false,
54  "Load LTM contents to WM after each learned snapshot (e.g. for visualization)");
55 
56  defineOptionalProperty<int>(
57  "InitialDelay", 0, "Timeout before starting the learning process (in ms)");
58  defineOptionalProperty<int>(
59  "DelayBetweenSnapshots", 0, "Timeout after each learned snapshot (in ms)");
60  defineOptionalProperty<std::string>(
61  "ObjectToLoad", "", "Name of object to load from LTM ");
62  defineOptionalProperty<std::string>(
63  "LTMSegment",
64  "objects",
65  "Name of segment in LTM to store learned CommonPlaces / to run queries on");
66  defineOptionalProperty<std::string>(
67  "ClusterDeviationType",
68  "AABB",
69  "Type of deviation: AABB, OrientedBBox or EqualSphere");
70  defineOptionalProperty<float>(
71  "ClusterMaxDeviation",
72  100.,
73  "Max. intra-cluster deviation (meanings depends of ClusterDeviationType)");
74 
75  defineOptionalProperty<int>("SampleSize", 10, "");
76  defineOptionalProperty<int>("IterationCount", 1, "");
77  }
78  };
79 
81  {
82  public:
83  /**
84  * @see PropertyUser::createPropertyDefinitions()
85  */
88  {
90  new CommonPlacesTesterPropertyDefinitions(getConfigIdentifier()));
91  }
92 
93  // inherited from Component
94  std::string
95  getDefaultName() const override
96  {
97  return "CommonPlacesTester";
98  }
99 
100  void onInitComponent() override;
101  void onConnectComponent() override;
102 
103  private:
104  WorkingMemoryInterfacePrx memoryPrx;
105  LongtermMemoryInterfacePrx longtermMemoryPrx;
106  CommonPlacesLearnerInterfacePrx cpLearnerPrx;
107  std::string testToRun;
108  std::string objectToLoad;
109  std::string ltmSegmentName;
110 
111  void testLearnFromSnapshot();
112  void testLearnFromSingleSnapshot();
113  void testLoadLTM();
114  void testClustering();
115 
116  void testMerging();
117  void testClusteringBatch();
118  void testAging();
119  void testAging2();
120  void testGetClusterLocations();
121 
122  void getRandomIds(std::vector<std::string>& allIds,
123  std::vector<std::string>& ids,
124  int sampleSize);
125 
126  DeviationType getDeviationTypeFromString(const std::string& devTypeStr);
127 
128  struct SimpleTimer
129  {
130  struct timeval tv1, tv2, dtv;
131  struct timezone tz;
132 
133  void
134  time_start()
135  {
136  gettimeofday(&tv1, &tz);
137  }
138 
139  long
140  time_stop()
141  {
142  gettimeofday(&tv2, &tz);
143  dtv.tv_sec = tv2.tv_sec - tv1.tv_sec;
144  dtv.tv_usec = tv2.tv_usec - tv1.tv_usec;
145 
146  if (dtv.tv_usec < 0)
147  {
148  dtv.tv_sec--;
149  dtv.tv_usec += 1000000;
150  }
151 
152  return dtv.tv_sec * 1000 + dtv.tv_usec / 1000;
153  }
154  };
155 
156  SimpleTimer mstimer;
157  };
158 } // namespace memoryx
memoryx::CommonPlacesTester
Definition: CommonPlacesTester.h:80
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::CommonPlacesTesterPropertyDefinitions
Definition: CommonPlacesTester.h:35
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::CommonPlacesTester::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CommonPlacesTester.h:87
memoryx::CommonPlacesTester::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: CommonPlacesTester.h:95
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
memoryx::CommonPlacesTesterPropertyDefinitions::CommonPlacesTesterPropertyDefinitions
CommonPlacesTesterPropertyDefinitions(std::string prefix)
Definition: CommonPlacesTester.h:38
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
ImportExportComponent.h