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 #include "../../../../core/entity/EntityRef.h"
27 
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  Entity()
41  {
43  }
44 
45  PredictionEntity::PredictionEntity(const EntityRefBasePtr& memorySnapshotRef, const EntityRefBasePtr& sourceMemorySnapshotRef, const EntityRefBasePtr& predictedMemorySnapshotRef, const EntityRefBaseList& predictedMemorySnapshotRefList, const std::string& predictionMethodName, Ice::Int taskCount, Ice::Float predictionScore) :
46  Entity()
47  {
49  setProfilerMemorySnapshotRef(memorySnapshotRef);
50  setSourceProfilerMemorySnapshotRef(sourceMemorySnapshotRef);
51  setPredictedProfilerMemorySnapshotRef(predictedMemorySnapshotRef);
52  setPredictedProfilerMemorySnapshotRefList(predictedMemorySnapshotRefList);
53  setPredictionMethodName(predictionMethodName);
54  setTaskCount(taskCount);
55  setPredictionScore(predictionScore);
56  }
57 
58 
60  IceUtil::Shared(source),
61  ::armarx::Serializable(source),
62  EntityBase(),// dont copy
63  PredictionEntityBase(source),
64  Entity(source)
65  {
66  }
67 
68 
70  {
71  }
72 
74  {
75  putAttribute(new EntityAttribute(PredictionEntity::SNAPSHOT_ATTRIBUTE));
76  putAttribute(new EntityAttribute(PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE));
77  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_ATTRIBUTE));
78  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_LIST_ATTRIBUTE));
79  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE));
80  putAttribute(new EntityAttribute(PredictionEntity::TASK_COUNT_ATTRIBUTE));
81  putAttribute(new EntityAttribute(PredictionEntity::PREDICTION_SCORE_ATTRIBUTE));
82  }
83 
84 
85  void PredictionEntity::output(std::ostream& stream) const
86  {
87  Entity::output(stream);
88  }
89 
90 
92  {
93  return this->clone();
94  }
95 
96 
97  PredictionEntityPtr PredictionEntity::clone(const Ice::Current& context) const
98  {
99  std::shared_lock entityLock(entityMutex);
100  std::scoped_lock attributesLock(attributesMutex);
101  std::scoped_lock wrappersLock(wrappersMutex);
102  return new PredictionEntity(*this);
103  }
104 
105  EntityRefBasePtr PredictionEntity::getProfilerMemorySnapshotRef(const Ice::Current&) const
106  {
107  return getAttributeValue(PredictionEntity::SNAPSHOT_ATTRIBUTE)->get<EntityRef>();
108  }
109 
110  void PredictionEntity::setProfilerMemorySnapshotRef(const EntityRefBasePtr& memorySnapshotRef, const Ice::Current&)
111  {
112  getAttribute(PredictionEntity::SNAPSHOT_ATTRIBUTE)->setValue(new armarx::Variant(memorySnapshotRef));
113  }
114 
115  EntityRefBasePtr PredictionEntity::getSourceProfilerMemorySnapshotRef(const Ice::Current&) const
116  {
117  return getAttributeValue(PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE)->get<EntityRef>();
118  }
119 
120  void PredictionEntity::setSourceProfilerMemorySnapshotRef(const EntityRefBasePtr& sourceMemorySnapshotRef, const Ice::Current&)
121  {
122  getAttribute(PredictionEntity::SOURCE_SNAPSHOT_ATTRIBUTE)->setValue(new armarx::Variant(sourceMemorySnapshotRef));
123  }
124 
125  EntityRefBasePtr PredictionEntity::getPredictedProfilerMemorySnapshotRef(const Ice::Current&) const
126  {
127  return getAttributeValue(PredictionEntity::PREDICTION_ATTRIBUTE)->get<EntityRef>();
128  }
129 
130  void PredictionEntity::setPredictedProfilerMemorySnapshotRef(const EntityRefBasePtr& predictedMemorySnapshotRef, const Ice::Current&)
131  {
132  getAttribute(PredictionEntity::PREDICTION_ATTRIBUTE)->setValue(new armarx::Variant(predictedMemorySnapshotRef));
133  }
134 
135  EntityRefBaseList PredictionEntity::getPredictedProfilerMemorySnapshotRefList(const Ice::Current&) const
136  {
137  EntityAttributeBasePtr attribute = getAttribute(PredictionEntity::PREDICTION_LIST_ATTRIBUTE);
138  EntityRefBaseList entityList;
139  for (int i = 0; i < attribute->size(); i++)
140  {
141  armarx::VariantPtr attributeValue = armarx::VariantPtr::dynamicCast(attribute->getValueAt(i));
142  entityList.push_back(attributeValue->get<EntityRef>());
143  }
144  return entityList;
145  }
146 
147  void PredictionEntity::setPredictedProfilerMemorySnapshotRefList(const EntityRefBaseList& predictedMemorySnapshotRefList, const Ice::Current&)
148  {
149  EntityAttributeBasePtr attribute = getAttribute(PredictionEntity::PREDICTION_LIST_ATTRIBUTE);
150  attribute->clear();
151  for (const EntityRefBasePtr& entityRef : predictedMemorySnapshotRefList)
152  {
153  attribute->addValue(new armarx::Variant(entityRef));
154  }
155  }
156 
157  std::string PredictionEntity::getPredictionMethodName(const Ice::Current&) const
158  {
159  return getAttribute(PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE)->getValue()->getString();
160  }
161 
162  void PredictionEntity::setPredictionMethodName(const std::string& predictionMethodName, const Ice::Current&)
163  {
164  getAttribute(PredictionEntity::PREDICTION_METHOD_NAME_ATTRIBUTE)->setValue(new armarx::Variant(predictionMethodName));
165  }
166 
167  Ice::Int PredictionEntity::getTaskCount(const Ice::Current&) const
168  {
169  return getAttributeValue(PredictionEntity::TASK_COUNT_ATTRIBUTE)->getInt();
170  }
171 
172  void PredictionEntity::setTaskCount(Ice::Int taskCount, const Ice::Current&)
173  {
174  getAttribute(PredictionEntity::TASK_COUNT_ATTRIBUTE)->setValue(new armarx::Variant(taskCount));
175  }
176 
178  {
179  return getAttributeValue(PredictionEntity::PREDICTION_SCORE_ATTRIBUTE)->getFloat();
180  }
181 
182  void PredictionEntity::setPredictionScore(Ice::Float predictionScore, const Ice::Current&)
183  {
184  getAttribute(PredictionEntity::PREDICTION_SCORE_ATTRIBUTE)->setValue(new armarx::Variant(predictionScore));
185  }
186 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
memoryx::PredictionEntity::getPredictionMethodName
std::string getPredictionMethodName(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:157
memoryx::PredictionEntity
Definition: PredictionEntity.h:35
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:327
memoryx::PredictionEntity::initializeAttributes
void initializeAttributes()
Definition: PredictionEntity.cpp:73
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:293
memoryx::PredictionEntity::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: PredictionEntity.cpp:91
memoryx::PredictionEntity::setProfilerMemorySnapshotRef
void setProfilerMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:110
memoryx::PredictionEntity::setSourceProfilerMemorySnapshotRef
void setSourceProfilerMemorySnapshotRef(const EntityRefBasePtr &sourceMemorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:120
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
IceUtil
Definition: Instance.h:21
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:409
memoryx::EntityRef
The EntityRef class is used to store references to Entities as values in other Entity instances.
Definition: EntityRef.h:45
memoryx::Entity::getAttributeValue
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition: Entity.cpp:308
memoryx::PredictionEntity::getPredictedProfilerMemorySnapshotRefList
EntityRefBaseList getPredictedProfilerMemorySnapshotRefList(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:135
memoryx::PredictionEntity::clone
PredictionEntityPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: PredictionEntity.cpp:97
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::PredictionEntity::~PredictionEntity
~PredictionEntity() override
Definition: PredictionEntity.cpp:69
memoryx::PredictionEntity::getTaskCount
Ice::Int getTaskCount(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:167
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:504
memoryx::PredictionEntity::getSourceProfilerMemorySnapshotRef
EntityRefBasePtr getSourceProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getSourceProfilerMemorySnapshotRef situation (memory snapshot) before the prediction
Definition: PredictionEntity.cpp:115
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:681
memoryx::PredictionEntity::setPredictedProfilerMemorySnapshotRefList
void setPredictedProfilerMemorySnapshotRefList(const EntityRefBaseList &predictedMemorySnapshotRefList, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:147
memoryx::PredictionEntity::setTaskCount
void setTaskCount(Ice::Int taskCount, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:172
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:105
memoryx::PredictionEntity::getPredictionScore
Ice::Float getPredictionScore(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PredictionEntity.cpp:177
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:505
memoryx::PredictionEntity::setPredictionScore
void setPredictionScore(Ice::Float predictionScore, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:182
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:48
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
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:125
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:162
memoryx::Entity
Definition: Entity.h:246
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:506
memoryx::PredictionEntity::setPredictedProfilerMemorySnapshotRef
void setPredictedProfilerMemorySnapshotRef(const EntityRefBasePtr &predictedMemorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PredictionEntity.cpp:130
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28