Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F4000252
latereasoning.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 9, 3:51 AM
Size
2 KB
Mime Type
text/x-c++
Expires
Sat, Jul 11, 3:51 AM (1 d, 5 h)
Engine
blob
Format
Raw Data
Handle
273131
Attached To
rXR Xreate
latereasoning.h
View Options
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* \file latereasoning.h
* \brief Late reasoning support
*
* Author: pgess <v.melnychenko@xreate.org>
*
* Created on June 2, 2018, 1:08 PM
*/
#ifndef LATEREASONING_H
#define LATEREASONING_H
#include "transcendlayer.h"
namespace xreate{ namespace latereasoning{
struct LateAnnotation{
LateAnnotation(){}
LateAnnotation(const Gringo::Symbol& symbolStatic);
std::list<std::pair<std::list<Gringo::Symbol>, Gringo::Symbol>> guardedContent;
std::list<SymbolPacked> guardKeys;
boost::optional<Gringo::Symbol> select(const std::list<Expression>& keys, AST* root, TranscendLayer* transcend) const;
};
struct LateAnnotationsGroup{
std::unordered_map<Gringo::Symbol, LateAnnotation> annotations;
};
typedef std::map<Gringo::Symbol, LateAnnotation> LateModel;
template<class Parent>
class LateReasoningTranscendDecorator: public Parent{
public:
const LateAnnotationsGroup& queryLate(const std::string& alias) const{
static LateAnnotationsGroup groupInvalid;
if(!__modelLate.count(alias)) return groupInvalid;
return __modelLate.at(alias);
}
protected:
virtual bool processSolution(Gringo::Model const &model) override{
const std::string& atomLateStatement = "late";
for(const Gringo::Symbol& atom: model.atoms(clingo_show_type_atoms)){
std::string atomName(atom.name().c_str());
if(atomName == atomLateStatement){
//late atom's format: (Target, (tuple of keys), (tuple of values), late-annotation)
auto atomLate = TranscendLayer::parse<Gringo::Symbol, std::list<SymbolPacked>, std::list<Gringo::Symbol>, Gringo::Symbol>(atom);
const std::string& atomAlias = std::get<3>(atomLate).name().c_str();
addLateAtom(atomAlias, std::get<0>(atomLate),
std::get<3>(atomLate), std::get<1>(atomLate),
std::get<2>(atomLate));
}
}
return Parent::processSolution(model);
}
private:
std::map<std::string, LateAnnotationsGroup> __modelLate;
void addLateAtom(const std::string& alias, const Gringo::Symbol& annId,
const Gringo::Symbol& content, const std::list<SymbolPacked>& guardKeys,
const std::list<Gringo::Symbol>& guardValues){
LateAnnotationsGroup& group = __modelLate[alias];
LateAnnotation& annotation = group.annotations[annId];
if (annotation.guardedContent.empty()){
annotation.guardKeys = guardKeys;
}
annotation.guardedContent.push_back(std::make_pair(guardValues, content));
}
};
}} // end of xreate::latereasoning
#endif /* LATEREASONING_H */
Event Timeline
Log In to Comment