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 
23 #include "OacPredictionFunction.h"
24 
26 
29 
30 namespace memoryx
31 {
32  std::string OacPredictionFunction::getPreconditionExpression(const Ice::Current& c) const
33  {
34  return precondition;
35  }
36 
37  void OacPredictionFunction::setPreconditionExpression(const std::string& precondition, const Ice::Current& c)
38  {
39  this->precondition = precondition;
40  }
41 
42  std::string OacPredictionFunction::getEffectExpression(const Ice::Current& c) const
43  {
44  return effect;
45  }
46 
47  void OacPredictionFunction::setEffectExpression(const std::string& effect, const Ice::Current& c)
48  {
49  this->effect = effect;
50  }
51 
52  void OacPredictionFunction::serialize(const armarx::ObjectSerializerBasePtr& serializer, const Ice::Current& c) const
53  {
54  armarx::AbstractObjectSerializerPtr obj = armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
55 
56  obj->setString("precondition", precondition);
57  obj->setString("effect", effect);
58 
59  if (SECPreconditions)
60  {
61  armarx::VariantPtr preconditionsVariant = new armarx::Variant(SECPreconditions);
62  obj->setVariant("SECPreconditions", preconditionsVariant);
63  }
64 
65  // else
66  // ARMARX_WARNING_S << "No SECPreconditions in OacPredictionFunction";
67  if (SECEffects)
68  {
69  armarx::VariantPtr effectsVariant = new armarx::Variant(SECEffects);
70  obj->setVariant("SECEffects", effectsVariant);
71  }
72 
73  // else
74  // ARMARX_WARNING_S << "No SECEffects in OacPredictionFunction";
75  std::vector<armarx::VariantPtr> relationList;
76  relationList.resize(SECSideConstraints.size());
77 
78  for (unsigned int i = 0; i < SECSideConstraints.size(); i++)
79  {
80  relationList.at(i) = new armarx::Variant(SECSideConstraints.at(i).relation1);
81  }
82 
83  obj->setVariantArray("SECSideConstraintsFirstRelations", relationList);
84 
85  for (unsigned int i = 0; i < SECSideConstraints.size(); i++)
86  {
87  relationList.at(i) = new armarx::Variant(SECSideConstraints.at(i).relation2);
88  }
89 
90  obj->setVariantArray("SECSideConstraintsSecondRelations", relationList);
91  }
92 
93  void OacPredictionFunction::deserialize(const armarx::ObjectSerializerBasePtr& serializer, const Ice::Current& c)
94  {
95  armarx::AbstractObjectSerializerPtr obj = armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
96 
97  precondition = obj->getString("precondition");
98  effect = obj->getString("effect");
99 
100  if (obj->hasElement("SECPreconditions") && obj->hasElement("SECEffects"))
101  {
102  SECEffects = obj->getVariant("SECEffects")->get<SECObjectRelations>();
103  SECPreconditions = obj->getVariant("SECPreconditions")->get<SECObjectRelations>();
104  }
105  else
106  {
107  ARMARX_DEBUG_S << "No SECEffects/SECPreconditions in OacPredictionFunction in oac segment";
108  }
109 
110  std::vector<armarx::VariantPtr> relationList;
111  obj->getVariantArray("SECSideConstraintsFirstRelations", relationList);
112  SECSideConstraints.resize(relationList.size());
113 
114  for (unsigned int i = 0; i < relationList.size(); i++)
115  {
116  SECSideConstraints.at(i).relation1 = relationList.at(i)->get<SECRelationBase>();
117  }
118 
119  obj->getVariantArray("SECSideConstraintsSecondRelations", relationList);
120 
121  for (unsigned int i = 0; i < relationList.size(); i++)
122  {
123  SECSideConstraints.at(i).relation2 = relationList.at(i)->get<SECRelationBase>();
124  }
125 
126 
127  }
128 
129  armarx::VariantDataClassPtr OacPredictionFunction::clone(const Ice::Current& c) const
130  {
132 
133  clone->setPreconditionExpression(this->getPreconditionExpression());
134  clone->setEffectExpression(this->getEffectExpression());
135 
136  if (getSECPreconditions())
137  {
138  clone->setSECPreconditions(SECObjectRelationsBasePtr::dynamicCast(getSECPreconditions()->ice_clone()));
139  }
140 
141  if (getSECEffects())
142  {
143  clone->setSECEffects(SECObjectRelationsBasePtr::dynamicCast(getSECEffects()->ice_clone()));
144  }
145 
146 
147  SECRelationPairList pairListOrig = getSECSideConstraints();
148  SECRelationPairList pairList;
149 
150  for (unsigned int i = 0; i < pairListOrig.size(); i++)
151  {
152  SECRelationPair newPair;
153 
154  if (pairListOrig.at(i).relation1)
155  {
156  newPair.relation1 = SECRelationBasePtr::dynamicCast(pairListOrig.at(i).relation1->ice_clone());
157  }
158 
159  if (pairListOrig.at(i).relation2)
160  {
161  newPair.relation2 = SECRelationBasePtr::dynamicCast(pairListOrig.at(i).relation2->ice_clone());
162  }
163 
164  pairList.push_back(newPair);
165  }
166 
167  clone->setSECSideConstraints(pairList);
168 
169  return clone;
170  }
171 
172  std::string OacPredictionFunction::output(const Ice::Current& c) const
173  {
174  return "OacPredictionFunction";
175  }
176 
177  int OacPredictionFunction::getType(const Ice::Current& c) const
178  {
180  }
181 
182 
183  memoryx::SECObjectRelationsBasePtr memoryx::OacPredictionFunction::getSECPreconditions(const Ice::Current&) const
184  {
185  return SECPreconditions;
186  }
187 
188  void memoryx::OacPredictionFunction::setSECPreconditions(const memoryx::SECObjectRelationsBasePtr& preconditions, const Ice::Current&)
189  {
190  SECPreconditions = preconditions;
191  }
192 
193  memoryx::SECObjectRelationsBasePtr memoryx::OacPredictionFunction::getSECEffects(const Ice::Current&) const
194  {
195  return SECEffects;
196  }
197 
198  void memoryx::OacPredictionFunction::setSECEffects(const memoryx::SECObjectRelationsBasePtr& effects, const Ice::Current&)
199  {
200  SECEffects = effects;
201  }
202 
203 
204  SECRelationPairList memoryx::OacPredictionFunction::getSECSideConstraints(const Ice::Current&) const
205  {
206  return SECSideConstraints;
207  }
208 
209  void memoryx::OacPredictionFunction::setSECSideConstraints(const SECRelationPairList& sideConstraints, const Ice::Current&)
210  {
211  SECSideConstraints = sideConstraints;
212  }
213 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
memoryx::OacPredictionFunction::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:172
memoryx::OacPredictionFunction::setSECSideConstraints
void setSECSideConstraints(const SECRelationPairList &sideConstraints, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OacPredictionFunction.cpp:209
OacPredictionFunction.h
memoryx::OacPredictionFunction::setEffectExpression
void setEffectExpression(const std::string &effect, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OacPredictionFunction.cpp:47
SECObjectRelations.h
memoryx::OacPredictionFunction::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OacPredictionFunction.cpp:93
memoryx::OacPredictionFunction::getSECPreconditions
SECObjectRelationsBasePtr getSECPreconditions(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:183
AbstractObjectSerializer.h
memoryx::OacPredictionFunction::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:52
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::OacPredictionFunction::clone
armarx::VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:129
memoryx::OacPredictionFunction::getSECSideConstraints
SECRelationPairList getSECSideConstraints(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:204
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::OacPredictionFunction::setSECEffects
void setSECEffects(const SECObjectRelationsBasePtr &effects, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OacPredictionFunction.cpp:198
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:198
memoryx::OacPredictionFunction::getPreconditionExpression
std::string getPreconditionExpression(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:32
memoryx::VariantType::OacPredictionFunction
const armarx::VariantTypeId OacPredictionFunction
Definition: OacPredictionFunction.h:31
memoryx::OacPredictionFunction::getSECEffects
SECObjectRelationsBasePtr getSECEffects(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:193
memoryx::OacPredictionFunction::getType
int getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:177
memoryx::OacPredictionFunction::setSECPreconditions
void setSECPreconditions(const SECObjectRelationsBasePtr &preconditions, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OacPredictionFunction.cpp:188
memoryx::SECObjectRelations
Definition: SECObjectRelations.h:34
memoryx::OacPredictionFunction::setPreconditionExpression
void setPreconditionExpression(const std::string &precondition, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OacPredictionFunction.cpp:37
Logging.h
memoryx::OacPredictionFunction::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: OacPredictionFunction.h:70
memoryx::OacPredictionFunction::getEffectExpression
std::string getEffectExpression(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: OacPredictionFunction.cpp:42