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
28
29namespace 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
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
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
94 Ice::ObjectPtr
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
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
The Variant class is described here: Variants.
Definition Variant.h:224
Attribute of MemoryX entities.
The EntityRef class is used to store references to Entities as values in other Entity instances.
Definition EntityRef.h:47
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition Entity.cpp:311
Entity(const Entity &source)
Definition Entity.cpp:34
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition Entity.cpp:327
std::mutex attributesMutex
Definition Entity.h:524
std::recursive_mutex wrappersMutex
Definition Entity.h:526
void output(std::ostream &stream) const
Definition Entity.cpp:436
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition Entity.cpp:347
std::shared_mutex entityMutex
Definition Entity.h:525
Ice::Int getTaskCount(const Ice::Current &c=Ice::emptyCurrent) const override
EntityRefBasePtr getSourceProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getSourceProfilerMemorySnapshotRef situation (memory snapshot) before the prediction
EntityRefBasePtr getPredictedProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getPredictedProfilerMemorySnapshotRef situation (memory snapshot) which was predicted on the basis of...
void setPredictionMethodName(const std::string &predictionMethodName, const Ice::Current &c=Ice::emptyCurrent) override
void setTaskCount(Ice::Int taskCount, const Ice::Current &c=Ice::emptyCurrent) override
void setPredictedProfilerMemorySnapshotRef(const EntityRefBasePtr &predictedMemorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
EntityRefBasePtr getProfilerMemorySnapshotRef(const Ice::Current &c=Ice::emptyCurrent) const override
getProfilerMemorySnapshotRef situation (memory snapshot) that actually occured (may differ from pedic...
void setPredictedProfilerMemorySnapshotRefList(const EntityRefBaseList &predictedMemorySnapshotRefList, const Ice::Current &c=Ice::emptyCurrent) override
void setPredictionScore(Ice::Float predictionScore, const Ice::Current &c=Ice::emptyCurrent) override
EntityRefBaseList getPredictedProfilerMemorySnapshotRefList(const Ice::Current &c=Ice::emptyCurrent) const override
PredictionEntityPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Ice::ObjectPtr ice_clone() const override
std::string getPredictionMethodName(const Ice::Current &c=Ice::emptyCurrent) const override
void setProfilerMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
void setSourceProfilerMemorySnapshotRef(const EntityRefBasePtr &sourceMemorySnapshotRef, const Ice::Current &c=Ice::emptyCurrent) override
Ice::Float getPredictionScore(const Ice::Current &c=Ice::emptyCurrent) const override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
VirtualRobot headers.
IceInternal::Handle< PredictionEntity > PredictionEntityPtr