id
int64
0
877k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
66
repo_stars
int64
94
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
11 values
repo_extraction_date
stringclasses
197 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
1,532,614
yudpconnect.h
lyqdy_ymodbus/ymodbus/ymod/master/yudpconnect.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YUDPCONNECT_H__ #define __YMODBUS_YUDPCONNECT_H__ #include "ymod/master/yconnect.h" #include <memory> #include <string> namespace YModbus { class UdpConnect : public IConnect { public: UdpConnect(const std::string &ip, uint16_t port); ~UdpConnect(); void SetTimeout(long to); bool Validate(void); void Purge(void); bool Send(uint8_t *buf, size_t len); int Recv(uint8_t *buf, size_t len); private: struct Impl; std::unique_ptr<Impl> impl_; }; } //namespace YModbus #endif //__YMODBUS_YUDPCONNECT_H__
665
C++
.h
27
21.481481
52
0.704545
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,615
yconnect.h
lyqdy_ymodbus/ymodbus/ymod/master/yconnect.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_MBCONNECT_H__ #define __YMODBUS_MBCONNECT_H__ #include <stdint.h> #include <stddef.h> namespace YModbus { class IConnect { public: virtual void SetTimeout(long to) = 0; virtual bool Validate(void) = 0; virtual void Purge(void) = 0; virtual bool Send(uint8_t *buf, size_t len) = 0; virtual int Recv(uint8_t *buf, size_t len) = 0; virtual ~IConnect() {} }; } //namespace YModbus #endif //__YMODBUS_MBCONNECT_H__
566
C++
.h
22
22.545455
52
0.685115
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,616
ymaster.h
lyqdy_ymodbus/ymodbus/ymod/master/ymaster.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YMASTER_H__ #define __YMODBUS_YMASTER_H__ #include "ymod/ymbdefs.h" #include "ymod/ymbstore.h" #include "ymod/ymbplayer.h" #include "ymod/ymbtask.h" #include "ymod/ymbnet.h" #include "ymod/ymbrtu.h" #include "ymod/ymbascii.h" #include "ymod/ymbutils.h" #include "ymod/master/ytcpconnect.h" #include "ymod/master/yserconnect.h" #include "ymod/master/yudpconnect.h" #include "ymblog.h" #include "ymbopts.h" #include <string> #include <vector> #include <memory> #include <queue> #include <mutex> #include <condition_variable> #include <thread> #include <map> namespace YModbus { struct MNullInterface {}; typedef Net<MNullInterface> MNet; typedef Rtu<MNullInterface> MRtu; typedef Ascii<MNullInterface> MAscii; //TProtocol: {MNet, MRtu, MAscii} //TConnect: {TcpConnect, SerConnect, UdpConnect} //TBase: {MNullInterface, IPlayer} template< typename TProtocol, typename TConnect, typename TBase = MNullInterface> class TMaster : public Task //for thread mode , public TBase { public: TMaster() = delete; TMaster(const TMaster&) = delete; TMaster &operator = (const TMaster &t) = delete; TMaster(TMaster &&t) = delete; TMaster &operator = (TMaster &&t) = delete; //TMaster api implementation TMaster(const std::string &ip, uint16_t port, eThreadMode thrm) : thrm_(thrm) , bor_(BOR_1234) , conn_(ip, port) { this->conn_.SetTimeout(this->perto_); this->conn_.Validate(); if (this->thrm_ == TASK) this->Start(); } TMaster(const std::string &com, uint32_t baudrate, char parity, uint8_t stopbits, eThreadMode thrm) : thrm_(thrm) , bor_(BOR_1234) , conn_(com, baudrate, 8, parity, stopbits) { this->conn_.SetTimeout(this->perto_); this->conn_.Validate(); if (thrm_ == TASK) this->Start(); } ~TMaster() { WaitAsynReader(); if (thrm_ == TASK) { this->Stop(); this->Wait(); } } void WaitAsynReader(void) { //wait for all of reader exit std::unique_lock<std::mutex> lock(asynMutex_); while (!asynReader_.empty()) { auto it = asynReader_.begin(); auto id = it->first; auto reader = std::move(it->second); lock.unlock(); if (reader.joinable()) reader.join(); lock.lock(); it = asynReader_.find(id); if (it != asynReader_.end()) asynReader_.erase(id); } } void SetByteOrder(eByteOrder bor) { bor_ = bor; } eByteOrder GetByteOrder(void) const { return bor_; } void SetStore(std::shared_ptr<IStore> store) { store_ = store; } std::shared_ptr<IStore> GetStore(void) const { return store_; } //reties: retry count void SetRetries(uint32_t retries) { retries_ = retries; } uint32_t GetRetries(void) const { return retries_; } //rdto: ms void SetReadTimeout(long rdto) { rdto_ = rdto; } long GetReadTimeout(void) const { return rdto_; } bool CheckConnect(void) { YMB_ASSERT(this->conn_); return this->conn_.Validate(); } //异步抓取操作,不需返回读取的数据,也不需等待执行完成 //返回的数据通过过SetStore的对象处理 void PullCoils(uint8_t sid, uint16_t reg, uint16_t num) { this->PostQuery({ sid, kFunReadCoils, reg, num }); } void PullDiscreteInputs(uint8_t sid, uint16_t reg, uint16_t num) { this->PostQuery({ sid, kFunReadDiscreteInputs, reg, num }); } void PullHoldingRegisters(uint8_t sid, uint16_t reg, uint16_t num) { this->PostQuery({ sid, kFunReadHoldingRegisters, reg, num }); } void PullInputRegisters(uint8_t sid, uint16_t reg, uint16_t num) { this->PostQuery({ sid, kFunReadInputRegisters, reg, num }); } //IPlayer================================================================ //return: >= 0, bytes of data to return; //return: < 0, errorcode of exception //buf: data value, net order int ReadCoils(uint8_t sid, uint16_t reg, uint16_t num, uint8_t *buf, size_t bufsiz) { MsgInf inf = { sid, kFunReadCoils, reg, num }; return this->Read(inf, buf, bufsiz); } int ReadDiscreteInputs(uint8_t sid, uint16_t reg, uint16_t num, uint8_t *buf, size_t bufsiz) { MsgInf inf = { sid, kFunReadDiscreteInputs, reg, num }; return this->Read(inf, buf, bufsiz); } int ReadInputRegisters(uint8_t sid, uint16_t reg, uint16_t num, uint8_t *buf, size_t bufsiz) { MsgInf inf = { sid, kFunReadInputRegisters, reg, num }; return this->Read(inf, buf, bufsiz); } int ReadHoldingRegisters(uint8_t sid, uint16_t reg, uint16_t num, uint8_t *buf, size_t bufsiz) { MsgInf inf = { sid, kFunReadHoldingRegisters, reg, num }; return this->Read(inf, buf, bufsiz); } //return: = 0, OK; //return: < 0, errorcode of exception //values: data value, net order int WriteSingleCoil(uint8_t sid, uint16_t reg, bool onoff) { uint8_t databuf[] = { static_cast<uint8_t>(onoff ? 0xff : 0x00), 0x00 }; MsgInf inf = { sid, kFunWriteSingleCoil, 0, 0, reg, 1, databuf, 2 }; return this->Write(inf); } int WriteCoils(uint8_t sid, uint16_t reg, uint16_t num, const uint8_t *bits, uint8_t wbytes) { MsgInf inf = { sid, kFunWriteMultiCoils, 0, 0, reg, num }; inf.databuf = const_cast<uint8_t*>(bits); inf.datalen = wbytes; return this->Write(inf); } int WriteSingleRegister(uint8_t sid, uint16_t reg, uint16_t value) { uint8_t databuf[] = { static_cast<uint8_t>(value >> 8), static_cast<uint8_t>(value & 0xff) }; MsgInf inf = { sid, kFunWriteSingleRegister, 0, 0, reg, 1, databuf, 2 }; return this->Write(inf); } int WriteRegisters(uint8_t sid, uint16_t reg, uint16_t num, const uint8_t *values, uint8_t wbytes) { MsgInf inf = { sid, kFunWriteMultiRegisters, 0, 0, reg, num }; inf.databuf = const_cast<uint8_t*>(values); inf.datalen = wbytes; return this->Write(inf); } int MaskWriteRegisters(uint8_t sid, uint16_t reg, uint16_t andmask, uint16_t ormask) { uint8_t databuf[] = { static_cast<uint8_t>(andmask >> 8), static_cast<uint8_t>(andmask & 0xff), static_cast<uint8_t>(ormask >> 8), static_cast<uint8_t>(ormask & 0xff) }; MsgInf inf = { sid, kFunMaskWriteRegister, 0, 0, reg, 1, databuf, 4 }; return this->Write(inf); } //return: >= 0, bytes of data to return //return: < 0, errorcode of exception //values/buf: data value, net order int WriteReadRegisters(uint8_t sid, uint16_t wreg, uint16_t wnum, const uint8_t *values, uint8_t wbytes, uint16_t rreg, uint16_t rnum, uint8_t *buf, size_t bufsiz) { MsgInf inf = { sid, kFunWriteAndReadRegisters, rreg, rnum, wreg, wnum }; inf.databuf = const_cast<uint8_t*>(values); inf.datalen = wbytes; return this->Read(inf, buf, bufsiz); } //return: >= 0, OK //return: < 0, errorcode of exception int ReportSlaveId(uint8_t maxsid, uint8_t *buf, size_t bufsiz) { YMB_DEBUG("%s%s not implementation.\n", __FILE__, __func__); return -1; } template<typename T> bool ReadValue(uint8_t sid, uint16_t startreg, T &val) { T value; //holding/input? TODO int ret = ReadHoldingRegisters(sid, startreg, sizeof(value)/2, reinterpret_cast<uint8_t*>(&value), sizeof(value)); YNetToHost(value, bor_); val = value; return ret == sizeof(T); } template<typename T> bool WriteValue(uint8_t sid, uint16_t startreg, T &val) { T value = val; YHostToNet(value, bor_); int ret = WriteReadRegisters(sid, startreg, sizeof(value) / 2, reinterpret_cast<uint8_t*>(&value), sizeof(value)); return ret == EOK; } template<typename Tw, typename Tr> bool WriteReadValue(uint8_t sid, uint16_t wreg, Tw &wval, uint16_t rreg, Tr &rval) { Tw wvalue = wval; Tr rvalue; YHostToNet(wvalue, bor_); int ret = ReadHoldingRegisters(sid, wreg, sizeof(wvalue) / 2, reinterpret_cast<uint8_t*>(&wvalue), sizeof(wvalue), rreg, sizeof(rvalue) / 2, reinterpret_cast<uint8_t*>(&rvalue), sizeof(rvalue)); YNetToHost(rvalue, bor_); rval = rvalue; return ret == sizeof(rvalue); } template<typename T, typename F> void AsyncRead(uint8_t sid, uint16_t startreg, F f) { std::unique_lock<std::mutex> lock(asynMutex_); for (auto id : exitReader_) { //erase exit reader thread auto it = asynReader_.find(id); if (it != asynReader_.end()) { auto reader = std::move(it->second); if (reader.joinable()) reader.join(); asynReader_.erase(it); } } exitReader_.clear(); asynReader_[asynId_] = std::thread( [this](uint8_t s, uint16_t r, F f, uint32_t id) { T val; if (this->ReadValue(s, r, val)) f(s, r, val); std::unique_lock<std::mutex> lock(this->asynMutex_); this->exitReader_.push_back(id); //mark exit reader }, sid, startreg, f, asynId_); asynId_++; } protected: void Run(void) override; //thread func std::string Name(void) override { return "TMaster Task"; } private: int ExecPoll(MsgInf &inf); int SendRecv(MsgInf &inf); int Read(MsgInf &inf, uint8_t *buf, size_t bufsiz); int Write(MsgInf &inf); int SendRequest(MsgInf &inf); void PostQuery(const MsgInf &inf); const uint32_t kDefRetries = 3; const long kDefRdTimeout = 500; //ms const long kPerReadTimeout = 10; //ms uint32_t retries_ = kDefRetries; long rdto_ = kDefRdTimeout; //read timeout const long perto_ = kPerReadTimeout; //ms 每次接收超时 eThreadMode thrm_; eByteOrder bor_; uint8_t msgbuf_[kMaxMsgLen]; std::shared_ptr<IStore> store_; TProtocol prot_; TConnect conn_; struct Request { Request(MsgInf &i) : err(0), inf(i) {} int err; //error, api or logical error MsgInf &inf; //modbus exception code is in inf.err std::mutex mutex; std::condition_variable cond; }; typedef std::shared_ptr<Request> RequestPtr; std::queue<RequestPtr> requests_; std::queue<MsgInf> querys_; std::mutex mutex_; std::condition_variable cond_; uint32_t asynId_ = 0; std::mutex asynMutex_; std::map<uint32_t, std::thread> asynReader_; std::vector<uint32_t> exitReader_; static thread_local int error; }; template<typename TProtocol, typename TConnect, typename TBase> thread_local int TMaster<TProtocol, TConnect, TBase>::error = 0; template<typename TProtocol, typename TConnect, typename TBase> int TMaster<TProtocol, TConnect, TBase>::Read(MsgInf &inf, uint8_t *buf, size_t bufsiz) { if (buf == nullptr) { //We don't need any response datas here. //But store will be updated after here. return this->SendRequest(inf); } //Because inf.databuf is a valid pointer of inf.pbuf //So we must guareentee inf.pbuf is valid after SendReuqest uint8_t msgbuf[kMaxMsgLen]; inf.pbuf = msgbuf; inf.bufsiz = sizeof(msgbuf); int ret = this->SendRequest(inf); if (ret == 0 && inf.datalen != 0) { //received data if (bufsiz >= inf.datalen) { YMB_ASSERT(inf.databuf != nullptr); memcpy(buf, inf.databuf, inf.datalen); ret = inf.datalen; } else { //buffer size is too small to fit data YMB_DEBUG("buffer size is too small!\n"); ret = -ENOMEM; } } return ret; } template<typename TProtocol, typename TConnect, typename TBase> int TMaster<TProtocol, TConnect, TBase>::Write(MsgInf &inf) { uint8_t sid = inf.id; uint8_t fun = inf.fun; uint16_t reg = inf.wreg; if (int ret = this->SendRequest(inf)) { YMB_DEBUG("eXecute Write failed!\n"); return ret; } if (inf.err != 0) { YMB_DEBUG("eXecute Write exception! code = %u\n", inf.err); return -EFAULT; } if (inf.id != sid || inf.fun != fun || inf.wreg != reg) { YMB_DEBUG("eXecute Write response error id/fun/reg\n"); return -EFAULT; } return EOK; } template<typename TProtocol, typename TConnect, typename TBase> int TMaster<TProtocol, TConnect, TBase>::SendRequest(MsgInf &inf) { uint32_t retry = 0; error = -EFAULT; do { if (thrm_ == TASK) { if (auto req = std::make_shared<Request>(inf)) { //发送请求 std::unique_lock<std::mutex> lockq(mutex_); requests_.push(req); cond_.notify_all(); lockq.unlock(); //等待执行 std::unique_lock<std::mutex> lockr(req->mutex); req->cond.wait(lockr); //错误信息存放在线程局部变量 error = req->err; } } else { //POLL, execute poll diretctly error = ExecPoll(inf); } } while (error != 0 && ++retry < retries_); return error; } template<typename TProtocol, typename TConnect, typename TBase> void TMaster<TProtocol, TConnect, TBase>::PostQuery(const MsgInf &inf) { if (thrm_ == TASK) { //提交查询,不需等待返回 std::unique_lock<std::mutex> lock(mutex_); querys_.push(inf); cond_.notify_all(); } else { //POLL mode, also need waiting for result, but only execute once error = ExecPoll(const_cast<MsgInf&>(inf)); } } template<typename TProtocol, typename TConnect, typename TBase> int TMaster<TProtocol, TConnect, TBase>::ExecPoll(MsgInf &inf) { bool bInnerBuf = false; if (inf.pbuf == nullptr) { inf.pbuf = msgbuf_; inf.bufsiz = sizeof(msgbuf_); bInnerBuf = true; } YMB_ASSERT(inf.bufsiz >= sizeof(msgbuf_)); int ret = SendRecv(inf); if (ret == EOK && inf.datalen != 0 && store_) { YMB_ASSERT(inf.databuf != nullptr); store_->Set(inf.id, inf.rreg, inf.databuf, inf.rnum); } if (bInnerBuf) { inf.pbuf = nullptr; inf.bufsiz = 0; inf.databuf = nullptr; inf.datalen = 0; } return ret; } template<typename TProtocol, typename TConnect, typename TBase> int TMaster<TProtocol, TConnect, TBase>::SendRecv(MsgInf &inf) { if (!conn_.Validate()) return -ENOLINK; YMB_ASSERT(inf.pbuf != nullptr); size_t msglen = prot_.MakeMasterMsg(inf.pbuf, inf.bufsiz, inf); conn_.Purge(); //清空buffer if (!conn_.Send(inf.pbuf, msglen)) return -ENETRESET; msglen = 0; for (long to = 0; to < rdto_; to += perto_) { //timeout int ret = conn_.Recv(inf.pbuf + msglen, inf.bufsiz - msglen); if (ret > 0) { //received some data msglen += ret; ret = prot_.VerifySlaveMsg(inf.pbuf, msglen); if (ret == EOK) //OK, msg arrived return prot_.ParseSlaveMsg(inf.pbuf, msglen, inf); if (ret < 0) //msg error return -EBADMSG; } if (ret < 0) //connect error return -ENETRESET; } return -EBUSY; } template<typename TProtocol, typename TConnect, typename TBase> void TMaster<TProtocol, TConnect, TBase>::Run(void) { while (this->IsRunning()) { //等待操作通知 std::unique_lock<std::mutex> lock(mutex_); cond_.wait_for(lock, std::chrono::seconds(1)); while (!requests_.empty() || !querys_.empty()) { if (!requests_.empty()) { //始终优先执行请求命令 auto req = requests_.front(); lock.unlock(); req->err = ExecPoll(req->inf); req->cond.notify_all(); lock.lock(); requests_.pop(); } else if (!querys_.empty()) { auto &inf = querys_.front(); lock.unlock(); ExecPoll(inf); lock.lock(); querys_.pop(); } else { ; //assert(false); } } } //完成所有等待的请求 std::unique_lock<std::mutex> lock(mutex_); while (!requests_.empty()) { auto req = requests_.front(); lock.unlock(); req->err = ExecPoll(req->inf); req->cond.notify_all(); lock.lock(); requests_.pop(); } } //The most useful master predefines typedef TMaster<MNet, TcpConnect> TcpMaster; typedef TMaster<MRtu, SerConnect> RtuMaster; typedef TMaster<MAscii, SerConnect> AsciiMaster; } //namespace YModbus #endif //__YMODBUS_YMASTER_H__
15,814
C++
.h
511
26.516634
75
0.663479
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,617
yserconnect.h
lyqdy_ymodbus/ymodbus/ymod/master/yserconnect.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YSERCONNECT_H__ #define __YMODBUS_YSERCONNECT_H__ #include "ymod/master/yconnect.h" #include <memory> #include <string> namespace YModbus { class SerConnect : public IConnect { public: SerConnect(const std::string &com, uint32_t baudrate, uint8_t databits, char parity, uint8_t stopbits); ~SerConnect(); void SetTimeout(long to); bool Validate(void); void Purge(void); bool Send(uint8_t *buf, size_t len); int Recv(uint8_t *buf, size_t len); private: struct Impl; std::unique_ptr<Impl> impl_; }; } //namespace YModbus #endif //__YMODBUS_YSERCONNECT_H__
723
C++
.h
28
22.607143
71
0.708767
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,618
ytcpconnect.h
lyqdy_ymodbus/ymodbus/ymod/master/ytcpconnect.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YTCPCONNECT_H__ #define __YMODBUS_YTCPCONNECT_H__ #include "ymod/master/yconnect.h" #include <memory> #include <string> namespace YModbus { class TcpConnect : public IConnect { public: TcpConnect(const std::string &ip, uint16_t port); ~TcpConnect(); void SetTimeout(long to); bool Validate(void); void Purge(void); bool Send(uint8_t *buf, size_t len); int Recv(uint8_t *buf, size_t len); private: struct Impl; std::unique_ptr<Impl> impl_; }; } //namespace YModbus #endif //__YMODBUS_YTCPCONNECT_H__
665
C++
.h
27
21.481481
52
0.704545
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,619
ytcplistener.h
lyqdy_ymodbus/ymodbus/ymod/slave/ytcplistener.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YTCPLISTENER_H__ #define __YMODBUS_YTCPLISTENER_H__ #include "ymod/slave/ylistener.h" #include <memory> namespace YModbus { class TcpListener: public IListerner { public: TcpListener(uint16_t port); ~TcpListener(); std::string GetName(void); void SetTimeout(long to); bool Listen(void); int Accept(std::vector<SessionPtr> &ses); private: struct Impl; std::unique_ptr<Impl> impl_; }; } //namespace YModbus #endif // ! __YMODBUS_YTCPLISTENER_H__
606
C++
.h
25
21.04
52
0.715564
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,620
yslave.h
lyqdy_ymodbus/ymodbus/ymod/slave/yslave.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YSLAVE_H__ #define __YMODBUS_YSLAVE_H__ #include "ymod/slave/ytcplistener.h" #include "ymod/slave/yudplistener.h" #include "ymod/slave/yserlistener.h" #include "ymod/ymbplayer.h" #include "ymod/ymbnet.h" #include "ymod/ymbrtu.h" #include "ymod/ymbascii.h" #include "ymod/ymbtask.h" #include "ymod/ymbdefs.h" #include "ymblog.h" #include "ymbopts.h" #include <string> #include <memory> namespace YModbus { struct SNullInterface {}; typedef Net<SNullInterface> SNet; typedef Rtu<SNullInterface> SRtu; typedef Ascii<SNullInterface> SAscii; //TProtocol: {SNet, SRtu, SAscii} //TListener: {TcpListener, UdpListener,SerListener} template< typename TProtocol, typename TListener, typename TPlayer = IPlayer > class TSlave : public Task { public: TSlave() = delete; TSlave(const TSlave&) = delete; TSlave(TSlave&&) = delete; TSlave& operator=(TSlave&&) = delete; TSlave(const std::string& port, uint32_t baudrate, uint8_t databits, char parity, uint8_t stopbits, eThreadMode thrm) : thrm_(thrm) , listener_(port, baudrate, databits, parity, stopbits) { this->listener_.SetTimeout(kDefListenTimeout); YMB_DEBUG("Create modbus TSlave server: %s: %s, mode: %s\n", this->listener_.GetName().c_str(), TProtocol::protname, thrm == POLL ? "POLL" : "TASK"); } TSlave(uint16_t port, eThreadMode thrm) : thrm_(thrm) , listener_(port) { this->listener_.SetTimeout(kDefListenTimeout); YMB_DEBUG("Create modbus TSlave server: %s: %s, mode: %s\n", this->listener_.GetName().c_str(), TProtocol::protname, thrm == POLL ? "POLL" : "TASK"); } ~TSlave() { } //By default, any id will receipt(id=0) void SetSlaveId(uint8_t id) { this->id_ = id; } uint8_t GetSlaveId(void) const { return this->id_; } void SetPlayer(std::shared_ptr<TPlayer> player) { this->player_ = player; } std::shared_ptr<TPlayer> GetPlayer(void) const { return this->player_; } bool Startup(void) { if (!this->listener_.Listen()) { LOG(ERROR) << "TSlave Listen failed."; return false; } if (this->thrm_ == TASK) { this->Start(); } return true; } void Shutdown(void) { if (this->thrm_ == TASK) { this->Stop(); this->Wait(); } } //for nthr = 0 to loop //to: timeout: ms //return: < 0: errorcode, = 0: no error int Run(long to) { YMB_ASSERT(this->thrm_ == POLL); listener_.SetTimeout(to); Accept(); return err_; } int GetLastError(void) const { return this->err_; } protected: virtual void Run(void) override { while (IsRunning()) { Accept(); } } virtual std::string Name(void) override { return "TSlave Task"; } private: void Accept(void); int Request(MsgInf &inf, uint8_t *rspbuf, size_t bufsiz); const long kDefListenTimeout = 1000; //ms eThreadMode thrm_; int err_ = 0; uint8_t id_ = kAnySlaveId; //TSlave id TProtocol prot_; std::shared_ptr<TPlayer> player_; TListener listener_; std::vector<SessionPtr> ses_; uint8_t rspbuf_[kMaxMsgLen]; size_t bufsiz_ = kMaxMsgLen; }; template<typename TProtocol, typename TListener, typename TPlayer> void TSlave<TProtocol, TListener, TPlayer>::Accept(void) { MsgInf inf; uint8_t *recvmsg; err_ = listener_.Accept(ses_); for (auto &session : ses_) { size_t msglen = session->Peek(&recvmsg); int need = prot_.VerifyMasterMsg(recvmsg, msglen); if (need < 0) { //bad msg YMB_HEXDUMP(recvmsg, msglen, "Bad master message! len = %u:", msglen); session->Purge(); //error, clear port data continue; } //msg has arrived if (need == 0 && prot_.ParseMasterMsg(recvmsg, msglen, inf) == EOK) { if (inf.id == id_ || id_ == kAnySlaveId) { //token or careless id size_t roff = prot_.GetSlaveDataOffset(inf.fun); int rsp = Request(inf, rspbuf_ + roff, bufsiz_ - roff); if (rsp >= 0 && inf.id != kBroadcastId) { inf.databuf = nullptr; //The Datas have filled into rspbuf. msglen = prot_.MakeSlaveMsg(rspbuf_, bufsiz_, inf); session->Purge(); //clear port before response session->Write(rspbuf_, msglen); } //exec ok } //id tocken } //request } //for ses_ } template<typename TProtocol, typename TListener, typename TPlayer> int TSlave<TProtocol, TListener, TPlayer>::Request(MsgInf &inf, uint8_t *rdbuf, size_t rdbufsiz) { int rsp; YMB_ASSERT(player_ != nullptr); YMB_DEBUG0("ExecRequest id = %u, fun = %u\n", inf.id, inf.fun); switch (inf.fun) { case kFunReadCoils: rsp = player_->ReadCoils(inf.id, inf.rreg, inf.rnum, rdbuf, rdbufsiz); break; case kFunReadDiscreteInputs: rsp = player_->ReadDiscreteInputs(inf.id, inf.rreg, inf.rnum, rdbuf, rdbufsiz); break; case kFunReadHoldingRegisters: rsp = player_->ReadHoldingRegisters(inf.id, inf.rreg, inf.rnum, rdbuf, rdbufsiz); break; case kFunReadInputRegisters: rsp = player_->ReadInputRegisters(inf.id, inf.rreg, inf.rnum, rdbuf, rdbufsiz); break; case kFunWriteAndReadRegisters: rsp = player_->WriteReadRegisters(inf.id, inf.wreg, inf.wnum, inf.databuf, inf.datalen, inf.rreg, inf.rnum, rdbuf, rdbufsiz); break; case kFunWriteMultiCoils: rsp = player_->WriteCoils(inf.id, inf.wreg, inf.wnum, inf.databuf, inf.datalen); break; case kFunWriteMultiRegisters: rsp = player_->WriteRegisters(inf.id, inf.wreg, inf.wnum, inf.databuf, inf.datalen); break; case kFunWriteSingleCoil: YMB_ASSERT(inf.databuf != nullptr && inf.datalen == 2); rsp = player_->WriteSingleCoil(inf.id, inf.wreg, inf.databuf[0] == 0xff && inf.databuf[1] == 0x00); if (rsp == 0) { rsp = 2; //ack the same data of request memmove(rdbuf, inf.databuf, rsp); } break; case kFunWriteSingleRegister: YMB_ASSERT(inf.databuf != nullptr && inf.datalen == 2); rsp = player_->WriteSingleRegister(inf.id, inf.wreg, static_cast<uint16_t>((inf.databuf[0] << 8) | inf.databuf[1])); if (rsp == 0) { rsp = 2; //ack the same data of request memmove(rdbuf, inf.databuf, rsp); } break; case kFunMaskWriteRegister: rsp = player_->MaskWriteRegisters(inf.id, inf.wreg, static_cast<uint16_t>((inf.databuf[0] << 8) | inf.databuf[1]), static_cast<uint16_t>((inf.databuf[2] << 8) | inf.databuf[3])); if (rsp == 0) { rsp = 4; //ack the same data of request memmove(rdbuf, inf.databuf, rsp); } break; default: rsp = -EINVAL; break; } inf.err = rsp >= 0 ? 0 : static_cast<uint8_t>(-rsp); inf.datalen = rsp > 0 ? static_cast<uint8_t>(rsp) : 0; inf.databuf = inf.datalen != 0 ? rdbuf : nullptr; YMB_DEBUG0("Exec Result rsp = %u\n", rsp); return rsp; } //The most useful slave predefines typedef TSlave<SNet, TcpListener> TcpSlave; typedef TSlave<SRtu, SerListener> RtuSlave; typedef TSlave<SAscii, SerListener> AsciiSlave; } //namespace YModbus #endif // ! __YMODBUS_YSLAVE_H__
7,140
C++
.h
246
25.154472
72
0.66853
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,621
yserlistener.h
lyqdy_ymodbus/ymodbus/ymod/slave/yserlistener.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YSERLISTENER_H__ #define __YMODBUS_YSERLISTENER_H__ #include "ymod/slave/ylistener.h" #include <memory> namespace YModbus { class SerListener : public IListerner { public: SerListener(const std::string& port, uint32_t baudrate, uint8_t databits, char parity, uint8_t stopbits); ~SerListener(); std::string GetName(void); void SetTimeout(long to); bool Listen(void); int Accept(std::vector<SessionPtr> &ses); private: struct Impl; std::shared_ptr<Impl> impl_; //for SessionPtr, shared_ptr is used. }; } //namespace YModbus #endif // ! __YMODBUS_YSERLISTENER_H__
735
C++
.h
29
22.034483
68
0.71345
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,622
ylistener.h
lyqdy_ymodbus/ymodbus/ymod/slave/ylistener.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YLISTENER_H__ #define __YMODBUS_YLISTENER_H__ #include "ymod/slave/ymbsession.h" #include <vector> namespace YModbus { class IListerner { public: virtual std::string GetName(void) = 0; virtual void SetTimeout(long to) = 0; virtual bool Listen(void) = 0; virtual int Accept(std::vector<SessionPtr> &ses) = 0; virtual ~IListerner() {} }; } //namespace YModbus #endif // ! __YMODBUS_YLISTENER_H__
545
C++
.h
21
22.857143
55
0.699605
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,623
ymbsession.h
lyqdy_ymodbus/ymodbus/ymod/slave/ymbsession.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YMBSESSION_H__ #define __YMODBUS_YMBSESSION_H__ #include <string> #include <memory> namespace YModbus { class ISession { public: virtual std::string PeerName(void) = 0; virtual int Write(uint8_t *msg, size_t msglen) = 0; virtual int Read(uint8_t *buf, size_t bufsiz) = 0; virtual size_t Peek(uint8_t **buf) = 0; virtual void Purge(void) = 0; virtual void Discard(size_t nbytes) = 0; virtual ~ISession() {} }; typedef std::shared_ptr<ISession> SessionPtr; } //namespace YModbus #endif // ! __YMODBUS_YMBSESSION_H__
674
C++
.h
24
24.875
53
0.694268
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,624
ymbslave.h
lyqdy_ymodbus/ymodbus/ymod/slave/ymbslave.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YMBSLAVE_H__ #define __YMODBUS_YMBSLAVE_H__ #include "ymod/ymbdefs.h" #include "ymod/ymbplayer.h" #include "ymod/ymbmonitor.h" #include <string> #include <memory> namespace YModbus { class Slave final { public: Slave() = delete; Slave(const Slave&) = default; Slave(Slave&&) = default; Slave& operator=(Slave&&) = default; //prot: YMB_RTU/YMB_ASCII //nthr: thread count, = 0: need call Run Slave(const std::string& port, uint32_t baudrate, char parity, uint8_t stopbits, eProtocol prot, eThreadMode thrm); //prot: //YMB_TCP/YMB_UDP //YMB_TCP_RTU/YMB_TCP_ASCII //YMB_UDP_RTU/YMB_UDP_ASCII //nthr: thread count, = 0: need call Run Slave(uint16_t port, eProtocol prot, eThreadMode thrm); ~Slave(); //By default, any id will receipt(id=0) void SetSlaveId(uint8_t id); uint8_t GetSlaveId(void) const; void Slave::SetMonitor(std::shared_ptr<IMonitor> monitor); std::shared_ptr<IMonitor> Slave::GetMonitor(void) const; void SetPlayer(std::shared_ptr<IPlayer> player); std::shared_ptr<IPlayer> GetPlayer(void) const; bool Startup(void); void Shutdown(void); //for nthr = 0 to loop //to: timeout: ms //return: < 0: errorcode, = 0: no error int Run(long to); int GetLastError(void) const; private: struct Impl; std::shared_ptr<Impl> impl_; }; } //namespace YModbus #endif // ! __YMODBUS_YMBSLAVE_H__
1,530
C++
.h
55
24.4
60
0.69541
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,625
yudplistener.h
lyqdy_ymodbus/ymodbus/ymod/slave/yudplistener.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YUDPLISTENER_H__ #define __YMODBUS_YUDPLISTENER_H__ #include "ymod/slave/ylistener.h" #include <memory> namespace YModbus { class UdpListener : public IListerner { public: UdpListener(uint16_t port); ~UdpListener(); std::string GetName(void); void SetTimeout(long to); bool Listen(void); int Accept(std::vector<SessionPtr> &ses); private: struct Impl; std::shared_ptr<Impl> impl_; }; } //namespace YModbus #endif // ! __YMODBUS_YUDPLISTENER_H__
607
C++
.h
25
21.08
52
0.714286
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,626
ymbopts.h
lyqdy_ymodbus/ymodbus/include/ymbopts.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YMBOPTS_H__ #define __YMODBUS_YMBOPTS_H__ #include <cstdint> #include <cstddef> namespace YModbus { const size_t kMaxTcpSessionNum = 256; const uint16_t kMaxSerailPort = 2; const size_t kMaxMsgLen = (512 + 7); } //namespace YModbus #endif // ! __YMODBUS_YMBOPTS_H__
404
C++
.h
15
23.866667
52
0.702413
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,627
ymblog.h
lyqdy_ymodbus/ymodbus/include/ymblog.h
/** * ymodbus * Copyright © 2019-2019 liuyongqing<lyqdy1@163.com> * v1.0.1 2019.05.04 */ #ifndef __YMODBUS_YMBLOG_H__ #define __YMODBUS_YMBLOG_H__ #include <iostream> #include <stdio.h> #include <string> #include <fstream> #ifndef WIN32 # include <sys/types.h> # include <sys/stat.h> # include <sys/time.h> # define GLOG_NO_ABBREVIATED_SEVERITIES # define LOG(x) std::cout << #x << ":" #else # include <direct.h> # include <time.h> # include <winsock2.h> # define LOG(x) std::cout << #x << ":" inline void gettimeofday(struct timeval *tv, void *tz) { SYSTEMTIME t; GetLocalTime(&t); tv->tv_sec = t.wSecond; tv->tv_usec = t.wMilliseconds * 1000; (void)tz; } #endif #ifndef ASSERT # include <assert.h> # define ASSERT(x) assert(x) #endif #define YMB_ASSERT(x) do { (void)(x); ASSERT(x); } while (0) #define YMB_VERIFY(x) do { if (!(x)) ASSERT(0&&(#x)); } while (0) #define YMB_ASSERT_MSG(x, fmt, ...) do { \ (void)(x); \ fprintf(stderr, fmt, ##__VA_ARGS__); \ ASSERT(x); \ } while (0) #ifndef NDEBUG #define YMB_DEBUG(fmt, ...) do { \ struct timeval __tv; \ gettimeofday(&__tv, NULL); \ fprintf(stdout, "%ld.%06ld: ", \ __tv.tv_sec, __tv.tv_usec); \ fprintf(stdout, fmt, ##__VA_ARGS__);\ } while (0) #define YMB_ERROR(fmt, ...) do { \ struct timeval __tv; \ gettimeofday(&__tv, NULL); \ fprintf(stderr, "%ld.%06ld: ", \ __tv.tv_sec,__tv.tv_usec); \ fprintf(stderr, fmt, ##__VA_ARGS__);\ } while (0) #define YMB_HEXDUMP(_xbuf, _xlen, fmt, ...) \ do { \ uint8_t *__xbuf = (uint8_t *)(_xbuf); \ struct timeval __tv; \ gettimeofday(&__tv, NULL); \ fprintf(stdout, "%ld.%06ld: ", \ __tv.tv_sec, __tv.tv_usec); \ fprintf(stdout, fmt, ##__VA_ARGS__); \ for (size_t _i = 0; _i < (size_t)(_xlen); ++_i) { \ fprintf(stdout, "%02X ", __xbuf[_i]); \ if (((_i + 1) % 128) == 0) \ fprintf(stdout, "\n"); \ } \ fprintf(stdout, "\n"); \ } while (0) #else #define YMB_DEBUG(fmt, ...) #define YMB_ERROR(fmt, ...) #define YMB_HEXDUMP(_xbuf, _xlen, fmt, ...) #endif //NDEBUG #define YMB_DEBUG0(fmt, ...) #define YMB_ERROR0(fmt, ...) #define YMB_HEXDUMP0(_xbuf, _xlen, fmt, ...) (void)(_xbuf) #endif // __YMODBUS_YMBLOG_H__
2,645
C++
.h
80
29.025
70
0.498221
lyqdy/ymodbus
34
39
2
GPL-3.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,628
main.cpp
doganulus_reelay/apps/ryjson1/main.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/json.hpp" #include "reelay/monitors.hpp" #include <cstring> // memset() #include <fstream> #include <iostream> #include <memory> #include <stdexcept> #include <string> #include <vector> #include "simdjson.h" #include "simdjson_adapter.hpp" #include "third_party/taywee/args.hpp" #include <glob.h> // glob(), globfree() namespace rycli { std::vector<std::string> expand_glob(const std::string& glob_str) { // glob struct resides on the stack glob_t glob_result; memset(&glob_result, 0, sizeof(glob_result)); // do the glob operation int return_value = glob(glob_str.c_str(), GLOB_TILDE, nullptr, &glob_result); // glob() error handling // Info: http://man7.org/linux/man-pages/man3/glob.3.html if(return_value == GLOB_ABORTED) { globfree(&glob_result); std::stringstream ss; ss << "glob() encountered a read error" << std::endl; throw std::runtime_error(ss.str()); } if(return_value == GLOB_NOSPACE) { globfree(&glob_result); std::stringstream ss; ss << "glob() running out of memory" << std::endl; throw std::runtime_error(ss.str()); } // collect all the filenames into a std::list<std::string> std::vector<std::string> filenames; for(size_t i = 0; i < glob_result.gl_pathc; ++i) { filenames.emplace_back(glob_result.gl_pathv[i]); } // cleanup globfree(&glob_result); // done return filenames; } template<typename X, typename Y> void discrete_timed_processing( reelay::monitor<X, Y>& monitor, const std::string& filename) { int stdout_line_count = 0; simdjson::dom::parser reader; std::ofstream output_file(filename + ".ryl"); std::cout << "Processing " + filename << std::endl; std::cout << "---" << std::endl; for(simdjson::dom::element doc : reader.load_many(filename)) { reelay::json result = monitor.update(doc); if(not result.empty()) { if(stdout_line_count < 5) { std::cout << result << std::endl; stdout_line_count++; } else if(stdout_line_count == 5) { std::cout << "..." << std::endl; stdout_line_count++; } output_file << result << std::endl; } } if(stdout_line_count < 5) { std::cout << "---" << std::endl; } std::cout << "Full output written to " + filename + ".ryl" << std::endl; } template<typename X, typename Y> void dense_timed_processing( reelay::monitor<X, Y>& monitor, const std::string& filename) { int stdout_line_count = 0; simdjson::dom::parser reader; std::ofstream output_file(filename + ".ryl"); std::cout << "Processing " + filename << std::endl; std::cout << "---" << std::endl; for(simdjson::dom::element doc : reader.load_many(filename)) { reelay::json result = monitor.update(doc); if(not result.empty()) { for(const auto& item : result) { if(stdout_line_count < 5) { std::cout << item << std::endl; stdout_line_count++; } else if(stdout_line_count == 5) { std::cout << "..." << std::endl; stdout_line_count++; } output_file << item << std::endl; } } } if(stdout_line_count < 5) { std::cout << "---" << std::endl; } std::cout << "Full output written to " + filename + ".ryl" << std::endl; } } // namespace rycli int main(int argc, char** argv) { using namespace reelay; // defaults // argparser args::ArgumentParser parser( "Reelay Command Line Interface", "Further information: https://github.com/doganulus/reelay"); args::Positional<std::string> spec( parser, "SPEC", "Specification in Rye Format", args::Options::Required); args::PositionalList<std::string> paths( parser, "FILE", "Log files to be checked against SPEC", args::Options::Required); args::Group gsetting(parser, "Monitor Settings"); args::Group gmodel( gsetting, "Time model:", args::Group::Validators::Xor, args::Options::Global); args::Flag fdense( gmodel, "fv", "Use dense time model (default)", {'v', "dense"}); args::Flag fdiscrete( gmodel, "fx", "Use discrete time model", {'x', "discrete"}); args::Group gdtype( gsetting, "Time datatype:", args::Group::Validators::Xor, args::Options::Global); args::Flag fint( gdtype, "fi", "Use int64 as time type (default)", {'i', "itime"}); args::Flag ffloat( gdtype, "ff", "with -v, use float64 as time type", {'f', "ftime"}); args::Group gsemantics( gsetting, "Value model:", args::Group::Validators::Xor, args::Options::Global); args::Flag fboolean( gsemantics, "fb", "Use boolean semantics", {'b', "boolean"}); args::Flag frobustness( gsemantics, "fr", "Use robustness semantics", {'r', "robustness"}); args::Group ginterp( gsetting, "Interpolation:", args::Group::Validators::Xor, args::Options::Global); args::Flag fconstant( ginterp, "fk", "with -v, use piecewise constant interpolation (default)", {'k', "pwc"}); args::Flag flinear( ginterp, "fl", "with -vf, use piecewise linear interpolation", {'l', "pwl"}); args::Flag fno_condense( gsetting, "fno-condense", "with -x, disable dense output", {'z', "no-condense"}); args::Group gioctrl(parser, "Input/Output Control"); args::Group gformat( gioctrl, "Input File Format:", args::Group::Validators::Xor, args::Options::Global); args::ValueFlag<std::string> t_name( gioctrl, "STRING", "Use STRING as the name of time field", {"tname"}, "time"); args::ValueFlag<std::string> y_name( gioctrl, "STRING", "use STRING as the name of output field", {"yname"}, "value"); args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); args::CompletionFlag completion(parser, {"complete"}); try { parser.ParseCLI(argc, argv); } catch(const args::Completion& e) { std::cout << e.what(); return 0; } catch(const args::Help&) { std::cout << parser; return 0; } catch(const args::ParseError& e) { std::cerr << e.what() << std::endl; std::cerr << parser; return 1; } // Choices bool use_discrete = args::get(fdiscrete); bool use_dense = args::get(fdense); bool use_boolean = args::get(fboolean); bool use_robustness = args::get(frobustness); bool use_integer = args::get(fint); bool use_floating = args::get(ffloat); bool use_constant = args::get(fconstant); bool use_linear = args::get(flinear); // Apply defaults if(not use_discrete and not use_dense) { use_discrete = true; } if(not use_boolean and not use_robustness) { use_boolean = true; } if(not use_integer and not use_floating) { use_integer = true; } if(not use_constant and not use_linear) { use_constant = true; } // Glob Expansion auto filenames = std::vector<std::string>(); for(const auto& p : args::get(paths)) { std::vector<std::string> expanded = rycli::expand_glob(p); filenames.insert(filenames.end(), expanded.begin(), expanded.end()); } using input_t = simdjson::dom::element; using output_t = reelay::json; auto manager = std::make_shared<reelay::binding_manager>(); auto monitor = reelay::monitor<input_t, output_t>(); if(use_discrete and use_boolean) { // -x -xb -xbz auto opts = reelay::discrete_timed<int64_t>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)) .with_condensing(not args::get(fno_condense)) .with_data_manager(manager); monitor = reelay::make_monitor(args::get(spec), opts); } else if(use_discrete and use_robustness) { // -xr -xrz auto opts = reelay::discrete_timed<int64_t>::robustness< double>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)) .with_condensing(not args::get(fno_condense)); monitor = reelay::make_monitor(args::get(spec), opts); } else if(use_dense and use_boolean and use_integer) { // -vbi auto opts = reelay::dense_timed<int64_t>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)) .with_data_manager(manager); monitor = reelay::make_monitor(args::get(spec), opts); } else if( use_dense and use_boolean and use_floating and use_constant) { // -vbf // -vbfk auto opts = reelay::dense_timed<double>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)) .with_interpolation(reelay::piecewise::constant) .with_data_manager(manager); monitor = reelay::make_monitor(args::get(spec), opts); } else if(use_dense and use_boolean and use_floating and use_linear) { // -vbfl auto opts = reelay::dense_timed<double>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)) .with_interpolation(reelay::piecewise::linear) .with_data_manager(manager); monitor = reelay::make_monitor(args::get(spec), opts); } else if(use_dense and use_robustness and use_integer) { // -vri auto opts = reelay::dense_timed<int64_t>::robustness< double>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)); monitor = reelay::make_monitor(args::get(spec), opts); } else if(use_dense and use_robustness and use_floating) { // -vrf auto opts = reelay::dense_timed<double>::robustness< double>::monitor<input_t, output_t>::options() .with_time_field_name(args::get(t_name)) .with_value_field_name(args::get(y_name)); monitor = reelay::make_monitor(args::get(spec), opts); } else { throw std::invalid_argument("Unsupported flag combination"); } if(use_discrete) { for(const auto& filename : filenames) { rycli::discrete_timed_processing(monitor, filename); } } else { for(const auto& filename : filenames) { rycli::dense_timed_processing(monitor, filename); } } return 0; }
10,721
C++
.cpp
316
28.870253
80
0.632062
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,629
discrete_tutorial_main.cpp
doganulus_reelay/apps/tutorial/door_open_warning/cpp/discrete_tutorial_main.cpp
#include <string> #include <vector> #include <fstream> #include <iostream> #include "reelay/monitors.hpp" int main(int argc, const char *argv[]) { using time_type = int64_t; using input_type = reelay::json; using output_type = reelay::json; if (argc != 2) { std::cout << "Error: Program requires a filename argument." << std::endl; return -1; } std::ifstream input_file(argv[1]); // Monitor constructions auto options = reelay::discrete_timed<time_t>::monitor< input_type, output_type>::options().disable_condensing(); auto my_monitor_1 = reelay::make_monitor( "(historically[0:5]{door_open} and not {dow_suppressed}) -> " "{door_open_warning}", options); auto my_monitor_2 = reelay::make_monitor( "{door_open_warning} -> historically[0:5]{door_open}", options); auto my_monitor_3 = reelay::make_monitor( "{door_open_warning} -> not {dow_suppressed}", options); auto my_monitor_4 = reelay::make_monitor( "{door_open_warning} -> not(pre({door_open} since {door_open_warning}))", options); // Execution for (std::string line; std::getline(input_file, line);) { reelay::json message = reelay::json::parse(line); auto r1 = my_monitor_1.update(message); auto r2 = my_monitor_2.update(message); auto r3 = my_monitor_3.update(message); auto r4 = my_monitor_4.update(message); if (r1["value"] == false) { std::cout << "Error at " << my_monitor_1.now() << " : False negative detected (SYS-REQ-01 Violation)" << std::endl; } if (r2["value"] == false) { std::cout << "Error at " << my_monitor_2.now() << " : False positive detected (SYS-REQ-01 Violation)" << std::endl; } if (r3["value"] == false) { std::cout << "Error at " << my_monitor_3.now() << " : False positive detected (SYS-REQ-01 Violation)" << std::endl; } if (r4["value"] == false) { std::cout << "Error at " << my_monitor_4.now() << " : False positive detected (SYS-REQ-02 Violation)" << std::endl; } } std::cout << "Exited successfully." << std::endl; return 0; }
2,217
C++
.cpp
58
32.051724
79
0.594783
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,630
dense_tutorial_main.cpp
doganulus_reelay/apps/tutorial/door_open_warning/cpp/dense_tutorial_main.cpp
#include <string> #include <vector> #include <fstream> #include <iostream> #include "reelay/monitors.hpp" int main(int argc, const char *argv[]) { using time_type = double; using input_type = reelay::json; using output_type = reelay::json; if (argc != 2) { std::cout << "Error: Program requires a filename argument." << std::endl; return -1; } std::ifstream input_file(argv[1]); // Monitor constructions auto options = reelay::dense_timed<time_t>::monitor< input_type, output_type>::options(); auto my_monitor_1 = reelay::make_monitor( "(historically[0:5]{door_open} and not {dow_suppressed}) -> " "{door_open_warning}", options); auto my_monitor_2 = reelay::make_monitor( "{door_open_warning} -> historically[0:5]{door_open}", options); auto my_monitor_3 = reelay::make_monitor( "{door_open_warning} -> not {dow_suppressed}", options); auto my_monitor_4 = reelay::make_monitor( "{door_open_warning} -> not(once[1:1]({door_open} since {door_open_warning}))", options); auto ar1 = reelay::json::array(); auto ar2 = reelay::json::array(); auto ar3 = reelay::json::array(); auto ar4 = reelay::json::array(); // Execution for (std::string line; std::getline(input_file, line);) { reelay::json message = reelay::json::parse(line); auto r1 = my_monitor_1.update(message); auto r2 = my_monitor_2.update(message); auto r3 = my_monitor_3.update(message); auto r4 = my_monitor_4.update(message); if(not r1.empty()){ ar1.insert(ar1.end(), r1.begin(), r1.end()); } if (not r2.empty()) { ar2.insert(ar2.end(), r2.begin(), r2.end()); } if (not r3.empty()) { ar3.insert(ar3.end(), r3.begin(), r3.end()); } if (not r4.empty()) { ar4.insert(ar4.end(), r4.begin(), r4.end()); } } std::cout << "SYS-REQ-1 Behavior:" << std::endl; std::cout << ar1 << std::endl; std::cout << "SYS-REQ-2 Behavior:" << std::endl; std::cout << ar2 << std::endl; std::cout << "SYS-REQ-3 Behavior:" << std::endl; std::cout << ar3 << std::endl; std::cout << "SYS-REQ-4 Behavior:" << std::endl; std::cout << ar4 << std::endl; std::cout << "Exited successfully." << std::endl; return 0; }
2,245
C++
.cpp
62
31.967742
85
0.620499
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,631
discrete_timed_robustness.test.cpp
doganulus_reelay/tests/src/discrete_timed_robustness.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/json.hpp" #include "reelay/networks/discrete_timed_robustness_network.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <vector> using time_type = int64_t; using input_type = reelay::json; using value_type = int64_t; TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Robustness Atoms", "[discrete_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Proposition") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({3, 4, 4, 5}); CHECK(result == expected); } SECTION("AtomicTrue") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", true}}); sequence.push_back(input_type{{"x1", true}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", false}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1: true}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({top, top, top, bot}); CHECK(result == expected); } SECTION("AtomicFalse") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", true}}); sequence.push_back(input_type{{"x1", true}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", false}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1: false}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({bot, bot, bot, top}); CHECK(result == expected); } SECTION("AtomicString") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", "a"}}); sequence.push_back(input_type{{"x1", "b"}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", "c"}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1: b}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({bot, top, top, bot}); CHECK(result == expected); } SECTION("AtomicNumber") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 1}}); sequence.push_back(input_type{{"x1", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 4}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1: 2}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({bot, top, top, bot}); CHECK(result == expected); } SECTION("AtomicAny") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", "1"}}); sequence.push_back(input_type{{"x2", "2"}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", "4"}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1: *}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({top, bot, bot, top}); CHECK(result == expected); } SECTION("GreaterThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 > 4}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({-1, 0, 0, 1}); CHECK(result == expected); } SECTION("Record Double Comparison") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 2}}); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.push_back(input_type{{"x1", 5}}); sequence.push_back(input_type{{"x1", 6}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 > 3, x1 < 5}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({-1, 0, 1, 0, -1}); CHECK(result == expected); } SECTION("GreaterEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 >= 4}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({-1, 0, 0, 1}); CHECK(result == expected); } SECTION("LessThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 < 4}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({1, 0, 0, -1}); CHECK(result == expected); } SECTION("LessEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 <= 4}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({1, 0, 0, -1}); CHECK(result == expected); } SECTION("Equal") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 == 4}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({-1, 0, 0, -1}); CHECK(result == expected); } SECTION("NotEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{x1 != 4}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({1, 0, 0, 1}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) " Discrete Timed Robustness Boolean Operations", "[discrete_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Disjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 0}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 0}, {"p2", 3}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 4}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} or {p2>0}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({0, 1, 3, 5}); CHECK(result == expected); } SECTION("Conjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 0}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 0}, {"p2", 3}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 4}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} and {p2>0}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({0, 0, 0, 4}); CHECK(result == expected); } SECTION("Implication") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 0}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 0}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 1}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} -> {p2>0}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({0, 0, 1, 1}); CHECK(result == expected); } SECTION("Negation") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", -10}}); sequence.push_back(input_type{{"p1", 10}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("not{p1>0}"); auto result = std::vector<value_type>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<value_type>({10, -10}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Robustness Temporal Operations (Untimed)", "[discrete_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Previous") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 8}, {"p2", -1}}); sequence.push_back(input_type{{"p1", 7}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 6}, {"p2", 0}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("pre{p1>0}"); auto net2 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("pre{p2>0}"); auto result1 = std::vector<value_type>(); auto result2 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); net2.update(s); result1.push_back(net1.output()); result2.push_back(net2.output()); } auto expected1 = std::vector<value_type>({bot, 8, 7, 5}); auto expected2 = std::vector<value_type>({bot, -1, 1, 0}); CHECK(result1 == expected1); CHECK(result2 == expected2); } SECTION("Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 8}, {"p2", -1}}); sequence.push_back(input_type{{"p1", 7}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 6}, {"p2", 0}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("historically{p1>0}"); auto net2 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("historically{p2>0}"); auto result1 = std::vector<value_type>(); auto result2 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); net2.update(s); result1.push_back(net1.output()); result2.push_back(net2.output()); } auto expected1 = std::vector<value_type>({8, 7, 5, 5}); auto expected2 = std::vector<value_type>({-1, -1, -1, -1}); CHECK(result1 == expected1); CHECK(result2 == expected2); } SECTION("Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 0}, {"p2", 4}}); sequence.push_back(input_type{{"p1", 6}, {"p2", 5}}); sequence.push_back(input_type{{"p1", 7}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 8}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("once{p1>0}"); auto net2 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("once{p2>0}"); auto result1 = std::vector<value_type>(); auto result2 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); net2.update(s); result1.push_back(net1.output()); result2.push_back(net2.output()); } auto expected1 = std::vector<value_type>({0, 6, 7, 7}); auto expected2 = std::vector<value_type>({4, 5, 5, 8}); CHECK(result1 == expected1); CHECK(result2 == expected2); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", -3}, {"p2", 0}}); sequence.push_back(input_type{{"p1", -1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", -1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 6}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 5}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} since {p2>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 5, 1}); CHECK(result1 == expected1); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}, {"p2", -120}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", -3}, {"p2", -100}}); sequence.push_back(input_type{{"p1", -1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", -1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", -4}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 5}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} since[:100] {p2>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>( {-120, 1, 1, 1, -3, -3, -3, 1, -1, -1, -4, -4, 5, 1, 1, 1}); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Robustness Temporal Operations (Bounded)", "[discrete_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 5}}); sequence.push_back(input_type{{"p1", 1}}); sequence.push_back(input_type{{"p1", 2}}); sequence.push_back(input_type{{"p1", -1}}); sequence.push_back(input_type{{"p1", -2}}); sequence.push_back(input_type{{"p1", 14}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 2}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("once[2:4]{p1>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({bot, bot, 3, 4, 5, 5, 5, 2, 2, 14, 14}); CHECK(result1 == expected1); } SECTION("Timed Once Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 5}}); sequence.push_back(input_type{{"p1", 1}}); sequence.push_back(input_type{{"p1", 2}}); sequence.push_back(input_type{{"p1", -1}}); sequence.push_back(input_type{{"p1", -2}}); sequence.push_back(input_type{{"p1", 14}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 2}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("once[:3]{p1>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({3, 4, 5, 5, 5, 5, 2, 14, 14, 14, 14}); CHECK(result1 == expected1); } SECTION("Timed Once Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 5}}); sequence.push_back(input_type{{"p1", 1}}); sequence.push_back(input_type{{"p1", 2}}); sequence.push_back(input_type{{"p1", -1}}); sequence.push_back(input_type{{"p1", -2}}); sequence.push_back(input_type{{"p1", 14}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 2}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("once[2:]{p1>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({bot, bot, 3, 4, 5, 5, 5, 5, 5, 14, 14}); CHECK(result1 == expected1); } SECTION("Timed Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 5}}); sequence.push_back(input_type{{"p1", 1}}); sequence.push_back(input_type{{"p1", 2}}); sequence.push_back(input_type{{"p1", -1}}); sequence.push_back(input_type{{"p1", -2}}); sequence.push_back(input_type{{"p1", 14}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 2}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("historically[2:4]{p1>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({top, top, 3, 3, 3, 1, 1, -1, -2, -2, -2}); CHECK(result1 == expected1); } SECTION("Timed Always Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 5}}); sequence.push_back(input_type{{"p1", 1}}); sequence.push_back(input_type{{"p1", 2}}); sequence.push_back(input_type{{"p1", -1}}); sequence.push_back(input_type{{"p1", -2}}); sequence.push_back(input_type{{"p1", 14}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 2}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("historically[:3]{p1>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({3, 3, 3, 1, 1, -1, -2, -2, -2, -2, 2}); CHECK(result1 == expected1); } SECTION("Timed Always Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 5}}); sequence.push_back(input_type{{"p1", 1}}); sequence.push_back(input_type{{"p1", 2}}); sequence.push_back(input_type{{"p1", -1}}); sequence.push_back(input_type{{"p1", -2}}); sequence.push_back(input_type{{"p1", 14}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 4}}); sequence.push_back(input_type{{"p1", 2}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("historically[2:]{p1>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({top, top, 3, 3, 3, 1, 1, -1, -2, -2, -2}); CHECK(result1 == expected1); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}, {"p2", -120}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", -3}, {"p2", -100}}); sequence.push_back(input_type{{"p1", -1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", -1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", -4}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 5}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); sequence.push_back(input_type{{"p1", 1}, {"p2", -100}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} since[2:4] {p2>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>( {bot, bot, -120, 1, -3, -3, -100, -100, -100, -1, -4, -4, -100, -100, 1, 1}); CHECK(result1 == expected1); } SECTION("Timed Since Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", -3}, {"p2", 0}}); sequence.push_back(input_type{{"p1", -1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", -1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 6}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 5}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} since[:4] {p2>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 5, 1}); CHECK(result1 == expected1); } SECTION("Timed Since Zero 2") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", 3}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", 5}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", -3}, {"p2", 0}}); sequence.push_back(input_type{{"p1", -1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", -1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 6}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 5}}); sequence.push_back(input_type{{"p1", 1}, {"p2", 0}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} since[:100] {p2>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 5, 1}); CHECK(result1 == expected1); } SECTION("Timed Since Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", -3}, {"p2", -6}}); sequence.push_back(input_type{{"p1", -4}, {"p2", 1}}); sequence.push_back(input_type{{"p1", -5}, {"p2", -8}}); sequence.push_back(input_type{{"p1", 15}, {"p2", 3}}); sequence.push_back(input_type{{"p1", -3}, {"p2", 22}}); auto net1 = reelay::discrete_timed_robustness_network< time_type, value_type, input_type>::make("{p1>0} since[2:] {p2>0}"); auto result1 = std::vector<value_type>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<value_type>({bot, bot, -6, -5, -5}); CHECK(result1 == expected1); } }
30,507
C++
.cpp
800
32.73125
74
0.601574
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,632
discrete_timed.test.cpp
doganulus_reelay/tests/src/discrete_timed.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/json.hpp" #include "reelay/networks/discrete_timed_network.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <string> #include <vector> using time_type = int64_t; using input_type = reelay::json; TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Atoms", "[discrete_timed]") { SECTION("AtomicProposition") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", false}}); sequence.push_back(input_type{{"x1", false}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, false, false, true}); CHECK(result == expected); } SECTION("AtomicTrue") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", false}}); sequence.push_back(input_type{{"x1", false}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1:true}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, false, false, true}); CHECK(result == expected); } SECTION("AtomicFalse") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", false}}); sequence.push_back(input_type{{"x1", false}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1:false}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, true, true, false}); CHECK(result == expected); } SECTION("GreaterThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1 > 4}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, false, false, true}); CHECK(result == expected); } SECTION("GreaterEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1 >= 4}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, true, true, true}); CHECK(result == expected); } SECTION("LessThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1 < 4}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false, false, false}); CHECK(result == expected); } SECTION("LessEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1 <= 4}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, true, true, false}); CHECK(result == expected); } SECTION("AtomicNotEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 5}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1 != 4}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false, false, true}); CHECK(result == expected); } SECTION("AtomicSimpleString") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", "a"}}); sequence.push_back(input_type{{"x1", "b"}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", "c"}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1: a}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false, false, false}); CHECK(result == expected); } SECTION("AtomicNumber") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 1}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x1", 3}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x1: 3}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false, false, true}); CHECK(result == expected); } SECTION("AtomicAny") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back({{"x1", "3"}, {"x2", "a"}}); sequence.push_back({{"x1", "1"}}); sequence.push_back({{"x1", "3"}, {"x2", "c"}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("{x2: *}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false, true}); CHECK(result == expected); } SECTION("Record Double Comparison") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x1", 2}}); sequence.push_back(input_type{{"x1", 3}}); sequence.push_back(input_type{{"x1", 4}}); sequence.push_back(input_type{{"x1", 5}}); sequence.push_back(input_type{{"x1", 6}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{x1 > 3, x1 < 5}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, false, true, false, false}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Boolean Operations", "[discrete_timed]") { SECTION("Disjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} or {p2}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, true, true, true}); CHECK(result == expected); } SECTION("Conjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} and {p2}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({false, false, false, true}); CHECK(result == expected); } SECTION("Implication") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} -> {p2}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false, true, true}); CHECK(result == expected); } SECTION("Negation") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}}); sequence.push_back(input_type{{"p1", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("not {p1}"); auto result = std::vector<bool>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto expected = std::vector<bool>({true, false}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Temporal Operations (Untimed)", "[discrete_timed]") { SECTION("Previous") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", true}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("pre{p1}"); auto net2 = reelay::discrete_timed_network<time_type, input_type>::make("pre{p2}"); auto result1 = std::vector<bool>(); auto result2 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); net2.update(s); result1.push_back(net1.output()); result2.push_back(net2.output()); } auto expected1 = std::vector<bool>({false, true, false, true}); auto expected2 = std::vector<bool>({false, false, true, false}); CHECK(result1 == expected1); CHECK(result2 == expected2); } SECTION("Past Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "historically{p1}"); auto net2 = reelay::discrete_timed_network<time_type, input_type>::make( "historically{p2}"); auto result1 = std::vector<bool>(); auto result2 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); net2.update(s); result1.push_back(net1.output()); result2.push_back(net2.output()); } auto expected1 = std::vector<bool>({true, true, true, true}); auto expected2 = std::vector<bool>({true, true, false, false}); CHECK(result1 == expected1); CHECK(result2 == expected2); } SECTION("Past Sometime") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make("once{p1}"); auto net2 = reelay::discrete_timed_network<time_type, input_type>::make("once{p2}"); auto result1 = std::vector<bool>(); auto result2 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); net2.update(s); result1.push_back(net1.output()); result2.push_back(net2.output()); } auto expected1 = std::vector<bool>({false, false, true, true}); auto expected2 = std::vector<bool>({false, false, false, false}); CHECK(result1 == expected1); CHECK(result2 == expected2); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} since {p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, true, true, true, true, false, false, true, true, true, false, false, true, true}); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Timed Temporal Operations (Bounded)", "[discrete_timed]") { SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "once[2:4]{p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, false, false, true, true, true, false, false, false, true, true}); CHECK(result1 == expected1); } SECTION("Timed Once Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "once[:4]{p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, true, true, true, true, true, false, true, true, true, true}); CHECK(result1 == expected1); } SECTION("Timed Once Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "once[2:]{p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, false, false, true, true, true, true, true, true, true, true}); CHECK(result1 == expected1); } SECTION("Timed Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "historically[2:4]{p1}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {true, true, false, false, false, true, true, true, true, true, true}); CHECK(result1 == expected1); } SECTION("Timed Always Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "historically[:4]{p1}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, false, false, false, false, true, true, true, true, true, false}); CHECK(result1 == expected1); } SECTION("Timed Always Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "historically[2:]{p1}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {true, true, true, true, true, true, true, true, true, true, false}); CHECK(result1 == expected1); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} since[2:4] {p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, false, false, true, true, true, false, false, false, true, false}); CHECK(result1 == expected1); } SECTION("Timed Since Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} since[:4] {p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, true, true, true, true, true, false, true, true, true, false}); CHECK(result1 == expected1); } SECTION("Timed Since Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"p1", false}, {"p2", false}}); auto net1 = reelay::discrete_timed_network<time_type, input_type>::make( "{p1} since[2:] {p2}"); auto result1 = std::vector<bool>(); for(const auto& s : sequence) { net1.update(s); result1.push_back(net1.output()); } auto expected1 = std::vector<bool>( {false, false, false, true, true, true, true, true, true, true, false}); CHECK(result1 == expected1); } }
26,942
C++
.cpp
653
35.961715
80
0.616086
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,633
dense_timed_robustness_0.test.cpp
doganulus_reelay/tests/src/dense_timed_robustness_0.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/intervals.hpp" #include "reelay/json.hpp" #include "reelay/networks/dense_timed_robustness_0_network.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <vector> using input_type = reelay::json; using value_type = int64_t; using time_type = int64_t; using interval = reelay::interval<time_type>; using robustness_map = reelay::robustness_interval_map<time_type, value_type>; TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Robustness Atoms", "[dense_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Proposition") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}}); sequence.push_back(input_type{{"time", 10}, {"x", 15}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), 11)); expected1.add(std::make_pair(interval::left_open(10, 20), 15)); expected1.add(std::make_pair(interval::left_open(20, 42), 13)); CHECK(result1 == expected1); } SECTION("GreaterEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 1}, {"x1", 5}}); sequence.push_back(input_type{{"time", 6}, {"x1", 4}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x1 >= 4}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), -1)); expected1.add(std::make_pair(interval::left_open(1, 6), 1)); expected1.add(std::make_pair(interval::left_open(6, 9), 0)); CHECK(result1 == expected1); } SECTION("GreaterThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 1}, {"x1", 5}}); sequence.push_back(input_type{{"time", 6}, {"x1", 4}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x1 > 4}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), -1)); expected1.add(std::make_pair(interval::left_open(1, 6), 1)); expected1.add(std::make_pair(interval::left_open(6, 9), 0)); CHECK(result1 == expected1); } SECTION("LessEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 1}, {"x1", 5}}); sequence.push_back(input_type{{"time", 6}, {"x1", 4}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x1 <= 4}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), 1)); expected1.add(std::make_pair(interval::left_open(1, 6), -1)); expected1.add(std::make_pair(interval::left_open(6, 9), 0)); CHECK(result1 == expected1); } SECTION("LessThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 1}, {"x1", 5}}); sequence.push_back(input_type{{"time", 6}, {"x1", 4}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x1 <= 4}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), 1)); expected1.add(std::make_pair(interval::left_open(1, 6), -1)); expected1.add(std::make_pair(interval::left_open(6, 9), 0)); CHECK(result1 == expected1); } SECTION("InBetween_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 1}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3}, {"x1", 6}}); sequence.push_back(input_type{{"time", 5}, {"x1", 4}}); sequence.push_back(input_type{{"time", 7}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x1 > 3, x1 < 5}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 3), 0)); expected1.add(std::make_pair(interval::left_open(0, 5), -1)); expected1.add(std::make_pair(interval::left_open(5, 7), 1)); CHECK(result1 == expected1); } SECTION("AtomicTrue") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", true}}); sequence.push_back(input_type{{"time", 10}, {"x", false}}); sequence.push_back(input_type{{"time", 20}, {"x", true}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x: true}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), top)); expected1.add(std::make_pair(interval::left_open(10, 20), bot)); expected1.add(std::make_pair(interval::left_open(20, 42), top)); CHECK(result1 == expected1); } SECTION("AtomicFalse") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", true}}); sequence.push_back(input_type{{"time", 10}, {"x", false}}); sequence.push_back(input_type{{"time", 20}, {"x", true}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x: false}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), bot)); expected1.add(std::make_pair(interval::left_open(10, 20), top)); expected1.add(std::make_pair(interval::left_open(20, 42), bot)); CHECK(result1 == expected1); } SECTION("AtomicString") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", "hello"}}); sequence.push_back(input_type{{"time", 10}, {"x", "world"}}); sequence.push_back(input_type{{"time", 20}, {"x", "alice"}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x: alice}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 20), bot)); expected1.add(std::make_pair(interval::left_open(20, 42), top)); CHECK(result1 == expected1); } SECTION("AtomicNumber") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 555}}); sequence.push_back(input_type{{"time", 10}, {"x", 666}}); sequence.push_back(input_type{{"time", 20}, {"x", 777}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x: 777}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 20), bot)); expected1.add(std::make_pair(interval::left_open(20, 42), top)); CHECK(result1 == expected1); } SECTION("AtomicAny") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 555}}); sequence.push_back(input_type{{"time", 10}}); sequence.push_back(input_type{{"time", 20}, {"x", 777}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x: *}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), top)); expected1.add(std::make_pair(interval::left_open(10, 20), bot)); expected1.add(std::make_pair(interval::left_open(20, 42), top)); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Robustness Boolean Operations", "[dense_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Negation") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}}); sequence.push_back(input_type{{"time", 10}, {"x", 15}}); sequence.push_back(input_type{{"time", 20}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "not{x >= 12}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), 1)); expected1.add(std::make_pair(interval::left_open(10, 20), -3)); CHECK(result1 == expected1); } SECTION("Disjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}, {"y", 10}}); sequence.push_back(input_type{{"time", 10}, {"x", 15}, {"y", 12}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}, {"y", 17}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x} or {y}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), 11)); expected1.add(std::make_pair(interval::left_open(10, 20), 15)); expected1.add(std::make_pair(interval::left_open(20, 42), 17)); CHECK(result1 == expected1); } SECTION("Conjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}, {"y", 10}}); sequence.push_back(input_type{{"time", 10}, {"x", 15}, {"y", 12}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}, {"y", 17}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x} and {y}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), 10)); expected1.add(std::make_pair(interval::left_open(10, 20), 12)); expected1.add(std::make_pair(interval::left_open(20, 42), 13)); CHECK(result1 == expected1); } SECTION("Implication") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", -11}, {"y", 10}}); sequence.push_back(input_type{{"time", 10}, {"x", -15}, {"y", 12}}); sequence.push_back(input_type{{"time", 20}, {"x", -13}, {"y", 17}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x} implies {y}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), 11)); expected1.add(std::make_pair(interval::left_open(10, 20), 15)); expected1.add(std::make_pair(interval::left_open(20, 42), 17)); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Robustness Temporal Operations (Untimed)", "[dense_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Past Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", -11}, {"y", 10}}); sequence.push_back(input_type{{"time", 10}, {"x", -15}, {"y", 9}}); sequence.push_back(input_type{{"time", 20}, {"x", -13}, {"y", 7}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "historically{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), -11)); expected1.add(std::make_pair(interval::left_open(10, 20), -15)); expected1.add(std::make_pair(interval::left_open(20, 42), -15)); CHECK(result1 == expected1); } SECTION("Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}, {"y", 10}}); sequence.push_back(input_type{{"time", 10}, {"x", 15}, {"y", 9}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}, {"y", 7}}); sequence.push_back(input_type{{"time", 42}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "once{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 10), 11)); expected1.add(std::make_pair(interval::left_open(10, 20), 15)); expected1.add(std::make_pair(interval::left_open(20, 42), 15)); CHECK(result1 == expected1); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 3}, {"y", 0}}); sequence.push_back(input_type{{"time", 1}, {"x", 4}, {"y", 1}}); sequence.push_back(input_type{{"time", 2}, {"x", 5}, {"y", 0}}); sequence.push_back(input_type{{"time", 3}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 4}, {"x", -3}, {"y", 0}}); sequence.push_back(input_type{{"time", 5}, {"x", -1}, {"y", 0}}); sequence.push_back(input_type{{"time", 6}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 7}, {"x", 4}, {"y", 1}}); sequence.push_back(input_type{{"time", 8}, {"x", -1}, {"y", 0}}); sequence.push_back(input_type{{"time", 9}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 10}, {"x", 6}, {"y", 0}}); sequence.push_back(input_type{{"time", 11}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 12}, {"x", 1}, {"y", 5}}); sequence.push_back(input_type{{"time", 13}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 14}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x} since {y}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); // std::cout << net1.output() << std::endl; result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), 0)); expected1.add(std::make_pair(interval::left_open(1, 2), 1)); expected1.add(std::make_pair(interval::left_open(2, 3), 1)); expected1.add(std::make_pair(interval::left_open(3, 4), 1)); expected1.add(std::make_pair(interval::left_open(4, 5), 0)); expected1.add(std::make_pair(interval::left_open(5, 6), 0)); expected1.add(std::make_pair(interval::left_open(6, 7), 0)); expected1.add(std::make_pair(interval::left_open(7, 8), 1)); expected1.add(std::make_pair(interval::left_open(8, 9), 0)); expected1.add(std::make_pair(interval::left_open(9, 10), 0)); expected1.add(std::make_pair(interval::left_open(10, 11), 0)); expected1.add(std::make_pair(interval::left_open(11, 12), 0)); expected1.add(std::make_pair(interval::left_open(12, 13), 5)); expected1.add(std::make_pair(interval::left_open(13, 14), 1)); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Robustness Temporal Operations (Bounded)", "[dense_timed_robustness]") { value_type top = reelay::infinity<value_type>::value(); value_type bot = -reelay::infinity<value_type>::value(); SECTION("Timed Past Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}}); sequence.push_back(input_type{{"time", 10}, {"x", 9}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}}); sequence.push_back(input_type{{"time", 30}, {"x", 17}}); sequence.push_back(input_type{{"time", 60}, {"x", 15}}); sequence.push_back(input_type{{"time", 70}, {"x", 4}}); sequence.push_back(input_type{{"time", 90}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "historically[12:24]{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 12), top)); expected1.add(std::make_pair(interval::left_open(12, 22), 11)); expected1.add(std::make_pair(interval::left_open(20, 44), 9)); expected1.add(std::make_pair(interval::left_open(44, 54), 13)); expected1.add(std::make_pair(interval::left_open(54, 72), 17)); expected1.add(std::make_pair(interval::left_open(72, 82), 15)); expected1.add(std::make_pair(interval::left_open(82, 90), 4)); CHECK(result1 == expected1); } SECTION("Timed Past Always Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}}); sequence.push_back(input_type{{"time", 10}, {"x", 9}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}}); sequence.push_back(input_type{{"time", 30}, {"x", 17}}); sequence.push_back(input_type{{"time", 60}, {"x", 15}}); sequence.push_back(input_type{{"time", 70}, {"x", 4}}); sequence.push_back(input_type{{"time", 90}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "historically[15:]{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 15), top)); expected1.add(std::make_pair(interval::left_open(15, 25), 11)); expected1.add(std::make_pair(interval::left_open(25, 85), 9)); expected1.add(std::make_pair(interval::left_open(85, 90), 4)); CHECK(result1 == expected1); } SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}}); sequence.push_back(input_type{{"time", 10}, {"x", 9}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}}); sequence.push_back(input_type{{"time", 30}, {"x", 17}}); sequence.push_back(input_type{{"time", 60}, {"x", 15}}); sequence.push_back(input_type{{"time", 70}, {"x", 4}}); sequence.push_back(input_type{{"time", 90}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "once[12:24]{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 12), bot)); expected1.add(std::make_pair(interval::left_open(12, 32), 11)); expected1.add(std::make_pair(interval::left_open(32, 42), 13)); expected1.add(std::make_pair(interval::left_open(42, 84), 17)); expected1.add(std::make_pair(interval::left_open(84, 90), 15)); CHECK(result1 == expected1); } SECTION("Timed Once Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 11}}); sequence.push_back(input_type{{"time", 10}, {"x", 9}}); sequence.push_back(input_type{{"time", 20}, {"x", 13}}); sequence.push_back(input_type{{"time", 30}, {"x", 17}}); sequence.push_back(input_type{{"time", 60}, {"x", 15}}); sequence.push_back(input_type{{"time", 70}, {"x", 4}}); sequence.push_back(input_type{{"time", 90}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "once[15:]{x}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 15), bot)); expected1.add(std::make_pair(interval::left_open(15, 35), 11)); expected1.add(std::make_pair(interval::left_open(35, 45), 13)); expected1.add(std::make_pair(interval::left_open(45, 90), 17)); CHECK(result1 == expected1); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", 3}, {"y", 0}}); sequence.push_back(input_type{{"time", 1}, {"x", 4}, {"y", 1}}); sequence.push_back(input_type{{"time", 2}, {"x", 5}, {"y", 0}}); sequence.push_back(input_type{{"time", 3}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 4}, {"x", -3}, {"y", 0}}); sequence.push_back(input_type{{"time", 5}, {"x", -1}, {"y", 0}}); sequence.push_back(input_type{{"time", 6}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 7}, {"x", 4}, {"y", 1}}); sequence.push_back(input_type{{"time", 8}, {"x", -1}, {"y", 0}}); sequence.push_back(input_type{{"time", 9}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 10}, {"x", 6}, {"y", 0}}); sequence.push_back(input_type{{"time", 11}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 12}, {"x", 1}, {"y", 5}}); sequence.push_back(input_type{{"time", 13}, {"x", 1}, {"y", 0}}); sequence.push_back(input_type{{"time", 14}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x>0} since[:100] {y>0}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); // std::cout << net1.output() << std::endl; result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), 0)); expected1.add(std::make_pair(interval::left_open(1, 2), 1)); expected1.add(std::make_pair(interval::left_open(2, 3), 1)); expected1.add(std::make_pair(interval::left_open(3, 4), 1)); expected1.add(std::make_pair(interval::left_open(4, 5), 0)); expected1.add(std::make_pair(interval::left_open(5, 6), 0)); expected1.add(std::make_pair(interval::left_open(6, 7), 0)); expected1.add(std::make_pair(interval::left_open(7, 8), 1)); expected1.add(std::make_pair(interval::left_open(8, 9), 0)); expected1.add(std::make_pair(interval::left_open(9, 10), 0)); expected1.add(std::make_pair(interval::left_open(10, 11), 0)); expected1.add(std::make_pair(interval::left_open(11, 12), 0)); expected1.add(std::make_pair(interval::left_open(12, 13), 5)); expected1.add(std::make_pair(interval::left_open(13, 14), 1)); CHECK(result1 == expected1); } SECTION("Timed Since 2") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", -3}, {"y", -6}}); sequence.push_back(input_type{{"time", 10}, {"x", -4}, {"y", 1}}); sequence.push_back(input_type{{"time", 20}, {"x", -5}, {"y", -8}}); sequence.push_back(input_type{{"time", 30}, {"x", 15}, {"y", 3}}); sequence.push_back(input_type{{"time", 40}, {"x", -3}, {"y", 22}}); sequence.push_back(input_type{{"time", 50}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x} since[5:15] {y}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 5), bot)); expected1.add(std::make_pair(interval::left_open(5, 15), -6)); expected1.add(std::make_pair(interval::left_open(15, 20), 1)); expected1.add(std::make_pair(interval::left_open(20, 35), -5)); expected1.add(std::make_pair(interval::left_open(35, 45), 3)); expected1.add(std::make_pair(interval::left_open(45, 50), 22)); CHECK(result1 == expected1); } SECTION("Timed Since Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x", -3}, {"y", -6}}); sequence.push_back(input_type{{"time", 1}, {"x", -4}, {"y", 1}}); sequence.push_back(input_type{{"time", 2}, {"x", -5}, {"y", -8}}); sequence.push_back(input_type{{"time", 3}, {"x", 15}, {"y", 3}}); sequence.push_back(input_type{{"time", 4}, {"x", -3}, {"y", 22}}); sequence.push_back(input_type{{"time", 5}}); auto net1 = reelay:: dense_timed_robustness_0_network<time_type, value_type, input_type>::make( "{x} since[2:] {y}"); auto result1 = robustness_map(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = robustness_map(); expected1.add(std::make_pair(interval::left_open(0, 1), bot)); expected1.add(std::make_pair(interval::left_open(1, 2), bot)); expected1.add(std::make_pair(interval::left_open(2, 3), -6)); expected1.add(std::make_pair(interval::left_open(3, 4), -5)); expected1.add(std::make_pair(interval::left_open(4, 5), -5)); CHECK(result1 == expected1); } }
28,918
C++
.cpp
643
39.748056
80
0.616847
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,634
monitors.test.cpp
doganulus_reelay/tests/src/monitors.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/monitors.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <vector> TEST_CASE("Options") { SECTION("Dense Timed Const Boolean") { auto opts = reelay::basic_options() .with_interpolation(reelay::piecewise::linear) .with_time_field_name("timestamp") .with_value_field_name("verdict"); CHECK(opts.get_interpolation() == reelay::piecewise::linear); CHECK(opts.get_time_field_name() == "timestamp"); CHECK(opts.get_value_field_name() == "verdict"); } } TEST_CASE("Dense Timed") // NOLINT(readability-function-cognitive-complexity) { using time_type = double; using value_type = double; using input_t = reelay::json; using output_t = reelay::json; SECTION("Dense Timed Const Boolean") { std::vector<input_t> sequence = std::vector<input_t>(); sequence.push_back(input_t{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"time", 10}, {"p1", false}, {"p2", true}}); sequence.push_back(input_t{{"time", 20}, {"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_t{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 175}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 201}, {"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"time", 248}, {"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"time", 287}, {"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"time", 444}}); auto opts = reelay::dense_timed<time_type>::monitor<input_t>::options() .with_interpolation(reelay::piecewise::constant) .with_time_field_name("timestamp") .with_value_field_name("verdict"); auto monitor = reelay::make_monitor("{p1} since[:24] {p2}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); result.insert(result.end(), r.begin(), r.end()); } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"timestamp", 0.0}, {"verdict", false}}); expected.push_back(output_t{{"timestamp", 115.0}, {"verdict", true}}); expected.push_back(output_t{{"timestamp", 180.0}, {"verdict", false}}); CHECK(result == expected); auto timestamp = output_t{{"timestamp", 444.0}}; CHECK(monitor.now() == timestamp); } SECTION("Dense Timed Linear Boolean") { std::vector<input_t> sequence = std::vector<input_t>(); sequence.push_back(input_t{{"time", 0}, {"x1", -2}}); sequence.push_back(input_t{{"time", 1}, {"x1", -2}}); sequence.push_back(input_t{{"time", 2}, {"x1", -1}}); sequence.push_back(input_t{{"time", 4}, {"x1", 1}}); sequence.push_back(input_t{{"time", 5}, {"x1", 2}}); sequence.push_back(input_t{{"time", 6}, {"x1", 2}}); sequence.push_back(input_t{{"time", 7}, {"x1", 1}}); sequence.push_back(input_t{{"time", 9}, {"x1", -1}}); sequence.push_back(input_t{{"time", 10}, {"x1", -2}}); sequence.push_back(input_t{{"time", 11}, {"x1", 0}}); sequence.push_back(input_t{{"time", 12}, {"x1", 0}}); sequence.push_back(input_t{{"time", 13}, {"x1", 2}}); sequence.push_back(input_t{{"time", 14}, {"x1", 0}}); sequence.push_back(input_t{{"time", 15}, {"x1", -2}}); auto opts = reelay::dense_timed<time_type>::monitor<input_t>::options() .with_interpolation(reelay::piecewise::linear); auto monitor = reelay::make_monitor("{x1 < 0}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); result.insert(result.end(), r.begin(), r.end()); } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"time", 0.0}, {"value", true}}); expected.push_back(output_t{{"time", 3.0}, {"value", false}}); expected.push_back(output_t{{"time", 8.0}, {"value", true}}); expected.push_back(output_t{{"time", 11.0}, {"value", false}}); expected.push_back(output_t{{"time", 14.0}, {"value", true}}); CHECK(result == expected); auto timestamp = output_t{{"time", 15.0}}; CHECK(monitor.now() == timestamp); } SECTION("Dense Timed Const Data") { std::vector<input_t> sequence = std::vector<input_t>(); sequence.push_back( input_t{{"time", 0}, {"state", "arrived"}, {"arg1", "a"}}); sequence.push_back(input_t{{"time", 1}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_t{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_t{{"time", 6}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_t{{"time", 7}, {"state", "close"}}); sequence.push_back(input_t{{"time", 9}}); auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::dense_timed<time_type>::monitor<input_t>::options() .with_data_manager(manager); auto monitor = reelay::make_monitor( "exists[arg].({state: open, arg1: *arg} since {state: arrived, arg1: " "*arg})", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); result.insert(result.end(), r.begin(), r.end()); } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"time", 0.0}, {"value", true}}); expected.push_back(output_t{{"time", 7.0}, {"value", false}}); CHECK(result == expected); auto timestamp = output_t{{"time", 9.0}}; CHECK(monitor.now() == timestamp); } SECTION("Dense Timed Const Robustness") { std::vector<input_t> sequence = std::vector<input_t>(); sequence.push_back(input_t{{"time", 0}, {"x", 11}}); sequence.push_back(input_t{{"time", 10}, {"x", 9}}); sequence.push_back(input_t{{"time", 20}, {"x", 13}}); sequence.push_back(input_t{{"time", 30}, {"x", 17}}); sequence.push_back(input_t{{"time", 60}, {"x", 15}}); sequence.push_back(input_t{{"time", 70}, {"x", 4}}); sequence.push_back(input_t{{"time", 90}}); auto opts = reelay::dense_timed<time_type>::robustness<value_type>::monitor< input_t>::options(); auto monitor = reelay::make_monitor("once[12:24]{x}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); result.insert(result.end(), r.begin(), r.end()); } auto bot = -reelay::infinity<value_type>::value(); auto expected = std::vector<output_t>(); expected.push_back(output_t{{"time", 0.0}, {"value", bot}}); expected.push_back(output_t{{"time", 12.0}, {"value", 11.0}}); expected.push_back(output_t{{"time", 32.0}, {"value", 13.0}}); expected.push_back(output_t{{"time", 42.0}, {"value", 17.0}}); expected.push_back(output_t{{"time", 84.0}, {"value", 15.0}}); CHECK(result == expected); auto timestamp = output_t{{"time", 90.0}}; CHECK(monitor.now() == timestamp); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed") { using time_type = intmax_t; using value_type = double; using input_t = reelay::json; using output_t = reelay::json; SECTION("Discrete Timed Condensing") { auto sequence = std::vector<input_t>(); sequence.push_back(input_t{{"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", true}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", true}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", false}, {"p2", false}}); auto opts = reelay::discrete_timed<time_type>::monitor<input_t>::options() .enable_condensing(); auto monitor = reelay::make_monitor("{p1} since[2:4] {p2}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); if(not r.empty()) { result.push_back(r); } } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"time", 0}, {"value", false}}); expected.push_back(output_t{{"time", 3}, {"value", true}}); expected.push_back(output_t{{"time", 6}, {"value", false}}); expected.push_back(output_t{{"time", 9}, {"value", true}}); expected.push_back(output_t{{"time", 10}, {"value", false}}); CHECK(result == expected); auto timestamp = output_t{{"time", 10}}; CHECK(monitor.now() == timestamp); } SECTION("Discrete Timed NonCondensing") { auto sequence = std::vector<input_t>(); sequence.push_back(input_t{{"p1", false}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", true}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", true}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", true}, {"p2", false}}); sequence.push_back(input_t{{"p1", false}, {"p2", false}}); auto opts = reelay::discrete_timed<time_type>::monitor<input_t>::options() .disable_condensing(); auto monitor = reelay::make_monitor("{p1} since[2:4] {p2}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); if(not r.empty()) { result.push_back(r); } } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", true}}); expected.push_back(output_t{{"value", true}}); expected.push_back(output_t{{"value", true}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", true}}); expected.push_back(output_t{{"value", false}}); CHECK(result == expected); auto timestamp = output_t{{"time", 10}}; CHECK(monitor.now() == timestamp); } SECTION("Discrete Timed Data Condensing") { auto sequence = std::vector<input_t>(); sequence.push_back(input_t{"access", "alice", "wonderland"}); sequence.push_back(input_t{"access", "bob", "white_rabbit"}); sequence.push_back(input_t{"access", "alice", "feed_your_head"}); sequence.push_back(input_t{"logout", "charlotte"}); sequence.push_back(input_t{"meet", "bob", "humpty", "dumpty"}); auto opts = reelay::discrete_timed<time_type>::monitor<input_t>::options() .with_data_manager(); auto monitor = reelay::make_monitor( "exists[file].({$0: access, $1: alice, $2: *file})", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); if(not r.empty()) { result.push_back(r); } } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"time", 0}, {"value", true}}); expected.push_back(output_t{{"time", 1}, {"value", false}}); expected.push_back(output_t{{"time", 2}, {"value", true}}); expected.push_back(output_t{{"time", 3}, {"value", false}}); CHECK(result == expected); auto timestamp = output_t{{"time", 4}}; CHECK(monitor.now() == timestamp); } SECTION("Discrete Timed Data NonCondensing") { auto sequence = std::vector<input_t>(); sequence.push_back(input_t{"access", "alice", "wonderland"}); sequence.push_back(input_t{"access", "bob", "white_rabbit"}); sequence.push_back(input_t{"access", "alice", "feed_your_head"}); sequence.push_back(input_t{"logout", "charlotte"}); sequence.push_back(input_t{"meet", "bob", "humpty", "dumpty"}); auto opts = reelay::discrete_timed<time_type>::monitor<input_t>::options() .with_data_manager() .disable_condensing(); auto monitor = reelay::make_monitor( "exists[file].({$0: access, $1: alice, $2: *file})", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); if(not r.empty()) { result.push_back(r); } } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"value", true}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", true}}); expected.push_back(output_t{{"value", false}}); expected.push_back(output_t{{"value", false}}); CHECK(result == expected); auto timestamp = output_t{{"time", 4}}; CHECK(monitor.now() == timestamp); } SECTION("Discrete Timed Robustness Condensing") { std::vector<input_t> sequence = std::vector<input_t>(); sequence.push_back(input_t{{"p1", 3}}); sequence.push_back(input_t{{"p1", 4}}); sequence.push_back(input_t{{"p1", 5}}); sequence.push_back(input_t{{"p1", 1}}); sequence.push_back(input_t{{"p1", 2}}); sequence.push_back(input_t{{"p1", -1}}); sequence.push_back(input_t{{"p1", -2}}); sequence.push_back(input_t{{"p1", 14}}); sequence.push_back(input_t{{"p1", 4}}); sequence.push_back(input_t{{"p1", 4}}); sequence.push_back(input_t{{"p1", 2}}); auto opts = reelay::discrete_timed<time_type>::robustness< value_type>::monitor<input_t>::options() .with_time_field_name("timestamp") .with_value_field_name("verdict"); auto monitor = reelay::make_monitor("historically[:3]{p1>0}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); if(not r.empty()) { result.push_back(r); } } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"timestamp", 0}, {"verdict", 3.0}}); expected.push_back(output_t{{"timestamp", 3}, {"verdict", 1.0}}); expected.push_back(output_t{{"timestamp", 5}, {"verdict", -1.0}}); expected.push_back(output_t{{"timestamp", 6}, {"verdict", -2.0}}); expected.push_back(output_t{{"timestamp", 10}, {"verdict", 2.0}}); CHECK(result == expected); auto timestamp = output_t{{"timestamp", 10}}; CHECK(monitor.now() == timestamp); } SECTION("Discrete Timed Const Robustness NonCondensing") { std::vector<input_t> sequence = std::vector<input_t>(); sequence.push_back(input_t{{"p1", 3}}); sequence.push_back(input_t{{"p1", 4}}); sequence.push_back(input_t{{"p1", 5}}); sequence.push_back(input_t{{"p1", 1}}); sequence.push_back(input_t{{"p1", 2}}); sequence.push_back(input_t{{"p1", -1}}); sequence.push_back(input_t{{"p1", -2}}); sequence.push_back(input_t{{"p1", 14}}); sequence.push_back(input_t{{"p1", 4}}); sequence.push_back(input_t{{"p1", 4}}); sequence.push_back(input_t{{"p1", 2}}); auto opts = reelay::discrete_timed<time_type>::robustness< value_type>::monitor<input_t>::options() .disable_condensing() .with_time_field_name("timestamp") .with_value_field_name("verdict"); auto monitor = reelay::make_monitor("historically[:3]{p1>0}", opts); auto result = std::vector<output_t>(); for(const auto& s : sequence) { auto r = monitor.update(s); result.push_back(r); } auto expected = std::vector<output_t>(); expected.push_back(output_t{{"verdict", 3.0}}); expected.push_back(output_t{{"verdict", 3.0}}); expected.push_back(output_t{{"verdict", 3.0}}); expected.push_back(output_t{{"verdict", 1.0}}); expected.push_back(output_t{{"verdict", 1.0}}); expected.push_back(output_t{{"verdict", -1.0}}); expected.push_back(output_t{{"verdict", -2.0}}); expected.push_back(output_t{{"verdict", -2.0}}); expected.push_back(output_t{{"verdict", -2.0}}); expected.push_back(output_t{{"verdict", -2.0}}); expected.push_back(output_t{{"verdict", 2.0}}); CHECK(result == expected); auto timestamp = output_t{{"timestamp", 10}}; CHECK(monitor.now() == timestamp); } }
17,549
C++
.cpp
378
40.62963
80
0.598618
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,635
dense_timed_data.test.cpp
doganulus_reelay/tests/src/dense_timed_data.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/intervals.hpp" #include "reelay/json.hpp" #include "reelay/networks/dense_timed_data_network.hpp" #include "reelay/options.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <vector> using input_type = reelay::json; using time_type = int64_t; using interval = reelay::interval<time_type>; using interval_map = reelay::data_interval_map<time_type>; TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Data Atoms", "[dense_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Proposition_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 31}}); sequence.push_back(input_type{{"time", 33}, {"x1", false}}); sequence.push_back(input_type{{"time", 35}, {"x1", false}}); sequence.push_back(input_type{{"time", 40}}); sequence.push_back(input_type{{"time", 52}, {"x1", true}}); sequence.push_back(input_type{{"time", 55}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), t)); expected1.add(std::make_pair(interval::left_open(33, 52), f)); expected1.add(std::make_pair(interval::left_open(52, 55), t)); CHECK(result1 == expected1); } SECTION("AtomicAny_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 31}}); sequence.push_back(input_type{{"time", 33}, {"x1", false}}); sequence.push_back(input_type{{"time", 35}, {"x1", false}}); sequence.push_back(input_type{{"time", 40}}); sequence.push_back(input_type{{"time", 52}, {"x1", true}}); sequence.push_back(input_type{{"time", 55}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1: *}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 31), t)); expected1.add(std::make_pair(interval::left_open(31, 33), f)); expected1.add(std::make_pair(interval::left_open(33, 40), t)); expected1.add(std::make_pair(interval::left_open(40, 52), f)); expected1.add(std::make_pair(interval::left_open(52, 55), t)); CHECK(result1 == expected1); } SECTION("BooleanTrue_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 31}}); sequence.push_back(input_type{{"time", 33}, {"x1", false}}); sequence.push_back(input_type{{"time", 35}, {"x1", false}}); sequence.push_back(input_type{{"time", 40}}); sequence.push_back(input_type{{"time", 52}, {"x1", true}}); sequence.push_back(input_type{{"time", 55}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1: true}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), t)); expected1.add(std::make_pair(interval::left_open(33, 52), f)); expected1.add(std::make_pair(interval::left_open(52, 55), t)); CHECK(result1 == expected1); } SECTION("BooleanFalse_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 31}}); sequence.push_back(input_type{{"time", 33}, {"x1", false}}); sequence.push_back(input_type{{"time", 35}, {"x1", false}}); sequence.push_back(input_type{{"time", 40}}); sequence.push_back(input_type{{"time", 52}, {"x1", true}}); sequence.push_back(input_type{{"time", 55}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1: false}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), f)); expected1.add(std::make_pair(interval::left_open(33, 52), t)); expected1.add(std::make_pair(interval::left_open(52, 55), f)); CHECK(result1 == expected1); } SECTION("AtomicString_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", "veritas"}}); sequence.push_back(input_type{{"time", 31}}); sequence.push_back(input_type{{"time", 33}, {"x1", "fortuna"}}); sequence.push_back(input_type{{"time", 35}, {"x1", "fortuna"}}); sequence.push_back(input_type{{"time", 40}}); sequence.push_back(input_type{{"time", 52}, {"x1", "veritas"}}); sequence.push_back(input_type{{"time", 55}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1: veritas}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), t)); expected1.add(std::make_pair(interval::left_open(33, 52), f)); expected1.add(std::make_pair(interval::left_open(52, 55), t)); CHECK(result1 == expected1); } SECTION("AtomicNumber_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 12}}); sequence.push_back(input_type{{"time", 31}}); sequence.push_back(input_type{{"time", 33}, {"x1", 11}}); sequence.push_back(input_type{{"time", 35}, {"x1", 12.5}}); sequence.push_back(input_type{{"time", 40}}); sequence.push_back(input_type{{"time", 52}, {"x1", 12.5}}); sequence.push_back(input_type{{"time", 55}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1: 12.5}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 35), f)); expected1.add(std::make_pair(interval::left_open(35, 55), t)); CHECK(result1 == expected1); } SECTION("LessThan_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 31}, {"x1", 3}}); sequence.push_back(input_type{{"time", 33}, {"x1", 5}}); sequence.push_back(input_type{{"time", 35}, {"x1", 4}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1 < 4}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), t)); expected1.add(std::make_pair(interval::left_open(33, 40), f)); CHECK(result1 == expected1); } SECTION("LessEqual_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 31}, {"x1", 3}}); sequence.push_back(input_type{{"time", 33}, {"x1", 5}}); sequence.push_back(input_type{{"time", 35}, {"x1", 4}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1 <= 4}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), t)); expected1.add(std::make_pair(interval::left_open(33, 35), f)); expected1.add(std::make_pair(interval::left_open(35, 40), t)); CHECK(result1 == expected1); } SECTION("GreaterThan_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 31}, {"x1", 3}}); sequence.push_back(input_type{{"time", 33}, {"x1", 5}}); sequence.push_back(input_type{{"time", 35}, {"x1", 4}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1 > 4}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), f)); expected1.add(std::make_pair(interval::left_open(33, 35), t)); expected1.add(std::make_pair(interval::left_open(35, 40), f)); CHECK(result1 == expected1); } SECTION("GreaterEqual_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 31}, {"x1", 3}}); sequence.push_back(input_type{{"time", 33}, {"x1", 5}}); sequence.push_back(input_type{{"time", 35}, {"x1", 4}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{x1 >= 4}", opts); auto result1 = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result1.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected1 = interval_map(); expected1.add(std::make_pair(interval::left_open(0, 33), f)); expected1.add(std::make_pair(interval::left_open(33, 40), t)); CHECK(result1 == expected1); } SECTION("Record Proposition 0") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}, {"dummy_field", "v2"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{event: access, user: alice, file: wonderland}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), t)); expected.add(std::make_pair(interval::left_open(3, 6), f)); expected.add(std::make_pair(interval::left_open(6, 9), t)); CHECK(result == expected); } SECTION("Record Proposition 1") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "bob"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{event: access, user: *name, file: wonderland}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto d1 = manager->assign("name", "alice"); auto d3 = manager->assign("name", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), d1)); expected.add(std::make_pair(interval::left_open(3, 6), f)); expected.add(std::make_pair(interval::left_open(6, 9), d3)); CHECK(result == expected); } SECTION("Record Proposition 2") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "bob"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back( input_type{{"time", 9}, {"event", "access"}, {"user", "charlotte"}}); sequence.push_back(input_type{{"time", 11}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{event: access, user: *name, file:*}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto d1 = manager->assign("name", "alice"); auto d2 = manager->assign("name", "bob"); auto d3 = manager->assign("name", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), d1)); expected.add(std::make_pair(interval::left_open(3, 6), d2)); expected.add(std::make_pair(interval::left_open(6, 9), d3)); expected.add(std::make_pair(interval::left_open(9, 11), f)); CHECK(result == expected); } SECTION("Record Proposition 2") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"event", "access"}, {"user", "alice"}}); sequence.push_back( input_type{{"time", 3}, {"event", "access"}, {"user", "bob"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{file: wonderland}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 6), f)); expected.add(std::make_pair(interval::left_open(6, 9), t)); CHECK(result == expected); } SECTION("Record Proposition") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"event", "access"}, {"user", "alice"}}); sequence.push_back( input_type{{"time", 3}, {"event", "access"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{file: wonderland, user:*}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 6), f)); expected.add(std::make_pair(interval::left_open(6, 9), t)); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Data Boolean Operations", "[dense_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Negation") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 1}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "logout"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{{"time", 10}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "!{event: access, user: alice}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), f)); expected.add(std::make_pair(interval::left_open(3, 10), t)); CHECK(result == expected); } SECTION("Conjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 1}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back( input_type{{"time", 6}, {"event", "logout"}, {"user", "alice"}}); sequence.push_back(input_type{{"time", 10}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{event: *e, user: alice, file: *f} and" "{event: access, user: *u, file: wonderland}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto alice_in_wland = manager->assign("e", "access") * manager->assign("u", "alice") * manager->assign("f", "wonderland"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 1), alice_in_wland)); expected.add(std::make_pair(interval::left_open(1, 10), f)); CHECK(result == expected); } SECTION("Disjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 1}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "square"}, {"file", "flatland"}}); sequence.push_back(input_type{{"time", 10}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{event: *e, user: alice, file: *f} or" "{event: access, user: *u, file: wonderland}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto datum1 = (manager->assign("e", "access") * manager->assign("f", "wonderland")) + manager->assign("u", "alice"); auto datum2 = manager->assign("e", "access") * manager->assign("f", "feed_your_head"); auto datum3 = manager->assign("u", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 1), datum1)); expected.add(std::make_pair(interval::left_open(1, 3), datum2)); expected.add(std::make_pair(interval::left_open(3, 6), datum3)); expected.add(std::make_pair(interval::left_open(6, 10), f)); CHECK(result == expected); } SECTION("Implication") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 1}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "square"}, {"file", "flatland"}}); sequence.push_back(input_type{{"time", 10}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "not{event: *e, user: alice, file: *f} implies" "{event: access, user: *u, file: wonderland}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto datum1 = (manager->assign("e", "access") * manager->assign("f", "wonderland")) + manager->assign("u", "alice"); auto datum2 = manager->assign("e", "access") * manager->assign("f", "feed_your_head"); auto datum3 = manager->assign("u", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 1), datum1)); expected.add(std::make_pair(interval::left_open(1, 3), datum2)); expected.add(std::make_pair(interval::left_open(3, 6), datum3)); expected.add(std::make_pair(interval::left_open(6, 10), f)); CHECK(result == expected); } SECTION("Existential Quantification") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 1}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "square"}, {"file", "flatland"}}); sequence.push_back(input_type{{"time", 10}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "exists[e]. {event: *e, user: alice, file: *f}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto datum1 = manager->assign("f", "wonderland"); auto datum2 = manager->assign("f", "feed_your_head"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 1), datum1)); expected.add(std::make_pair(interval::left_open(1, 3), datum2)); expected.add(std::make_pair(interval::left_open(3, 10), f)); CHECK(result == expected); } SECTION("Existential Quantification") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"time", 0}, {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 1}, {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"time", 3}, {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"time", 6}, {"event", "access"}, {"user", "square"}, {"file", "flatland"}}); sequence.push_back(input_type{{"time", 10}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "not(forall[e].(not{event: *e, user: alice, file: *f}))", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto datum1 = manager->assign("f", "wonderland"); auto datum2 = manager->assign("f", "feed_your_head"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 1), datum1)); expected.add(std::make_pair(interval::left_open(1, 3), datum2)); expected.add(std::make_pair(interval::left_open(3, 10), f)); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Data Temporal Operations (Untimed)", "[dense_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 6}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "once{state: open, arg1: c}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 4), f)); expected.add(std::make_pair(interval::left_open(4, 9), t)); CHECK(result == expected); } SECTION("Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 6}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "once{state: open, arg1: *val}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto val_a = manager->assign("val", "a"); auto val_c = manager->assign("val", "c"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 4), val_a)); expected.add(std::make_pair(interval::left_open(4, 9), val_a + val_c)); CHECK(result == expected); } SECTION("Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 6}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "historically{state: open, arg1: a}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 7), t)); expected.add(std::make_pair(interval::left_open(7, 9), f)); CHECK(result == expected); } SECTION("Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 6}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "historically{state: open, arg1: *val}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto val_a = manager->assign("val", "a"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 7), val_a)); expected.add(std::make_pair(interval::left_open(7, 9), f)); CHECK(result == expected); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"state", "arrived"}}); sequence.push_back( input_type{{"time", 1}, {"state", "open"}, {"arg1", "b"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 6}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 7}, {"state", "close"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{state: open, arg1: *} since {state: arrived}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 7), t)); expected.add(std::make_pair(interval::left_open(7, 9), f)); CHECK(result == expected); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "arrived"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 1}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 6}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 7}, {"state", "close"}}); sequence.push_back(input_type{{"time", 9}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "{state: open, arg1: *arg} since {state: arrived, arg1: *arg}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto arg_a = manager->assign("arg", "a"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 7), arg_a)); expected.add(std::make_pair(interval::left_open(7, 9), f)); CHECK(result == expected); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}}); sequence.push_back(input_type{ {"time", 3}, {"visitor1", "alice"}, {"visitor2", "charlotte"}, {"visiting1", "alice"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 9}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 13}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 21}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "({visiting1: *name} or {visiting2: *name}) " "since ({visitor1: *name} or {visitor2: *name})", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto alice = manager->assign("name", "alice"); auto charlotte = manager->assign("name", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), f)); expected.add(std::make_pair(interval::left_open(3, 21), alice + charlotte)); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Data Temporal Operations (Bounded)", "[dense_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 1}, {"state", "open"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 3}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 6}, {"state", "close"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 9}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 12}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back(input_type{{"time", 17}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "once[2:8]{state: open, arg1: c}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), f)); expected.add(std::make_pair(interval::left_open(3, 11), t)); expected.add(std::make_pair(interval::left_open(11, 17), f)); CHECK(result == expected); } SECTION("Timed Once Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 1}, {"state", "open"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 3}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 6}, {"state", "close"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 9}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 12}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back(input_type{{"time", 17}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "once[:8]{state: open, arg1: c}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 1), f)); expected.add(std::make_pair(interval::left_open(1, 11), t)); expected.add(std::make_pair(interval::left_open(11, 17), f)); CHECK(result == expected); } SECTION("Timed Once Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 1}, {"state", "open"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 3}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 6}, {"state", "close"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back( input_type{{"time", 9}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 12}, {"state", "close"}, {"arg1", "c"}}); sequence.push_back(input_type{{"time", 17}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "once[2:]{state: open, arg1: c}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), f)); expected.add(std::make_pair(interval::left_open(3, 17), t)); CHECK(result == expected); } SECTION("Timed Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "b"}}); sequence.push_back( input_type{{"time", 1}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 3}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 11}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 12}, {"state", "close"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 14}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "historically[:8]{state: open, arg1: a}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 9), f)); expected.add(std::make_pair(interval::left_open(9, 12), t)); expected.add(std::make_pair(interval::left_open(12, 14), f)); CHECK(result == expected); } SECTION("Timed Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 3}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 11}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 12}, {"state", "close"}}); sequence.push_back(input_type{{"time", 19}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "historically[4:]{state: open, arg1: a}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 16), t)); expected.add(std::make_pair(interval::left_open(16, 19), f)); CHECK(result == expected); } SECTION("Timed Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back( input_type{{"time", 0}, {"state", "open"}, {"arg1", "b"}}); sequence.push_back( input_type{{"time", 3}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 4}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 7}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back( input_type{{"time", 11}, {"state", "open"}, {"arg1", "a"}}); sequence.push_back(input_type{{"time", 12}, {"state", "close"}}); sequence.push_back(input_type{{"time", 19}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "historically[2:4]{state: open, arg1: a}", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 2), t)); expected.add(std::make_pair(interval::left_open(2, 7), f)); expected.add(std::make_pair(interval::left_open(7, 14), t)); expected.add(std::make_pair(interval::left_open(14, 19), f)); CHECK(result == expected); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}}); sequence.push_back(input_type{ {"time", 1}, {"visitor1", "alice"}, {"visitor2", "charlotte"}, {"visiting1", "alice"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 3}, {"visitor1", ""}, {"visitor2", ""}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 9}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 13}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{{"time", 21}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "({visiting1: *name} or {visiting2: *name}) " "since[2:12] ({visitor1: *name} or {visitor2: *name})", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto alice = manager->assign("name", "alice"); auto charlotte = manager->assign("name", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), f)); expected.add(std::make_pair(interval::left_open(3, 5), alice)); expected.add(std::make_pair(interval::left_open(5, 15), alice + charlotte)); expected.add(std::make_pair(interval::left_open(15, 21), f)); CHECK(result == expected); } SECTION("Timed Since Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}}); sequence.push_back(input_type{ {"time", 1}, {"visitor1", "alice"}, {"visitor2", "charlotte"}, {"visiting1", "alice"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 3}, {"visitor1", "alice"}, {"visitor2", "charlotte"}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 9}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 13}, {"visiting1", "alice"}, {"visiting2", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{ {"time", 21}, {"visiting1", "charlotte"}, {"where", "wonderland"}}); sequence.push_back(input_type{{"time", 23}}); auto net1 = reelay::dense_timed_data_network<time_type, input_type>::make( "({visiting1: *name} or {visiting2: *name}) " "since[2:] ({visitor1: *name} or {visitor2: *name})", opts); auto result = interval_map(); for(const auto& row : sequence) { net1.update(row); for(const auto& intv : net1.output()) { result.add(intv); } } auto t = manager->one(); auto f = manager->zero(); auto alice = manager->assign("name", "alice"); auto charlotte = manager->assign("name", "charlotte"); auto expected = interval_map(); expected.add(std::make_pair(interval::left_open(0, 3), f)); expected.add(std::make_pair(interval::left_open(3, 5), alice)); expected.add(std::make_pair(interval::left_open(5, 21), alice + charlotte)); expected.add(std::make_pair(interval::left_open(21, 23), charlotte)); CHECK(result == expected); } }
48,608
C++
.cpp
1,273
32.417125
80
0.588871
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,636
dense_timed.test.cpp
doganulus_reelay/tests/src/dense_timed.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/intervals.hpp" #include "reelay/json.hpp" #include "reelay/networks/dense_timed_network.hpp" #include "reelay/options.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <vector> using time_type = double; using input_type = reelay::json; using interval = reelay::interval<time_type>; using interval_set = reelay::interval_set<time_type>; TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Atoms", "[dense_timed]") { SECTION("Proposition_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", false}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", false}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", true}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.3)); expected1.add(interval::left_open(5.2, 5.5)); CHECK(result1 == expected1); } SECTION("AtomicAny_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", false}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", false}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", true}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1:*}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.1)); expected1.add(interval::left_open(3.3, 4)); expected1.add(interval::left_open(5.2, 5.5)); CHECK(result1 == expected1); } SECTION("BooleanTrue_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", false}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", false}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", true}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1: true}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.3)); expected1.add(interval::left_open(5.2, 5.5)); CHECK(result1 == expected1); } SECTION("BooleanFalse_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", true}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", false}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", false}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", true}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1: false}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3.3, 5.2)); CHECK(result1 == expected1); } SECTION("AtomicString_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", "veritas"}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", "fortuna"}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", "fortuna"}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", "veritas"}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1: veritas}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.3)); expected1.add(interval::left_open(5.2, 5.5)); CHECK(result1 == expected1); } SECTION("AtomicStringQuoted_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", "lorem ipsum"}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", "not_a_string"}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", "not_a_string_too"}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", "lorem ipsum"}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{x1: 'lorem ipsum'}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.3)); expected1.add(interval::left_open(5.2, 5.5)); CHECK(result1 == expected1); } SECTION("AtomicNumber_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 12}}); sequence.push_back(input_type{{"time", 3.1}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", 11}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", 12.5}}); sequence.push_back(input_type{{"time", 4}}); sequence.push_back(input_type{{"time", 5.2}, {"x1", 12.5}}); sequence.push_back(input_type{{"time", 5.5}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1: 12.5}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3.5, 5.5)); CHECK(result1 == expected1); } SECTION("LessThan_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.1}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", 5}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", 4}}); sequence.push_back(input_type{{"time", 4}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1 < 4}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.3)); CHECK(result1 == expected1); } SECTION("LessEqualThan_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.1}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", 5}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", 4}}); sequence.push_back(input_type{{"time", 4}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1 <= 4}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3.3)); expected1.add(interval::left_open(3.5, 4)); CHECK(result1 == expected1); } SECTION("GreaterThan_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.1}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", 5}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", 4}}); sequence.push_back(input_type{{"time", 4}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1 > 4}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3.3, 3.5)); CHECK(result1 == expected1); } SECTION("GreaterEqualThan_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.1}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", 5}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", 4}}); sequence.push_back(input_type{{"time", 4}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{x1 >= 4}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3.3, 4)); CHECK(result1 == expected1); } SECTION("InBetween_ZeroHoldForward") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.1}, {"x1", 3}}); sequence.push_back(input_type{{"time", 3.3}, {"x1", 5}}); sequence.push_back(input_type{{"time", 3.5}, {"x1", 4}}); sequence.push_back(input_type{{"time", 4}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{x1 > 3.5, x1 < 4.5}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3.5, 4)); CHECK(result1 == expected1); } SECTION("LessThan_PiecewiseLinear") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", -2}}); sequence.push_back(input_type{{"time", 1}, {"x1", -2}}); sequence.push_back(input_type{{"time", 2}, {"x1", -1}}); sequence.push_back(input_type{{"time", 4}, {"x1", 1}}); sequence.push_back(input_type{{"time", 5}, {"x1", 2}}); sequence.push_back(input_type{{"time", 6}, {"x1", 2}}); sequence.push_back(input_type{{"time", 7}, {"x1", 1}}); sequence.push_back(input_type{{"time", 9}, {"x1", -1}}); sequence.push_back(input_type{{"time", 10}, {"x1", -2}}); sequence.push_back(input_type{{"time", 11}, {"x1", 0}}); sequence.push_back(input_type{{"time", 12}, {"x1", 0}}); sequence.push_back(input_type{{"time", 13}, {"x1", 2}}); sequence.push_back(input_type{{"time", 14}, {"x1", 0}}); sequence.push_back(input_type{{"time", 15}, {"x1", -2}}); auto opts = reelay::basic_options().with_interpolation(reelay::piecewise::linear); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{x1 < 0}", opts); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3)); expected1.add(interval::left_open(8, 11)); expected1.add(interval::left_open(14, 15)); CHECK(result1 == expected1); } SECTION("LessEqualThan_PiecewiseLinear") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", -2}}); sequence.push_back(input_type{{"time", 1}, {"x1", -2}}); sequence.push_back(input_type{{"time", 2}, {"x1", -1}}); sequence.push_back(input_type{{"time", 4}, {"x1", 1}}); sequence.push_back(input_type{{"time", 5}, {"x1", 2}}); sequence.push_back(input_type{{"time", 6}, {"x1", 2}}); sequence.push_back(input_type{{"time", 7}, {"x1", 1}}); sequence.push_back(input_type{{"time", 9}, {"x1", -1}}); sequence.push_back(input_type{{"time", 10}, {"x1", -2}}); sequence.push_back(input_type{{"time", 11}, {"x1", 0}}); sequence.push_back(input_type{{"time", 12}, {"x1", 0}}); sequence.push_back(input_type{{"time", 13}, {"x1", 2}}); sequence.push_back(input_type{{"time", 14}, {"x1", 0}}); sequence.push_back(input_type{{"time", 15}, {"x1", -2}}); auto opts = reelay::basic_options().with_interpolation(reelay::piecewise::linear); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{x1 <= 0}", opts); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 3)); expected1.add(interval::left_open(8, 12)); expected1.add(interval::left_open(14, 15)); CHECK(result1 == expected1); } SECTION("GreaterThan_PiecewiseLinear") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", -2}}); sequence.push_back(input_type{{"time", 1}, {"x1", -2}}); sequence.push_back(input_type{{"time", 2}, {"x1", -1}}); sequence.push_back(input_type{{"time", 4}, {"x1", 1}}); sequence.push_back(input_type{{"time", 5}, {"x1", 2}}); sequence.push_back(input_type{{"time", 6}, {"x1", 2}}); sequence.push_back(input_type{{"time", 7}, {"x1", 1}}); sequence.push_back(input_type{{"time", 9}, {"x1", -1}}); sequence.push_back(input_type{{"time", 10}, {"x1", -2}}); sequence.push_back(input_type{{"time", 11}, {"x1", 0}}); sequence.push_back(input_type{{"time", 12}, {"x1", 0}}); sequence.push_back(input_type{{"time", 13}, {"x1", 2}}); sequence.push_back(input_type{{"time", 14}, {"x1", 0}}); sequence.push_back(input_type{{"time", 15}, {"x1", -2}}); auto opts = reelay::basic_options().with_interpolation(reelay::piecewise::linear); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{x1 > 0}", opts); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3, 8)); expected1.add(interval::left_open(12, 14)); CHECK(result1 == expected1); } SECTION("GreaterEqualThan_PiecewiseLinear") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"x1", -2}}); sequence.push_back(input_type{{"time", 1}, {"x1", -2}}); sequence.push_back(input_type{{"time", 2}, {"x1", -1}}); sequence.push_back(input_type{{"time", 4}, {"x1", 1}}); sequence.push_back(input_type{{"time", 5}, {"x1", 2}}); sequence.push_back(input_type{{"time", 6}, {"x1", 2}}); sequence.push_back(input_type{{"time", 7}, {"x1", 1}}); sequence.push_back(input_type{{"time", 9}, {"x1", -1}}); sequence.push_back(input_type{{"time", 10}, {"x1", -2}}); sequence.push_back(input_type{{"time", 11}, {"x1", 0}}); sequence.push_back(input_type{{"time", 12}, {"x1", 0}}); sequence.push_back(input_type{{"time", 13}, {"x1", 2}}); sequence.push_back(input_type{{"time", 14}, {"x1", 0}}); sequence.push_back(input_type{{"time", 15}, {"x1", -2}}); auto opts = reelay::basic_options().with_interpolation(reelay::piecewise::linear); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{x1 >= 0}", opts); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(3, 8)); expected1.add(interval::left_open(11, 14)); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Boolean Operations", "[dense_timed]") { SECTION("Disjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{p1} or {p2}"); auto result = interval_set(); for(const auto& s : sequence) { net1.update(s); result = result | net1.output(); } auto expected = interval_set(); expected.add(interval::left_open(10, 40)); CHECK(result == expected); } SECTION("Conjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{p1} and {p2}"); auto result = interval_set(); for(const auto& s : sequence) { net1.update(s); result = result | net1.output(); } auto expected = interval_set(); expected.add(interval::left_open(30, 40)); CHECK(result == expected); } SECTION("Implication") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 40}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("{p1} -> {p2}"); auto result = interval_set(); for(const auto& s : sequence) { net1.update(s); result = result | net1.output(); } auto expected = interval_set(); expected.add(interval::left_open(0, 10)); expected.add(interval::left_open(20, 40)); CHECK(result == expected); } SECTION("Negation") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}}); sequence.push_back(input_type{{"time", 20}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("not{p1}"); auto result = interval_set(); for(const auto& s : sequence) { net1.update(s); result = result | net1.output(); } auto expected = interval_set(); expected.add(interval::left_open(0, 10)); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Temporal Operations (Untimed)", "[dense_timed]") { SECTION("Past Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 120}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "historically{p1}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 60)); CHECK(result1 == expected1); } SECTION("Past Sometime") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 125}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("once{p1}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(60, 125)); CHECK(result1 == expected1); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 201}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 248}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{p1} since {p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(115, 201)); CHECK(result1 == expected1); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Dense Timed Temporal Operations (Bounded)", "[dense_timed]") { SECTION("Timed Past Always") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 248}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); // auto net1 = // reelay::detail::dense_timed<time_type>::network<input_type>::make("not // (p1 since [12:24] not p2)"); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "historically[12:24]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 12)); expected1.add(interval::left_open(139, 168)); expected1.add(interval::left_open(199, 260)); expected1.add(interval::left_open(311, 312)); CHECK(result1 == expected1); } SECTION("Timed Past Always Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 248}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); // auto net1 = // reelay::detail::dense_timed<time_type>::network<input_type>::make("not // (p1 since [12:24] not p2)"); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "historically[0:24]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(139, 156)); expected1.add(interval::left_open(199, 248)); CHECK(result1 == expected1); } SECTION("Timed Past Always Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 248}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); // auto net1 = // reelay::detail::dense_timed<time_type>::network<input_type>::make("not // (p1 since [12:24] not p2)"); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "historically[12:]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(0, 12)); CHECK(result1 == expected1); } SECTION("Timed Past Sometime") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 248}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "once[12:24]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(22, 44)); expected1.add(interval::left_open(127, 180)); expected1.add(interval::left_open(187, 272)); expected1.add(interval::left_open(299, 324)); CHECK(result1 == expected1); } SECTION("Timed Past Sometime Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 248}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); // auto net1 = // reelay::detail::dense_timed<time_type>::network<input_type>::make("p1 // since [12:24] p2"); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("once[:24]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(10, 44)); expected1.add(interval::left_open(115, 180)); expected1.add(interval::left_open(175, 272)); expected1.add(interval::left_open(287, 324)); CHECK(result1 == expected1); } SECTION("Timed Past Sometime Inf") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 248}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); // auto net1 = // reelay::detail::dense_timed<time_type>::network<input_type>::make("p1 // since [12:24] p2"); auto net1 = reelay::dense_timed_network<time_type, input_type>::make("once[12:]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(22, 444)); CHECK(result1 == expected1); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 201}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 248}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{p1} since[18:24]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(interval::left_open(133, 180)); CHECK(result1 == expected1); } SECTION("Timed Since Zero") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 201}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 248}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{p1} since[:24]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(interval::left_open(115, 180)); CHECK(result1 == expected1); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", false}, {"p2", true}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 115}, {"p1", true}, {"p2", true}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 201}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 248}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", false}, {"p2", false}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}, {"p2", false}}); sequence.push_back(input_type{{"time", 444}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "{p1} since[18:]{p2}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(interval::left_open(133, 201)); CHECK(result1 == expected1); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"time", 0}, {"p1", false}}); sequence.push_back(input_type{{"time", 10}, {"p1", false}}); sequence.push_back(input_type{{"time", 20}, {"p1", false}}); sequence.push_back(input_type{{"time", 30}, {"p1", true}}); sequence.push_back(input_type{{"time", 60}, {"p1", true}}); sequence.push_back(input_type{{"time", 70}, {"p1", true}}); sequence.push_back(input_type{{"time", 90}, {"p1", true}}); sequence.push_back(input_type{{"time", 115}, {"p1", false}}); sequence.push_back(input_type{{"time", 156}, {"p1", true}}); sequence.push_back(input_type{{"time", 175}, {"p1", true}}); sequence.push_back(input_type{{"time", 201}, {"p1", false}}); sequence.push_back(input_type{{"time", 248}, {"p1", false}}); sequence.push_back(input_type{{"time", 287}, {"p1", false}}); sequence.push_back(input_type{{"time", 300}, {"p1", true}}); sequence.push_back(input_type{{"time", 315}, {"p1", true}}); sequence.push_back(input_type{{"time", 444}}); auto net1 = reelay::dense_timed_network<time_type, input_type>::make( "!{p1} since[10:20] {p1}"); auto result1 = interval_set(); for(const auto& s : sequence) { net1.update(s); result1 = result1 | net1.output(); } auto expected1 = interval_set(); expected1.add(interval::left_open(125, 135)); expected1.add(interval::left_open(211, 221)); CHECK(result1 == expected1); } }
42,701
C++
.cpp
886
43.066591
80
0.602828
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,637
discrete_timed_data.test.cpp
doganulus_reelay/tests/src/discrete_timed_data.test.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/json.hpp" #include "reelay/networks/discrete_timed_data_network.hpp" #include "reelay/options.hpp" #include <catch2/catch_test_macros.hpp> #include <iostream> #include <vector> using input_type = reelay::json; using time_type = int64_t; TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Data Atoms", "[discrete_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("AtomicProposition") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", true}}); sequence.push_back(input_type{{"x", false}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", true}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, f, t}); CHECK(result == expected); } SECTION("AtomicTrue") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", true}}); sequence.push_back(input_type{{"x", false}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", true}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x: true}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, f, t}); CHECK(result == expected); } SECTION("AtomicFalse") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", true}}); sequence.push_back(input_type{{"x", false}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", true}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x: false}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, f}); CHECK(result == expected); } SECTION("AtomicString") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", "a"}}); sequence.push_back(input_type{{"x", "b"}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", "c"}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x: b}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, f}); CHECK(result == expected); } SECTION("AtomicNumber") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x: 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, f}); CHECK(result == expected); } SECTION("GreaterThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x > 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, f, t}); CHECK(result == expected); } SECTION("GreaterEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x >= 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, t}); CHECK(result == expected); } SECTION("LessThan") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x < 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, f, f}); CHECK(result == expected); } SECTION("LessEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x <= 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, t, t, f}); CHECK(result == expected); } SECTION("Equal") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x == 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, f}); CHECK(result == expected); } SECTION("NotEqual") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", 1}}); sequence.push_back(input_type{{"x", 2}}); sequence.emplace_back(input_type{}); sequence.push_back(input_type{{"x", 3}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x != 2}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, f, t}); CHECK(result == expected); } SECTION("AtomicAny") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{{"x", "1"}}); sequence.push_back(input_type{{"y", "2"}}); sequence.push_back(input_type{{"x", "3"}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{x: *}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, t}); CHECK(result == expected); } SECTION("List Proposition 0") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "alice"}); sequence.push_back(input_type{"tritiny", "bob", "humpie", "dumpie"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: access, $1: bob, $2: white_rabbit}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, f, f, f}); CHECK(result == expected); } SECTION("List Proposition 1") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "alice"}); sequence.push_back(input_type{"tritiny", "bob", "humpie", "dumpie"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: access, $1: alice}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, t, f, f}); CHECK(result == expected); } SECTION("List Proposition 3") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "alice"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: *, $1: alice, $2: *}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, t, f, f}); CHECK(result == expected); } SECTION("List Proposition 4") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "charlotte"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: *event, $1: alice, $2: *}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto datum = manager->assign("event", "access"); auto expected = std::vector<reelay::data_set_t>({datum, f, datum, f, f}); CHECK(result == expected); } SECTION("List Proposition 5") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "alice"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: access, $1: *user, $2: *file}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto alice_in_wonderland = manager->assign("user", "alice") * manager->assign("file", "wonderland"); auto bobs_white_rabbit = manager->assign("user", "bob") * manager->assign("file", "white_rabbit"); auto alice_feed_your_head = manager->assign("user", "alice") * manager->assign("file", "feed_your_head"); auto expected = std::vector<reelay::data_set_t>( {alice_in_wonderland, bobs_white_rabbit, alice_feed_your_head, f, f}); CHECK(result == expected); } SECTION("Record Proposition 0") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"event", "access"}, {"user", "alice"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}, {"version", "v2"}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{event: access, user: alice, file: wonderland}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, f, t}); CHECK(result == expected); } SECTION("Record Proposition 1") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"event", "access"}, {"user", "bob"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{event: access, user: *name, file: wonderland}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto d1 = manager->assign("name", "alice"); auto d3 = manager->assign("name", "charlotte"); auto expected = std::vector<reelay::data_set_t>({d1, f, d3}); CHECK(result == expected); } SECTION("Record Proposition 1") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{ {"event", "access"}, {"user", "alice"}, {"file", "wonderland"}}); sequence.push_back(input_type{ {"event", "access"}, {"user", "bob"}, {"file", "feed_your_head"}}); sequence.push_back(input_type{ {"event", "access"}, {"user", "charlotte"}, {"file", "wonderland"}}); sequence.push_back(input_type{{"event", "access"}, {"user", "charlotte"}}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{event: access, user: *name, file:*}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto d1 = manager->assign("name", "alice"); auto d2 = manager->assign("name", "bob"); auto d3 = manager->assign("name", "charlotte"); auto expected = std::vector<reelay::data_set_t>({d1, d2, d3, f}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Data Boolean Operations", "[discrete_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Negation") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "alice"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "!{$0: access, $1: alice, $2: *}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, f, t, t}); CHECK(result == expected); } SECTION("Conjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "alice"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: *event, $1: alice, $2: *file} and " "{$0: access, $1: *user, $2: wonderland}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto alice_in_wonderland = manager->assign("event", "access") * manager->assign("user", "alice") * manager->assign("file", "wonderland"); auto expected = std::vector<reelay::data_set_t>({alice_in_wonderland, f, f, f, f}); CHECK(result == expected); } SECTION("Disjunction") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "charlotte"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: *event, $1: alice, $2: *file} or " "{$0: access, $1: *user, $2: wonderland}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto datum1 = (manager->assign("event", "access") * manager->assign("file", "wonderland")) + manager->assign("user", "alice"); auto datum3 = manager->assign("event", "access") * manager->assign("file", "feed_your_head"); auto expected = std::vector<reelay::data_set_t>({datum1, f, datum3, f, f}); CHECK(result == expected); } SECTION("Implication") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "charlotte"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "!{$0: *event, $1: alice, $2: *file} implies " "{$0: access, $1: *user, $2: wonderland}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto datum1 = (manager->assign("event", "access") * manager->assign("file", "wonderland")) + manager->assign("user", "alice"); auto datum3 = manager->assign("event", "access") * manager->assign("file", "feed_your_head"); auto expected = std::vector<reelay::data_set_t>({datum1, f, datum3, f, f}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Data Temporal Operations (Untimed)", "[discrete_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Previous") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "1"}); sequence.push_back(input_type{"open", "2"}); sequence.push_back(input_type{"close", "2"}); sequence.push_back(input_type{"close", "2"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "pre{$0: open, $1: *}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, f}); CHECK(result == expected); } SECTION("Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"open", "c"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "once{$0: open, $1: c}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, t}); CHECK(result == expected); } SECTION("Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"close", "a"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "historically{$0: is_open, $1: a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, t, t, f}); CHECK(result == expected); } SECTION("Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "b"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0: is_open, $1: a} since {$0: open, $1: a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, t, t, t, f}); CHECK(result == expected); } SECTION("Existential Quantification") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "charlotte"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "exists[event]. {$0: *event, $1: alice, $2: *file}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto datum1 = manager->assign("file", "wonderland"); auto datum3 = manager->assign("file", "feed_your_head"); auto expected = std::vector<reelay::data_set_t>({datum1, f, datum3, f, f}); CHECK(result == expected); } SECTION("Universal Quantification") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"access", "alice", "wonderland"}); sequence.push_back(input_type{"access", "bob", "white_rabbit"}); sequence.push_back(input_type{"access", "alice", "feed_your_head"}); sequence.push_back(input_type{"logout", "charlotte"}); sequence.push_back(input_type{"meet", "bob", "humpty", "dumpty"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "not(forall[event].(!{$0: *event, $1: alice, $2: *file}))", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto datum1 = manager->assign("file", "wonderland"); auto datum3 = manager->assign("file", "feed_your_head"); auto expected = std::vector<reelay::data_set_t>({datum1, f, datum3, f, f}); CHECK(result == expected); } } TEST_CASE( // NOLINT(readability-function-cognitive-complexity) "Discrete Timed Data Temporal Operations (Bounded)", "[discrete_timed_data]") { auto manager = std::make_shared<reelay::binding_manager>(); auto opts = reelay::basic_options().with_data_manager(manager); SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"open", "c"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "c"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "once[2:4]{$0: open, $1: c}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, f, t, t, t, f}); CHECK(result == expected); } SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"open", "c"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "c"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "once[:4]{$0: open, $1: c}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, t, t, t, t, t, f}); CHECK(result == expected); } SECTION("Timed Once") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"open", "c"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "c"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "c"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "once[2:]{$0: open, $1: c}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, f, t, t, t, t}); CHECK(result == expected); } SECTION("Timed Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"is_open", "b"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"close", "a"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "historically[:4]{$0:is_open, $1:a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, f, f, f, t, f}); CHECK(result == expected); } SECTION("Timed Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"is_open", "b"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "a"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "historically[2:4]{$0:is_open, $1:a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, f, f, f, t, t, t, f}); CHECK(result == expected); } SECTION("Timed Historically") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "a"}); sequence.push_back(input_type{"close", "a"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "historically[2:]{$0:is_open, $1:a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, t, t, t, t, t, t, f}); CHECK(result == expected); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "b"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0:is_open, $1:a} since[2:4] {$0: open, $1: a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, t, t, t, f, f, f}); CHECK(result == expected); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "b"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0:is_open, $1:a} since[:4] {$0: open, $1: a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({t, t, t, t, t, f, f, f}); CHECK(result == expected); } SECTION("Timed Since") { std::vector<input_type> sequence = std::vector<input_type>(); sequence.push_back(input_type{"open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "a"}); sequence.push_back(input_type{"is_open", "b"}); auto net1 = reelay::discrete_timed_data_network<time_type, input_type>::make( "{$0:is_open, $1:a} since[2:] {$0: open, $1: a}", opts); auto result = std::vector<reelay::data_set_t>(); for(const auto& row : sequence) { net1.update(row); result.push_back(net1.output()); } auto t = manager->one(); auto f = manager->zero(); auto expected = std::vector<reelay::data_set_t>({f, f, t, t, t, t, t, f}); CHECK(result == expected); } }
36,902
C++
.cpp
915
34.71694
79
0.614789
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,638
main.cpp
doganulus_reelay/src/pybind11/main.cpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #include "reelay/formatters/python_formatter.hpp" #include "reelay/monitors/dense_timed_data_monitor.hpp" #include "reelay/monitors/dense_timed_monitor.hpp" #include "reelay/monitors/dense_timed_robustness_0_monitor.hpp" #include "reelay/monitors/discrete_timed_data_monitor.hpp" #include "reelay/monitors/discrete_timed_monitor.hpp" #include "reelay/monitors/discrete_timed_robustness_monitor.hpp" #include "reelay/monitors/monitor.hpp" #include "reelay/options.hpp" #include "reelay/parser/ptl_inspector.hpp" #include "pybind11/pybind11.h" namespace py = pybind11; namespace ry = reelay; py::dict inspect(const std::string& pattern) { auto gadget = reelay::ptl_inspector(); auto result = gadget.inspect(pattern); bool timed = reelay::any_cast<bool>(result["timed"]); bool has_references = reelay::any_cast<bool>(result["has_references"]); return py::dict( py::arg("timed") = timed, py::arg("has_references") = has_references); } PYBIND11_MODULE(MODULE_NAME, m) { m.doc() = "This package provides Python bindings of runtime monitors constructed " "from formal specifications using Reelay C++ library."; m.def("inspect", &inspect, "A function to inspect specifications"); py::class_<ry::basic_options>(m, "monitor_options") .def(py::init<const std::string&, const std::string&, bool, bool>()) .def(py::init< const std::string&, const std::string&, const std::string&, bool>()); ; using discrete_monitor_t = ry::discrete_timed_monitor<intmax_t, py::object, py::object, false>; py::class_<discrete_monitor_t>(m, "discrete_monitor") .def("make", &discrete_monitor_t::make) .def("now", &discrete_monitor_t::now) .def("update", &discrete_monitor_t::update); using condensing_monitor_t = ry::discrete_timed_monitor<intmax_t, py::object, py::object, true>; py::class_<condensing_monitor_t>(m, "condensing_monitor") .def("make", &condensing_monitor_t::make) .def("now", &condensing_monitor_t::now) .def("update", &condensing_monitor_t::update); using discrete_data_monitor_t = ry::discrete_timed_data_monitor<intmax_t, py::object, py::object, false>; py::class_<discrete_data_monitor_t>(m, "discrete_data_monitor") .def("make", &discrete_data_monitor_t::make) .def("now", &discrete_data_monitor_t::now) .def("update", &discrete_data_monitor_t::update); using condensing_data_monitor_t = ry::discrete_timed_data_monitor<intmax_t, py::object, py::object, true>; py::class_<condensing_data_monitor_t>(m, "condensing_data_monitor") .def("make", &condensing_data_monitor_t::make) .def("now", &condensing_data_monitor_t::now) .def("update", &condensing_data_monitor_t::update); using discrete_robustness_monitor_t = ry::discrete_timed_robustness_monitor< intmax_t, double, py::object, py::object, false>; py::class_<discrete_robustness_monitor_t>(m, "discrete_robustness_monitor") .def("make", &discrete_robustness_monitor_t::make) .def("now", &discrete_robustness_monitor_t::now) .def("update", &discrete_robustness_monitor_t::update); using condensing_robustness_monitor_t = ry::discrete_timed_robustness_monitor< intmax_t, double, py::object, py::object, true>; py::class_<condensing_robustness_monitor_t>( m, "condensing_robustness_monitor") .def("make", &condensing_robustness_monitor_t::make) .def("now", &condensing_robustness_monitor_t::now) .def("update", &condensing_robustness_monitor_t::update); using dense_monitor_t = ry::dense_timed_monitor<double, py::object, py::object>; py::class_<dense_monitor_t>(m, "dense_monitor") .def("make", &dense_monitor_t::make) .def("now", &dense_monitor_t::now) .def("update", &dense_monitor_t::update); using dense_data_monitor_t = ry::dense_timed_data_monitor<double, py::object, py::object>; py::class_<dense_data_monitor_t>(m, "dense_data_monitor") .def("make", &dense_data_monitor_t::make) .def("now", &dense_data_monitor_t::now) .def("update", &dense_data_monitor_t::update); using dense_robustness_monitor_t = ry:: dense_timed_robustness_0_monitor<double, double, py::object, py::object>; py::class_<dense_robustness_monitor_t>(m, "dense_robustness_monitor") .def("make", &dense_robustness_monitor_t::make) .def("now", &dense_robustness_monitor_t::now) .def("update", &dense_robustness_monitor_t::update); }
4,705
C++
.cpp
107
40.046729
80
0.699847
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,639
simdjson_adapter.hpp
doganulus_reelay/apps/ryjson1/simdjson_adapter.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/datafield.hpp" #include "unordered_set" namespace reelay { template<typename T> struct timefield<T, simdjson::dom::element> { using input_t = simdjson::dom::element; inline static T get_time(const input_t& container) { return container.at_key("time"); } }; template<> struct datafield<simdjson::dom::element> { using input_t = simdjson::dom::element; inline static input_t at(const input_t& container, const std::string& key) { return container.at_key(key); } inline static input_t at(const input_t& container, std::size_t index) { return container.at(index); } inline static bool contains(const input_t& container, const std::string& key) { for(simdjson::dom::object::iterator field = simdjson::dom::object(container).begin(); field != simdjson::dom::object(container).end(); ++field) { if(key == field.key()) { return true; } } return false; } inline static bool as_bool(const input_t& container, const std::string& key) { return container.at_key(key).get<bool>(); } inline static int64_t as_integer( const input_t& container, const std::string& key) { return container.at_key(key).get<int64_t>(); } inline static double as_floating( const input_t& container, const std::string& key) { return container.at_key(key).get<double>(); } inline static std::string as_string( const input_t& container, const std::string& key) { std::string_view sv = container.at_key(key).get<std::string_view>(); return std::string(sv); } inline static bool contains(const input_t& container, std::size_t index) { return index < simdjson::dom::array(container).size(); } inline static bool as_bool(const input_t& container, std::size_t index) { return container.at(index).get<bool>(); } inline static int as_integer(const input_t& container, std::size_t index) { return container.at(index).get<int64_t>(); } inline static double as_floating(const input_t& container, std::size_t index) { return container.at(index).get<double>(); } inline static std::string as_string( const input_t& container, std::size_t index) { std::string_view sv = container.at(index).get<std::string_view>(); return std::string(sv); } }; } // namespace reelay
2,626
C++
.h
86
26.767442
79
0.68373
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,641
version.hpp
doganulus_reelay/include/reelay/version.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #ifndef REELAY_VERSION_HPP #define REELAY_VERSION_HPP #define REELAY_VERSION_MAJOR 23 #define REELAY_VERSION_MINOR 8 #endif
377
C++
.h
12
29.666667
70
0.751381
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,642
datafield.hpp
doganulus_reelay/include/reelay/datafield.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <stdexcept> #include <string> #include <unordered_map> #include <unordered_set> namespace reelay { template<typename time_t, typename input_t> struct timefield { }; template<typename input_t> struct datafield { }; template<typename T> struct timefield<T, std::unordered_map<std::string, std::string>> { using input_t = std::unordered_map<std::string, std::string>; inline static T get_time(const input_t& container) { return container.at("time"); } }; template<> struct datafield<std::unordered_map<std::string, std::string>> { using input_t = std::unordered_map<std::string, std::string>; static std::unordered_set<std::string>& falsity() { static std::unordered_set<std::string> f = {"0", "false", "False"}; return f; } inline static bool contains(const input_t& container, const std::string& key) { return container.find(key) != container.end(); } inline static bool as_bool(const input_t& container, const std::string& key) { return falsity().find(container.at(key)) == falsity().end(); } inline static int as_integer(const input_t& container, const std::string& key) { return std::stoi(container.at(key)); } inline static double as_floating( const input_t& container, const std::string& key) { return std::stod(container.at(key)); } inline static std::string as_string( const input_t& container, const std::string& key) { return container.at(key); } inline static bool contains(const input_t& container, std::size_t index) { throw std::runtime_error(""); } inline static bool as_bool(const input_t& container, std::size_t index) { throw std::runtime_error(""); } inline static int as_integer(const input_t& container, std::size_t index) { throw std::runtime_error(""); } inline static double as_floating(const input_t& container, std::size_t index) { throw std::runtime_error(""); } inline static std::string as_string( const input_t& container, std::size_t index) { throw std::runtime_error(""); } }; } // namespace reelay
2,361
C++
.h
80
26.45
80
0.696729
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,643
options.hpp
doganulus_reelay/include/reelay/options.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <string> #include <utility> // #include "reelay/json.hpp" #include "reelay/unordered_data.hpp" namespace reelay { // enum class time_model : int { error = 0, discrete = 1, dense = 2 }; // enum class value_model : int { error = 0, boolean = 1, robustness = 2 }; enum class piecewise : int { error = 0, constant = 1, linear = 2 }; struct basic_options { basic_options() = default; basic_options( std::string tname, std::string yname, bool condense, bool with_data_manager) : time_field_name(std::move(tname)), value_field_name(std::move(yname)), condensing(condense) { if(with_data_manager) { data_manager = std::make_shared<reelay::binding_manager>(); } } basic_options( std::string tname, std::string yname, const std::string& interpolation, bool with_data_manager) : time_field_name(std::move(tname)), value_field_name(std::move(yname)) { if(interpolation == "constant") { interpolation_option = piecewise::constant; } else if(interpolation == "linear") { interpolation_option = piecewise::linear; } if(with_data_manager) { data_manager = std::make_shared<reelay::binding_manager>(); } } basic_options& with_interpolation(piecewise order) { interpolation_option = order; return *this; } basic_options& with_data_manager() { data_manager = std::make_shared<reelay::binding_manager>(); return *this; } basic_options& with_data_manager(const data_mgr_t& mgr) { data_manager = mgr; return *this; } basic_options& with_condensing(bool flag) { condensing = flag; return *this; } basic_options& enable_condensing() { condensing = true; return *this; } basic_options& disable_condensing() { condensing = false; return *this; } basic_options& with_time_field_name(const std::string& name) { time_field_name = name; return *this; } basic_options& with_value_field_name(const std::string& name) { value_field_name = name; return *this; } [[nodiscard]] std::string get_time_field_name() const { return time_field_name; } [[nodiscard]] std::string get_value_field_name() const { return value_field_name; } [[nodiscard]] data_mgr_t get_data_manager() const { return data_manager; } [[nodiscard]] piecewise get_interpolation() const { return interpolation_option; } [[nodiscard]] bool is_condensing() const { return condensing; } private: data_mgr_t data_manager; // Setting options enum piecewise interpolation_option = piecewise::constant; // Formatter options bool condensing = true; std::string time_field_name = "time"; std::string value_field_name = "value"; }; template<typename T, typename X, typename Y> struct dense_monitor_options { using time_type = T; using input_type = X; using output_type = Y; dense_monitor_options() = default; dense_monitor_options& with_interpolation(piecewise order) { options.with_interpolation(order); return *this; } dense_monitor_options& with_data_manager() { options.with_data_manager(); return *this; } dense_monitor_options& with_data_manager(const data_mgr_t& mgr) { options.with_data_manager(mgr); return *this; } dense_monitor_options& with_time_field_name(const std::string& name) { options.with_time_field_name(name); return *this; } dense_monitor_options& with_value_field_name(const std::string& name) { options.with_value_field_name(name); return *this; } [[nodiscard]] piecewise get_interpolation() const { return options.get_interpolation(); } [[nodiscard]] std::string get_time_field_name() const { return options.get_time_field_name(); } [[nodiscard]] std::string get_value_field_name() const { return options.get_value_field_name(); } [[nodiscard]] basic_options get_basic_options() const { return options; } private: basic_options options; }; template<typename T, typename V, typename X, typename Y> struct dense_robustness_monitor_options { using time_type = T; using value_type = V; using input_type = X; using output_type = Y; dense_robustness_monitor_options() = default; dense_robustness_monitor_options& with_time_field_name( const std::string& name) { options.with_time_field_name(name); return *this; } dense_robustness_monitor_options& with_value_field_name( const std::string& name) { options.with_value_field_name(name); return *this; } [[nodiscard]] std::string get_time_field_name() const { return options.get_time_field_name(); } [[nodiscard]] std::string get_value_field_name() const { return options.get_value_field_name(); } [[nodiscard]] basic_options get_basic_options() const { return options; } private: basic_options options; }; template<typename T, typename X, typename Y> struct discrete_monitor_options { using time_type = T; using input_type = X; using output_type = Y; discrete_monitor_options() = default; discrete_monitor_options& with_data_manager() { options.with_data_manager(); return *this; } discrete_monitor_options& with_data_manager(const data_mgr_t& mgr) { options.with_data_manager(mgr); return *this; } discrete_monitor_options& with_time_field_name(const std::string& name) { options.with_time_field_name(name); return *this; } discrete_monitor_options& with_value_field_name(const std::string& name) { options.with_value_field_name(name); return *this; } discrete_monitor_options& with_condensing(bool flag) { options.with_condensing(flag); return *this; } discrete_monitor_options& enable_condensing() { options.enable_condensing(); return *this; } discrete_monitor_options& disable_condensing() { options.disable_condensing(); return *this; } [[nodiscard]] bool is_condensing() const { return options.is_condensing(); } [[nodiscard]] std::string get_time_field_name() const { return options.get_time_field_name(); } [[nodiscard]] std::string get_value_field_name() const { return options.get_value_field_name(); } [[nodiscard]] basic_options get_basic_options() const { return options; } private: basic_options options; }; template<typename T, typename V, typename X, typename Y> struct discrete_robustness_monitor_options { using time_type = T; using value_type = V; using input_type = X; using output_type = Y; discrete_robustness_monitor_options() = default; discrete_robustness_monitor_options& with_time_field_name( const std::string& name) { options.with_time_field_name(name); return *this; } discrete_robustness_monitor_options& with_value_field_name( const std::string& name) { options.with_value_field_name(name); return *this; } discrete_robustness_monitor_options& with_condensing(bool flag) { options.with_condensing(flag); return *this; } discrete_robustness_monitor_options& enable_condensing() { options.enable_condensing(); return *this; } discrete_robustness_monitor_options& disable_condensing() { options.disable_condensing(); return *this; } [[nodiscard]] bool is_condensing() const { return options.is_condensing(); } [[nodiscard]] std::string get_time_field_name() const { return options.get_time_field_name(); } [[nodiscard]] std::string get_value_field_name() const { return options.get_value_field_name(); } [[nodiscard]] basic_options get_basic_options() const { return options; } private: basic_options options; }; } // namespace reelay
8,074
C++
.h
313
22.073482
80
0.691027
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,644
networks.hpp
doganulus_reelay/include/reelay/networks.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/networks/dense_timed_data_network.hpp" #include "reelay/networks/dense_timed_network.hpp" #include "reelay/networks/dense_timed_robustness_0_network.hpp" #include "reelay/networks/discrete_timed_data_network.hpp" #include "reelay/networks/discrete_timed_network.hpp" #include "reelay/networks/discrete_timed_robustness_network.hpp"
614
C++
.h
14
42.285714
70
0.779264
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,645
unordered_data.hpp
doganulus_reelay/include/reelay/unordered_data.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <memory> #include <string> #include <unordered_map> #include "cudd.h" #include "cuddObj.hh" template<> struct std::hash<BDD> { std::size_t operator()(const BDD& k) const { return std::hash<DdNode*>{}(k.getNode()); } }; namespace reelay { struct binding_manager; using data_mgr_t = std::shared_ptr<binding_manager>; using data_set_t = BDD; struct binding_manager { using set_t = BDD; using mgr_t = Cudd; template<typename V = std::string> struct variable_t { set_t one; set_t cube; set_t other_cubes; set_t empty_slots; std::size_t n = 0; std::vector<set_t> bddvars; std::unordered_map<set_t, V> values = {}; std::unordered_map<V, set_t> slots = {}; variable_t() = default; variable_t(const mgr_t& mgr, const std::vector<set_t>& vars) : one(mgr.bddOne()), cube(mgr.computeCube(vars)), empty_slots(~cube), bddvars(vars) { } std::size_t size() { return bddvars.size(); } // set_t assign(const V &value) { // if (slots.find(value) != slots.end()) { // return slots[value]; // } // auto slot = empty_slots.PickOneMinterm(bddvars); // values[slot] = value; // slots[value] = slot; // empty_slots = ~slot * empty_slots; // Excludes slot from empty slots // return slot; // } set_t assign(const V& value) { if(slots.find(value) != slots.end()) { return slots[value]; } auto slot = make_minterm_of(n); n++; values[slot] = value; slots[value] = slot; return slot; } set_t make_minterm_of(std::size_t n) { std::size_t k = n; set_t c = one; for(std::size_t i = 0; i < bddvars.size(); i++) { if(k % 2 != 0) { c *= bddvars[i]; } else { c *= ~bddvars[i]; } k /= 2; } return c; } set_t erase(const V& value) { auto slot = slots[value]; values.erase(slot); slots.erase(value); return slot; } V erase(const set_t& slot) { auto value = values[slot]; slots.erase(value); values.erase(slot); return value; } set_t get_used_slots(const set_t& data_set) { auto used_slots = data_set.ExistAbstract(other_cubes) * (~data_set).ExistAbstract(other_cubes); return used_slots; } }; mgr_t cudd; std::unordered_map<std::string, variable_t<std::string>> variables = {}; binding_manager() { cudd = Cudd(0, 0); cudd.AutodynDisable(); } set_t one() const { return cudd.bddOne(); } set_t zero() const { return cudd.bddZero(); } void add_variable(std::string name, std::size_t nbits = 20) { if(variables.find(name) == variables.end()) { std::vector<set_t> bddvars = {}; for(std::size_t i = 0; i < nbits; i++) { bddvars.push_back(cudd.bddVar()); } variables[name] = variable_t<std::string>(cudd, bddvars); } } set_t assign(std::string name, std::string value) { return variables[name].assign(value); } }; } // namespace reelay
3,450
C++
.h
137
19.978102
77
0.578387
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,646
intervals.hpp
doganulus_reelay/include/reelay/intervals.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "boost/icl/interval.hpp" #include "boost/icl/interval_map.hpp" #include "boost/icl/interval_set.hpp" #include "cuddObj.hh" namespace boost { namespace icl { /* * Inplace BDD OR functor */ template<typename V> struct data_join { using first_argument_type = V&; using second_argument_type = const V&; using result_type = void; using type = data_join<V>; inline static V identity_element() { // This static function is unsafe and causes a segfault if accessed. // By design Boost ICL requires this function to exist and be static. // // The main problem: The identity element for BDDs, `false` node for join // operation, cannot be defined at compile time as we need a BDD manager // first, only constructed at runtime. Alternative solution would be to // define a singleton manager but it would hurt flexibility deeply. // // For long term we need to write our own interval_map implementation. throw std::runtime_error("Identity element shall not have been accessed!"); return BDD(); } // Unsafe void operator()(V& object, const V& operand) const { object |= operand; } }; /* * Inplace BDD AND functor */ template<typename V> struct data_meet { using first_argument_type = V&; using second_argument_type = const V&; using result_type = void; using type = data_meet<V>; inline static V identity_element() { // This static function is unsafe and causes a segfault if accessed. // By design Boost ICL requires this function to exist and be static. // // The main problem: The identity element for BDDs, `true` node for meet // operation, cannot be defined at compile time as we need a BDD manager // first, only constructed at runtime. Alternative solution would be to // define a singleton manager but it would hurt flexibility deeply. // // For long term we need to write our own interval_map implementation. throw std::runtime_error("Identity element shall not have been accessed!"); return BDD(); } void operator()(V& object, const V& operand) const { object &= operand; } }; /* * Boost ICL uses operator+ for Combiner functor (here data_join) */ template<class T> struct inverse<boost::icl::data_join<T>> { using type = boost::icl::data_meet<T>; }; /* * Boost ICL uses operator- for the inverse of Combiner functor (here data_meet) */ template<class T> struct inverse<boost::icl::data_meet<T>> { using type = boost::icl::data_join<T>; }; /* * Inplace MAX functor */ template<typename V> struct robustness_join { using first_argument_type = V&; using second_argument_type = const V&; using result_type = void; using type = robustness_join<V>; inline static V identity_element() { return -infinity<V>::value(); } void operator()(V& object, const V& operand) const { if(object < operand) { object = operand; } } }; /* * Inplace MIN functor */ template<typename V> struct robustness_meet { using first_argument_type = V&; using second_argument_type = const V&; using result_type = void; using type = robustness_meet<V>; inline static V identity_element() { return infinity<V>::value(); } void operator()(V& object, const V& operand) const { if(object > operand) { object = operand; } } }; /* * Boost ICL uses operator+ for Combiner functor * (here robustness_join) */ template<class T> struct inverse<robustness_meet<T>> { using type = robustness_join<T>; }; /* * Boost ICL uses operator- for the inverse of Combiner functor * (here robustness_meet) */ template<class T> struct inverse<robustness_join<T>> { using type = robustness_meet<T>; }; } // namespace icl } // namespace boost namespace reelay { template<class V> using infinity = boost::icl::infinity<V>; // aka arbitrarily large finite number template<class T> using interval = boost::icl::interval<T>; /* * This is the base data structure for timed Boolean monitors * It represents a Boolean signal, a map from the time domain to Boolean * domain, but intervals mapped to `false` are not included explicitly. */ template<class T> using interval_set = boost::icl::interval_set<T>; /* * This is the base data structure for timed robustness monitors * It represents a robustness signal, a map from the time domain to a numerical * value domain called robust satisfaction degree. */ template<class T, class V> using robustness_interval_map = boost::icl::interval_map< T, V, boost::icl::total_enricher, std::less, boost::icl::robustness_join>; /* * This is the base data structure for timed unordered data monitors * It represents a BDD signal, a map from the time domain to BDDs, which * encode sets of assignments between a number of data variables and elements. */ template<class T> using data_interval_map = boost::icl::interval_map< T, BDD, boost::icl::total_enricher, std::less, boost::icl::data_join>; } // namespace reelay
5,266
C++
.h
180
26.516667
80
0.715898
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,647
json.hpp
doganulus_reelay/include/reelay/json.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/datafield.hpp" #include "reelay/third_party/nlohmann/json.hpp" #include <string> #include <unordered_set> namespace reelay { using json = nlohmann::json; template<typename T> struct timefield<T, json> { using input_t = json; inline static T get_time(const input_t& container) { return T(container.at("time")); } }; template<> struct datafield<json> { using input_t = json; inline static input_t at(const input_t& container, const std::string& key) { return container[key]; } inline static input_t at(const input_t& container, std::size_t index) { return container[index]; } inline static bool contains(const input_t& container, const std::string& key) { return container.find(key) != container.end(); } inline static bool as_bool(const input_t& container, const std::string& key) { return container.at(key); } inline static int as_integer(const input_t& container, const std::string& key) { return container.at(key); } inline static double as_floating( const input_t& container, const std::string& key) { return container.at(key); } inline static std::string as_string( const input_t& container, const std::string& key) { return container.at(key); } inline static bool contains(const input_t& container, std::size_t index) { return index < container.size(); } inline static bool as_bool(const input_t& container, std::size_t index) { return container.at(index); } inline static int as_integer(const input_t& container, std::size_t index) { return container.at(index); } inline static double as_floating(const input_t& container, std::size_t index) { return container.at(index); } inline static std::string as_string( const input_t& container, std::size_t index) { return container.at(index); } }; } // namespace reelay
2,166
C++
.h
78
24.564103
80
0.706963
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,648
monitors.hpp
doganulus_reelay/include/reelay/monitors.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/formatters/json_formatter.hpp" #include "reelay/monitors/dense_timed_data_monitor.hpp" #include "reelay/monitors/dense_timed_monitor.hpp" #include "reelay/monitors/dense_timed_robustness_0_monitor.hpp" #include "reelay/monitors/discrete_timed_data_monitor.hpp" #include "reelay/monitors/discrete_timed_monitor.hpp" #include "reelay/monitors/discrete_timed_robustness_monitor.hpp" #include "reelay/monitors/monitor.hpp" #include "reelay/networks.hpp" #include "reelay/options.hpp" #include "reelay/parser/ptl_inspector.hpp" #include <exception> namespace reelay { // Helper structs template<typename TimeT> struct dense_timed { template<typename InputT, typename OutputT = json> struct monitor { static dense_monitor_options<TimeT, InputT, OutputT> options() { return dense_monitor_options<TimeT, InputT, OutputT>(); } }; template<typename ValueT> struct robustness { template<typename InputT, typename OutputT = json> struct monitor { static dense_robustness_monitor_options<TimeT, ValueT, InputT, OutputT> options() { return dense_robustness_monitor_options< TimeT, ValueT, InputT, OutputT>(); } }; }; }; template<typename TimeT> struct discrete_timed { template<typename InputT, typename OutputT = json> struct monitor { static discrete_monitor_options<TimeT, InputT, OutputT> options() { return discrete_monitor_options<TimeT, InputT, OutputT>(); } }; template<typename ValueT> struct robustness { template<typename InputT, typename OutputT = json> struct monitor { static discrete_robustness_monitor_options<TimeT, ValueT, InputT, OutputT> options() { return discrete_robustness_monitor_options< TimeT, ValueT, InputT, OutputT>(); } }; }; }; template<typename TimeT, typename InputT, typename OutputT> static monitor<InputT, OutputT> make_monitor( const std::string& pattern, const dense_monitor_options<TimeT, InputT, OutputT>& options) { using time_type = TimeT; using input_type = InputT; using output_type = OutputT; using type = monitor<InputT, OutputT>; auto inspector = reelay::ptl_inspector(); auto inspection = inspector.inspect(pattern); if(reelay::any_cast<bool>(inspection["has_references"])) { return type( dense_timed_data_monitor<time_type, input_type, output_type>::make_shared( pattern, options.get_basic_options())); } return type( dense_timed_monitor<time_type, input_type, output_type>::make_shared( pattern, options.get_basic_options())); } template<typename TimeT, typename ValueT, typename InputT, typename OutputT> static monitor<InputT, OutputT> make_monitor( const std::string& pattern, const dense_robustness_monitor_options<TimeT, ValueT, InputT, OutputT>& options) { using time_type = TimeT; using value_type = ValueT; using input_type = InputT; using output_type = OutputT; using type = monitor<InputT, OutputT>; auto inspector = reelay::ptl_inspector(); auto inspection = inspector.inspect(pattern); if(not reelay::any_cast<bool>(inspection["has_references"])) { return type( dense_timed_robustness_0_monitor< time_type, value_type, input_type, output_type>::make_shared(pattern, options.get_basic_options())); } throw std::invalid_argument( "Error: Data references are not supported for robustness settings."); } template<typename TimeT, typename InputT, typename OutputT> static monitor<InputT, OutputT> make_monitor( const std::string& pattern, const discrete_monitor_options<TimeT, InputT, OutputT>& options) { using time_type = TimeT; using input_type = InputT; using output_type = OutputT; using type = monitor<InputT, OutputT>; auto inspector = reelay::ptl_inspector(); auto inspection = inspector.inspect(pattern); if( reelay::any_cast<bool>(inspection["has_references"]) and options.is_condensing()) { return type( discrete_timed_data_monitor<time_type, input_type, output_type, true>:: make_shared(pattern, options.get_basic_options())); } if( reelay::any_cast<bool>(inspection["has_references"]) and not options.is_condensing()) { return type( discrete_timed_data_monitor<time_type, input_type, output_type, false>:: make_shared(pattern, options.get_basic_options())); } if( not reelay::any_cast<bool>(inspection["has_references"]) and options.is_condensing()) { return type( discrete_timed_monitor<time_type, input_type, output_type, true>:: make_shared(pattern, options.get_basic_options())); } return type( discrete_timed_monitor<time_type, input_type, output_type, false>:: make_shared(pattern, options.get_basic_options())); } template<typename TimeT, typename ValueT, typename InputT, typename OutputT> static monitor<InputT, OutputT> make_monitor( const std::string& pattern, const discrete_robustness_monitor_options<TimeT, ValueT, InputT, OutputT>& options) { using time_type = TimeT; using value_type = ValueT; using input_type = InputT; using output_type = OutputT; using type = monitor<InputT, OutputT>; auto inspector = reelay::ptl_inspector(); auto inspection = inspector.inspect(pattern); if( not reelay::any_cast<bool>(inspection["has_references"]) and options.is_condensing()) { return type(discrete_timed_robustness_monitor< time_type, value_type, input_type, output_type, true>::make_shared(pattern, options.get_basic_options())); } if( not reelay::any_cast<bool>(inspection["has_references"]) and not options.is_condensing()) { return type(discrete_timed_robustness_monitor< time_type, value_type, input_type, output_type, false>::make_shared(pattern, options.get_basic_options())); } throw std::invalid_argument( "Error: Data references are not supported for robustness settings."); } } // namespace reelay
6,477
C++
.h
189
29.417989
80
0.700927
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,649
pybind11.hpp
doganulus_reelay/include/reelay/pybind11.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/datafield.hpp" #include "pybind11/pybind11.h" #include "unordered_set" #include "vector" using namespace pybind11::literals; namespace reelay { using pyobj = pybind11::object; template<typename T> struct timefield<T, pybind11::object> { using input_t = pybind11::object; inline static T get_time(const input_t& container) { return container["time"].cast<T>(); } }; template<> struct datafield<pybind11::object> { using input_t = pybind11::object; static const std::unordered_set<std::string> falsity; inline static input_t at(const input_t& container, const std::string& key) { return container[key.c_str()]; } inline static input_t at(const input_t& container, int index) { return container[pybind11::int_(index)]; } inline static bool contains(const input_t& container, const std::string& key) { return container.contains(key); } inline static bool as_bool(const input_t& container, const std::string& key) { return container[key.c_str()].cast<bool>(); } inline static int as_integer(const input_t& container, const std::string& key) { return container[key.c_str()].cast<long>(); } inline static double as_floating( const input_t& container, const std::string& key) { return container[key.c_str()].cast<double>(); } inline static std::string as_string( const input_t& container, const std::string& key) { return container[key.c_str()].cast<std::string>(); } inline static bool contains(const input_t& container, int index) { throw std::runtime_error(""); } inline static bool as_bool(const input_t& container, int index) { throw std::runtime_error(""); } inline static int as_integer(const input_t& container, int index) { throw std::runtime_error(""); } inline static double as_floating(const input_t& container, int index) { throw std::runtime_error(""); } inline static std::string as_string(const input_t& container, int index) { throw std::runtime_error(""); } template<typename time_t> inline static time_t timestamp(const input_t& container) { return container["time"].cast<time_t>(); } }; const std::unordered_set<std::string> datafield<pyobj>::falsity = { "0", "false", "False"}; } // namespace reelay
2,575
C++
.h
86
26.767442
80
0.702758
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,650
settings.hpp
doganulus_reelay/include/reelay/settings.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/settings/dense_timed/setting.hpp" #include "reelay/settings/dense_timed_data/setting.hpp" #include "reelay/settings/dense_timed_robustness_0/setting.hpp" #include "reelay/settings/discrete_timed/setting.hpp" #include "reelay/settings/discrete_timed_data/setting.hpp" #include "reelay/settings/discrete_timed_robustness/setting.hpp"
614
C++
.h
14
42.285714
70
0.779264
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,651
common.hpp
doganulus_reelay/include/reelay/common.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <string> #include <unordered_map> #define PEGLIB_USE_STD_ANY 0 #include "reelay/third_party/cpp-peglib/peglib.h" namespace reelay { using any = peg::any; template<typename T, typename... Args> inline auto any_cast(Args&&... args) -> decltype(peg::any_cast<T>(std::forward<Args>(args)...)) { return peg::any_cast<T>(std::forward<Args>(args)...); } using kwargs = std::unordered_map<std::string, any>; } // namespace reelay
707
C++
.h
22
30.318182
70
0.713442
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,652
ptl_grammar.hpp
doganulus_reelay/include/reelay/parser/ptl_grammar.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once namespace reelay { struct ptl_grammar { static constexpr auto grammar = R"( Expression <- ExistsExpr / ForallExpr / Implicative ExistsExpr <- EXISTS '[' NonEmptyVarList ']' '.' Implicative ForallExpr <- FORALL '[' NonEmptyVarList ']' '.' Implicative Implicative <- Disjunctive (LIMPLIES Disjunctive)? Disjunctive <- Conjunctive (LOR Conjunctive)* Conjunctive <- SinceExpr (LAND SinceExpr)* SinceExpr <- Unary (SINCE Bound? Unary)? Unary <- NotExpr / PrevExpr / TimedOnceExpr / OnceExpr / TimedHistExpr / HistExpr / Atom / '(' Expression ')' NotExpr <- LNOT Atom / LNOT '(' Expression ')' PrevExpr <- PREV Atom / PREV '(' Expression ')' OnceExpr <- ONCE Atom / ONCE '(' Expression ')' HistExpr <- HIST Atom / HIST '(' Expression ')' TimedOnceExpr <- ONCE Bound Atom / ONCE Bound '(' Expression ')' TimedHistExpr <- HIST Bound Atom / HIST Bound '(' Expression ')' Atom <- CustomPredicate / RecordProposition CustomPredicate <- '$' LCURLY Name RCURLY RecordProposition <- NestedAnyRecordProposition / NestedAllRecordProposition / NestedRecordProposition / SimpleRecordProposition NestedAnyRecordProposition <- PathKey 'any' LCURLY KeyValuePair (COMMA KeyValuePair)* RCURLY NestedAllRecordProposition <- PathKey 'all' LCURLY KeyValuePair (COMMA KeyValuePair)* RCURLY NestedRecordProposition <- PathKey LCURLY KeyValuePair (COMMA KeyValuePair)* RCURLY SimpleRecordProposition <- LCURLY KeyValuePair (COMMA KeyValuePair)* RCURLY KeyValuePair <- RecordProposition/ KeyValuePairTrue / KeyValuePairFalse / KeyValuePairNumber / KeyValuePairString / KeyValuePairEQ / KeyValuePairNE / KeyValuePairLT / KeyValuePairLE / KeyValuePairGT / KeyValuePairGE / KeyValuePairReference / KeyValuePairAnyValue / KeyValueProp /ListingTrue / ListingFalse / ListingNumber / ListingString / ListingReference / ListingAnyValue / ListingEQ / ListingNE / ListingLT / ListingLE / ListingGT / ListingGE ArrayKey <- DOLLAR <[0-9]+> FieldKey <- String PathKey <- (String COLCOL)+ ListingTrue <- ArrayKey ':' TRUE ListingFalse <- ArrayKey ':' FALSE ListingNumber <- ArrayKey ':' Number ListingString <- ArrayKey ':' String ListingAnyValue <- ArrayKey ':' STAR ListingReference <- ArrayKey ':' STAR Name ListingEQ <- ArrayKey EQ Number ListingNE <- ArrayKey NE Number ListingLT <- ArrayKey LT Number ListingLE <- ArrayKey LE Number ListingGT <- ArrayKey GT Number ListingGE <- ArrayKey GE Number KeyValueProp <- FieldKey KeyValuePairTrue <- FieldKey ':' TRUE KeyValuePairFalse <- FieldKey ':' FALSE KeyValuePairNumber <- FieldKey ':' Number KeyValuePairString <- FieldKey ':' String KeyValuePairAnyValue <- FieldKey ':' STAR KeyValuePairReference <- FieldKey ':' STAR Name KeyValuePairEQ <- FieldKey EQ Number KeyValuePairNE <- FieldKey NE Number KeyValuePairLT <- FieldKey LT Number KeyValuePairLE <- FieldKey LE Number KeyValuePairGT <- FieldKey GT Number KeyValuePairGE <- FieldKey GE Number NonEmptyVarList <- Name (COMMA Name)* Bound <- FullBound / LowerBound / UpperBound FullBound <- "[" Number ":" Number "]" LowerBound <- "[" Number ":" 'inf'? "]" UpperBound <- "[" ":" Number "]" String <- SQString / DQString / Name SQString <- SQ <[^']*> SQ DQString <- DQ <[^"]*> DQ Name <- <[_a-zA-Z][_a-zA-Z0-9]*> Number <- <'-'? [0-9]+ ('.' [0-9]+)?> ~EVENT <- < '@' / 'event' > ~PREV <- < 'Y' / 'pre' > ~HIST <- < 'H' / 'historically' > ~ONCE <- < 'P' / 'once' > ~SINCE <- < 'S' / 'since' > ~LOR <- < "||" / 'or' > ~LAND <- < "&&" / 'and' > ~LNOT <- < "!" / 'not' > ~LIMPLIES <- < "->" / 'implies' > ~EXISTS <- < 'E' / 'exists' > ~FORALL <- < 'A' / 'forall' > ~COMMA <- < ',' > ~LPARAM <- < '(' > ~RPARAM <- < ')' > ~LBRACE <- < '[' > ~RBRACE <- < ']' > ~LCURLY <- < '{' > ~RCURLY <- < '}' > ~LT <- < '<' > ~LE <- < '<=' > ~GT <- < '>' > ~GE <- < '>=' > ~EQ <- < '==' > ~NE <- < '!=' > ~DOT <- < '.' > ~STAR <- < '*' > ~AMSAND <- < '&' > ~DOLLAR <- < '$' > ~SQUARE <- < '#' > ~COLCOL <- < '::' > ~SQ <- < "'" > ~DQ <- < '"' > ~TRUE <- < 'true' > ~FALSE <- < 'false' > %whitespace <- [ \t\r\n]* )"; }; } // namespace reelay
4,736
C++
.h
109
38.238532
450
0.618234
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,653
ptl.hpp
doganulus_reelay/include/reelay/parser/ptl.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <iostream> #include <string> #define PEGLIB_USE_STD_ANY 0 #include "reelay/third_party/cpp-peglib/peglib.h" // #include "reelay/parser/ptl_grammar.hpp" // #include "reelay/options.hpp" #include "reelay/settings.hpp" namespace reelay { template <class NetworkT> struct ptl_parser : ptl_grammar{ using time_t = typename NetworkT::time_t; using value_t = typename NetworkT::value_t; using input_t = typename NetworkT::input_t; using output_t = typename NetworkT::output_t; using node_t = typename NetworkT::node_t; using state_t = typename NetworkT::state_t; using network_t = typename NetworkT::type; using node_ptr_t = typename NetworkT::node_ptr_t; using state_ptr_t = typename NetworkT::state_ptr_t; using options_t = typename NetworkT::options_t; using Setting = typename NetworkT::setting_t; peg::parser parser; reelay::kwargs meta; std::vector<state_ptr_t> states = std::vector<state_ptr_t>(); explicit ptl_parser(const reelay::kwargs &mm = reelay::kwargs()) : meta(mm) { parser = peg::parser(grammar); parser.log = [](size_t line, size_t col, const std::string &msg) { std::cerr << line << ":" << col << ": " << msg << std::endl; }; parser["SimpleRecordProposition"] = [&](const peg::SemanticValues &sv) { if (sv.size() > 1) { std::vector<node_ptr_t> args; for (size_t i = 0; i < sv.size(); i++) { node_ptr_t child = reelay::any_cast<node_ptr_t>(sv[i]); args.push_back(child); } reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("atomic_map", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = reelay::any_cast<node_ptr_t>(sv[0]); return child; } }; // parser["NestedRecordProposition"] = [&](const peg::SemanticValues &sv) { // auto path = reelay::any_cast<std::vector<std::string>>(sv[0]); // std::vector<state_ptr_t> args; // for (size_t i = 1; i < sv.size(); i++) { // node_ptr_t child = reelay::any_cast<node_ptr_t>(sv[i]); // args.push_back(std::static_pointer_cast<state_t>(child)); // } // reelay::kwargs kw = {{"args", args}, {"path", path}}; // kw.insert(meta.begin(), meta.end()); // auto expr = Setting::make_state("atomic_nested", kw); // this->states.push_back(expr); // return std::static_pointer_cast<node_t>(expr); // }; // parser["NestedAnyRecordProposition"] = [&](const peg::SemanticValues &sv) { // auto path = reelay::any_cast<std::vector<std::string>>(sv[0]); // std::vector<state_ptr_t> args; // for (size_t i = 1; i < sv.size(); i++) { // node_ptr_t child = reelay::any_cast<node_ptr_t>(sv[i]); // args.push_back(std::static_pointer_cast<state_t>(child)); // } // reelay::kwargs kw = {{"args", args}, {"path", path}}; // kw.insert(meta.begin(), meta.end()); // auto expr = Setting::make_state("atomic_nested_any", kw); // this->states.push_back(expr); // return std::static_pointer_cast<node_t>(expr); // }; // parser["NestedAllRecordProposition"] = [&](const peg::SemanticValues &sv) { // auto path = reelay::any_cast<std::vector<std::string>>(sv[0]); // std::vector<state_ptr_t> args; // for (size_t i = 1; i < sv.size(); i++) { // node_ptr_t child = reelay::any_cast<node_ptr_t>(sv[i]); // args.push_back(std::static_pointer_cast<state_t>(child)); // } // reelay::kwargs kw = {{"args", args}, {"path", path}}; // kw.insert(meta.begin(), meta.end()); // auto expr = Setting::make_state("atomic_nested_all", kw); // this->states.push_back(expr); // return std::static_pointer_cast<node_t>(expr); // }; parser["KeyValueProp"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); reelay::kwargs kw = {{"key", keys[0]}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_prop", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairTrue"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); reelay::kwargs kw = {{"key", keys[0]}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_true", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairFalse"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); reelay::kwargs kw = {{"key", keys[0]}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_false", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairNumber"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_number", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairString"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_string", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairEQ"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_eq", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairNE"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_ne", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairGE"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_ge", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairGT"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_gt", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairLE"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_le", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairLT"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_lt", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairAnyValue"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); reelay::kwargs kw = {{"key", keys[0]}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_any", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["KeyValuePairReference"] = [&](const peg::SemanticValues &sv) { auto keys = reelay::any_cast<std::vector<std::string>>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", keys[0]}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("mapping_ref", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ArrayKey"] = [&](const peg::SemanticValues &sv) { auto index = std::atoi(sv.token().c_str()); return index; }; parser["FieldKey"] = [&](const peg::SemanticValues &sv) { auto keys = std::vector<std::string>(); for (std::size_t i = 0; i < sv.size(); i++) { keys.push_back(reelay::any_cast<std::string>(sv[i])); } return keys; }; parser["ListingTrue"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); reelay::kwargs kw = {{"key", index}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_true", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingFalse"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); reelay::kwargs kw = {{"key", index}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_false", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingNumber"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_number", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingGE"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_ge", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingGT"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_gt", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingLE"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_le", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingLT"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_lt", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingString"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_string", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingAnyValue"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); reelay::kwargs kw = {{"key", index}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_any", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["ListingReference"] = [&](const peg::SemanticValues &sv) { auto index = reelay::any_cast<int>(sv[0]); auto cstr = reelay::any_cast<std::string>(sv[1]); reelay::kwargs kw = {{"key", index}, {"constant", cstr}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("listing_ref", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; // parser["CustomPredicate"] = [&](const peg::SemanticValues &sv) { // auto name = any_cast<std::string>(sv[0]); // auto func = meta[name]; // reelay::kwargs kw = {{"function", func}}; // kw.insert(meta.begin(), meta.end()); // auto expr = Setting::make_state("predicate", kw); // this->states.push_back(expr); // return std::static_pointer_cast<node_t>(expr); // }; parser["ExistsExpr"] = [&](const peg::SemanticValues &sv) { auto vars = any_cast<std::vector<std::string>>(sv[0]); auto child = any_cast<node_ptr_t>(sv[1]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}, {"vars", vars}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("exists", kw); return std::static_pointer_cast<node_t>(expr); }; parser["ForallExpr"] = [&](const peg::SemanticValues &sv) { auto vars = any_cast<std::vector<std::string>>(sv[0]); auto child = any_cast<node_ptr_t>(sv[1]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}, {"vars", vars}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("forall", kw); return std::static_pointer_cast<node_t>(expr); }; parser["NotExpr"] = [&](const peg::SemanticValues &sv) { // Rule: NotExpr <- LNOT Expression node_ptr_t child = any_cast<node_ptr_t>(sv[0]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("negation", kw); return std::static_pointer_cast<node_t>(expr); }; parser["Implicative"] = [&](const peg::SemanticValues &sv) { // Rule: if (sv.size() > 1) { std::vector<node_ptr_t> args; for (size_t i = 0; i < sv.size(); i++) { node_ptr_t child = any_cast<node_ptr_t>(sv[i]); args.push_back(child); } reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("implication", kw); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); return child; } }; parser["Disjunctive"] = [&](const peg::SemanticValues &sv) { // Rule: if (sv.size() > 1) { std::vector<node_ptr_t> args; for (size_t i = 0; i < sv.size(); i++) { node_ptr_t child = any_cast<node_ptr_t>(sv[i]); args.push_back(child); } reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("disjunction", kw); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); return child; } }; parser["Conjunctive"] = [&](const peg::SemanticValues &sv) { // Rule: if (sv.size() > 1) { std::vector<node_ptr_t> args; for (size_t i = 0; i < sv.size(); i++) { node_ptr_t child = any_cast<node_ptr_t>(sv[i]); args.push_back(child); } reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("conjunction", kw); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); return child; } }; parser["PrevExpr"] = [&](const peg::SemanticValues &sv) { // Rule: node_ptr_t child = any_cast<node_ptr_t>(sv[0]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("previous", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["OnceExpr"] = [&](const peg::SemanticValues &sv) { // Rule: node_ptr_t child = any_cast<node_ptr_t>(sv[0]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("past_sometime", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["TimedOnceExpr"] = [&](const peg::SemanticValues &sv) { std::pair<float, float> bound = any_cast<std::pair<float, float>>(sv[0]); node_ptr_t child = any_cast<node_ptr_t>(sv[1]); time_t lbound = time_t(std::get<0>(bound)); time_t ubound = time_t(std::get<1>(bound)); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}, {"lbound", lbound}, {"ubound", ubound}}; kw.insert(meta.begin(), meta.end()); state_ptr_t expr; if (ubound > 0) { expr = Setting::make_state("past_sometime_bounded", kw); } else { expr = Setting::make_state("past_sometime_bounded_half", kw); } this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["HistExpr"] = [&](const peg::SemanticValues &sv) { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("past_always", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["TimedHistExpr"] = [&](const peg::SemanticValues &sv) { std::pair<float, float> bound = any_cast<std::pair<float, float>>(sv[0]); node_ptr_t child = any_cast<node_ptr_t>(sv[1]); time_t lbound = time_t(std::get<0>(bound)); time_t ubound = time_t(std::get<1>(bound)); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}, {"lbound", lbound}, {"ubound", ubound}}; kw.insert(meta.begin(), meta.end()); state_ptr_t expr; if (ubound > 0) { expr = Setting::make_state("past_always_bounded", kw); } else { expr = Setting::make_state("past_always_bounded_half", kw); } this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["SinceExpr"] = [&](const peg::SemanticValues &sv) { if (sv.size() == 3) { node_ptr_t left = any_cast<node_ptr_t>(sv[0]); std::pair<float, float> bound = any_cast<std::pair<float, float>>(sv[1]); node_ptr_t right = any_cast<node_ptr_t>(sv[2]); time_t lbound = time_t(std::get<0>(bound)); time_t ubound = time_t(std::get<1>(bound)); auto args = std::vector<node_ptr_t>({left, right}); reelay::kwargs kw = {{"args", args}, {"lbound", lbound}, {"ubound", ubound}}; kw.insert(meta.begin(), meta.end()); state_ptr_t expr; if (ubound > 0){ expr = Setting::make_state("since_bounded", kw); } else { expr = Setting::make_state("since_bounded_half", kw); } this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); } else if (sv.size() == 2) { node_ptr_t left = any_cast<node_ptr_t>(sv[0]); node_ptr_t right = any_cast<node_ptr_t>(sv[1]); auto args = std::vector<node_ptr_t>({left, right}); reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("since", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); return child; } }; parser["FullBound"] = [](const peg::SemanticValues &sv) { float l = std::stof(any_cast<std::string>(sv[0])); float u = std::stof(any_cast<std::string>(sv[1])); return std::make_pair(l, u); }; parser["LowerBound"] = [](const peg::SemanticValues &sv) { float l = std::stof(any_cast<std::string>(sv[0])); return std::make_pair(l, 0.0f); }; parser["UpperBound"] = [](const peg::SemanticValues &sv) { float u = std::stof(any_cast<std::string>(sv[0])); return std::make_pair(0.0f, u); }; parser["NonEmptyVarList"] = [&](const peg::SemanticValues &sv) { auto vlist = std::vector<std::string>(); for (std::size_t i = 0; i < sv.size(); i++) { auto child = reelay::any_cast<std::string>(sv[i]); vlist.push_back(child); } return vlist; }; parser["PathKey"] = [](const peg::SemanticValues &sv) { std::vector<std::string> path; for (std::size_t i = 0; i < sv.size(); i++) { path.push_back(any_cast<std::string>(sv[i])); } return path; }; parser["Name"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["Number"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["SQString"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["DQString"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser.enable_packrat_parsing(); // Enable packrat parsing. } network_t parse(const std::string &pattern, const options_t& options = options_t()) { node_ptr_t root; parser.parse(pattern.c_str(), root); return network_t(root, states, options); } std::shared_ptr<network_t> make_shared(const std::string &pattern, const options_t& options = options_t()) { node_ptr_t root; parser.parse(pattern.c_str(), root); return std::make_shared<network_t>(root, states, options); } }; } // namespace reelay
24,359
C++
.h
545
37.715596
110
0.584687
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,654
regex.hpp
doganulus_reelay/include/reelay/parser/regex.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <iostream> #include <string> #define PEGLIB_USE_STD_ANY 0 #include "reelay/third_party/peglib.h" #include "reelay/networks.hpp" #include "reelay/settings.hpp" namespace reelay { template <class Setting> struct regex_parser { using time_t = typename Setting::time_t; using input_t = typename Setting::input_t; using output_t = typename Setting::output_t; using function_t = typename Setting::function_t; using node_t = typename Setting::node_t; using state_t = typename Setting::state_t; using network_t = typename Setting::network_t; using node_ptr_t = typename Setting::node_ptr_t; using state_ptr_t = typename Setting::state_ptr_t; static constexpr auto grammar = R"( Expression <- Disjunctive Disjunctive <- Conjunctive (REG_OR Conjunctive)* Conjunctive <- SequenceExpr (REG_AND SequenceExpr)* SequenceExpr <- RegularUnary (REG_CAT? RegularUnary)* RegularUnary <- RegularStar / RegularPlus / RegularOption / RegularBounded /BooleanExpression / RegularGrouping RegularStar <- BooleanExpression STAR / LPARAM Expression RPARAM STAR RegularPlus <- BooleanExpression PLUS / LPARAM Expression RPARAM PLUS RegularOption <- BooleanExpression QMARK / LPARAM Expression RPARAM QMARK RegularBounded <- BooleanExpression TimeBound / LPARAM Expression RPARAM TimeBound RegularGrouping <- LPARAM Expression RPARAM BooleanExpression <- BoolDisjunctive BoolDisjunctive <- BoolConjunctive (LOR BoolConjunctive)* BoolConjunctive <- BooleanUnary (LAND BooleanUnary)* BooleanUnary <- BoolNegative / BooleanAtom / LPARAM BooleanExpression RPARAM BoolNegative <- LNOT BooleanAtom / LNOT LPARAM BooleanExpression RPARAM BooleanAtom <- RecordProposition / AnyRecord AnyRecord <- LCURLY STAR RCURLY RecordProposition <- LCURLY NonEmptyKeyValuePairs RCURLY NonEmptyKeyValuePairs <- KeyValuePair (COMMA KeyValuePair)* FieldKey <- Name (DOT Name)* FieldValue <- Bool / SQString / DQString / Name / Number / VariableRef / AnyValue KeyValuePair <- KeyValuePairST / KeyValuePairEQ / KeyValuePairNE / KeyValuePairLT / KeyValuePairLE / KeyValuePairGT / KeyValuePairGE KeyValuePairST <- FieldKey ':' FieldValue KeyValuePairEQ <- FieldKey '==' Number KeyValuePairNE <- FieldKey '!=' Number KeyValuePairLT <- FieldKey '<' Number KeyValuePairLE <- FieldKey '<=' Number KeyValuePairGT <- FieldKey '>' Number KeyValuePairGE <- FieldKey '>=' Number AnyValue <- STAR VariableRef <- STAR Name TimeBound <- FullBound / LowerBound / UpperBound FullBound <- "[" Number ":" Number "]" LowerBound <- "[" Number ":" 'inf'? "]" UpperBound <- "[" ":" Number "]" ~REG_OR <- < "|" / 'or'> ~REG_AND <- < "&" / 'and'> ~REG_CAT <- < ';' > ~LOR <- < "||" > ~LAND <- < "&&" > ~LNOT <- < "!" > ~LIMPLIES <- < "->" / 'implies' > ~COMMA <- < ',' > ~LPARAM <- < '(' > ~RPARAM <- < ')' > ~LBRACE <- < '[' > ~RBRACE <- < ']' > ~LCURLY <- < '{' > ~RCURLY <- < '}' > ~DOT <- < '.' > ~THREEDOT <- < '...' > ~STAR <- < '*' > ~PLUS <- < '+' > ~QMARK <- < '?' > ~AMSAND <- < '&' > ~DOLLAR <- < '$' > ~SQUARE <- < '#' > Name <- <[_a-zA-Z][_a-zA-Z0-9]*> SQString <- "'" < [^']* > "'" DQString <- '"' < [^"]* > '"' Number <- <'-'? [0-9]+ ('.' [0-9]+)?> Bool <- TRUE / FALSE ~TRUE <- < 'true'> ~FALSE <- < 'false'> %whitespace <- [ \t\r\n]* )"; peg::parser parser; reelay::kwargs meta; std::vector<state_ptr_t> states = std::vector<state_ptr_t>(); explicit regex_parser(const reelay::kwargs &kw = reelay::kwargs()) : meta(kw) { parser = peg::parser(grammar); parser.log = [](size_t line, size_t col, const std::string &msg) { std::cerr << line << ":" << col << ": " << msg << std::endl; }; parser["RecordProposition"] = [&](const peg::SemanticValues &sv) { auto fields = any_cast<std::vector< std::pair<std::string, std::pair<std::string, std::string>>>>(sv[0]); reelay::kwargs kw = {{"fields", fields}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_state("record", kw); this->states.push_back(expr); return std::static_pointer_cast<node_t>(expr); }; parser["NonEmptyKeyValuePairs"] = [&](const peg::SemanticValues &sv) { auto keyvals = std::vector< std::pair<std::string, std::pair<std::string, std::string>>>(); for (std::size_t i = 0; i < sv.size(); i++) { auto child = any_cast< std::pair<std::string, std::pair<std::string, std::string>>>(sv[i]); keyvals.push_back(child); } return keyvals; }; parser["VariableRef"] = [&](const peg::SemanticValues &sv) { return std::pair<std::string, std::string>("variable_ref", any_cast<std::string>(sv[0])); }; parser["UnnamedRef"] = [&](const peg::SemanticValues &) { return std::pair<std::string, std::string>("ignore_field",""); }; parser["FieldKey"] = [&](const peg::SemanticValues &sv) { auto keys = std::vector<std::string>(); for (std::size_t i = 0; i < sv.size(); i++) { keys.push_back(any_cast<std::string>(sv[i])); } return keys; }; parser["KeyValuePair"] = [&](const peg::SemanticValues &sv) { auto key_path = any_cast<std::vector<std::string>>(sv[0]); auto value = any_cast<std::pair<std::string, std::string>>(sv[1]); auto key = key_path[0]; for (std::size_t i = 1; i < key_path.size(); i++) { key += '/'+ key_path[i]; } return std::pair<std::string, std::pair<std::string, std::string>>(key, value); }; parser["BoolNegative"] = [&](const peg::SemanticValues &sv) { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); auto args = std::vector<node_ptr_t>({child}); reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("negation", kw); return std::static_pointer_cast<node_t>(expr); }; parser["BoolDisjunctive"] = [&](const peg::SemanticValues &sv) { // Rule: if (sv.size() > 1) { std::vector<node_ptr_t> args; for (size_t i = 0; i < sv.size(); i++) { node_ptr_t child = any_cast<node_ptr_t>(sv[i]); args.push_back(child); } reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("disjunction", kw); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); return child; } }; parser["BoolConjunctive"] = [&](const peg::SemanticValues &sv) { // Rule: if (sv.size() > 1) { std::vector<node_ptr_t> args; for (size_t i = 0; i < sv.size(); i++) { node_ptr_t child = any_cast<node_ptr_t>(sv[i]); args.push_back(child); } reelay::kwargs kw = {{"args", args}}; kw.insert(meta.begin(), meta.end()); auto expr = Setting::make_node("conjunction", kw); return std::static_pointer_cast<node_t>(expr); } else { node_ptr_t child = any_cast<node_ptr_t>(sv[0]); return child; } }; parser["FullBound"] = [](const peg::SemanticValues &sv) { float l = std::stof(any_cast<std::string>(sv[0])); float u = std::stof(any_cast<std::string>(sv[1])); return std::make_pair(l, u); }; parser["LowerBound"] = [](const peg::SemanticValues &sv) { float l = std::stof(any_cast<std::string>(sv[0])); return std::make_pair(l, 0.0f); }; parser["UpperBound"] = [](const peg::SemanticValues &sv) { float u = std::stof(any_cast<std::string>(sv[0])); return std::make_pair(0.0f, u); }; parser["Name"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["SQString"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["DQString"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["Number"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser["Bool"] = [](const peg::SemanticValues &sv) { return sv.token(); }; parser.enable_packrat_parsing(); // Enable packrat parsing. } std::shared_ptr<network_t> parse(const std::string &pattern) { node_ptr_t output_func; parser.parse(pattern.c_str(), output_func); auto network = std::make_shared<network_t>(output_func, states); return network; } }; } // namespace reelay
9,016
C++
.h
217
35.304147
136
0.596876
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,655
ptl_inspector.hpp
doganulus_reelay/include/reelay/parser/ptl_inspector.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <iostream> #include <string> #define PEGLIB_USE_STD_ANY 0 #include "reelay/third_party/cpp-peglib/peglib.h" #include "reelay/common.hpp" #include "reelay/parser/ptl_grammar.hpp" namespace reelay { struct ptl_inspector : ptl_grammar { peg::parser parser; reelay::kwargs meta = reelay::kwargs({{"timed", false}, {"has_references", false}}); explicit ptl_inspector() { parser = peg::parser(grammar); parser.log = [](size_t line, size_t col, const std::string &msg) { std::cerr << line << ":" << col << ": " << msg << std::endl; }; parser["KeyValuePairReference"] = [&](const peg::SemanticValues &sv) { this->meta["has_references"] = true; }; parser["ExistsExpr"] = [&](const peg::SemanticValues &sv) { this->meta["has_references"] = true; }; parser["ForallExpr"] = [&](const peg::SemanticValues &sv) { this->meta["has_references"] = true; }; parser["TimedOnceExpr"] = [&](const peg::SemanticValues &sv) { this->meta["timed"] = true; }; parser["TimedHistExpr"] = [&](const peg::SemanticValues &sv) { this->meta["timed"] = true; }; parser["SinceExpr"] = [&](const peg::SemanticValues &sv) { if (sv.size() == 3) { this->meta["timed"] = true; } }; parser.enable_packrat_parsing(); // Enable packrat parsing. } reelay::kwargs inspect(const std::string &pattern) { parser.parse(pattern.c_str()); return this->meta; } }; } // namespace reelay
1,769
C++
.h
52
29.75
74
0.633314
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,656
discrete_timed_data_network.hpp
doganulus_reelay/include/reelay/networks/discrete_timed_data_network.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "string" // #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" #include "reelay/parser/ptl.hpp" #include "reelay/settings/discrete_timed_data/setting.hpp" #include "reelay/unordered_data.hpp" // #include "reelay/options.hpp" namespace reelay { template <typename T, typename X> struct discrete_timed_data_network : public discrete_timed_state<X, data_set_t, T> { using time_t = T; using input_t = X; using value_t = data_set_t; using output_t = data_set_t; using type = discrete_timed_data_network<time_t, input_t>; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using setting_t = discrete_timed_data_setting::factory<input_t, time_t>; using options_t = basic_options; data_mgr_t manager; node_ptr_t root; std::vector<state_ptr_t> states; time_t current = -1; discrete_timed_data_network(const data_mgr_t mgr, const node_ptr_t &n, const std::vector<state_ptr_t> &ss) : manager(mgr), root(n), states(ss) {} discrete_timed_data_network( const node_ptr_t &n, const std::vector<state_ptr_t> &ss, const options_t &options) : discrete_timed_data_network(options.get_data_manager(), n, ss) {} time_t now() const { return current; } void update(const input_t &args, time_t tn) override { for (const auto &state : this->states) { state->update(args, tn); } } output_t output(time_t tn) override { return root->output(tn); } output_t update(const input_t &args) { current = current + time_t(1); this->update(args, current); return root->output(current); } output_t output() { return output(current); } static type make( const std::string &pattern, const options_t &options = options_t()) { // // Workaround until new parser auto manager = options.get_data_manager(); kwargs kw = {{"manager", manager}}; auto parser = ptl_parser<type>(kw); return parser.parse(pattern, options); } static std::shared_ptr<type> make_shared( const std::string &pattern, const options_t &options = options_t()) { // // Workaround until new parser auto manager = options.get_data_manager(); kwargs kw = {{"manager", manager}}; auto parser = ptl_parser<type>(kw); return parser.make_shared(pattern, options); } }; } // namespace reelay
2,814
C++
.h
80
31.5
75
0.686969
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,657
discrete_timed_network.hpp
doganulus_reelay/include/reelay/networks/discrete_timed_network.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "string" // #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" #include "reelay/parser/ptl.hpp" #include "reelay/settings/discrete_timed/setting.hpp" // #include "reelay/options.hpp" namespace reelay { template <typename T, typename X> struct discrete_timed_network : public discrete_timed_state<X, bool, T> { using time_t = T; using value_t = bool; using input_t = X; using output_t = bool; using type = discrete_timed_network<time_t, input_t>; using factory = discrete_timed_setting::factory<input_t, time_t>; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using setting_t = discrete_timed_setting::factory<input_t, time_t>; using options_t = basic_options; node_ptr_t root; std::vector<state_ptr_t> states; time_t current = -1; discrete_timed_network() {} discrete_timed_network(const node_ptr_t& n, const std::vector<state_ptr_t>& ss) : root(n), states(ss) {} discrete_timed_network(const node_ptr_t& n, const std::vector<state_ptr_t>& ss, const options_t& options) : discrete_timed_network(n, ss) {} time_t now() const { return current; } void update(const input_t& args, time_t tn) override { for (const auto& state : this->states) { state->update(args, tn); } } output_t output(time_t tn) override { return root->output(tn); } output_t update(const input_t& args) { current = current + time_t(1); this->update(args, current); return root->output(current); } output_t output() { return output(current); } static type make(const std::string& pattern, const options_t& options = options_t()) { auto parser = ptl_parser<type>(); return parser.parse(pattern, options); } static std::shared_ptr<type> make_shared( const std::string& pattern, const options_t& options = options_t()) { auto parser = ptl_parser<type>(); return parser.make_shared(pattern, options); } }; } // namespace reelay
2,527
C++
.h
69
32.15942
75
0.672959
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,658
basic_structure.hpp
doganulus_reelay/include/reelay/networks/basic_structure.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "memory" #include "vector" namespace reelay { template<typename OutputT, typename TimeT> struct discrete_timed_node { virtual ~discrete_timed_node() {} virtual OutputT output(TimeT) = 0; }; template<typename OutputT, typename TimeT> struct dense_timed_node { virtual ~dense_timed_node() {} virtual OutputT output(TimeT, TimeT) = 0; }; template<typename InputT, typename OutputT, typename TimeT> struct discrete_timed_state : discrete_timed_node<OutputT, TimeT> { virtual ~discrete_timed_state() {} virtual OutputT output(TimeT) override = 0; virtual void update(const InputT&, TimeT) = 0; }; template<typename InputT, typename OutputT, typename TimeT> struct dense_timed_state : dense_timed_node<OutputT, TimeT> { virtual ~dense_timed_state() {} virtual OutputT output(TimeT, TimeT) override = 0; virtual void update(const InputT&, const InputT&, TimeT, TimeT) = 0; }; } // namespace reelay
1,192
C++
.h
34
33.058824
70
0.746957
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,659
dense_timed_robustness_0_network.hpp
doganulus_reelay/include/reelay/networks/dense_timed_robustness_0_network.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <memory> #include <string> // #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/parser/ptl.hpp" // #include "reelay/networks/basic_structure.hpp" #include "reelay/settings/dense_timed_robustness_0/setting.hpp" // #include "reelay/options.hpp" namespace reelay { template <typename T, typename V, typename X> struct dense_timed_robustness_0_network : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using value_t = V; using base_t = reelay::robustness_interval_map<time_t, value_t>; using input_t = X; using output_t = base_t; using type = dense_timed_robustness_0_network<time_t, value_t, input_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<base_t, time_t>; using state_t = dense_timed_state<input_t, base_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using setting_t = dense_timed_robustness_0_setting::factory<input_t, value_t, time_t>; using options_t = basic_options; node_ptr_t root; std::vector<state_ptr_t> states; input_t prevargs = input_t{}; time_t previous = 0; // Time Zero time_t current = 0; // Time Zero time_t now() const { return current; } dense_timed_robustness_0_network( const node_ptr_t &n, const std::vector<state_ptr_t> &ss) : root(n), states(ss) {} dense_timed_robustness_0_network( const node_ptr_t &n, const std::vector<state_ptr_t> &ss, const options_t &options) : dense_timed_robustness_0_network(n, ss) {} void update( const input_t &pargs, const input_t &args, time_t previous, time_t now) override { for (const auto &state : this->states) { state->update(pargs, args, previous, now); } } base_t output(time_t previous, time_t now) override { return root->output(previous, now); } base_t update(const input_t &args) { previous = current; current = timefield<time_t, input_t>::get_time(args); this->update(prevargs, args, previous, current); prevargs = args; return output(previous, current); } base_t output() { return output(previous, current); } static type make( const std::string &pattern, const options_t &options = options_t()) { auto parser = ptl_parser<type>(); return parser.parse(pattern, options); } static std::shared_ptr<type> make_shared( const std::string &pattern, const options_t &options = options_t()) { auto parser = ptl_parser<type>(); return parser.make_shared(pattern, options); } }; } // namespace reelay
2,972
C++
.h
82
32.597561
88
0.690534
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,660
dense_timed_network.hpp
doganulus_reelay/include/reelay/networks/dense_timed_network.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <memory> #include <string> // #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" #include "reelay/parser/ptl.hpp" #include "reelay/settings/dense_timed/setting.hpp" // #include "reelay/options.hpp" namespace reelay { template<typename T, typename X> struct dense_timed_network : public dense_timed_state<X, interval_set<T>, T> { using time_t = T; using value_t = bool; using base_t = reelay::interval_set<time_t>; using input_t = X; using output_t = base_t; using type = dense_timed_network<time_t, input_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; using node_t = reelay::dense_timed_node<output_t, time_t>; using state_t = reelay::dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using setting_t = dense_timed_setting::factory<input_t, time_t>; using options_t = basic_options; node_ptr_t root; std::vector<state_ptr_t> states; input_t prevargs = input_t{}; time_t previous = 0; // Time Zero time_t current = 0; // Time Zero dense_timed_network(const node_ptr_t& n, const std::vector<state_ptr_t>& ss) : root(n), states(ss) { } dense_timed_network( const node_ptr_t& n, const std::vector<state_ptr_t>& ss, const options_t& options) : dense_timed_network(n, ss) { } time_t now() const { return current; } void update( const input_t& pargs, const input_t& args, time_t tp, time_t tn) override { for(const auto& state : this->states) { state->update(pargs, args, tp, tn); } } output_t output(time_t tp, time_t tn) override { return root->output(tp, tn); } output_t update(const input_t& args) { previous = current; current = timefield<time_t, input_t>::get_time(args); this->update(prevargs, args, previous, current); prevargs = args; return this->output(previous, current); } output_t output() { return output(previous, current); } static type make( const std::string& pattern, const options_t& options = options_t()) { // // Workaround until new parser kwargs kw; if(options.get_interpolation() == piecewise::constant) { kw["order"] = 0; } else if(options.get_interpolation() == piecewise::linear) { kw["order"] = 1; } auto parser = ptl_parser<type>(kw); return parser.parse(pattern, options); } static std::shared_ptr<type> make_shared( const std::string& pattern, const options_t& options = options_t()) { kwargs kw; if(options.get_interpolation() == piecewise::constant) { kw["order"] = 0; } else if(options.get_interpolation() == piecewise::linear) { kw["order"] = 1; } auto parser = ptl_parser<type>(); return parser.make_shared(pattern, options); } }; } // namespace reelay
3,246
C++
.h
108
26.324074
78
0.66956
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,661
dense_timed_data_network.hpp
doganulus_reelay/include/reelay/networks/dense_timed_data_network.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include <memory> #include <string> // #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" #include "reelay/parser/ptl.hpp" #include "reelay/settings/dense_timed_data/setting.hpp" #include "reelay/unordered_data.hpp" // #include "reelay/options.hpp" namespace reelay { template <typename T, typename X> struct dense_timed_data_network : public dense_timed_state<X, data_interval_map<T>, T> { using time_t = T; using value_t = data_set_t; using base_t = reelay::data_interval_map<time_t>; using input_t = X; using output_t = base_t; using type = dense_timed_data_network<time_t, input_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::data_interval_map<time_t>; using setting_t = dense_timed_data_setting::factory<input_t, time_t>; using options_t = basic_options; data_mgr_t manager; node_ptr_t root; std::vector<state_ptr_t> states; input_t prevargs = input_t{}; time_t previous = 0; // Time Zero time_t current = 0; // Time Zero dense_timed_data_network( const data_mgr_t mgr, const node_ptr_t &n, const std::vector<state_ptr_t> &ss) : manager(mgr), root(n), states(ss) {} dense_timed_data_network( const node_ptr_t &n, const std::vector<state_ptr_t> &ss, const options_t &options) : dense_timed_data_network(options.get_data_manager(), n, ss) {} void update(const input_t &pargs, const input_t &args, time_t tp, time_t tn) override { for (const auto &state : this->states) { state->update(pargs, args, tp, tn); } } time_t now() const { return current; } output_t output(time_t tp, time_t tn) override { return root->output(tp, tn); } output_t update(const input_t &args) { previous = current; current = timefield<time_t, input_t>::get_time(args); this->update(prevargs, args, previous, current); prevargs = args; return this->output(previous, current); } output_t output() { return output(previous, current); } static type make( const std::string &pattern, const options_t &options = options_t()) { // // Workaround until new parser auto manager = options.get_data_manager(); kwargs kw = {{"manager", manager}}; auto parser = ptl_parser<type>(kw); return parser.parse(pattern, options); } static std::shared_ptr<type> make_shared( const std::string &pattern, const options_t &options = options_t()) { // // Workaround until new parser auto manager = options.get_data_manager(); kwargs kw = {{"manager", manager}}; auto parser = ptl_parser<type>(kw); return parser.make_shared(pattern, options); } }; } // namespace reelay
3,227
C++
.h
91
31.681319
78
0.68233
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,662
discrete_timed_robustness_network.hpp
doganulus_reelay/include/reelay/networks/discrete_timed_robustness_network.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "string" // #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" #include "reelay/parser/ptl.hpp" #include "reelay/settings/discrete_timed_robustness/setting.hpp" // #include "reelay/options.hpp" namespace reelay { template <typename T, typename V, typename X> struct discrete_timed_robustness_network : public discrete_timed_state<X, V, T> { using input_t = X; using time_t = T; using value_t = V; using output_t = V; using type = discrete_timed_robustness_network<time_t, value_t, input_t>; using node_t = reelay::discrete_timed_node<value_t, time_t>; using state_t = reelay::discrete_timed_state<input_t, value_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using setting_t = discrete_timed_robustness_setting::factory<input_t, value_t, time_t>; using options_t = basic_options; node_ptr_t root; std::vector<state_ptr_t> states; time_t current = -1; discrete_timed_robustness_network( const node_ptr_t &n, const std::vector<state_ptr_t> &ss) : root(n), states(ss) {} discrete_timed_robustness_network( const node_ptr_t &n, const std::vector<state_ptr_t> &ss, const options_t &options) : discrete_timed_robustness_network(n, ss) {} time_t now() const { return current; } void update(const input_t &args, time_t tn) override { for (const auto &state : this->states) { state->update(args, tn); } } output_t output(time_t tn) override { return root->output(tn); } output_t update(const input_t &args) { current = current + time_t(1); this->update(args, current); return root->output(current); } output_t output() { return output(current); } static type make( const std::string &pattern, const options_t &options = options_t()) { auto parser = ptl_parser<type>(); return parser.parse(pattern, options); } static std::shared_ptr<type> make_shared( const std::string &pattern, const options_t &options = options_t()) { auto parser = ptl_parser<type>(); return parser.make_shared(pattern, options); } }; } // namespace reelay
2,491
C++
.h
71
31.521127
77
0.693078
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,663
atomic_number.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_number.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_number final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; double constant; bool value = false; explicit atomic_number(const key_t &k, const std::string &c_str) : key(k), constant(std::stod(c_str)) {} explicit atomic_number(const kwargs &kw) : atomic_number(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); if (new_data == constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,558
C++
.h
46
30.23913
79
0.682911
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,664
past_sometime_bounded.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/past_sometime_bounded.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct past_sometime_bounded final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; interval_set value = interval_set(); node_ptr_t first; time_t lbound; time_t ubound; past_sometime_bounded(time_t l = 0, time_t u = 0) : lbound(l), ubound(u) {} past_sometime_bounded(const std::vector<node_ptr_t> &args, time_t l = 0, time_t u = 0) : first(args[0]), lbound(l), ubound(u) {} explicit past_sometime_bounded(const kwargs &kw) : past_sometime_bounded( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound")), reelay::any_cast<time_t>(kw.at("ubound"))) {} void update(bool p, time_t now) { if (p) { value = value.add(interval::closed(now + lbound, now + ubound)); value = value - interval_set(interval::right_open(0, now)); } } void update(const input_t&, time_t now) { update(first->output(now), now); } output_t output(time_t now) { return boost::icl::contains(value, now); } }; } // namespace discrete_timed_setting } // namespace reelay
1,978
C++
.h
52
33.826923
78
0.666317
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,665
negation.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/negation.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct negation final : public discrete_timed_node<bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t arg1; explicit negation(const std::vector<node_ptr_t> &args) : arg1(args[0]) {} explicit negation(const kwargs &kw) : negation(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t now) { return not arg1->output(now); } }; } // namespace discrete_timed_setting } // namespace reelay
1,159
C++
.h
31
34.935484
77
0.713518
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,666
since_bounded_half.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/since_bounded_half.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct since_bounded_half final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; interval_set value = interval_set(); node_ptr_t first; node_ptr_t second; time_t lbound; since_bounded_half(const std::vector<node_ptr_t> &args, time_t l=0) : first(args[0]), second(args[1]), lbound(l) {} explicit since_bounded_half(const kwargs &kw) : since_bounded_half( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound"))) {} void update(const input_t&, time_t now) { if (first->output(now) and second->output(now)) { value = value.add( interval::closed(now + lbound, std::numeric_limits<time_t>::max())); value = value - interval_set(interval::right_open(0, now)); } else if (not first->output(now) and second->output(now)) { value = interval_set( interval::closed(now + lbound, std::numeric_limits<time_t>::max())); } else if (first->output(now) and not second->output(now)) { // Laziness -- No need to update // state = state - interval_set(interval::right_open(0, t.now)); } else { value = interval_set(); } } output_t output(time_t now) { return boost::icl::contains(value, now); } }; } // namespace discrete_timed_setting } // namespace reelay
2,182
C++
.h
54
36.277778
78
0.669664
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,667
atomic_lt.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_lt.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_lt final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; double constant; bool value = false; explicit atomic_lt(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_lt(const kwargs &kw) : atomic_lt(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); if (new_data < constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,529
C++
.h
46
29.695652
79
0.681416
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,668
since_bounded.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/since_bounded.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct since_bounded final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; interval_set value = interval_set(); node_ptr_t first; node_ptr_t second; time_t lbound; time_t ubound; since_bounded(time_t l = 0, time_t u = 0) : lbound(l), ubound(u) {} since_bounded(const std::vector<node_ptr_t> &args, time_t l=0, time_t u=0) : first(args[0]), second(args[1]), lbound(l), ubound(u) {} explicit since_bounded(const kwargs &kw) : since_bounded(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound")), reelay::any_cast<time_t>(kw.at("ubound"))) {} inline void update(const input_t&, time_t now) { update(first->output(now), second->output(now), now); } inline void update(bool p1, bool p2, time_t now) { if (p1 and p2) { value = value.add(interval::closed(now + lbound, now + ubound)); value = value - interval_set(interval::right_open(0, now)); } else if (not p1 and p2) { value = interval_set(interval::closed(now + lbound, now + ubound)); } else if (p1 and not p2) { // Laziness -- No need to update // state = state - interval_set(interval::right_open(0, t.now)); } else { value = interval_set(); } } output_t output(time_t now) { return boost::icl::contains(value, now); } }; } // namespace discrete_timed_setting } // namespace reelay
2,299
C++
.h
58
35.37931
79
0.659622
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,669
past_sometime_bounded_half.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/past_sometime_bounded_half.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct past_sometime_bounded_half final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; interval_set value = interval_set(); node_ptr_t first; time_t lbound; past_sometime_bounded_half(const std::vector<node_ptr_t> &args, time_t l=0) : first(args[0]), lbound(l) {} explicit past_sometime_bounded_half(const kwargs &kw) : past_sometime_bounded_half( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound"))) {} void update(const input_t&, time_t now) { if (first->output(now)) { value = value.add( interval::closed(now + lbound, std::numeric_limits<time_t>::max())); value = value - interval_set(interval::right_open(0, now)); } } output_t output(time_t now) { return boost::icl::contains(value, now); } }; } // namespace discrete_timed_setting } // namespace reelay
1,765
C++
.h
46
34.673913
78
0.686217
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,670
since.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/since.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct since final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; node_ptr_t second; bool value = false; explicit since(const std::vector<node_ptr_t> &args) : first(args[0]), second(args[1]) {} explicit since(const kwargs &kw) : since(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t &, time_t now) override { value = second->output(now) || (first->output(now) && value); } output_t output(time_t) override { return value; } }; } // namespace discrete_timed_setting } // namespace reelay
1,295
C++
.h
35
34.171429
74
0.698718
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,671
past_always_bounded_half.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/past_always_bounded_half.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct past_always_bounded_half final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; interval_set value = interval_set(); // true node_ptr_t first; time_t lbound; past_always_bounded_half(const std::vector<node_ptr_t> &args, time_t l=0) : first(args[0]), lbound(l) {} explicit past_always_bounded_half(const kwargs &kw) : past_always_bounded_half( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound"))) {} void update(const input_t&, time_t now) { if (not first->output(now)) { value = value.add( interval::closed(now + lbound, std::numeric_limits<time_t>::max())); value = value - interval_set(interval::right_open(0, now)); } } output_t output(time_t now) { return not boost::icl::contains(value, now); } }; } // namespace discrete_timed_setting } // namespace reelay
1,774
C++
.h
46
34.869565
78
0.683781
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,672
setting.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/setting.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "string" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" // #include "reelay/settings/discrete_timed/atomic_any.hpp" #include "reelay/settings/discrete_timed/atomic_false.hpp" #include "reelay/settings/discrete_timed/atomic_ge.hpp" #include "reelay/settings/discrete_timed/atomic_gt.hpp" #include "reelay/settings/discrete_timed/atomic_le.hpp" #include "reelay/settings/discrete_timed/atomic_lt.hpp" #include "reelay/settings/discrete_timed/atomic_ne.hpp" #include "reelay/settings/discrete_timed/atomic_number.hpp" #include "reelay/settings/discrete_timed/atomic_prop.hpp" #include "reelay/settings/discrete_timed/atomic_string.hpp" #include "reelay/settings/discrete_timed/atomic_true.hpp" #include "reelay/settings/discrete_timed/atomic_map.hpp" #include "reelay/settings/discrete_timed/conjunction.hpp" #include "reelay/settings/discrete_timed/disjunction.hpp" #include "reelay/settings/discrete_timed/implication.hpp" #include "reelay/settings/discrete_timed/negation.hpp" #include "reelay/settings/discrete_timed/past_always.hpp" #include "reelay/settings/discrete_timed/past_sometime.hpp" #include "reelay/settings/discrete_timed/previous.hpp" #include "reelay/settings/discrete_timed/since.hpp" #include "reelay/settings/discrete_timed/past_always_bounded.hpp" #include "reelay/settings/discrete_timed/past_sometime_bounded.hpp" #include "reelay/settings/discrete_timed/since_bounded.hpp" #include "reelay/settings/discrete_timed/past_always_bounded_half.hpp" #include "reelay/settings/discrete_timed/past_sometime_bounded_half.hpp" #include "reelay/settings/discrete_timed/since_bounded_half.hpp" namespace reelay { namespace discrete_timed_setting { template <class X, class T> struct factory { using input_t = X; using time_t = T; using value_t = bool; using output_t = bool; using function_t = std::function<bool(const input_t&)>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; using node_t = reelay::discrete_timed_node<output_t, time_t>; using state_t = reelay::discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; const static output_t top = true; const static output_t bottom = false; static node_ptr_t make_node(const std::string &name, const kwargs &kw) { node_ptr_t result; if (name == "disjunction") { result = std::make_shared<disjunction<input_t, time_t>>(kw); } else if (name == "conjunction") { result = std::make_shared<conjunction<input_t, time_t>>(kw); } else if (name == "negation") { result = std::make_shared<negation<input_t, time_t>>(kw); } else if (name == "implication") { result = std::make_shared<implication<input_t, time_t>>(kw); } else { throw std::invalid_argument( "Unsupported operator for the discrete timed setting"); } return result; } static state_ptr_t make_state(const std::string &name, const kwargs &kw) { state_ptr_t result; if (name == "atomic_map") { result = std::make_shared<atomic_map<input_t, time_t>>(kw); } else if (name == "mapping_prop") { result = std::make_shared<atomic_prop<input_t, time_t>>(kw); } else if (name == "mapping_false") { result = std::make_shared<atomic_false<input_t, time_t>>(kw); } else if (name == "mapping_true") { result = std::make_shared<atomic_true<input_t, time_t>>(kw); } else if (name == "mapping_string") { result = std::make_shared<atomic_string<input_t, time_t>>(kw); } else if (name == "mapping_number") { result = std::make_shared<atomic_number<input_t, time_t>>(kw); } else if (name == "mapping_eq") { result = std::make_shared<atomic_number<input_t, time_t>>(kw); } else if (name == "mapping_ne") { result = std::make_shared<atomic_ne<input_t, time_t>>(kw); } else if (name == "mapping_ge") { result = std::make_shared<atomic_ge<input_t, time_t>>(kw); } else if (name == "mapping_gt") { result = std::make_shared<atomic_gt<input_t, time_t>>(kw); } else if (name == "mapping_le") { result = std::make_shared<atomic_le<input_t, time_t>>(kw); } else if (name == "mapping_lt") { result = std::make_shared<atomic_lt<input_t, time_t>>(kw); } else if (name == "mapping_any") { result = std::make_shared<atomic_any<input_t, time_t>>(kw); } else if (name == "previous") { result = std::make_shared<previous<input_t, time_t>>(kw); } else if (name == "past_sometime") { result = std::make_shared<past_sometime<input_t, time_t>>(kw); } else if (name == "past_always") { result = std::make_shared<past_always<input_t, time_t>>(kw); } else if (name == "since") { result = std::make_shared<since<input_t, time_t>>(kw); } else if (name == "past_sometime_bounded") { result = std::make_shared<past_sometime_bounded<input_t, time_t>>(kw); } else if (name == "past_always_bounded") { result = std::make_shared<past_always_bounded<input_t, time_t>>(kw); } else if (name == "since_bounded") { result = std::make_shared<since_bounded<input_t, time_t>>(kw); } else if (name == "past_sometime_bounded_half") { result = std::make_shared<past_sometime_bounded_half<input_t, time_t>>(kw); } else if (name == "past_always_bounded_half") { result = std::make_shared<past_always_bounded_half<input_t, time_t>>(kw); } else if (name == "since_bounded_half") { result = std::make_shared<since_bounded_half<input_t, time_t>>(kw); } else { throw std::invalid_argument( "Unsupported operator for the discrete timed setting"); } return result; } }; } // namespace discrete_timed_setting } // namespace reelay
6,150
C++
.h
131
42.832061
79
0.684404
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,673
past_always.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/past_always.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct past_always final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; bool value = true; node_ptr_t first; explicit past_always(const std::vector<node_ptr_t> &args) : first(args[0]) {} explicit past_always(const kwargs &kw) : past_always(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t&, time_t now) override { value = first->output(now) && value; } output_t output(time_t) override { return value; } }; } // namespace discrete_timed_setting } // namespace reelay
1,250
C++
.h
33
35.181818
80
0.706224
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,674
past_always_bounded.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/past_always_bounded.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct past_always_bounded final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using interval = reelay::interval<time_t>; using interval_set = reelay::interval_set<time_t>; interval_set value = interval_set(); // true node_ptr_t first; time_t lbound; time_t ubound; past_always_bounded(const std::vector<node_ptr_t> &args, time_t l = 0, time_t u = 0) : first(args[0]), lbound(l), ubound(u) {} explicit past_always_bounded(const kwargs &kw) : past_always_bounded( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound")), reelay::any_cast<time_t>(kw.at("ubound"))) {} void update(const input_t&, time_t now) { if (not first->output(now)) { value = value.add(interval::closed(now + lbound, now + ubound)); value = value - interval_set(interval::right_open(0, now)); } } output_t output(time_t now) { return not boost::icl::contains(value, now); } }; } // namespace discrete_timed_setting } // namespace reelay
1,839
C++
.h
47
35
78
0.671919
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,675
atomic_true.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_true.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_true final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; bool value = false; explicit atomic_true(const key_t &key) : key(key) {} explicit atomic_true(const kwargs &kw) : atomic_true(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } bool new_data = datafield<input_t>::as_bool(args, key); value = new_data; } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,326
C++
.h
39
31.205128
79
0.706991
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,676
atomic_map.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_map.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "string" #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct atomic_map final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; output_t value = false; std::vector<node_ptr_t> mappings; explicit atomic_map(const std::vector<node_ptr_t> &nodeptrs) : mappings(nodeptrs) {} explicit atomic_map(const kwargs &kw) : atomic_map(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t &args, time_t now) override { value = std::all_of(mappings.cbegin(), mappings.cend(), [now](node_ptr_t arg) { return arg->output(now); }); } output_t output(time_t) override { return value; } }; } // namespace discrete_timed_setting } // namespace reelay
1,399
C++
.h
36
35.444444
79
0.694074
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,677
atomic_gt.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_gt.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_gt final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; double constant; bool value = false; explicit atomic_gt(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_gt(const kwargs &kw) : atomic_gt(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); if (new_data > constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace dense_timed_setting } // namespace reelay
1,533
C++
.h
46
29.782609
79
0.681602
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,678
previous.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/previous.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct previous final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; bool prev_value = false; bool value = false; node_ptr_t first; explicit previous(const std::vector<node_ptr_t> &args) : first(args[0]) {} explicit previous(const kwargs &kw) : previous(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t &, time_t now) override { prev_value = value; value = first->output(now); } output_t output(time_t) override { return prev_value; } }; } // namespace discrete_timed_setting } // namespace reelay
1,328
C++
.h
39
31.282051
77
0.706113
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,679
past_sometime.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/past_sometime.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct past_sometime final : public discrete_timed_state<X, bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; bool value = false; node_ptr_t first; explicit past_sometime(const std::vector<node_ptr_t> &args) : first(args[0]) {} explicit past_sometime(const kwargs &kw) : past_sometime(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t&, time_t now) override { value = first->output(now) || value; } output_t output(time_t) override { return value; } }; } // namespace discrete_timed_setting } // namespace reelay
1,265
C++
.h
34
34.382353
82
0.705496
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,680
disjunction.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/disjunction.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct disjunction final : public discrete_timed_node<bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; std::vector<node_ptr_t> args; explicit disjunction(const std::vector<node_ptr_t> &nodeptrs) : args(nodeptrs) {} explicit disjunction(const kwargs &kw) : disjunction(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t now) { return std::any_of(args.cbegin(), args.cend(), [now](node_ptr_t arg) { return arg->output(now); }); } }; } // namespace discrete_timed_setting } // namespace reelay
1,294
C++
.h
35
33.685714
80
0.694712
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,681
atomic_le.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_le.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_le final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; std::string key; double constant; bool value = false; explicit atomic_le(const std::string &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_le(const kwargs &kw) : atomic_le(reelay::any_cast<std::string>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); if (new_data <= constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,548
C++
.h
46
30.108696
79
0.682796
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,682
conjunction.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/conjunction.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct conjunction final : public discrete_timed_node<bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; std::vector<node_ptr_t> args; explicit conjunction(const std::vector<node_ptr_t> &nodeptrs) : args(nodeptrs) {} explicit conjunction(const kwargs &kw) : conjunction(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t now) { return std::all_of(args.cbegin(), args.cend(), [now](node_ptr_t arg) { return arg->output(now); }); } }; } // namespace discrete_timed_setting } // namespace reelay
1,294
C++
.h
35
33.685714
80
0.694712
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,683
atomic_any.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_any.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_any final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; bool value = false; explicit atomic_any(const key_t &key) : key(key) {} explicit atomic_any(const kwargs &kw) : atomic_any(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &args, time_t) override { value = datafield<input_t>::contains(args, key); } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,149
C++
.h
35
30.428571
70
0.715322
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,684
atomic_ge.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_ge.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_ge final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; double constant; bool value = false; explicit atomic_ge(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_ge(const kwargs &kw) : atomic_ge(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); if (new_data >= constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,530
C++
.h
46
29.717391
79
0.680952
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,685
implication.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/implication.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T> struct implication final : public discrete_timed_node<bool, T> { using time_t = T; using input_t = X; using output_t = bool; using node_t = discrete_timed_node<output_t, time_t>; using state_t = discrete_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t arg1; node_ptr_t arg2; explicit implication(const std::vector<node_ptr_t> &args) : arg1(args[0]), arg2(args[1]) {} explicit implication(const kwargs &kw) : implication(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t now) { return not arg1->output(now) or arg2->output(now); } }; } // namespace discrete_timed_setting } // namespace reelay
1,238
C++
.h
35
32.685714
80
0.708893
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,686
atomic_false.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_false.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_false final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; bool value = false; explicit atomic_false(const key_t &key) : key(key) {} explicit atomic_false(const kwargs &kw) : atomic_false(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } bool new_data = datafield<input_t>::as_bool(args, key); value = not new_data; } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,334
C++
.h
39
31.410256
79
0.708041
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,687
atomic_prop.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_prop.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_prop final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; bool value = false; explicit atomic_prop(const key_t &key) : key(key) {} explicit atomic_prop(const kwargs &kw) : atomic_prop(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } bool new_data = datafield<input_t>::as_bool(args, key); value = new_data; } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,326
C++
.h
39
31.205128
79
0.706991
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,688
atomic_ne.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_ne.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_ne final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; double constant; bool value = false; explicit atomic_ne(const key_t &k, const std::string &c_str) : key(k), constant(std::stod(c_str)) {} explicit atomic_ne(const kwargs &kw) : atomic_ne(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); if (new_data != constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,538
C++
.h
46
29.891304
79
0.681326
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,689
atomic_string.hpp
doganulus_reelay/include/reelay/settings/discrete_timed/atomic_string.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace discrete_timed_setting { template <typename X, typename T, typename K = std::string> struct atomic_string final : public discrete_timed_state<X, bool, T> { using key_t = K; using time_t = T; using input_t = X; using output_t = bool; key_t key; std::string constant; bool value = false; explicit atomic_string(const key_t &k, const std::string &c) : key(k), constant(c) {} explicit atomic_string(const kwargs &kw) : atomic_string(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &args, time_t) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } std::string new_data = datafield<input_t>::as_string(args, key); if (new_data == constant) { value = true; } else { value = false; } } output_t output(time_t) override { return value; } }; } // namespace untimed_setting } // namespace reelay
1,547
C++
.h
46
30
79
0.68191
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,690
atomic_number.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_number.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_number final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; double constant; explicit atomic_number(const key_t &k, const std::string &c_str) : key(k), constant(std::stod(c_str)) {} explicit atomic_number(const kwargs &kw) : atomic_number(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); value = value & interval::left_open(previous, now); if (new_data == constant) { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), reelay::infinity<value_t>::value())); } else { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,387
C++
.h
60
35.083333
79
0.66955
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,691
past_sometime_bounded.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/past_sometime_bounded.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct past_sometime_bounded final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; time_t lbound = 0; time_t ubound = 0; interval_map value = interval_map(); past_sometime_bounded(const std::vector<node_ptr_t> &args, time_t l = 0, time_t u = 0) : first(args[0]), lbound(l), ubound(u) { value = interval_map( std::make_pair(interval::left_open(-infinity<time_t>::value(), lbound), -infinity<value_t>::value())); } explicit past_sometime_bounded(const kwargs &kw) : past_sometime_bounded( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound")), reelay::any_cast<time_t>(kw.at("ubound"))) {} void update(const input_t &, const input_t &, time_t previous, time_t now) override { for (const auto &intv : first->output(previous, now)) { value.add(std::make_pair(interval::left_open(intv.first.lower() + lbound, intv.first.upper() + ubound), intv.second)); } value = value & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,380
C++
.h
57
35.561404
80
0.639948
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,692
negation.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/negation.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct negation final : public dense_timed_node<robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t arg1; explicit negation(const std::vector<node_ptr_t> &args) : arg1(args[0]) {} explicit negation(const kwargs &kw) : negation(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t previous, time_t now) { auto result = interval_map(); for (const auto &intv : arg1->output(previous, now)) { result.add(std::make_pair(intv.first, -intv.second)); } return result; } }; } // namespace dense_timed_setting } // namespace reelay
1,534
C++
.h
40
35.35
77
0.703779
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,693
since_bounded_half.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/since_bounded_half.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct since_bounded_half final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; node_ptr_t second; time_t lbound; interval_map value0 = interval_map(); interval_map value1 = interval_map(); interval_map value2 = interval_map(); interval_map last_pair0 = interval_map(); interval_map last_pair1 = interval_map(); interval_map last_pair2 = interval_map(); since_bounded_half(const std::vector<node_ptr_t> &args, time_t l = 0) : first(args[0]), second(args[1]), lbound(l) { value1.add(std::make_pair( interval::closed(-reelay::infinity<time_t>::value(), lbound), -reelay::infinity<value_t>::value())); value2.add(std::make_pair( interval::closed(-reelay::infinity<time_t>::value(), lbound), -reelay::infinity<value_t>::value())); } explicit since_bounded_half(const kwargs &kw) : since_bounded_half( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound"))) {} void update(value_t p1, value_t p2, time_t previous, time_t now) { last_pair0 = interval_map( std::make_pair(interval::left_open(previous, now), std::max(p2, std::min(last_pair0.begin()->second, p1)))); last_pair1 = interval_map(std::make_pair( reelay::interval<time_t>::left_open(previous, now + lbound), -last_pair0.begin()->second)); last_pair2 = interval_map(std::make_pair( interval::left_open(previous + lbound, infinity<value_t>::value()), p2)); value0 = value0 | last_pair0; value1 = value1 | last_pair1; value2 = value2 | last_pair2; } void update(const input_t &, const input_t &, time_t previous, time_t now) override { /* * The following code performs the sychronization between two arbitrary * chunks and calls the update function for each constant period * from past to future. The synchronization algorithm is a variant of * plane sweep algorithms from computational geometry. */ // Sweep line starts from the earliest timepoint in the segment time_t time = previous; auto active1 = first->output(previous, now); auto active2 = second->output(previous, now); auto it1 = active1.begin(); auto it2 = active2.begin(); while (it1 != active1.end() and it2 != active2.end()) { if (it1->first.upper() < it2->first.upper()) { update(it1->second, it2->second, time, it1->first.upper()); time = it1->first.upper(); it1++; } else if (it2->first.upper() < it1->first.upper()) { update(it1->second, it2->second, time, it2->first.upper()); time = it2->first.upper(); it2++; } else { // it1->first.upper() == it2->first.upper() update(it1->second, it2->second, time, it1->first.upper()); time = it1->first.upper(); it1++; it2++; } } value0 = value0 & interval::left_open(previous, infinity<time_t>::value()); value1 = value1 & interval::left_open(previous, infinity<time_t>::value()); value2 = value2 & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { auto negated_value1 = interval_map(); for (const auto &intv : value1) { negated_value1.add(std::make_pair(intv.first, -intv.second)); } return (negated_value1 & interval::left_open(previous, now)) - (value2 & interval::left_open(previous, now)); } }; } // namespace dense_timed_setting } // namespace reelay
4,551
C++
.h
107
37.037383
80
0.651495
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,694
since_bounded.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/since_bounded.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct since_bounded final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; node_ptr_t second; time_t lbound; time_t ubound; interval_map value0 = interval_map(); interval_map value1 = interval_map(); interval_map value2 = interval_map(); interval_map last_pair0 = interval_map(); interval_map last_pair1 = interval_map(); interval_map last_pair2 = interval_map(); since_bounded(const std::vector<node_ptr_t> &args, time_t l = 0, time_t u = 0) : first(args[0]), second(args[1]), lbound(l), ubound(u) { value1.add(std::make_pair( interval::closed(-reelay::infinity<time_t>::value(), lbound), -reelay::infinity<value_t>::value())); value2.add(std::make_pair( interval::closed(-reelay::infinity<time_t>::value(), lbound), -reelay::infinity<value_t>::value())); } explicit since_bounded(const kwargs &kw) : since_bounded(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound")), reelay::any_cast<time_t>(kw.at("ubound"))) {} void update(value_t p1, value_t p2, time_t previous, time_t now) { last_pair0 = interval_map( std::make_pair(interval::left_open(previous, now), std::max(p2, std::min(last_pair0.begin()->second, p1)))); last_pair1 = interval_map(std::make_pair( reelay::interval<time_t>::left_open(previous, now + lbound), -last_pair0.begin()->second)); last_pair2 = interval_map(std::make_pair( interval::left_open(previous + lbound, now + ubound), p2)); value0 = value0 | last_pair0; value1 = value1 | last_pair1; value2 = value2 | last_pair2; } void update(const input_t &, const input_t &, time_t previous, time_t now) override { /* * The following code performs the sychronization between two arbitrary * chunks and calls the update function for each constant period * from past to future. The synchronization algorithm is a variant of * plane sweep algorithms from computational geometry. */ // Sweep line starts from the earliest timepoint in the segment time_t time = previous; auto active1 = first->output(previous, now); auto active2 = second->output(previous, now); auto it1 = active1.begin(); auto it2 = active2.begin(); while (it1 != active1.end() and it2 != active2.end()) { if (it1->first.upper() < it2->first.upper()) { update(it1->second, it2->second, time, it1->first.upper()); time = it1->first.upper(); it1++; } else if (it2->first.upper() < it1->first.upper()) { update(it1->second, it2->second, time, it2->first.upper()); time = it2->first.upper(); it2++; } else { // it1->first.upper() == it2->first.upper() update(it1->second, it2->second, time, it1->first.upper()); time = it1->first.upper(); it1++; it2++; } } value0 = value0 & interval::left_open(previous, infinity<time_t>::value()); value1 = value1 & interval::left_open(previous, infinity<time_t>::value()); value2 = value2 & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { auto negated_value1 = interval_map(); for (const auto &intv : value1) { negated_value1.add(std::make_pair(intv.first, -intv.second)); } return (negated_value1 & interval::left_open(previous, now)) - (value2 & interval::left_open(previous, now)); } }; } // namespace dense_timed_setting } // namespace reelay
4,614
C++
.h
107
37.485981
80
0.648504
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,695
past_sometime_bounded_half.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/past_sometime_bounded_half.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct past_sometime_bounded_half final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; time_t lbound; interval_map value = interval_map(); past_sometime_bounded_half(const std::vector<node_ptr_t> &args, time_t l=0) : first(args[0]), lbound(l) { value = interval_map( std::make_pair(interval::left_open(-infinity<time_t>::value(), lbound), -infinity<value_t>::value())); } explicit past_sometime_bounded_half(const kwargs &kw) : past_sometime_bounded_half( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound"))) {} void update(const input_t &, const input_t &, time_t previous, time_t now) override { for (const auto &intv : first->output(previous, now)) { value.add(std::make_pair(interval::left_open(intv.first.lower() + lbound, infinity<time_t>::value()), intv.second)); } value = value & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,267
C++
.h
54
36.203704
79
0.653321
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,696
since.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/since.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct since final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; node_ptr_t second; interval_map value = interval_map(); interval_map last_pair = interval_map( std::make_pair(interval::left_open(-infinity<time_t>::value(), 0), -infinity<value_t>::value())); explicit since(const std::vector<node_ptr_t> &args) : first(args[0]), second(args[1]) {} explicit since(const kwargs &kw) : since(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(value_t p1, value_t p2, time_t previous, time_t now) { last_pair = interval_map( std::make_pair(interval::left_open(previous, now), std::max(p2, std::min(last_pair.begin()->second, p1)))); value = value | last_pair; value = value & interval::closed(previous, infinity<time_t>::value()); } void update(const input_t&, const input_t&, time_t previous, time_t now) override { /* * The following code performs the sychronization between two arbitrary * chunks and calls the update function for each constant period * from past to future. The synchronization algorithm is a variant of * plane sweep algorithms from computational geometry. */ // Sweep line starts from the earliest timepoint in the segment time_t time = previous; auto active1 = first->output(previous, now); auto active2 = second->output(previous, now); auto it1 = active1.begin(); auto it2 = active2.begin(); while (it1 != active1.end() and it2 != active2.end()) { if (it1->first.upper() < it2->first.upper()) { update(it1->second, it2->second, time, it1->first.upper()); time = it1->first.upper(); it1++; } else if (it2->first.upper() < it1->first.upper()) { update(it1->second, it2->second, time, it2->first.upper()); time = it2->first.upper(); it2++; } else { // it1->first.upper() == it2->first.upper() update(it1->second, it2->second, time, it1->first.upper()); time = it1->first.upper(); it1++; it2++; } } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
3,322
C++
.h
82
34.987805
79
0.647187
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,697
atomic_lt_0.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_lt_0.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_lt_0 final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; double constant; explicit atomic_lt_0(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_lt_0(const kwargs &kw) : atomic_lt_0(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); value = value & interval::left_open(previous, now); value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), constant - new_data)); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,158
C++
.h
53
36.150943
91
0.682455
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,698
past_always_bounded_half.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/past_always_bounded_half.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct past_always_bounded_half final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; time_t lbound; interval_map value; past_always_bounded_half(const std::vector<node_ptr_t> &args, time_t l=0) : first(args[0]), lbound(l) { value = interval_map( std::make_pair(interval::left_open(-infinity<time_t>::value(), lbound), -infinity<value_t>::value())); } explicit past_always_bounded_half(const kwargs &kw) : past_always_bounded_half( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound"))) {} void update(const input_t &, const input_t &, time_t previous, time_t now) override { for (const auto &intv : first->output(previous, now)) { value.add(std::make_pair( interval::left_open(intv.first.lower() + lbound, infinity<time_t>::value()), -intv.second)); } value = value & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { auto negated_value = interval_map(); for (const auto &intv : this->value) { negated_value.add(std::make_pair(intv.first, -intv.second)); } return negated_value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,347
C++
.h
58
35.775862
86
0.668865
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,699
setting.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/setting.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "string" #include "reelay/networks/basic_structure.hpp" // #include "reelay/settings/dense_timed_robustness_0/atomic_any.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_false.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_ge_0.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_gt_0.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_le_0.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_lt_0.hpp" // #include "reelay/settings/dense_timed_robustness_0/atomic_ne.hpp" // #include "reelay/settings/dense_timed_robustness_0/atomic_eq.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_number.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_prop.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_string.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_true.hpp" #include "reelay/settings/dense_timed_robustness_0/atomic_map.hpp" #include "reelay/settings/dense_timed_robustness_0/conjunction.hpp" #include "reelay/settings/dense_timed_robustness_0/disjunction.hpp" #include "reelay/settings/dense_timed_robustness_0/implication.hpp" #include "reelay/settings/dense_timed_robustness_0/negation.hpp" #include "reelay/settings/dense_timed_robustness_0/past_always.hpp" #include "reelay/settings/dense_timed_robustness_0/past_sometime.hpp" #include "reelay/settings/dense_timed_robustness_0/since.hpp" #include "reelay/settings/dense_timed_robustness_0/past_always_bounded.hpp" #include "reelay/settings/dense_timed_robustness_0/past_sometime_bounded.hpp" #include "reelay/settings/dense_timed_robustness_0/since_bounded.hpp" #include "reelay/settings/dense_timed_robustness_0/past_always_bounded_half.hpp" #include "reelay/settings/dense_timed_robustness_0/past_sometime_bounded_half.hpp" #include "reelay/settings/dense_timed_robustness_0/since_bounded_half.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct factory { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; using function_t = std::function<output_t(const input_t &, const input_t &, time_t, time_t)>; static node_ptr_t make_node(const std::string &name, const kwargs &kw) { node_ptr_t result; if (name == "disjunction") { result = std::make_shared<disjunction<input_t, value_t, time_t>>(kw); } else if (name == "conjunction") { result = std::make_shared<conjunction<input_t, value_t, time_t>>(kw); } else if (name == "negation") { result = std::make_shared<negation<input_t, value_t, time_t>>(kw); } else if (name == "implication") { result = std::make_shared<implication<input_t, value_t, time_t>>(kw); } else { throw std::invalid_argument( "Unsupported operator for the dense timed robustness setting"); } return result; } static state_ptr_t make_state(const std::string &name, const kwargs &kw) { state_ptr_t result; if (name == "atomic_map") { result = std::make_shared<atomic_map<input_t, value_t, time_t>>(kw); } else if (name == "mapping_prop") { result = std::make_shared<atomic_prop<input_t, value_t, time_t>>(kw); } else if (name == "mapping_false") { result = std::make_shared<atomic_false<input_t, value_t, time_t>>(kw); } else if (name == "mapping_true") { result = std::make_shared<atomic_true<input_t, value_t, time_t>>(kw); } else if (name == "mapping_string") { result = std::make_shared<atomic_string<input_t, value_t, time_t>>(kw); } else if (name == "mapping_number") { result = std::make_shared<atomic_number<input_t, value_t, time_t>>(kw); } else if (name == "mapping_ge") { result = std::make_shared<atomic_ge_0<input_t, value_t, time_t>>(kw); } else if (name == "mapping_gt") { result = std::make_shared<atomic_gt_0<input_t, value_t, time_t>>(kw); } else if (name == "mapping_le") { result = std::make_shared<atomic_le_0<input_t, value_t, time_t>>(kw); } else if (name == "mapping_lt") { result = std::make_shared<atomic_lt_0<input_t, value_t, time_t>>(kw); } else if (name == "mapping_any") { result = std::make_shared<atomic_any<input_t, value_t, time_t>>(kw); } else if (name == "past_sometime") { result = std::make_shared<past_sometime<input_t, value_t, time_t>>(kw); } else if (name == "past_always") { result = std::make_shared<past_always<input_t, value_t, time_t>>(kw); } else if (name == "since") { result = std::make_shared<since<input_t, value_t, time_t>>(kw); } else if (name == "past_sometime_bounded") { result = std::make_shared<past_sometime_bounded<input_t, value_t, time_t>>(kw); } else if (name == "past_always_bounded") { result = std::make_shared<past_always_bounded<input_t, value_t, time_t>>(kw); } else if (name == "since_bounded") { result = std::make_shared<since_bounded<input_t, value_t, time_t>>(kw); } else if (name == "past_sometime_bounded_half") { result = std::make_shared< past_sometime_bounded_half<input_t, value_t, time_t>>(kw); } else if (name == "past_always_bounded_half") { result = std::make_shared<past_always_bounded_half<input_t, value_t, time_t>>( kw); } else if (name == "since_bounded_half") { result = std::make_shared<since_bounded_half<input_t, value_t, time_t>>(kw); } else { throw std::invalid_argument( "Unsupported operator for the untimed setting"); } return result; } }; } // namespace dense_timed_robustness_0_setting } // namespace reelay
6,401
C++
.h
127
46.007874
82
0.685911
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,700
past_always.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/past_always.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct past_always final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; interval_map value = interval_map(); explicit past_always(const std::vector<node_ptr_t> &args) : first(args[0]) {} explicit past_always(const kwargs &kw) : past_always(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t&, const input_t&, time_t previous, time_t now) override { for (const auto &intv : first->output(previous, now)) { value.add(std::make_pair( interval::left_open(intv.first.lower(), infinity<time_t>::value()), -intv.second)); } value = value & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { auto negated_value = interval_map(); for (const auto &intv : this->value) { negated_value.add(std::make_pair(intv.first, -intv.second)); } return negated_value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,057
C++
.h
52
35.307692
80
0.678894
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,701
past_always_bounded.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/past_always_bounded.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct past_always_bounded final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; time_t lbound; time_t ubound; interval_map value; past_always_bounded(const std::vector<node_ptr_t> &args, time_t l = 0, time_t u = 0) : first(args[0]), lbound(l), ubound(u) { value = interval_map( std::make_pair(interval::left_open(-infinity<time_t>::value(), lbound), -infinity<value_t>::value())); } explicit past_always_bounded(const kwargs &kw) : past_always_bounded( reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args")), reelay::any_cast<time_t>(kw.at("lbound")), reelay::any_cast<time_t>(kw.at("ubound"))) {} void update(const input_t &, const input_t &, time_t previous, time_t now) override { for (const auto &intv : first->output(previous, now)) { value.add(std::make_pair(interval::left_open(intv.first.lower() + lbound, intv.first.upper() + ubound), -intv.second)); } value = value & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { auto negated_value = interval_map(); for (const auto &intv : this->value) { negated_value.add(std::make_pair(intv.first, -intv.second)); } return negated_value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,516
C++
.h
61
35.04918
80
0.640657
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,702
atomic_true.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_true.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_true final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; explicit atomic_true(const key_t &key) : key(key) {} explicit atomic_true(const kwargs &kw) : atomic_true(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } bool new_data = datafield<input_t>::as_bool(args, key); value = value & interval::left_open(previous, now); if (new_data) { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), reelay::infinity<value_t>::value())); } else { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_robustness_0_setting } // namespace reelay
2,227
C++
.h
57
34.701754
79
0.675638
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,703
atomic_map.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_map.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "string" #include "reelay/common.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct atomic_map final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; interval_map value = interval_map(); std::vector<node_ptr_t> mappings; explicit atomic_map(const std::vector<node_ptr_t> &nodeptrs) : mappings(nodeptrs) {} explicit atomic_map(const kwargs &kw) : atomic_map(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t &, const input_t &, time_t previous, time_t now) override { value = mappings[0]->output(previous, now); for (size_t i = 1; i < mappings.size(); i++) { value = value - mappings[i]->output(previous, now); } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
1,801
C++
.h
46
35.804348
79
0.695577
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,704
past_sometime.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/past_sometime.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct past_sometime final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t first; interval_map value = interval_map(); explicit past_sometime(const std::vector<node_ptr_t> &args) : first(args[0]) {} explicit past_sometime(const kwargs &kw) : past_sometime(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} void update(const input_t &, const input_t &, time_t previous, time_t now) override { for (const auto &intv : first->output(previous, now)) { value.add(std::make_pair( interval::left_open(intv.first.lower(), infinity<time_t>::value()), intv.second)); } value = value & interval::left_open(previous, infinity<time_t>::value()); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
1,878
C++
.h
47
36.234043
82
0.690699
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,705
disjunction.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/disjunction.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct disjunction final : public dense_timed_node<robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; std::vector<node_ptr_t> args; explicit disjunction(const std::vector<node_ptr_t> &args) : args(args) {} explicit disjunction(const kwargs &kw) : disjunction(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t previous, time_t now) { auto result = args[0]->output(previous, now); for (size_t i = 1; i < args.size(); i++) { result = result + args[i]->output(previous, now); } return result; } }; } // namespace dense_timed_setting } // namespace reelay
1,562
C++
.h
41
35
80
0.69715
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,706
conjunction.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/conjunction.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct conjunction final : public dense_timed_node<robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; std::vector<node_ptr_t> args; explicit conjunction(const std::vector<node_ptr_t> &args) : args(args) {} explicit conjunction(const kwargs &kw) : conjunction(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t previous, time_t now) { auto result = args[0]->output(previous, now); for (size_t i = 1; i < args.size(); i++) { result = result - args[i]->output(previous, now); } return result; } }; } // namespace dense_timed_setting } // namespace reelay
1,556
C++
.h
40
35.9
80
0.699468
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,707
atomic_any.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_any.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_any final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), reelay::infinity<value_t>::value())); key_t key; explicit atomic_any(const key_t &key) : key(key) {} explicit atomic_any(const kwargs &kw) : atomic_any(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t& pargs, const input_t& args, time_t previous, time_t now) override { bool key_exists = datafield<input_t>::contains(args, key); value = value & interval::left_open(previous, now); if (key_exists) { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), reelay::infinity<value_t>::value())); } else { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_robustness_0_setting } // namespace reelay
2,115
C++
.h
56
33.089286
79
0.668787
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,708
implication.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/implication.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "vector" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T> struct implication final : public dense_timed_node<robustness_interval_map<T, V>, T> { using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; using node_t = dense_timed_node<output_t, time_t>; using state_t = dense_timed_state<input_t, output_t, time_t>; using node_ptr_t = std::shared_ptr<node_t>; using state_ptr_t = std::shared_ptr<state_t>; node_ptr_t arg1; node_ptr_t arg2; explicit implication(const std::vector<node_ptr_t> &args) : arg1(args[0]), arg2(args[1]) {} explicit implication(const kwargs &kw) : implication(reelay::any_cast<std::vector<node_ptr_t>>(kw.at("args"))) {} output_t output(time_t previous, time_t now) { auto negated_arg1 = interval_map(); for (const auto &intv : arg1->output(previous, now)) { negated_arg1.add(std::make_pair(intv.first, -intv.second)); } return negated_arg1 + arg2->output(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
1,634
C++
.h
42
35.809524
80
0.703797
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,709
atomic_false.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_false.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_false final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; explicit atomic_false(const key_t &key) : key(key) {} explicit atomic_false(const kwargs &kw) : atomic_false(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } bool new_data = datafield<input_t>::as_bool(args, key); value = value & interval::left_open(previous, now); if (not new_data) { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), reelay::infinity<value_t>::value())); } else { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_robustness_0_setting } // namespace reelay
2,235
C++
.h
57
34.842105
79
0.676375
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,710
atomic_le_0.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_le_0.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_le_0 final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; double constant; explicit atomic_le_0(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_le_0(const kwargs &kw) : atomic_le_0(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); value = value & interval::left_open(previous, now); value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), constant - new_data)); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,145
C++
.h
54
35.462963
79
0.680154
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,711
atomic_prop.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_prop.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_prop final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; explicit atomic_prop(const key_t &key) : key(key) {} explicit atomic_prop(const kwargs &kw) : atomic_prop(reelay::any_cast<key_t>(kw.at("key"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); value = value & interval::left_open(previous, now); value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), new_data)); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_robustness_0_setting } // namespace reelay
2,002
C++
.h
50
36.24
80
0.693856
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,712
atomic_ge_0.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_ge_0.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_ge_0 final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; double constant; explicit atomic_ge_0(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_ge_0(const kwargs &kw) : atomic_ge_0(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); value = value & interval::left_open(previous, now); value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), new_data - constant)); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,145
C++
.h
54
35.462963
79
0.680154
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,713
atomic_string.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_string.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_string final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; std::string constant; explicit atomic_string(const key_t &k, const std::string &c) : key(k), constant(c) {} explicit atomic_string(const kwargs &kw) : atomic_string(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } std::string new_data = datafield<input_t>::as_string(args, key); value = value & interval::left_open(previous, now); if (new_data == constant) { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), reelay::infinity<value_t>::value())); } else { value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); } } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,375
C++
.h
60
34.9
79
0.66884
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,532,714
atomic_gt_0.hpp
doganulus_reelay/include/reelay/settings/dense_timed_robustness_0/atomic_gt_0.hpp
/* * Copyright (c) 2019-2023 Dogan Ulus * * 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/. */ #pragma once #include "functional" #include "memory" #include "vector" #include "reelay/common.hpp" #include "reelay/datafield.hpp" #include "reelay/intervals.hpp" #include "reelay/networks/basic_structure.hpp" namespace reelay { namespace dense_timed_robustness_0_setting { template <typename X, typename V, typename T, typename K = std::string> struct atomic_gt_0 final : public dense_timed_state<X, robustness_interval_map<T, V>, T> { using key_t = K; using time_t = T; using input_t = X; using value_t = V; using output_t = reelay::robustness_interval_map<time_t, value_t>; using interval = reelay::interval<time_t>; using interval_map = reelay::robustness_interval_map<time_t, value_t>; interval_map value = interval_map( std::make_pair(interval::left_open(0, reelay::infinity<time_t>::value()), -reelay::infinity<value_t>::value())); key_t key; double constant; explicit atomic_gt_0(const key_t &k, const std::string &c) : key(k), constant(std::stod(c)) {} explicit atomic_gt_0(const kwargs &kw) : atomic_gt_0(reelay::any_cast<key_t>(kw.at("key")), reelay::any_cast<std::string>(kw.at("constant"))) {} void update(const input_t &pargs, const input_t &args, time_t previous, time_t now) override { if (not datafield<input_t>::contains(args, key)) { return; // Do nothing if the key does not exist - existing value persists } double new_data = datafield<input_t>::as_floating(args, key); value = value & interval::left_open(previous, now); value.add(std::make_pair( interval::left_open(now, reelay::infinity<time_t>::value()), new_data - constant)); } output_t output(time_t previous, time_t now) override { return value & interval::left_open(previous, now); } }; } // namespace dense_timed_setting } // namespace reelay
2,144
C++
.h
54
35.462963
79
0.680154
doganulus/reelay
33
5
3
MPL-2.0
9/20/2024, 10:43:45 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false