PredictionEntity.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::Core
19  * @author Manfred Kroehnert (Manfred dot Kroehnert at kit dot edu)
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "PredictionEntity.h"
26 
27 #include "../../../../core/entity/EntityRef.h"
28 
29 namespace memoryx
30 {
31  const std::string PredictionEntity::SNAPSHOT_ATTRIBUTE("memorySnapshot");
32  const std::string PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE("sourceMemorySnapshot");
33  const std::string PredictionEntity::PREDICTION_ATTRIBUTE("predictedMemorySnapshot");
34  const std::string PredictionEntity::PREDICTION_LIST_ATTRIBUTE("predictedMemorySnapshotList");
35  const std::string PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE("predictionMethodName");
36  const std::string PredictionEntity::TASK_COUNT_ATTRIBUTE("taskCount");
37  const std::string PredictionEntity::PREDICTION_SCORE_ATTRIBUTE("predictionScore");
38 
40  {
42  }
43 
44  PredictionEntity::PredictionEntity(const EntityRefBasePtr& memorySnapshotRef,
45  const EntityRefBasePtr& sourceMemorySnapshotRef,
46  const EntityRefBasePtr& predictedMemorySnapshotRef,
47  const EntityRefBaseList& predictedMemorySnapshotRefList,
48  const std::string& predictionMethodName,
49  Ice::Int taskCount,
50  Ice::Float predictionScore) :
51  Entity()
52  {
54  setProfilerMemorySnapshotRef(memorySnapshotRef);
55  setSourceProfilerMemorySnapshotRef(sourceMemorySnapshotRef);
56  setPredictedProfilerMemorySnapshotRef(predictedMemorySnapshotRef);
57  setPredictedProfilerMemorySnapshotRefList(predictedMemorySnapshotRefList);
58  setPredictionMethodName(predictionMethodName);
59  setTaskCount(taskCount);
60  setPredictionScore(predictionScore);
61  }
62 
64  IceUtil::Shared(source),
65  ::armarx::Serializable(source),
66  EntityBase(), // dont copy
67  PredictionEntityBase(source),
68  Entity(source)
69  {
70  }
71 
73  {
74  }
75 
76  void
78  {
79  putAttribute(new EntityAttribute(PredictionEntity::SNAPSHOT_ATTRIBUTE));
80  putAttribute(new EntityAttribute(PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE));
81  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_ATTRIBUTE));
82  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_LIST_ATTRIBUTE));
83  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE));
84  putAttribute(new EntityAttribute(PredictionEntity::TASK_COUNT_ATTRIBUTE));
85  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_SCORE_ATTRIBUTE));
86  }
87 
88  void
89  PredictionEntity::output(std::ostream& stream) const
90  {
91  Entity::output(stream);
92  }
93 
96  {
97  return this->clone();
98  }
99 
101  PredictionEntity::clone(const Ice::Current& context) const
102  {
103  std::shared_lock entityLock(entityMutex);
104  std::scoped_lock attributesLock(attributesMutex);
105  std::scoped_lock wrappersLock(wrappersMutex);
106  return new PredictionEntity(*this);
107  }
108 
109  EntityRefBasePtr
111  {
112  return getAttributeValue(PredictionEntity::SNAPSHOT_ATTRIBUTE)->get<EntityRef>();
113  }
114 
115  void
116  PredictionEntity::setProfilerMemorySnapshotRef(const EntityRefBasePtr& memorySnapshotRef,
117  const Ice::Current&)
118  {
119  getAttribute(PredictionEntity::SNAPSHOT_ATTRIBUTE)
120  ->setValue(new armarx::Variant(memorySnapshotRef));
121  }
122 
123  EntityRefBasePtr
125  {
126  return getAttributeValue(PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE)->get<EntityRef>();
127  }
128 
129  void
131  const EntityRefBasePtr& sourceMemorySnapshotRef,
132  const Ice::Current&)
133  {
134  getAttribute(PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE)
135  ->setValue(new armarx::Variant(sourceMemorySnapshotRef));
136  }
137 
138  EntityRefBasePtr
140  {
141  return getAttributeValue(PredictionEntity::PREDICTION_ATTRIBUTE)->get<EntityRef>();
142  }
143 
144  void
146  const EntityRefBasePtr& predictedMemorySnapshotRef,
147  const Ice::Current&)
148  {
149  getAttribute(PredictionEntity::PREDICTION_ATTRIBUTE)
150  ->setValue(new armarx::Variant(predictedMemorySnapshotRef));
151  }
152 
153  EntityRefBaseList
155  {
156  EntityAttributeBasePtr attribute =
157  getAttribute(PredictionEntity::PREDICTION_LIST_ATTRIBUTE);
158  EntityRefBaseList entityList;
159  for (int i = 0; i < attribute->size(); i++)
160  {
161  armarx::VariantPtr attributeValue =
162  armarx::VariantPtr::dynamicCast(attribute->getValueAt(i));
163  entityList.push_back(attributeValue->get<EntityRef>());
164  }
165  return entityList;
166  }
167 
168  void
170  const EntityRefBaseList& predictedMemorySnapshotRefList,
171  const Ice::Current&)
172  {
173  EntityAttributeBasePtr attribute =
174  getAttribute(PredictionEntity::PREDICTION_LIST_ATTRIBUTE);
175  attribute->clear();
176  for (const EntityRefBasePtr& entityRef : predictedMemorySnapshotRefList)
177  {
178  attribute->addValue(new armarx::Variant(entityRef));
179  }
180  }
181 
182  std::string
183  PredictionEntity::getPredictionMethodName(const Ice::Current&) const
184  {
185  return getAttribute(PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE)
186  ->getValue()
187  ->getString();
188  }
189 
190  void
191  PredictionEntity::setPredictionMethodName(const std::string& predictionMethodName,
192  const Ice::Current&)
193  {
194  getAttribute(PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE)
195  ->setValue(new armarx::Variant(predictionMethodName));
196  }
197 
198  Ice::Int
199  PredictionEntity::getTaskCount(const Ice::Current&) const
200  {
201  return getAttributeValue(PredictionEntity::TASK_COUNT_ATTRIBUTE)->getInt();
202  }
203 
204  void
205  PredictionEntity::setTaskCount(Ice::Int taskCount, const Ice::Current&)
206  {
207  getAttribute(PredictionEntity::TASK_COUNT_ATTRIBUTE)
208  ->setValue(new armarx::Variant(taskCount));
209  }
210 
211  Ice::Float
212  PredictionEntity::getPredictionScore(const Ice::Current&) const
213  {
214  return getAttributeValue(PredictionEntity::PREDICTION_SCORE_ATTRIBUTE)->getFloat();
215  }
216 
217  void
218  PredictionEntity::setPredictionScore(Ice::Float predictionScore, const Ice::Current&)
219  {
220  getAttribute(PredictionEntity::PREDICTION_SCORE_ATTRIBUTE)
221  ->setValue(new armarx::Variant(predictionScore));
222  }
223 } // namespace memoryx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
memoryx::PredictionEntity::getPredictionMethodName
std::string getPredictionMethodName(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:183
memoryx::PredictionEntity
Definition: PredictionEntity.h:35
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:347
memoryx::PredictionEntity::initializeAttributes
void initializeAttributes()
Definition: PredictionEntity.cpp:77
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:311
memoryx::PredictionEntity::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: PredictionEntity.cpp:95
memoryx::PredictionEntity::setProfilerMemorySnapshotRef
void setProfilerMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:116
memoryx::PredictionEntity::setSourceProfilerMemorySnapshotRef
void setSourceProfilerMemorySnapshotRef(const EntityRefBasePtr &sourceMemorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:130
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
IceUtil
Definition: Instance.h:21
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:436
memoryx::EntityRef
The EntityRef class is used to store references to Entities as values in other Entity instances.
Definition: EntityRef.h:46
memoryx::Entity::getAttributeValue
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition: Entity.cpp:327
memoryx::PredictionEntity::getPredictedProfilerMemorySnapshotRefList
EntityRefBaseList getPredictedProfilerMemorySnapshotRefList(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:154
memoryx::PredictionEntity::clone
PredictionEntityPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: PredictionEntity.cpp:101
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::PredictionEntity::~PredictionEntity
~PredictionEntity() override
Definition: PredictionEntity.cpp:72
memoryx::PredictionEntity::getTaskCount
Ice::Int getTaskCount(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:199
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:524
memoryx::PredictionEntity::getSourceProfilerMemorySnapshotRef
EntityRefBasePtr getSourceProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getSourceProfilerMemorySnapshotRef situation (memory snapshot) before the prediction
Definition: PredictionEntity.cpp:124
memoryx::PredictionEntity::PredictionEntity
PredictionEntity()
Definition: PredictionEntity.cpp:39
PredictionEntity.h
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
memoryx::PredictionEntity::setPredictedProfilerMemorySnapshotRefList
void setPredictedProfilerMemorySnapshotRefList(const EntityRefBaseList &predictedMemorySnapshotRefList, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:169
memoryx::PredictionEntity::setTaskCount
void setTaskCount(Ice::Int taskCount, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:205
memoryx::PredictionEntity::getProfilerMemorySnapshotRef
EntityRefBasePtr getProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getProfilerMemorySnapshotRef situation (memory snapshot) that actually occured (may differ from pedic...
Definition: PredictionEntity.cpp:110
memoryx::PredictionEntity::getPredictionScore
Ice::Float getPredictionScore(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:212
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:525
memoryx::PredictionEntity::setPredictionScore
void setPredictionScore(Ice::Float predictionScore, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:218
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:49
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
memoryx::PredictionEntity::getPredictedProfilerMemorySnapshotRef
EntityRefBasePtr getPredictedProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getPredictedProfilerMemorySnapshotRef situation (memory snapshot) which was predicted on the basis of...
Definition: PredictionEntity.cpp:139
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::PredictionEntity::setPredictionMethodName
void setPredictionMethodName(const std::string &predictionMethodName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:191
memoryx::Entity
Definition: Entity.h:245
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:526
memoryx::PredictionEntity::setPredictedProfilerMemorySnapshotRef
void setPredictedProfilerMemorySnapshotRef(const EntityRefBasePtr &predictedMemorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:145
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27