Relation.h
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 Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
26 #include <MemoryX/interface/core/EntityBase.h>
27 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
28 
29 namespace memoryx
30 {
31 
32  class Relation;
34 
35  /**
36  * Relation class represents a directed relation between entities.
37  * It allows to specify the uncertainty of this relation as DoB probability.
38  *
39  */
40  class Relation : public memoryx::RelationBase, public memoryx::Entity
41  {
42  public:
43  /**
44  * Constucts a new Relation
45  *
46  * @param name name of the relation (and actually its type, i.e. "isOn")
47  * @param entities the list of entity refs between which this relation holds
48  * @param sign whether the relation is known to be true or false
49  * @param prob existence probability of relation
50  */
51  Relation(const std::string& name = "",
52  const EntityRefList& entities = EntityRefList{},
53  bool sign = true,
54  float prob = 1.f);
55 
56  /**
57  * Retrieve the entities involved in this relation
58  *
59  * @return list of entity refs
60  */
61  EntityRefList getEntities(const ::Ice::Current& = Ice::emptyCurrent) const override;
62 
63  /**
64  * set the entities involved in this relation
65  *
66  * @param entities list of entity refs
67  */
68  void setEntities(const EntityRefList& entities,
69  const ::Ice::Current& = Ice::emptyCurrent) override;
70 
71  /**
72  * Retrieve whether this relation is true or false
73  *
74  * @return the sign
75  */
76  bool getSign(const ::Ice::Current& = Ice::emptyCurrent) const override;
77 
78  /**
79  * Set whether this relation is true or false
80  *
81  * @param sign the sign
82  */
83  void setSign(bool sign, const ::Ice::Current& = Ice::emptyCurrent) override;
84 
85  /**
86  * Retrieve probability that this relation actually exists
87  *
88  * @return existence probability
89  */
90  ::Ice::Float getProb(const ::Ice::Current& = Ice::emptyCurrent) const override;
91 
92  /**
93  * Set probability that this relation actually exists
94  *
95  * @prob existence probability
96  */
97  void setProb(::Ice::Float prob, const ::Ice::Current& = Ice::emptyCurrent) override;
98 
99  std::string getAttributes() const;
100 
101  void setAttributes(std::string const& attributes);
102 
103  std::string getSourceAttributes() const;
104 
105  void setSourceAttributes(std::string const& attributes);
106 
107  std::string getTargetAttributes() const;
108 
109  void setTargetAttributes(std::string const& attributes);
110 
111  // cloning
112  Ice::ObjectPtr ice_clone() const override;
113  RelationPtr clone(const Ice::Current& c = Ice::emptyCurrent) const;
114 
115  private:
116  void output(std::ostream& stream) const;
117 
118  public: // streaming operator
119  friend std::ostream&
120  operator<<(std::ostream& stream, const Relation& rhs)
121  {
122  rhs.output(stream);
123  return stream;
124  }
125 
126  friend std::ostream&
127  operator<<(std::ostream& stream, const RelationPtr& rhs)
128  {
129  rhs->output(stream);
130  return stream;
131  }
132 
133  friend std::ostream&
134  operator<<(std::ostream& stream, const RelationBasePtr& rhs)
135  {
136  stream << RelationPtr::dynamicCast(rhs);
137  return stream;
138  }
139  };
140 
141 } // namespace memoryx
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
memoryx::Relation::getSourceAttributes
std::string getSourceAttributes() const
Definition: Relation.cpp:118
memoryx::Relation::clone
RelationPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: Relation.cpp:148
memoryx::Relation::setAttributes
void setAttributes(std::string const &attributes)
Definition: Relation.cpp:112
memoryx::Relation::getProb
::Ice::Float getProb(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve probability that this relation actually exists.
Definition: Relation.cpp:94
armarx::sign
T sign(T t)
Definition: algorithm.h:214
memoryx::Relation
Relation class represents a directed relation between entities.
Definition: Relation.h:40
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::Relation::getAttributes
std::string getAttributes() const
Definition: Relation.cpp:106
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::Relation::setSourceAttributes
void setSourceAttributes(std::string const &attributes)
Definition: Relation.cpp:124
memoryx::Relation::operator<<
friend std::ostream & operator<<(std::ostream &stream, const Relation &rhs)
Definition: Relation.h:120
memoryx::Relation::Relation
Relation(const std::string &name="", const EntityRefList &entities=EntityRefList{}, bool sign=true, float prob=1.f)
Constucts a new Relation.
Definition: Relation.cpp:30
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::Relation::setEntities
void setEntities(const EntityRefList &entities, const ::Ice::Current &=Ice::emptyCurrent) override
set the entities involved in this relation
Definition: Relation.cpp:68
memoryx::Relation::getTargetAttributes
std::string getTargetAttributes() const
Definition: Relation.cpp:130
memoryx::Relation::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: Relation.cpp:142
Entity.h
memoryx::Relation::setSign
void setSign(bool sign, const ::Ice::Current &=Ice::emptyCurrent) override
Set whether this relation is true or false.
Definition: Relation.cpp:88
memoryx::Relation::getSign
bool getSign(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve whether this relation is true or false.
Definition: Relation.cpp:82
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::Relation::getEntities
EntityRefList getEntities(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve the entities involved in this relation.
Definition: Relation.cpp:53
memoryx::Entity
Definition: Entity.h:245
memoryx::Relation::setTargetAttributes
void setTargetAttributes(std::string const &attributes)
Definition: Relation.cpp:136
memoryx::Relation::setProb
void setProb(::Ice::Float prob, const ::Ice::Current &=Ice::emptyCurrent) override
Set probability that this relation actually exists.
Definition: Relation.cpp:100