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/WorkingMemoryInterface.h>
29 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
30 #include <MemoryX/interface/components/CommonPlacesLearnerInterface.h>
31 
32 namespace memoryx
33 {
34 
37  {
38  public:
41  {
42  defineOptionalProperty<std::string>("TestToRun", "LearnFromSnapshot", "Name of test that should be executed (LearnFromSnapshot, LoadLTM)");
43  defineOptionalProperty<std::string>("SnapshotToLoad", "", "Name of snapshot to be loaded into WM on startup");
44  defineOptionalProperty<std::string>("SnapshotsToLearnFrom", "", "Comma-separated list of snapshot to be processed by CommonPlacesLearner");
45  defineOptionalProperty<bool>("LoadToWM", false, "Load LTM contents to WM after each learned snapshot (e.g. for visualization)");
46 
47  defineOptionalProperty<int>("InitialDelay", 0, "Timeout before starting the learning process (in ms)");
48  defineOptionalProperty<int>("DelayBetweenSnapshots", 0, "Timeout after each learned snapshot (in ms)");
49  defineOptionalProperty<std::string>("ObjectToLoad", "", "Name of object to load from LTM ");
50  defineOptionalProperty<std::string>("LTMSegment", "objects", "Name of segment in LTM to store learned CommonPlaces / to run queries on");
51  defineOptionalProperty<std::string>("ClusterDeviationType", "AABB", "Type of deviation: AABB, OrientedBBox or EqualSphere");
52  defineOptionalProperty<float>("ClusterMaxDeviation", 100., "Max. intra-cluster deviation (meanings depends of ClusterDeviationType)");
53 
54  defineOptionalProperty<int>("SampleSize", 10, "");
55  defineOptionalProperty<int>("IterationCount", 1, "");
56 
57  }
58  };
59 
61  virtual public armarx::Component
62  {
63  public:
64  /**
65  * @see PropertyUser::createPropertyDefinitions()
66  */
68  {
71  getConfigIdentifier()));
72  }
73 
74  // inherited from Component
75  std::string getDefaultName() const override
76  {
77  return "CommonPlacesTester";
78  }
79  void onInitComponent() override;
80  void onConnectComponent() override;
81 
82  private:
83  WorkingMemoryInterfacePrx memoryPrx;
84  LongtermMemoryInterfacePrx longtermMemoryPrx;
85  CommonPlacesLearnerInterfacePrx cpLearnerPrx;
86  std::string testToRun;
87  std::string objectToLoad;
88  std::string ltmSegmentName;
89 
90  void testLearnFromSnapshot();
91  void testLearnFromSingleSnapshot();
92  void testLoadLTM();
93  void testClustering();
94 
95  void testMerging();
96  void testClusteringBatch();
97  void testAging();
98  void testAging2();
99  void testGetClusterLocations();
100 
101  void getRandomIds(std::vector<std::string>& allIds, std::vector<std::string>& ids, int sampleSize);
102 
103  DeviationType getDeviationTypeFromString(const std::string& devTypeStr);
104 
105  struct SimpleTimer
106  {
107  struct timeval tv1, tv2, dtv;
108  struct timezone tz;
109  void time_start()
110  {
111  gettimeofday(&tv1, &tz);
112  }
113  long time_stop()
114  {
115  gettimeofday(&tv2, &tz);
116  dtv.tv_sec = tv2.tv_sec - tv1.tv_sec;
117  dtv.tv_usec = tv2.tv_usec - tv1.tv_usec;
118 
119  if (dtv.tv_usec < 0)
120  {
121  dtv.tv_sec--;
122  dtv.tv_usec += 1000000;
123  }
124 
125  return dtv.tv_sec * 1000 + dtv.tv_usec / 1000;
126  }
127  };
128 
129  SimpleTimer mstimer;
130  };
131 }
memoryx::CommonPlacesTester
Definition: CommonPlacesTester.h:60
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
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:67
memoryx::CommonPlacesTester::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: CommonPlacesTester.h:75
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
memoryx::CommonPlacesTesterPropertyDefinitions::CommonPlacesTesterPropertyDefinitions
CommonPlacesTesterPropertyDefinitions(std::string prefix)
Definition: CommonPlacesTester.h:39
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
ImportExportComponent.h