OacPredictionFunction.cpp
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::Core
17* @author Nils Adermann <naderman@naderman.de>
18* @date 2013
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
24
27
29
30namespace memoryx
31{
32 std::string
34 {
35 return precondition;
36 }
37
38 void
39 OacPredictionFunction::setPreconditionExpression(const std::string& precondition,
40 const Ice::Current& c)
41 {
42 this->precondition = precondition;
43 }
44
45 std::string
47 {
48 return effect;
49 }
50
51 void
52 OacPredictionFunction::setEffectExpression(const std::string& effect, const Ice::Current& c)
53 {
54 this->effect = effect;
55 }
56
57 void
58 OacPredictionFunction::serialize(const armarx::ObjectSerializerBasePtr& serializer,
59 const Ice::Current& c) const
60 {
62 armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
63
64 obj->setString("precondition", precondition);
65 obj->setString("effect", effect);
66
67 if (SECPreconditions)
68 {
69 armarx::VariantPtr preconditionsVariant = new armarx::Variant(SECPreconditions);
70 obj->setVariant("SECPreconditions", preconditionsVariant);
71 }
72
73 // else
74 // ARMARX_WARNING_S << "No SECPreconditions in OacPredictionFunction";
75 if (SECEffects)
76 {
77 armarx::VariantPtr effectsVariant = new armarx::Variant(SECEffects);
78 obj->setVariant("SECEffects", effectsVariant);
79 }
80
81 // else
82 // ARMARX_WARNING_S << "No SECEffects in OacPredictionFunction";
83 std::vector<armarx::VariantPtr> relationList;
84 relationList.resize(SECSideConstraints.size());
85
86 for (unsigned int i = 0; i < SECSideConstraints.size(); i++)
87 {
88 relationList.at(i) = new armarx::Variant(SECSideConstraints.at(i).relation1);
89 }
90
91 obj->setVariantArray("SECSideConstraintsFirstRelations", relationList);
92
93 for (unsigned int i = 0; i < SECSideConstraints.size(); i++)
94 {
95 relationList.at(i) = new armarx::Variant(SECSideConstraints.at(i).relation2);
96 }
97
98 obj->setVariantArray("SECSideConstraintsSecondRelations", relationList);
99 }
100
101 void
102 OacPredictionFunction::deserialize(const armarx::ObjectSerializerBasePtr& serializer,
103 const Ice::Current& c)
104 {
106 armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
107
108 precondition = obj->getString("precondition");
109 effect = obj->getString("effect");
110
111 if (obj->hasElement("SECPreconditions") && obj->hasElement("SECEffects"))
112 {
113 SECEffects = obj->getVariant("SECEffects")->get<SECObjectRelations>();
114 SECPreconditions = obj->getVariant("SECPreconditions")->get<SECObjectRelations>();
115 }
116 else
117 {
119 << "No SECEffects/SECPreconditions in OacPredictionFunction in oac segment";
120 }
121
122 std::vector<armarx::VariantPtr> relationList;
123 obj->getVariantArray("SECSideConstraintsFirstRelations", relationList);
124 SECSideConstraints.resize(relationList.size());
125
126 for (unsigned int i = 0; i < relationList.size(); i++)
127 {
128 SECSideConstraints.at(i).relation1 = relationList.at(i)->get<SECRelationBase>();
129 }
130
131 obj->getVariantArray("SECSideConstraintsSecondRelations", relationList);
132
133 for (unsigned int i = 0; i < relationList.size(); i++)
134 {
135 SECSideConstraints.at(i).relation2 = relationList.at(i)->get<SECRelationBase>();
136 }
137 }
138
139 armarx::VariantDataClassPtr
140 OacPredictionFunction::clone(const Ice::Current& c) const
141 {
143
144 clone->setPreconditionExpression(this->getPreconditionExpression());
145 clone->setEffectExpression(this->getEffectExpression());
146
148 {
149 clone->setSECPreconditions(
150 SECObjectRelationsBasePtr::dynamicCast(getSECPreconditions()->ice_clone()));
151 }
152
153 if (getSECEffects())
154 {
155 clone->setSECEffects(
156 SECObjectRelationsBasePtr::dynamicCast(getSECEffects()->ice_clone()));
157 }
158
159
160 SECRelationPairList pairListOrig = getSECSideConstraints();
161 SECRelationPairList pairList;
162
163 for (unsigned int i = 0; i < pairListOrig.size(); i++)
164 {
165 SECRelationPair newPair;
166
167 if (pairListOrig.at(i).relation1)
168 {
169 newPair.relation1 =
170 SECRelationBasePtr::dynamicCast(pairListOrig.at(i).relation1->ice_clone());
171 }
172
173 if (pairListOrig.at(i).relation2)
174 {
175 newPair.relation2 =
176 SECRelationBasePtr::dynamicCast(pairListOrig.at(i).relation2->ice_clone());
177 }
178
179 pairList.push_back(newPair);
180 }
181
182 clone->setSECSideConstraints(pairList);
183
184 return clone;
185 }
186
187 std::string
188 OacPredictionFunction::output(const Ice::Current& c) const
189 {
190 return "OacPredictionFunction";
191 }
192
193 int
194 OacPredictionFunction::getType(const Ice::Current& c) const
195 {
197 }
198
199 memoryx::SECObjectRelationsBasePtr
201 {
202 return SECPreconditions;
203 }
204
205 void
207 const memoryx::SECObjectRelationsBasePtr& preconditions,
208 const Ice::Current&)
209 {
210 SECPreconditions = preconditions;
211 }
212
213 memoryx::SECObjectRelationsBasePtr
215 {
216 return SECEffects;
217 }
218
219 void
220 memoryx::OacPredictionFunction::setSECEffects(const memoryx::SECObjectRelationsBasePtr& effects,
221 const Ice::Current&)
222 {
223 SECEffects = effects;
224 }
225
226 SECRelationPairList
228 {
229 return SECSideConstraints;
230 }
231
232 void
234 const SECRelationPairList& sideConstraints,
235 const Ice::Current&)
236 {
237 SECSideConstraints = sideConstraints;
238 }
239} // namespace memoryx
constexpr T c
The Variant class is described here: Variants.
Definition Variant.h:224
void setSECPreconditions(const SECObjectRelationsBasePtr &preconditions, const Ice::Current &c=Ice::emptyCurrent) override
int getType(const Ice::Current &c=Ice::emptyCurrent) const override
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
void setSECSideConstraints(const SECRelationPairList &sideConstraints, const Ice::Current &c=Ice::emptyCurrent) override
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) override
void setPreconditionExpression(const std::string &precondition, const Ice::Current &c=Ice::emptyCurrent) override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) const override
SECObjectRelationsBasePtr getSECPreconditions(const Ice::Current &c=Ice::emptyCurrent) const override
std::string getEffectExpression(const Ice::Current &c=Ice::emptyCurrent) const override
armarx::VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
SECRelationPairList getSECSideConstraints(const Ice::Current &c=Ice::emptyCurrent) const override
Ice::ObjectPtr ice_clone() const override
void setEffectExpression(const std::string &effect, const Ice::Current &c=Ice::emptyCurrent) override
std::string getPreconditionExpression(const Ice::Current &c=Ice::emptyCurrent) const override
SECObjectRelationsBasePtr getSECEffects(const Ice::Current &c=Ice::emptyCurrent) const override
void setSECEffects(const SECObjectRelationsBasePtr &effects, const Ice::Current &c=Ice::emptyCurrent) override
#define ARMARX_DEBUG_S
The logging level for output that is only interesting while debugging.
Definition Logging.h:205
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< AbstractObjectSerializer > AbstractObjectSerializerPtr
const armarx::VariantTypeId OacPredictionFunction
VirtualRobot headers.
IceInternal::Handle< OacPredictionFunction > OacPredictionFunctionPtr