49 objectInstances =
wm->getObjectInstancesSegment();
50 objectClasses = prior->getObjectClassesSegment();
51 objectRelations =
wm->getRelationsSegment();
54 memoryx::PredicateInstanceList
58 PredicateInstanceList worldState;
59 observablePredicateInstances.clear();
61 std::unique_lock lock(updaterMutex);
63 auto start = IceUtil::Time::now().toMilliSeconds();
65 ARMARX_VERBOSE << msg << ": " << (IceUtil::Time::now().toMilliSeconds() - start) << "ms"; \
66 start = IceUtil::Time::now().toMilliSeconds();
68 for (
const auto& pair : updaters)
70 PredicateInstanceList allowedPredicates;
72 ARMARX_INFO <<
"calculating predicates of '" << pair.first <<
"'";
75 for (
const PredicateInstance& predicate : pair.second->calcPredicates())
77 if (areAllowed(predicate.argValues))
79 allowedPredicates.push_back(predicate);
88 addListToList(worldState, allowedPredicates);
93 addListToList(worldState, getNonobservableRelationsAndPredicates());
101 auto it = std::find_if(updaters.cbegin(),
103 [&](
const std::pair<std::string, WorldStateUpdaterInterfacePrx>& arg)
105 for (const auto& predicateInfo : arg.second->getPredicateInfos())
107 if (predicateInfo.name == predicateName)
115 return it != updaters.end();
120 bool removePredicate,
123 memoryx::RelationBasePtr relation =
124 objectRelations->getRelationByAttrValues(
pi.name,
pi.argValues,
pi.sign);
131 objectRelations->removeEntity(relation->getId());
136 <<
", but it doesn't exist";
145 memoryx::RelationBasePtr relation =
new Relation(
pi.name,
pi.argValues,
pi.sign);
146 objectRelations->addEntity(relation);
150 ARMARX_VERBOSE <<
"Trying to add the relation " << relation->getName()
151 <<
", but it is already there";
163 this->argumentWhitelist = argumentWhitelist;
169 argumentWhitelist.clear();
173 WorldStateObserver::areAllowed(
const std::vector<EntityRefBasePtr>& entityRefs)
175 if (argumentWhitelist.empty())
180 for (
const auto& ref : entityRefs)
182 auto id = ref->entityId;
184 if (
auto instance = ObjectInstancePtr::dynamicCast(ref->getEntity()))
186 id = objectClasses->getEntityByName(instance->getMostProbableClass())->getId();
189 bool whitelisted = std::find_if(argumentWhitelist.cbegin(),
190 argumentWhitelist.cend(),
191 [&](
const EntityBasePtr& entity) {
192 return entity->getId() == id;
193 }) != argumentWhitelist.cend();
205 WorldStateObserver::addListToList(PredicateInstanceList& target,
206 const PredicateInstanceList& source)
209 for (
size_t i = 0; i <
source.size(); i++)
211 std::string entityNames;
213 for (
const auto& entity :
source.at(i).argValues)
215 entityNames += entity->entityName +
", ";
218 ARMARX_DEBUG <<
"adding to target: " <<
source.at(i).name <<
" args: " << entityNames;
223 PredicateInstanceList
224 WorldStateObserver::getNonobservableRelationsAndPredicates()
226 PredicateInstanceList returnPIList;
228 EntityIdList allEntityIDs = objectRelations->getAllEntityIds();
230 <<
" relations from the relations segment to the world state";
232 for (
const std::string&
id : allEntityIDs)
234 const RelationBasePtr relation = objectRelations->getRelationById(
id);
236 returnPIList.push_back(PredicateInstance{
237 relation->getName(), relation->getEntities(), relation->getSign()});
245 const PredicateInstanceList& predicates,
248 observablePredicateInstances.insert(
249 observablePredicateInstances.end(), predicates.begin(), predicates.end());
254 const WorldStateUpdaterInterfacePrx& updater,
257 std::unique_lock lock(updaterMutex);
259 if (updaters.find(name) != updaters.end())
261 throw armarx::LocalException()
262 <<
"Updater with name " << name <<
" already registered.";
265 updaters.insert(std::make_pair(name, updater));
268 WorldStateUpdaterInterfaceList
271 WorldStateUpdaterInterfaceList result;
273 for (
const auto& updater : updaters)
275 result.push_back(updater.second);
284 return "WorldStateObserver";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Relation class represents a directed relation between entities.
The WorldStateObserver class.
void onInitComponent() override
Pure virtual hook for the subclass.
void setPredicateArgumentWhitelist(const EntityBaseList &argumentWhitelist, const Ice::Current &) override
void resetPredicateArgumentWhitelist(const ::Ice::Current &) override
memoryx::PredicateInstanceList getWorldState(const ::Ice::Current &) override
void addObservablePredicateInstances(const PredicateInstanceList &predicates, const Ice::Current &) override
void registerAsUpdater(const std::string &name, const WorldStateUpdaterInterfacePrx &updater, const Ice::Current &) override
bool updatePredicateValue(const PredicateInstance &pi, bool removePredicate, const ::Ice::Current &) override
void onConnectComponent() override
Pure virtual hook for the subclass.
static std::string GetDefaultName()
WorldStateUpdaterInterfaceList getRegisteredUpdaters(const Ice::Current &) override
bool isObservable(const ::std::string &predicateName, const ::Ice::Current &) override
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_VERBOSE
The logging level for verbose information.
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)