From f97942ca7664947b76f2548128fcaaa788073203 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 15 Jul 2019 14:50:22 +0200 Subject: [PATCH 01/95] [REFACT] events to occasions --- CMakeLists.txt | 10 +-- docs/ClientBase.html | 9 +- docs/CppAPI.html | 21 ++--- docs/Download.html | 9 +- docs/{Event.html => Fact.html} | 90 ++++++++++--------- docs/InstallMementar.html | 9 +- docs/ManagerClient.html | 9 +- ...Publisher.html => OccasionsPublisher.html} | 36 ++++---- ...bscriber.html => OccasionsSubscriber.html} | 66 +++++++------- docs/SetUp.html | 9 +- docs/TimelineManipulator.html | 11 +-- docs/TimelinesManipulator.html | 9 +- docs/construction.html | 9 +- include/mementar/API/EventsPublisher.h | 29 ------ include/mementar/API/{Event.h => Fact.h} | 20 ++--- include/mementar/API/OccasionsPublisher.h | 29 ++++++ ...entsSubscriber.h => OccasionsSubscriber.h} | 22 ++--- include/mementar/API/TimelineManipulator.h | 4 +- include/mementar/RosInterface.h | 4 +- .../core/{Events => Occasions}/IdManager.h | 0 .../OccasionsManager.h} | 12 +-- .../core/{Events => Occasions}/Subscription.h | 2 +- package.xml | 2 +- ...tsPublisher.cpp => OccasionsPublisher.cpp} | 10 +-- ...Subscriber.cpp => OccasionsSubscriber.cpp} | 26 +++--- src/API/TimelineManipulator.cpp | 2 +- src/RosInterface.cpp | 12 +-- .../OccasionsManager.cpp} | 22 ++--- .../{Events => Occasions}/Subscription.cpp | 2 +- src/test/event_sub_pub.cpp | 48 ---------- src/test/occasions_sub_pub.cpp | 48 ++++++++++ 31 files changed, 309 insertions(+), 282 deletions(-) rename docs/{Event.html => Fact.html} (54%) rename docs/{EventsPublisher.html => OccasionsPublisher.html} (67%) rename docs/{EventsSubscriber.html => OccasionsSubscriber.html} (51%) delete mode 100644 include/mementar/API/EventsPublisher.h rename include/mementar/API/{Event.h => Fact.h} (80%) create mode 100644 include/mementar/API/OccasionsPublisher.h rename include/mementar/API/{EventsSubscriber.h => OccasionsSubscriber.h} (51%) rename include/mementar/core/{Events => Occasions}/IdManager.h (100%) rename include/mementar/core/{Events/EventsManager.h => Occasions/OccasionsManager.h} (80%) rename include/mementar/core/{Events => Occasions}/Subscription.h (93%) rename src/API/{EventsPublisher.cpp => OccasionsPublisher.cpp} (56%) rename src/API/{EventsSubscriber.cpp => OccasionsSubscriber.cpp} (67%) rename src/core/{Events/EventsManager.cpp => Occasions/OccasionsManager.cpp} (73%) rename src/core/{Events => Occasions}/Subscription.cpp (95%) delete mode 100644 src/test/event_sub_pub.cpp create mode 100644 src/test/occasions_sub_pub.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b15d50..1e71037 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,8 @@ target_link_libraries(mementar_core_lib ############################## add_library(mementar_events_lib - src/core/Events/Subscription.cpp - src/core/Events/EventsManager.cpp + src/core/Occasions/Subscription.cpp + src/core/Occasions/OccasionsManager.cpp ) target_link_libraries(mementar_events_lib ${catkin_LIBRARIES}) add_dependencies(mementar_events_lib ${catkin_EXPORTED_TARGETS} mementar_gencpp) @@ -128,8 +128,8 @@ add_library(mementar_lib src/API/TimelinesManipulator.cpp src/API/clients/ManagerClient.cpp src/API/clients/ClientBase.cpp - src/API/EventsPublisher.cpp - src/API/EventsSubscriber.cpp + src/API/OccasionsPublisher.cpp + src/API/OccasionsSubscriber.cpp ) target_link_libraries(mementar_lib ${catkin_LIBRARIES}) add_dependencies(mementar_lib ${catkin_EXPORTED_TARGETS} mementar_gencpp) @@ -166,7 +166,7 @@ add_dependencies(mementar_multi ${catkin_EXPORTED_TARGETS}) ############################## -add_executable(event_sub_pub src/test/event_sub_pub.cpp) +add_executable(event_sub_pub src/test/occasions_sub_pub.cpp) target_link_libraries(event_sub_pub ${catkin_LIBRARIES}) target_link_libraries(event_sub_pub mementar_lib) diff --git a/docs/ClientBase.html b/docs/ClientBase.html index d002ad7..509710a 100644 --- a/docs/ClientBase.html +++ b/docs/ClientBase.html @@ -1,7 +1,7 @@ - ClientBase Class | Mementar 0.0.2 + ClientBase Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -68,10 +69,10 @@

    Getting Start

    All C++ Classes

    diff --git a/docs/CppAPI.html b/docs/CppAPI.html index ac7a99e..71761eb 100644 --- a/docs/CppAPI.html +++ b/docs/CppAPI.html @@ -1,7 +1,7 @@ - C++ API | Mementar 0.0.2 + C++ API | Mementar 0.0.3 @@ -38,6 +38,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -59,10 +60,10 @@

    Getting Start

    All C++ Classes

    @@ -74,14 +75,14 @@

    All C++ Classes

    ClientBase

    The ClientBase class provides a common ROS service abstraction.

    -

    Event

    -

    The Event class provides a way to represent events in mementar.

    -

    EventsPublisher

    -

    The EventsPublisher class provides an abstraction for mementar insertion topic.

    -

    EventsSubscriber

    -

    The EventsSubscriber class can be seen as an action server to subscribe to events.

    +

    Fact

    +

    The Fact class provides a way to represent facts in mementar.

    ManagerClient

    The ManagerClient class provides an abstraction for mementar manage service.

    +

    OccasionsPublisher

    +

    The OccasionsPublisher class provides an abstraction for mementar insertion topic.

    +

    OccasionsSubscriber

    +

    The OccasionsSubscriber class can be seen as an action server to subscribe to occasions.

    TimelineManipulator

    The OntologyManipulator class is an object with instances of all classes needed to manipulate an ontology.

    TimelinesManipulator

    diff --git a/docs/Download.html b/docs/Download.html index 6dcb335..1bcc3d5 100644 --- a/docs/Download.html +++ b/docs/Download.html @@ -1,7 +1,7 @@ - Download | Mementar 0.0.2 + Download | Mementar 0.0.3 @@ -38,6 +38,7 @@
  • Pipelines
  • Mementar Documentation

    +

    Mementar 0.0.3

    @@ -59,10 +60,10 @@

    Getting Start

    All C++ Classes

    diff --git a/docs/Event.html b/docs/Fact.html similarity index 54% rename from docs/Event.html rename to docs/Fact.html index 6355eee..6c4de6c 100644 --- a/docs/Event.html +++ b/docs/Fact.html @@ -1,7 +1,7 @@ - Event Class | Mementar 0.2.1 + Fact Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -66,10 +67,10 @@

    Getting Start

    All C++ Classes

    @@ -78,12 +79,12 @@

    All C++ Classes

    -

    Event Class

    -

    The Event class provides a way to represent events in mementar. More...

    +

    Fact Class

    +

    The Fact class provides a way to represent facts in mementar. More...

    -
    Header: #include "mementar/API/Event.h" +
    Header: #include "mementar/API/Fact.h"
    @@ -93,16 +94,16 @@

    Public Functions

    - - - - - - - - - - + + + + + + + + + +
    Event(const std::string& event)
    Event(const std::string& subject, const std::string& predicat, const std::string& object)
    std::string subject()
    std::string predicat()
    std::string object()
    std::string operator()()
    void subject(const std::string& subject)
    void predicat(const std::string& predicat)
    void object(const std::string& object)
    void operator()(const std::string& event)
    Fact(const std::string& fact)
    Fact(const std::string& subject, const std::string& predicat, const std::string& object)
    std::string subject()
    std::string predicat()
    std::string object()
    std::string operator()()
    void subject(const std::string& subject)
    void predicat(const std::string& predicat)
    void object(const std::string& object)
    void operator()(const std::string& fact)
    @@ -110,45 +111,50 @@

    Public Functions

    Detailed Description

    -

    The Event class provides a way to represent events in mementar.

    -

    Mementar formats the data representing an event to be able to communicate them at the level of ROS messages. The Event class makes it possible to make the link between this formatted representation and the representation in the form of a triplet.

    +

    The Fact class provides a way to represent facts in mementar.

    +

    Mementar formats the data representing an fact to be able to communicate them at the level of ROS messages. The Fact class makes it possible to make the link between this formatted representation and the representation in the form of a triplet.

    +

    In mementar, a fact is a datum that is not linked to a temporal stamp. When a fact occurs at a moment t, it is + called an occasion. An occasion is a particular time or instance of an event. An event occurs on a time interval. + It is thus composed of two occasions, one being the beginning of the event and the other the end. An event is + therefore a change of state of a fact, so that two facts have the same subject and the same predicate, but the + object changes.

    Public Functions Documentation

    -

    mementar::Event::Event(const std::string& event)

    -

    Constructs a new event from the formatted parameter event.

    -

    In its formatted form, an event is written as follows: subject|predicat|object

    +

    mementar::Fact::Fact(const std::string& fact)

    +

    Constructs a new fact from the formatted parameter fact.

    +

    In its formatted form, an fact is written as follows: subject|predicat|object

    -

    mementar::Event::Event(const std::string& subject, const std::string& predicat, const std::string& object)

    -

    Constructs a new event from the triplet defined by the parameters subject, predicat and object.

    +

    mementar::Fact::Fact(const std::string& subject, const std::string& predicat, const std::string& object)

    +

    Constructs a new fact from the triplet defined by the parameters subject, predicat and object.

    -

    std::string mementar::Event::subject()

    -

    Return the subject of the event.

    +

    std::string mementar::Fact::subject()

    +

    Return the subject of the fact.

    -

    std::string mementar::Event::predicat()

    -

    Return the predicat of the event.

    +

    std::string mementar::Fact::predicat()

    +

    Return the predicat of the fact.

    -

    std::string mementar::Event::object()

    -

    Return the object of the event.

    +

    std::string mementar::Fact::object()

    +

    Return the object of the fact.

    -

    std::string mementar::Event::operator()()

    -

    Return the event in its formatted form.

    -

    In its formatted form, an event is written as follows: subject|predicat|object

    +

    std::string mementar::Fact::operator()()

    +

    Return the fact in its formatted form.

    +

    In its formatted form, an fact is written as follows: subject|predicat|object

    -

    void mementar::Event::subject(const std::string& subject)

    -

    Set the subject of the event.

    +

    void mementar::Fact::subject(const std::string& subject)

    +

    Set the subject of the fact.

    -

    void mementar::Event::predicat(const std::string& predicat)

    -

    Set the predicat of the event.

    +

    void mementar::Fact::predicat(const std::string& predicat)

    +

    Set the predicat of the fact.

    -

    void mementar::Event::object(const std::string& object)

    -

    Set the object of the event.

    +

    void mementar::Fact::object(const std::string& object)

    +

    Set the object of the fact.

    -

    void mementar::Event::operator()(const std::string& event)

    -

    Set the event using its formatted form.

    -

    In its formatted form, an event is written as follows: subject|predicat|object

    +

    void mementar::Fact::operator()(const std::string& fact)

    +

    Set the fact using its formatted form.

    +

    In its formatted form, an fact is written as follows: subject|predicat|object

    diff --git a/docs/InstallMementar.html b/docs/InstallMementar.html index c47f510..af68208 100644 --- a/docs/InstallMementar.html +++ b/docs/InstallMementar.html @@ -1,7 +1,7 @@ - Install | Mementar 0.0.2 + Install | Mementar 0.0.3 @@ -38,6 +38,7 @@
  • Pipelines
  • Mementar Documentation

    +

    Mementar 0.0.3

    @@ -59,10 +60,10 @@

    Getting Start

    All C++ Classes

    diff --git a/docs/ManagerClient.html b/docs/ManagerClient.html index 3b69f18..5c63a24 100644 --- a/docs/ManagerClient.html +++ b/docs/ManagerClient.html @@ -1,7 +1,7 @@ - ManagerClient Class | Mementar 0.0.2 + ManagerClient Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -67,10 +68,10 @@

    Getting Start

    All C++ Classes

    diff --git a/docs/EventsPublisher.html b/docs/OccasionsPublisher.html similarity index 67% rename from docs/EventsPublisher.html rename to docs/OccasionsPublisher.html index 20fa1a6..79f3716 100644 --- a/docs/EventsPublisher.html +++ b/docs/OccasionsPublisher.html @@ -1,7 +1,7 @@ - EventsPublisher Class | Mementar 0.2.1 + OccasionsPublisher Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -66,10 +67,10 @@

    Getting Start

    All C++ Classes

    @@ -78,12 +79,12 @@

    All C++ Classes

    -

    EventsPublisher Class

    -

    The EventsPublisher class provides an abstraction for mementar insertion topic. More...

    +

    OccasionsPublisher Class

    +

    The OccasionsPublisher class provides an abstraction for mementar insertion topic. More...

    -
    Header: #include "mementar/API/EventsPublisher.h" +
    Header: #include "mementar/API/OccasionsPublisher.h"
    Inherited By: OntologiesManipulator
    @@ -94,8 +95,8 @@

    Public Functions

    - - + +
    EventsPublisher(ros::NodeHandle* n, const std::string& name = "")
    void insert(const Event& event, time_t stamp = 0)
    OccasionsPublisher(ros::NodeHandle* n, const std::string& name = "")
    void insert(const Fact& fact, time_t stamp = 0)
    @@ -103,20 +104,25 @@

    Public Functions

    Detailed Description

    -

    The EventsPublisher class provides an abstraction for mementar insertion ROS topic.

    +

    The OccasionsPublisher class provides an abstraction for mementar insertion ROS topic.

    The insertion process is asynchronous and therefore does not guarantee any response time.

    +

    In mementar, a fact is a datum that is not linked to a temporal stamp. When a fact occurs at a moment t, it is + called an occasion. An occasion is a particular time or instance of an event. An event occurs on a time interval. + It is thus composed of two occasions, one being the beginning of the event and the other the end. An event is + therefore a change of state of a fact, so that two facts have the same subject and the same predicate, but the + object changes.

    Public Functions Documentation

    -

    mementar::EventsPublisher::EventsPublisher(ros::NodeHandle* n, const std::string& name = "")

    -

    Constructs an EventsPublisher with a pointer to a NodeHandle n.

    +

    mementar::OccasionsPublisher::OccasionsPublisher(ros::NodeHandle* n, const std::string& name = "")

    +

    Constructs an OccasionsPublisher with a pointer to a NodeHandle n.

    Can be used in a multi-process mode by specifying the name of the mementar instance name. For classic use, name should be defined as "".

    -

    void mementar::EventsPublisher::insert(const Event& data, time_t& stamp = 0)

    -

    Inserts the event defined in the event object.

    -

    The event can be stamped using the stamp parameter. If the stamp parameter is not set (set to default 0), it will be set at the current time.

    +

    void mementar::OccasionsPublisher::insert(const Fact& fact, time_t stamp = 0)

    +

    Inserts the fact defined in the fact object.

    +

    The fact can be stamped using the stamp parameter. If the stamp parameter is not set (set to default 0), it will be set at the current time.

    diff --git a/docs/EventsSubscriber.html b/docs/OccasionsSubscriber.html similarity index 51% rename from docs/EventsSubscriber.html rename to docs/OccasionsSubscriber.html index 53ad281..c89b219 100644 --- a/docs/EventsSubscriber.html +++ b/docs/OccasionsSubscriber.html @@ -1,7 +1,7 @@ - EventsSubscriber Class | Mementar 0.2.1 + OccasionsSubscriber Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -66,10 +67,10 @@

    Getting Start

    All C++ Classes

    @@ -78,12 +79,12 @@

    All C++ Classes

    -

    EventsPublisher Class

    -

    The EventsSubscriber class can be seen as an action server to subscribe to events. More...

    +

    OccasionsPublisher Class

    +

    The OccasionsSubscriber class can be seen as an action server to subscribe to occasions. More...

    -
    Header: #include "mementar/API/EventsSubscriber.h" +
    Header: #include "mementar/API/OccasionsSubscriber.h"
    @@ -93,12 +94,12 @@

    Public Functions

    - - - - - - + + + + + +
    EventsSubscriber(std::function<void(const Event&)> callback, const std::string& name = "", bool spin_thread = true)
    EventsSubscriber(std::function<void(const Event&)> callback, bool spin_thread)
    ~EventsSubscriber()
    bool subscribe(constEvent & pattern, size_t count = -1)
    bool cancel()
    bool end()
    OccasionsSubscriber(std::function<void(const Fact&)> callback, const std::string& name = "", bool spin_thread = true)
    OccasionsSubscriber(std::function<void(const Fact&)> callback, bool spin_thread)
    ~OccasionsSubscriber()
    bool subscribe(const Fact& pattern, size_t count = -1)
    bool cancel()
    bool end()
    @@ -106,37 +107,42 @@

    Public Functions

    Detailed Description

    -

    The EventsSubscriber class can be seen as an action server to subscribe to events.

    -

    It allows you to subscribe to multiple event patterns at the same time and specify a number of events that you expect.

    +

    The OccasionsSubscriber class can be seen as an action server to subscribe to occasions.

    +

    It allows you to subscribe to multiple fact patterns at the same time and specify a number of occasions that you expect.

    +

    In mementar, a fact is a datum that is not linked to a temporal stamp. When a fact occurs at a moment t, it is + called an occasion. An occasion is a particular time or instance of an event. An event occurs on a time interval. + It is thus composed of two occasions, one being the beginning of the event and the other the end. An event is + therefore a change of state of a fact, so that two facts have the same subject and the same predicate, but the + object changes.

    Public Functions Documentation

    -

    mementar::EventsSubscriber::EventsSubscriber(const std::function<void(Event&)> callback, const std::string& name = "", bool spin_thread = true)

    -

    Constructs an EventsSubscriber with a callback function callback.

    -

    The EventsSubscriber constructor also takes a boolean option to automatically spin a thread. If you prefer not to use threads (and you want the EventsSubscriber to do the 'thread magic' behind the scenes), this is a good option for you.

    +

    mementar::OccasionsSubscriber::OccasionsSubscriber(const std::function<void(Fact&)> callback, const std::string& name = "", bool spin_thread = true)

    +

    Constructs an OccasionsSubscriber with a callback function callback.

    +

    The OccasionsSubscriber constructor also takes a boolean option to automatically spin a thread. If you prefer not to use threads (and you want the OccasionsSubscriber to do the 'thread magic' behind the scenes), this is a good option for you.

    Can be used in a multi-process mode by specifying the name of the mementar instance name. For classic use, name should be defined as "".

    -

    mementar::EventsSubscriber::EventsSubscriber(const std::function<void(Event&)> callback, bool spin_thread)

    -

    Constructs an EventsSubscriber with a callback function callback.

    -

    The EventsSubscriber constructor also takes a boolean option to automatically spin a thread. If you prefer not to use threads (and you want the EventsSubscriber to do the 'thread magic' behind the scenes), this is a good option for you.

    +

    mementar::OccasionsSubscriber::OccasionsSubscriber(const std::function<void(Fact&)> callback, bool spin_thread)

    +

    Constructs an OccasionsSubscriber with a callback function callback.

    +

    The OccasionsSubscriber constructor also takes a boolean option to automatically spin a thread. If you prefer not to use threads (and you want the OccasionsSubscriber to do the 'thread magic' behind the scenes), this is a good option for you.

    -

    mementar::EventsSubscriber::~EventsSubscriber()

    -

    The EventsSubscriber destructor cancel all the subscriptions previous done.

    +

    mementar::OccasionsSubscriber::~OccasionsSubscriber()

    +

    The OccasionsSubscriber destructor cancel all the subscriptions previous done.

    -

    bool mementar::EventsSubscriber::subscribe(const Event& pattern, size_t& count = -1)

    -

    Subscribe to the event pattern pattern defined as an Event object.

    -

    A pattern can be constructed as a classic event, but each component of the triplet can also be set to the value "?" to represent anything.

    -

    The count parameter defines the number of events corresponding to the model you want to know. By using the default value -1, the number of events is unlimited.

    +

    bool mementar::OccasionsSubscriber::subscribe(const Fact& pattern, size_t& count = -1)

    +

    Subscribe to the fact pattern pattern defined as an Fact object.

    +

    A pattern can be constructed as a classic fact, but each component of the triplet can also be set to the value "?" to represent anything.

    +

    The count parameter defines the number of occasions corresponding to the model you want to know. By using the default value -1, the number of occasions is unlimited.

    Returns false if the subscription failed.

    -

    bool mementar::EventsSubscriber::cancel()

    +

    bool mementar::OccasionsSubscriber::cancel()

    Cancel all subscriptions.

    Returns false if at least one subscription fails.

    -

    bool mementar::EventsSubscriber::end()

    -

    Returns true if no more events are expected.

    +

    bool mementar::OccasionsSubscriber::end()

    +

    Returns true if no more occasions are expected.

    If at least one subscription has been made with an account set to -1, the end function will always return false until the next cancellation.

    diff --git a/docs/SetUp.html b/docs/SetUp.html index 99cd91c..09c91a9 100644 --- a/docs/SetUp.html +++ b/docs/SetUp.html @@ -1,7 +1,7 @@ - Set up | Mementar 0.0.2 + Set up | Mementar 0.0.3 @@ -38,6 +38,7 @@
  • Pipelines
  • Mementar Documentation

    +

    Mementar 0.0.3

    @@ -59,10 +60,10 @@

    Getting Start

    All C++ Classes

    diff --git a/docs/TimelineManipulator.html b/docs/TimelineManipulator.html index ec0b0b2..d8c77d0 100644 --- a/docs/TimelineManipulator.html +++ b/docs/TimelineManipulator.html @@ -1,7 +1,7 @@ - TimelineManipulator Class | Mementar 0.0.2 + TimelineManipulator Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -67,10 +68,10 @@

    Getting Start

    All C++ Classes

    @@ -84,7 +85,7 @@

    TimelineManipulator Class

    +
    Header: #include "mementar/API/TimelineManipulator.h" -
    Inherits: EventsPublisher
    Inherits: OccasionsPublisher
    diff --git a/docs/TimelinesManipulator.html b/docs/TimelinesManipulator.html index a68fa09..ae1bf0c 100644 --- a/docs/TimelinesManipulator.html +++ b/docs/TimelinesManipulator.html @@ -1,7 +1,7 @@ - TimelinesManipulator Class | Mementar 0.0.2 + TimelinesManipulator Class | Mementar 0.0.3 @@ -37,6 +37,7 @@
  • Pipelines
  • Mementar API Documentation

    +

    Mementar 0.0.3

    @@ -67,10 +68,10 @@

    Getting Start

    All C++ Classes

    diff --git a/docs/construction.html b/docs/construction.html index c4f02e0..30d9c2d 100644 --- a/docs/construction.html +++ b/docs/construction.html @@ -1,7 +1,7 @@ - Under Construction + Under Construction | Mementar 0.0.3 @@ -40,6 +40,7 @@
  • Pipelines
  • Mementar Documentation

    +

    Mementar 0.0.3

    @@ -61,10 +62,10 @@

    Getting Start

    All C++ Classes

    diff --git a/include/mementar/API/EventsPublisher.h b/include/mementar/API/EventsPublisher.h deleted file mode 100644 index bf6e404..0000000 --- a/include/mementar/API/EventsPublisher.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MEMENTAR_EVENTSPUBLISHER_H -#define MEMENTAR_EVENTSPUBLISHER_H - -#include - -#include - -#include "mementar/API/Event.h" - -namespace mementar -{ - -class EventsPublisher -{ -public: - EventsPublisher(ros::NodeHandle* n, const std::string& name = ""); - - void insert(const Event& event, time_t stamp = 0); - -private: - ros::NodeHandle* n_; - ros::Publisher pub_; - - void publish(const std::string& str, time_t stamp = 0); -}; - -} // namespace mementar - -#endif // MEMENTAR_EVENTSPUBLISHER_H diff --git a/include/mementar/API/Event.h b/include/mementar/API/Fact.h similarity index 80% rename from include/mementar/API/Event.h rename to include/mementar/API/Fact.h index fa7c10c..53fcf1d 100644 --- a/include/mementar/API/Event.h +++ b/include/mementar/API/Fact.h @@ -1,5 +1,5 @@ -#ifndef MEMENTAR_EVENT_H -#define MEMENTAR_EVENT_H +#ifndef MEMENTAR_API_FACT_H +#define MEMENTAR_API_FACT_H #include #include @@ -7,12 +7,12 @@ namespace mementar { -class Event +class Fact { public: - Event(const std::string& event) + Fact(const std::string& fact) { - std::vector splitted = split(event, "|"); + std::vector splitted = split(fact, "|"); if(splitted.size() >= 1) subject_ = splitted[0]; if(splitted.size() >= 2) @@ -20,8 +20,8 @@ class Event if(splitted.size() >= 3) object_ = splitted[2]; } - - Event(const std::string& subject, const std::string& predicat, const std::string& object) + + Fact(const std::string& subject, const std::string& predicat, const std::string& object) { subject_ = subject; predicat_ = predicat; @@ -36,9 +36,9 @@ class Event void subject(const std::string& subject) { subject_ = subject; } void predicat(const std::string& predicat) { predicat_ = predicat; } void object(const std::string& object) { object_ = object; } - void operator()(const std::string& event) + void operator()(const std::string& fact) { - std::vector splitted = split(event, "|"); + std::vector splitted = split(fact, "|"); if(splitted.size() >= 1) subject_ = splitted[0]; if(splitted.size() >= 2) @@ -76,4 +76,4 @@ class Event } // namespace mementar -#endif +#endif // MEMENTAR_API_FACT_H diff --git a/include/mementar/API/OccasionsPublisher.h b/include/mementar/API/OccasionsPublisher.h new file mode 100644 index 0000000..7ea83d4 --- /dev/null +++ b/include/mementar/API/OccasionsPublisher.h @@ -0,0 +1,29 @@ +#ifndef MEMENTAR_API_OCCASIONSPUBLISHER_H +#define MEMENTAR_API_OCCASIONSPUBLISHER_H + +#include + +#include + +#include "mementar/API/Fact.h" + +namespace mementar +{ + +class OccasionsPublisher +{ +public: + OccasionsPublisher(ros::NodeHandle* n, const std::string& name = ""); + + void insert(const Fact& fact, time_t stamp = 0); + +private: + ros::NodeHandle* n_; + ros::Publisher pub_; + + void publish(const std::string& str, time_t stamp = 0); +}; + +} // namespace mementar + +#endif // MEMENTAR_API_OCCASIONSPUBLISHER_H diff --git a/include/mementar/API/EventsSubscriber.h b/include/mementar/API/OccasionsSubscriber.h similarity index 51% rename from include/mementar/API/EventsSubscriber.h rename to include/mementar/API/OccasionsSubscriber.h index 11a4329..935e4f7 100644 --- a/include/mementar/API/EventsSubscriber.h +++ b/include/mementar/API/OccasionsSubscriber.h @@ -1,5 +1,5 @@ -#ifndef MEMENTAR_EVENTSSUBSCRIBER_H -#define MEMENTAR_EVENTSSUBSCRIBER_H +#ifndef MEMENTAR_API_OCCASIONSSUBSCRIBER_H +#define MEMENTAR_API_OCCASIONSSUBSCRIBER_H #include #include @@ -10,19 +10,19 @@ #include #include "mementar/MementarEvent.h" -#include "mementar/API/Event.h" +#include "mementar/API/Fact.h" namespace mementar { -class EventsSubscriber +class OccasionsSubscriber { public: - EventsSubscriber(std::function callback, const std::string& name = "", bool spin_thread = true); - EventsSubscriber(std::function callback, bool spin_thread); - ~EventsSubscriber(); + OccasionsSubscriber(std::function callback, const std::string& name = "", bool spin_thread = true); + OccasionsSubscriber(std::function callback, bool spin_thread); + ~OccasionsSubscriber(); - bool subscribe(const Event& pattern, size_t count = -1); + bool subscribe(const Fact& pattern, size_t count = -1); bool cancel(); bool end() { return ids_.size() == 0; } @@ -40,13 +40,13 @@ class EventsSubscriber std::vector ids_; - void eventCallback(MementarEvent msg); + void occasionCallback(MementarEvent msg); - std::function callback_; + std::function callback_; void spinThread(); }; } // namespace mementar -#endif // MEMENTAR_EVENTSSUBSCRIBER_H +#endif // MEMENTAR_API_OCCASIONSSUBSCRIBER_H diff --git a/include/mementar/API/TimelineManipulator.h b/include/mementar/API/TimelineManipulator.h index b48deae..4199244 100644 --- a/include/mementar/API/TimelineManipulator.h +++ b/include/mementar/API/TimelineManipulator.h @@ -5,13 +5,13 @@ #include -#include "mementar/API/EventsPublisher.h" +#include "mementar/API/OccasionsPublisher.h" #include "mementar/API/clients/ClientBase.h" namespace mementar { -class TimelineManipulator : public EventsPublisher +class TimelineManipulator : public OccasionsPublisher { public: TimelineManipulator(ros::NodeHandle* n, const std::string& name = ""); diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index ae8bb50..40101d8 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -11,7 +11,7 @@ #include "mementar/StampedString.h" #include "mementar/core/EpisodicTree/ArchivedLeafNode.h" -#include "mementar/core/Events/EventsManager.h" +#include "mementar/core/Occasions/OccasionsManager.h" namespace mementar { @@ -32,7 +32,7 @@ class RosInterface std::string directory_; size_t order_; ArchivedLeafNode* tree_; - EventsManager events_; + OccasionsManager occasions_; std::string name_; std::atomic run_; diff --git a/include/mementar/core/Events/IdManager.h b/include/mementar/core/Occasions/IdManager.h similarity index 100% rename from include/mementar/core/Events/IdManager.h rename to include/mementar/core/Occasions/IdManager.h diff --git a/include/mementar/core/Events/EventsManager.h b/include/mementar/core/Occasions/OccasionsManager.h similarity index 80% rename from include/mementar/core/Events/EventsManager.h rename to include/mementar/core/Occasions/OccasionsManager.h index d3781df..c547512 100644 --- a/include/mementar/core/Events/EventsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -1,5 +1,5 @@ -#ifndef MEMENTAR_EVENTSMANAGER_H -#define MEMENTAR_EVENTSMANAGER_H +#ifndef MEMENTAR_OCCASIONSMANAGER_H +#define MEMENTAR_OCCASIONSMANAGER_H #include #include @@ -10,16 +10,16 @@ #include "mementar/MementarEventSubscription.h" #include "mementar/MementarEventUnsubscription.h" -#include "mementar/core/Events/Subscription.h" +#include "mementar/core/Occasions/Subscription.h" #include "mementar/core/Fact.h" namespace mementar { -class EventsManager +class OccasionsManager { public: - EventsManager(ros::NodeHandle* n, std::string name = ""); + OccasionsManager(ros::NodeHandle* n, std::string name = ""); void run(); @@ -54,4 +54,4 @@ class EventsManager } // namespace mementar -#endif // MEMENTAR_EVENTSMANAGER_H +#endif // MEMENTAR_OCCASIONSMANAGER_H diff --git a/include/mementar/core/Events/Subscription.h b/include/mementar/core/Occasions/Subscription.h similarity index 93% rename from include/mementar/core/Events/Subscription.h rename to include/mementar/core/Occasions/Subscription.h index 66fbe01..f85b099 100644 --- a/include/mementar/core/Events/Subscription.h +++ b/include/mementar/core/Occasions/Subscription.h @@ -6,7 +6,7 @@ #include #include "mementar/core/Fact.h" -#include "mementar/core/Events/IdManager.h" +#include "mementar/core/Occasions/IdManager.h" namespace mementar { diff --git a/package.xml b/package.xml index 13069e9..e3fb494 100644 --- a/package.xml +++ b/package.xml @@ -1,7 +1,7 @@ mementar - 0.0.2 + 0.0.3 The mementar package srth diff --git a/src/API/EventsPublisher.cpp b/src/API/OccasionsPublisher.cpp similarity index 56% rename from src/API/EventsPublisher.cpp rename to src/API/OccasionsPublisher.cpp index 0358528..d8ae552 100644 --- a/src/API/EventsPublisher.cpp +++ b/src/API/OccasionsPublisher.cpp @@ -1,22 +1,22 @@ -#include "mementar/API/EventsPublisher.h" +#include "mementar/API/OccasionsPublisher.h" #include "mementar/StampedString.h" namespace mementar { -EventsPublisher::EventsPublisher(ros::NodeHandle* n, const std::string& name) : +OccasionsPublisher::OccasionsPublisher(ros::NodeHandle* n, const std::string& name) : pub_(n->advertise((name == "") ? "mementar/insert_stamped" : "mementar/insert_stamped/" + name, 1000)) { n_ = n; } -void EventsPublisher::insert(const Event& event, time_t stamp) +void OccasionsPublisher::insert(const Fact& fact, time_t stamp) { - publish(event(), stamp); + publish(fact(), stamp); } -void EventsPublisher::publish(const std::string& str, time_t stamp) +void OccasionsPublisher::publish(const std::string& str, time_t stamp) { StampedString msg; msg.data = str; diff --git a/src/API/EventsSubscriber.cpp b/src/API/OccasionsSubscriber.cpp similarity index 67% rename from src/API/EventsSubscriber.cpp rename to src/API/OccasionsSubscriber.cpp index 18d909f..e497949 100644 --- a/src/API/EventsSubscriber.cpp +++ b/src/API/OccasionsSubscriber.cpp @@ -1,4 +1,4 @@ -#include "mementar/API/EventsSubscriber.h" +#include "mementar/API/OccasionsSubscriber.h" #include "mementar/MementarEventSubscription.h" #include "mementar/MementarEventUnsubscription.h" @@ -6,11 +6,11 @@ namespace mementar { -EventsSubscriber::EventsSubscriber(std::function callback, const std::string& name, bool spin_thread) +OccasionsSubscriber::OccasionsSubscriber(std::function callback, const std::string& name, bool spin_thread) { callback_ = callback; - sub_ = n_.subscribe((name == "") ? "mementar/events" : "mementar/events/" + name, 1000, &EventsSubscriber::eventCallback, this); + sub_ = n_.subscribe((name == "") ? "mementar/occasions" : "mementar/occasions/" + name, 1000, &OccasionsSubscriber::occasionCallback, this); client_subscribe_ = n_.serviceClient((name == "") ? "mementar/subscribe" : "mementar/subscribe/" + name); client_cancel_ = n_.serviceClient((name == "") ? "mementar/unsubscribe" : "mementar/unsubscribe/" + name); @@ -18,17 +18,17 @@ EventsSubscriber::EventsSubscriber(std::function callback, c { need_to_terminate_ = false; n_.setCallbackQueue(&callback_queue_); - spin_thread_ = new std::thread(std::bind(&EventsSubscriber::spinThread, this)); + spin_thread_ = new std::thread(std::bind(&OccasionsSubscriber::spinThread, this)); } else spin_thread_ = nullptr; } -EventsSubscriber::EventsSubscriber(std::function callback, bool spin_thread) +OccasionsSubscriber::OccasionsSubscriber(std::function callback, bool spin_thread) { callback_ = callback; - sub_ = n_.subscribe("mementar/events", 1000, &EventsSubscriber::eventCallback, this); + sub_ = n_.subscribe("mementar/occasions", 1000, &OccasionsSubscriber::occasionCallback, this); client_subscribe_ = n_.serviceClient("mementar/subscribe"); client_cancel_ = n_.serviceClient("mementar/unsubscribe"); @@ -36,13 +36,13 @@ EventsSubscriber::EventsSubscriber(std::function callback, b { need_to_terminate_ = false; n_.setCallbackQueue(&callback_queue_); - spin_thread_ = new std::thread(std::bind(&EventsSubscriber::spinThread, this)); + spin_thread_ = new std::thread(std::bind(&OccasionsSubscriber::spinThread, this)); } else spin_thread_ = nullptr; } -EventsSubscriber::~EventsSubscriber() +OccasionsSubscriber::~OccasionsSubscriber() { cancel(); if(spin_thread_) @@ -55,7 +55,7 @@ EventsSubscriber::~EventsSubscriber() } } -bool EventsSubscriber::subscribe(const Event& pattern, size_t count) +bool OccasionsSubscriber::subscribe(const Fact& pattern, size_t count) { MementarEventSubscription srv; srv.request.data = pattern(); @@ -70,7 +70,7 @@ bool EventsSubscriber::subscribe(const Event& pattern, size_t count) return false; } -bool EventsSubscriber::cancel() +bool OccasionsSubscriber::cancel() { bool done = true; for(size_t i = 0; i < ids_.size();) @@ -94,18 +94,18 @@ bool EventsSubscriber::cancel() return done; } -void EventsSubscriber::eventCallback(MementarEvent msg) +void OccasionsSubscriber::occasionCallback(MementarEvent msg) { auto it = std::find(ids_.begin(), ids_.end(), msg.id); if(it != ids_.end()) { - callback_(Event(msg.data)); + callback_(Fact(msg.data)); if(msg.last == true) ids_.erase(it); } } -void EventsSubscriber::spinThread() +void OccasionsSubscriber::spinThread() { while(n_.ok()) { diff --git a/src/API/TimelineManipulator.cpp b/src/API/TimelineManipulator.cpp index 39d007c..9e2ea50 100644 --- a/src/API/TimelineManipulator.cpp +++ b/src/API/TimelineManipulator.cpp @@ -3,7 +3,7 @@ namespace mementar { -TimelineManipulator::TimelineManipulator(ros::NodeHandle* n, const std::string& name) : EventsPublisher(n, name) +TimelineManipulator::TimelineManipulator(ros::NodeHandle* n, const std::string& name) : OccasionsPublisher(n, name) { n_ = n; name_ = name; diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 9e1e554..20a8789 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -10,7 +10,7 @@ namespace mementar { -RosInterface::RosInterface(ros::NodeHandle* n, const std::string& directory, size_t order, std::string name) : events_(n, name), +RosInterface::RosInterface(ros::NodeHandle* n, const std::string& directory, size_t order, std::string name) : occasions_(n, name), run_(true) { n_ = n; @@ -46,7 +46,7 @@ void RosInterface::run() service_name = (name_ == "") ? "actions" : "actions/" + name_; ros::ServiceServer service = n_->advertiseService(service_name, &RosInterface::actionsHandle, this); - std::thread event_thread(&EventsManager::run, &events_); + std::thread occasions_thread(&OccasionsManager::run, &occasions_); ROS_DEBUG("%s mementar ready", name_.c_str()); @@ -55,8 +55,8 @@ void RosInterface::run() ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1)); } - events_.stop(); - event_thread.join(); + occasions_.stop(); + occasions_thread.join(); } void RosInterface::reset() @@ -83,7 +83,7 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) mut_.lock_shared(); tree_->insert(time(0), fact); mut_.unlock_shared(); - events_.add(fact); + occasions_.add(fact); } } @@ -95,7 +95,7 @@ void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) mut_.lock_shared(); tree_->insert(msg->stamp.sec, fact); mut_.unlock_shared(); - events_.add(fact); + occasions_.add(fact); } } diff --git a/src/core/Events/EventsManager.cpp b/src/core/Occasions/OccasionsManager.cpp similarity index 73% rename from src/core/Events/EventsManager.cpp rename to src/core/Occasions/OccasionsManager.cpp index ae24efc..f9f199d 100644 --- a/src/core/Events/EventsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -1,24 +1,24 @@ -#include "mementar/core/Events/EventsManager.h" +#include "mementar/core/Occasions/OccasionsManager.h" #include "mementar/MementarEvent.h" namespace mementar { -EventsManager::EventsManager(ros::NodeHandle* n, std::string name) : run_(false), - pub_(n->advertise((name == "") ? "events" : "events/" + name, 1000)) +OccasionsManager::OccasionsManager(ros::NodeHandle* n, std::string name) : run_(false), + pub_(n->advertise((name == "") ? "occasions" : "occasions/" + name, 1000)) { n_ = n; std::string service_name; service_name = (name == "") ? "subscribe" : "subscribe/" + name; - sub_service_ = n_->advertiseService(service_name, &EventsManager::SubscribeCallback, this); + sub_service_ = n_->advertiseService(service_name, &OccasionsManager::SubscribeCallback, this); service_name = (name == "") ? "unsubscribe" : "unsubscribe/" + name; - unsub_service_ = n_->advertiseService(service_name, &EventsManager::UnsubscribeCallback, this); + unsub_service_ = n_->advertiseService(service_name, &OccasionsManager::UnsubscribeCallback, this); } -void EventsManager::run() +void OccasionsManager::run() { run_ = true; ros::Rate r(50); @@ -45,7 +45,7 @@ void EventsManager::run() } } -void EventsManager::add(const Fact& fact) +void OccasionsManager::add(const Fact& fact) { mutex_.lock(); if(queue_choice_ == true) @@ -55,7 +55,7 @@ void EventsManager::add(const Fact& fact) mutex_.unlock(); } -bool EventsManager::SubscribeCallback(mementar::MementarEventSubscription::Request &req, +bool OccasionsManager::SubscribeCallback(mementar::MementarEventSubscription::Request &req, mementar::MementarEventSubscription::Response &res) { Fact fact_patern(req.data); @@ -67,7 +67,7 @@ bool EventsManager::SubscribeCallback(mementar::MementarEventSubscription::Reque return true; } -bool EventsManager::UnsubscribeCallback(mementar::MementarEventUnsubscription::Request &req, +bool OccasionsManager::UnsubscribeCallback(mementar::MementarEventUnsubscription::Request &req, mementar::MementarEventUnsubscription::Response &res) { if(subscription_.unsubscribe(req.id)) @@ -78,7 +78,7 @@ bool EventsManager::UnsubscribeCallback(mementar::MementarEventUnsubscription::R return true; } -Fact EventsManager::get() +Fact OccasionsManager::get() { Fact res; mutex_.lock(); @@ -108,7 +108,7 @@ Fact EventsManager::get() return res; } -bool EventsManager::empty() +bool OccasionsManager::empty() { bool res = true; mutex_.lock(); diff --git a/src/core/Events/Subscription.cpp b/src/core/Occasions/Subscription.cpp similarity index 95% rename from src/core/Events/Subscription.cpp rename to src/core/Occasions/Subscription.cpp index 2631326..460f5b5 100644 --- a/src/core/Events/Subscription.cpp +++ b/src/core/Occasions/Subscription.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/Events/Subscription.h" +#include "mementar/core/Occasions/Subscription.h" namespace mementar { diff --git a/src/test/event_sub_pub.cpp b/src/test/event_sub_pub.cpp deleted file mode 100644 index 202b907..0000000 --- a/src/test/event_sub_pub.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include - -#include "ros/ros.h" - -#include "mementar/API/TimelineManipulator.h" -#include "mementar/API/EventsSubscriber.h" - -void callback_1(const mementar::Event& evt) -{ - std::cout << "[CB1] " << evt() << std::endl; -} - -void callback_2(const mementar::Event& evt) -{ - std::cout << "[CB2] " << evt() << std::endl; -} - -int main(int argc, char** argv) -{ - ros::init(argc, argv, "event_sub_pub"); - - ros::NodeHandle n; - - mementar::TimelineManipulator manip(&n); - manip.waitInit(); - - mementar::EventsSubscriber sub1(&callback_1, true); - sub1.subscribe(mementar::Event("bob", "eat", "?"), 2); - mementar::EventsSubscriber sub2(&callback_2, true); - sub2.subscribe(mementar::Event("max", "eat", "?"), 3); - - size_t cpt = 0; - ros::Rate r(100); - while((!sub1.end() || !sub2.end()) && ros::ok()) - { - cpt++; - if(cpt > 100) - { - cpt = 0; - manip.insert(mementar::Event("bob", "eat", "blop")); - manip.insert(mementar::Event("max", "eat", "blop")); - } - ros::spinOnce(); - r.sleep(); - } - - return 0; -} diff --git a/src/test/occasions_sub_pub.cpp b/src/test/occasions_sub_pub.cpp new file mode 100644 index 0000000..a4b6600 --- /dev/null +++ b/src/test/occasions_sub_pub.cpp @@ -0,0 +1,48 @@ +#include + +#include "ros/ros.h" + +#include "mementar/API/TimelineManipulator.h" +#include "mementar/API/OccasionsSubscriber.h" + +void callback_1(const mementar::Fact& fct) +{ + std::cout << "[CB1] " << fct() << std::endl; +} + +void callback_2(const mementar::Fact& fct) +{ + std::cout << "[CB2] " << fct() << std::endl; +} + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "occasions_sub_pub"); + + ros::NodeHandle n; + + mementar::TimelineManipulator manip(&n); + manip.waitInit(); + + mementar::OccasionsSubscriber sub1(&callback_1, true); + sub1.subscribe(mementar::Fact("bob", "eat", "?"), 2); + mementar::OccasionsSubscriber sub2(&callback_2, true); + sub2.subscribe(mementar::Fact("max", "eat", "?"), 3); + + size_t cpt = 0; + ros::Rate r(100); + while((!sub1.end() || !sub2.end()) && ros::ok()) + { + cpt++; + if(cpt > 100) + { + cpt = 0; + manip.insert(mementar::Fact("bob", "eat", "blop")); + manip.insert(mementar::Fact("max", "eat", "blop")); + } + ros::spinOnce(); + r.sleep(); + } + + return 0; +} From 2c3b9db02f50c44cb38644ddff65dab0973111e0 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 15 Jul 2019 14:57:07 +0200 Subject: [PATCH 02/95] [REFACT] events to occasions for messages and services --- CMakeLists.txt | 6 +++--- include/mementar/API/OccasionsSubscriber.h | 4 ++-- .../mementar/core/Occasions/OccasionsManager.h | 12 ++++++------ ...{MementarEvent.msg => MementarOccasion.msg} | 0 src/API/OccasionsSubscriber.cpp | 18 +++++++++--------- src/core/Occasions/OccasionsManager.cpp | 14 +++++++------- ....srv => MementarOcassionUnsubscription.srv} | 0 ...on.srv => MementarOccasionSubscription.srv} | 0 8 files changed, 27 insertions(+), 27 deletions(-) rename msg/{MementarEvent.msg => MementarOccasion.msg} (100%) rename srv/{MementarEventUnsubscription.srv => MementarOcassionUnsubscription.srv} (100%) rename srv/{MementarEventSubscription.srv => MementarOccasionSubscription.srv} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e71037..e5edeb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport) ## Generate messages in the 'msg' folder add_message_files( FILES - MementarEvent.msg + MementarOccasion.msg StampedString.msg ) @@ -38,8 +38,8 @@ find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport) add_service_files( FILES MementarService.srv - MementarEventSubscription.srv - MementarEventUnsubscription.srv + MementarOccasionSubscription.srv + MementarOcassionUnsubscription.srv ) ## Generate added messages and services with any dependencies listed here diff --git a/include/mementar/API/OccasionsSubscriber.h b/include/mementar/API/OccasionsSubscriber.h index 935e4f7..d3a284a 100644 --- a/include/mementar/API/OccasionsSubscriber.h +++ b/include/mementar/API/OccasionsSubscriber.h @@ -9,7 +9,7 @@ #include #include -#include "mementar/MementarEvent.h" +#include "mementar/MementarOccasion.h" #include "mementar/API/Fact.h" namespace mementar @@ -40,7 +40,7 @@ class OccasionsSubscriber std::vector ids_; - void occasionCallback(MementarEvent msg); + void occasionCallback(MementarOccasion msg); std::function callback_; diff --git a/include/mementar/core/Occasions/OccasionsManager.h b/include/mementar/core/Occasions/OccasionsManager.h index c547512..625baf1 100644 --- a/include/mementar/core/Occasions/OccasionsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -7,8 +7,8 @@ #include -#include "mementar/MementarEventSubscription.h" -#include "mementar/MementarEventUnsubscription.h" +#include "mementar/MementarOccasionSubscription.h" +#include "mementar/MementarOcassionUnsubscription.h" #include "mementar/core/Occasions/Subscription.h" #include "mementar/core/Fact.h" @@ -43,10 +43,10 @@ class OccasionsManager std::queue fifo_1; std::queue fifo_2; - bool SubscribeCallback(mementar::MementarEventSubscription::Request &req, - mementar::MementarEventSubscription::Response &res); - bool UnsubscribeCallback(mementar::MementarEventUnsubscription::Request &req, - mementar::MementarEventUnsubscription::Response &res); + bool SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, + mementar::MementarOccasionSubscription::Response &res); + bool UnsubscribeCallback(mementar::MementarOcassionUnsubscription::Request &req, + mementar::MementarOcassionUnsubscription::Response &res); Fact get(); bool empty(); diff --git a/msg/MementarEvent.msg b/msg/MementarOccasion.msg similarity index 100% rename from msg/MementarEvent.msg rename to msg/MementarOccasion.msg diff --git a/src/API/OccasionsSubscriber.cpp b/src/API/OccasionsSubscriber.cpp index e497949..78f9d40 100644 --- a/src/API/OccasionsSubscriber.cpp +++ b/src/API/OccasionsSubscriber.cpp @@ -1,7 +1,7 @@ #include "mementar/API/OccasionsSubscriber.h" -#include "mementar/MementarEventSubscription.h" -#include "mementar/MementarEventUnsubscription.h" +#include "mementar/MementarOccasionSubscription.h" +#include "mementar/MementarOcassionUnsubscription.h" namespace mementar { @@ -11,8 +11,8 @@ OccasionsSubscriber::OccasionsSubscriber(std::function callba callback_ = callback; sub_ = n_.subscribe((name == "") ? "mementar/occasions" : "mementar/occasions/" + name, 1000, &OccasionsSubscriber::occasionCallback, this); - client_subscribe_ = n_.serviceClient((name == "") ? "mementar/subscribe" : "mementar/subscribe/" + name); - client_cancel_ = n_.serviceClient((name == "") ? "mementar/unsubscribe" : "mementar/unsubscribe/" + name); + client_subscribe_ = n_.serviceClient((name == "") ? "mementar/subscribe" : "mementar/subscribe/" + name); + client_cancel_ = n_.serviceClient((name == "") ? "mementar/unsubscribe" : "mementar/unsubscribe/" + name); if(spin_thread) { @@ -29,8 +29,8 @@ OccasionsSubscriber::OccasionsSubscriber(std::function callba callback_ = callback; sub_ = n_.subscribe("mementar/occasions", 1000, &OccasionsSubscriber::occasionCallback, this); - client_subscribe_ = n_.serviceClient("mementar/subscribe"); - client_cancel_ = n_.serviceClient("mementar/unsubscribe"); + client_subscribe_ = n_.serviceClient("mementar/subscribe"); + client_cancel_ = n_.serviceClient("mementar/unsubscribe"); if(spin_thread) { @@ -57,7 +57,7 @@ OccasionsSubscriber::~OccasionsSubscriber() bool OccasionsSubscriber::subscribe(const Fact& pattern, size_t count) { - MementarEventSubscription srv; + MementarOccasionSubscription srv; srv.request.data = pattern(); srv.request.count = count; @@ -75,7 +75,7 @@ bool OccasionsSubscriber::cancel() bool done = true; for(size_t i = 0; i < ids_.size();) { - MementarEventUnsubscription srv; + MementarOcassionUnsubscription srv; srv.request.id = ids_[i]; if(client_cancel_.call(srv)) { @@ -94,7 +94,7 @@ bool OccasionsSubscriber::cancel() return done; } -void OccasionsSubscriber::occasionCallback(MementarEvent msg) +void OccasionsSubscriber::occasionCallback(MementarOccasion msg) { auto it = std::find(ids_.begin(), ids_.end(), msg.id); if(it != ids_.end()) diff --git a/src/core/Occasions/OccasionsManager.cpp b/src/core/Occasions/OccasionsManager.cpp index f9f199d..38f1926 100644 --- a/src/core/Occasions/OccasionsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -1,12 +1,12 @@ #include "mementar/core/Occasions/OccasionsManager.h" -#include "mementar/MementarEvent.h" +#include "mementar/MementarOccasion.h" namespace mementar { OccasionsManager::OccasionsManager(ros::NodeHandle* n, std::string name) : run_(false), - pub_(n->advertise((name == "") ? "occasions" : "occasions/" + name, 1000)) + pub_(n->advertise((name == "") ? "occasions" : "occasions/" + name, 1000)) { n_ = n; std::string service_name; @@ -33,7 +33,7 @@ void OccasionsManager::run() std::vector ids = subscription_.evaluate(fact); for(auto id : ids) { - mementar::MementarEvent msg; + mementar::MementarOccasion msg; msg.id = id; msg.data = fact.toString(); msg.last = subscription_.isFinished(id); @@ -55,8 +55,8 @@ void OccasionsManager::add(const Fact& fact) mutex_.unlock(); } -bool OccasionsManager::SubscribeCallback(mementar::MementarEventSubscription::Request &req, - mementar::MementarEventSubscription::Response &res) +bool OccasionsManager::SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, + mementar::MementarOccasionSubscription::Response &res) { Fact fact_patern(req.data); if(!fact_patern.valid()) @@ -67,8 +67,8 @@ bool OccasionsManager::SubscribeCallback(mementar::MementarEventSubscription::Re return true; } -bool OccasionsManager::UnsubscribeCallback(mementar::MementarEventUnsubscription::Request &req, - mementar::MementarEventUnsubscription::Response &res) +bool OccasionsManager::UnsubscribeCallback(mementar::MementarOcassionUnsubscription::Request &req, + mementar::MementarOcassionUnsubscription::Response &res) { if(subscription_.unsubscribe(req.id)) res.id = req.id; diff --git a/srv/MementarEventUnsubscription.srv b/srv/MementarOcassionUnsubscription.srv similarity index 100% rename from srv/MementarEventUnsubscription.srv rename to srv/MementarOcassionUnsubscription.srv diff --git a/srv/MementarEventSubscription.srv b/srv/MementarOccasionSubscription.srv similarity index 100% rename from srv/MementarEventSubscription.srv rename to srv/MementarOccasionSubscription.srv From a9ade203b4871ca8a8ae6bc2c534bcaaa2f8c15c Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 17 Jul 2019 13:32:57 +0200 Subject: [PATCH 03/95] [ADD] mementar website index --- docs/img/background.png | Bin 0 -> 80747 bytes docs/img/logo/mementar_simple.png | Bin 0 -> 7083 bytes docs/index.html | 211 ++++++++++++++ docs/style/index.css | 439 ++++++++++++++++++------------ 4 files changed, 480 insertions(+), 170 deletions(-) create mode 100644 docs/img/background.png create mode 100644 docs/img/logo/mementar_simple.png create mode 100644 docs/index.html diff --git a/docs/img/background.png b/docs/img/background.png new file mode 100644 index 0000000000000000000000000000000000000000..29afabe9f5bb10b59d6af1cbc6f74629b28aea5d GIT binary patch literal 80747 zcmeEs^;^^5`~Of8MF9~BNku7XDQS_>B_SOm9Rq1b4T}^IBqS$DO6O=$N*EzI8tE9h zvB4N)-|6f6{0ZOR-p^}su5)(n-2J%k`<&?Kx@uIE%#;8CfJ#FhXaE3EgaZIqo?N?1 zn%Nrvp-lR^{#xD42LQN1_xDW($jD+MP15+PnEI-^xH|yk{5*VJeBB-F6;f&usiY;Q zze_+{UkAWr5m9Mj5h-C&se7WLGU6gKBH}%JrbeXS-1_?)BNvbZK!h~=-%E72i~Hx_ z{r>&6x9z`0(I5KsoTN#rzmv+OId5CQe_zhTgKg5njlTe8XP4OixLE?X}3alI#b|55J1txu@Pm^=Sce-UrDi?e+KhGmbar z{%;64l)etQ{NGso8Q`z9NY7W=OP&7)06^R=z+dr_9_RM}k^e?dA6yA1`)|m6A8_-( z(eGJ^l zTr8{(;mXVGt>NP=*eX001)1{=U^N!L#=uQ;k6;aQ#|tVkcg(&9SL=i}g;oEu zC}X@4TUdiLwV(R@eIV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CKjKUtstJhW{r-j_s0k zwV#8nb>Q?A5))gh0(K+!K1nAU_x}O_@BhYZmrMJNS@3IcQ{2IiVMq6SW#B)5{khkl z-}^}Zm!koV|NNKN{2B~2%P*V#g2o;_e$ff|KdQl#J|R`*e8*j8&ost{76yb%E|2~P D2Lr`o literal 0 HcmV?d00001 diff --git a/docs/img/logo/mementar_simple.png b/docs/img/logo/mementar_simple.png new file mode 100644 index 0000000000000000000000000000000000000000..4cc8ca756183da7bc204f2351b998edd11fdf39e GIT binary patch literal 7083 zcmeHM_g52Jv`#{mj)?RgK#?j!=qNQK0#a3)ToI6t5NQfY^wN8fW+)1g5{e)o5L&LF zUPVL#0s?`E0treJFi{ZR_||)Gy&vBn@UqrqGUuGk+2`AP_P4(?=@%Vr`FSLHAP@*Y zfV6UkKwxSR2o%oE3AR8fl0M*xJ=y|rSItj@W{m90@@+kMSMF7;nEF>jCwNuZbg@?k z(GIX0s7UJJPgC+~U(v|H$Yw70NuT->bfIl!Ff5AT<8$%s>&0DXAr4`+(GGT#67YTS%R$BKHwNu`hg6i{U*=v zhNZwyJ{KVKVtIiD=N{9v&{DlY^F0G!FZ)@-X%iR=-jcS;Y#7;=qS+JLbZ~@}627+z zhv%+u@5_|%ek(z5AER%PFJX5lIwQi^*I{Pt-|nMDl!5Ln)x;95+WC9`E?+V88f3kl zB_^02GbnziDdArFm|Rbu?!})1h%>EZi)(_4_&|ltyN#ZWMtrahIMqs~&oQi`0b{8f z-U+W)bir(=nMY>bfAZPBvoDx)Q)!X;DF3Offy}ho6al0Pk zq|(d{+VTA4lM*j2Kg7#zA>PJ3=)v40${huqjhBVcXX*MI&39Z~lRHHQB2f6pWWNSk zalkpmfe<^e7G9x1;}^}%CT%A?Xa!LSA9M>-u8(>39$$Rh=1t0{Fy~$+?5&{<5w~R{ zipWhILGl~0VS*iVC|X1;+|We^%2zRyrGEw|e})5+{|JzmhS2ntH%o)Fb-(x_=1NI& z|CUZ&()Yj-njYBgrzWnyZMxAoQ86WK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dsxGv*?D%{saX$7vF`-G*cU=O^9e?VRJf)x2ZwRO^Jj-HboAe8y>r z7jnOpZJWji9i_hP1#lCH8a9LoI#OTo%TAbm2^{#n>}!N>cvi2!ja}!oB=;8oz@Mz3F`6==ya8?# zS(&TosXOLq68;Kjs}R`NBnbhy2ec1_PL@q&@(qh-*g<{MSTP)^HpWk{!G2gnGS4DD zIn4_yJ+^xSl%|a_T<-|zN$)F2kHDA7=E}gTLN4ST=j73a3txgS&RZFQ1dU6W2q&ZS z=EFp&UatAWm|~b8Q5tMM79zc=NK+j`NUa6vMVj?9F5?LOEppmoT}3RF>x4#SjrhYT z->4#|JUH;;_OVR|U)e2Y+Z<<^wb8b&#)^&It!O7XV0Au@CQpl``Op246#FI8V+UvROlUs?Im?*?=$BAb_=lRkMZf-Twd|pgJ)C literal 0 HcmV?d00001 diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..f4a9cbc --- /dev/null +++ b/docs/index.html @@ -0,0 +1,211 @@ + + + + Mementar 0.0.2 + + + + Exemple avec navbar-default + + + + + + + + + + + + + + +

    +
    + +
    +
    + + + +
    +
    +
    + +
    +
    +
    +

    mementar

    +
    + + +
    + +
    +

    A powerful way to store your robot experience.

    +
    +

    A smart way to organize the knowledge of your agent.

    +
    +

    A natural way to evolve the knowledge of your agents.

    +
    +

    A efficient way to embed your agents memories.

    +
    +
    + +
    + +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    +

    About mementar

    +

    Mementar is a research project aimed at providing that which can be seen as a episodic memory + for artificial agents. Focusing only on this task, mementar is currently a robust and efficient + open-source software that can be deployed in many applications.

    + +

    Mementar is under development and is currently considered a beta version.

    + +

    Linked to ontologenius, a semantic memory for artificial agents, it allows to realize high level + queries to explore the memories of robotic agent.

    + +

    Based on the principle of compression and archiving, Mementar aims to store a large amount of + past events.

    + + +
    Mementar uses ROS for maximum compatibility with all robotics projects. + +
    +
    +
    + +
    +

    What's New

    +
    + +

    C++ API is already available

    +
    +

    As part of a recent effort to facilitate the use of ontologenius, we are now developing a C ++ API + covering the majority of features. The complete documentation of this API is now available online.

    +
    + +
    +
    + +
    + + +
    +
    +

    See also

    +
    +
    +
    +
    +
    +

    Ontologenius

    +
    +
    +
    + +
    + + +
    +
    +
    +
    +
    +
    +
    + +
    +
    + + + + +
    +
    +

    + Brought to you by: + +

    +
    +
    + + diff --git a/docs/style/index.css b/docs/style/index.css index 5e3aba2..533b55f 100644 --- a/docs/style/index.css +++ b/docs/style/index.css @@ -1,222 +1,321 @@ +@import url('cookie-confirm.css') screen; body { - background: #E5E5E5; - line-height:1; - font-family:Arial, Helvetica, sans-serif; - font-weight:400; - transition-duration:1s; - font-size: 16px; -} - -html, body { height: 100%; + width: 100%; + margin: 0; } -@keyframes appear { - 0% {opacity:0;} - 100% {opacity:1;} +.container { + margin-right: auto; + margin-left: auto; + padding-left: 20px; + padding-right: 20px; } -button { - position: absolute; - box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.75); - border: 5px solid transparent; - background: #000000; - color: #F0F0F0; - border-radius: 70px; - padding: 15px 15; - overflow: hidden; - width: 140px; - height: 140px; - white-space: nowrap; - font-weight: bold; - margin-left: calc(90px + 50px - 70px ); - - opacity:0; - animation-name: appear; - animation-duration: 2s; - animation-delay: 2.5s; - animation-fill-mode: forwards; - - transition: - box-shadow 0.3s, - border 1.0s, - margin-left 1.0s, - all 1.0s 0.5s; -} - -button > span { - transform: translateY(300px); - font-weight: normal; - opacity: 0; - transition: - opacity 0.1s, - transform 0.4s; -} - -button:hover { - background: #d43617; - color: #0f0f0f; - width: 260px; - height: 260px; - border-radius: 130px; - border: 50px solid #a3a3a3; - box-shadow: 0px 0px 59px -20px rgba(0,0,0,0.75); - margin-left: calc(90px + 50px - 130px ); - transition: - all 1.2s, - border 1.2s 0.5s, - margin-left 1.2s, - box-shadow 1.2s 0.5s; -} - -button:hover > span { - display: inline-block; - transform: translateY(0); - opacity: 1; - transition: - opacity 0.1s 0.5s, - transform 0.4s 0.5s; +.onto-teaser { + display: none; } -.header { +.banner { width: 100%; - height: 220px; } -.main { +.banner h1, .banner h2, .banner img{ + padding: 0; + margin: 0px 20px; + vertical-align: middle; + text-align: center; +} + +.banner h1{ + font-size: 300%; +} + +.banner h2{ + font-size: 150%; +} + +.onto_container +{ + margin-right: auto; + margin-left: auto; + padding-left: 20px; + padding-right: 20px; + width: 1180px; +} + +.article { + margin-top: 20px; + margin-bottom: 20px; +} + +#nav { + z-index: 1000000; + position: absolute; width: 100%; - height: auto; - display: flex; + transition: all 0.5s ease; } -.main-left, .main-right { - width: 280px; - height: auto; +.navbar { + position: relative; + min-height: 50px; + margin-bottom: 20px; + border: 1px solid transparent; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; } -.main-left > button, .main-right > button { - display:block; +.navbar-default { + background-color: #324a5e; + border-color: #324a5e; } -.main-center { - width: calc(100% - 280px * 2); +.navbar-default .navbar-brand, +.navbar-default .navbar-nav > li > a { + color: #fff; } -@keyframes up-box { - 0% {height: 0%;} - 100% {height: 100%;} +.navbar-default .navbar-brand:hover, +.navbar-default .navbar-nav > li > a:hover { + color: #ccc; } -@keyframes middle-box { - from {width: 0%;} - to {width: calc(100% - 180px);} +.navbar-brand img { + width: auto; + height: 20px; + -webkit-filter: invert(1); + filter: invert(1); } -@keyframes bottom-box { - 0% {height: 0%;} - 100% {height: calc(100% - 220px);} +.navbar-brand > img { + display: inline; + margin-right: 10px; } -/* The element to apply the animation to */ -.up-stripe { +.nav > li > a { position: relative; - margin-left: auto; - margin-right: auto; - width: 100px; - height: 0%; - background-color: #324a5e; - animation-name: up-box; - animation-duration: 0.5s; - animation-fill-mode: forwards; - animation-timing-function: ease-out; + display: block; + padding: 10px 15px; +} + +.nav::before { + content: " "; + display: table; +} + +.jumbotron { + background: url(../img/background.png) no-repeat center center; + background-size: auto; + background-size: cover; + padding-bottom: 5px; + padding: 0; +} + +.jumbotron { + margin-top: 50px; +} + +.jumboopaque { + padding: 20px; + background-color: rgba(240, 240, 240, 0.8); +} + +.jumbo-list-item { + color: #202020; + text-decoration: none; +} + +.jumbo-list-item:hover { + color: #000; + text-decoration: underline; +} + +.github-icon { + margin-top: -6px; + width: 18px; + height: 20px; + -webkit-filter: invert(1); + filter: invert(1); +} + +.btn { + margin-top: 10px; + margin-bottom: 10px; +} + +.btn-custom { + color: #ffffff; + background-color: #808282; + border-color: #808282; } -.middle-stripe { +.btn-custom:hover { + color: #eeeeee; + background-color: #707272; + border-color: #707272; +} + +.jumbo-list { + padding-left: 0px; +} + +.jumbo-list-item { + padding: 10px; + min-width: 100px !important; + display: inline-block; + text-transform: uppercase; + font-size: 16px; +} + +.onto-content h1 { + border-left: 5px solid #324a5e; + border-bottom: 2px solid #324a5e; + padding-left: 10px; +} + +.onto-grid-item { + height: 200px; + margin-bottom: 40px; + background-size: contain; + background-position: center; position: relative; - margin-left: auto; - margin-right: auto; - bottom: 100px; - width: 0%; - height: 100px; - background-color: #324a5e; - animation-name: middle-box; - animation-duration: 1.2s; - animation-delay: 0.3s; - animation-fill-mode: forwards; - animation-timing-function: ease-in; - text-align: center; - text-indent: -150px; + overflow: hidden; + transition: all 0.5s ease; + background-repeat: no-repeat; +} + +.onto-grid-item:hover .onto-grid-item-title { + right: -190px; } -.page-title { +.onto-grid-item:hover .onto-grid-item-menu { + left: 0px; +} + +.onto-grid-item-content { + width: 100%; + background-color: rgba(150, 150, 150, 0.3); + height: 100%; + transition: all 0.5s ease; +} + +.onto-grid-print-img { + display: none; +} + +.onto-grid-item-title { + background-color: #324a5e; + max-width: 80%; + padding: 5px 20px; + top: 0px; position: absolute; - padding-top: 25px; - width: 300px; - font-family:Bookman; - font-size: 50px; - color: white; + right: 0px; + transition: all 1.0s ease; +} - opacity:0; - animation-name: appear; - animation-duration: 2s; - animation-delay: 2.5s; - animation-fill-mode: forwards; +.onto-grid-item-title h4 { + color: #fff; } -.right-side-stripe, .left-side-stripe { +.onto-grid-item-menu { + width: 215px; + height: 200px; + background-color: #808282; position: absolute; - margin-left: 90px; - width: 100px; - height: 0%; - background-color: #324a5e; - animation-name: bottom-box; - animation-duration: 1s; - animation-delay: 1.5s; - animation-fill-mode: forwards; + left: -190px; + transition: all 1.0s ease; } -.bl1 { - top: 300px; - transition: - top 1.0s, +.onto-grid-item-menu .glyphicon { + position: absolute; + right: 5px; + top: 90px; + color: #fff; } -.bl1:hover { - top: calc(300px - 130px + 70px); - transition: - top 1.2s, + +.onto-grid-item-menu ul { + list-style: none; + padding: 0; + width: 190px; + overflow: hidden; } -.bl2 { - top: calc(300px + 280px); - transition: - top 1.0s, +.onto-grid-item-menu li { + height: 50px; + line-height: 50px; + transition: all 0.25s ease; + font-size: 2rem; + padding: 0 20px; + color: #fff; +} + +.onto-grid-item-menu li a { + color: #ffffff; + text-decoration: none; + width: 100%; + height: 100%; + display: inline-block; +} + +.onto-grid-item-link { + width: 100%; + height: 100%; + display: block; } -.bl2:hover { - top: calc(300px + 280px - 130px + 70px); - transition: - top 1.2s, + +footer { + line-height:1; + font-family:Arial, Helvetica, sans-serif; + font-weight:400; + transition-duration:1s; + font-size: 16px; + background-color:#324a5e; + color:#ffffff; + height: 80px; + padding: 10px; } -.bl3 { - top: calc(300px + 280px * 2); - transition: - top 1.0s, +a.laas_logo { + color:#ffffff; + margin: auto auto auto auto; + position:relative; } -.bl3:hover { - top: calc(300px + 280px * 2 - 130px + 70px); - transition: - top 1.2s, + +@media (min-width: 768px) { + .container { + width: 760px; + } + + .onto-teaser { + display: inline; + } + + .navbar-nav { + float: left; + margin: 0; + } + + .navbar { + border-radius: 0; + } + + .navbar-nav > li > a { + padding-top: 15px; + padding-bottom: 15px; + } } -.main-content { - margin-top: 50px; +@media (min-width: 992px) { + .container { + width: 980px; + } } -hr { - height: .25em; - padding: 0; - margin: 24px 0; - background-color: #a1a4a8; - border: 0; +@media (min-width: 1200px) { + .container { + width: 1180px; + } } From 6092137b8ce9948b69bcd04f0746075b14a733f7 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Thu, 18 Jul 2019 08:49:52 +0200 Subject: [PATCH 04/95] [ADD] LinkedFact --- .../mementar/core/EpisodicTree/ArchivedLeaf.h | 2 +- .../core/EpisodicTree/ArchivedLeafNode.h | 12 +++--- .../core/EpisodicTree/CompressedLeaf.h | 8 ++-- .../core/EpisodicTree/CompressedLeafNode.h | 18 ++++----- .../EpisodicTree/CompressedLeafNodeSession.h | 16 ++++---- .../core/EpisodicTree/CompressedLeafSession.h | 4 +- include/mementar/core/EpisodicTree/Context.h | 4 +- include/mementar/core/LinkedFact.h | 30 +++++++++++++++ src/RosInterface.cpp | 6 +-- src/core/EpisodicTree/ArchivedLeaf.cpp | 6 +-- src/core/EpisodicTree/ArchivedLeafNode.cpp | 20 +++++----- src/core/EpisodicTree/CompressedLeaf.cpp | 14 +++---- src/core/EpisodicTree/CompressedLeafNode.cpp | 38 +++++++++---------- .../CompressedLeafNodeSession.cpp | 28 +++++++------- .../EpisodicTree/CompressedLeafSession.cpp | 6 +-- src/core/EpisodicTree/Context.cpp | 24 ++++++------ 16 files changed, 133 insertions(+), 103 deletions(-) create mode 100644 include/mementar/core/LinkedFact.h diff --git a/include/mementar/core/EpisodicTree/ArchivedLeaf.h b/include/mementar/core/EpisodicTree/ArchivedLeaf.h index 6ca96eb..58479b1 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeaf.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeaf.h @@ -18,7 +18,7 @@ class ArchivedLeaf std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - Btree* getTree(size_t i); + Btree* getTree(size_t i); std::vector getContexts(); private: diff --git a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h index e8adfac..3fe0aee 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h @@ -14,12 +14,12 @@ class ArchivedLeafNode ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); - void insert(const time_t& key, const Fact& data); - void remove(const time_t& key, const Fact& data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + void insert(const time_t& key, const LinkedFact& data); + void remove(const time_t& key, const LinkedFact& data); + BtreeLeaf* find(const time_t& key); + BtreeLeaf* findNear(const time_t& key); + BtreeLeaf* getFirst(); + BtreeLeaf* getLast(); void display(time_t key); diff --git a/include/mementar/core/EpisodicTree/CompressedLeaf.h b/include/mementar/core/EpisodicTree/CompressedLeaf.h index 7fed08e..8a81366 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeaf.h +++ b/include/mementar/core/EpisodicTree/CompressedLeaf.h @@ -5,7 +5,7 @@ #include #include "mementar/core/Btree/Btree.h" -#include "mementar/core/Fact.h" +#include "mementar/core/LinkedFact.h" namespace mementar { @@ -13,18 +13,18 @@ namespace mementar class CompressedLeaf { public: - CompressedLeaf(Btree* tree, const std::string& directory); + CompressedLeaf(Btree* tree, const std::string& directory); CompressedLeaf(const time_t& key, const std::string& directory); std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - Btree* getTree(); + Btree* getTree(); private: time_t key_; std::string directory_; - std::string treeToString(Btree* tree); + std::string treeToString(Btree* tree); }; } // namespace mementar diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/EpisodicTree/CompressedLeafNode.h index cb530a8..59884d6 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNode.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/Fact.h" +#include "mementar/core/LinkedFact.h" #include "mementar/core/Btree/Btree.h" #include "mementar/core/EpisodicTree/CompressedLeaf.h" #include "mementar/core/EpisodicTree/Context.h" @@ -25,12 +25,12 @@ class CompressedLeafNode CompressedLeafNode* split(); - void insert(const time_t& key, const Fact& data); - void remove(const time_t& key, const Fact& data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + void insert(const time_t& key, const LinkedFact& data); + void remove(const time_t& key, const LinkedFact& data); + BtreeLeaf* find(const time_t& key); + BtreeLeaf* findNear(const time_t& key); + BtreeLeaf* getFirst(); + BtreeLeaf* getLast(); void display(time_t key); size_t size() { return keys_.size(); } @@ -58,9 +58,9 @@ class CompressedLeafNode // keys_[i] correspond to the first key of child i std::vector keys_; std::vector contexts_; - std::vector*> btree_childs_; + std::vector*> btree_childs_; std::vector compressed_childs_; - std::vector*> compressed_sessions_tree_; + std::vector*> compressed_sessions_tree_; std::vector compressed_sessions_timeout_; //ms std::vector modified_; diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h index b5a0567..3ff5209 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/Fact.h" +#include "mementar/core/LinkedFact.h" #include "mementar/core/Btree/Btree.h" #include "mementar/core/EpisodicTree/CompressedLeafSession.h" #include "mementar/core/EpisodicTree/Context.h" @@ -23,12 +23,12 @@ class CompressedLeafNodeSession CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); - void insert(const time_t& key, const Fact& data); - bool remove(const time_t& key, const Fact& data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + void insert(const time_t& key, const LinkedFact& data); + bool remove(const time_t& key, const LinkedFact& data); + BtreeLeaf* find(const time_t& key); + BtreeLeaf* findNear(const time_t& key); + BtreeLeaf* getFirst(); + BtreeLeaf* getLast(); time_t getKey() { @@ -49,7 +49,7 @@ class CompressedLeafNodeSession // keys_[i] correspond to the first key of child i std::vector contexts_; std::vector childs_; - std::vector*> sessions_tree_; + std::vector*> sessions_tree_; std::vector modified_; time_t earlier_key_; diff --git a/include/mementar/core/EpisodicTree/CompressedLeafSession.h b/include/mementar/core/EpisodicTree/CompressedLeafSession.h index adb75ec..fccc8d1 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafSession.h @@ -5,7 +5,7 @@ #include "mementar/core/archiving_compressing/archiving/Header.h" #include "mementar/core/Btree/Btree.h" -#include "mementar/core/Fact.h" +#include "mementar/core/LinkedFact.h" namespace mementar { @@ -18,7 +18,7 @@ class CompressedLeafSession time_t getKey() { return key_; } size_t getIndex() { return index_; } - Btree* getTree(Header& header, Archive& arch); + Btree* getTree(Header& header, Archive& arch); std::vector getRawData(Header& header, Archive& arch); private: time_t key_; diff --git a/include/mementar/core/EpisodicTree/Context.h b/include/mementar/core/EpisodicTree/Context.h index 1e5547a..51cd8e0 100644 --- a/include/mementar/core/EpisodicTree/Context.h +++ b/include/mementar/core/EpisodicTree/Context.h @@ -15,8 +15,8 @@ class Context public: Context(time_t key) { key_ = key; } - void insert(const Fact& fact); - void remove(const Fact& fact); + void insert(const Fact* fact); + void remove(const Fact* fact); bool exist(const std::string& name); bool subjectExist(const std::string& subject); diff --git a/include/mementar/core/LinkedFact.h b/include/mementar/core/LinkedFact.h new file mode 100644 index 0000000..17dba56 --- /dev/null +++ b/include/mementar/core/LinkedFact.h @@ -0,0 +1,30 @@ +#ifndef MEMENTAR_LINKEDFACT_H +#define MEMENTAR_LINKEDFACT_H + +#include "mementar/core/Fact.h" + +namespace mementar +{ + +class LinkedFact : public Fact +{ +public: + LinkedFact(const std::string& subject, const std::string& predicat, const std::string& object) : Fact(subject, predicat, object) + { + next_ = nullptr; + prev_ = nullptr; + } + + LinkedFact(const std::string& triplet = "") : Fact(triplet) + { + next_ = nullptr; + prev_ = nullptr; + } + + LinkedFact* next_; + LinkedFact* prev_; +}; + +} // namespace mementar + +#endif // MEMENTAR_LINKEDFACT_H diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 20a8789..f08ab1e 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -77,7 +77,7 @@ void RosInterface::reset() void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { - Fact fact(msg->data); + LinkedFact fact(msg->data); if(fact.valid()) { mut_.lock_shared(); @@ -89,7 +89,7 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { - Fact fact(msg->data); + LinkedFact fact(msg->data); if(fact.valid()) { mut_.lock_shared(); @@ -109,7 +109,7 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, if(req.action == "remove") { - Fact fact(req.param); + LinkedFact fact(req.param); if(fact.valid()) { mut_.lock_shared(); diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index 90c9f26..e4f12d2 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -58,7 +58,7 @@ ArchivedLeaf::ArchivedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -Btree* ArchivedLeaf::getTree(size_t i) +Btree* ArchivedLeaf::getTree(size_t i) { mementar::Archive arch; std::cout << "ArchivedLeaf::getTree READ BINARY FILE " << directory_ << ".mar" << std::endl; @@ -71,7 +71,7 @@ Btree* ArchivedLeaf::getTree(size_t i) LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); lz.uncompress(comp_data, out); - Btree* tree = new Btree(); + Btree* tree = new Btree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); std::smatch match; @@ -82,7 +82,7 @@ Btree* ArchivedLeaf::getTree(size_t i) { if(std::regex_match(line, match, regex)) { - Fact fact(match[2].str(), match[3].str(), match[4].str()); + LinkedFact fact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index 83a1bea..b824b69 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -50,7 +50,7 @@ ArchivedLeafNode::~ArchivedLeafNode() mut_.unlock(); } -void ArchivedLeafNode::insert(const time_t& key, const Fact& data) +void ArchivedLeafNode::insert(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -117,7 +117,7 @@ void ArchivedLeafNode::insert(const time_t& key, const Fact& data) earlier_key_ = key; } -void ArchivedLeafNode::remove(const time_t& key, const Fact& data) +void ArchivedLeafNode::remove(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); int index = getKeyIndex(key); @@ -137,9 +137,9 @@ void ArchivedLeafNode::remove(const time_t& key, const Fact& data) mut_.unlock_shared(); } -BtreeLeaf* ArchivedLeafNode::find(const time_t& key) +BtreeLeaf* ArchivedLeafNode::find(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -159,9 +159,9 @@ BtreeLeaf* ArchivedLeafNode::find(const time_t& key) return res; } -BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) +BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -182,9 +182,9 @@ BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) return res; } -BtreeLeaf* ArchivedLeafNode::getFirst() +BtreeLeaf* ArchivedLeafNode::getFirst() { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); if(archived_childs_.size()) @@ -201,9 +201,9 @@ BtreeLeaf* ArchivedLeafNode::getFirst() return res; } -BtreeLeaf* ArchivedLeafNode::getLast() +BtreeLeaf* ArchivedLeafNode::getLast() { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); if(compressed_childs_.size()) diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index b691a1d..1a3139d 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -9,7 +9,7 @@ namespace mementar { -CompressedLeaf::CompressedLeaf(Btree* tree, const std::string& directory) +CompressedLeaf::CompressedLeaf(Btree* tree, const std::string& directory) { if(tree == nullptr) return; @@ -33,7 +33,7 @@ CompressedLeaf::CompressedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -Btree* CompressedLeaf::getTree() +Btree* CompressedLeaf::getTree() { std::string out; @@ -42,7 +42,7 @@ Btree* CompressedLeaf::getTree() if(lz.readBinaryFile(data, directory_ + ".mlz")) { lz.uncompress(data, out); - Btree* tree = new Btree(); + Btree* tree = new Btree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); std::smatch match; @@ -53,7 +53,7 @@ Btree* CompressedLeaf::getTree() { if(std::regex_match(line, match, regex)) { - Fact fact(match[2].str(), match[3].str(), match[4].str()); + LinkedFact fact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; @@ -68,11 +68,11 @@ Btree* CompressedLeaf::getTree() return nullptr; } -std::string CompressedLeaf::treeToString(Btree* tree) +std::string CompressedLeaf::treeToString(Btree* tree) { std::string res; - std::vector tmp_data; - BtreeLeaf* it = tree->getFirst(); + std::vector tmp_data; + BtreeLeaf* it = tree->getFirst(); while(it != nullptr) { tmp_data = it->getData(); diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/EpisodicTree/CompressedLeafNode.cpp index 5404b6d..0cffdc8 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/EpisodicTree/CompressedLeafNode.cpp @@ -88,7 +88,7 @@ CompressedLeafNode* CompressedLeafNode::split() return new_one; } -void CompressedLeafNode::insert(const time_t& key, const Fact& data) +void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -97,7 +97,7 @@ void CompressedLeafNode::insert(const time_t& key, const Fact& data) createNewTreeChild(key); mut_.lock_shared(); last_tree_nb_leafs_ = btree_childs_[0]->insert(key, data); - contexts_[0].insert(data); + contexts_[0].insert(&data); } else { @@ -117,7 +117,7 @@ void CompressedLeafNode::insert(const time_t& key, const Fact& data) createNewTreeChild(key); mut_.lock_shared(); last_tree_nb_leafs_ = btree_childs_[0]->insert(key, data); - contexts_[keys_.size() - 1].insert(data); + contexts_[keys_.size() - 1].insert(&data); } else { @@ -125,7 +125,7 @@ void CompressedLeafNode::insert(const time_t& key, const Fact& data) createSession(index); mut_.lock_shared(); compressed_sessions_tree_[index]->insert(key, data); - contexts_[index].insert(data); + contexts_[index].insert(&data); modified_[index] = true; } } @@ -135,7 +135,7 @@ void CompressedLeafNode::insert(const time_t& key, const Fact& data) createNewTreeChild(key); mut_.lock_shared(); last_tree_nb_leafs_ = btree_childs_[btree_childs_.size() - 1]->insert(key, data); - contexts_[keys_.size() - 1].insert(data); + contexts_[keys_.size() - 1].insert(&data); //verify if a chld need to be compressed if(btree_childs_.size() > 2) @@ -148,12 +148,12 @@ void CompressedLeafNode::insert(const time_t& key, const Fact& data) else if(index - keys_.size() + 1 == 0) // if insert in more recent tree { last_tree_nb_leafs_ = btree_childs_[index - compressed_childs_.size()]->insert(key,data); - contexts_[index].insert(data); + contexts_[index].insert(&data); } else { btree_childs_[index - compressed_childs_.size()]->insert(key,data); - contexts_[index].insert(data); + contexts_[index].insert(&data); } } mut_.unlock_shared(); @@ -162,7 +162,7 @@ void CompressedLeafNode::insert(const time_t& key, const Fact& data) earlier_key_ = key; } -void CompressedLeafNode::remove(const time_t& key, const Fact& data) +void CompressedLeafNode::remove(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); int index = getKeyIndex(key); @@ -176,21 +176,21 @@ void CompressedLeafNode::remove(const time_t& key, const Fact& data) if(compressed_sessions_tree_[index]->remove(key, data)) { modified_[index] = true; - contexts_[index].remove(data); + contexts_[index].remove(&data); } } else { if(btree_childs_[index - compressed_childs_.size()]->remove(key, data)) - contexts_[index].remove(data); + contexts_[index].remove(&data); } } mut_.unlock_shared(); } -BtreeLeaf* CompressedLeafNode::find(const time_t& key) +BtreeLeaf* CompressedLeafNode::find(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -210,9 +210,9 @@ BtreeLeaf* CompressedLeafNode::find(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) +BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -233,9 +233,9 @@ BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNode::getFirst() +BtreeLeaf* CompressedLeafNode::getFirst() { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); if(compressed_childs_.size()) @@ -252,9 +252,9 @@ BtreeLeaf* CompressedLeafNode::getFirst() return res; } -BtreeLeaf* CompressedLeafNode::getLast() +BtreeLeaf* CompressedLeafNode::getLast() { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); if(btree_childs_.size()) @@ -295,7 +295,7 @@ void CompressedLeafNode::init() void CompressedLeafNode::createNewTreeChild(const time_t& key) { mut_.lock(); - btree_childs_.push_back(new Btree(order_)); + btree_childs_.push_back(new Btree(order_)); keys_.push_back(key); contexts_.push_back(Context(key)); mut_.unlock(); diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index d8a5fe2..9f47f3e 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -58,7 +58,7 @@ int CompressedLeafNodeSession::getKeyIndex(const time_t& key) return index; } -void CompressedLeafNodeSession::insert(const time_t& key, const Fact& data) +void CompressedLeafNodeSession::insert(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); if(contexts_.size() == 0) @@ -78,14 +78,14 @@ void CompressedLeafNodeSession::insert(const time_t& key, const Fact& data) createSession(index); mut_.lock_shared(); sessions_tree_[index]->insert(key, data); - contexts_[index].insert(data); + contexts_[index].insert(&data); modified_[index] = true; } mut_.unlock_shared(); } -bool CompressedLeafNodeSession::remove(const time_t& key, const Fact& data) +bool CompressedLeafNodeSession::remove(const time_t& key, const LinkedFact& data) { bool res = false; mut_.lock_shared(); @@ -98,7 +98,7 @@ bool CompressedLeafNodeSession::remove(const time_t& key, const Fact& data) if(sessions_tree_[index]->remove(key, data)) { modified_[index] = true; - contexts_[index].remove(data); + contexts_[index].remove(&data); res = true; } } @@ -106,9 +106,9 @@ bool CompressedLeafNodeSession::remove(const time_t& key, const Fact& data) return res; } -BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key) +BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -123,9 +123,9 @@ BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& key) +BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -141,9 +141,9 @@ BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNodeSession::getFirst() +BtreeLeaf* CompressedLeafNodeSession::getFirst() { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; createSession(0); mut_.lock_shared(); @@ -153,9 +153,9 @@ BtreeLeaf* CompressedLeafNodeSession::getFirst() return res; } -BtreeLeaf* CompressedLeafNodeSession::getLast() +BtreeLeaf* CompressedLeafNodeSession::getLast() { - BtreeLeaf* res = nullptr; + BtreeLeaf* res = nullptr; createSession(childs_.size() - 1); mut_.lock_shared(); @@ -200,8 +200,8 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) { std::string res; - std::vector tmp_data; - BtreeLeaf* it = sessions_tree_[index]->getFirst(); + std::vector tmp_data; + BtreeLeaf* it = sessions_tree_[index]->getFirst(); while(it != nullptr) { tmp_data = it->getData(); diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index 7af9b51..d462bf1 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -13,7 +13,7 @@ CompressedLeafSession::CompressedLeafSession(const time_t& key, size_t index) index_ = index; } -Btree* CompressedLeafSession::getTree(Header& header, Archive& arch) +Btree* CompressedLeafSession::getTree(Header& header, Archive& arch) { std::string comp = arch.extractFile(index_, header); @@ -21,7 +21,7 @@ Btree* CompressedLeafSession::getTree(Header& header, Archive& arc LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); lz.uncompress(comp_data, out); - Btree* tree = new Btree(); + Btree* tree = new Btree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); std::smatch match; @@ -32,7 +32,7 @@ Btree* CompressedLeafSession::getTree(Header& header, Archive& arc { if(std::regex_match(line, match, regex)) { - Fact fact(match[2].str(), match[3].str(), match[4].str()); + LinkedFact fact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; diff --git a/src/core/EpisodicTree/Context.cpp b/src/core/EpisodicTree/Context.cpp index 1d70d0d..f69ff1e 100644 --- a/src/core/EpisodicTree/Context.cpp +++ b/src/core/EpisodicTree/Context.cpp @@ -10,45 +10,45 @@ namespace mementar { -void Context::insert(const Fact& fact) +void Context::insert(const Fact* fact) { std::map::iterator it; - it = subjects_.find(fact.subject_); + it = subjects_.find(fact->subject_); if(it != subjects_.end()) it->second++; else - subjects_[fact.subject_] = 1; + subjects_[fact->subject_] = 1; - it = predicats_.find(fact.predicat_); + it = predicats_.find(fact->predicat_); if(it != predicats_.end()) it->second++; else - predicats_[fact.predicat_] = 1; + predicats_[fact->predicat_] = 1; - if(fact.object_.find(":") == std::string::npos) + if(fact->object_.find(":") == std::string::npos) { - it = objects_.find(fact.object_); + it = objects_.find(fact->object_); if(it != objects_.end()) it->second++; else - objects_[fact.object_] = 1; + objects_[fact->object_] = 1; } } -void Context::remove(const Fact& fact) +void Context::remove(const Fact* fact) { std::map::iterator it; - it = subjects_.find(fact.subject_); + it = subjects_.find(fact->subject_); if(it != subjects_.end()) it->second--; - it = predicats_.find(fact.predicat_); + it = predicats_.find(fact->predicat_); if(it != predicats_.end()) it->second--; - it = objects_.find(fact.object_); + it = objects_.find(fact->object_); if(it != objects_.end()) it->second--; } From c7b13dcd0a0bbc4a6306c3f51402b74f78ac9513 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Thu, 18 Jul 2019 17:39:39 +0200 Subject: [PATCH 05/95] [REFACT] data to pointer --- include/mementar/core/Btree/Btree.h | 10 +++++----- include/mementar/core/Btree/BtreeLeaf.h | 19 ++++++++++++------- include/mementar/core/Btree/BtreeLeafNode.h | 8 ++++---- include/mementar/core/Btree/BtreeNode.h | 4 ++-- .../core/EpisodicTree/ArchivedLeafNode.h | 2 +- .../core/EpisodicTree/CompressedLeafNode.h | 2 +- .../EpisodicTree/CompressedLeafNodeSession.h | 2 +- include/mementar/core/Fact.h | 4 ++-- include/mementar/core/LinkedFact.h | 6 ++++++ .../core/Occasions/OccasionsManager.h | 8 ++++---- src/RosInterface.cpp | 8 ++++---- src/core/EpisodicTree/ArchivedLeaf.cpp | 2 +- src/core/EpisodicTree/ArchivedLeafNode.cpp | 2 +- src/core/EpisodicTree/CompressedLeaf.cpp | 8 ++++---- src/core/EpisodicTree/CompressedLeafNode.cpp | 14 +++++++------- .../CompressedLeafNodeSession.cpp | 10 +++++----- .../EpisodicTree/CompressedLeafSession.cpp | 2 +- src/core/Occasions/OccasionsManager.cpp | 14 +++++++------- 18 files changed, 68 insertions(+), 57 deletions(-) diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index 1cec619..ad5c84e 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -38,7 +38,7 @@ class Btree } } - size_t insert(const Tkey& key, const Tdata& data); + size_t insert(const Tkey& key, const Tdata* data); bool remove(const Tkey& key, const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); @@ -68,7 +68,7 @@ class Btree }; template -size_t Btree::insert(const Tkey& key, const Tdata& data) +size_t Btree::insert(const Tkey& key, const Tdata* data) { nb_data_++; if(last_ == nullptr) @@ -139,10 +139,10 @@ void Btree::display(int count) std::cout << "******" << std::endl; while((tmp != nullptr) && ((cpt < count) || (count == -1))) { - std::vector datas = tmp->getData(); + std::vector datas = tmp->getData(); std::cout << tmp->getKey() << " => "; - for(const auto& data : datas) - std::cout << data << " : "; + for(auto data : datas) + std::cout << *data << " : "; std::cout << std::endl; tmp = tmp->prev_; cpt++; diff --git a/include/mementar/core/Btree/BtreeLeaf.h b/include/mementar/core/Btree/BtreeLeaf.h index 7ed1a7c..ef850e4 100644 --- a/include/mementar/core/Btree/BtreeLeaf.h +++ b/include/mementar/core/Btree/BtreeLeaf.h @@ -13,7 +13,7 @@ template class BtreeLeaf { public: - BtreeLeaf(const Tkey& key, const Tdata& data) + BtreeLeaf(const Tkey& key, const Tdata* data) { next_ = nullptr; prev_ = nullptr; @@ -23,9 +23,14 @@ class BtreeLeaf data_.push_back(data); } - ~BtreeLeaf() {} + ~BtreeLeaf() + { + for(auto data : data_) + delete data; + data_.clear(); + } - void push_back(const Tdata& data) { data_.push_back(data); } + void push_back(const Tdata* data) { data_.push_back(data); } void remove(const Tdata& data); BtreeLeaf* next_; @@ -44,15 +49,15 @@ class BtreeLeaf bool operator<=(const BtreeLeaf* other) { return ((key_ < other->key_) || (key_ == other->key_)); } Tkey getKey() const { return key_; } - std::vector getData() const { return data_; } - void getData(std::vector& data) { data = data_; } + std::vector getData() const { return data_; } + void getData(std::vector& data) { data = data_; } void setMother(BtreeLeafNode* mother) { mother_ = mother; } BtreeLeafNode* getMother() { return mother_; } private: Tkey key_; - std::vector data_; + std::vector data_; BtreeLeafNode* mother_; }; @@ -61,7 +66,7 @@ void BtreeLeaf::remove(const Tdata& data) { for(size_t i = 0; i < data_.size();) { - if(data_[i] == data) + if(data_[i]->operator==(data)) data_.erase(data_.begin() + i); else i++; diff --git a/include/mementar/core/Btree/BtreeLeafNode.h b/include/mementar/core/Btree/BtreeLeafNode.h index 0b8fc31..80d7dbd 100644 --- a/include/mementar/core/Btree/BtreeLeafNode.h +++ b/include/mementar/core/Btree/BtreeLeafNode.h @@ -16,7 +16,7 @@ class BtreeLeafNode : public BtreeNode ~BtreeLeafNode() {} - BtreeLeaf* insert(const Tkey& key, const Tdata& data); + BtreeLeaf* insert(const Tkey& key, const Tdata* data); bool remove(const Tkey& key, const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); @@ -31,7 +31,7 @@ class BtreeLeafNode : public BtreeNode }; template -BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, const Tdata& data) +BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, const Tdata* data) { BtreeLeaf* res = nullptr; @@ -196,10 +196,10 @@ void BtreeLeafNode::display(size_t depth) { for(size_t j = 0; j < depth; j++) std::cout << "\t"; - std::vector datas = leafs_[i]->getData(); + std::vector datas = leafs_[i]->getData(); std::cout << this->keys_[i] << " => "; for(auto data : datas) - std::cout << data << " : "; + std::cout << *data << " : "; std::cout << std::endl; } } diff --git a/include/mementar/core/Btree/BtreeNode.h b/include/mementar/core/Btree/BtreeNode.h index 4a30bcc..9321adb 100644 --- a/include/mementar/core/Btree/BtreeNode.h +++ b/include/mementar/core/Btree/BtreeNode.h @@ -25,7 +25,7 @@ class BtreeNode delete child; } - virtual BtreeLeaf* insert(const Tkey& key, const Tdata& data); + virtual BtreeLeaf* insert(const Tkey& key, const Tdata* data); void insert(BtreeNode* new_node, const Tkey& key); virtual bool remove(const Tkey& key, const Tdata& data); virtual BtreeLeaf* find(const Tkey& key); @@ -53,7 +53,7 @@ class BtreeNode }; template -BtreeLeaf* BtreeNode::insert(const Tkey& key, const Tdata& data) +BtreeLeaf* BtreeNode::insert(const Tkey& key, const Tdata* data) { size_t index = childs_.size() - 1; for(size_t i = 0; i < this->keys_.size(); i++) diff --git a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h index 3fe0aee..ea2ae22 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h @@ -14,7 +14,7 @@ class ArchivedLeafNode ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); - void insert(const time_t& key, const LinkedFact& data); + void insert(const time_t& key, const LinkedFact* data); void remove(const time_t& key, const LinkedFact& data); BtreeLeaf* find(const time_t& key); BtreeLeaf* findNear(const time_t& key); diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/EpisodicTree/CompressedLeafNode.h index 59884d6..c56a388 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNode.h @@ -25,7 +25,7 @@ class CompressedLeafNode CompressedLeafNode* split(); - void insert(const time_t& key, const LinkedFact& data); + void insert(const time_t& key, const LinkedFact* data); void remove(const time_t& key, const LinkedFact& data); BtreeLeaf* find(const time_t& key); BtreeLeaf* findNear(const time_t& key); diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h index 3ff5209..beac8bc 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h @@ -23,7 +23,7 @@ class CompressedLeafNodeSession CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); - void insert(const time_t& key, const LinkedFact& data); + void insert(const time_t& key, const LinkedFact* data); bool remove(const time_t& key, const LinkedFact& data); BtreeLeaf* find(const time_t& key); BtreeLeaf* findNear(const time_t& key); diff --git a/include/mementar/core/Fact.h b/include/mementar/core/Fact.h index 2caad0f..cff2ce4 100644 --- a/include/mementar/core/Fact.h +++ b/include/mementar/core/Fact.h @@ -28,12 +28,12 @@ class Fact object_ = splitted[2]; } - bool valid() + bool valid() const { return((subject_ != "") && (predicat_ != "") && (object_ != "")); } - std::string toString() + std::string toString() const { return subject_ + "|" + predicat_ + "|" + object_; } diff --git a/include/mementar/core/LinkedFact.h b/include/mementar/core/LinkedFact.h index 17dba56..e6cf54d 100644 --- a/include/mementar/core/LinkedFact.h +++ b/include/mementar/core/LinkedFact.h @@ -21,6 +21,12 @@ class LinkedFact : public Fact prev_ = nullptr; } + bool isEventPart(const LinkedFact& other) const + { + return ((subject_ == other.subject_) + && (predicat_ == other.predicat_)); + } + LinkedFact* next_; LinkedFact* prev_; }; diff --git a/include/mementar/core/Occasions/OccasionsManager.h b/include/mementar/core/Occasions/OccasionsManager.h index 625baf1..886a0b3 100644 --- a/include/mementar/core/Occasions/OccasionsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -23,7 +23,7 @@ class OccasionsManager void run(); - void add(const Fact& fact); + void add(const Fact* fact); void stop() {run_ = false; } inline bool isRunning() {return run_; } @@ -40,15 +40,15 @@ class OccasionsManager std::mutex mutex_; bool queue_choice_; - std::queue fifo_1; - std::queue fifo_2; + std::queue fifo_1; + std::queue fifo_2; bool SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res); bool UnsubscribeCallback(mementar::MementarOcassionUnsubscription::Request &req, mementar::MementarOcassionUnsubscription::Response &res); - Fact get(); + const Fact* get(); bool empty(); }; diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index f08ab1e..86d2929 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -77,8 +77,8 @@ void RosInterface::reset() void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { - LinkedFact fact(msg->data); - if(fact.valid()) + LinkedFact* fact = new LinkedFact(msg->data); + if(fact->valid()) { mut_.lock_shared(); tree_->insert(time(0), fact); @@ -89,8 +89,8 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { - LinkedFact fact(msg->data); - if(fact.valid()) + LinkedFact* fact = new LinkedFact(msg->data); + if(fact->valid()) { mut_.lock_shared(); tree_->insert(msg->stamp.sec, fact); diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index e4f12d2..f9d4bec 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -82,7 +82,7 @@ Btree* ArchivedLeaf::getTree(size_t i) { if(std::regex_match(line, match, regex)) { - LinkedFact fact(match[2].str(), match[3].str(), match[4].str()); + LinkedFact* fact = new LinkedFact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index b824b69..587dea8 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -50,7 +50,7 @@ ArchivedLeafNode::~ArchivedLeafNode() mut_.unlock(); } -void ArchivedLeafNode::insert(const time_t& key, const LinkedFact& data) +void ArchivedLeafNode::insert(const time_t& key, const LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 1a3139d..3c2cfd7 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -53,7 +53,7 @@ Btree* CompressedLeaf::getTree() { if(std::regex_match(line, match, regex)) { - LinkedFact fact(match[2].str(), match[3].str(), match[4].str()); + LinkedFact* fact = new LinkedFact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; @@ -71,13 +71,13 @@ Btree* CompressedLeaf::getTree() std::string CompressedLeaf::treeToString(Btree* tree) { std::string res; - std::vector tmp_data; + std::vector tmp_data; BtreeLeaf* it = tree->getFirst(); while(it != nullptr) { tmp_data = it->getData(); - for(auto& data : tmp_data) - res += "[" + std::to_string(it->getKey()) + "]" + data.toString() + "\n"; + for(auto data : tmp_data) + res += "[" + std::to_string(it->getKey()) + "]" + data->toString() + "\n"; it = it->next_; } diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/EpisodicTree/CompressedLeafNode.cpp index 0cffdc8..3222d58 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/EpisodicTree/CompressedLeafNode.cpp @@ -88,7 +88,7 @@ CompressedLeafNode* CompressedLeafNode::split() return new_one; } -void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) +void CompressedLeafNode::insert(const time_t& key, const LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -97,7 +97,7 @@ void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) createNewTreeChild(key); mut_.lock_shared(); last_tree_nb_leafs_ = btree_childs_[0]->insert(key, data); - contexts_[0].insert(&data); + contexts_[0].insert(data); } else { @@ -117,7 +117,7 @@ void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) createNewTreeChild(key); mut_.lock_shared(); last_tree_nb_leafs_ = btree_childs_[0]->insert(key, data); - contexts_[keys_.size() - 1].insert(&data); + contexts_[keys_.size() - 1].insert(data); } else { @@ -125,7 +125,7 @@ void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) createSession(index); mut_.lock_shared(); compressed_sessions_tree_[index]->insert(key, data); - contexts_[index].insert(&data); + contexts_[index].insert(data); modified_[index] = true; } } @@ -135,7 +135,7 @@ void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) createNewTreeChild(key); mut_.lock_shared(); last_tree_nb_leafs_ = btree_childs_[btree_childs_.size() - 1]->insert(key, data); - contexts_[keys_.size() - 1].insert(&data); + contexts_[keys_.size() - 1].insert(data); //verify if a chld need to be compressed if(btree_childs_.size() > 2) @@ -148,12 +148,12 @@ void CompressedLeafNode::insert(const time_t& key, const LinkedFact& data) else if(index - keys_.size() + 1 == 0) // if insert in more recent tree { last_tree_nb_leafs_ = btree_childs_[index - compressed_childs_.size()]->insert(key,data); - contexts_[index].insert(&data); + contexts_[index].insert(data); } else { btree_childs_[index - compressed_childs_.size()]->insert(key,data); - contexts_[index].insert(&data); + contexts_[index].insert(data); } } mut_.unlock_shared(); diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index 9f47f3e..f561c7f 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -58,7 +58,7 @@ int CompressedLeafNodeSession::getKeyIndex(const time_t& key) return index; } -void CompressedLeafNodeSession::insert(const time_t& key, const LinkedFact& data) +void CompressedLeafNodeSession::insert(const time_t& key, const LinkedFact* data) { mut_.lock_shared(); if(contexts_.size() == 0) @@ -78,7 +78,7 @@ void CompressedLeafNodeSession::insert(const time_t& key, const LinkedFact& data createSession(index); mut_.lock_shared(); sessions_tree_[index]->insert(key, data); - contexts_[index].insert(&data); + contexts_[index].insert(data); modified_[index] = true; } @@ -200,13 +200,13 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) { std::string res; - std::vector tmp_data; + std::vector tmp_data; BtreeLeaf* it = sessions_tree_[index]->getFirst(); while(it != nullptr) { tmp_data = it->getData(); - for(auto& data : tmp_data) - res += "[" + std::to_string(it->getKey()) + "]" + data.toString() + "\n"; + for(auto data : tmp_data) + res += "[" + std::to_string(it->getKey()) + "]" + data->toString() + "\n"; it = it->next_; } diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index d462bf1..687b1cb 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -32,7 +32,7 @@ Btree* CompressedLeafSession::getTree(Header& header, Archiv { if(std::regex_match(line, match, regex)) { - LinkedFact fact(match[2].str(), match[3].str(), match[4].str()); + LinkedFact* fact = new LinkedFact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; diff --git a/src/core/Occasions/OccasionsManager.cpp b/src/core/Occasions/OccasionsManager.cpp index 38f1926..790d039 100644 --- a/src/core/Occasions/OccasionsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -27,15 +27,15 @@ void OccasionsManager::run() { while(!empty()) { - Fact fact = get(); - if(fact.valid()) + const Fact* fact = get(); + if(fact->valid()) { - std::vector ids = subscription_.evaluate(fact); + std::vector ids = subscription_.evaluate(*fact); for(auto id : ids) { mementar::MementarOccasion msg; msg.id = id; - msg.data = fact.toString(); + msg.data = fact->toString(); msg.last = subscription_.isFinished(id); pub_.publish(msg); } @@ -45,7 +45,7 @@ void OccasionsManager::run() } } -void OccasionsManager::add(const Fact& fact) +void OccasionsManager::add(const Fact* fact) { mutex_.lock(); if(queue_choice_ == true) @@ -78,9 +78,9 @@ bool OccasionsManager::UnsubscribeCallback(mementar::MementarOcassionUnsubscript return true; } -Fact OccasionsManager::get() +const Fact* OccasionsManager::get() { - Fact res; + const Fact* res; mutex_.lock(); if(queue_choice_ == true) { From 1a32131c42bcddff3af5877838c9588548ffc56e Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jul 2019 11:28:58 +0200 Subject: [PATCH 06/95] [REFACT] data to non const pointer --- include/mementar/core/Btree/Btree.h | 8 ++++---- include/mementar/core/Btree/BtreeLeaf.h | 10 +++++----- include/mementar/core/Btree/BtreeLeafNode.h | 12 ++++++------ include/mementar/core/Btree/BtreeNode.h | 4 ++-- include/mementar/core/EpisodicTree/ArchivedLeaf.h | 2 +- .../mementar/core/EpisodicTree/ArchivedLeafNode.h | 2 +- include/mementar/core/EpisodicTree/CompressedLeaf.h | 4 ++-- .../mementar/core/EpisodicTree/CompressedLeafNode.h | 8 ++++---- .../core/EpisodicTree/CompressedLeafNodeSession.h | 6 +++--- .../core/EpisodicTree/CompressedLeafSession.h | 4 ++-- include/mementar/core/LinkedFact.h | 5 +++++ src/core/EpisodicTree/ArchivedLeaf.cpp | 4 ++-- src/core/EpisodicTree/ArchivedLeafNode.cpp | 2 +- src/core/EpisodicTree/CompressedLeaf.cpp | 6 +++--- src/core/EpisodicTree/CompressedLeafNode.cpp | 4 ++-- src/core/EpisodicTree/CompressedLeafNodeSession.cpp | 4 ++-- src/core/EpisodicTree/CompressedLeafSession.cpp | 4 ++-- 17 files changed, 47 insertions(+), 42 deletions(-) diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index ad5c84e..2fd9af3 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -38,7 +38,7 @@ class Btree } } - size_t insert(const Tkey& key, const Tdata* data); + size_t insert(const Tkey& key, Tdata* data); bool remove(const Tkey& key, const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); @@ -59,7 +59,7 @@ class Btree void display(int count = -1); -private: +protected: BtreeNode* root_; BtreeLeaf* last_; size_t order_; @@ -68,7 +68,7 @@ class Btree }; template -size_t Btree::insert(const Tkey& key, const Tdata* data) +size_t Btree::insert(const Tkey& key, Tdata* data) { nb_data_++; if(last_ == nullptr) @@ -139,7 +139,7 @@ void Btree::display(int count) std::cout << "******" << std::endl; while((tmp != nullptr) && ((cpt < count) || (count == -1))) { - std::vector datas = tmp->getData(); + std::vector datas = tmp->getData(); std::cout << tmp->getKey() << " => "; for(auto data : datas) std::cout << *data << " : "; diff --git a/include/mementar/core/Btree/BtreeLeaf.h b/include/mementar/core/Btree/BtreeLeaf.h index ef850e4..8b982d4 100644 --- a/include/mementar/core/Btree/BtreeLeaf.h +++ b/include/mementar/core/Btree/BtreeLeaf.h @@ -13,7 +13,7 @@ template class BtreeLeaf { public: - BtreeLeaf(const Tkey& key, const Tdata* data) + BtreeLeaf(const Tkey& key, Tdata* data) { next_ = nullptr; prev_ = nullptr; @@ -30,7 +30,7 @@ class BtreeLeaf data_.clear(); } - void push_back(const Tdata* data) { data_.push_back(data); } + void push_back(Tdata* data) { data_.push_back(data); } void remove(const Tdata& data); BtreeLeaf* next_; @@ -49,15 +49,15 @@ class BtreeLeaf bool operator<=(const BtreeLeaf* other) { return ((key_ < other->key_) || (key_ == other->key_)); } Tkey getKey() const { return key_; } - std::vector getData() const { return data_; } - void getData(std::vector& data) { data = data_; } + std::vector getData() const { return data_; } + void getData(std::vector& data) { data = data_; } void setMother(BtreeLeafNode* mother) { mother_ = mother; } BtreeLeafNode* getMother() { return mother_; } private: Tkey key_; - std::vector data_; + std::vector data_; BtreeLeafNode* mother_; }; diff --git a/include/mementar/core/Btree/BtreeLeafNode.h b/include/mementar/core/Btree/BtreeLeafNode.h index 80d7dbd..f53561f 100644 --- a/include/mementar/core/Btree/BtreeLeafNode.h +++ b/include/mementar/core/Btree/BtreeLeafNode.h @@ -16,22 +16,22 @@ class BtreeLeafNode : public BtreeNode ~BtreeLeafNode() {} - BtreeLeaf* insert(const Tkey& key, const Tdata* data); - bool remove(const Tkey& key, const Tdata& data); + virtual BtreeLeaf* insert(const Tkey& key, Tdata* data); + virtual bool remove(const Tkey& key, const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); BtreeLeaf* getFirst(); virtual void display(size_t depth = 0); -private: +protected: std::vector*> leafs_; virtual bool needBalancing(); - void split(); + virtual void split(); }; template -BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, const Tdata* data) +BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, Tdata* data) { BtreeLeaf* res = nullptr; @@ -196,7 +196,7 @@ void BtreeLeafNode::display(size_t depth) { for(size_t j = 0; j < depth; j++) std::cout << "\t"; - std::vector datas = leafs_[i]->getData(); + std::vector datas = leafs_[i]->getData(); std::cout << this->keys_[i] << " => "; for(auto data : datas) std::cout << *data << " : "; diff --git a/include/mementar/core/Btree/BtreeNode.h b/include/mementar/core/Btree/BtreeNode.h index 9321adb..a88eb91 100644 --- a/include/mementar/core/Btree/BtreeNode.h +++ b/include/mementar/core/Btree/BtreeNode.h @@ -25,7 +25,7 @@ class BtreeNode delete child; } - virtual BtreeLeaf* insert(const Tkey& key, const Tdata* data); + virtual BtreeLeaf* insert(const Tkey& key, Tdata* data); void insert(BtreeNode* new_node, const Tkey& key); virtual bool remove(const Tkey& key, const Tdata& data); virtual BtreeLeaf* find(const Tkey& key); @@ -53,7 +53,7 @@ class BtreeNode }; template -BtreeLeaf* BtreeNode::insert(const Tkey& key, const Tdata* data) +BtreeLeaf* BtreeNode::insert(const Tkey& key, Tdata* data) { size_t index = childs_.size() - 1; for(size_t i = 0; i < this->keys_.size(); i++) diff --git a/include/mementar/core/EpisodicTree/ArchivedLeaf.h b/include/mementar/core/EpisodicTree/ArchivedLeaf.h index 58479b1..d0a09d8 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeaf.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeaf.h @@ -18,7 +18,7 @@ class ArchivedLeaf std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - Btree* getTree(size_t i); + LinkedBtree* getTree(size_t i); std::vector getContexts(); private: diff --git a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h index ea2ae22..0f16f9e 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h @@ -14,7 +14,7 @@ class ArchivedLeafNode ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); - void insert(const time_t& key, const LinkedFact* data); + void insert(const time_t& key, LinkedFact* data); void remove(const time_t& key, const LinkedFact& data); BtreeLeaf* find(const time_t& key); BtreeLeaf* findNear(const time_t& key); diff --git a/include/mementar/core/EpisodicTree/CompressedLeaf.h b/include/mementar/core/EpisodicTree/CompressedLeaf.h index 8a81366..246cea9 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeaf.h +++ b/include/mementar/core/EpisodicTree/CompressedLeaf.h @@ -4,7 +4,7 @@ #include #include -#include "mementar/core/Btree/Btree.h" +#include "mementar/core/LinkedBtree/LinkedBtree.h" #include "mementar/core/LinkedFact.h" namespace mementar @@ -19,7 +19,7 @@ class CompressedLeaf std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - Btree* getTree(); + LinkedBtree* getTree(); private: time_t key_; std::string directory_; diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/EpisodicTree/CompressedLeafNode.h index c56a388..01bb3ab 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNode.h @@ -7,7 +7,7 @@ #include #include "mementar/core/LinkedFact.h" -#include "mementar/core/Btree/Btree.h" +#include "mementar/core/LinkedBtree/LinkedBtree.h" #include "mementar/core/EpisodicTree/CompressedLeaf.h" #include "mementar/core/EpisodicTree/Context.h" @@ -25,7 +25,7 @@ class CompressedLeafNode CompressedLeafNode* split(); - void insert(const time_t& key, const LinkedFact* data); + void insert(const time_t& key, LinkedFact* data); void remove(const time_t& key, const LinkedFact& data); BtreeLeaf* find(const time_t& key); BtreeLeaf* findNear(const time_t& key); @@ -58,9 +58,9 @@ class CompressedLeafNode // keys_[i] correspond to the first key of child i std::vector keys_; std::vector contexts_; - std::vector*> btree_childs_; + std::vector*> btree_childs_; std::vector compressed_childs_; - std::vector*> compressed_sessions_tree_; + std::vector*> compressed_sessions_tree_; std::vector compressed_sessions_timeout_; //ms std::vector modified_; diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h index beac8bc..d62eaa1 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h @@ -7,7 +7,7 @@ #include #include "mementar/core/LinkedFact.h" -#include "mementar/core/Btree/Btree.h" +#include "mementar/core/LinkedBtree/LinkedBtree.h" #include "mementar/core/EpisodicTree/CompressedLeafSession.h" #include "mementar/core/EpisodicTree/Context.h" @@ -23,7 +23,7 @@ class CompressedLeafNodeSession CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); - void insert(const time_t& key, const LinkedFact* data); + void insert(const time_t& key, LinkedFact* data); bool remove(const time_t& key, const LinkedFact& data); BtreeLeaf* find(const time_t& key); BtreeLeaf* findNear(const time_t& key); @@ -49,7 +49,7 @@ class CompressedLeafNodeSession // keys_[i] correspond to the first key of child i std::vector contexts_; std::vector childs_; - std::vector*> sessions_tree_; + std::vector*> sessions_tree_; std::vector modified_; time_t earlier_key_; diff --git a/include/mementar/core/EpisodicTree/CompressedLeafSession.h b/include/mementar/core/EpisodicTree/CompressedLeafSession.h index fccc8d1..67a971a 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafSession.h @@ -4,7 +4,7 @@ #include "mementar/core/archiving_compressing/archiving/Archive.h" #include "mementar/core/archiving_compressing/archiving/Header.h" -#include "mementar/core/Btree/Btree.h" +#include "mementar/core/LinkedBtree/LinkedBtree.h" #include "mementar/core/LinkedFact.h" namespace mementar @@ -18,7 +18,7 @@ class CompressedLeafSession time_t getKey() { return key_; } size_t getIndex() { return index_; } - Btree* getTree(Header& header, Archive& arch); + LinkedBtree* getTree(Header& header, Archive& arch); std::vector getRawData(Header& header, Archive& arch); private: time_t key_; diff --git a/include/mementar/core/LinkedFact.h b/include/mementar/core/LinkedFact.h index e6cf54d..4d5ceca 100644 --- a/include/mementar/core/LinkedFact.h +++ b/include/mementar/core/LinkedFact.h @@ -1,6 +1,8 @@ #ifndef MEMENTAR_LINKEDFACT_H #define MEMENTAR_LINKEDFACT_H +#include + #include "mementar/core/Fact.h" namespace mementar @@ -29,6 +31,9 @@ class LinkedFact : public Fact LinkedFact* next_; LinkedFact* prev_; + + std::vector toLinkNext; + std::vector toLinkPrev; }; } // namespace mementar diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index f9d4bec..5f7b5e6 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -58,7 +58,7 @@ ArchivedLeaf::ArchivedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -Btree* ArchivedLeaf::getTree(size_t i) +LinkedBtree* ArchivedLeaf::getTree(size_t i) { mementar::Archive arch; std::cout << "ArchivedLeaf::getTree READ BINARY FILE " << directory_ << ".mar" << std::endl; @@ -71,7 +71,7 @@ Btree* ArchivedLeaf::getTree(size_t i) LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); lz.uncompress(comp_data, out); - Btree* tree = new Btree(); + LinkedBtree* tree = new LinkedBtree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); std::smatch match; diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index 587dea8..9fd2416 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -50,7 +50,7 @@ ArchivedLeafNode::~ArchivedLeafNode() mut_.unlock(); } -void ArchivedLeafNode::insert(const time_t& key, const LinkedFact* data) +void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 3c2cfd7..57f08d7 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -33,7 +33,7 @@ CompressedLeaf::CompressedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -Btree* CompressedLeaf::getTree() +LinkedBtree* CompressedLeaf::getTree() { std::string out; @@ -42,7 +42,7 @@ Btree* CompressedLeaf::getTree() if(lz.readBinaryFile(data, directory_ + ".mlz")) { lz.uncompress(data, out); - Btree* tree = new Btree(); + LinkedBtree* tree = new LinkedBtree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); std::smatch match; @@ -71,7 +71,7 @@ Btree* CompressedLeaf::getTree() std::string CompressedLeaf::treeToString(Btree* tree) { std::string res; - std::vector tmp_data; + std::vector tmp_data; BtreeLeaf* it = tree->getFirst(); while(it != nullptr) { diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/EpisodicTree/CompressedLeafNode.cpp index 3222d58..9445723 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/EpisodicTree/CompressedLeafNode.cpp @@ -88,7 +88,7 @@ CompressedLeafNode* CompressedLeafNode::split() return new_one; } -void CompressedLeafNode::insert(const time_t& key, const LinkedFact* data) +void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -295,7 +295,7 @@ void CompressedLeafNode::init() void CompressedLeafNode::createNewTreeChild(const time_t& key) { mut_.lock(); - btree_childs_.push_back(new Btree(order_)); + btree_childs_.push_back(new LinkedBtree(order_)); keys_.push_back(key); contexts_.push_back(Context(key)); mut_.unlock(); diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index f561c7f..b55f166 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -58,7 +58,7 @@ int CompressedLeafNodeSession::getKeyIndex(const time_t& key) return index; } -void CompressedLeafNodeSession::insert(const time_t& key, const LinkedFact* data) +void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* data) { mut_.lock_shared(); if(contexts_.size() == 0) @@ -200,7 +200,7 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) { std::string res; - std::vector tmp_data; + std::vector tmp_data; BtreeLeaf* it = sessions_tree_[index]->getFirst(); while(it != nullptr) { diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index 687b1cb..92bc68d 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -13,7 +13,7 @@ CompressedLeafSession::CompressedLeafSession(const time_t& key, size_t index) index_ = index; } -Btree* CompressedLeafSession::getTree(Header& header, Archive& arch) +LinkedBtree* CompressedLeafSession::getTree(Header& header, Archive& arch) { std::string comp = arch.extractFile(index_, header); @@ -21,7 +21,7 @@ Btree* CompressedLeafSession::getTree(Header& header, Archiv LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); lz.uncompress(comp_data, out); - Btree* tree = new Btree(); + LinkedBtree* tree = new LinkedBtree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); std::smatch match; From c73a6eeb7d2f49e5cf206e31213d2866e0984efd Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jul 2019 11:30:55 +0200 Subject: [PATCH 07/95] [ADD] LinkedBtree --- .../mementar/core/LinkedBtree/LinkedBtree.h | 52 +++++ .../core/LinkedBtree/LinkedBtreeLeafNode.h | 199 ++++++++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 include/mementar/core/LinkedBtree/LinkedBtree.h create mode 100644 include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h diff --git a/include/mementar/core/LinkedBtree/LinkedBtree.h b/include/mementar/core/LinkedBtree/LinkedBtree.h new file mode 100644 index 0000000..65d02ac --- /dev/null +++ b/include/mementar/core/LinkedBtree/LinkedBtree.h @@ -0,0 +1,52 @@ +#ifndef MEMENTAR_LINKEDBTREE_H +#define MEMENTAR_LINKEDBTREE_H + +#include "mementar/core/Btree/Btree.h" +#include "mementar/core/LinkedBtree/LinkedBtreeLeafNode.h" +#include "mementar/core/LinkedFact.h" + +namespace mementar +{ + +template +class LinkedBtree : public Btree +{ +public: + LinkedBtree(size_t order = 10) : Btree(order) {} + + size_t insert(const Tkey& key, LinkedFact* data); + +private: +}; + +template +size_t LinkedBtree::insert(const Tkey& key, LinkedFact* data) +{ + this->nb_data_++; + if(this->last_ == nullptr) + { + this->root_ = new LinkedBtreeLeafNode(this->order_); + this->level_ = this->root_->getLevel(); + this->last_ = this->root_->insert(key, data); + } + else + { + BtreeLeaf* tmp = this->root_->insert(key, data); + if(tmp != nullptr) + { + if(tmp->operator>(this->last_)) + this->last_ = tmp; + if(this->root_->getMother() != nullptr) + { + this->root_ = this->root_->getMother(); + this->level_ = this->root_->getLevel(); + } + } + } + + return this->nb_data_; +} + +} // namespace mementar + +#endif // MEMENTAR_LINKEDBTREE_H diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h new file mode 100644 index 0000000..9efa094 --- /dev/null +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -0,0 +1,199 @@ +#ifndef MEMENTAR_LINKEDBTREELEAFNODE_H +#define MEMENTAR_LINKEDBTREELEAFNODE_H + +#include "mementar/core/Btree/BtreeLeafNode.h" +#include "mementar/core/LinkedFact.h" + +namespace mementar +{ + +template +class LinkedBtreeLeafNode : public BtreeLeafNode +{ +public: + LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode(order) + {} + + BtreeLeaf* insert(const Tkey& key, LinkedFact* data); + bool remove(const Tkey& key, LinkedFact* data); + +private: + void split(); + + LinkedFact* getPrev(BtreeLeaf* current, LinkedFact* data); + LinkedFact* getNext(BtreeLeaf* current, LinkedFact* data); + + void linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next); + void linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev); +}; + +template +BtreeLeaf* LinkedBtreeLeafNode::insert(const Tkey& key, LinkedFact* data) +{ + BtreeLeaf* res = BtreeLeafNode::insert(key, data); + + if(res != nullptr) + { + std::cout << "insert using LinkedBtreeLeafNode" << std::endl; + data->next_ = getNext(res, data); + data->prev_ = getPrev(res, data); + } + + return res; +} + +template +bool LinkedBtreeLeafNode::remove(const Tkey& key, LinkedFact* data) +{ + for(size_t i = 0; i < this->keys_.size(); i++) + { + if(this->keys_[i] == key) + { + this->leafs_[i]->remove(data); + if(this->leafs_[i]->getData().size() == 0) + { + if(this->leafs_[i]->prev_ != nullptr) + this->leafs_[i]->prev_->next_ = this->leafs_[i]->next_; + if(this->leafs_[i]->next_ != nullptr) + this->leafs_[i]->next_->prev_ = this->leafs_[i]->prev_; + delete this->leafs_[i]; + this->leafs_.erase(this->leafs_.begin() + i); + this->keys_.erase(this->keys_.begin() + i); + + if(this->leafs_.size() == 0) + std::cout << "a node is empty but will not be destroyed" << std::endl; + } + return true; + } + } + return false; +} + +template +void LinkedBtreeLeafNode::split() +{ + LinkedBtreeLeafNode* new_node = new LinkedBtreeLeafNode(this->order_); + + size_t half_order = this->order_/2; + for(size_t i = 0; i < half_order; i++) + { + new_node->leafs_.insert(new_node->leafs_.begin(), this->leafs_[this->leafs_.size() - 1]); + this->leafs_.erase(this->leafs_.begin() + this->leafs_.size() - 1); + new_node->leafs_[i]->setMother(new_node); + + new_node->keys_.insert(new_node->keys_.begin(), this->keys_[this->keys_.size() - 1]); + this->keys_.erase(this->keys_.begin() + this->keys_.size() - 1); + } + + if(this->mother_ != nullptr) + { + this->mother_->insert(new_node, new_node->keys_[0]); + } + else + { + BtreeNode* new_mother = new BtreeNode(this->order_); + new_mother->setLevel(this->level_ + 1); + new_mother->insert(this, new_node->keys_[0]); + new_mother->insert(new_node, new_node->keys_[0]); + } +} + +template +LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf* current, LinkedFact* data) +{ + LinkedFact* res = nullptr; + + BtreeLeaf* leaf = current; + while(leaf->prev_ != nullptr) + { + for(auto data : leaf->getData()) + { + if(data->isEventPart(*data)) + { + res = data; + break; + } + } + leaf = leaf->prev_; + } + + return res; +} + +template +LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* current, LinkedFact* data) +{ + LinkedFact* res = nullptr; + + BtreeLeaf* leaf = current; + while(leaf->next_ != nullptr) + { + for(auto data : leaf->getData()) + { + if(data->isEventPart(*data)) + { + res = data; + break; + } + } + leaf = leaf->next_; + } + + return res; +} + +template +void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next) +{ + if(current->operator==(*prev)) + { + if(next == nullptr) + { + current->toLinkNext = prev->toLinkNext; + prev->toLinkNext.clear(); + current->toLinkNext.push_back(prev); + } + current->prev_ = prev->prev_; + } + else + { + current->prev_ = prev; + prev->next_ = current; + if(prev->toLinkNext.size()) + { + for(auto d : prev->toLinkNext) + d->next_ = current; + prev->toLinkNext.clear(); + } + } +} + +template +void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev) +{ + if(current->operator==(*next)) + { + if(prev == nullptr) + { + current->toLinkPrev = next->toLinkPrev; + next->toLinkPrev.clear(); + current->toLinkPrev.push_back(next); + } + current->next_ = prev->next_; + } + else + { + current->next_ = next; + prev->prev_ = current; + if(prev->toLinkPrev.size()) + { + for(auto d : next->toLinkPrev) + d->prev_ = current; + next->toLinkPrev.clear(); + } + } +} + +} // namespace mementar + +#endif // MEMENTAR_LINKEDBTREELEAFNODE_H From 92c7822f2907a71215986f9c9b9390a158a3a130 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jul 2019 16:25:39 +0200 Subject: [PATCH 08/95] [FIX] event link --- CMakeLists.txt | 4 +- include/mementar/core/Btree/Btree.h | 4 +- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 50 ++++++++++--------- src/core/EpisodicTree/ArchivedLeafNode.cpp | 2 +- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5edeb5..fdc607a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,11 +165,13 @@ add_dependencies(mementar_multi ${catkin_EXPORTED_TARGETS}) ## Test executables ############################## - add_executable(event_sub_pub src/test/occasions_sub_pub.cpp) target_link_libraries(event_sub_pub ${catkin_LIBRARIES}) target_link_libraries(event_sub_pub mementar_lib) +add_executable(eventLink src/test/EventLink.cpp) +target_link_libraries(eventLink mementar_core_lib) + ############################## ## Install ############################## diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index 2fd9af3..5d216fc 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -24,7 +24,7 @@ class Btree nb_data_ = 0; } - ~Btree() + virtual ~Btree() { if(root_ != nullptr) delete root_; @@ -38,7 +38,7 @@ class Btree } } - size_t insert(const Tkey& key, Tdata* data); + virtual size_t insert(const Tkey& key, Tdata* data); bool remove(const Tkey& key, const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h index 9efa094..a9616cf 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -4,6 +4,8 @@ #include "mementar/core/Btree/BtreeLeafNode.h" #include "mementar/core/LinkedFact.h" +#include "mementar/core/utility/Display.h" + namespace mementar { @@ -34,9 +36,11 @@ BtreeLeaf* LinkedBtreeLeafNode::insert(const Tkey& key, L if(res != nullptr) { - std::cout << "insert using LinkedBtreeLeafNode" << std::endl; - data->next_ = getNext(res, data); - data->prev_ = getPrev(res, data); + auto next = getNext(res, data); + auto prev = getPrev(res, data); + + linkPrev(data, prev, next); + linkNext(data, next, prev); } return res; @@ -61,7 +65,7 @@ bool LinkedBtreeLeafNode::remove(const Tkey& key, LinkedFact* data) this->keys_.erase(this->keys_.begin() + i); if(this->leafs_.size() == 0) - std::cout << "a node is empty but will not be destroyed" << std::endl; + Display::Info("a node is empty but will not be destroyed"); } return true; } @@ -103,16 +107,13 @@ LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf* curre { LinkedFact* res = nullptr; - BtreeLeaf* leaf = current; - while(leaf->prev_ != nullptr) + BtreeLeaf* leaf = current->prev_; + while(leaf != nullptr) { - for(auto data : leaf->getData()) + for(auto ld : leaf->getData()) { - if(data->isEventPart(*data)) - { - res = data; - break; - } + if(data->isEventPart(*ld)) + return ld; } leaf = leaf->prev_; } @@ -125,16 +126,13 @@ LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* curre { LinkedFact* res = nullptr; - BtreeLeaf* leaf = current; - while(leaf->next_ != nullptr) + BtreeLeaf* leaf = current->next_; + while(leaf != nullptr) { - for(auto data : leaf->getData()) + for(auto ld : leaf->getData()) { - if(data->isEventPart(*data)) - { - res = data; - break; - } + if(data->isEventPart(*ld)) + return ld; } leaf = leaf->next_; } @@ -145,6 +143,9 @@ LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* curre template void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next) { + if(prev == nullptr) + return; + if(current->operator==(*prev)) { if(next == nullptr) @@ -171,6 +172,9 @@ void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, template void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev) { + if(next == nullptr) + return; + if(current->operator==(*next)) { if(prev == nullptr) @@ -179,13 +183,13 @@ void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, next->toLinkPrev.clear(); current->toLinkPrev.push_back(next); } - current->next_ = prev->next_; + current->next_ = next->next_; } else { current->next_ = next; - prev->prev_ = current; - if(prev->toLinkPrev.size()) + next->prev_ = current; + if(next->toLinkPrev.size()) { for(auto d : next->toLinkPrev) d->prev_ = current; diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index 9fd2416..5b2837f 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -64,7 +64,7 @@ void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) { if(key < keys_[0]) { - std::cout << "[ERROR] try to insert fact in past that do not exist" << std::endl; + Display::Error("try to insert fact in past that do not exist"); return; } From e950fbadd450b05b1a684b00d3963f32ce5fc0a2 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jul 2019 16:26:22 +0200 Subject: [PATCH 09/95] [ADD] event link test file --- src/test/EventLink.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/EventLink.cpp diff --git a/src/test/EventLink.cpp b/src/test/EventLink.cpp new file mode 100644 index 0000000..c59e951 --- /dev/null +++ b/src/test/EventLink.cpp @@ -0,0 +1,37 @@ +#include "mementar/core/LinkedBtree/LinkedBtree.h" + +int main() +{ + mementar::LinkedBtree tree; + + for(int i = 20; i >= 0; i--) + { + if(i % 2) + tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i-1))); + else + tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i))); + } + + auto leaf = tree.find(1); + + std::cout << "**********" << std::endl; + if(leaf) + { + std::vector datas = leaf->getData(); + if(datas.size()) + { + mementar::LinkedFact* c = datas[0]; + while(c != nullptr) + { + std::cout << *c << std::endl; + c = c->next_; + } + } + else + std::cout << "no data in the leaf" << std::endl; + } + else + std::cout << "no leaf" << std::endl; + + return 0; +} From dae87dad2c0d1e319d8c9eb273cb7c4a6591f4ca Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 22 Jul 2019 17:11:09 +0200 Subject: [PATCH 10/95] [FIX] display empty tree --- include/mementar/core/Btree/Btree.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index 5d216fc..ae854f1 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -148,7 +148,8 @@ void Btree::display(int count) cpt++; } std::cout << "******" << std::endl; - root_->display(); + if(root_) + root_->display(); } } // namespace mementar From 9e581577745125ab73a11ba725326fb274c360b1 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 22 Jul 2019 17:57:40 +0200 Subject: [PATCH 11/95] [FIX] BtreeNode Node insertion in past --- include/mementar/core/Btree/BtreeNode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mementar/core/Btree/BtreeNode.h b/include/mementar/core/Btree/BtreeNode.h index a88eb91..26665dd 100644 --- a/include/mementar/core/Btree/BtreeNode.h +++ b/include/mementar/core/Btree/BtreeNode.h @@ -96,7 +96,7 @@ void BtreeNode::insert(BtreeNode* new_node, const Tkey& if(key < this->keys_[i]) { this->keys_.insert(this->keys_.begin() + i, key); - this->childs_.insert(this->childs_.begin() + i, new_node); + this->childs_.insert(this->childs_.begin() + i + 1, new_node); new_node->setMother(this); break; } From 9b21f47294156cc96977cc03d702e5830d5ae9c1 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jul 2019 10:49:18 +0200 Subject: [PATCH 12/95] [UPDATE] remove event link --- include/mementar/core/Btree/BtreeLeaf.h | 15 ++ include/mementar/core/Btree/BtreeLeafNode.h | 2 +- include/mementar/core/Fact.h | 8 +- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 147 +++++++++++++++++- include/mementar/core/LinkedFact.h | 4 +- src/test/EventLink.cpp | 35 ++++- 6 files changed, 199 insertions(+), 12 deletions(-) diff --git a/include/mementar/core/Btree/BtreeLeaf.h b/include/mementar/core/Btree/BtreeLeaf.h index 8b982d4..e82ecd7 100644 --- a/include/mementar/core/Btree/BtreeLeaf.h +++ b/include/mementar/core/Btree/BtreeLeaf.h @@ -51,6 +51,7 @@ class BtreeLeaf Tkey getKey() const { return key_; } std::vector getData() const { return data_; } void getData(std::vector& data) { data = data_; } + Tdata* getData(const Tdata& data); void setMother(BtreeLeafNode* mother) { mother_ = mother; } BtreeLeafNode* getMother() { return mother_; } @@ -67,12 +68,26 @@ void BtreeLeaf::remove(const Tdata& data) for(size_t i = 0; i < data_.size();) { if(data_[i]->operator==(data)) + { + delete data_[i]; data_.erase(data_.begin() + i); + } else i++; } } +template +Tdata* BtreeLeaf::getData(const Tdata& data) +{ + for(size_t i = 0; i < data_.size(); i++) + { + if(data_[i]->operator==(data)) + return data_[i]; + } + return nullptr; +} + } // mementar #endif // MEMENTAR_BTREELEAF_H diff --git a/include/mementar/core/Btree/BtreeLeafNode.h b/include/mementar/core/Btree/BtreeLeafNode.h index f53561f..fe826d0 100644 --- a/include/mementar/core/Btree/BtreeLeafNode.h +++ b/include/mementar/core/Btree/BtreeLeafNode.h @@ -184,7 +184,7 @@ void BtreeLeafNode::split() { BtreeNode* new_mother = new BtreeNode(this->order_); new_mother->setLevel(this->level_ + 1); - new_mother->insert(this, new_node->keys_[0]); + new_mother->insert(this, this->keys_[0]); new_mother->insert(new_node, new_node->keys_[0]); } } diff --git a/include/mementar/core/Fact.h b/include/mementar/core/Fact.h index cff2ce4..1997f40 100644 --- a/include/mementar/core/Fact.h +++ b/include/mementar/core/Fact.h @@ -10,14 +10,15 @@ namespace mementar class Fact { public: - Fact(const std::string& subject, const std::string& predicat, const std::string& object) + Fact(const std::string& subject, const std::string& predicat, const std::string& object, time_t stamp = 0) { subject_ = subject; predicat_ = predicat; object_ = object; + stamp_ = stamp; } - Fact(const std::string& triplet = "") + Fact(const std::string& triplet = "", time_t stamp = 0) { std::vector splitted = split(triplet, "|"); if(splitted.size() >= 1) @@ -26,6 +27,8 @@ class Fact predicat_ = splitted[1]; if(splitted.size() >= 3) object_ = splitted[2]; + + stamp_ = stamp; } bool valid() const @@ -62,6 +65,7 @@ class Fact std::string subject_; std::string predicat_; std::string object_; + time_t stamp_; private: diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h index a9616cf..fd5d3f7 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -17,16 +17,22 @@ class LinkedBtreeLeafNode : public BtreeLeafNode {} BtreeLeaf* insert(const Tkey& key, LinkedFact* data); - bool remove(const Tkey& key, LinkedFact* data); + bool remove(const Tkey& key, const LinkedFact& data); private: void split(); LinkedFact* getPrev(BtreeLeaf* current, LinkedFact* data); + std::vector getPrevs(BtreeLeaf* current, LinkedFact* data); LinkedFact* getNext(BtreeLeaf* current, LinkedFact* data); + std::vector getNexts(BtreeLeaf* current, LinkedFact* data); void linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next); void linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev); + + void unlink(LinkedFact* current_data, BtreeLeaf* current_leaf); + void unlinkPrev(LinkedFact* current, std::vector prev, LinkedFact* next); + void unlinkNext(LinkedFact* current, std::vector next, LinkedFact* prev); }; template @@ -47,12 +53,14 @@ BtreeLeaf* LinkedBtreeLeafNode::insert(const Tkey& key, L } template -bool LinkedBtreeLeafNode::remove(const Tkey& key, LinkedFact* data) +bool LinkedBtreeLeafNode::remove(const Tkey& key, const LinkedFact& data) { for(size_t i = 0; i < this->keys_.size(); i++) { if(this->keys_[i] == key) { + LinkedFact* current_data = this->leafs_[i]->getData(data); + unlink(current_data, this->leafs_[i]); this->leafs_[i]->remove(data); if(this->leafs_[i]->getData().size() == 0) { @@ -97,7 +105,7 @@ void LinkedBtreeLeafNode::split() { BtreeNode* new_mother = new BtreeNode(this->order_); new_mother->setLevel(this->level_ + 1); - new_mother->insert(this, new_node->keys_[0]); + new_mother->insert(this, this->keys_[0]); new_mother->insert(new_node, new_node->keys_[0]); } } @@ -121,6 +129,37 @@ LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf* curre return res; } +template +std::vector LinkedBtreeLeafNode::getPrevs(BtreeLeaf* current, LinkedFact* data) +{ + std::vector res; + bool end = false; + + BtreeLeaf* leaf = current->prev_; + if(leaf == nullptr) + end = true; + + while(!end) + { + for(auto ld : leaf->getData()) + { + if(data->isEventPart(*ld)) + { + res.push_back(ld); + if(ld->prev_->next_ == ld) + end = true; + break; + } + } + + leaf = leaf->prev_; + if(leaf == nullptr) + end = true; + } + + return res; +} + template LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* current, LinkedFact* data) { @@ -140,6 +179,37 @@ LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* curre return res; } +template +std::vector LinkedBtreeLeafNode::getNexts(BtreeLeaf* current, LinkedFact* data) +{ + std::vector res; + bool end = false; + + BtreeLeaf* leaf = current->next_; + if(leaf == nullptr) + end = true; + + while(!end) + { + for(auto ld : leaf->getData()) + { + if(data->isEventPart(*ld)) + { + res.push_back(ld); + if(ld->next_->prev_ == ld) + end = true; + break; + } + } + + leaf = leaf->next_; + if(leaf == nullptr) + end = true; + } + + return res; +} + template void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next) { @@ -198,6 +268,77 @@ void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, } } +template +void LinkedBtreeLeafNode::unlink(LinkedFact* current_data, BtreeLeaf* current_leaf) +{ + std::vector prev; + std::vector next; + + prev = getPrevs(current_leaf, current_data); + next = getNexts(current_leaf, current_data); + + unlinkPrev(current_data, prev, next.size() ? next[0] : nullptr); + unlinkNext(current_data, next, prev.size() ? prev[0] : nullptr); +} + +template +void LinkedBtreeLeafNode::unlinkPrev(LinkedFact* current, std::vector prev, LinkedFact* next) +{ + if(prev.size()) + { + if(!current->operator==(*prev[0])) + { + if(!current->operator==(*next)) + { + for(auto p : prev) + p->next_ = current->next_; + } + else + { + for(auto p : prev) + p->next_ = next; + } + } + } + else if(current->toLinkPrev.size()) + { + if(current->operator==(*next)) + { + next->toLinkPrev = std::move(current->toLinkPrev); + next->toLinkPrev.pop_back(); + } + } +} + +template +void LinkedBtreeLeafNode::unlinkNext(LinkedFact* current, std::vector next, LinkedFact* prev) +{ + if(next.size()) + { + if(!current->operator==(*next[0])) + { + if(!current->operator==(*prev)) + { + for(auto n : next) + n->prev_ = current->prev_; + } + else + { + for(auto n : next) + n->prev_ = prev; + } + } + } + else if(current->toLinkNext.size()) + { + if(current->operator==(*prev)) + { + prev->toLinkNext = std::move(current->toLinkNext); + prev->toLinkNext.pop_back(); + } + } +} + } // namespace mementar #endif // MEMENTAR_LINKEDBTREELEAFNODE_H diff --git a/include/mementar/core/LinkedFact.h b/include/mementar/core/LinkedFact.h index 4d5ceca..d455b4c 100644 --- a/include/mementar/core/LinkedFact.h +++ b/include/mementar/core/LinkedFact.h @@ -11,13 +11,13 @@ namespace mementar class LinkedFact : public Fact { public: - LinkedFact(const std::string& subject, const std::string& predicat, const std::string& object) : Fact(subject, predicat, object) + LinkedFact(const std::string& subject, const std::string& predicat, const std::string& object, time_t stamp = 0) : Fact(subject, predicat, object, stamp) { next_ = nullptr; prev_ = nullptr; } - LinkedFact(const std::string& triplet = "") : Fact(triplet) + LinkedFact(const std::string& triplet = "", time_t stamp = 0) : Fact(triplet, stamp) { next_ = nullptr; prev_ = nullptr; diff --git a/src/test/EventLink.cpp b/src/test/EventLink.cpp index c59e951..0bc3a9a 100644 --- a/src/test/EventLink.cpp +++ b/src/test/EventLink.cpp @@ -1,20 +1,47 @@ #include "mementar/core/LinkedBtree/LinkedBtree.h" + +void displayLink(mementar::LinkedBtree* t) +{ + auto first = t->getFirst(); + while(first != nullptr) + { + auto data = first->getData()[0]; + std::cout << data->stamp_ << " : " << *data << std::endl; + if(data->next_) + std::cout << "\tN = " << data->next_->stamp_ << " : " << *(data->next_) << std::endl; + else + std::cout << "\tN = nullptr" << std::endl; + + if(data->prev_) + std::cout << "\tP = " << data->prev_->stamp_ << " : " << *(data->prev_) << std::endl; + else + std::cout << "\tP = nullptr" << std::endl; + + first = first->next_; + } +} + int main() { - mementar::LinkedBtree tree; + mementar::LinkedBtree tree; for(int i = 20; i >= 0; i--) { if(i % 2) - tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i-1))); + tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i-1), i)); else - tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i))); + tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i), i)); } + tree.remove(4, mementar::LinkedFact("max", "hasCounted", std::to_string(4))); + tree.remove(5, mementar::LinkedFact("max", "hasCounted", std::to_string(4))); + tree.remove(6, mementar::LinkedFact("max", "hasCounted", std::to_string(6))); + displayLink(&tree); + //tree.display(); auto leaf = tree.find(1); - std::cout << "**********" << std::endl; + std::cout << "+++++++++++++" << std::endl; if(leaf) { std::vector datas = leaf->getData(); From 73bc0b3aaa06bb4ad51ef87bf0f20043292ff978 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jul 2019 13:23:53 +0200 Subject: [PATCH 13/95] [UPDATE] stampted data --- include/mementar/core/Btree/Btree.h | 3 +++ include/mementar/core/{ => Data}/Fact.h | 13 +++++---- include/mementar/core/{ => Data}/LinkedFact.h | 8 +++--- include/mementar/core/Data/StampedData.h | 27 +++++++++++++++++++ .../core/EpisodicTree/CompressedLeaf.h | 2 +- .../core/EpisodicTree/CompressedLeafNode.h | 2 +- .../EpisodicTree/CompressedLeafNodeSession.h | 2 +- .../core/EpisodicTree/CompressedLeafSession.h | 2 +- include/mementar/core/EpisodicTree/Context.h | 6 ++--- .../mementar/core/LinkedBtree/LinkedBtree.h | 2 +- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 2 +- .../core/Occasions/OccasionsManager.h | 10 +++---- .../mementar/core/Occasions/Subscription.h | 8 +++--- src/RosInterface.cpp | 8 +++--- src/core/EpisodicTree/ArchivedLeaf.cpp | 2 +- src/core/EpisodicTree/CompressedLeaf.cpp | 2 +- .../EpisodicTree/CompressedLeafSession.cpp | 2 +- src/core/EpisodicTree/Context.cpp | 4 +-- src/core/Occasions/OccasionsManager.cpp | 10 +++---- src/core/Occasions/Subscription.cpp | 6 ++--- src/test/EventLink.cpp | 16 +++++------ 21 files changed, 83 insertions(+), 54 deletions(-) rename include/mementar/core/{ => Data}/Fact.h (87%) rename include/mementar/core/{ => Data}/LinkedFact.h (62%) create mode 100644 include/mementar/core/Data/StampedData.h diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index ae854f1..b8995ba 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -8,12 +8,15 @@ #include "mementar/core/Btree/BtreeLeafNode.h" #include "mementar/core/Btree/BtreeLeaf.h" +#include "mementar/core/Data/StampedData.h" + namespace mementar { template class Btree { + //static_assert(std::is_base_of::value, "Tdata must be derived from StampedData"); public: Btree(size_t order = 10) { diff --git a/include/mementar/core/Fact.h b/include/mementar/core/Data/Fact.h similarity index 87% rename from include/mementar/core/Fact.h rename to include/mementar/core/Data/Fact.h index 1997f40..bdbd147 100644 --- a/include/mementar/core/Fact.h +++ b/include/mementar/core/Data/Fact.h @@ -4,21 +4,23 @@ #include #include +#include "mementar/core/Data/StampedData.h" + namespace mementar { -class Fact +template +class Fact : public StampedData { public: - Fact(const std::string& subject, const std::string& predicat, const std::string& object, time_t stamp = 0) + Fact(T stamp, const std::string& subject, const std::string& predicat, const std::string& object) : StampedData(stamp) { subject_ = subject; predicat_ = predicat; object_ = object; - stamp_ = stamp; } - Fact(const std::string& triplet = "", time_t stamp = 0) + Fact(T stamp, const std::string& triplet = "") : StampedData(stamp) { std::vector splitted = split(triplet, "|"); if(splitted.size() >= 1) @@ -27,8 +29,6 @@ class Fact predicat_ = splitted[1]; if(splitted.size() >= 3) object_ = splitted[2]; - - stamp_ = stamp; } bool valid() const @@ -65,7 +65,6 @@ class Fact std::string subject_; std::string predicat_; std::string object_; - time_t stamp_; private: diff --git a/include/mementar/core/LinkedFact.h b/include/mementar/core/Data/LinkedFact.h similarity index 62% rename from include/mementar/core/LinkedFact.h rename to include/mementar/core/Data/LinkedFact.h index d455b4c..1b43675 100644 --- a/include/mementar/core/LinkedFact.h +++ b/include/mementar/core/Data/LinkedFact.h @@ -3,21 +3,21 @@ #include -#include "mementar/core/Fact.h" +#include "mementar/core/Data/Fact.h" namespace mementar { -class LinkedFact : public Fact +class LinkedFact : public Fact { public: - LinkedFact(const std::string& subject, const std::string& predicat, const std::string& object, time_t stamp = 0) : Fact(subject, predicat, object, stamp) + LinkedFact(time_t stamp, const std::string& subject, const std::string& predicat, const std::string& object) : Fact(stamp, subject, predicat, object) { next_ = nullptr; prev_ = nullptr; } - LinkedFact(const std::string& triplet = "", time_t stamp = 0) : Fact(triplet, stamp) + LinkedFact(time_t stamp, const std::string& triplet = "") : Fact(stamp, triplet) { next_ = nullptr; prev_ = nullptr; diff --git a/include/mementar/core/Data/StampedData.h b/include/mementar/core/Data/StampedData.h new file mode 100644 index 0000000..19ae56a --- /dev/null +++ b/include/mementar/core/Data/StampedData.h @@ -0,0 +1,27 @@ +#ifndef MEMENTAR_STAMPEDDATA_H +#define MEMENTAR_STAMPEDDATA_H + +namespace mementar +{ + +template +class StampedData +{ +public: + StampedData(T stamp) + { + stamp_ = stamp; + } + + T getStamp() + { + return stamp_; + } + +private: + T stamp_; +}; + +} // namespace mementar + +#endif // MEMENTAR_STAMPEDDATA_H diff --git a/include/mementar/core/EpisodicTree/CompressedLeaf.h b/include/mementar/core/EpisodicTree/CompressedLeaf.h index 246cea9..0dd0a64 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeaf.h +++ b/include/mementar/core/EpisodicTree/CompressedLeaf.h @@ -5,7 +5,7 @@ #include #include "mementar/core/LinkedBtree/LinkedBtree.h" -#include "mementar/core/LinkedFact.h" +#include "mementar/core/Data/LinkedFact.h" namespace mementar { diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/EpisodicTree/CompressedLeafNode.h index 01bb3ab..d15f10e 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNode.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/LinkedFact.h" +#include "mementar/core/Data/LinkedFact.h" #include "mementar/core/LinkedBtree/LinkedBtree.h" #include "mementar/core/EpisodicTree/CompressedLeaf.h" #include "mementar/core/EpisodicTree/Context.h" diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h index d62eaa1..04af224 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/LinkedFact.h" +#include "mementar/core/Data/LinkedFact.h" #include "mementar/core/LinkedBtree/LinkedBtree.h" #include "mementar/core/EpisodicTree/CompressedLeafSession.h" #include "mementar/core/EpisodicTree/Context.h" diff --git a/include/mementar/core/EpisodicTree/CompressedLeafSession.h b/include/mementar/core/EpisodicTree/CompressedLeafSession.h index 67a971a..6a524bb 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafSession.h @@ -5,7 +5,7 @@ #include "mementar/core/archiving_compressing/archiving/Header.h" #include "mementar/core/LinkedBtree/LinkedBtree.h" -#include "mementar/core/LinkedFact.h" +#include "mementar/core/Data/LinkedFact.h" namespace mementar { diff --git a/include/mementar/core/EpisodicTree/Context.h b/include/mementar/core/EpisodicTree/Context.h index 51cd8e0..f68a938 100644 --- a/include/mementar/core/EpisodicTree/Context.h +++ b/include/mementar/core/EpisodicTree/Context.h @@ -5,7 +5,7 @@ #include #include -#include "mementar/core/Fact.h" +#include "mementar/core/Data/Fact.h" namespace mementar { @@ -15,8 +15,8 @@ class Context public: Context(time_t key) { key_ = key; } - void insert(const Fact* fact); - void remove(const Fact* fact); + void insert(const Fact* fact); + void remove(const Fact* fact); bool exist(const std::string& name); bool subjectExist(const std::string& subject); diff --git a/include/mementar/core/LinkedBtree/LinkedBtree.h b/include/mementar/core/LinkedBtree/LinkedBtree.h index 65d02ac..06e46eb 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtree.h +++ b/include/mementar/core/LinkedBtree/LinkedBtree.h @@ -3,7 +3,7 @@ #include "mementar/core/Btree/Btree.h" #include "mementar/core/LinkedBtree/LinkedBtreeLeafNode.h" -#include "mementar/core/LinkedFact.h" +#include "mementar/core/Data/LinkedFact.h" namespace mementar { diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h index fd5d3f7..0e07b68 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -2,7 +2,7 @@ #define MEMENTAR_LINKEDBTREELEAFNODE_H #include "mementar/core/Btree/BtreeLeafNode.h" -#include "mementar/core/LinkedFact.h" +#include "mementar/core/Data/LinkedFact.h" #include "mementar/core/utility/Display.h" diff --git a/include/mementar/core/Occasions/OccasionsManager.h b/include/mementar/core/Occasions/OccasionsManager.h index 886a0b3..2264c1c 100644 --- a/include/mementar/core/Occasions/OccasionsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -11,7 +11,7 @@ #include "mementar/MementarOcassionUnsubscription.h" #include "mementar/core/Occasions/Subscription.h" -#include "mementar/core/Fact.h" +#include "mementar/core/Data/Fact.h" namespace mementar { @@ -23,7 +23,7 @@ class OccasionsManager void run(); - void add(const Fact* fact); + void add(const Fact* fact); void stop() {run_ = false; } inline bool isRunning() {return run_; } @@ -40,15 +40,15 @@ class OccasionsManager std::mutex mutex_; bool queue_choice_; - std::queue fifo_1; - std::queue fifo_2; + std::queue*> fifo_1; + std::queue*> fifo_2; bool SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res); bool UnsubscribeCallback(mementar::MementarOcassionUnsubscription::Request &req, mementar::MementarOcassionUnsubscription::Response &res); - const Fact* get(); + const Fact* get(); bool empty(); }; diff --git a/include/mementar/core/Occasions/Subscription.h b/include/mementar/core/Occasions/Subscription.h index f85b099..c35eeb9 100644 --- a/include/mementar/core/Occasions/Subscription.h +++ b/include/mementar/core/Occasions/Subscription.h @@ -5,7 +5,7 @@ #include #include -#include "mementar/core/Fact.h" +#include "mementar/core/Data/Fact.h" #include "mementar/core/Occasions/IdManager.h" namespace mementar @@ -14,16 +14,16 @@ namespace mementar class Subscription { public: - size_t subscribe(const Fact& patern, size_t count); + size_t subscribe(const Fact& patern, size_t count); bool unsubscribe(size_t id); bool isFinished(size_t id); bool empty() { return fact_paterns_.size() == 0; } - std::vector evaluate(const Fact& fact); + std::vector evaluate(const Fact& fact); private: - std::map fact_paterns_; + std::map> fact_paterns_; std::map counts_; std::mutex map_mut_; diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 86d2929..54a5b60 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -77,7 +77,7 @@ void RosInterface::reset() void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { - LinkedFact* fact = new LinkedFact(msg->data); + LinkedFact* fact = new LinkedFact(time(0), msg->data); if(fact->valid()) { mut_.lock_shared(); @@ -89,7 +89,7 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { - LinkedFact* fact = new LinkedFact(msg->data); + LinkedFact* fact = new LinkedFact(msg->stamp.sec, msg->data); if(fact->valid()) { mut_.lock_shared(); @@ -109,11 +109,11 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, if(req.action == "remove") { - LinkedFact fact(req.param); + LinkedFact fact(req.stamp.sec, req.param); if(fact.valid()) { mut_.lock_shared(); - tree_->remove(req.stamp.sec, req.param); + tree_->remove(req.stamp.sec, fact); mut_.unlock_shared(); } else diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index 5f7b5e6..149e22d 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -82,10 +82,10 @@ LinkedBtree* ArchivedLeaf::getTree(size_t i) { if(std::regex_match(line, match, regex)) { - LinkedFact* fact = new LinkedFact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; + LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); tree->insert(key, fact); } diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 57f08d7..b8a42fb 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -53,10 +53,10 @@ LinkedBtree* CompressedLeaf::getTree() { if(std::regex_match(line, match, regex)) { - LinkedFact* fact = new LinkedFact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; + LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); tree->insert(key, fact); } diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index 92bc68d..cc45309 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -32,10 +32,10 @@ LinkedBtree* CompressedLeafSession::getTree(Header& header, Archive& arc { if(std::regex_match(line, match, regex)) { - LinkedFact* fact = new LinkedFact(match[2].str(), match[3].str(), match[4].str()); time_t key; std::istringstream iss(match[1].str()); iss >> key; + LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); tree->insert(key, fact); } diff --git a/src/core/EpisodicTree/Context.cpp b/src/core/EpisodicTree/Context.cpp index f69ff1e..44bd90e 100644 --- a/src/core/EpisodicTree/Context.cpp +++ b/src/core/EpisodicTree/Context.cpp @@ -10,7 +10,7 @@ namespace mementar { -void Context::insert(const Fact* fact) +void Context::insert(const Fact* fact) { std::map::iterator it; @@ -36,7 +36,7 @@ void Context::insert(const Fact* fact) } } -void Context::remove(const Fact* fact) +void Context::remove(const Fact* fact) { std::map::iterator it; diff --git a/src/core/Occasions/OccasionsManager.cpp b/src/core/Occasions/OccasionsManager.cpp index 790d039..aebdae9 100644 --- a/src/core/Occasions/OccasionsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -27,7 +27,7 @@ void OccasionsManager::run() { while(!empty()) { - const Fact* fact = get(); + const Fact* fact = get(); if(fact->valid()) { std::vector ids = subscription_.evaluate(*fact); @@ -45,7 +45,7 @@ void OccasionsManager::run() } } -void OccasionsManager::add(const Fact* fact) +void OccasionsManager::add(const Fact* fact) { mutex_.lock(); if(queue_choice_ == true) @@ -58,7 +58,7 @@ void OccasionsManager::add(const Fact* fact) bool OccasionsManager::SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res) { - Fact fact_patern(req.data); + Fact fact_patern(0, req.data); if(!fact_patern.valid()) return false; @@ -78,9 +78,9 @@ bool OccasionsManager::UnsubscribeCallback(mementar::MementarOcassionUnsubscript return true; } -const Fact* OccasionsManager::get() +const Fact* OccasionsManager::get() { - const Fact* res; + const Fact* res; mutex_.lock(); if(queue_choice_ == true) { diff --git a/src/core/Occasions/Subscription.cpp b/src/core/Occasions/Subscription.cpp index 460f5b5..37e48ef 100644 --- a/src/core/Occasions/Subscription.cpp +++ b/src/core/Occasions/Subscription.cpp @@ -3,11 +3,11 @@ namespace mementar { -size_t Subscription::subscribe(const Fact& patern, size_t count) +size_t Subscription::subscribe(const Fact& patern, size_t count) { map_mut_.lock(); size_t id = id_manager_.getNewId(); - fact_paterns_.insert(std::pair(id, patern)); + fact_paterns_.insert(std::pair>(id, patern)); counts_[id] = count; map_mut_.unlock(); @@ -42,7 +42,7 @@ bool Subscription::isFinished(size_t id) return res; } -std::vector Subscription::evaluate(const Fact& fact) +std::vector Subscription::evaluate(const Fact& fact) { std::vector res; diff --git a/src/test/EventLink.cpp b/src/test/EventLink.cpp index 0bc3a9a..ee185de 100644 --- a/src/test/EventLink.cpp +++ b/src/test/EventLink.cpp @@ -7,14 +7,14 @@ void displayLink(mementar::LinkedBtree* t) while(first != nullptr) { auto data = first->getData()[0]; - std::cout << data->stamp_ << " : " << *data << std::endl; + std::cout << data->getStamp() << " : " << *data << std::endl; if(data->next_) - std::cout << "\tN = " << data->next_->stamp_ << " : " << *(data->next_) << std::endl; + std::cout << "\tN = " << data->next_->getStamp() << " : " << *(data->next_) << std::endl; else std::cout << "\tN = nullptr" << std::endl; if(data->prev_) - std::cout << "\tP = " << data->prev_->stamp_ << " : " << *(data->prev_) << std::endl; + std::cout << "\tP = " << data->prev_->getStamp() << " : " << *(data->prev_) << std::endl; else std::cout << "\tP = nullptr" << std::endl; @@ -29,14 +29,14 @@ int main() for(int i = 20; i >= 0; i--) { if(i % 2) - tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i-1), i)); + tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i-1))); else - tree.insert(i, new mementar::LinkedFact("max", "hasCounted", std::to_string(i), i)); + tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i))); } - tree.remove(4, mementar::LinkedFact("max", "hasCounted", std::to_string(4))); - tree.remove(5, mementar::LinkedFact("max", "hasCounted", std::to_string(4))); - tree.remove(6, mementar::LinkedFact("max", "hasCounted", std::to_string(6))); + tree.remove(4, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); + tree.remove(5, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); + tree.remove(6, mementar::LinkedFact(6, "max", "hasCounted", std::to_string(6))); displayLink(&tree); //tree.display(); auto leaf = tree.find(1); From 3c184e8d3858b9916aacd9b4c4ec6e6470584b14 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jul 2019 15:03:27 +0200 Subject: [PATCH 14/95] [UPDATE] template LinkedFact --- include/mementar/core/Btree/Btree.h | 2 +- include/mementar/core/Data/LinkedFact.h | 21 +++--- .../core/EpisodicTree/ArchivedLeafNode.h | 12 +-- .../core/EpisodicTree/CompressedLeaf.h | 4 +- .../core/EpisodicTree/CompressedLeafNode.h | 12 +-- .../EpisodicTree/CompressedLeafNodeSession.h | 12 +-- .../mementar/core/LinkedBtree/LinkedBtree.h | 10 +-- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 74 +++++++++---------- src/RosInterface.cpp | 6 +- src/core/EpisodicTree/ArchivedLeaf.cpp | 2 +- src/core/EpisodicTree/ArchivedLeafNode.cpp | 20 ++--- src/core/EpisodicTree/CompressedLeaf.cpp | 10 +-- src/core/EpisodicTree/CompressedLeafNode.cpp | 20 ++--- .../CompressedLeafNodeSession.cpp | 24 +++--- .../EpisodicTree/CompressedLeafSession.cpp | 2 +- src/test/EventLink.cpp | 18 ++--- 16 files changed, 125 insertions(+), 124 deletions(-) diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index b8995ba..e19bbd9 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -16,7 +16,7 @@ namespace mementar template class Btree { - //static_assert(std::is_base_of::value, "Tdata must be derived from StampedData"); + static_assert(std::is_base_of,Tdata>::value, "Tdata must be derived from StampedData"); public: Btree(size_t order = 10) { diff --git a/include/mementar/core/Data/LinkedFact.h b/include/mementar/core/Data/LinkedFact.h index 1b43675..74d5885 100644 --- a/include/mementar/core/Data/LinkedFact.h +++ b/include/mementar/core/Data/LinkedFact.h @@ -8,32 +8,33 @@ namespace mementar { -class LinkedFact : public Fact +template +class LinkedFact : public Fact { public: - LinkedFact(time_t stamp, const std::string& subject, const std::string& predicat, const std::string& object) : Fact(stamp, subject, predicat, object) + LinkedFact(T stamp, const std::string& subject, const std::string& predicat, const std::string& object) : Fact(stamp, subject, predicat, object) { next_ = nullptr; prev_ = nullptr; } - LinkedFact(time_t stamp, const std::string& triplet = "") : Fact(stamp, triplet) + LinkedFact(T stamp, const std::string& triplet = "") : Fact(stamp, triplet) { next_ = nullptr; prev_ = nullptr; } - bool isEventPart(const LinkedFact& other) const + bool isEventPart(const LinkedFact& other) const { - return ((subject_ == other.subject_) - && (predicat_ == other.predicat_)); + return ((this->subject_ == other.subject_) + && (this->predicat_ == other.predicat_)); } - LinkedFact* next_; - LinkedFact* prev_; + LinkedFact* next_; + LinkedFact* prev_; - std::vector toLinkNext; - std::vector toLinkPrev; + std::vector*> toLinkNext; + std::vector*> toLinkPrev; }; } // namespace mementar diff --git a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h index 0f16f9e..31f6f51 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h @@ -14,12 +14,12 @@ class ArchivedLeafNode ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); - void insert(const time_t& key, LinkedFact* data); - void remove(const time_t& key, const LinkedFact& data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + void insert(const time_t& key, LinkedFact* data); + void remove(const time_t& key, const LinkedFact& data); + BtreeLeaf>* find(const time_t& key); + BtreeLeaf>* findNear(const time_t& key); + BtreeLeaf>* getFirst(); + BtreeLeaf>* getLast(); void display(time_t key); diff --git a/include/mementar/core/EpisodicTree/CompressedLeaf.h b/include/mementar/core/EpisodicTree/CompressedLeaf.h index 0dd0a64..aff6738 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeaf.h +++ b/include/mementar/core/EpisodicTree/CompressedLeaf.h @@ -13,7 +13,7 @@ namespace mementar class CompressedLeaf { public: - CompressedLeaf(Btree* tree, const std::string& directory); + CompressedLeaf(Btree>* tree, const std::string& directory); CompressedLeaf(const time_t& key, const std::string& directory); std::string getDirectory() { return directory_; } @@ -24,7 +24,7 @@ class CompressedLeaf time_t key_; std::string directory_; - std::string treeToString(Btree* tree); + std::string treeToString(Btree>* tree); }; } // namespace mementar diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/EpisodicTree/CompressedLeafNode.h index d15f10e..0be4103 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNode.h @@ -25,12 +25,12 @@ class CompressedLeafNode CompressedLeafNode* split(); - void insert(const time_t& key, LinkedFact* data); - void remove(const time_t& key, const LinkedFact& data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + void insert(const time_t& key, LinkedFact* data); + void remove(const time_t& key, const LinkedFact& data); + BtreeLeaf>* find(const time_t& key); + BtreeLeaf>* findNear(const time_t& key); + BtreeLeaf>* getFirst(); + BtreeLeaf>* getLast(); void display(time_t key); size_t size() { return keys_.size(); } diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h index 04af224..55dd43d 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h @@ -23,12 +23,12 @@ class CompressedLeafNodeSession CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); - void insert(const time_t& key, LinkedFact* data); - bool remove(const time_t& key, const LinkedFact& data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + void insert(const time_t& key, LinkedFact* data); + bool remove(const time_t& key, const LinkedFact& data); + BtreeLeaf>* find(const time_t& key); + BtreeLeaf>* findNear(const time_t& key); + BtreeLeaf>* getFirst(); + BtreeLeaf>* getLast(); time_t getKey() { diff --git a/include/mementar/core/LinkedBtree/LinkedBtree.h b/include/mementar/core/LinkedBtree/LinkedBtree.h index 06e46eb..fa29f22 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtree.h +++ b/include/mementar/core/LinkedBtree/LinkedBtree.h @@ -9,18 +9,18 @@ namespace mementar { template -class LinkedBtree : public Btree +class LinkedBtree : public Btree> { public: - LinkedBtree(size_t order = 10) : Btree(order) {} + LinkedBtree(size_t order = 10) : Btree>(order) {} - size_t insert(const Tkey& key, LinkedFact* data); + size_t insert(const Tkey& key, LinkedFact* data); private: }; template -size_t LinkedBtree::insert(const Tkey& key, LinkedFact* data) +size_t LinkedBtree::insert(const Tkey& key, LinkedFact* data) { this->nb_data_++; if(this->last_ == nullptr) @@ -31,7 +31,7 @@ size_t LinkedBtree::insert(const Tkey& key, LinkedFact* data) } else { - BtreeLeaf* tmp = this->root_->insert(key, data); + BtreeLeaf>* tmp = this->root_->insert(key, data); if(tmp != nullptr) { if(tmp->operator>(this->last_)) diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h index 0e07b68..e1b3199 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -10,35 +10,35 @@ namespace mementar { template -class LinkedBtreeLeafNode : public BtreeLeafNode +class LinkedBtreeLeafNode : public BtreeLeafNode> { public: - LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode(order) + LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode>(order) {} - BtreeLeaf* insert(const Tkey& key, LinkedFact* data); - bool remove(const Tkey& key, const LinkedFact& data); + BtreeLeaf>* insert(const Tkey& key, LinkedFact* data); + bool remove(const Tkey& key, const LinkedFact& data); private: void split(); - LinkedFact* getPrev(BtreeLeaf* current, LinkedFact* data); - std::vector getPrevs(BtreeLeaf* current, LinkedFact* data); - LinkedFact* getNext(BtreeLeaf* current, LinkedFact* data); - std::vector getNexts(BtreeLeaf* current, LinkedFact* data); + LinkedFact* getPrev(BtreeLeaf>* current, LinkedFact* data); + std::vector*> getPrevs(BtreeLeaf>* current, LinkedFact* data); + LinkedFact* getNext(BtreeLeaf>* current, LinkedFact* data); + std::vector*> getNexts(BtreeLeaf>* current, LinkedFact* data); - void linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next); - void linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev); + void linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next); + void linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev); - void unlink(LinkedFact* current_data, BtreeLeaf* current_leaf); - void unlinkPrev(LinkedFact* current, std::vector prev, LinkedFact* next); - void unlinkNext(LinkedFact* current, std::vector next, LinkedFact* prev); + void unlink(LinkedFact* current_data, BtreeLeaf>* current_leaf); + void unlinkPrev(LinkedFact* current, std::vector*> prev, LinkedFact* next); + void unlinkNext(LinkedFact* current, std::vector*> next, LinkedFact* prev); }; template -BtreeLeaf* LinkedBtreeLeafNode::insert(const Tkey& key, LinkedFact* data) +BtreeLeaf>* LinkedBtreeLeafNode::insert(const Tkey& key, LinkedFact* data) { - BtreeLeaf* res = BtreeLeafNode::insert(key, data); + BtreeLeaf>* res = BtreeLeafNode>::insert(key, data); if(res != nullptr) { @@ -53,13 +53,13 @@ BtreeLeaf* LinkedBtreeLeafNode::insert(const Tkey& key, L } template -bool LinkedBtreeLeafNode::remove(const Tkey& key, const LinkedFact& data) +bool LinkedBtreeLeafNode::remove(const Tkey& key, const LinkedFact& data) { for(size_t i = 0; i < this->keys_.size(); i++) { if(this->keys_[i] == key) { - LinkedFact* current_data = this->leafs_[i]->getData(data); + LinkedFact* current_data = this->leafs_[i]->getData(data); unlink(current_data, this->leafs_[i]); this->leafs_[i]->remove(data); if(this->leafs_[i]->getData().size() == 0) @@ -103,7 +103,7 @@ void LinkedBtreeLeafNode::split() } else { - BtreeNode* new_mother = new BtreeNode(this->order_); + BtreeNode>* new_mother = new BtreeNode>(this->order_); new_mother->setLevel(this->level_ + 1); new_mother->insert(this, this->keys_[0]); new_mother->insert(new_node, new_node->keys_[0]); @@ -111,11 +111,11 @@ void LinkedBtreeLeafNode::split() } template -LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf* current, LinkedFact* data) +LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf>* current, LinkedFact* data) { - LinkedFact* res = nullptr; + LinkedFact* res = nullptr; - BtreeLeaf* leaf = current->prev_; + BtreeLeaf>* leaf = current->prev_; while(leaf != nullptr) { for(auto ld : leaf->getData()) @@ -130,12 +130,12 @@ LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf* curre } template -std::vector LinkedBtreeLeafNode::getPrevs(BtreeLeaf* current, LinkedFact* data) +std::vector*> LinkedBtreeLeafNode::getPrevs(BtreeLeaf>* current, LinkedFact* data) { - std::vector res; + std::vector*> res; bool end = false; - BtreeLeaf* leaf = current->prev_; + BtreeLeaf>* leaf = current->prev_; if(leaf == nullptr) end = true; @@ -161,11 +161,11 @@ std::vector LinkedBtreeLeafNode::getPrevs(BtreeLeaf -LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* current, LinkedFact* data) +LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf>* current, LinkedFact* data) { - LinkedFact* res = nullptr; + LinkedFact* res = nullptr; - BtreeLeaf* leaf = current->next_; + BtreeLeaf>* leaf = current->next_; while(leaf != nullptr) { for(auto ld : leaf->getData()) @@ -180,12 +180,12 @@ LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf* curre } template -std::vector LinkedBtreeLeafNode::getNexts(BtreeLeaf* current, LinkedFact* data) +std::vector*> LinkedBtreeLeafNode::getNexts(BtreeLeaf>* current, LinkedFact* data) { - std::vector res; + std::vector*> res; bool end = false; - BtreeLeaf* leaf = current->next_; + BtreeLeaf>* leaf = current->next_; if(leaf == nullptr) end = true; @@ -211,7 +211,7 @@ std::vector LinkedBtreeLeafNode::getNexts(BtreeLeaf -void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next) +void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next) { if(prev == nullptr) return; @@ -240,7 +240,7 @@ void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, } template -void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev) +void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev) { if(next == nullptr) return; @@ -269,10 +269,10 @@ void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, } template -void LinkedBtreeLeafNode::unlink(LinkedFact* current_data, BtreeLeaf* current_leaf) +void LinkedBtreeLeafNode::unlink(LinkedFact* current_data, BtreeLeaf>* current_leaf) { - std::vector prev; - std::vector next; + std::vector*> prev; + std::vector*> next; prev = getPrevs(current_leaf, current_data); next = getNexts(current_leaf, current_data); @@ -282,7 +282,7 @@ void LinkedBtreeLeafNode::unlink(LinkedFact* current_data, BtreeLeaf -void LinkedBtreeLeafNode::unlinkPrev(LinkedFact* current, std::vector prev, LinkedFact* next) +void LinkedBtreeLeafNode::unlinkPrev(LinkedFact* current, std::vector*> prev, LinkedFact* next) { if(prev.size()) { @@ -311,7 +311,7 @@ void LinkedBtreeLeafNode::unlinkPrev(LinkedFact* current, std::vector -void LinkedBtreeLeafNode::unlinkNext(LinkedFact* current, std::vector next, LinkedFact* prev) +void LinkedBtreeLeafNode::unlinkNext(LinkedFact* current, std::vector*> next, LinkedFact* prev) { if(next.size()) { diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 54a5b60..c499771 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -77,7 +77,7 @@ void RosInterface::reset() void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { - LinkedFact* fact = new LinkedFact(time(0), msg->data); + LinkedFact* fact = new LinkedFact(time(0), msg->data); if(fact->valid()) { mut_.lock_shared(); @@ -89,7 +89,7 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { - LinkedFact* fact = new LinkedFact(msg->stamp.sec, msg->data); + LinkedFact* fact = new LinkedFact(msg->stamp.sec, msg->data); if(fact->valid()) { mut_.lock_shared(); @@ -109,7 +109,7 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, if(req.action == "remove") { - LinkedFact fact(req.stamp.sec, req.param); + LinkedFact fact(req.stamp.sec, req.param); if(fact.valid()) { mut_.lock_shared(); diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index 149e22d..0642b83 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -85,7 +85,7 @@ LinkedBtree* ArchivedLeaf::getTree(size_t i) time_t key; std::istringstream iss(match[1].str()); iss >> key; - LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); + LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); tree->insert(key, fact); } diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index 5b2837f..80fb9db 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -50,7 +50,7 @@ ArchivedLeafNode::~ArchivedLeafNode() mut_.unlock(); } -void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) +void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -117,7 +117,7 @@ void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) earlier_key_ = key; } -void ArchivedLeafNode::remove(const time_t& key, const LinkedFact& data) +void ArchivedLeafNode::remove(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); int index = getKeyIndex(key); @@ -137,9 +137,9 @@ void ArchivedLeafNode::remove(const time_t& key, const LinkedFact& data) mut_.unlock_shared(); } -BtreeLeaf* ArchivedLeafNode::find(const time_t& key) +BtreeLeaf>* ArchivedLeafNode::find(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -159,9 +159,9 @@ BtreeLeaf* ArchivedLeafNode::find(const time_t& key) return res; } -BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) +BtreeLeaf>* ArchivedLeafNode::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -182,9 +182,9 @@ BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) return res; } -BtreeLeaf* ArchivedLeafNode::getFirst() +BtreeLeaf>* ArchivedLeafNode::getFirst() { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); if(archived_childs_.size()) @@ -201,9 +201,9 @@ BtreeLeaf* ArchivedLeafNode::getFirst() return res; } -BtreeLeaf* ArchivedLeafNode::getLast() +BtreeLeaf>* ArchivedLeafNode::getLast() { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); if(compressed_childs_.size()) diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index b8a42fb..2a2e8e3 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -9,7 +9,7 @@ namespace mementar { -CompressedLeaf::CompressedLeaf(Btree* tree, const std::string& directory) +CompressedLeaf::CompressedLeaf(Btree>* tree, const std::string& directory) { if(tree == nullptr) return; @@ -56,7 +56,7 @@ LinkedBtree* CompressedLeaf::getTree() time_t key; std::istringstream iss(match[1].str()); iss >> key; - LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); + LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); tree->insert(key, fact); } @@ -68,11 +68,11 @@ LinkedBtree* CompressedLeaf::getTree() return nullptr; } -std::string CompressedLeaf::treeToString(Btree* tree) +std::string CompressedLeaf::treeToString(Btree>* tree) { std::string res; - std::vector tmp_data; - BtreeLeaf* it = tree->getFirst(); + std::vector*> tmp_data; + BtreeLeaf>* it = tree->getFirst(); while(it != nullptr) { tmp_data = it->getData(); diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/EpisodicTree/CompressedLeafNode.cpp index 9445723..ada7805 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/EpisodicTree/CompressedLeafNode.cpp @@ -88,7 +88,7 @@ CompressedLeafNode* CompressedLeafNode::split() return new_one; } -void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) +void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -162,7 +162,7 @@ void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) earlier_key_ = key; } -void CompressedLeafNode::remove(const time_t& key, const LinkedFact& data) +void CompressedLeafNode::remove(const time_t& key, const LinkedFact& data) { mut_.lock_shared(); int index = getKeyIndex(key); @@ -188,9 +188,9 @@ void CompressedLeafNode::remove(const time_t& key, const LinkedFact& data) mut_.unlock_shared(); } -BtreeLeaf* CompressedLeafNode::find(const time_t& key) +BtreeLeaf>* CompressedLeafNode::find(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -210,9 +210,9 @@ BtreeLeaf* CompressedLeafNode::find(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) +BtreeLeaf>* CompressedLeafNode::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -233,9 +233,9 @@ BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNode::getFirst() +BtreeLeaf>* CompressedLeafNode::getFirst() { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); if(compressed_childs_.size()) @@ -252,9 +252,9 @@ BtreeLeaf* CompressedLeafNode::getFirst() return res; } -BtreeLeaf* CompressedLeafNode::getLast() +BtreeLeaf>* CompressedLeafNode::getLast() { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); if(btree_childs_.size()) diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index b55f166..99cd692 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -58,7 +58,7 @@ int CompressedLeafNodeSession::getKeyIndex(const time_t& key) return index; } -void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* data) +void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* data) { mut_.lock_shared(); if(contexts_.size() == 0) @@ -85,7 +85,7 @@ void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* data) mut_.unlock_shared(); } -bool CompressedLeafNodeSession::remove(const time_t& key, const LinkedFact& data) +bool CompressedLeafNodeSession::remove(const time_t& key, const LinkedFact& data) { bool res = false; mut_.lock_shared(); @@ -106,9 +106,9 @@ bool CompressedLeafNodeSession::remove(const time_t& key, const LinkedFact& data return res; } -BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key) +BtreeLeaf>* CompressedLeafNodeSession::find(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -123,9 +123,9 @@ BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key return res; } -BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& key) +BtreeLeaf>* CompressedLeafNodeSession::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -141,9 +141,9 @@ BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& return res; } -BtreeLeaf* CompressedLeafNodeSession::getFirst() +BtreeLeaf>* CompressedLeafNodeSession::getFirst() { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; createSession(0); mut_.lock_shared(); @@ -153,9 +153,9 @@ BtreeLeaf* CompressedLeafNodeSession::getFirst() return res; } -BtreeLeaf* CompressedLeafNodeSession::getLast() +BtreeLeaf>* CompressedLeafNodeSession::getLast() { - BtreeLeaf* res = nullptr; + BtreeLeaf>* res = nullptr; createSession(childs_.size() - 1); mut_.lock_shared(); @@ -200,8 +200,8 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) { std::string res; - std::vector tmp_data; - BtreeLeaf* it = sessions_tree_[index]->getFirst(); + std::vector*> tmp_data; + BtreeLeaf>* it = sessions_tree_[index]->getFirst(); while(it != nullptr) { tmp_data = it->getData(); diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index cc45309..698e487 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -35,7 +35,7 @@ LinkedBtree* CompressedLeafSession::getTree(Header& header, Archive& arc time_t key; std::istringstream iss(match[1].str()); iss >> key; - LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); + LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); tree->insert(key, fact); } diff --git a/src/test/EventLink.cpp b/src/test/EventLink.cpp index ee185de..721522e 100644 --- a/src/test/EventLink.cpp +++ b/src/test/EventLink.cpp @@ -1,7 +1,7 @@ #include "mementar/core/LinkedBtree/LinkedBtree.h" -void displayLink(mementar::LinkedBtree* t) +void displayLink(mementar::LinkedBtree* t) { auto first = t->getFirst(); while(first != nullptr) @@ -24,19 +24,19 @@ void displayLink(mementar::LinkedBtree* t) int main() { - mementar::LinkedBtree tree; + mementar::LinkedBtree tree; for(int i = 20; i >= 0; i--) { if(i % 2) - tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i-1))); + tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i-1))); else - tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i))); + tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i))); } - tree.remove(4, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); - tree.remove(5, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); - tree.remove(6, mementar::LinkedFact(6, "max", "hasCounted", std::to_string(6))); + tree.remove(4, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); + tree.remove(5, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); + tree.remove(6, mementar::LinkedFact(6, "max", "hasCounted", std::to_string(6))); displayLink(&tree); //tree.display(); auto leaf = tree.find(1); @@ -44,10 +44,10 @@ int main() std::cout << "+++++++++++++" << std::endl; if(leaf) { - std::vector datas = leaf->getData(); + std::vector*> datas = leaf->getData(); if(datas.size()) { - mementar::LinkedFact* c = datas[0]; + mementar::LinkedFact* c = datas[0]; while(c != nullptr) { std::cout << *c << std::endl; From 6412694c0a9f772f34e011981a1f3ba54fde2f6d Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jul 2019 15:22:05 +0200 Subject: [PATCH 15/95] [UPDATE] remove key from insert and remove btree functions --- include/mementar/core/Btree/Btree.h | 14 +++---- include/mementar/core/Btree/BtreeLeaf.h | 4 +- include/mementar/core/Btree/BtreeLeafNode.h | 30 +++++++-------- include/mementar/core/Btree/BtreeNode.h | 16 ++++---- include/mementar/core/Data/StampedData.h | 2 +- .../core/EpisodicTree/ArchivedLeafNode.h | 4 +- .../core/EpisodicTree/CompressedLeafNode.h | 4 +- .../EpisodicTree/CompressedLeafNodeSession.h | 4 +- .../mementar/core/LinkedBtree/LinkedBtree.h | 8 ++-- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 12 +++--- src/RosInterface.cpp | 6 +-- src/core/EpisodicTree/ArchivedLeaf.cpp | 2 +- src/core/EpisodicTree/ArchivedLeafNode.cpp | 34 ++++++++--------- src/core/EpisodicTree/CompressedLeaf.cpp | 2 +- src/core/EpisodicTree/CompressedLeafNode.cpp | 38 +++++++++---------- .../CompressedLeafNodeSession.cpp | 14 +++---- .../EpisodicTree/CompressedLeafSession.cpp | 2 +- src/test/EventLink.cpp | 10 ++--- 18 files changed, 103 insertions(+), 103 deletions(-) diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index e19bbd9..773775d 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -41,8 +41,8 @@ class Btree } } - virtual size_t insert(const Tkey& key, Tdata* data); - bool remove(const Tkey& key, const Tdata& data); + virtual size_t insert(Tdata* data); + bool remove(const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); BtreeLeaf* getFirst(); @@ -71,18 +71,18 @@ class Btree }; template -size_t Btree::insert(const Tkey& key, Tdata* data) +size_t Btree::insert(Tdata* data) { nb_data_++; if(last_ == nullptr) { root_ = new BtreeLeafNode(order_); level_ = root_->getLevel(); - last_ = root_->insert(key, data); + last_ = root_->insert(data); } else { - BtreeLeaf* tmp = root_->insert(key, data); + BtreeLeaf* tmp = root_->insert(data); if(tmp != nullptr) { if(tmp->operator>(last_)) @@ -99,11 +99,11 @@ size_t Btree::insert(const Tkey& key, Tdata* data) } template -bool Btree::remove(const Tkey& key, const Tdata& data) +bool Btree::remove(const Tdata& data) { nb_data_--; if(root_ != nullptr) - return root_->remove(key, data); + return root_->remove(data); return false; } diff --git a/include/mementar/core/Btree/BtreeLeaf.h b/include/mementar/core/Btree/BtreeLeaf.h index e82ecd7..56a85ac 100644 --- a/include/mementar/core/Btree/BtreeLeaf.h +++ b/include/mementar/core/Btree/BtreeLeaf.h @@ -13,13 +13,13 @@ template class BtreeLeaf { public: - BtreeLeaf(const Tkey& key, Tdata* data) + BtreeLeaf(Tdata* data) { next_ = nullptr; prev_ = nullptr; mother_ = nullptr; - key_ = key; + key_ = data->getStamp(); data_.push_back(data); } diff --git a/include/mementar/core/Btree/BtreeLeafNode.h b/include/mementar/core/Btree/BtreeLeafNode.h index fe826d0..cab1557 100644 --- a/include/mementar/core/Btree/BtreeLeafNode.h +++ b/include/mementar/core/Btree/BtreeLeafNode.h @@ -16,8 +16,8 @@ class BtreeLeafNode : public BtreeNode ~BtreeLeafNode() {} - virtual BtreeLeaf* insert(const Tkey& key, Tdata* data); - virtual bool remove(const Tkey& key, const Tdata& data); + virtual BtreeLeaf* insert(Tdata* data); + virtual bool remove(const Tdata& data); BtreeLeaf* find(const Tkey& key); BtreeLeaf* findNear(const Tkey& key); BtreeLeaf* getFirst(); @@ -31,14 +31,14 @@ class BtreeLeafNode : public BtreeNode }; template -BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, Tdata* data) +BtreeLeaf* BtreeLeafNode::insert(Tdata* data) { BtreeLeaf* res = nullptr; if(leafs_.size() == 0) { - this->keys_.push_back(key); - res = new BtreeLeaf(key, data); + this->keys_.push_back(data->getStamp()); + res = new BtreeLeaf(data); leafs_.push_back(res); res->setMother(this); } @@ -48,17 +48,17 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, Tdata* if(leafs_.size()) last = leafs_[leafs_.size() - 1]; - if(key > this->keys_[this->keys_.size() - 1]) + if(data->getStamp() > this->keys_[this->keys_.size() - 1]) { - this->keys_.push_back(key); - res = new BtreeLeaf(key, data); + this->keys_.push_back(data->getStamp()); + res = new BtreeLeaf(data); leafs_.push_back(res); res->next_ = last->next_; last->next_ = res; res->prev_ = last; res->setMother(this); } - else if(this->keys_[this->keys_.size() - 1] == key) + else if(this->keys_[this->keys_.size() - 1] == data->getStamp()) { last->push_back(data); } @@ -66,15 +66,15 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, Tdata* { for(size_t i = 0; i < this->keys_.size(); i++) { - if(this->keys_[i] >= key) + if(this->keys_[i] >= data->getStamp()) { - if(this->keys_[i] == key) + if(this->keys_[i] == data->getStamp()) { leafs_[i]->push_back(data); } else { - res = new BtreeLeaf(key, data); + res = new BtreeLeaf(data); // here last is the next node of res last = leafs_[i]; res->next_ = last; @@ -83,7 +83,7 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, Tdata* res->prev_->next_ = res; if(res->next_) res->next_->prev_ = res; - this->keys_.insert(this->keys_.begin() + i, key); + this->keys_.insert(this->keys_.begin() + i, data->getStamp()); this->leafs_.insert(this->leafs_.begin() + i, res); res->setMother(this); } @@ -100,11 +100,11 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, Tdata* } template -bool BtreeLeafNode::remove(const Tkey& key, const Tdata& data) +bool BtreeLeafNode::remove(const Tdata& data) { for(size_t i = 0; i < this->keys_.size(); i++) { - if(this->keys_[i] == key) + if(this->keys_[i] == data.getStamp()) { leafs_[i]->remove(data); if(leafs_[i]->getData().size() == 0) diff --git a/include/mementar/core/Btree/BtreeNode.h b/include/mementar/core/Btree/BtreeNode.h index 26665dd..cc80661 100644 --- a/include/mementar/core/Btree/BtreeNode.h +++ b/include/mementar/core/Btree/BtreeNode.h @@ -25,9 +25,9 @@ class BtreeNode delete child; } - virtual BtreeLeaf* insert(const Tkey& key, Tdata* data); + virtual BtreeLeaf* insert(Tdata* data); void insert(BtreeNode* new_node, const Tkey& key); - virtual bool remove(const Tkey& key, const Tdata& data); + virtual bool remove(const Tdata& data); virtual BtreeLeaf* find(const Tkey& key); virtual BtreeLeaf* findNear(const Tkey& key); virtual BtreeLeaf* getFirst(); @@ -53,18 +53,18 @@ class BtreeNode }; template -BtreeLeaf* BtreeNode::insert(const Tkey& key, Tdata* data) +BtreeLeaf* BtreeNode::insert(Tdata* data) { size_t index = childs_.size() - 1; for(size_t i = 0; i < this->keys_.size(); i++) { - if(key < this->keys_[i]) + if(data->getStamp() < this->keys_[i]) { index = i; break; } } - return childs_[index]->insert(key, data); + return childs_[index]->insert(data); } template @@ -109,18 +109,18 @@ void BtreeNode::insert(BtreeNode* new_node, const Tkey& } template -bool BtreeNode::remove(const Tkey& key, const Tdata& data) +bool BtreeNode::remove( const Tdata& data) { size_t index = this->keys_.size(); for(size_t i = 0; i < this->keys_.size(); i++) { - if(this->keys_[i] > key) + if(this->keys_[i] > data.getStamp()) { index = i; break; } } - return this->childs_[index]->remove(key, data); + return this->childs_[index]->remove(data); if(this->keys_.size() == 0) std::cout << "a node is empty but will not be destroyed" << std::endl; diff --git a/include/mementar/core/Data/StampedData.h b/include/mementar/core/Data/StampedData.h index 19ae56a..35ea4d0 100644 --- a/include/mementar/core/Data/StampedData.h +++ b/include/mementar/core/Data/StampedData.h @@ -13,7 +13,7 @@ class StampedData stamp_ = stamp; } - T getStamp() + T getStamp() const { return stamp_; } diff --git a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h index 31f6f51..7288aad 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/EpisodicTree/ArchivedLeafNode.h @@ -14,8 +14,8 @@ class ArchivedLeafNode ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); - void insert(const time_t& key, LinkedFact* data); - void remove(const time_t& key, const LinkedFact& data); + void insert(LinkedFact* data); + void remove(const LinkedFact& data); BtreeLeaf>* find(const time_t& key); BtreeLeaf>* findNear(const time_t& key); BtreeLeaf>* getFirst(); diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/EpisodicTree/CompressedLeafNode.h index 0be4103..e90c6b9 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNode.h @@ -25,8 +25,8 @@ class CompressedLeafNode CompressedLeafNode* split(); - void insert(const time_t& key, LinkedFact* data); - void remove(const time_t& key, const LinkedFact& data); + void insert(LinkedFact* data); + void remove(const LinkedFact& data); BtreeLeaf>* find(const time_t& key); BtreeLeaf>* findNear(const time_t& key); BtreeLeaf>* getFirst(); diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h index 55dd43d..3ad4cc6 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h @@ -23,8 +23,8 @@ class CompressedLeafNodeSession CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); - void insert(const time_t& key, LinkedFact* data); - bool remove(const time_t& key, const LinkedFact& data); + void insert(LinkedFact* data); + bool remove(const LinkedFact& data); BtreeLeaf>* find(const time_t& key); BtreeLeaf>* findNear(const time_t& key); BtreeLeaf>* getFirst(); diff --git a/include/mementar/core/LinkedBtree/LinkedBtree.h b/include/mementar/core/LinkedBtree/LinkedBtree.h index fa29f22..3832eba 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtree.h +++ b/include/mementar/core/LinkedBtree/LinkedBtree.h @@ -14,24 +14,24 @@ class LinkedBtree : public Btree> public: LinkedBtree(size_t order = 10) : Btree>(order) {} - size_t insert(const Tkey& key, LinkedFact* data); + size_t insert(LinkedFact* data); private: }; template -size_t LinkedBtree::insert(const Tkey& key, LinkedFact* data) +size_t LinkedBtree::insert(LinkedFact* data) { this->nb_data_++; if(this->last_ == nullptr) { this->root_ = new LinkedBtreeLeafNode(this->order_); this->level_ = this->root_->getLevel(); - this->last_ = this->root_->insert(key, data); + this->last_ = this->root_->insert(data); } else { - BtreeLeaf>* tmp = this->root_->insert(key, data); + BtreeLeaf>* tmp = this->root_->insert(data); if(tmp != nullptr) { if(tmp->operator>(this->last_)) diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h index e1b3199..2ec6d64 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -16,8 +16,8 @@ class LinkedBtreeLeafNode : public BtreeLeafNode> LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode>(order) {} - BtreeLeaf>* insert(const Tkey& key, LinkedFact* data); - bool remove(const Tkey& key, const LinkedFact& data); + BtreeLeaf>* insert(LinkedFact* data); + bool remove(const LinkedFact& data); private: void split(); @@ -36,9 +36,9 @@ class LinkedBtreeLeafNode : public BtreeLeafNode> }; template -BtreeLeaf>* LinkedBtreeLeafNode::insert(const Tkey& key, LinkedFact* data) +BtreeLeaf>* LinkedBtreeLeafNode::insert(LinkedFact* data) { - BtreeLeaf>* res = BtreeLeafNode>::insert(key, data); + BtreeLeaf>* res = BtreeLeafNode>::insert(data); if(res != nullptr) { @@ -53,11 +53,11 @@ BtreeLeaf>* LinkedBtreeLeafNode::insert(const Tkey& } template -bool LinkedBtreeLeafNode::remove(const Tkey& key, const LinkedFact& data) +bool LinkedBtreeLeafNode::remove( const LinkedFact& data) { for(size_t i = 0; i < this->keys_.size(); i++) { - if(this->keys_[i] == key) + if(this->keys_[i] == data.getStamp()) { LinkedFact* current_data = this->leafs_[i]->getData(data); unlink(current_data, this->leafs_[i]); diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index c499771..f2a49ad 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -81,7 +81,7 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) if(fact->valid()) { mut_.lock_shared(); - tree_->insert(time(0), fact); + tree_->insert(fact); mut_.unlock_shared(); occasions_.add(fact); } @@ -93,7 +93,7 @@ void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) if(fact->valid()) { mut_.lock_shared(); - tree_->insert(msg->stamp.sec, fact); + tree_->insert(fact); mut_.unlock_shared(); occasions_.add(fact); } @@ -113,7 +113,7 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, if(fact.valid()) { mut_.lock_shared(); - tree_->remove(req.stamp.sec, fact); + tree_->remove(fact); mut_.unlock_shared(); } else diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index 0642b83..7640be3 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -87,7 +87,7 @@ LinkedBtree* ArchivedLeaf::getTree(size_t i) iss >> key; LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); - tree->insert(key, fact); + tree->insert(fact); } } diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index 80fb9db..2f50d6e 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -50,41 +50,41 @@ ArchivedLeafNode::~ArchivedLeafNode() mut_.unlock(); } -void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) +void ArchivedLeafNode::insert(LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) { mut_.unlock_shared(); - createNewCompressedChild(key); + createNewCompressedChild(data->getStamp()); mut_.lock_shared(); - compressed_childs_[0]->insert(key, data); + compressed_childs_[0]->insert(data); } else { - if(key < keys_[0]) + if(data->getStamp() < keys_[0]) { Display::Error("try to insert fact in past that do not exist"); return; } - size_t index = getKeyIndex(key); + size_t index = getKeyIndex(data->getStamp()); if(index < archived_childs_.size()) { - if((index == archived_childs_.size() - 1) && (keys_.size() == archived_childs_.size()) && (key > earlier_key_)) + if((index == archived_childs_.size() - 1) && (keys_.size() == archived_childs_.size()) && (data->getStamp() > earlier_key_)) { mut_.unlock_shared(); - createNewCompressedChild(key); + createNewCompressedChild(data->getStamp()); mut_.lock_shared(); - compressed_childs_[0]->insert(key, data); + compressed_childs_[0]->insert(data); } else { mut_.unlock_shared(); createSession(index); mut_.lock_shared(); - archived_sessions_tree_[index]->insert(key, data); + archived_sessions_tree_[index]->insert(data); modified_[index] = true; } } @@ -96,7 +96,7 @@ void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) keys_.push_back(compressed_childs_[compressed_childs_.size() - 1]->getKey()); mut_.unlock(); mut_.lock_shared(); - compressed_childs_[compressed_childs_.size() - 1]->insert(key, data); + compressed_childs_[compressed_childs_.size() - 1]->insert(data); //verify if a chld need to be compressed if(compressed_childs_.size() > 1) @@ -108,19 +108,19 @@ void ArchivedLeafNode::insert(const time_t& key, LinkedFact* data) } else { - compressed_childs_[index - archived_childs_.size()]->insert(key,data); + compressed_childs_[index - archived_childs_.size()]->insert(data); } } mut_.unlock_shared(); - if(earlier_key_ < key) - earlier_key_ = key; + if(earlier_key_ < data->getStamp()) + earlier_key_ = data->getStamp(); } -void ArchivedLeafNode::remove(const time_t& key, const LinkedFact& data) +void ArchivedLeafNode::remove(const LinkedFact& data) { mut_.lock_shared(); - int index = getKeyIndex(key); + int index = getKeyIndex(data.getStamp()); if(index >= 0) { if((size_t)index < archived_childs_.size()) @@ -128,11 +128,11 @@ void ArchivedLeafNode::remove(const time_t& key, const LinkedFact& data) mut_.unlock_shared(); createSession(index); mut_.lock_shared(); - if(archived_sessions_tree_[index]->remove(key, data)) + if(archived_sessions_tree_[index]->remove(data)) modified_[index] = true; } else - compressed_childs_[index - archived_childs_.size()]->remove(key, data); + compressed_childs_[index - archived_childs_.size()]->remove(data); } mut_.unlock_shared(); } diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 2a2e8e3..963106a 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -58,7 +58,7 @@ LinkedBtree* CompressedLeaf::getTree() iss >> key; LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); - tree->insert(key, fact); + tree->insert(fact); } } diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/EpisodicTree/CompressedLeafNode.cpp index ada7805..918dd54 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/EpisodicTree/CompressedLeafNode.cpp @@ -88,35 +88,35 @@ CompressedLeafNode* CompressedLeafNode::split() return new_one; } -void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) +void CompressedLeafNode::insert(LinkedFact* data) { mut_.lock_shared(); if(keys_.size() == 0) { mut_.unlock_shared(); - createNewTreeChild(key); + createNewTreeChild(data->getStamp()); mut_.lock_shared(); - last_tree_nb_leafs_ = btree_childs_[0]->insert(key, data); + last_tree_nb_leafs_ = btree_childs_[0]->insert(data); contexts_[0].insert(data); } else { - if(key < keys_[0]) + if(data->getStamp() < keys_[0]) { Display::Error("try to insert fact in past that do not exist"); return; } - size_t index = getKeyIndex(key); + size_t index = getKeyIndex(data->getStamp()); if(index < compressed_childs_.size()) { - if((index == compressed_childs_.size() - 1) && (keys_.size() == compressed_childs_.size()) && (key > earlier_key_)) + if((index == compressed_childs_.size() - 1) && (keys_.size() == compressed_childs_.size()) && (data->getStamp() > earlier_key_)) { mut_.unlock_shared(); - createNewTreeChild(key); + createNewTreeChild(data->getStamp()); mut_.lock_shared(); - last_tree_nb_leafs_ = btree_childs_[0]->insert(key, data); + last_tree_nb_leafs_ = btree_childs_[0]->insert(data); contexts_[keys_.size() - 1].insert(data); } else @@ -124,7 +124,7 @@ void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) mut_.unlock_shared(); createSession(index); mut_.lock_shared(); - compressed_sessions_tree_[index]->insert(key, data); + compressed_sessions_tree_[index]->insert(data); contexts_[index].insert(data); modified_[index] = true; } @@ -132,9 +132,9 @@ void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) else if(useNewTree()) { mut_.unlock_shared(); - createNewTreeChild(key); + createNewTreeChild(data->getStamp()); mut_.lock_shared(); - last_tree_nb_leafs_ = btree_childs_[btree_childs_.size() - 1]->insert(key, data); + last_tree_nb_leafs_ = btree_childs_[btree_childs_.size() - 1]->insert(data); contexts_[keys_.size() - 1].insert(data); //verify if a chld need to be compressed @@ -147,25 +147,25 @@ void CompressedLeafNode::insert(const time_t& key, LinkedFact* data) } else if(index - keys_.size() + 1 == 0) // if insert in more recent tree { - last_tree_nb_leafs_ = btree_childs_[index - compressed_childs_.size()]->insert(key,data); + last_tree_nb_leafs_ = btree_childs_[index - compressed_childs_.size()]->insert(data); contexts_[index].insert(data); } else { - btree_childs_[index - compressed_childs_.size()]->insert(key,data); + btree_childs_[index - compressed_childs_.size()]->insert(data); contexts_[index].insert(data); } } mut_.unlock_shared(); - if(earlier_key_ < key) - earlier_key_ = key; + if(earlier_key_ < data->getStamp()) + earlier_key_ = data->getStamp(); } -void CompressedLeafNode::remove(const time_t& key, const LinkedFact& data) +void CompressedLeafNode::remove(const LinkedFact& data) { mut_.lock_shared(); - int index = getKeyIndex(key); + int index = getKeyIndex(data.getStamp()); if(index >= 0) { if((size_t)index < compressed_childs_.size()) @@ -173,7 +173,7 @@ void CompressedLeafNode::remove(const time_t& key, const LinkedFact& dat mut_.unlock_shared(); createSession(index); mut_.lock_shared(); - if(compressed_sessions_tree_[index]->remove(key, data)) + if(compressed_sessions_tree_[index]->remove(data)) { modified_[index] = true; contexts_[index].remove(&data); @@ -181,7 +181,7 @@ void CompressedLeafNode::remove(const time_t& key, const LinkedFact& dat } else { - if(btree_childs_[index - compressed_childs_.size()]->remove(key, data)) + if(btree_childs_[index - compressed_childs_.size()]->remove(data)) contexts_[index].remove(&data); } } diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index 99cd692..6cdf445 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -58,7 +58,7 @@ int CompressedLeafNodeSession::getKeyIndex(const time_t& key) return index; } -void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* data) +void CompressedLeafNodeSession::insert(LinkedFact* data) { mut_.lock_shared(); if(contexts_.size() == 0) @@ -67,17 +67,17 @@ void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* da } else { - if(key < contexts_[0].getKey()) + if(data->getStamp() < contexts_[0].getKey()) { Display::Error("try to insert fact in past that do not exist"); return; } - size_t index = getKeyIndex(key); + size_t index = getKeyIndex(data->getStamp()); mut_.unlock_shared(); createSession(index); mut_.lock_shared(); - sessions_tree_[index]->insert(key, data); + sessions_tree_[index]->insert(data); contexts_[index].insert(data); modified_[index] = true; } @@ -85,17 +85,17 @@ void CompressedLeafNodeSession::insert(const time_t& key, LinkedFact* da mut_.unlock_shared(); } -bool CompressedLeafNodeSession::remove(const time_t& key, const LinkedFact& data) +bool CompressedLeafNodeSession::remove(const LinkedFact& data) { bool res = false; mut_.lock_shared(); - int index = getKeyIndex(key); + int index = getKeyIndex(data.getStamp()); if(index >= 0) { mut_.unlock_shared(); createSession(index); mut_.lock_shared(); - if(sessions_tree_[index]->remove(key, data)) + if(sessions_tree_[index]->remove(data)) { modified_[index] = true; contexts_[index].remove(&data); diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index 698e487..18df27f 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -37,7 +37,7 @@ LinkedBtree* CompressedLeafSession::getTree(Header& header, Archive& arc iss >> key; LinkedFact* fact = new LinkedFact(key, match[2].str(), match[3].str(), match[4].str()); - tree->insert(key, fact); + tree->insert(fact); } } diff --git a/src/test/EventLink.cpp b/src/test/EventLink.cpp index 721522e..c026c34 100644 --- a/src/test/EventLink.cpp +++ b/src/test/EventLink.cpp @@ -29,14 +29,14 @@ int main() for(int i = 20; i >= 0; i--) { if(i % 2) - tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i-1))); + tree.insert(new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i-1))); else - tree.insert(i, new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i))); + tree.insert(new mementar::LinkedFact(i, "max", "hasCounted", std::to_string(i))); } - tree.remove(4, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); - tree.remove(5, mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); - tree.remove(6, mementar::LinkedFact(6, "max", "hasCounted", std::to_string(6))); + tree.remove(mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); + tree.remove(mementar::LinkedFact(4, "max", "hasCounted", std::to_string(4))); + tree.remove(mementar::LinkedFact(6, "max", "hasCounted", std::to_string(6))); displayLink(&tree); //tree.display(); auto leaf = tree.find(1); From 0bc9f213bddbfc25a0c33d509a88f79e0c214f75 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jul 2019 15:43:55 +0200 Subject: [PATCH 16/95] [UPDATE] specific test files --- src/core/Btree/tests/btree_test.cpp | 35 +++++++++++++++---- src/core/Btree/tests/max_insertion.cpp | 27 ++++++++++++-- src/core/EpisodicTree/tests/archived_tree.cpp | 6 ++-- src/core/EpisodicTree/tests/episodic_tree.cpp | 6 ++-- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/core/Btree/tests/btree_test.cpp b/src/core/Btree/tests/btree_test.cpp index 5884644..39ecdc9 100644 --- a/src/core/Btree/tests/btree_test.cpp +++ b/src/core/Btree/tests/btree_test.cpp @@ -6,12 +6,35 @@ #include "mementar/core/Btree/BtreeLeaf.h" #include "mementar/core/Btree/Btree.h" +#include "mementar/core/Data/StampedData.h" + using namespace std::chrono; +class stampedInt : public mementar::StampedData +{ +public: + stampedInt(int stamp, int data) : StampedData(stamp) + { + data_ = data; + } + int data_; + + friend std::ostream& operator<<(std::ostream& os, const stampedInt& data) + { + os << data.data_; + return os; + } + + bool operator==(const stampedInt& other) const + { + return (data_ == other.data_); + } +}; + int main() { - mementar::BtreeLeaf leaf1(0, 2); - mementar::BtreeLeaf leaf2(1, 3); + mementar::BtreeLeaf leaf1(new stampedInt(0, 2)); + mementar::BtreeLeaf leaf2(new stampedInt(1, 3)); if(leaf1.operator<(&leaf2)) std::cout << "inf" << std::endl; @@ -24,9 +47,9 @@ int main() { high_resolution_clock::time_point t1 = high_resolution_clock::now(); - mementar::Btree tree(3); + mementar::Btree tree(3); for(size_t i = 0; i < nb; i++) - tree.insert(i, i); + tree.insert(new stampedInt(i, i)); //tree.display(); @@ -43,8 +66,8 @@ int main() res = tree.getFirst(); if(res) std::cout << res->getKey() << std::endl; - tree.remove(40,40); - tree.insert(40,41); + tree.remove(stampedInt(40,40)); + tree.insert(new stampedInt(40,41)); tree.display(); std::cout << "estimation = " << tree.estimateMinLeaves() << std::endl; diff --git a/src/core/Btree/tests/max_insertion.cpp b/src/core/Btree/tests/max_insertion.cpp index 4bb7e1b..a54275c 100644 --- a/src/core/Btree/tests/max_insertion.cpp +++ b/src/core/Btree/tests/max_insertion.cpp @@ -6,17 +6,40 @@ #include "mementar/core/Btree/BtreeLeaf.h" #include "mementar/core/Btree/Btree.h" +#include "mementar/core/Data/StampedData.h" + using namespace std::chrono; +class stampedInt : public mementar::StampedData +{ +public: + stampedInt(size_t stamp, int data) : StampedData(stamp) + { + data_ = data; + } + size_t data_; + + friend std::ostream& operator<<(std::ostream& os, const stampedInt& data) + { + os << data.data_; + return os; + } + + bool operator==(const stampedInt& other) const + { + return (data_ == other.data_); + } +}; + int main() { size_t nb = 349526; high_resolution_clock::time_point t1 = high_resolution_clock::now(); - mementar::Btree tree(5); + mementar::Btree tree(5); for(size_t i = 0; true; i++) - if(tree.insert(i, i) >= nb) + if(tree.insert(new stampedInt(i, i)) >= nb) break; high_resolution_clock::time_point t2 = high_resolution_clock::now(); diff --git a/src/core/EpisodicTree/tests/archived_tree.cpp b/src/core/EpisodicTree/tests/archived_tree.cpp index 67ab66a..f3c6d13 100644 --- a/src/core/EpisodicTree/tests/archived_tree.cpp +++ b/src/core/EpisodicTree/tests/archived_tree.cpp @@ -19,7 +19,7 @@ int main() std::cout << " *************" << std::endl; for(size_t i = 0; i < 400000; i++) { - archived_node.insert(i, mementar::Fact("bob", "hasValue", std::to_string(i))); + archived_node.insert(new mementar::LinkedFact(i, "bob", "hasValue", std::to_string(i))); if(i == 250000) archived_node.newSession(); } @@ -30,9 +30,9 @@ int main() std::cout << "took " << time_span.count() << std::endl; std::cout << "will remove" << std::endl; - archived_node.remove(102,mementar::Fact("bob", "hasValue", std::to_string(102))); + archived_node.remove(mementar::LinkedFact(102, "bob", "hasValue", std::to_string(102))); std::cout << "removed" << std::endl; - archived_node.insert(0, mementar::Fact("bob", "hasValue", std::to_string(0))); + archived_node.insert(new mementar::LinkedFact(0, "bob", "hasValue", std::to_string(0))); std::cout << "inserted" << std::endl; std::cout << " *************" << std::endl; diff --git a/src/core/EpisodicTree/tests/episodic_tree.cpp b/src/core/EpisodicTree/tests/episodic_tree.cpp index ba2f3e7..c18bf65 100644 --- a/src/core/EpisodicTree/tests/episodic_tree.cpp +++ b/src/core/EpisodicTree/tests/episodic_tree.cpp @@ -21,7 +21,7 @@ int main() for(size_t i = 0; i < 400000; i++) { //std::cout << i << std::endl; - compressed_node.insert(i, mementar::Fact("bob", "hasValue", std::to_string(i))); + compressed_node.insert(new mementar::LinkedFact(i, "bob", "hasValue", std::to_string(i))); //usleep(1); } std::cout << " *************" << std::endl; @@ -30,8 +30,8 @@ int main() duration time_span = duration_cast>(t2 - t1); std::cout << "took " << time_span.count() << std::endl; - compressed_node.remove(102,mementar::Fact("bob", "hasValue", std::to_string(102))); - compressed_node.insert(0, mementar::Fact("bob", "hasValue", std::to_string(0))); + compressed_node.remove(mementar::LinkedFact(102, "bob", "hasValue", std::to_string(102))); + compressed_node.insert(new mementar::LinkedFact(0, "bob", "hasValue", std::to_string(0))); std::cout << " *************" << std::endl; /*//compressed_node.display(150000); From 7a8dfcafe7046d6c2b162ac17f8f9a9d8bcece40 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jul 2019 16:50:52 +0200 Subject: [PATCH 17/95] [REFACT] LinkedBtreeLeafNode typedef --- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h index 2ec6d64..c831f52 100644 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h @@ -12,33 +12,35 @@ namespace mementar template class LinkedBtreeLeafNode : public BtreeLeafNode> { + typedef LinkedFact LinkedFact_; + typedef BtreeLeaf LinkedBtreeLeaf_; public: - LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode>(order) + LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode(order) {} - BtreeLeaf>* insert(LinkedFact* data); - bool remove(const LinkedFact& data); + BtreeLeaf* insert(LinkedFact_* data); + bool remove(const LinkedFact_& data); private: void split(); - LinkedFact* getPrev(BtreeLeaf>* current, LinkedFact* data); - std::vector*> getPrevs(BtreeLeaf>* current, LinkedFact* data); - LinkedFact* getNext(BtreeLeaf>* current, LinkedFact* data); - std::vector*> getNexts(BtreeLeaf>* current, LinkedFact* data); + LinkedFact_* getPrev(LinkedBtreeLeaf_* current, LinkedFact_* data); + std::vector getPrevs(LinkedBtreeLeaf_* current, LinkedFact_* data); + LinkedFact_* getNext(LinkedBtreeLeaf_* current, LinkedFact_* data); + std::vector getNexts(LinkedBtreeLeaf_* current, LinkedFact_* data); - void linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next); - void linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev); + void linkPrev(LinkedFact_* current, LinkedFact_* prev, LinkedFact_* next); + void linkNext(LinkedFact_* current, LinkedFact_* next, LinkedFact_* prev); - void unlink(LinkedFact* current_data, BtreeLeaf>* current_leaf); - void unlinkPrev(LinkedFact* current, std::vector*> prev, LinkedFact* next); - void unlinkNext(LinkedFact* current, std::vector*> next, LinkedFact* prev); + void unlink(LinkedFact_* current_data, LinkedBtreeLeaf_* current_leaf); + void unlinkPrev(LinkedFact_* current, std::vector prev, LinkedFact_* next); + void unlinkNext(LinkedFact_* current, std::vector next, LinkedFact_* prev); }; template BtreeLeaf>* LinkedBtreeLeafNode::insert(LinkedFact* data) { - BtreeLeaf>* res = BtreeLeafNode>::insert(data); + LinkedBtreeLeaf_* res = BtreeLeafNode>::insert(data); if(res != nullptr) { @@ -59,7 +61,7 @@ bool LinkedBtreeLeafNode::remove( const LinkedFact& data) { if(this->keys_[i] == data.getStamp()) { - LinkedFact* current_data = this->leafs_[i]->getData(data); + LinkedFact_* current_data = this->leafs_[i]->getData(data); unlink(current_data, this->leafs_[i]); this->leafs_[i]->remove(data); if(this->leafs_[i]->getData().size() == 0) @@ -103,7 +105,7 @@ void LinkedBtreeLeafNode::split() } else { - BtreeNode>* new_mother = new BtreeNode>(this->order_); + BtreeNode* new_mother = new BtreeNode(this->order_); new_mother->setLevel(this->level_ + 1); new_mother->insert(this, this->keys_[0]); new_mother->insert(new_node, new_node->keys_[0]); @@ -113,9 +115,9 @@ void LinkedBtreeLeafNode::split() template LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf>* current, LinkedFact* data) { - LinkedFact* res = nullptr; + LinkedFact_* res = nullptr; - BtreeLeaf>* leaf = current->prev_; + LinkedBtreeLeaf_* leaf = current->prev_; while(leaf != nullptr) { for(auto ld : leaf->getData()) @@ -132,10 +134,10 @@ LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf std::vector*> LinkedBtreeLeafNode::getPrevs(BtreeLeaf>* current, LinkedFact* data) { - std::vector*> res; + std::vector res; bool end = false; - BtreeLeaf>* leaf = current->prev_; + LinkedBtreeLeaf_* leaf = current->prev_; if(leaf == nullptr) end = true; @@ -163,9 +165,9 @@ std::vector*> LinkedBtreeLeafNode::getPrevs(BtreeLeaf LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf>* current, LinkedFact* data) { - LinkedFact* res = nullptr; + LinkedFact_* res = nullptr; - BtreeLeaf>* leaf = current->next_; + LinkedBtreeLeaf_* leaf = current->next_; while(leaf != nullptr) { for(auto ld : leaf->getData()) @@ -182,10 +184,10 @@ LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf std::vector*> LinkedBtreeLeafNode::getNexts(BtreeLeaf>* current, LinkedFact* data) { - std::vector*> res; + std::vector res; bool end = false; - BtreeLeaf>* leaf = current->next_; + LinkedBtreeLeaf_* leaf = current->next_; if(leaf == nullptr) end = true; @@ -271,8 +273,8 @@ void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact void LinkedBtreeLeafNode::unlink(LinkedFact* current_data, BtreeLeaf>* current_leaf) { - std::vector*> prev; - std::vector*> next; + std::vector prev; + std::vector next; prev = getPrevs(current_leaf, current_data); next = getNexts(current_leaf, current_data); From fa5c6807a7dfda06fea5492bd839007c755f6194 Mon Sep 17 00:00:00 2001 From: Julien Combattelli Date: Sun, 17 Nov 2019 21:44:35 +0100 Subject: [PATCH 18/95] Fix path to string conversion --- src/core/EpisodicTree/ArchivedLeafNode.cpp | 2 +- src/core/EpisodicTree/CompressedLeafNode.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/EpisodicTree/ArchivedLeafNode.cpp index 2f50d6e..c2ec671 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/EpisodicTree/ArchivedLeafNode.cpp @@ -283,7 +283,7 @@ void ArchivedLeafNode::loadStoredData() for(const auto& entry : std::experimental::filesystem::directory_iterator(directory_)) { - std::string complete_dir = entry.path(); + std::string complete_dir = entry.path().generic_string(); std::string dir = complete_dir.substr(directory_.size()); if(dir[0] == '/') dir.erase(dir.begin()); diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/EpisodicTree/CompressedLeafNode.cpp index 918dd54..9d8b03a 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/EpisodicTree/CompressedLeafNode.cpp @@ -341,7 +341,12 @@ bool CompressedLeafNode::loadStoredData() for(const auto& entry : std::experimental::filesystem::directory_iterator(directory_)) { - std::string complete_dir = entry.path(); + // std::filesystem::path to std::string conversion is platform-dependent: + // it needs std::string on POSIX and std::wstring on Windows. Futhermore, + // the directory separator change between operating systems. + // To solve this, we force the conversion to std::string ('/' is used as + // directory separator). + std::string complete_dir = entry.path().generic_string(); std::string dir = complete_dir.substr(directory_.size()); if(dir[0] == '/') dir.erase(dir.begin()); From 14f3d72a9fcb923cdf073628d6cd894dddbad625 Mon Sep 17 00:00:00 2001 From: Julien Combattelli Date: Mon, 18 Nov 2019 19:00:26 +0100 Subject: [PATCH 19/95] Remove unused and non cross-platform unistd include --- src/core/EpisodicTree/tests/archived_tree.cpp | 1 - src/core/EpisodicTree/tests/episodic_tree.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/core/EpisodicTree/tests/archived_tree.cpp b/src/core/EpisodicTree/tests/archived_tree.cpp index f3c6d13..1806ca7 100644 --- a/src/core/EpisodicTree/tests/archived_tree.cpp +++ b/src/core/EpisodicTree/tests/archived_tree.cpp @@ -3,7 +3,6 @@ #include /* srand, rand */ #include /* time */ #include -#include #include "mementar/core/Btree/Btree.h" #include "mementar/core/EpisodicTree/ArchivedLeafNode.h" diff --git a/src/core/EpisodicTree/tests/episodic_tree.cpp b/src/core/EpisodicTree/tests/episodic_tree.cpp index c18bf65..0e6bc8b 100644 --- a/src/core/EpisodicTree/tests/episodic_tree.cpp +++ b/src/core/EpisodicTree/tests/episodic_tree.cpp @@ -3,7 +3,6 @@ #include /* srand, rand */ #include /* time */ #include -#include #include "mementar/core/EpisodicTree/CompressedLeaf.h" #include "mementar/core/Btree/Btree.h" From 75f44f01404e0c401bb25417969140b77500a781 Mon Sep 17 00:00:00 2001 From: Julien Combattelli Date: Mon, 18 Nov 2019 18:54:09 +0100 Subject: [PATCH 20/95] Add missing include for std::max --- src/core/archiving_compressing/compressing/LzCompress.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/archiving_compressing/compressing/LzCompress.cpp b/src/core/archiving_compressing/compressing/LzCompress.cpp index 5e06d93..3baaa2e 100644 --- a/src/core/archiving_compressing/compressing/LzCompress.cpp +++ b/src/core/archiving_compressing/compressing/LzCompress.cpp @@ -1,5 +1,6 @@ #include "mementar/core/archiving_compressing/compressing/LzCompress.h" +#include #include #include From 4db5b0e9b74d410074e4cfb080349ac5b6aa7f21 Mon Sep 17 00:00:00 2001 From: Julien Combattelli Date: Sun, 17 Nov 2019 21:23:56 +0100 Subject: [PATCH 21/95] Add missing sstream inclusions --- src/core/EpisodicTree/CompressedLeaf.cpp | 1 + src/core/EpisodicTree/CompressedLeafSession.cpp | 1 + src/core/EpisodicTree/Context.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 963106a..406ea7a 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "mementar/core/EpisodicTree/CompressedLeaf.h" diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index 18df27f..67977ec 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -1,6 +1,7 @@ #include "mementar/core/EpisodicTree/CompressedLeafSession.h" #include +#include #include "mementar/core/archiving_compressing/compressing/LzUncompress.h" diff --git a/src/core/EpisodicTree/Context.cpp b/src/core/EpisodicTree/Context.cpp index 44bd90e..a54951a 100644 --- a/src/core/EpisodicTree/Context.cpp +++ b/src/core/EpisodicTree/Context.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "mementar/core/utility/Display.h" From ea605adab3e2beb794ea18c4f879c9317c628115 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 30 Mar 2020 17:27:43 +0200 Subject: [PATCH 22/95] huffman encoding optimisation --- .../binaryManagement/BinaryManager.h | 3 +- .../binaryManagement/BitFileGenerator.h | 4 +- .../compressing/Huffman_.h | 62 ++++++ src/core/archiving_compressing/CMakeLists.txt | 7 + .../binaryManagement/BitFileGenerator.cpp | 42 +++- .../compressing/Huffman_.cpp | 203 ++++++++++++++++++ .../tests/perfs/huffman_in.cpp | 102 +++++++++ 7 files changed, 412 insertions(+), 11 deletions(-) create mode 100644 include/mementar/core/archiving_compressing/compressing/Huffman_.h create mode 100644 src/core/archiving_compressing/compressing/Huffman_.cpp create mode 100644 src/core/archiving_compressing/tests/perfs/huffman_in.cpp diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h b/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h index cc51c04..fafe0c2 100644 --- a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h +++ b/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h @@ -26,8 +26,7 @@ class BinaryManager { std::ofstream outfile; outfile.open(file_name + "." + extension_, std::ios::binary | std::ios::out); - std::string str(data.begin(), data.end()); - outfile.write(str.c_str(), str.length()); + outfile.write(reinterpret_cast(data.data()), data.size()); outfile.close(); std::cout << "Saved into " << file_name << "." << extension_ << std::endl; diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h b/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h index bebfe04..a5512dd 100644 --- a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h +++ b/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h @@ -11,18 +11,20 @@ class BitFileGenerator { public: BitFileGenerator(uint8_t size_1 = 0, uint8_t size_2 = 0, uint8_t size_3 = 0, uint8_t size_4 = 0); + void resize(size_t size) { data_.resize(size, 0); }; void writeType1(uint32_t value); void writeType2(uint32_t value); void writeType3(uint32_t value); void writeType4(uint32_t value); void writeN(size_t size, uint32_t value); + void writeNReverse(size_t size, uint32_t value); void writeChar(char value); void writeBitTrue(); void writeBitFalse(); - std::vector get() { return data_; } + std::vector get() { return std::vector(data_.begin(), data_.begin() + major_index_); } void get(std::vector& out) { out = data_; } private: diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_.h b/include/mementar/core/archiving_compressing/compressing/Huffman_.h new file mode 100644 index 0000000..8cd103b --- /dev/null +++ b/include/mementar/core/archiving_compressing/compressing/Huffman_.h @@ -0,0 +1,62 @@ +#ifndef MEMENTAR_HUFFMAN__H +#define MEMENTAR_HUFFMAN__H + +#include +#include +#include + +#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" + +namespace mementar +{ + +struct HuffCode_t +{ + uint32_t value_; + uint8_t size_; +}; + +struct HuffNode_t { + using Index = std::uint16_t; + using Frequency = std::uint32_t; + + static constexpr Index invalid_index = std::numeric_limits::max(); + + Frequency freq{}; + Index left{invalid_index}; + Index right{invalid_index}; + HuffCode_t code; +}; + +// Number of values representable with a byte +static constexpr HuffNode_t::Index values_in_byte = 1 << (sizeof(std::uint8_t) * 8); + +// Maximum number of leaf nodes (character) in an Huffman tree +static constexpr HuffNode_t::Index leaf_count = values_in_byte; + +// Maximum number of nodes (leaf + bind) in an Huffman tree +static constexpr HuffNode_t::Index node_count = leaf_count * 2; + +using FrequencyMap = std::array; +using NodeList = std::array; + +class Huffman_ : public BinaryManager +{ +public: + Huffman_(); + void generateTree(const std::string& data, std::size_t jobs = 1); + void getTreeCode(std::vector& out); + void getDataCode(const std::vector& data, std::vector& out); + +private: + NodeList nodes_{}; + + void sum(const FrequencyMap& other, FrequencyMap& into); + FrequencyMap count_char(const std::string& text, std::size_t jobs = 1); + HuffNode_t::Index generateTree(const FrequencyMap& freq); + void generateCode(HuffNode_t::Index index); +}; + +} // namespace mementar + +#endif // MEMENTAR_HUFFMAN__H diff --git a/src/core/archiving_compressing/CMakeLists.txt b/src/core/archiving_compressing/CMakeLists.txt index 83d28fc..5d5e3da 100644 --- a/src/core/archiving_compressing/CMakeLists.txt +++ b/src/core/archiving_compressing/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(mementar_compression_lib compressing/LzCompress.cpp compressing/LzUncompress.cpp compressing/Huffman.cpp + compressing/Huffman_.cpp archiving/Header.cpp archiving/Archive.cpp ) @@ -25,3 +26,9 @@ target_link_libraries(uncompress mementar_compression_lib) add_executable(archive tests/archive.cpp) target_link_libraries(archive mementar_compression_lib) + + +### + +add_executable(huffman_in tests/perfs/huffman_in.cpp) +target_link_libraries(huffman_in mementar_compression_lib pthread) diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp b/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp index ce20f1d..148b7fb 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp +++ b/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp @@ -29,8 +29,9 @@ void BitFileGenerator::writeType1(uint32_t value) to_add -= added; if(to_add >= 0) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -52,8 +53,9 @@ void BitFileGenerator::writeType2(uint32_t value) to_add -= added; if(to_add >= 0) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -75,8 +77,9 @@ void BitFileGenerator::writeType3(uint32_t value) to_add -= added; if(to_add >= 0) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -98,8 +101,9 @@ void BitFileGenerator::writeType4(uint32_t value) to_add -= added; if(to_add >= 0) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -121,8 +125,9 @@ void BitFileGenerator::writeN(size_t size, uint32_t value) to_add -= added; if(to_add >= 0) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -131,6 +136,24 @@ void BitFileGenerator::writeN(size_t size, uint32_t value) while(to_add > 0); } +void BitFileGenerator::writeNReverse(size_t size, uint32_t value) +{ + for(uint32_t i = 1 << (size - 1); i > 0; i >>= 1) + { + if(value & i) + data_[major_index_] |= (1 << minor_index_); + + minor_index_++; + if(minor_index_ > 7) + { + major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); + minor_index_ = 0; + } + } +} + void BitFileGenerator::writeChar(char value) { int8_t to_add = 7; @@ -144,8 +167,9 @@ void BitFileGenerator::writeChar(char value) to_add -= added; if(to_add >= 0) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -159,8 +183,9 @@ void BitFileGenerator::writeBitTrue() data_[major_index_] |= (1 << minor_index_); if(minor_index_ >= 7) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else @@ -171,8 +196,9 @@ void BitFileGenerator::writeBitFalse() { if(minor_index_ >= 7) { - data_.push_back(0x00); major_index_++; + if(data_.size() <= major_index_) + data_.push_back(0x00); minor_index_ = 0; } else diff --git a/src/core/archiving_compressing/compressing/Huffman_.cpp b/src/core/archiving_compressing/compressing/Huffman_.cpp new file mode 100644 index 0000000..d61e929 --- /dev/null +++ b/src/core/archiving_compressing/compressing/Huffman_.cpp @@ -0,0 +1,203 @@ +#include "mementar/core/archiving_compressing/compressing/Huffman_.h" + +#include +#include +#include +#include +#include + +#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" + +#define TREE_CHAR_SIZE 8 +#define TREE_VALUE_SIZE 6 +#define TREE_VALUE_SIZE_SIZE 31 //do not go over 31 + +template +struct static_alloc { + using value_type = T; + static_alloc() = default; + template + constexpr static_alloc(const static_alloc&) noexcept {}; + [[nodiscard]] constexpr value_type* allocate(std::size_t n) { + return buffer.data(); + } + constexpr void deallocate(value_type* p, std::size_t n) {} + template + struct rebind { + using other = static_alloc; + }; + std::array buffer{}; +}; +template +bool operator==(const static_alloc&, const static_alloc&) { + return true; +} +template +bool operator!=(const static_alloc&, const static_alloc&) { + return false; +} + +namespace mementar { + + struct NodeCompare + { + public: + explicit NodeCompare(const NodeList& nodes) : nodes_{nodes} {} + bool operator()(HuffNode_t::Index l, HuffNode_t::Index r) + { + return nodes_[l].freq > nodes_[r].freq; + } + + private: + const NodeList& nodes_; + }; + + Huffman_::Huffman_() : BinaryManager("mhu") + { + + } + + void Huffman_::generateTree(const std::string& data, std::size_t jobs) + { + auto freqs = count_char(data, jobs); + auto root_node = generateTree(freqs); + nodes_[root_node].code.size_ = 0; + nodes_[root_node].code.value_ = 0; + generateCode(root_node); + } + + void Huffman_::getTreeCode(std::vector& out) + { + BitFileGenerator bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); + size_t valid_leaf = 0; + for(size_t i = 0; i < leaf_count; i++) + if(nodes_[i].freq != 0) + valid_leaf++; + + //coding tree + bit.writeType1((valid_leaf >> 0) & 0x000000ff); + bit.writeType1((valid_leaf >> 8) & 0x000000ff); + + for(size_t i = 0; i < leaf_count; i++) + { + if(nodes_[i].freq != 0) + { + bit.writeType1((char)i); + bit.writeType2(nodes_[i].code.size_); + bit.writeType3(nodes_[i].code.value_); + } + } + std::vector tmp; + bit.get(tmp); + out.insert(out.end(), tmp.begin(), tmp.end()); + } + + void Huffman_::getDataCode(const std::vector& data, std::vector& out) + { + BitFileGenerator bit(8); + bit.resize(data.size()); + + bit.writeType1((data.size() >> 0) & 0x000000ff); + bit.writeType1((data.size() >> 8) & 0x000000ff); + bit.writeType1((data.size() >> 16) & 0x000000ff); + bit.writeType1((data.size() >> 24) & 0x000000ff); + + for(const std::uint8_t& c : data) + bit.writeNReverse(nodes_[c].code.size_, nodes_[c].code.value_); + + std::vector tmp = bit.get(); + out.insert(out.end(), tmp.begin(), tmp.end()); + } + + void Huffman_::sum(const FrequencyMap& other, FrequencyMap& into) + { + std::transform(std::begin(other), std::end(other), std::begin(into), + std::begin(into), std::plus<>{}); + } + + FrequencyMap count_char_impl(const std::string& text) + { + FrequencyMap freq{}; // Zero-initialized array + for (const std::uint8_t& c : text) + freq[c]++; + return freq; + } + + FrequencyMap Huffman_::count_char(const std::string& text, std::size_t jobs) + { + if (jobs <= 1) + return count_char_impl(text); + + const auto thread_count = jobs - 1; + const auto bound = text.size() / thread_count; + + std::vector> counting_units(thread_count); + + size_t lower_bound = 0; + for (auto& unit : counting_units) + { + unit = std::async(std::launch::async, count_char_impl, + text.substr(lower_bound, bound)); + lower_bound += bound; + } + auto result = count_char_impl(text.substr(lower_bound)); + + for (auto& unit : counting_units) + sum(unit.get(), result); + + return result; + } + + HuffNode_t::Index Huffman_::generateTree(const FrequencyMap& freq) + { + using minheap = std::priority_queue< + HuffNode_t::Index, + std::vector>, + NodeCompare>; + + minheap heap{NodeCompare{nodes_}}; + + for (HuffNode_t::Index i = 0; i < freq.size(); ++i) + { + if (freq[i] == 0) + continue; // Do not set unused characters + nodes_[i].freq = freq[i]; + heap.push(i); + } + + HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves + + while (heap.size() != 1) + { + auto right = heap.top(); + heap.pop(); + auto left = heap.top(); + heap.pop(); + + nodes_[bind_node_index].freq = + nodes_[left].freq + nodes_[right].freq; + nodes_[bind_node_index].left = left; + nodes_[bind_node_index].right = right; + heap.push(bind_node_index); + + ++bind_node_index; + } + return heap.top(); + } + + void Huffman_::generateCode(HuffNode_t::Index index) + { + if(nodes_[index].right != HuffNode_t::invalid_index) + { + nodes_[nodes_[index].right].code.value_ = (nodes_[index].code.value_ << 1); + nodes_[nodes_[index].right].code.size_ = nodes_[index].code.size_ + 1; + generateCode(nodes_[index].right); + } + if(nodes_[index].left != HuffNode_t::invalid_index) + { + nodes_[nodes_[index].left].code.value_ = (nodes_[index].code.value_ << 1) | 0x01; + nodes_[nodes_[index].left].code.size_ = nodes_[index].code.size_ + 1; + generateCode(nodes_[index].left); + } + } +} diff --git a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp new file mode 100644 index 0000000..0c096c0 --- /dev/null +++ b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp @@ -0,0 +1,102 @@ +#include +#include +#include + +#include +#include /* srand, rand */ +#include /* time */ + +//#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/archiving_compressing/compressing/Huffman_.h" + +using namespace std::chrono; + + +/*float testHuffman(size_t nb, const std::string& input_file) +{ + std::ifstream t(input_file); + std::string in((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i++) + { + std::vector in_vect(in.begin(), in.end()); + + mementar::Huffman huff; + huff.analyse(in_vect); + huff.generateTree(); + std::vector out_vect; + huff.getTreeCode(out_vect); + huff.getDataCode(in_vect, out_vect); + + if(i == 0) + huff.displayCompressionRate(in.size(), out_vect.size()); + } + + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + + return time_span.count()*1000/nb; // return time span in ms +}*/ + +float testHuffman(size_t nb, const std::string& input_file) +{ + std::ifstream t(input_file); + std::string in((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i++) + { + std::vector in_vect(in.begin(), in.end()); + + mementar::Huffman_ huff; + high_resolution_clock::time_point t11 = high_resolution_clock::now(); + huff.generateTree(in); + high_resolution_clock::time_point t12 = high_resolution_clock::now(); + std::vector out_vect; + huff.getTreeCode(out_vect); + high_resolution_clock::time_point t13 = high_resolution_clock::now(); + huff.getDataCode(in_vect, out_vect); + high_resolution_clock::time_point t14 = high_resolution_clock::now(); + + duration time_span = duration_cast>(t12 - t11); + std::cout << "2-1 " << time_span.count()*1000 << std::endl; + time_span = duration_cast>(t13 - t12); + std::cout << "3-2 " << time_span.count()*1000 << std::endl; + time_span = duration_cast>(t14 - t13); + std::cout << "4-3 " << time_span.count()*1000 << std::endl; + + if(i == 0) + { + huff.displayCompressionRate(in.size(), out_vect.size()); + huff.saveToFile(out_vect, std::to_string(in.size())); + } + } + + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + + return time_span.count()*1000/nb; // return time span in ms +} + +int main (int argc, char* argv[]) +{ + const size_t nb = 1; + + float time_252 = testHuffman(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_252_1MB.txt"); + float time_10 = testHuffman(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_10_9MB.txt"); + float time_6 = testHuffman(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_6_5MB.txt"); + + float mean = (time_252 + time_10 + time_6) / 3.0; + + std::cout << "252 = " << time_252 << std::endl; + std::cout << "10 = " << time_10 << std::endl; + std::cout << "6 = " << time_6 << std::endl; + std::cout << "mean = " << mean << std::endl; + + return 0; +} From 1378a0062c83dd1d3d529c1bb93fb933a4fd50b7 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 31 Mar 2020 15:24:14 +0200 Subject: [PATCH 23/95] huffman decoding optimisation --- .../compressing/Huffman_.h | 4 + src/core/archiving_compressing/CMakeLists.txt | 3 + .../binaryManagement/BitFileGetter.cpp | 2 +- .../compressing/Huffman.cpp | 3 +- .../compressing/Huffman_.cpp | 98 ++++++++++++++++++- .../tests/perfs/huffman_in.cpp | 11 --- 6 files changed, 107 insertions(+), 14 deletions(-) diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_.h b/include/mementar/core/archiving_compressing/compressing/Huffman_.h index 8cd103b..1bed524 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman_.h +++ b/include/mementar/core/archiving_compressing/compressing/Huffman_.h @@ -48,8 +48,12 @@ class Huffman_ : public BinaryManager void getTreeCode(std::vector& out); void getDataCode(const std::vector& data, std::vector& out); + size_t setTree(std::vector& in); + std::string getFile(std::vector& data); + private: NodeList nodes_{}; + HuffNode_t::Index root_node_{HuffNode_t::invalid_index}; void sum(const FrequencyMap& other, FrequencyMap& into); FrequencyMap count_char(const std::string& text, std::size_t jobs = 1); diff --git a/src/core/archiving_compressing/CMakeLists.txt b/src/core/archiving_compressing/CMakeLists.txt index 5d5e3da..f6c78b9 100644 --- a/src/core/archiving_compressing/CMakeLists.txt +++ b/src/core/archiving_compressing/CMakeLists.txt @@ -32,3 +32,6 @@ target_link_libraries(archive mementar_compression_lib) add_executable(huffman_in tests/perfs/huffman_in.cpp) target_link_libraries(huffman_in mementar_compression_lib pthread) + +add_executable(huffman_out tests/perfs/huffman_out.cpp) +target_link_libraries(huffman_out mementar_compression_lib pthread) diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp b/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp index 1816d8e..9158e17 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp +++ b/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp @@ -180,7 +180,7 @@ bool BitFileGetter::getBit() { bool res = (data_[major_index_] >> minor_index_) & 0x01; - if(minor_index_ >= 7) + if(minor_index_ > 6) { minor_index_ = 0; major_index_++; diff --git a/src/core/archiving_compressing/compressing/Huffman.cpp b/src/core/archiving_compressing/compressing/Huffman.cpp index adafed8..58892ae 100644 --- a/src/core/archiving_compressing/compressing/Huffman.cpp +++ b/src/core/archiving_compressing/compressing/Huffman.cpp @@ -186,6 +186,7 @@ void Huffman::getFile(std::vector& data, std::string& out) bit.set(data); auto out_file_size = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + out.reserve(out_file_size); while(out.size() < out_file_size) { HuffNode_t* node = heap_[0]; @@ -196,7 +197,7 @@ void Huffman::getFile(std::vector& data, std::string& out) else node = node->right_; } - out.push_back(node->data_); + out += node->data_; } } diff --git a/src/core/archiving_compressing/compressing/Huffman_.cpp b/src/core/archiving_compressing/compressing/Huffman_.cpp index d61e929..b16e477 100644 --- a/src/core/archiving_compressing/compressing/Huffman_.cpp +++ b/src/core/archiving_compressing/compressing/Huffman_.cpp @@ -7,6 +7,7 @@ #include #include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" #define TREE_CHAR_SIZE 8 #define TREE_VALUE_SIZE 6 @@ -52,6 +53,26 @@ namespace mementar { const NodeList& nodes_; }; + struct NodeValueCompare + { + public: + explicit NodeValueCompare(const NodeList& nodes) : nodes_{nodes} {} + bool operator()(HuffNode_t::Index l, HuffNode_t::Index r) + { + if(nodes_[l].code.size_ < nodes_[r].code.size_) + return true; + else if(nodes_[l].code.size_ > nodes_[r].code.size_) + return false; + else if(nodes_[l].code.value_ < nodes_[r].code.value_) + return false; + else + return true; + } + + private: + const NodeList& nodes_; + }; + Huffman_::Huffman_() : BinaryManager("mhu") { @@ -104,11 +125,86 @@ namespace mementar { for(const std::uint8_t& c : data) bit.writeNReverse(nodes_[c].code.size_, nodes_[c].code.value_); - + std::vector tmp = bit.get(); out.insert(out.end(), tmp.begin(), tmp.end()); } + size_t Huffman_::setTree(std::vector& in) + { + BitFileGetter bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); + bit.set(in); + + auto nb_leaf = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + + using minheap = std::priority_queue< + HuffNode_t::Index, + std::vector>, + NodeValueCompare>; + + minheap heap{NodeValueCompare{nodes_}}; + + for(size_t i = 0; i < nb_leaf; i++) + { + HuffNode_t::Index data = bit.getType1(); + nodes_[data].code.size_ = bit.getType2(); + nodes_[data].code.value_ = bit.getType3(); + heap.push((HuffNode_t::Index)data); + } + + HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves + + while(heap.size() != 1) + { + auto right = heap.top(); + heap.pop(); + auto left = heap.top(); + heap.pop(); + + nodes_[bind_node_index].right = right; + nodes_[bind_node_index].left = left; + nodes_[bind_node_index].code.size_ = nodes_[right].code.size_ - 1; + nodes_[bind_node_index].code.value_ = (nodes_[right].code.value_ >> 1) & 0xefffffff; + + heap.push(bind_node_index); + ++bind_node_index; + } + + root_node_ = bind_node_index - 1; + + size_t tree_bit_size = (2*8 + nb_leaf*(TREE_CHAR_SIZE + TREE_VALUE_SIZE + TREE_VALUE_SIZE_SIZE)); + + return tree_bit_size / 8 + 1; + } + + std::string Huffman_::getFile(std::vector& data) + { + std::string out = ""; + BitFileGetter bit(8); + bit.set(data); + + auto out_file_size = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + out.reserve(out_file_size); + + auto nodes = nodes_.data(); + auto node = &nodes_[root_node_]; + while(out.size() < out_file_size) + { + node = nodes + root_node_; + while(node->right != HuffNode_t::invalid_index) + { + if(bit.getBit()) + node = nodes + node->left; + else + node = nodes + node->right; + //node = nodes + (bit.getBit() ? node->left : node->right); + } + out += (char)(node - nodes); + } + + return out; + } + void Huffman_::sum(const FrequencyMap& other, FrequencyMap& into) { std::transform(std::begin(other), std::end(other), std::begin(into), diff --git a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp index 0c096c0..b90cd20 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp +++ b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp @@ -54,21 +54,10 @@ float testHuffman(size_t nb, const std::string& input_file) std::vector in_vect(in.begin(), in.end()); mementar::Huffman_ huff; - high_resolution_clock::time_point t11 = high_resolution_clock::now(); huff.generateTree(in); - high_resolution_clock::time_point t12 = high_resolution_clock::now(); std::vector out_vect; huff.getTreeCode(out_vect); - high_resolution_clock::time_point t13 = high_resolution_clock::now(); huff.getDataCode(in_vect, out_vect); - high_resolution_clock::time_point t14 = high_resolution_clock::now(); - - duration time_span = duration_cast>(t12 - t11); - std::cout << "2-1 " << time_span.count()*1000 << std::endl; - time_span = duration_cast>(t13 - t12); - std::cout << "3-2 " << time_span.count()*1000 << std::endl; - time_span = duration_cast>(t14 - t13); - std::cout << "4-3 " << time_span.count()*1000 << std::endl; if(i == 0) { From 59c938d17ccb321d4d20accc8637460f0a2ee722 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 31 Mar 2020 17:43:41 +0200 Subject: [PATCH 24/95] huffman decoding optimisation by removing bitGetter --- .../binaryManagement/BitFileGetter.h | 3 +- .../compressing/Huffman_.h | 4 +- .../binaryManagement/BitFileGetter.cpp | 34 +++---- .../compressing/Huffman_.cpp | 34 ++++--- .../tests/perfs/huffman_out.cpp | 91 +++++++++++++++++++ 5 files changed, 135 insertions(+), 31 deletions(-) create mode 100644 src/core/archiving_compressing/tests/perfs/huffman_out.cpp diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h b/include/mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h index 2540239..8e1376f 100644 --- a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h +++ b/include/mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h @@ -37,10 +37,11 @@ class BitFileGetter bool end(size_t offset = 0); - void set(std::vector& data) { data_ = data; } + void set(const std::vector& data) { data_ = data; current_data_ = data_[0]; } private: std::vector data_; + char current_data_; size_t major_index_; uint8_t minor_index_; diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_.h b/include/mementar/core/archiving_compressing/compressing/Huffman_.h index 1bed524..2a1f56c 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman_.h +++ b/include/mementar/core/archiving_compressing/compressing/Huffman_.h @@ -48,8 +48,8 @@ class Huffman_ : public BinaryManager void getTreeCode(std::vector& out); void getDataCode(const std::vector& data, std::vector& out); - size_t setTree(std::vector& in); - std::string getFile(std::vector& data); + size_t setTree(const std::vector& in); + std::string getFile(const std::vector& data); private: NodeList nodes_{}; diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp b/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp index 9158e17..421e652 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp +++ b/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp @@ -22,7 +22,7 @@ uint32_t BitFileGetter::getType1() int8_t to_get = type_1_size_; while(true) { - uint32_t working_data = (data_[major_index_] & 0x000000ff) >> minor_index_; + uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; @@ -30,7 +30,7 @@ uint32_t BitFileGetter::getType1() to_get -= getted; if(to_get > 0) { - major_index_++; + current_data_ = data_[++major_index_]; minor_index_ = 0; } else @@ -39,7 +39,7 @@ uint32_t BitFileGetter::getType1() if(minor_index_ >= 8) { minor_index_ = 0; - major_index_++; + current_data_ = data_[++major_index_]; } break; } @@ -54,7 +54,7 @@ uint32_t BitFileGetter::getType2() int8_t to_get = type_2_size_; while(true) { - uint32_t working_data = (data_[major_index_] & 0x000000ff) >> minor_index_; + uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; res |= ((working_data & ~((0xffffffff) << to_get)) << (type_2_size_ - to_get)); uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; @@ -62,7 +62,7 @@ uint32_t BitFileGetter::getType2() to_get -= getted; if(to_get > 0) { - major_index_++; + current_data_ = data_[++major_index_]; minor_index_ = 0; } else @@ -71,7 +71,7 @@ uint32_t BitFileGetter::getType2() if(minor_index_ >= 8) { minor_index_ = 0; - major_index_++; + current_data_ = data_[++major_index_]; } break; } @@ -86,7 +86,7 @@ uint32_t BitFileGetter::getType3() int8_t to_get = type_3_size_; while(true) { - uint32_t working_data = (data_[major_index_] & 0x000000ff) >> minor_index_; + uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; res |= ((working_data & ~((0xffffffff) << to_get)) << (type_3_size_ - to_get)); uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; @@ -94,7 +94,7 @@ uint32_t BitFileGetter::getType3() to_get -= getted; if(to_get > 0) { - major_index_++; + current_data_ = data_[++major_index_]; minor_index_ = 0; } else @@ -103,7 +103,7 @@ uint32_t BitFileGetter::getType3() if(minor_index_ >= 8) { minor_index_ = 0; - major_index_++; + current_data_ = data_[++major_index_]; } break; } @@ -118,7 +118,7 @@ uint32_t BitFileGetter::getType4() int8_t to_get = type_4_size_; while(true) { - uint32_t working_data = (data_[major_index_] & 0x000000ff) >> minor_index_; + uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; res |= ((working_data & ~((0xffffffff) << to_get)) << (type_4_size_ - to_get)); uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; @@ -126,7 +126,7 @@ uint32_t BitFileGetter::getType4() to_get -= getted; if(to_get > 0) { - major_index_++; + current_data_ = data_[++major_index_]; minor_index_ = 0; } else @@ -135,7 +135,7 @@ uint32_t BitFileGetter::getType4() if(minor_index_ >= 8) { minor_index_ = 0; - major_index_++; + current_data_ = data_[++major_index_]; } break; } @@ -150,7 +150,7 @@ char BitFileGetter::getChar() int8_t to_get = 7; while(true) { - uint32_t working_data = (data_[major_index_] & 0x000000ff) >> minor_index_; + uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; res |= ((working_data & ~((0xffffffff) << to_get)) << (7 - to_get)); uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; @@ -158,7 +158,7 @@ char BitFileGetter::getChar() to_get -= getted; if(to_get > 0) { - major_index_++; + current_data_ = data_[++major_index_]; minor_index_ = 0; } else @@ -167,7 +167,7 @@ char BitFileGetter::getChar() if(minor_index_ >= 8) { minor_index_ = 0; - major_index_++; + current_data_ = data_[++major_index_]; } break; } @@ -178,12 +178,12 @@ char BitFileGetter::getChar() bool BitFileGetter::getBit() { - bool res = (data_[major_index_] >> minor_index_) & 0x01; + bool res = (current_data_ >> minor_index_) & 0x01; if(minor_index_ > 6) { minor_index_ = 0; - major_index_++; + current_data_ = data_[++major_index_]; } else minor_index_ ++; diff --git a/src/core/archiving_compressing/compressing/Huffman_.cpp b/src/core/archiving_compressing/compressing/Huffman_.cpp index b16e477..2369edf 100644 --- a/src/core/archiving_compressing/compressing/Huffman_.cpp +++ b/src/core/archiving_compressing/compressing/Huffman_.cpp @@ -130,7 +130,7 @@ namespace mementar { out.insert(out.end(), tmp.begin(), tmp.end()); } - size_t Huffman_::setTree(std::vector& in) + size_t Huffman_::setTree(const std::vector& in) { BitFileGetter bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); bit.set(in); @@ -149,7 +149,7 @@ namespace mementar { HuffNode_t::Index data = bit.getType1(); nodes_[data].code.size_ = bit.getType2(); nodes_[data].code.value_ = bit.getType3(); - heap.push((HuffNode_t::Index)data); + heap.push(data); } HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves @@ -177,29 +177,41 @@ namespace mementar { return tree_bit_size / 8 + 1; } - std::string Huffman_::getFile(std::vector& data) + std::string Huffman_::getFile(const std::vector& data) { std::string out = ""; - BitFileGetter bit(8); - bit.set(data); - auto out_file_size = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + const auto out_file_size = toInteger({(uint8_t)data[0], (uint8_t)data[1], (uint8_t)data[2], (uint8_t)data[3]}); out.reserve(out_file_size); auto nodes = nodes_.data(); auto node = &nodes_[root_node_]; - while(out.size() < out_file_size) + auto root_node = nodes + root_node_; + + uint8_t mask = 0x00; + uint8_t bit_data = 0x00; + + uint32_t index = 3; + + for(;;) { - node = nodes + root_node_; - while(node->right != HuffNode_t::invalid_index) + node = root_node; + while(node->right - HuffNode_t::invalid_index) { - if(bit.getBit()) + if((mask<<=1) == 0x00) + { + bit_data = data[++index]; + mask = 0x01; + } + + if(bit_data & mask) node = nodes + node->left; else node = nodes + node->right; - //node = nodes + (bit.getBit() ? node->left : node->right); } out += (char)(node - nodes); + if(out.size() == out_file_size) + break; } return out; diff --git a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp b/src/core/archiving_compressing/tests/perfs/huffman_out.cpp new file mode 100644 index 0000000..bb23ab4 --- /dev/null +++ b/src/core/archiving_compressing/tests/perfs/huffman_out.cpp @@ -0,0 +1,91 @@ +#include +#include +#include + +#include +#include /* srand, rand */ +#include /* time */ + +#define NEW_V + +#ifdef NEW_V +#include "mementar/core/archiving_compressing/compressing/Huffman_.h" +#else +#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#endif + + +using namespace std::chrono; + + +float testHuffman(size_t nb, const std::string& input_file) +{ + std::ifstream t(input_file); + std::string in((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i++) + { + #ifdef NEW_V + mementar::Huffman_ huff; + #else + mementar::Huffman huff; + #endif + std::vector data; + if(huff.readBinaryFile(data, input_file)) + { + high_resolution_clock::time_point t11 = high_resolution_clock::now(); + #ifdef NEW_V + size_t tree_size = huff.setTree(data); + high_resolution_clock::time_point t12 = high_resolution_clock::now(); + data = std::vector(data.begin() + tree_size, data.end()); + std::string out = huff.getFile(data); + #else + std::string out; + size_t tree_size = huff.setTree(data); + high_resolution_clock::time_point t12 = high_resolution_clock::now(); + data = std::vector(data.begin() + tree_size, data.end()); + huff.getFile(data, out); + #endif + high_resolution_clock::time_point t13 = high_resolution_clock::now(); + + duration time_span = duration_cast>(t12 - t11); + std::cout << "(2 - 1) = " << time_span.count()*1000 << std::endl; + time_span = duration_cast>(t13 - t12); + std::cout << "(3 - 2) = " << time_span.count()*1000 << std::endl; + + if(i == 0) + { + std::ofstream myfile; + myfile.open ("../tests_files/out/" + std::to_string(data.size()) + ".txt"); + myfile << out; + myfile.close(); + } + } + } + + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + + return time_span.count()*1000/nb; // return time span in ms +} + +int main (int argc, char* argv[]) +{ + const size_t nb = 10; + + float time_252 = testHuffman(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_252_1MB.mhu"); + float time_10 = testHuffman(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_10_9MB.mhu"); + float time_6 = testHuffman(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_6_5MB.mhu"); + + float mean = (time_252 + time_10 + time_6) / 3.0; + + std::cout << "252 = " << time_252 << std::endl; + std::cout << "10 = " << time_10 << std::endl; + std::cout << "6 = " << time_6 << std::endl; + std::cout << "mean = " << mean << std::endl; + + return 0; +} From 63fe2e5fe2b4a5fe544b32b36cf17546787d0fee Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 1 Apr 2020 14:40:14 +0200 Subject: [PATCH 25/95] [UPDATE] optimise huffman decoding using h_min --- .../compressing/Huffman_.h | 4 +- .../compressing/Huffman_.cpp | 39 ++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_.h b/include/mementar/core/archiving_compressing/compressing/Huffman_.h index 2a1f56c..bffee40 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman_.h +++ b/include/mementar/core/archiving_compressing/compressing/Huffman_.h @@ -39,6 +39,7 @@ static constexpr HuffNode_t::Index node_count = leaf_count * 2; using FrequencyMap = std::array; using NodeList = std::array; +using TreeList = std::array; class Huffman_ : public BinaryManager { @@ -53,7 +54,8 @@ class Huffman_ : public BinaryManager private: NodeList nodes_{}; - HuffNode_t::Index root_node_{HuffNode_t::invalid_index}; + TreeList subtrees_{}; + size_t h_min_; void sum(const FrequencyMap& other, FrequencyMap& into); FrequencyMap count_char(const std::string& text, std::size_t jobs = 1); diff --git a/src/core/archiving_compressing/compressing/Huffman_.cpp b/src/core/archiving_compressing/compressing/Huffman_.cpp index 2369edf..0a69b19 100644 --- a/src/core/archiving_compressing/compressing/Huffman_.cpp +++ b/src/core/archiving_compressing/compressing/Huffman_.cpp @@ -143,6 +143,7 @@ namespace mementar { NodeValueCompare>; minheap heap{NodeValueCompare{nodes_}}; + h_min_ = leaf_count; for(size_t i = 0; i < nb_leaf; i++) { @@ -150,6 +151,8 @@ namespace mementar { nodes_[data].code.size_ = bit.getType2(); nodes_[data].code.value_ = bit.getType3(); heap.push(data); + if(nodes_[data].code.size_ < h_min_) + h_min_ = nodes_[data].code.size_; } HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves @@ -165,12 +168,18 @@ namespace mementar { nodes_[bind_node_index].left = left; nodes_[bind_node_index].code.size_ = nodes_[right].code.size_ - 1; nodes_[bind_node_index].code.value_ = (nodes_[right].code.value_ >> 1) & 0xefffffff; + if(nodes_[bind_node_index].code.size_ == h_min_) + subtrees_[nodes_[bind_node_index].code.value_] = bind_node_index; heap.push(bind_node_index); ++bind_node_index; } - root_node_ = bind_node_index - 1; + for(size_t i = 0; i < leaf_count; i++) + { + if(nodes_[i].code.size_ == h_min_) + subtrees_[nodes_[i].code.value_] = i; + } size_t tree_bit_size = (2*8 + nb_leaf*(TREE_CHAR_SIZE + TREE_VALUE_SIZE + TREE_VALUE_SIZE_SIZE)); @@ -185,26 +194,38 @@ namespace mementar { out.reserve(out_file_size); auto nodes = nodes_.data(); - auto node = &nodes_[root_node_]; - auto root_node = nodes + root_node_; + auto node = &nodes_[0]; - uint8_t mask = 0x00; + uint8_t mask_index = 8; uint8_t bit_data = 0x00; + uint8_t h_min_data = 0x00; uint32_t index = 3; for(;;) { - node = root_node; - while(node->right - HuffNode_t::invalid_index) + h_min_data = 0x00; + for(size_t i = 0; i < h_min_; i++) { - if((mask<<=1) == 0x00) + bit_data>>=1; + if((++mask_index) >= 8) { bit_data = data[++index]; - mask = 0x01; + mask_index = 0; } + h_min_data = (h_min_data << 1) | (bit_data & 0x01); + } + node = nodes + subtrees_[h_min_data]; - if(bit_data & mask) + while(node->right - HuffNode_t::invalid_index) + { + bit_data>>=1; + if((++mask_index) >= 8) + { + bit_data = data[++index]; + mask_index = 0; + } + if(bit_data & 0x01) node = nodes + node->left; else node = nodes + node->right; From a897492cdc6933595a6d1bb9297253ffaa990fe8 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 1 Apr 2020 15:54:54 +0200 Subject: [PATCH 26/95] [REFACT] replace old huffman version --- .../archiving_compressing/archiving/Archive.h | 2 +- .../binaryManagement/BinaryManager.h | 8 + .../compressing/Huffman.h | 81 ++-- .../compressing/Huffman_.h | 68 --- .../compressing/Huffman_old.h | 73 +++ src/core/archiving_compressing/CMakeLists.txt | 7 +- .../archiving/Archive.cpp | 17 +- .../compressing/Huffman.cpp | 430 ++++++++++++------ .../compressing/Huffman_.cpp | 332 -------------- .../compressing/Huffman_old.cpp | 204 +++++++++ .../archiving_compressing/tests/compress.cpp | 8 +- .../tests/perfs/huffman_in.cpp | 11 +- .../tests/perfs/huffman_out.cpp | 8 +- .../tests/uncompress.cpp | 2 +- 14 files changed, 630 insertions(+), 621 deletions(-) delete mode 100644 include/mementar/core/archiving_compressing/compressing/Huffman_.h create mode 100644 include/mementar/core/archiving_compressing/compressing/Huffman_old.h delete mode 100644 src/core/archiving_compressing/compressing/Huffman_.cpp create mode 100644 src/core/archiving_compressing/compressing/Huffman_old.cpp diff --git a/include/mementar/core/archiving_compressing/archiving/Archive.h b/include/mementar/core/archiving_compressing/archiving/Archive.h index 54783fe..2f05d4a 100644 --- a/include/mementar/core/archiving_compressing/archiving/Archive.h +++ b/include/mementar/core/archiving_compressing/archiving/Archive.h @@ -20,7 +20,7 @@ class Archive : public BinaryManager } void load(std::vector& out); - void load(std::vector& out, std::vector >& raw_datas); + void load(std::vector& out, std::vector& raw_datas); Header getHeader(std::vector& data); Header getHeader() { return getHeader(data_); } diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h b/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h index fafe0c2..697c168 100644 --- a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h +++ b/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h @@ -44,6 +44,14 @@ class BinaryManager else return false; } + + std::string readBinaryFile(const std::string& file_name) + { + std::ifstream infile(file_name, std::ios::binary | std::ios::ate); + std::string res((std::istreambuf_iterator(infile)), + std::istreambuf_iterator()); + return res; + } private: std::string extension_; }; diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman.h b/include/mementar/core/archiving_compressing/compressing/Huffman.h index 4ca0796..ef42cd0 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman.h +++ b/include/mementar/core/archiving_compressing/compressing/Huffman.h @@ -1,10 +1,9 @@ #ifndef MEMENTAR_HUFFMAN_H #define MEMENTAR_HUFFMAN_H -#include +#include +#include #include -#include -#include #include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" @@ -17,55 +16,53 @@ struct HuffCode_t uint8_t size_; }; -struct HuffNode_t -{ - size_t freq_; - char data_; - HuffCode_t code_; - HuffNode_t* left_; - HuffNode_t* right_; - - HuffNode_t() - { - freq_ = 1; - data_ = ' '; - left_ = right_ = nullptr; - } - HuffNode_t(char data) - { - freq_ = 1; - data_ = data; - left_ = right_ = nullptr; - } - - ~HuffNode_t() - { - if(left_ != nullptr) - delete left_; - if(right_ != nullptr) - delete right_; - } +struct HuffNode_t { + using Index = std::uint16_t; + using Frequency = std::uint32_t; + + static constexpr Index invalid_index = std::numeric_limits::max(); + + Frequency freq{}; + Index left{invalid_index}; + Index right{invalid_index}; + HuffCode_t code; }; +// Number of values representable with a byte +static constexpr HuffNode_t::Index values_in_byte = 1 << (sizeof(std::uint8_t) * 8); + +// Maximum number of leaf nodes (character) in an Huffman tree +static constexpr HuffNode_t::Index leaf_count = values_in_byte; + +// Maximum number of nodes (leaf + bind) in an Huffman tree +static constexpr HuffNode_t::Index node_count = leaf_count * 2; + +using FrequencyMap = std::array; +using NodeList = std::array; +using TreeList = std::array; + class Huffman : public BinaryManager { public: - void analyse(std::vector& data); - void generateTree(); + Huffman(); + void analyse(const std::string& data, std::size_t jobs = 1); + void generateCode(); void getTreeCode(std::vector& out); - void getDataCode(std::vector& data, std::vector& out); + void getDataCode(const std::string& in_data, std::vector& out); - size_t setTree(std::vector& in); - void getFile(std::vector& data, std::string& out); - - Huffman(); - ~Huffman(); + size_t setTree(const std::vector& in); + std::string getFile(const std::vector& data); private: - std::vector heap_; - std::map leaf_map_; + FrequencyMap frequencies_{}; + NodeList nodes_{}; + TreeList subtrees_{}; + size_t h_min_; - void generateCode(HuffNode_t* node); + void sum(const FrequencyMap& other, FrequencyMap& into); + void count_char(const std::string& text, std::size_t jobs = 1); + HuffNode_t::Index generateTree(); + void generateCode(HuffNode_t::Index index); }; } // namespace mementar diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_.h b/include/mementar/core/archiving_compressing/compressing/Huffman_.h deleted file mode 100644 index bffee40..0000000 --- a/include/mementar/core/archiving_compressing/compressing/Huffman_.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef MEMENTAR_HUFFMAN__H -#define MEMENTAR_HUFFMAN__H - -#include -#include -#include - -#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" - -namespace mementar -{ - -struct HuffCode_t -{ - uint32_t value_; - uint8_t size_; -}; - -struct HuffNode_t { - using Index = std::uint16_t; - using Frequency = std::uint32_t; - - static constexpr Index invalid_index = std::numeric_limits::max(); - - Frequency freq{}; - Index left{invalid_index}; - Index right{invalid_index}; - HuffCode_t code; -}; - -// Number of values representable with a byte -static constexpr HuffNode_t::Index values_in_byte = 1 << (sizeof(std::uint8_t) * 8); - -// Maximum number of leaf nodes (character) in an Huffman tree -static constexpr HuffNode_t::Index leaf_count = values_in_byte; - -// Maximum number of nodes (leaf + bind) in an Huffman tree -static constexpr HuffNode_t::Index node_count = leaf_count * 2; - -using FrequencyMap = std::array; -using NodeList = std::array; -using TreeList = std::array; - -class Huffman_ : public BinaryManager -{ -public: - Huffman_(); - void generateTree(const std::string& data, std::size_t jobs = 1); - void getTreeCode(std::vector& out); - void getDataCode(const std::vector& data, std::vector& out); - - size_t setTree(const std::vector& in); - std::string getFile(const std::vector& data); - -private: - NodeList nodes_{}; - TreeList subtrees_{}; - size_t h_min_; - - void sum(const FrequencyMap& other, FrequencyMap& into); - FrequencyMap count_char(const std::string& text, std::size_t jobs = 1); - HuffNode_t::Index generateTree(const FrequencyMap& freq); - void generateCode(HuffNode_t::Index index); -}; - -} // namespace mementar - -#endif // MEMENTAR_HUFFMAN__H diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_old.h b/include/mementar/core/archiving_compressing/compressing/Huffman_old.h new file mode 100644 index 0000000..1a156f1 --- /dev/null +++ b/include/mementar/core/archiving_compressing/compressing/Huffman_old.h @@ -0,0 +1,73 @@ +#ifndef MEMENTAR_HUFFMAN__H +#define MEMENTAR_HUFFMAN__H + +#include +#include +#include +#include + +#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" + +namespace mementar +{ + +struct HuffCode_t +{ + uint32_t value_; + uint8_t size_; +}; + +struct HuffNode_t +{ + size_t freq_; + char data_; + HuffCode_t code_; + HuffNode_t* left_; + HuffNode_t* right_; + + HuffNode_t() + { + freq_ = 1; + data_ = ' '; + left_ = right_ = nullptr; + } + HuffNode_t(char data) + { + freq_ = 1; + data_ = data; + left_ = right_ = nullptr; + } + + ~HuffNode_t() + { + if(left_ != nullptr) + delete left_; + if(right_ != nullptr) + delete right_; + } +}; + +class Huffman_ : public BinaryManager +{ +public: + void analyse(std::vector& data); + void generateTree(); + void getTreeCode(std::vector& out); + void getDataCode(std::vector& data, std::vector& out); + + size_t setTree(std::vector& in); + void getFile(std::vector& data, std::string& out); + + Huffman_(); + ~Huffman_(); + +private: + std::vector heap_; + std::map leaf_map_; + + void generateCode(HuffNode_t* node); +}; + +} // namespace mementar + +#endif // MEMENTAR_HUFFMAN__H diff --git a/src/core/archiving_compressing/CMakeLists.txt b/src/core/archiving_compressing/CMakeLists.txt index f6c78b9..9581546 100644 --- a/src/core/archiving_compressing/CMakeLists.txt +++ b/src/core/archiving_compressing/CMakeLists.txt @@ -13,10 +13,11 @@ add_library(mementar_compression_lib compressing/LzCompress.cpp compressing/LzUncompress.cpp compressing/Huffman.cpp - compressing/Huffman_.cpp + compressing/Huffman_old.cpp archiving/Header.cpp archiving/Archive.cpp ) +target_link_libraries(mementar_compression_lib pthread) add_executable(compress tests/compress.cpp) target_link_libraries(compress mementar_compression_lib) @@ -31,7 +32,7 @@ target_link_libraries(archive mementar_compression_lib) ### add_executable(huffman_in tests/perfs/huffman_in.cpp) -target_link_libraries(huffman_in mementar_compression_lib pthread) +target_link_libraries(huffman_in mementar_compression_lib) add_executable(huffman_out tests/perfs/huffman_out.cpp) -target_link_libraries(huffman_out mementar_compression_lib pthread) +target_link_libraries(huffman_out mementar_compression_lib) diff --git a/src/core/archiving_compressing/archiving/Archive.cpp b/src/core/archiving_compressing/archiving/Archive.cpp index 8c89712..da413a1 100644 --- a/src/core/archiving_compressing/archiving/Archive.cpp +++ b/src/core/archiving_compressing/archiving/Archive.cpp @@ -49,17 +49,16 @@ void Archive::load(std::vector& out) header_.description_file_.size_ = out_vect.size(); out_vect = std::vector(); - std::vector > input_files; + std::vector input_files; Huffman huff; for(const auto& file : header_.input_files_) { - std::vector in_vect; - huff.readBinaryFile(in_vect, file.path_); - input_files.push_back(in_vect); - huff.analyse(in_vect); + auto str = huff.readBinaryFile(file.path_); + input_files.push_back(str); + huff.analyse(str); } - huff.generateTree(); + huff.generateCode(); huff.getTreeCode(out_vect); out.insert(out.end(), out_vect.begin(), out_vect.end()); offset += out_vect.size(); @@ -79,7 +78,7 @@ void Archive::load(std::vector& out) out.insert(out.begin(), out_vect.begin(), out_vect.end()); } -void Archive::load(std::vector& out, std::vector >& raw_datas) +void Archive::load(std::vector& out, std::vector& raw_datas) { if(raw_datas.size() != header_.input_files_.size()) { @@ -101,7 +100,7 @@ void Archive::load(std::vector& out, std::vector >& raw_ for(auto& raw_data : raw_datas) huff.analyse(raw_data); - huff.generateTree(); + huff.generateCode(); huff.getTreeCode(out_vect); out.insert(out.end(), out_vect.begin(), out_vect.end()); offset += out_vect.size(); @@ -144,7 +143,7 @@ std::string Archive::extractFile(size_t index, Header& head, std::vector& std::vector tree_data(data.begin() + head.description_file_.offset_ + head.description_file_.size_, data.end()); huff.setTree(tree_data); std::vector tmp_data(data.begin() + head.input_files_[index].offset_, data.begin() + head.input_files_[index].offset_ + head.input_files_[index].size_); - huff.getFile(tmp_data, out); + out = huff.getFile(tmp_data); return out; } diff --git a/src/core/archiving_compressing/compressing/Huffman.cpp b/src/core/archiving_compressing/compressing/Huffman.cpp index 58892ae..c2cdeb8 100644 --- a/src/core/archiving_compressing/compressing/Huffman.cpp +++ b/src/core/archiving_compressing/compressing/Huffman.cpp @@ -1,204 +1,334 @@ #include "mementar/core/archiving_compressing/compressing/Huffman.h" -#include #include +#include +#include +#include +#include #include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" #include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" -namespace mementar -{ - #define TREE_CHAR_SIZE 8 #define TREE_VALUE_SIZE 6 #define TREE_VALUE_SIZE_SIZE 31 //do not go over 31 -void print_tree(HuffNode_t* node) -{ - for(size_t i = 0; i < node->code_.size_; i++) - std::cout << " "; - std::cout << std::hex << node->code_.value_ << std::endl; - - if(node->left_ != nullptr) - print_tree(node->left_); - if(node->right_ != nullptr) - print_tree(node->right_); -} - -bool comparePtrNode(HuffNode_t* a, HuffNode_t* b) -{ - return (a->freq_ < b->freq_); -} - -bool comparePtrNodeByCode(HuffNode_t* a, HuffNode_t* b) -{ - if(a->code_.size_ < b->code_.size_) - return false; - else if(a->code_.size_ > b->code_.size_) - return true; - else if(a->code_.value_ < b->code_.value_) +template +struct static_alloc { + using value_type = T; + static_alloc() = default; + template + constexpr static_alloc(const static_alloc&) noexcept {}; + [[nodiscard]] constexpr value_type* allocate(std::size_t n) { + return buffer.data(); + } + constexpr void deallocate(value_type* p, std::size_t n) {} + template + struct rebind { + using other = static_alloc; + }; + std::array buffer{}; +}; +template +bool operator==(const static_alloc&, const static_alloc&) { return true; - else +} +template +bool operator!=(const static_alloc&, const static_alloc&) { return false; } -Huffman::Huffman() : BinaryManager("mhu") -{ +namespace mementar { -} + struct NodeCompare + { + public: + explicit NodeCompare(const NodeList& nodes) : nodes_{nodes} {} + bool operator()(HuffNode_t::Index l, HuffNode_t::Index r) + { + return nodes_[l].freq > nodes_[r].freq; + } -Huffman::~Huffman() -{ - for(auto it : heap_) - delete it; -} + private: + const NodeList& nodes_; + }; -void Huffman::analyse(std::vector& data) -{ - for(const auto& c : data) + struct NodeValueCompare { - auto it = leaf_map_.find(c); - if(it == leaf_map_.end()) + public: + explicit NodeValueCompare(const NodeList& nodes) : nodes_{nodes} {} + bool operator()(HuffNode_t::Index l, HuffNode_t::Index r) { - HuffNode_t* leaf = new HuffNode_t(c); - heap_.push_back(leaf); - leaf_map_[c] = leaf; + if(nodes_[l].code.size_ < nodes_[r].code.size_) + return true; + else if(nodes_[l].code.size_ > nodes_[r].code.size_) + return false; + else if(nodes_[l].code.value_ < nodes_[r].code.value_) + return false; + else + return true; } - else - it->second->freq_++; - } -} -void Huffman::generateTree() -{ - while(heap_.size() > 1) + private: + const NodeList& nodes_; + }; + + Huffman::Huffman() : BinaryManager("mhu") { - std::sort(heap_.begin(), heap_.end(), comparePtrNode); - - HuffNode_t* tmp = new HuffNode_t(); - tmp->right_ = heap_[0]; - tmp->left_ = heap_[1]; - tmp->freq_ = tmp->right_->freq_ + tmp->left_->freq_; - heap_.erase(heap_.begin()); - heap_.erase(heap_.begin()); - heap_.push_back(tmp); - } - heap_[0]->code_.value_ = 0; - heap_[0]->code_.size_ = 0; - generateCode(heap_[0]); -} + } -void Huffman::generateCode(HuffNode_t* node) -{ - if(node->right_ != nullptr) + void Huffman::analyse(const std::string& data, std::size_t jobs) { - node->right_->code_.value_ = (node->code_.value_ << 1); - node->right_->code_.size_ = node->code_.size_ + 1; - generateCode(node->right_); + count_char(data, jobs); } - if(node->left_ != nullptr) + + void Huffman::generateCode() { - node->left_->code_.value_ = (node->code_.value_ << 1) | 0x01; - node->left_->code_.size_ = node->code_.size_ + 1; - generateCode(node->left_); + auto root_node = generateTree(); + nodes_[root_node].code.size_ = 0; + nodes_[root_node].code.value_ = 0; + generateCode(root_node); } -} - -void Huffman::getTreeCode(std::vector& out) -{ - BitFileGenerator bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); - //coding tree - bit.writeType1((leaf_map_.size() >> 0) & 0x000000ff); - bit.writeType1((leaf_map_.size() >> 8) & 0x000000ff); - for(const auto& it : leaf_map_) + void Huffman::getTreeCode(std::vector& out) { - bit.writeType1(it.second->data_); - bit.writeType2(it.second->code_.size_); - bit.writeType3(it.second->code_.value_); + BitFileGenerator bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); + size_t valid_leaf = 0; + for(size_t i = 0; i < leaf_count; i++) + if(nodes_[i].freq != 0) + valid_leaf++; + + //coding tree + bit.writeType1((valid_leaf >> 0) & 0x000000ff); + bit.writeType1((valid_leaf >> 8) & 0x000000ff); + + for(size_t i = 0; i < leaf_count; i++) + { + if(nodes_[i].freq != 0) + { + bit.writeType1((char)i); + bit.writeType2(nodes_[i].code.size_); + bit.writeType3(nodes_[i].code.value_); + } + } + std::vector tmp; + bit.get(tmp); + out.insert(out.end(), tmp.begin(), tmp.end()); } - std::vector tmp; - bit.get(tmp); - out.insert(out.end(), tmp.begin(), tmp.end()); -} -void Huffman::getDataCode(std::vector& data, std::vector& out) -{ - BitFileGenerator bit(8); + void Huffman::getDataCode(const std::string& in_data, std::vector& out) + { + BitFileGenerator bit(8); + bit.resize(in_data.size()); + + bit.writeType1((in_data.size() >> 0) & 0x000000ff); + bit.writeType1((in_data.size() >> 8) & 0x000000ff); + bit.writeType1((in_data.size() >> 16) & 0x000000ff); + bit.writeType1((in_data.size() >> 24) & 0x000000ff); - bit.writeType1((data.size() >> 0) & 0x000000ff); - bit.writeType1((data.size() >> 8) & 0x000000ff); - bit.writeType1((data.size() >> 16) & 0x000000ff); - bit.writeType1((data.size() >> 24) & 0x000000ff); + for(const std::uint8_t& c : in_data) + bit.writeNReverse(nodes_[c].code.size_, nodes_[c].code.value_); + + std::vector tmp = bit.get(); + out.insert(out.end(), tmp.begin(), tmp.end()); + } - for(auto c : data) + size_t Huffman::setTree(const std::vector& in) { - auto& code = leaf_map_.find(c)->second->code_; - for(uint32_t i = 1 << (code.size_ - 1); i > 0; i >>= 1) - if(code.value_ & i) - bit.writeBitTrue(); - else - bit.writeBitFalse(); + BitFileGetter bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); + bit.set(in); + + auto nb_leaf = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + + using minheap = std::priority_queue< + HuffNode_t::Index, + std::vector>, + NodeValueCompare>; + + minheap heap{NodeValueCompare{nodes_}}; + h_min_ = leaf_count; + + for(size_t i = 0; i < nb_leaf; i++) + { + HuffNode_t::Index data = bit.getType1(); + nodes_[data].code.size_ = bit.getType2(); + nodes_[data].code.value_ = bit.getType3(); + heap.push(data); + if(nodes_[data].code.size_ < h_min_) + h_min_ = nodes_[data].code.size_; + } + + HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves + + while(heap.size() != 1) + { + auto right = heap.top(); + heap.pop(); + auto left = heap.top(); + heap.pop(); + + nodes_[bind_node_index].right = right; + nodes_[bind_node_index].left = left; + nodes_[bind_node_index].code.size_ = nodes_[right].code.size_ - 1; + nodes_[bind_node_index].code.value_ = (nodes_[right].code.value_ >> 1) & 0xefffffff; + if(nodes_[bind_node_index].code.size_ == h_min_) + subtrees_[nodes_[bind_node_index].code.value_] = bind_node_index; + + heap.push(bind_node_index); + ++bind_node_index; + } + + for(size_t i = 0; i < leaf_count; i++) + { + if(nodes_[i].code.size_ == h_min_) + subtrees_[nodes_[i].code.value_] = i; + } + + size_t tree_bit_size = (2*8 + nb_leaf*(TREE_CHAR_SIZE + TREE_VALUE_SIZE + TREE_VALUE_SIZE_SIZE)); + + return tree_bit_size / 8 + 1; } - std::vector tmp = bit.get(); - out.insert(out.end(), tmp.begin(), tmp.end()); -} -size_t Huffman::setTree(std::vector& in) -{ - BitFileGetter bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); - bit.set(in); + std::string Huffman::getFile(const std::vector& data) + { + std::string out = ""; + + const auto out_file_size = toInteger({(uint8_t)data[0], (uint8_t)data[1], (uint8_t)data[2], (uint8_t)data[3]}); + out.reserve(out_file_size); + + const auto nodes = nodes_.data(); + auto node = &nodes_[0]; - auto nb_leaf = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + uint8_t mask_index = 8; + uint8_t bit_data = 0x00; + uint8_t h_min_data = 0x00; - for(size_t i = 0; i < nb_leaf; i++) + uint32_t index = 3; + + for(;;) + { + h_min_data = 0x00; + for(size_t i = 0; i < h_min_; i++) + { + bit_data>>=1; + if((++mask_index) >= 8) + { + bit_data = data[++index]; + mask_index = 0; + } + h_min_data = (h_min_data << 1) | (bit_data & 0x01); + } + node = nodes + subtrees_[h_min_data]; + + while(node->right - HuffNode_t::invalid_index) + { + bit_data>>=1; + if((++mask_index) >= 8) + { + bit_data = data[++index]; + mask_index = 0; + } + node = ((bit_data & 0x01) ? nodes + node->left : nodes + node->right); + } + out += (char)(node - nodes); + if(out.size() == out_file_size) + break; + } + + return out; + } + + void Huffman::sum(const FrequencyMap& other, FrequencyMap& into) { - HuffNode_t* tmp_node = new HuffNode_t(bit.getType1()); - tmp_node->code_.size_ = bit.getType2(); - tmp_node->code_.value_ = bit.getType3(); - heap_.push_back(tmp_node); + std::transform(std::begin(other), std::end(other), std::begin(into), + std::begin(into), std::plus<>{}); } - std::sort(heap_.begin(), heap_.end(), comparePtrNodeByCode); - while(heap_.size() > 1) + FrequencyMap count_char_impl(const std::string& text) { - HuffNode_t* tmp_node = new HuffNode_t; - tmp_node->left_ = heap_[1]; - tmp_node->right_ = heap_[0]; - tmp_node->code_.size_ = heap_[0]->code_.size_ - 1; - tmp_node->code_.value_ = (heap_[0]->code_.value_ >> 1) & 0xefffffff; - heap_.erase(heap_.begin()); - heap_.erase(heap_.begin()); - heap_.push_back(tmp_node); - std::sort(heap_.begin(), heap_.end(), comparePtrNodeByCode); + FrequencyMap freq{}; // Zero-initialized array + for (const std::uint8_t& c : text) + freq[c]++; + return freq; } - size_t tree_bit_size = (2*8 + nb_leaf*(TREE_CHAR_SIZE + TREE_VALUE_SIZE + TREE_VALUE_SIZE_SIZE)); + void Huffman::count_char(const std::string& text, std::size_t jobs) + { + if (jobs <= 1) + { + sum(count_char_impl(text), frequencies_); + return; + } - return tree_bit_size / 8 + 1; -} + const auto thread_count = jobs - 1; + const auto bound = text.size() / thread_count; -void Huffman::getFile(std::vector& data, std::string& out) -{ - out = ""; - BitFileGetter bit(8); - bit.set(data); + std::vector> counting_units(thread_count); - auto out_file_size = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); - out.reserve(out_file_size); - while(out.size() < out_file_size) + size_t lower_bound = 0; + for (auto& unit : counting_units) + { + unit = std::async(std::launch::async, count_char_impl, + text.substr(lower_bound, bound)); + lower_bound += bound; + } + sum(count_char_impl(text.substr(lower_bound)), frequencies_); + + for (auto& unit : counting_units) + sum(unit.get(), frequencies_); + } + + HuffNode_t::Index Huffman::generateTree() { - HuffNode_t* node = heap_[0]; - while(node->right_ != nullptr) + using minheap = std::priority_queue< + HuffNode_t::Index, + std::vector>, + NodeCompare>; + + minheap heap{NodeCompare{nodes_}}; + + for (HuffNode_t::Index i = 0; i < frequencies_.size(); ++i) { - if(bit.getBit()) - node = node->left_; - else - node = node->right_; + if (frequencies_[i] == 0) + continue; // Do not set unused characters + nodes_[i].freq = frequencies_[i]; + heap.push(i); + } + + HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves + + while (heap.size() != 1) + { + auto right = heap.top(); + heap.pop(); + auto left = heap.top(); + heap.pop(); + + nodes_[bind_node_index].freq = + nodes_[left].freq + nodes_[right].freq; + nodes_[bind_node_index].left = left; + nodes_[bind_node_index].right = right; + heap.push(bind_node_index); + + ++bind_node_index; } - out += node->data_; + return heap.top(); } -} -} // namespace mementar + void Huffman::generateCode(HuffNode_t::Index index) + { + if(nodes_[index].right != HuffNode_t::invalid_index) + { + nodes_[nodes_[index].right].code.value_ = (nodes_[index].code.value_ << 1); + nodes_[nodes_[index].right].code.size_ = nodes_[index].code.size_ + 1; + generateCode(nodes_[index].right); + } + if(nodes_[index].left != HuffNode_t::invalid_index) + { + nodes_[nodes_[index].left].code.value_ = (nodes_[index].code.value_ << 1) | 0x01; + nodes_[nodes_[index].left].code.size_ = nodes_[index].code.size_ + 1; + generateCode(nodes_[index].left); + } + } +} diff --git a/src/core/archiving_compressing/compressing/Huffman_.cpp b/src/core/archiving_compressing/compressing/Huffman_.cpp deleted file mode 100644 index 0a69b19..0000000 --- a/src/core/archiving_compressing/compressing/Huffman_.cpp +++ /dev/null @@ -1,332 +0,0 @@ -#include "mementar/core/archiving_compressing/compressing/Huffman_.h" - -#include -#include -#include -#include -#include - -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" - -#define TREE_CHAR_SIZE 8 -#define TREE_VALUE_SIZE 6 -#define TREE_VALUE_SIZE_SIZE 31 //do not go over 31 - -template -struct static_alloc { - using value_type = T; - static_alloc() = default; - template - constexpr static_alloc(const static_alloc&) noexcept {}; - [[nodiscard]] constexpr value_type* allocate(std::size_t n) { - return buffer.data(); - } - constexpr void deallocate(value_type* p, std::size_t n) {} - template - struct rebind { - using other = static_alloc; - }; - std::array buffer{}; -}; -template -bool operator==(const static_alloc&, const static_alloc&) { - return true; -} -template -bool operator!=(const static_alloc&, const static_alloc&) { - return false; -} - -namespace mementar { - - struct NodeCompare - { - public: - explicit NodeCompare(const NodeList& nodes) : nodes_{nodes} {} - bool operator()(HuffNode_t::Index l, HuffNode_t::Index r) - { - return nodes_[l].freq > nodes_[r].freq; - } - - private: - const NodeList& nodes_; - }; - - struct NodeValueCompare - { - public: - explicit NodeValueCompare(const NodeList& nodes) : nodes_{nodes} {} - bool operator()(HuffNode_t::Index l, HuffNode_t::Index r) - { - if(nodes_[l].code.size_ < nodes_[r].code.size_) - return true; - else if(nodes_[l].code.size_ > nodes_[r].code.size_) - return false; - else if(nodes_[l].code.value_ < nodes_[r].code.value_) - return false; - else - return true; - } - - private: - const NodeList& nodes_; - }; - - Huffman_::Huffman_() : BinaryManager("mhu") - { - - } - - void Huffman_::generateTree(const std::string& data, std::size_t jobs) - { - auto freqs = count_char(data, jobs); - auto root_node = generateTree(freqs); - nodes_[root_node].code.size_ = 0; - nodes_[root_node].code.value_ = 0; - generateCode(root_node); - } - - void Huffman_::getTreeCode(std::vector& out) - { - BitFileGenerator bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); - size_t valid_leaf = 0; - for(size_t i = 0; i < leaf_count; i++) - if(nodes_[i].freq != 0) - valid_leaf++; - - //coding tree - bit.writeType1((valid_leaf >> 0) & 0x000000ff); - bit.writeType1((valid_leaf >> 8) & 0x000000ff); - - for(size_t i = 0; i < leaf_count; i++) - { - if(nodes_[i].freq != 0) - { - bit.writeType1((char)i); - bit.writeType2(nodes_[i].code.size_); - bit.writeType3(nodes_[i].code.value_); - } - } - std::vector tmp; - bit.get(tmp); - out.insert(out.end(), tmp.begin(), tmp.end()); - } - - void Huffman_::getDataCode(const std::vector& data, std::vector& out) - { - BitFileGenerator bit(8); - bit.resize(data.size()); - - bit.writeType1((data.size() >> 0) & 0x000000ff); - bit.writeType1((data.size() >> 8) & 0x000000ff); - bit.writeType1((data.size() >> 16) & 0x000000ff); - bit.writeType1((data.size() >> 24) & 0x000000ff); - - for(const std::uint8_t& c : data) - bit.writeNReverse(nodes_[c].code.size_, nodes_[c].code.value_); - - std::vector tmp = bit.get(); - out.insert(out.end(), tmp.begin(), tmp.end()); - } - - size_t Huffman_::setTree(const std::vector& in) - { - BitFileGetter bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); - bit.set(in); - - auto nb_leaf = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); - - using minheap = std::priority_queue< - HuffNode_t::Index, - std::vector>, - NodeValueCompare>; - - minheap heap{NodeValueCompare{nodes_}}; - h_min_ = leaf_count; - - for(size_t i = 0; i < nb_leaf; i++) - { - HuffNode_t::Index data = bit.getType1(); - nodes_[data].code.size_ = bit.getType2(); - nodes_[data].code.value_ = bit.getType3(); - heap.push(data); - if(nodes_[data].code.size_ < h_min_) - h_min_ = nodes_[data].code.size_; - } - - HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves - - while(heap.size() != 1) - { - auto right = heap.top(); - heap.pop(); - auto left = heap.top(); - heap.pop(); - - nodes_[bind_node_index].right = right; - nodes_[bind_node_index].left = left; - nodes_[bind_node_index].code.size_ = nodes_[right].code.size_ - 1; - nodes_[bind_node_index].code.value_ = (nodes_[right].code.value_ >> 1) & 0xefffffff; - if(nodes_[bind_node_index].code.size_ == h_min_) - subtrees_[nodes_[bind_node_index].code.value_] = bind_node_index; - - heap.push(bind_node_index); - ++bind_node_index; - } - - for(size_t i = 0; i < leaf_count; i++) - { - if(nodes_[i].code.size_ == h_min_) - subtrees_[nodes_[i].code.value_] = i; - } - - size_t tree_bit_size = (2*8 + nb_leaf*(TREE_CHAR_SIZE + TREE_VALUE_SIZE + TREE_VALUE_SIZE_SIZE)); - - return tree_bit_size / 8 + 1; - } - - std::string Huffman_::getFile(const std::vector& data) - { - std::string out = ""; - - const auto out_file_size = toInteger({(uint8_t)data[0], (uint8_t)data[1], (uint8_t)data[2], (uint8_t)data[3]}); - out.reserve(out_file_size); - - auto nodes = nodes_.data(); - auto node = &nodes_[0]; - - uint8_t mask_index = 8; - uint8_t bit_data = 0x00; - uint8_t h_min_data = 0x00; - - uint32_t index = 3; - - for(;;) - { - h_min_data = 0x00; - for(size_t i = 0; i < h_min_; i++) - { - bit_data>>=1; - if((++mask_index) >= 8) - { - bit_data = data[++index]; - mask_index = 0; - } - h_min_data = (h_min_data << 1) | (bit_data & 0x01); - } - node = nodes + subtrees_[h_min_data]; - - while(node->right - HuffNode_t::invalid_index) - { - bit_data>>=1; - if((++mask_index) >= 8) - { - bit_data = data[++index]; - mask_index = 0; - } - if(bit_data & 0x01) - node = nodes + node->left; - else - node = nodes + node->right; - } - out += (char)(node - nodes); - if(out.size() == out_file_size) - break; - } - - return out; - } - - void Huffman_::sum(const FrequencyMap& other, FrequencyMap& into) - { - std::transform(std::begin(other), std::end(other), std::begin(into), - std::begin(into), std::plus<>{}); - } - - FrequencyMap count_char_impl(const std::string& text) - { - FrequencyMap freq{}; // Zero-initialized array - for (const std::uint8_t& c : text) - freq[c]++; - return freq; - } - - FrequencyMap Huffman_::count_char(const std::string& text, std::size_t jobs) - { - if (jobs <= 1) - return count_char_impl(text); - - const auto thread_count = jobs - 1; - const auto bound = text.size() / thread_count; - - std::vector> counting_units(thread_count); - - size_t lower_bound = 0; - for (auto& unit : counting_units) - { - unit = std::async(std::launch::async, count_char_impl, - text.substr(lower_bound, bound)); - lower_bound += bound; - } - auto result = count_char_impl(text.substr(lower_bound)); - - for (auto& unit : counting_units) - sum(unit.get(), result); - - return result; - } - - HuffNode_t::Index Huffman_::generateTree(const FrequencyMap& freq) - { - using minheap = std::priority_queue< - HuffNode_t::Index, - std::vector>, - NodeCompare>; - - minheap heap{NodeCompare{nodes_}}; - - for (HuffNode_t::Index i = 0; i < freq.size(); ++i) - { - if (freq[i] == 0) - continue; // Do not set unused characters - nodes_[i].freq = freq[i]; - heap.push(i); - } - - HuffNode_t::Index bind_node_index = leaf_count; // bind nodes are stored after all leaves - - while (heap.size() != 1) - { - auto right = heap.top(); - heap.pop(); - auto left = heap.top(); - heap.pop(); - - nodes_[bind_node_index].freq = - nodes_[left].freq + nodes_[right].freq; - nodes_[bind_node_index].left = left; - nodes_[bind_node_index].right = right; - heap.push(bind_node_index); - - ++bind_node_index; - } - return heap.top(); - } - - void Huffman_::generateCode(HuffNode_t::Index index) - { - if(nodes_[index].right != HuffNode_t::invalid_index) - { - nodes_[nodes_[index].right].code.value_ = (nodes_[index].code.value_ << 1); - nodes_[nodes_[index].right].code.size_ = nodes_[index].code.size_ + 1; - generateCode(nodes_[index].right); - } - if(nodes_[index].left != HuffNode_t::invalid_index) - { - nodes_[nodes_[index].left].code.value_ = (nodes_[index].code.value_ << 1) | 0x01; - nodes_[nodes_[index].left].code.size_ = nodes_[index].code.size_ + 1; - generateCode(nodes_[index].left); - } - } -} diff --git a/src/core/archiving_compressing/compressing/Huffman_old.cpp b/src/core/archiving_compressing/compressing/Huffman_old.cpp new file mode 100644 index 0000000..0703de0 --- /dev/null +++ b/src/core/archiving_compressing/compressing/Huffman_old.cpp @@ -0,0 +1,204 @@ +#include "mementar/core/archiving_compressing/compressing/Huffman_old.h" + +#include +#include + +#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" + +namespace mementar +{ + +#define TREE_CHAR_SIZE 8 +#define TREE_VALUE_SIZE 6 +#define TREE_VALUE_SIZE_SIZE 31 //do not go over 31 + +void print_tree(HuffNode_t* node) +{ + for(size_t i = 0; i < node->code_.size_; i++) + std::cout << " "; + std::cout << std::hex << node->code_.value_ << std::endl; + + if(node->left_ != nullptr) + print_tree(node->left_); + if(node->right_ != nullptr) + print_tree(node->right_); +} + +bool comparePtrNode(HuffNode_t* a, HuffNode_t* b) +{ + return (a->freq_ < b->freq_); +} + +bool comparePtrNodeByCode(HuffNode_t* a, HuffNode_t* b) +{ + if(a->code_.size_ < b->code_.size_) + return false; + else if(a->code_.size_ > b->code_.size_) + return true; + else if(a->code_.value_ < b->code_.value_) + return true; + else + return false; +} + +Huffman_::Huffman_() : BinaryManager("mhu") +{ + +} + +Huffman_::~Huffman_() +{ + for(auto it : heap_) + delete it; +} + +void Huffman_::analyse(std::vector& data) +{ + for(const auto& c : data) + { + auto it = leaf_map_.find(c); + if(it == leaf_map_.end()) + { + HuffNode_t* leaf = new HuffNode_t(c); + heap_.push_back(leaf); + leaf_map_[c] = leaf; + } + else + it->second->freq_++; + } +} + +void Huffman_::generateTree() +{ + while(heap_.size() > 1) + { + std::sort(heap_.begin(), heap_.end(), comparePtrNode); + + HuffNode_t* tmp = new HuffNode_t(); + tmp->right_ = heap_[0]; + tmp->left_ = heap_[1]; + tmp->freq_ = tmp->right_->freq_ + tmp->left_->freq_; + heap_.erase(heap_.begin()); + heap_.erase(heap_.begin()); + heap_.push_back(tmp); + } + + heap_[0]->code_.value_ = 0; + heap_[0]->code_.size_ = 0; + generateCode(heap_[0]); +} + +void Huffman_::generateCode(HuffNode_t* node) +{ + if(node->right_ != nullptr) + { + node->right_->code_.value_ = (node->code_.value_ << 1); + node->right_->code_.size_ = node->code_.size_ + 1; + generateCode(node->right_); + } + if(node->left_ != nullptr) + { + node->left_->code_.value_ = (node->code_.value_ << 1) | 0x01; + node->left_->code_.size_ = node->code_.size_ + 1; + generateCode(node->left_); + } +} + +void Huffman_::getTreeCode(std::vector& out) +{ + BitFileGenerator bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); + //coding tree + bit.writeType1((leaf_map_.size() >> 0) & 0x000000ff); + bit.writeType1((leaf_map_.size() >> 8) & 0x000000ff); + + for(const auto& it : leaf_map_) + { + bit.writeType1(it.second->data_); + bit.writeType2(it.second->code_.size_); + bit.writeType3(it.second->code_.value_); + } + std::vector tmp; + bit.get(tmp); + out.insert(out.end(), tmp.begin(), tmp.end()); +} + +void Huffman_::getDataCode(std::vector& data, std::vector& out) +{ + BitFileGenerator bit(8); + + bit.writeType1((data.size() >> 0) & 0x000000ff); + bit.writeType1((data.size() >> 8) & 0x000000ff); + bit.writeType1((data.size() >> 16) & 0x000000ff); + bit.writeType1((data.size() >> 24) & 0x000000ff); + + for(auto c : data) + { + auto& code = leaf_map_.find(c)->second->code_; + for(uint32_t i = 1 << (code.size_ - 1); i > 0; i >>= 1) + if(code.value_ & i) + bit.writeBitTrue(); + else + bit.writeBitFalse(); + } + std::vector tmp = bit.get(); + out.insert(out.end(), tmp.begin(), tmp.end()); +} + +size_t Huffman_::setTree(std::vector& in) +{ + BitFileGetter bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); + bit.set(in); + + auto nb_leaf = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + + for(size_t i = 0; i < nb_leaf; i++) + { + HuffNode_t* tmp_node = new HuffNode_t(bit.getType1()); + tmp_node->code_.size_ = bit.getType2(); + tmp_node->code_.value_ = bit.getType3(); + heap_.push_back(tmp_node); + } + + std::sort(heap_.begin(), heap_.end(), comparePtrNodeByCode); + while(heap_.size() > 1) + { + HuffNode_t* tmp_node = new HuffNode_t; + tmp_node->left_ = heap_[1]; + tmp_node->right_ = heap_[0]; + tmp_node->code_.size_ = heap_[0]->code_.size_ - 1; + tmp_node->code_.value_ = (heap_[0]->code_.value_ >> 1) & 0xefffffff; + heap_.erase(heap_.begin()); + heap_.erase(heap_.begin()); + heap_.push_back(tmp_node); + std::sort(heap_.begin(), heap_.end(), comparePtrNodeByCode); + } + + size_t tree_bit_size = (2*8 + nb_leaf*(TREE_CHAR_SIZE + TREE_VALUE_SIZE + TREE_VALUE_SIZE_SIZE)); + + return tree_bit_size / 8 + 1; +} + +void Huffman_::getFile(std::vector& data, std::string& out) +{ + out = ""; + BitFileGetter bit(8); + bit.set(data); + + auto out_file_size = toInteger({(uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1(), (uint8_t)bit.getType1()}); + out.reserve(out_file_size); + while(out.size() < out_file_size) + { + HuffNode_t* node = heap_[0]; + while(node->right_ != nullptr) + { + if(bit.getBit()) + node = node->left_; + else + node = node->right_; + } + out += node->data_; + } +} + +} // namespace mementar diff --git a/src/core/archiving_compressing/tests/compress.cpp b/src/core/archiving_compressing/tests/compress.cpp index 5aab2eb..fe9cf05 100644 --- a/src/core/archiving_compressing/tests/compress.cpp +++ b/src/core/archiving_compressing/tests/compress.cpp @@ -99,14 +99,12 @@ int main (int argc, char* argv[]) } else if(code_type == huffman) { - std::vector in_vect(in.begin(), in.end()); - mementar::Huffman huff; - huff.analyse(in_vect); - huff.generateTree(); + huff.analyse(in); + huff.generateCode(); std::vector out_vect; huff.getTreeCode(out_vect); - huff.getDataCode(in_vect, out_vect); + huff.getDataCode(in, out_vect); huff.displayCompressionRate(in.size(), out_vect.size()); huff.saveToFile(out_vect, output_file); diff --git a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp index b90cd20..f35327d 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp +++ b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp @@ -7,7 +7,7 @@ #include /* time */ //#include "mementar/core/archiving_compressing/compressing/Huffman.h" -#include "mementar/core/archiving_compressing/compressing/Huffman_.h" +#include "mementar/core/archiving_compressing/compressing/Huffman.h" using namespace std::chrono; @@ -51,13 +51,12 @@ float testHuffman(size_t nb, const std::string& input_file) for(size_t i = 0; i < nb; i++) { - std::vector in_vect(in.begin(), in.end()); - - mementar::Huffman_ huff; - huff.generateTree(in); + mementar::Huffman huff; + huff.analyse(in); + huff.generateCode(); std::vector out_vect; huff.getTreeCode(out_vect); - huff.getDataCode(in_vect, out_vect); + huff.getDataCode(in, out_vect); if(i == 0) { diff --git a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp b/src/core/archiving_compressing/tests/perfs/huffman_out.cpp index bb23ab4..e970d73 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp +++ b/src/core/archiving_compressing/tests/perfs/huffman_out.cpp @@ -9,9 +9,9 @@ #define NEW_V #ifdef NEW_V -#include "mementar/core/archiving_compressing/compressing/Huffman_.h" -#else #include "mementar/core/archiving_compressing/compressing/Huffman.h" +#else +#include "mementar/core/archiving_compressing/compressing/Huffman_old.h" #endif @@ -29,9 +29,9 @@ float testHuffman(size_t nb, const std::string& input_file) for(size_t i = 0; i < nb; i++) { #ifdef NEW_V - mementar::Huffman_ huff; - #else mementar::Huffman huff; + #else + mementar::Huffman_ huff; #endif std::vector data; if(huff.readBinaryFile(data, input_file)) diff --git a/src/core/archiving_compressing/tests/uncompress.cpp b/src/core/archiving_compressing/tests/uncompress.cpp index 09a1195..60cec34 100644 --- a/src/core/archiving_compressing/tests/uncompress.cpp +++ b/src/core/archiving_compressing/tests/uncompress.cpp @@ -97,7 +97,7 @@ int main (int argc, char* argv[]) { size_t tree_size = huff.setTree(data); data = std::vector(data.begin() + tree_size, data.end()); - huff.getFile(data, out); + out = huff.getFile(data); } } From a8901dc57d27d5242eb3477c070a773a64c83160 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 1 Apr 2020 16:13:16 +0200 Subject: [PATCH 27/95] [REFACT] replace old huffman version in ROS mementar --- .../EpisodicTree/CompressedLeafNodeSession.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index 6cdf445..85bcae2 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -22,18 +22,27 @@ CompressedLeafNodeSession::~CompressedLeafNodeSession() Archive arch(description, header_); - std::vector > raw_datas; + std::vector raw_datas; for(size_t i = 0; i < childs_.size(); i++) { if(sessions_tree_[i] != nullptr) { if(modified_[i]) - raw_datas.push_back(treeToRaw(i)); + { + auto tmp_raw = treeToRaw(i); + raw_datas.emplace_back(tmp_raw.begin(), tmp_raw.end()); + } else - raw_datas.push_back(childs_[i].getRawData(header_, arch_)); + { + auto tmp_raw = childs_[i].getRawData(header_, arch_); + raw_datas.emplace_back(tmp_raw.begin(), tmp_raw.end()); + } } else - raw_datas.push_back(childs_[i].getRawData(header_, arch_)); + { + auto tmp_raw = childs_[i].getRawData(header_, arch_); + raw_datas.emplace_back(tmp_raw.begin(), tmp_raw.end()); + } } std::vector data; From fac7ea1966fcb705e9df39747ced4030971ae849 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Thu, 2 Apr 2020 17:38:12 +0200 Subject: [PATCH 28/95] [REFACT] lz compression --- .../binaryManagement/BitFileGenerator.h | 2 +- .../compressing/LzCompress.h | 2 +- src/core/EpisodicTree/CompressedLeaf.cpp | 3 +- .../CompressedLeafNodeSession.cpp | 5 +- src/core/archiving_compressing/CMakeLists.txt | 3 + .../archiving/Archive.cpp | 6 +- .../binaryManagement/BitFileGenerator.cpp | 77 +++++++++++-------- .../compressing/LzCompress.cpp | 48 +++++++----- .../archiving_compressing/tests/compress.cpp | 3 +- .../tests/perfs/lz_in.cpp | 55 +++++++++++++ 10 files changed, 140 insertions(+), 64 deletions(-) create mode 100644 src/core/archiving_compressing/tests/perfs/lz_in.cpp diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h b/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h index a5512dd..a30a335 100644 --- a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h +++ b/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h @@ -24,7 +24,7 @@ class BitFileGenerator void writeBitTrue(); void writeBitFalse(); - std::vector get() { return std::vector(data_.begin(), data_.begin() + major_index_); } + std::vector get() { return std::vector(data_.begin(), data_.begin() + major_index_ + 1); } void get(std::vector& out) { out = data_; } private: diff --git a/include/mementar/core/archiving_compressing/compressing/LzCompress.h b/include/mementar/core/archiving_compressing/compressing/LzCompress.h index 3f62968..1ec25e3 100644 --- a/include/mementar/core/archiving_compressing/compressing/LzCompress.h +++ b/include/mementar/core/archiving_compressing/compressing/LzCompress.h @@ -15,7 +15,7 @@ class LzCompress : public BinaryManager public: LzCompress(size_t search_size = 2048, size_t la_size = 64); - void compress(std::string& in, std::vector& out); + std::vector compress(const std::string& in); private: size_t search_size_; diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 406ea7a..9fa6056 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -19,9 +19,8 @@ CompressedLeaf::CompressedLeaf(Btree>* tree, const st directory_ = directory + '/' + std::to_string(key_); LzCompress lz_comp; - std::vector out_vect; std::string in = treeToString(tree); - lz_comp.compress(in, out_vect); + std::vector out_vect = lz_comp.compress(in); lz_comp.displayCompressionRate(in.size(), out_vect.size()); lz_comp.saveToFile(out_vect, directory_); diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index 85bcae2..9c8c8ed 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -220,10 +220,7 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) } mementar::LzCompress lz_comp; - std::vector res_vect; - lz_comp.compress(res, res_vect); - - return res_vect; + return lz_comp.compress(res); } } // namespace mementar diff --git a/src/core/archiving_compressing/CMakeLists.txt b/src/core/archiving_compressing/CMakeLists.txt index 9581546..06e81a8 100644 --- a/src/core/archiving_compressing/CMakeLists.txt +++ b/src/core/archiving_compressing/CMakeLists.txt @@ -36,3 +36,6 @@ target_link_libraries(huffman_in mementar_compression_lib) add_executable(huffman_out tests/perfs/huffman_out.cpp) target_link_libraries(huffman_out mementar_compression_lib) + +add_executable(lz_in tests/perfs/lz_in.cpp) +target_link_libraries(lz_in mementar_compression_lib) diff --git a/src/core/archiving_compressing/archiving/Archive.cpp b/src/core/archiving_compressing/archiving/Archive.cpp index da413a1..e039332 100644 --- a/src/core/archiving_compressing/archiving/Archive.cpp +++ b/src/core/archiving_compressing/archiving/Archive.cpp @@ -39,11 +39,10 @@ Archive::Archive() : BinaryManager("mar") void Archive::load(std::vector& out) { - std::vector out_vect; size_t offset = 0; LzCompress lz_comp; - lz_comp.compress(description_, out_vect); + std::vector out_vect = lz_comp.compress(description_); out.insert(out.end(), out_vect.begin(), out_vect.end()); offset += out_vect.size(); header_.description_file_.size_ = out_vect.size(); @@ -86,11 +85,10 @@ void Archive::load(std::vector& out, std::vector& raw_datas) return; } - std::vector out_vect; size_t offset = 0; LzCompress lz_comp; - lz_comp.compress(description_, out_vect); + std::vector out_vect = lz_comp.compress(description_); out.insert(out.end(), out_vect.begin(), out_vect.end()); offset += out_vect.size(); header_.description_file_.size_ = out_vect.size(); diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp b/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp index 148b7fb..35d0b5c 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp +++ b/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp @@ -23,19 +23,21 @@ void BitFileGenerator::writeType1(uint32_t value) { data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); - uint8_t added = 8 - minor_index_; + const uint8_t added = 8 - minor_index_; value >>= added; to_add -= added; if(to_add >= 0) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } else + { minor_index_ = 8 + to_add; + return; + } } while(to_add > 0); } @@ -47,19 +49,21 @@ void BitFileGenerator::writeType2(uint32_t value) { data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); - uint8_t added = 8 - minor_index_; + const uint8_t added = 8 - minor_index_; value >>= added; to_add -= added; if(to_add >= 0) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } else + { minor_index_ = 8 + to_add; + return; + } } while(to_add > 0); } @@ -71,19 +75,21 @@ void BitFileGenerator::writeType3(uint32_t value) { data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); - uint8_t added = 8 - minor_index_; + const uint8_t added = 8 - minor_index_; value >>= added; to_add -= added; if(to_add >= 0) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } else + { minor_index_ = 8 + to_add; + return; + } } while(to_add > 0); } @@ -95,19 +101,21 @@ void BitFileGenerator::writeType4(uint32_t value) { data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); - uint8_t added = 8 - minor_index_; + const uint8_t added = 8 - minor_index_; value >>= added; to_add -= added; if(to_add >= 0) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } else + { minor_index_ = 8 + to_add; + return; + } } while(to_add > 0); } @@ -119,19 +127,21 @@ void BitFileGenerator::writeN(size_t size, uint32_t value) { data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); - uint8_t added = 8 - minor_index_; + const uint8_t added = 8 - minor_index_; value >>= added; to_add -= added; if(to_add >= 0) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } else + { minor_index_ = 8 + to_add; + return; + } } while(to_add > 0); } @@ -146,8 +156,7 @@ void BitFileGenerator::writeNReverse(size_t size, uint32_t value) minor_index_++; if(minor_index_ > 7) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } @@ -161,19 +170,21 @@ void BitFileGenerator::writeChar(char value) { data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); - uint8_t added = 8 - minor_index_; + const uint8_t added = 8 - minor_index_; value >>= added; to_add -= added; if(to_add >= 0) { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; } else + { minor_index_ = 8 + to_add; + return; + } } while(to_add > 0); } @@ -181,28 +192,34 @@ void BitFileGenerator::writeChar(char value) void BitFileGenerator::writeBitTrue() { data_[major_index_] |= (1 << minor_index_); - if(minor_index_ >= 7) + if(7 - minor_index_) + { + ++minor_index_; + return; + } + else { - major_index_++; - if(data_.size() <= major_index_) + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; + return; } - else - minor_index_++; } void BitFileGenerator::writeBitFalse() { - if(minor_index_ >= 7) + if(7 - minor_index_) { - major_index_++; - if(data_.size() <= major_index_) + ++minor_index_; + return; + } + else + { + if(data_.size() <= ++major_index_) data_.push_back(0x00); minor_index_ = 0; + return; } - else - minor_index_++; } } // namespace mementar diff --git a/src/core/archiving_compressing/compressing/LzCompress.cpp b/src/core/archiving_compressing/compressing/LzCompress.cpp index 3baaa2e..ecad5a9 100644 --- a/src/core/archiving_compressing/compressing/LzCompress.cpp +++ b/src/core/archiving_compressing/compressing/LzCompress.cpp @@ -16,9 +16,10 @@ LzCompress::LzCompress(size_t search_size, size_t la_size) : BinaryManager("mlz" la_size_1_ = la_size_ - 1; } -void LzCompress::compress(std::string& in, std::vector& out) +std::vector LzCompress::compress(const std::string& in) { - size_t in_size = in.size(); + const size_t in_size = in.size(); + bit.resize(in_size); bit.writeType3(in_size >> 0); bit.writeType3(in_size >> 8); @@ -35,35 +36,42 @@ void LzCompress::compress(std::string& in, std::vector& out) bit.writeChar(in[0]); size_t cursor = 1; + size_t cursor_1 = 0; size_t index = -1; size_t length = 1; size_t tmp_length = 1; size_t search_index = 1; size_t la_index = 1; size_t i = -1; + char c_tmp; while (cursor < in_size) { length = 1; - char c_tmp = in[cursor]; - for(i = std::max(cursor - search_size_1_, size_t{0}); i < cursor; i++) + c_tmp = in[cursor]; + cursor_1 = cursor - 1; + for(i = std::max(cursor - search_size_1_, size_t{0}); i < cursor_1; i++) { if(in[i] == c_tmp) { - tmp_length = 1; - search_index = i + 1; - la_index = cursor + 1; - while((in[search_index] == in[la_index]) && (tmp_length < la_size_1_) && (search_index < cursor)) + if(in[i+1] == in[cursor+1]) // directly check the second character in order + // to avoid to do usless expensive tests { - tmp_length++; - search_index++; - la_index++; - } - - if(tmp_length > length) - { - length = tmp_length; - index = i; + tmp_length = 1; + search_index = i + 1; + la_index = cursor + 1; + while((in[search_index] == in[la_index]) && (tmp_length - la_size_1_) && (search_index < cursor)) + { + ++tmp_length; + ++search_index; + ++la_index; + } + + if(tmp_length > length) + { + length = tmp_length; + index = i; + } } } } @@ -73,17 +81,17 @@ void LzCompress::compress(std::string& in, std::vector& out) bit.writeBitTrue(); bit.writeType1(cursor - index); bit.writeType2(length); + cursor += length; } else { bit.writeBitFalse(); bit.writeChar(c_tmp); + ++cursor; } - - cursor += length; } - bit.get(out); + return bit.get(); } int LzCompress::neededBitCount(size_t max_value) diff --git a/src/core/archiving_compressing/tests/compress.cpp b/src/core/archiving_compressing/tests/compress.cpp index fe9cf05..3a26f48 100644 --- a/src/core/archiving_compressing/tests/compress.cpp +++ b/src/core/archiving_compressing/tests/compress.cpp @@ -91,8 +91,7 @@ int main (int argc, char* argv[]) if(code_type == lz77) { mementar::LzCompress lz_comp; - std::vector out_vect; - lz_comp.compress(in, out_vect); + std::vector out_vect = lz_comp.compress(in); lz_comp.displayCompressionRate(in.size(), out_vect.size()); lz_comp.saveToFile(out_vect, output_file); diff --git a/src/core/archiving_compressing/tests/perfs/lz_in.cpp b/src/core/archiving_compressing/tests/perfs/lz_in.cpp new file mode 100644 index 0000000..75fdb79 --- /dev/null +++ b/src/core/archiving_compressing/tests/perfs/lz_in.cpp @@ -0,0 +1,55 @@ +#include +#include +#include + +#include +#include /* srand, rand */ +#include /* time */ + +#include "mementar/core/archiving_compressing/compressing/LzCompress.h" + +using namespace std::chrono; + +float testLz(size_t nb, const std::string& input_file) +{ + std::ifstream t(input_file); + std::string in((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i++) + { + mementar::LzCompress lz_comp; + std::vector out_vect = lz_comp.compress(in); + + if(i == 0) + { + lz_comp.displayCompressionRate(in.size(), out_vect.size()); + lz_comp.saveToFile(out_vect, "../tests_files/out/" + std::to_string(in.size())); + } + } + + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + + return time_span.count()*1000/nb; // return time span in ms +} + +int main (int argc, char* argv[]) +{ + const size_t nb = 1; + + float time_252 = testLz(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_252_1MB.txt"); + float time_10 = testLz(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_10_9MB.txt"); + float time_6 = testLz(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_6_5MB.txt"); + + float mean = (time_252 + time_10 + time_6) / 3.0; + + std::cout << "252 = " << time_252 << std::endl; + std::cout << "10 = " << time_10 << std::endl; + std::cout << "6 = " << time_6 << std::endl; + std::cout << "mean = " << mean << std::endl; + + return 0; +} From 100670501ab3033c5cd5f2ecd2f57d780d784721 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 3 Apr 2020 11:09:16 +0200 Subject: [PATCH 29/95] [REFACT] lz decompression --- .../compressing/LzUncompress.h | 7 +- src/core/EpisodicTree/ArchivedLeaf.cpp | 3 +- src/core/EpisodicTree/CompressedLeaf.cpp | 4 +- .../EpisodicTree/CompressedLeafSession.cpp | 3 +- src/core/archiving_compressing/CMakeLists.txt | 3 + .../archiving/Archive.cpp | 4 +- .../binaryManagement/BitFileGetter.cpp | 85 ++++++++++--------- .../compressing/LzUncompress.cpp | 22 ++--- .../tests/perfs/huffman_out.cpp | 4 - .../tests/uncompress.cpp | 2 +- 10 files changed, 65 insertions(+), 72 deletions(-) diff --git a/include/mementar/core/archiving_compressing/compressing/LzUncompress.h b/include/mementar/core/archiving_compressing/compressing/LzUncompress.h index 3d2f7f8..d720dc7 100644 --- a/include/mementar/core/archiving_compressing/compressing/LzUncompress.h +++ b/include/mementar/core/archiving_compressing/compressing/LzUncompress.h @@ -12,14 +12,9 @@ class LzUncompress : public BinaryManager public: LzUncompress(); - void uncompress(std::vector& data, std::string& out); + std::string uncompress(const std::vector& data); private: - size_t search_size_; - size_t la_size_; - - BitFileGetter bit; - int neededBitCount(size_t max_value); }; diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index 7640be3..c3d90fb 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -67,10 +67,9 @@ LinkedBtree* ArchivedLeaf::getTree(size_t i) std::string comp = arch.extractFile(i, header); - std::string out; LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); - lz.uncompress(comp_data, out); + std::string out = lz.uncompress(comp_data); LinkedBtree* tree = new LinkedBtree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/EpisodicTree/CompressedLeaf.cpp index 9fa6056..d85497f 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/EpisodicTree/CompressedLeaf.cpp @@ -35,13 +35,11 @@ CompressedLeaf::CompressedLeaf(const time_t& key, const std::string& directory) LinkedBtree* CompressedLeaf::getTree() { - std::string out; - LzUncompress lz; std::vector data; if(lz.readBinaryFile(data, directory_ + ".mlz")) { - lz.uncompress(data, out); + std::string out = lz.uncompress(data); LinkedBtree* tree = new LinkedBtree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/EpisodicTree/CompressedLeafSession.cpp index 67977ec..41bc489 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafSession.cpp @@ -18,10 +18,9 @@ LinkedBtree* CompressedLeafSession::getTree(Header& header, Archive& arc { std::string comp = arch.extractFile(index_, header); - std::string out; LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); - lz.uncompress(comp_data, out); + std::string out = lz.uncompress(comp_data); LinkedBtree* tree = new LinkedBtree(); std::regex regex("\\[(\\d+)\\](\\w+)\\|(\\w+)\\|(\\w+)"); diff --git a/src/core/archiving_compressing/CMakeLists.txt b/src/core/archiving_compressing/CMakeLists.txt index 06e81a8..ccda8fb 100644 --- a/src/core/archiving_compressing/CMakeLists.txt +++ b/src/core/archiving_compressing/CMakeLists.txt @@ -39,3 +39,6 @@ target_link_libraries(huffman_out mementar_compression_lib) add_executable(lz_in tests/perfs/lz_in.cpp) target_link_libraries(lz_in mementar_compression_lib) + +add_executable(lz_out tests/perfs/lz_out.cpp) +target_link_libraries(lz_out mementar_compression_lib) diff --git a/src/core/archiving_compressing/archiving/Archive.cpp b/src/core/archiving_compressing/archiving/Archive.cpp index e039332..ef807fb 100644 --- a/src/core/archiving_compressing/archiving/Archive.cpp +++ b/src/core/archiving_compressing/archiving/Archive.cpp @@ -126,11 +126,9 @@ Header Archive::getHeader(std::vector& data) std::string Archive::extractDescription(Header& head, std::vector& data) { - std::string out; LzUncompress lz; std::vector tmp_data(data.begin() + head.description_file_.offset_, data.begin() + head.description_file_.offset_ + head.description_file_.size_); - lz.uncompress(tmp_data, out); - return out; + return lz.uncompress(tmp_data); } std::string Archive::extractFile(size_t index, Header& head, std::vector& data) diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp b/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp index 421e652..46ae935 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp +++ b/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp @@ -20,12 +20,15 @@ uint32_t BitFileGetter::getType1() { uint32_t res = 0; int8_t to_get = type_1_size_; - while(true) + for(;;) { - uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; - res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); + //const uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; + //res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); + res |= (( ((current_data_ & 0x000000ff) >> minor_index_) & + ~((0xffffffff) << to_get)) + << (type_1_size_ - to_get)); - uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; + const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; to_get -= getted; if(to_get > 0) @@ -36,28 +39,29 @@ uint32_t BitFileGetter::getType1() else { minor_index_ += getted; - if(minor_index_ >= 8) + if(minor_index_ > 7) { minor_index_ = 0; current_data_ = data_[++major_index_]; } - break; + return res; } } - - return res; } uint32_t BitFileGetter::getType2() { uint32_t res = 0; int8_t to_get = type_2_size_; - while(true) + for(;;) { - uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; - res |= ((working_data & ~((0xffffffff) << to_get)) << (type_2_size_ - to_get)); + //const uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; + //res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); + res |= (( ((current_data_ & 0x000000ff) >> minor_index_) & + ~((0xffffffff) << to_get)) + << (type_2_size_ - to_get)); - uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; + const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; to_get -= getted; if(to_get > 0) @@ -68,28 +72,29 @@ uint32_t BitFileGetter::getType2() else { minor_index_ += getted; - if(minor_index_ >= 8) + if(minor_index_ > 7) { minor_index_ = 0; current_data_ = data_[++major_index_]; } - break; + return res; } } - - return res; } uint32_t BitFileGetter::getType3() { uint32_t res = 0; int8_t to_get = type_3_size_; - while(true) + for(;;) { - uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; - res |= ((working_data & ~((0xffffffff) << to_get)) << (type_3_size_ - to_get)); + //const uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; + //res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); + res |= (( ((current_data_ & 0x000000ff) >> minor_index_) & + ~((0xffffffff) << to_get)) + << (type_3_size_ - to_get)); - uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; + const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; to_get -= getted; if(to_get > 0) @@ -100,28 +105,29 @@ uint32_t BitFileGetter::getType3() else { minor_index_ += getted; - if(minor_index_ >= 8) + if(minor_index_ > 7) { minor_index_ = 0; current_data_ = data_[++major_index_]; } - break; + return res; } } - - return res; } uint32_t BitFileGetter::getType4() { uint32_t res = 0; int8_t to_get = type_4_size_; - while(true) + for(;;) { - uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; - res |= ((working_data & ~((0xffffffff) << to_get)) << (type_4_size_ - to_get)); + //const uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; + //res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); + res |= (( ((current_data_ & 0x000000ff) >> minor_index_) & + ~((0xffffffff) << to_get)) + << (type_4_size_ - to_get)); - uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; + const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; to_get -= getted; if(to_get > 0) @@ -132,28 +138,29 @@ uint32_t BitFileGetter::getType4() else { minor_index_ += getted; - if(minor_index_ >= 8) + if(minor_index_ > 7) { minor_index_ = 0; current_data_ = data_[++major_index_]; } - break; + return res; } } - - return res; } char BitFileGetter::getChar() { char res = 0; int8_t to_get = 7; - while(true) + for(;;) { - uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; - res |= ((working_data & ~((0xffffffff) << to_get)) << (7 - to_get)); + //const uint32_t working_data = (current_data_ & 0x000000ff) >> minor_index_; + //res |= ((working_data & ~((0xffffffff) << to_get)) << (type_1_size_ - to_get)); + res |= (( ((current_data_ & 0x000000ff) >> minor_index_) & + ~((0xffffffff) << to_get)) + << (7 - to_get)); - uint8_t getted = (minor_index_ + to_get >= 8) ? 8 - minor_index_ : to_get; + const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; to_get -= getted; if(to_get > 0) @@ -164,16 +171,14 @@ char BitFileGetter::getChar() else { minor_index_ += getted; - if(minor_index_ >= 8) + if(minor_index_ > 7) { minor_index_ = 0; current_data_ = data_[++major_index_]; } - break; + return res; } } - - return res; } bool BitFileGetter::getBit() diff --git a/src/core/archiving_compressing/compressing/LzUncompress.cpp b/src/core/archiving_compressing/compressing/LzUncompress.cpp index 99c8c4e..b10ad5f 100644 --- a/src/core/archiving_compressing/compressing/LzUncompress.cpp +++ b/src/core/archiving_compressing/compressing/LzUncompress.cpp @@ -7,26 +7,25 @@ namespace mementar { -LzUncompress::LzUncompress() : BinaryManager("mlz"), bit(0, 0, 8) +LzUncompress::LzUncompress() : BinaryManager("mlz") { - // la_size_ <= search_size_ - search_size_ = 0; - la_size_ = 0; } -void LzUncompress::uncompress(std::vector& data, std::string& out) +std::string LzUncompress::uncompress(const std::vector& data) { + std::string out; + BitFileGetter bit(0, 0, 8); bit.set(data); size_t offset = 0; - size_t length = 0; - auto out_file_size = toInteger({(uint8_t)bit.getType3(), (uint8_t)bit.getType3(), (uint8_t)bit.getType3(), (uint8_t)bit.getType3()}); + const auto out_file_size = toInteger({(uint8_t)bit.getType3(), (uint8_t)bit.getType3(), (uint8_t)bit.getType3(), (uint8_t)bit.getType3()}); + out.reserve(out_file_size); - search_size_ = toInteger({(uint8_t)bit.getType3(), (uint8_t)bit.getType3()}); + const size_t search_size_ = toInteger({(uint8_t)bit.getType3(), (uint8_t)bit.getType3()}); bit.setSize1(neededBitCount(search_size_)); - la_size_ = toInteger({(uint8_t)bit.getType3(), (uint8_t)bit.getType3()}); + const size_t la_size_ = toInteger({(uint8_t)bit.getType3(), (uint8_t)bit.getType3()}); bit.setSize2(neededBitCount(la_size_)); while(out.size() < out_file_size) @@ -34,12 +33,13 @@ void LzUncompress::uncompress(std::vector& data, std::string& out) if(bit.getBit()) { offset = bit.getType1(); - length = bit.getType2(); - out += out.substr(out.size() - offset, length); + out += out.substr(out.size() - offset, bit.getType2()); } else out.push_back(bit.getChar()); } + + return out; } int LzUncompress::neededBitCount(size_t max_value) diff --git a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp b/src/core/archiving_compressing/tests/perfs/huffman_out.cpp index e970d73..8fe7f6c 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp +++ b/src/core/archiving_compressing/tests/perfs/huffman_out.cpp @@ -20,10 +20,6 @@ using namespace std::chrono; float testHuffman(size_t nb, const std::string& input_file) { - std::ifstream t(input_file); - std::string in((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - high_resolution_clock::time_point t1 = high_resolution_clock::now(); for(size_t i = 0; i < nb; i++) diff --git a/src/core/archiving_compressing/tests/uncompress.cpp b/src/core/archiving_compressing/tests/uncompress.cpp index 60cec34..9842bfc 100644 --- a/src/core/archiving_compressing/tests/uncompress.cpp +++ b/src/core/archiving_compressing/tests/uncompress.cpp @@ -87,7 +87,7 @@ int main (int argc, char* argv[]) mementar::LzUncompress lz; std::vector data; if(lz.readBinaryFile(data, input_file)) - lz.uncompress(data, out); + out = lz.uncompress(data); } else if(code_type == huffman) { From a12d24704555de24ea3bfe9da3611b81b53cf43e Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 3 Apr 2020 11:09:25 +0200 Subject: [PATCH 30/95] [REFACT] lz decompression --- .../tests/perfs/lz_out.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/core/archiving_compressing/tests/perfs/lz_out.cpp diff --git a/src/core/archiving_compressing/tests/perfs/lz_out.cpp b/src/core/archiving_compressing/tests/perfs/lz_out.cpp new file mode 100644 index 0000000..b80bcd8 --- /dev/null +++ b/src/core/archiving_compressing/tests/perfs/lz_out.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +#include +#include /* srand, rand */ +#include /* time */ + +#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" + +using namespace std::chrono; + +float testLz(size_t nb, const std::string& input_file) +{ + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i++) + { + mementar::LzUncompress lz; + std::vector data; + std::string out; + if(lz.readBinaryFile(data, input_file)) + out = lz.uncompress(data); + + if(i == 0) + { + std::ofstream myfile; + myfile.open ("../tests_files/out/" + std::to_string(out.size()) + ".txt"); + myfile << out; + myfile.close(); + } + } + + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + + return time_span.count()*1000/nb; // return time span in ms +} + +int main (int argc, char* argv[]) +{ + const size_t nb = 10; + + float time_252 = testLz(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_252_1MB.mlz"); + float time_10 = testLz(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_10_9MB.mlz"); + float time_6 = testLz(nb, "/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/tests_files/test_6_5MB.mlz"); + + float mean = (time_252 + time_10 + time_6) / 3.0; + + std::cout << "252 = " << time_252 << std::endl; + std::cout << "10 = " << time_10 << std::endl; + std::cout << "6 = " << time_6 << std::endl; + std::cout << "mean = " << mean << std::endl; + + return 0; +} From 1372b3fe59030738337bec41058df5ac3ab3a826 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 3 Apr 2020 16:44:30 +0200 Subject: [PATCH 31/95] [REFACT] archiving --- .../archiving_compressing/archiving/Archive.h | 16 +++--- .../archiving_compressing/archiving/Header.h | 6 +-- .../binaryManagement/BinaryManager.h | 4 +- .../compressing/Huffman.h | 4 +- src/core/EpisodicTree/ArchivedLeaf.cpp | 3 +- .../CompressedLeafNodeSession.cpp | 3 +- .../archiving/Archive.cpp | 54 ++++++++++--------- .../archiving/Header.cpp | 11 ++-- .../compressing/Huffman.cpp | 13 +++-- .../archiving_compressing/tests/archive.cpp | 7 ++- .../archiving_compressing/tests/compress.cpp | 6 +-- .../tests/perfs/huffman_in.cpp | 8 +-- 12 files changed, 65 insertions(+), 70 deletions(-) diff --git a/include/mementar/core/archiving_compressing/archiving/Archive.h b/include/mementar/core/archiving_compressing/archiving/Archive.h index 2f05d4a..b0dfcfa 100644 --- a/include/mementar/core/archiving_compressing/archiving/Archive.h +++ b/include/mementar/core/archiving_compressing/archiving/Archive.h @@ -10,7 +10,7 @@ namespace mementar class Archive : public BinaryManager { public: - Archive(std::string& description, std::vector& files); + Archive(const std::string& description, const std::vector& files); Archive(const std::string& description, const Header& header); Archive(); @@ -19,19 +19,19 @@ class Archive : public BinaryManager return BinaryManager::readBinaryFile(data_, file_name); } - void load(std::vector& out); - void load(std::vector& out, std::vector& raw_datas); + std::vector load(); + std::vector load(const std::vector& raw_datas); - Header getHeader(std::vector& data); + Header getHeader(const std::vector& data); Header getHeader() { return getHeader(data_); } - std::string extractDescription(Header& head, std::vector& data); - std::string extractDescription(Header& head) + std::string extractDescription(const Header& head, const std::vector& data); + std::string extractDescription(const Header& head) { return extractDescription(head, data_); } - std::string extractFile(size_t index, Header& head, std::vector& data); - std::string extractFile(size_t index, Header& head) + std::string extractFile(size_t index, const Header& head, const std::vector& data); + std::string extractFile(size_t index, const Header& head) { return extractFile(index, head, data_); } diff --git a/include/mementar/core/archiving_compressing/archiving/Header.h b/include/mementar/core/archiving_compressing/archiving/Header.h index fed7bf7..baf4060 100644 --- a/include/mementar/core/archiving_compressing/archiving/Header.h +++ b/include/mementar/core/archiving_compressing/archiving/Header.h @@ -9,7 +9,7 @@ namespace mementar struct File_t { - File_t(std::string name = "", size_t offset = 0, size_t size = 0) + File_t(const std::string& name = "", size_t offset = 0, size_t size = 0) { path_ = name; name_ = name; @@ -35,9 +35,9 @@ class Header std::string toString(); - size_t endodedSize(); + size_t encodedSize(); void encode(std::vector& out); - void decode(std::vector& data); + void decode(const std::vector& data); }; } // namespace mementar diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h b/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h index 697c168..032b1d4 100644 --- a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h +++ b/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h @@ -28,8 +28,6 @@ class BinaryManager outfile.open(file_name + "." + extension_, std::ios::binary | std::ios::out); outfile.write(reinterpret_cast(data.data()), data.size()); outfile.close(); - - std::cout << "Saved into " << file_name << "." << extension_ << std::endl; } bool readBinaryFile(std::vector& data, const std::string& file_name) @@ -47,7 +45,7 @@ class BinaryManager std::string readBinaryFile(const std::string& file_name) { - std::ifstream infile(file_name, std::ios::binary | std::ios::ate); + std::ifstream infile(file_name, std::ios::binary); std::string res((std::istreambuf_iterator(infile)), std::istreambuf_iterator()); return res; diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman.h b/include/mementar/core/archiving_compressing/compressing/Huffman.h index ef42cd0..09276bb 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman.h +++ b/include/mementar/core/archiving_compressing/compressing/Huffman.h @@ -47,8 +47,8 @@ class Huffman : public BinaryManager Huffman(); void analyse(const std::string& data, std::size_t jobs = 1); void generateCode(); - void getTreeCode(std::vector& out); - void getDataCode(const std::string& in_data, std::vector& out); + std::vector getTreeCode(); + std::vector getDataCode(const std::string& in_data); size_t setTree(const std::vector& in); std::string getFile(const std::vector& data); diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/EpisodicTree/ArchivedLeaf.cpp index c3d90fb..59fadfd 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/EpisodicTree/ArchivedLeaf.cpp @@ -37,8 +37,7 @@ ArchivedLeaf::ArchivedLeaf(CompressedLeafNode* tree, size_t nb, const std::strin Archive arch(context, input_files); - std::vector data; - arch.load(data); + std::vector data = arch.load(); arch.saveToFile(data, directory_); diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp index 9c8c8ed..17e48be 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/EpisodicTree/CompressedLeafNodeSession.cpp @@ -45,8 +45,7 @@ CompressedLeafNodeSession::~CompressedLeafNodeSession() } } - std::vector data; - arch.load(data, raw_datas); + std::vector data = arch.load(raw_datas); arch.saveToFile(data, file_name_); diff --git a/src/core/archiving_compressing/archiving/Archive.cpp b/src/core/archiving_compressing/archiving/Archive.cpp index ef807fb..4a78a96 100644 --- a/src/core/archiving_compressing/archiving/Archive.cpp +++ b/src/core/archiving_compressing/archiving/Archive.cpp @@ -7,15 +7,15 @@ namespace mementar { -Archive::Archive(std::string& description, std::vector& files) : BinaryManager("mar") +Archive::Archive(const std::string& description, const std::vector& files) : BinaryManager("mar") { description_ = description; header_.description_file_ = File_t("description"); for(const auto& file : files) - header_.input_files_.push_back(File_t(file)); + header_.input_files_.emplace_back(file); //set header_ offset - size_t header_size = header_.endodedSize(); + size_t header_size = header_.encodedSize(); header_.description_file_.offset_ = header_size; for(auto& file : header_.input_files_) file.offset_ = header_size; @@ -28,7 +28,7 @@ Archive::Archive(const std::string& description, const Header& header) : BinaryM header_.input_files_ = header.input_files_; //set header_ offset - size_t header_size = header_.endodedSize(); + size_t header_size = header_.encodedSize(); header_.description_file_.offset_ = header_size; for(auto& file : header_.input_files_) file.offset_ = header_size; @@ -37,35 +37,35 @@ Archive::Archive(const std::string& description, const Header& header) : BinaryM Archive::Archive() : BinaryManager("mar") {} -void Archive::load(std::vector& out) +std::vector Archive::load() { size_t offset = 0; LzCompress lz_comp; - std::vector out_vect = lz_comp.compress(description_); - out.insert(out.end(), out_vect.begin(), out_vect.end()); - offset += out_vect.size(); - header_.description_file_.size_ = out_vect.size(); - out_vect = std::vector(); + std::vector out = lz_comp.compress(description_); + offset += out.size(); + header_.description_file_.size_ = out.size(); std::vector input_files; Huffman huff; for(const auto& file : header_.input_files_) { auto str = huff.readBinaryFile(file.path_); + if(str.size() == 0) + std::cout << "can not read file: \'" << file.path_ << "\'" << std::endl; input_files.push_back(str); huff.analyse(str); } huff.generateCode(); - huff.getTreeCode(out_vect); + std::vector out_vect = huff.getTreeCode(); out.insert(out.end(), out_vect.begin(), out_vect.end()); offset += out_vect.size(); out_vect = std::vector(); for(size_t i = 0; i < input_files.size(); i++) { - huff.getDataCode(input_files[i], out_vect); + out_vect = huff.getDataCode(input_files[i]); out.insert(out.end(), out_vect.begin(), out_vect.end()); header_.input_files_[i].offset_ += offset; offset += out_vect.size(); @@ -75,38 +75,38 @@ void Archive::load(std::vector& out) header_.encode(out_vect); out.insert(out.begin(), out_vect.begin(), out_vect.end()); + + return out; } -void Archive::load(std::vector& out, std::vector& raw_datas) +std::vector Archive::load(const std::vector& raw_datas) { if(raw_datas.size() != header_.input_files_.size()) { std::cout << "ERROR" <(); } size_t offset = 0; LzCompress lz_comp; - std::vector out_vect = lz_comp.compress(description_); - out.insert(out.end(), out_vect.begin(), out_vect.end()); - offset += out_vect.size(); - header_.description_file_.size_ = out_vect.size(); - out_vect = std::vector(); + std::vector out = lz_comp.compress(description_); + offset += out.size(); + header_.description_file_.size_ = out.size(); Huffman huff; - for(auto& raw_data : raw_datas) + for(const auto& raw_data : raw_datas) huff.analyse(raw_data); huff.generateCode(); - huff.getTreeCode(out_vect); + std::vector out_vect = huff.getTreeCode(); out.insert(out.end(), out_vect.begin(), out_vect.end()); offset += out_vect.size(); - out_vect = std::vector(); + out_vect = std::vector(); for(size_t i = 0; i < raw_datas.size(); i++) { - huff.getDataCode(raw_datas[i], out_vect); + out_vect = huff.getDataCode(raw_datas[i]); out.insert(out.end(), out_vect.begin(), out_vect.end()); header_.input_files_[i].offset_ += offset; offset += out_vect.size(); @@ -116,22 +116,24 @@ void Archive::load(std::vector& out, std::vector& raw_datas) header_.encode(out_vect); out.insert(out.begin(), out_vect.begin(), out_vect.end()); + + return out; } -Header Archive::getHeader(std::vector& data) +Header Archive::getHeader(const std::vector& data) { header_.decode(data); return header_; } -std::string Archive::extractDescription(Header& head, std::vector& data) +std::string Archive::extractDescription(const Header& head, const std::vector& data) { LzUncompress lz; std::vector tmp_data(data.begin() + head.description_file_.offset_, data.begin() + head.description_file_.offset_ + head.description_file_.size_); return lz.uncompress(tmp_data); } -std::string Archive::extractFile(size_t index, Header& head, std::vector& data) +std::string Archive::extractFile(size_t index, const Header& head, const std::vector& data) { std::string out; Huffman huff; diff --git a/src/core/archiving_compressing/archiving/Header.cpp b/src/core/archiving_compressing/archiving/Header.cpp index 8e61f47..95efafd 100644 --- a/src/core/archiving_compressing/archiving/Header.cpp +++ b/src/core/archiving_compressing/archiving/Header.cpp @@ -31,7 +31,7 @@ std::string Header::toString() return res; } -size_t Header::endodedSize() +size_t Header::encodedSize() { size_t nb_bit = 0; nb_bit += 8 + description_file_.name_.size()*7 + 31 + 31; @@ -48,7 +48,7 @@ void Header::encode(std::vector& out) { BitFileGenerator bit(31, 16, 8); bit.writeType3(description_file_.name_.size()); - for(auto c : description_file_.name_) + for(const auto& c : description_file_.name_) bit.writeChar(c); bit.writeType1(description_file_.offset_); bit.writeType1(description_file_.size_); @@ -57,18 +57,17 @@ void Header::encode(std::vector& out) for(const auto& file : input_files_) { bit.writeType3(file.name_.size()); - for(auto c : file.name_) + for(const auto& c : file.name_) bit.writeChar(c); bit.writeType1(file.offset_); bit.writeType1(file.size_); } - std::vector tmp; - bit.get(tmp); + std::vector tmp = bit.get(); out.insert(out.end(), tmp.begin(), tmp.end()); } -void Header::decode(std::vector& data) +void Header::decode(const std::vector& data) { BitFileGetter bit(31, 16, 8); bit.set(data); diff --git a/src/core/archiving_compressing/compressing/Huffman.cpp b/src/core/archiving_compressing/compressing/Huffman.cpp index c2cdeb8..ddd925a 100644 --- a/src/core/archiving_compressing/compressing/Huffman.cpp +++ b/src/core/archiving_compressing/compressing/Huffman.cpp @@ -86,12 +86,13 @@ namespace mementar { void Huffman::generateCode() { auto root_node = generateTree(); + std::cout << "generateTree" << std::endl; nodes_[root_node].code.size_ = 0; nodes_[root_node].code.value_ = 0; generateCode(root_node); } - void Huffman::getTreeCode(std::vector& out) + std::vector Huffman::getTreeCode() { BitFileGenerator bit(TREE_CHAR_SIZE, TREE_VALUE_SIZE, TREE_VALUE_SIZE_SIZE); size_t valid_leaf = 0; @@ -112,12 +113,11 @@ namespace mementar { bit.writeType3(nodes_[i].code.value_); } } - std::vector tmp; - bit.get(tmp); - out.insert(out.end(), tmp.begin(), tmp.end()); + + return bit.get(); } - void Huffman::getDataCode(const std::string& in_data, std::vector& out) + std::vector Huffman::getDataCode(const std::string& in_data) { BitFileGenerator bit(8); bit.resize(in_data.size()); @@ -130,8 +130,7 @@ namespace mementar { for(const std::uint8_t& c : in_data) bit.writeNReverse(nodes_[c].code.size_, nodes_[c].code.value_); - std::vector tmp = bit.get(); - out.insert(out.end(), tmp.begin(), tmp.end()); + return bit.get(); } size_t Huffman::setTree(const std::vector& in) diff --git a/src/core/archiving_compressing/tests/archive.cpp b/src/core/archiving_compressing/tests/archive.cpp index d42e373..8007589 100644 --- a/src/core/archiving_compressing/tests/archive.cpp +++ b/src/core/archiving_compressing/tests/archive.cpp @@ -68,6 +68,7 @@ int main (int argc, char* argv[]) std::cout << "Available options are :" << std::endl; std::cout << "\t-i : input file" << std::endl; std::cout << "\t-o : output file (or output path for extraction mode)" << std::endl; + std::cout << "\t-d : description file for archiving mode" << std::endl; std::cout << "\t-l : list the contents of the input archive" << std::endl; std::cout << "\t-x : extract the contents of the input archive" << std::endl; return 0; @@ -86,7 +87,7 @@ int main (int argc, char* argv[]) } if((description_file == "") && (action == act_archive)) { - std::cout << "specify a description_file file with -o" << std::endl; + std::cout << "specify a description_file file with -d" << std::endl; return -1; } @@ -100,9 +101,7 @@ int main (int argc, char* argv[]) std::istreambuf_iterator()); mementar::Archive arch(in, input_files); - std::vector data; - arch.load(data); - + std::vector data = arch.load(); arch.saveToFile(data, output_file); } else if(action == act_extract) diff --git a/src/core/archiving_compressing/tests/compress.cpp b/src/core/archiving_compressing/tests/compress.cpp index 3a26f48..310625f 100644 --- a/src/core/archiving_compressing/tests/compress.cpp +++ b/src/core/archiving_compressing/tests/compress.cpp @@ -101,9 +101,9 @@ int main (int argc, char* argv[]) mementar::Huffman huff; huff.analyse(in); huff.generateCode(); - std::vector out_vect; - huff.getTreeCode(out_vect); - huff.getDataCode(in, out_vect); + std::vector out_vect = huff.getTreeCode(); + std::vector tmp = huff.getDataCode(in); + out_vect.insert(out_vect.end(), tmp.begin(), tmp.end()); huff.displayCompressionRate(in.size(), out_vect.size()); huff.saveToFile(out_vect, output_file); diff --git a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp index f35327d..d0d9be3 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp +++ b/src/core/archiving_compressing/tests/perfs/huffman_in.cpp @@ -54,14 +54,14 @@ float testHuffman(size_t nb, const std::string& input_file) mementar::Huffman huff; huff.analyse(in); huff.generateCode(); - std::vector out_vect; - huff.getTreeCode(out_vect); - huff.getDataCode(in, out_vect); + std::vector out_vect = huff.getTreeCode(); + std::vector tmp = huff.getDataCode(in); + out_vect.insert(out_vect.end(), tmp.begin(), tmp.end()); if(i == 0) { huff.displayCompressionRate(in.size(), out_vect.size()); - huff.saveToFile(out_vect, std::to_string(in.size())); + huff.saveToFile(out_vect, "../tests_files/out/" + std::to_string(in.size())); } } From 9ecbf1b427bbd818229d61421dc3e61fe741a787 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 6 Apr 2020 12:27:04 +0200 Subject: [PATCH 32/95] [REFACT] Btree --- include/mementar/core/Btree/Btree.h | 6 ++- include/mementar/core/Btree/BtreeLeafNode.h | 17 ++++---- include/mementar/core/Btree/BtreeNode.h | 43 ++++++++++----------- src/core/Btree/tests/btree_test.cpp | 20 +++++----- src/core/Btree/tests/max_insertion.cpp | 21 ++++++++-- 5 files changed, 62 insertions(+), 45 deletions(-) diff --git a/include/mementar/core/Btree/Btree.h b/include/mementar/core/Btree/Btree.h index 773775d..32c5838 100644 --- a/include/mementar/core/Btree/Btree.h +++ b/include/mementar/core/Btree/Btree.h @@ -103,7 +103,11 @@ bool Btree::remove(const Tdata& data) { nb_data_--; if(root_ != nullptr) - return root_->remove(data); + if(root_->remove(data)) + { + nb_data_--; + return true; + } return false; } diff --git a/include/mementar/core/Btree/BtreeLeafNode.h b/include/mementar/core/Btree/BtreeLeafNode.h index cab1557..78d3044 100644 --- a/include/mementar/core/Btree/BtreeLeafNode.h +++ b/include/mementar/core/Btree/BtreeLeafNode.h @@ -41,14 +41,15 @@ BtreeLeaf* BtreeLeafNode::insert(Tdata* data) res = new BtreeLeaf(data); leafs_.push_back(res); res->setMother(this); + return res; } else { BtreeLeaf* last = nullptr; if(leafs_.size()) - last = leafs_[leafs_.size() - 1]; + last = leafs_.back(); - if(data->getStamp() > this->keys_[this->keys_.size() - 1]) + if(data->getStamp() > this->keys_.back()) { this->keys_.push_back(data->getStamp()); res = new BtreeLeaf(data); @@ -58,7 +59,7 @@ BtreeLeaf* BtreeLeafNode::insert(Tdata* data) res->prev_ = last; res->setMother(this); } - else if(this->keys_[this->keys_.size() - 1] == data->getStamp()) + else if(this->keys_.back() == data->getStamp()) { last->push_back(data); } @@ -145,7 +146,7 @@ BtreeLeaf* BtreeLeafNode::findNear(const Tkey& key) if(this->keys_[i] >= key) return leafs_[i]; } - return leafs_[leafs_.size() - 1]->next_; + return leafs_.back(); } template @@ -168,12 +169,12 @@ void BtreeLeafNode::split() size_t half_order = this->order_/2; for(size_t i = 0; i < half_order; i++) { - new_node->leafs_.insert(new_node->leafs_.begin(), leafs_[leafs_.size() - 1]); - leafs_.erase(leafs_.begin() + leafs_.size() - 1); + new_node->leafs_.insert(new_node->leafs_.begin(), leafs_.back()); + leafs_.pop_back(); new_node->leafs_[i]->setMother(new_node); - new_node->keys_.insert(new_node->keys_.begin(), this->keys_[this->keys_.size() - 1]); - this->keys_.erase(this->keys_.begin() + this->keys_.size() - 1); + new_node->keys_.insert(new_node->keys_.begin(), this->keys_.back()); + this->keys_.pop_back(); } if(this->mother_ != nullptr) diff --git a/include/mementar/core/Btree/BtreeNode.h b/include/mementar/core/Btree/BtreeNode.h index cc80661..38493ff 100644 --- a/include/mementar/core/Btree/BtreeNode.h +++ b/include/mementar/core/Btree/BtreeNode.h @@ -55,14 +55,12 @@ class BtreeNode template BtreeLeaf* BtreeNode::insert(Tdata* data) { - size_t index = childs_.size() - 1; - for(size_t i = 0; i < this->keys_.size(); i++) + auto stamp = data->getStamp(); + size_t index; + for(index = 0; index < this->keys_.size(); index++) { - if(data->getStamp() < this->keys_[i]) - { - index = i; + if(stamp < this->keys_[index]) break; - } } return childs_[index]->insert(data); } @@ -74,6 +72,7 @@ void BtreeNode::insert(BtreeNode* new_node, const Tkey& { childs_.push_back(new_node); new_node->setMother(this); + return; } else { @@ -111,10 +110,11 @@ void BtreeNode::insert(BtreeNode* new_node, const Tkey& template bool BtreeNode::remove( const Tdata& data) { + auto stamp = data.getStamp(); size_t index = this->keys_.size(); for(size_t i = 0; i < this->keys_.size(); i++) { - if(this->keys_[i] > data.getStamp()) + if(this->keys_[i] > stamp) { index = i; break; @@ -145,7 +145,6 @@ BtreeLeaf* BtreeNode::findNear(const Tkey& key) if(this->keys_[i] > key) return this->childs_[i]->findNear(key); } - return this->childs_[this->keys_.size()]->findNear(key); } @@ -166,33 +165,33 @@ void BtreeNode::split() { BtreeNode* new_node = new BtreeNode(order_); - size_t half_order = order_/2; + size_t half_order = order_/2 - 1; for(size_t i = 0; i < half_order; i++) { - new_node->childs_.insert(new_node->childs_.begin(), childs_[childs_.size() - 1]); - childs_.erase(childs_.begin() + childs_.size() - 1); + new_node->childs_.insert(new_node->childs_.begin(), childs_.back()); + childs_.pop_back(); new_node->childs_[i]->setMother(new_node); - } - half_order = half_order - 1; - for(size_t i = 0; i < half_order; i++) - { - new_node->keys_.insert(new_node->keys_.begin(), keys_[keys_.size() - 1]); - keys_.erase(keys_.begin() + keys_.size() - 1); + new_node->keys_.insert(new_node->keys_.begin(), keys_.back()); + keys_.pop_back(); } + new_node->childs_.insert(new_node->childs_.begin(), childs_.back()); + childs_.pop_back(); + new_node->childs_[half_order]->setMother(new_node); + if(mother_ != nullptr) { - mother_->insert(new_node, keys_[keys_.size() - 1]); - keys_.erase(keys_.begin() + keys_.size() - 1); + mother_->insert(new_node, keys_.back()); + keys_.pop_back(); } else { BtreeNode* new_mother = new BtreeNode(order_); new_mother->setLevel(this->level_ + 1); - new_mother->insert(this, keys_[keys_.size() - 1]); - new_mother->insert(new_node, keys_[keys_.size() - 1]); - keys_.erase(keys_.begin() + keys_.size() - 1); + new_mother->insert(this, keys_.back()); + new_mother->insert(new_node, keys_.back()); + keys_.pop_back(); } } diff --git a/src/core/Btree/tests/btree_test.cpp b/src/core/Btree/tests/btree_test.cpp index 39ecdc9..b986781 100644 --- a/src/core/Btree/tests/btree_test.cpp +++ b/src/core/Btree/tests/btree_test.cpp @@ -41,7 +41,7 @@ int main() else std::cout << "sup" << std::endl; - std::vector sizes = {1234}; + std::vector sizes = {50}; std::vector times; for(auto nb : sizes) { @@ -54,20 +54,20 @@ int main() //tree.display(); auto res = tree.find(10); - if(res) std::cout << res->getKey() << std::endl; + if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; res = tree.find(28); - if(res) std::cout << res->getKey() << std::endl; + if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; res = tree.find(74); - if(res) std::cout << res->getKey() << std::endl; + if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; res = tree.find(53); - if(res) std::cout << res->getKey() << std::endl; - res = tree.findNear(49); - if(res) std::cout << res->getKey() << std::endl; + if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; + res = tree.findNear(59); + if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; res = tree.getFirst(); - if(res) std::cout << res->getKey() << std::endl; + if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; - tree.remove(stampedInt(40,40)); - tree.insert(new stampedInt(40,41)); + tree.remove(stampedInt(49,49)); + tree.insert(new stampedInt(50,0)); tree.display(); std::cout << "estimation = " << tree.estimateMinLeaves() << std::endl; diff --git a/src/core/Btree/tests/max_insertion.cpp b/src/core/Btree/tests/max_insertion.cpp index a54275c..e8144f9 100644 --- a/src/core/Btree/tests/max_insertion.cpp +++ b/src/core/Btree/tests/max_insertion.cpp @@ -33,18 +33,31 @@ class stampedInt : public mementar::StampedData int main() { - size_t nb = 349526; + //size_t nb = 1000000; + //size_t nb = 2000000; + size_t nb = 10000000; high_resolution_clock::time_point t1 = high_resolution_clock::now(); mementar::Btree tree(5); - for(size_t i = 0; true; i++) - if(tree.insert(new stampedInt(i, i)) >= nb) + for(size_t i = 0; true; i+=2) + if(tree.insert(new stampedInt(i, i)) >= nb/2) break; high_resolution_clock::time_point t2 = high_resolution_clock::now(); duration time_span = duration_cast>(t2 - t1); - std::cout << "took " << time_span.count() << std::endl; + std::cout << "took " << time_span.count()*1000 << " for " << nb/2 << std::endl; + + /**********************/ + + t1 = high_resolution_clock::now(); + for(size_t i = 1; true; i+=2) + if(tree.insert(new stampedInt(i, i)) >= nb) + break; + + t2 = high_resolution_clock::now(); + time_span = duration_cast>(t2 - t1); + std::cout << "took " << time_span.count()*1000 << " for " << nb/2 << std::endl; //tree.display(); std::cout << "level = " << tree.estimateMaxLevel(nb) << ">=" << tree.getCurrentLevel() << std::endl; From 86e45bec38ac34295b63e7eda1f998731584fe35 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jun 2020 17:41:42 +0200 Subject: [PATCH 33/95] [ADD] EllNode and EllElement --- CMakeLists.txt | 2 + .../memGraphs/Branchs/ContextualizedEvent.h | 11 +- include/mementar/core/memGraphs/Btree/Btree.h | 5 +- .../mementar/core/memGraphs/Btree/BtreeLeaf.h | 2 +- .../core/memGraphs/Btree/BtreeLeafNode.h | 6 +- .../mementar/core/memGraphs/Btree/BtreeNode.h | 2 +- .../memGraphs/DoublyLinkedList/DllCargoNode.h | 10 +- .../memGraphs/EventLinkedList/EllElement.h | 33 +++ .../core/memGraphs/EventLinkedList/EllNode.h | 41 +++ .../core/memGraphs/Graphs/EventGraph.h | 4 +- .../DoublyLinkedList/DllCargoNode.cpp | 7 +- .../memGraphs/EventLinkedList/EllElement.cpp | 11 + .../memGraphs/EventLinkedList/EllNode.cpp | 270 ++++++++++++++++++ src/test/graphs.cpp | 4 +- 14 files changed, 389 insertions(+), 19 deletions(-) create mode 100644 include/mementar/core/memGraphs/EventLinkedList/EllElement.h create mode 100644 include/mementar/core/memGraphs/EventLinkedList/EllNode.h create mode 100644 src/core/memGraphs/EventLinkedList/EllElement.cpp create mode 100644 src/core/memGraphs/EventLinkedList/EllNode.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c2f70aa..6a60827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,8 @@ add_library(mementar_memGraphs_lib src/core/memGraphs/Branchs/types/Action.cpp src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp + src/core/memGraphs/EventLinkedList/EllElement.cpp + src/core/memGraphs/EventLinkedList/EllNode.cpp src/core/memGraphs/Graphs/ActionGraph.cpp src/core/memGraphs/Graphs/EventGraph.cpp ) diff --git a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h index 1b7181a..2c7f16c 100644 --- a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h +++ b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h @@ -6,12 +6,13 @@ #include "mementar/core/memGraphs/Branchs/ValuedNode.h" #include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" +#include "mementar/core/memGraphs/EventLinkedList/EllElement.h" #include namespace mementar { -class ContextualizedEvent : public Event, public ValuedNode, public DllLinkedElement +class ContextualizedEvent : public Event, public ValuedNode, public EllElement { public: ContextualizedEvent(const std::string& id, const Event& other, Action* action = nullptr) : Event(other), ValuedNode(id) @@ -43,7 +44,13 @@ class ContextualizedEvent : public Event, public ValuedNode, public DllLinkedEle bool operator==(const DllLinkedElement* other) { - return this->operator==(static_cast(other)); + return this->Event::operator==(static_cast(other)); + } + + virtual bool isEventPart(const DllLinkedElement* other) + { + return ( (subject_ == static_cast(other)->subject_) && + (predicat_ == static_cast(other)->predicat_)); } }; diff --git a/include/mementar/core/memGraphs/Btree/Btree.h b/include/mementar/core/memGraphs/Btree/Btree.h index 472f85c..265160f 100644 --- a/include/mementar/core/memGraphs/Btree/Btree.h +++ b/include/mementar/core/memGraphs/Btree/Btree.h @@ -16,7 +16,7 @@ namespace mementar template> class Btree { - static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); + //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); public: Btree(size_t order = 10) { @@ -146,9 +146,8 @@ void Btree::display(int count) std::cout << "******" << std::endl; while((tmp != nullptr) && ((cpt < count) || (count == -1))) { - std::vector datas = tmp->getData(); std::cout << tmp->getKey() << " => "; - for(auto data : datas) + for(auto data : tmp->getData()) std::cout << data << " : "; std::cout << std::endl; tmp = static_cast*>(tmp->getPreviousNode()); diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeaf.h b/include/mementar/core/memGraphs/Btree/BtreeLeaf.h index fb6e6f6..8cf2061 100644 --- a/include/mementar/core/memGraphs/Btree/BtreeLeaf.h +++ b/include/mementar/core/memGraphs/Btree/BtreeLeaf.h @@ -14,7 +14,7 @@ class BtreeLeafNode; template> class BtreeLeaf : public Tnode { - static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); + //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); public: BtreeLeaf(const Tkey& key, const Tdata& data) : Tnode(data) { diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h b/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h index b90a595..511ffab 100644 --- a/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h +++ b/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h @@ -10,7 +10,7 @@ namespace mementar template class BtreeLeafNode : public BtreeNode { - static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); + //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); public: BtreeLeafNode(size_t order = 10) : BtreeNode(order) {} @@ -198,9 +198,9 @@ void BtreeLeafNode::display(size_t depth) { for(size_t j = 0; j < depth; j++) std::cout << "\t"; - std::vector datas = leafs_[i]->getData(); + //std::vector datas = ; std::cout << this->keys_[i] << " => "; - for(auto data : datas) + for(auto data : leafs_[i]->getData()) std::cout << data << " : "; std::cout << std::endl; } diff --git a/include/mementar/core/memGraphs/Btree/BtreeNode.h b/include/mementar/core/memGraphs/Btree/BtreeNode.h index 05c0a24..ba89da6 100644 --- a/include/mementar/core/memGraphs/Btree/BtreeNode.h +++ b/include/mementar/core/memGraphs/Btree/BtreeNode.h @@ -11,7 +11,7 @@ namespace mementar template class BtreeNode { - static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); + //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); public: BtreeNode(size_t order = 10) { diff --git a/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h b/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h index 706b2f2..f3cc38c 100644 --- a/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h +++ b/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h @@ -11,11 +11,13 @@ class DllCargoNode : public DllNode { public: DllCargoNode(DllLinkedElement* data); - ~DllCargoNode() {} + virtual ~DllCargoNode() {} - void push_back(DllLinkedElement* data); - void remove(DllLinkedElement* data); -private: + virtual void push_back(DllLinkedElement* data); + virtual void remove(DllLinkedElement* data); + +protected: + void unlinkDll(size_t i); }; } // namespace mementar diff --git a/include/mementar/core/memGraphs/EventLinkedList/EllElement.h b/include/mementar/core/memGraphs/EventLinkedList/EllElement.h new file mode 100644 index 0000000..a702d68 --- /dev/null +++ b/include/mementar/core/memGraphs/EventLinkedList/EllElement.h @@ -0,0 +1,33 @@ +#ifndef MEMENTAR_ELLELEMENT_H +#define MEMENTAR_ELLELEMENT_H + +#include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" +#include "mementar/core/memGraphs/EventLinkedList/EllNode.h" + +namespace mementar { + +class EllElement : public DllLinkedElement +{ + friend EllNode; +public: + EllElement(); + ~EllElement() {} + + EllElement* getPreviousEllElement() { return prev_elem_; } + EllElement* getNextEllElement() { return next_elem_; } + + virtual bool operator==(const DllLinkedElement*) = 0; + virtual bool isEventPart(const DllLinkedElement* other) = 0; + virtual void print(std::ostream& os) const { os << this; } + +private: + EllElement* prev_elem_; + EllElement* next_elem_; + + std::vector to_link_prev; + std::vector to_link_next; +}; + +} // namespace mementar + +#endif // MEMENTAR_ELLELEMENT_H diff --git a/include/mementar/core/memGraphs/EventLinkedList/EllNode.h b/include/mementar/core/memGraphs/EventLinkedList/EllNode.h new file mode 100644 index 0000000..70b3619 --- /dev/null +++ b/include/mementar/core/memGraphs/EventLinkedList/EllNode.h @@ -0,0 +1,41 @@ +#ifndef MEMENTAR_ELLNODE_H +#define MEMENTAR_ELLNODE_H + +#include "mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h" + +#include + +namespace mementar { + +class EllElement; + +class EllNode : public DllCargoNode +{ +public: + EllNode(EllElement* data); + ~EllNode() {} + + void push_back(EllElement* data); + void remove(EllElement* data); +private: + + void link(EllElement* data); + + EllElement* getPrev(EllElement* data); + std::vector getPrevs(EllElement* data); + + EllElement* getNext(EllElement* data); + std::vector getNexts(EllElement* data); + + void linkPrev(EllElement* current, EllElement* prev, EllElement* next); + void linkNext(EllElement* current, EllElement* next, EllElement* prev); + + void unlink(EllElement* current_data); + + void unlinkPrev(EllElement* current, std::vector prev, EllElement* next); + void unlinkNext(EllElement* current, std::vector next, EllElement* prev); +}; + +} // namespace mementar + +#endif // MEMENTAR_ELLNODE_H diff --git a/include/mementar/core/memGraphs/Graphs/EventGraph.h b/include/mementar/core/memGraphs/Graphs/EventGraph.h index 9f5e7c5..e09a0ae 100644 --- a/include/mementar/core/memGraphs/Graphs/EventGraph.h +++ b/include/mementar/core/memGraphs/Graphs/EventGraph.h @@ -28,11 +28,11 @@ class EventGraph : public Graph return all_events_; } - Btree* getTimeline() { return &timeline; } + Btree* getTimeline() { return &timeline; } private: std::vector all_events_; - Btree timeline; + Btree timeline; }; } // namespace mementar diff --git a/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp b/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp index b225209..c9a22b8 100644 --- a/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp +++ b/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp @@ -24,7 +24,7 @@ void DllCargoNode::remove(DllLinkedElement* data) { if(payload_[i]->operator==(data)) { - payload_[i]->dll_node_ = nullptr; + unlinkDll(i); payload_.erase(payload_.begin() + i); } else @@ -32,4 +32,9 @@ void DllCargoNode::remove(DllLinkedElement* data) } } +void DllCargoNode::unlinkDll(size_t i) +{ + payload_[i]->dll_node_ = nullptr; +} + } // namespace mementar diff --git a/src/core/memGraphs/EventLinkedList/EllElement.cpp b/src/core/memGraphs/EventLinkedList/EllElement.cpp new file mode 100644 index 0000000..0f1f5fe --- /dev/null +++ b/src/core/memGraphs/EventLinkedList/EllElement.cpp @@ -0,0 +1,11 @@ +#include "mementar/core/memGraphs/EventLinkedList/EllElement.h" + +namespace mementar { + +EllElement::EllElement() +{ + prev_elem_ = nullptr; + next_elem_ = nullptr; +} + +} diff --git a/src/core/memGraphs/EventLinkedList/EllNode.cpp b/src/core/memGraphs/EventLinkedList/EllNode.cpp new file mode 100644 index 0000000..17ac98f --- /dev/null +++ b/src/core/memGraphs/EventLinkedList/EllNode.cpp @@ -0,0 +1,270 @@ +#include "mementar/core/memGraphs/EventLinkedList/EllNode.h" + +#include "mementar/core/memGraphs/EventLinkedList/EllElement.h" + +namespace mementar { + +EllNode::EllNode(EllElement* data) : DllCargoNode(data) +{ + std::cout << "--->EllNode " << data << std::endl; + link(data); +} + +void EllNode::push_back(EllElement* data) +{ + std::cout << "--->push_back " << data << std::endl; + DllCargoNode::push_back(data); + link(data); +} + +void EllNode::remove(EllElement* data) +{ + for(size_t i = 0; i < payload_.size();) + { + if(payload_[i]->operator==(data)) + { + unlinkDll(i); + + unlink(dynamic_cast(payload_[i])); + + payload_.erase(payload_.begin() + i); + } + else + i++; + } +} + +void EllNode::link(EllElement* data) +{ + auto next = getNext(data); + auto prev = getPrev(data); + + if(prev != nullptr) std::cout << prev; else std::cout << "null"; + std::cout << " : "; + if(next != nullptr) std::cout << next; else std::cout << "null"; + std::cout << std::endl; + + linkPrev(data, prev, next); + linkNext(data, next, prev); +} + +EllElement* EllNode::getPrev(EllElement* data) +{ + EllElement* res = nullptr; + + DllCargoNode* prev_node = dynamic_cast(data->getPreviousDllNode()); + while(prev_node != nullptr) + { + std::cout << "prev has " << prev_node->getData().size() << " data" << std::endl; + for(auto ld : prev_node->getData()) + { + std::cout << "test " << data << " with " << ld << std::endl; + if(data->isEventPart(ld)) + return dynamic_cast(ld); + } + prev_node = dynamic_cast(prev_node->getPreviousNode()); + } + + return res; +} + +std::vector EllNode::getPrevs(EllElement* data) +{ + std::vector res; + bool end = false; + + DllCargoNode* prev_node = dynamic_cast(data->getPreviousDllNode()); + if(prev_node == nullptr) + end = true; + + while(!end) + { + for(auto ld : prev_node->getData()) + { + if(data->isEventPart(ld)) + { + res.push_back(dynamic_cast(ld)); + if(dynamic_cast(ld)->prev_elem_->next_elem_ == ld) + end = true; + break; + } + } + + prev_node = dynamic_cast(prev_node->getPreviousNode()); + if(prev_node == nullptr) + end = true; + } + + return res; +} + +EllElement* EllNode::getNext(EllElement* data) +{ + EllElement* res = nullptr; + + DllCargoNode* next_node = dynamic_cast(data->getNextDllNode()); + while(next_node != nullptr) + { + for(auto ld : next_node->getData()) + { + if(data->isEventPart(ld)) + return dynamic_cast(ld); + } + next_node = dynamic_cast(next_node->getNextNode()); + } + + return res; +} + +std::vector EllNode::getNexts(EllElement* data) +{ + std::vector res; + bool end = false; + + DllCargoNode* next_node = dynamic_cast(data->getNextDllNode()); + if(next_node == nullptr) + end = true; + + while(!end) + { + for(auto ld : next_node->getData()) + { + if(data->isEventPart(ld)) + { + res.push_back(dynamic_cast(ld)); + if(dynamic_cast(ld)->next_elem_->prev_elem_ == ld) + end = true; + break; + } + } + + next_node = dynamic_cast(next_node->getNextNode()); + if(next_node == nullptr) + end = true; + } + + return res; +} + +void EllNode::linkPrev(EllElement* current, EllElement* prev, EllElement* next) +{ + if(prev == nullptr) + return; + + if(current->operator==(prev)) + { + if(next == nullptr) + { + current->to_link_next = prev->to_link_next; + prev->to_link_next.clear(); + current->to_link_next.push_back(prev); + } + current->prev_elem_ = prev->prev_elem_; + } + else + { + current->prev_elem_ = prev; + prev->next_elem_ = current; + if(prev->to_link_next.size()) + { + for(auto d : prev->to_link_next) + d->next_elem_ = current; + prev->to_link_next.clear(); + } + } +} + +void EllNode::linkNext(EllElement* current, EllElement* next, EllElement* prev) +{ + if(next == nullptr) + return; + + if(current->operator==(next)) + { + if(prev == nullptr) + { + current->to_link_prev = next->to_link_prev; + next->to_link_prev.clear(); + current->to_link_prev.push_back(next); + } + current->next_elem_ = next->next_elem_; + } + else + { + current->next_elem_ = next; + next->prev_elem_ = current; + if(next->to_link_prev.size()) + { + for(auto d : next->to_link_prev) + d->prev_elem_ = current; + next->to_link_prev.clear(); + } + } +} + +void EllNode::unlink(EllElement* current_data) +{ + std::vector prev = getPrevs(current_data); + std::vector next = getNexts(current_data); + + unlinkPrev(current_data, prev, next.size() ? next[0] : nullptr); + unlinkNext(current_data, next, prev.size() ? prev[0] : nullptr); +} + +void EllNode::unlinkPrev(EllElement* current, std::vector prev, EllElement* next) +{ + if(prev.size()) + { + if(!current->operator==(prev[0])) + { + if(!current->operator==(next)) + { + for(auto p : prev) + p->next_elem_ = current->next_elem_; + } + else + { + for(auto p : prev) + p->next_elem_ = next; + } + } + } + else if(current->to_link_prev.size()) + { + if(current->operator==(next)) + { + next->to_link_prev = std::move(current->to_link_prev); + next->to_link_prev.pop_back(); + } + } +} + +void EllNode::unlinkNext(EllElement* current, std::vector next, EllElement* prev) +{ + if(next.size()) + { + if(!current->operator==(next[0])) + { + if(!current->operator==(prev)) + { + for(auto n : next) + n->prev_elem_ = current->prev_elem_; + } + else + { + for(auto n : next) + n->prev_elem_ = prev; + } + } + } + else if(current->to_link_next.size()) + { + if(current->operator==(prev)) + { + prev->to_link_next = std::move(current->to_link_next); + prev->to_link_next.pop_back(); + } + } +} + +} // namespace mementar diff --git a/src/test/graphs.cpp b/src/test/graphs.cpp index e899b12..f995b02 100644 --- a/src/test/graphs.cpp +++ b/src/test/graphs.cpp @@ -52,8 +52,8 @@ int main() event_graph.add(new mementar::ContextualizedEvent("ce3", e1)); event_graph.add(new mementar::ContextualizedEvent("ce4", e2)); - for(size_t i = 10; i < 20; i++) - event_graph.add(new mementar::ContextualizedEvent("ce" + std::to_string(i), mementar::Event("cube|" + std::to_string(i) + "|isOn Table_2", i))); + //for(size_t i = 10; i < 20; i++) + //event_graph.add(new mementar::ContextualizedEvent("ce" + std::to_string(i), mementar::Event("cube" + std::to_string(i) + "|isOn|Table_3", i))); auto actions = action_graph.getSafe(); for(auto action : actions) From acc50667a7e304312854e6f07784aaea2849ed2d Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jun 2020 17:47:19 +0200 Subject: [PATCH 34/95] [FIX] BtreeLeaf init data after Dll link --- include/mementar/core/memGraphs/Btree/BtreeLeaf.h | 2 +- include/mementar/core/memGraphs/Btree/BtreeLeafNode.h | 9 ++++++--- .../core/memGraphs/DoublyLinkedList/DllCargoNode.h | 2 +- .../mementar/core/memGraphs/DoublyLinkedList/DllNode.h | 4 +--- .../mementar/core/memGraphs/EventLinkedList/EllNode.h | 2 +- src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp | 4 +--- src/core/memGraphs/EventLinkedList/EllNode.cpp | 6 +----- src/test/graphs.cpp | 4 ++-- 8 files changed, 14 insertions(+), 19 deletions(-) diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeaf.h b/include/mementar/core/memGraphs/Btree/BtreeLeaf.h index 8cf2061..251c175 100644 --- a/include/mementar/core/memGraphs/Btree/BtreeLeaf.h +++ b/include/mementar/core/memGraphs/Btree/BtreeLeaf.h @@ -16,7 +16,7 @@ class BtreeLeaf : public Tnode { //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); public: - BtreeLeaf(const Tkey& key, const Tdata& data) : Tnode(data) + BtreeLeaf(const Tkey& key) : Tnode() { mother_ = nullptr; diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h b/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h index 511ffab..36c31fa 100644 --- a/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h +++ b/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h @@ -39,9 +39,10 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& if(leafs_.size() == 0) { this->keys_.push_back(key); - res = new BtreeLeaf(key, data); + res = new BtreeLeaf(key); leafs_.push_back(res); res->setMother(this); + res->push_back(data); return res; } else @@ -53,12 +54,13 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& if(key > this->keys_.back()) { this->keys_.push_back(key); - res = new BtreeLeaf(key, data); + res = new BtreeLeaf(key); leafs_.push_back(res); res->setNextNode(last->getNextNode()); last->setNextNode(res); res->setPreviousNode(last); res->setMother(this); + res->push_back(data); } else if(this->keys_.back() == key) { @@ -76,7 +78,7 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& } else { - res = new BtreeLeaf(key, data); + res = new BtreeLeaf(key); // here last is the next node of res last = leafs_[i]; res->setNextNode(last); @@ -88,6 +90,7 @@ BtreeLeaf* BtreeLeafNode::insert(const Tkey& this->keys_.insert(this->keys_.begin() + i, key); this->leafs_.insert(this->leafs_.begin() + i, res); res->setMother(this); + res->push_back(data); } break; } diff --git a/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h b/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h index f3cc38c..ae5b2df 100644 --- a/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h +++ b/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h @@ -10,7 +10,7 @@ class DllLinkedElement; class DllCargoNode : public DllNode { public: - DllCargoNode(DllLinkedElement* data); + DllCargoNode(); virtual ~DllCargoNode() {} virtual void push_back(DllLinkedElement* data); diff --git a/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h b/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h index f001d56..b9e4f90 100644 --- a/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h +++ b/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h @@ -17,12 +17,10 @@ template using is_dllnode = decltype(is_dllnode_impl(std::declval())); public: - DllNode(const Tdata& data) + DllNode() { prev_ = nullptr; next_ = nullptr; - - push_back(data); } virtual ~DllNode() {} diff --git a/include/mementar/core/memGraphs/EventLinkedList/EllNode.h b/include/mementar/core/memGraphs/EventLinkedList/EllNode.h index 70b3619..c5461dc 100644 --- a/include/mementar/core/memGraphs/EventLinkedList/EllNode.h +++ b/include/mementar/core/memGraphs/EventLinkedList/EllNode.h @@ -12,7 +12,7 @@ class EllElement; class EllNode : public DllCargoNode { public: - EllNode(EllElement* data); + EllNode(); ~EllNode() {} void push_back(EllElement* data); diff --git a/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp b/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp index c9a22b8..ca27b0e 100644 --- a/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp +++ b/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp @@ -6,10 +6,8 @@ namespace mementar { -DllCargoNode::DllCargoNode(DllLinkedElement* data) : DllNode(data) +DllCargoNode::DllCargoNode() : DllNode() { - for(auto p : payload_) - p->dll_node_ = this; } void DllCargoNode::push_back(DllLinkedElement* data) diff --git a/src/core/memGraphs/EventLinkedList/EllNode.cpp b/src/core/memGraphs/EventLinkedList/EllNode.cpp index 17ac98f..1ff2425 100644 --- a/src/core/memGraphs/EventLinkedList/EllNode.cpp +++ b/src/core/memGraphs/EventLinkedList/EllNode.cpp @@ -4,10 +4,8 @@ namespace mementar { -EllNode::EllNode(EllElement* data) : DllCargoNode(data) +EllNode::EllNode() : DllCargoNode() { - std::cout << "--->EllNode " << data << std::endl; - link(data); } void EllNode::push_back(EllElement* data) @@ -55,10 +53,8 @@ EllElement* EllNode::getPrev(EllElement* data) DllCargoNode* prev_node = dynamic_cast(data->getPreviousDllNode()); while(prev_node != nullptr) { - std::cout << "prev has " << prev_node->getData().size() << " data" << std::endl; for(auto ld : prev_node->getData()) { - std::cout << "test " << data << " with " << ld << std::endl; if(data->isEventPart(ld)) return dynamic_cast(ld); } diff --git a/src/test/graphs.cpp b/src/test/graphs.cpp index f995b02..4de3366 100644 --- a/src/test/graphs.cpp +++ b/src/test/graphs.cpp @@ -52,8 +52,8 @@ int main() event_graph.add(new mementar::ContextualizedEvent("ce3", e1)); event_graph.add(new mementar::ContextualizedEvent("ce4", e2)); - //for(size_t i = 10; i < 20; i++) - //event_graph.add(new mementar::ContextualizedEvent("ce" + std::to_string(i), mementar::Event("cube" + std::to_string(i) + "|isOn|Table_3", i))); + for(size_t i = 10; i < 20; i++) + event_graph.add(new mementar::ContextualizedEvent("ce" + std::to_string(i), mementar::Event("cube" + std::to_string(i) + "|isOn|Table_3", i))); auto actions = action_graph.getSafe(); for(auto action : actions) From f6c60948bfc399cb771268549c87bf63c10a48e4 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 19 Jun 2020 17:55:34 +0200 Subject: [PATCH 35/95] [UPDATE] ell test --- src/core/memGraphs/EventLinkedList/EllNode.cpp | 6 ------ src/test/graphs.cpp | 13 +++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/memGraphs/EventLinkedList/EllNode.cpp b/src/core/memGraphs/EventLinkedList/EllNode.cpp index 1ff2425..bf4aa41 100644 --- a/src/core/memGraphs/EventLinkedList/EllNode.cpp +++ b/src/core/memGraphs/EventLinkedList/EllNode.cpp @@ -10,7 +10,6 @@ EllNode::EllNode() : DllCargoNode() void EllNode::push_back(EllElement* data) { - std::cout << "--->push_back " << data << std::endl; DllCargoNode::push_back(data); link(data); } @@ -37,11 +36,6 @@ void EllNode::link(EllElement* data) auto next = getNext(data); auto prev = getPrev(data); - if(prev != nullptr) std::cout << prev; else std::cout << "null"; - std::cout << " : "; - if(next != nullptr) std::cout << next; else std::cout << "null"; - std::cout << std::endl; - linkPrev(data, prev, next); linkNext(data, next, prev); } diff --git a/src/test/graphs.cpp b/src/test/graphs.cpp index 4de3366..9f48738 100644 --- a/src/test/graphs.cpp +++ b/src/test/graphs.cpp @@ -30,6 +30,15 @@ void print(mementar::ContextualizedEvent* evt) printNext( static_cast(nexts[0])); } +void printEventList(mementar::ContextualizedEvent* evt) +{ + if(evt) + { + std::cout << evt->toString() << std::endl; + printEventList(dynamic_cast(evt->getNextEllElement())); + } +} + int main() { mementar::EventGraph event_graph; @@ -70,5 +79,9 @@ int main() auto first_evt = event_graph.findBranch("pick_1_start"); print(first_evt); + std::cout << "********" << std::endl; + auto cube12_ison_evt = event_graph.findBranch("ce3"); + printEventList(cube12_ison_evt); + return 0; } From 9c8e2f10bf157810d4320bdf0f3636c75e7f8c0d Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 22 Jun 2020 09:23:53 +0200 Subject: [PATCH 36/95] [REMOVE] unused linked events --- include/mementar/core/Data/LinkedFact.h | 42 --- .../mementar/core/LinkedBtree/LinkedBtree.h | 52 --- .../core/LinkedBtree/LinkedBtreeLeafNode.h | 346 ------------------ 3 files changed, 440 deletions(-) delete mode 100644 include/mementar/core/Data/LinkedFact.h delete mode 100644 include/mementar/core/LinkedBtree/LinkedBtree.h delete mode 100644 include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h diff --git a/include/mementar/core/Data/LinkedFact.h b/include/mementar/core/Data/LinkedFact.h deleted file mode 100644 index 5801309..0000000 --- a/include/mementar/core/Data/LinkedFact.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef MEMENTAR_LINKEDFACT_H -#define MEMENTAR_LINKEDFACT_H - -#include - -#include "mementar/core/memGraphs/Branchs/types/Fact.h" - -namespace mementar -{ - -template -class LinkedFact : public Fact -{ -public: - LinkedFact(T stamp, const std::string& subject, const std::string& predicat, const std::string& object) : Fact(stamp, subject, predicat, object) - { - next_ = nullptr; - prev_ = nullptr; - } - - LinkedFact(T stamp, const std::string& triplet = "") : Fact(stamp, triplet) - { - next_ = nullptr; - prev_ = nullptr; - } - - bool isEventPart(const LinkedFact& other) const - { - return ((this->subject_ == other.subject_) - && (this->predicat_ == other.predicat_)); - } - - LinkedFact* next_; - LinkedFact* prev_; - - std::vector*> toLinkNext; - std::vector*> toLinkPrev; -}; - -} // namespace mementar - -#endif // MEMENTAR_LINKEDFACT_H diff --git a/include/mementar/core/LinkedBtree/LinkedBtree.h b/include/mementar/core/LinkedBtree/LinkedBtree.h deleted file mode 100644 index 5de9871..0000000 --- a/include/mementar/core/LinkedBtree/LinkedBtree.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MEMENTAR_LINKEDBTREE_H -#define MEMENTAR_LINKEDBTREE_H - -#include "mementar/core/memGraphs/Btree/Btree.h" -#include "mementar/core/LinkedBtree/LinkedBtreeLeafNode.h" -#include "mementar/core/Data/LinkedFact.h" - -namespace mementar -{ - -template -class LinkedBtree : public Btree> -{ -public: - LinkedBtree(size_t order = 10) : Btree>(order) {} - - size_t insert(LinkedFact* data); - -private: -}; - -template -size_t LinkedBtree::insert(LinkedFact* data) -{ - this->nb_data_++; - if(this->last_ == nullptr) - { - this->root_ = new LinkedBtreeLeafNode(this->order_); - this->level_ = this->root_->getLevel(); - this->last_ = this->root_->insert(data); - } - else - { - BtreeLeaf>* tmp = this->root_->insert(data); - if(tmp != nullptr) - { - if(tmp->operator>(this->last_)) - this->last_ = tmp; - if(this->root_->getMother() != nullptr) - { - this->root_ = this->root_->getMother(); - this->level_ = this->root_->getLevel(); - } - } - } - - return this->nb_data_; -} - -} // namespace mementar - -#endif // MEMENTAR_LINKEDBTREE_H diff --git a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h b/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h deleted file mode 100644 index 0271364..0000000 --- a/include/mementar/core/LinkedBtree/LinkedBtreeLeafNode.h +++ /dev/null @@ -1,346 +0,0 @@ -#ifndef MEMENTAR_LINKEDBTREELEAFNODE_H -#define MEMENTAR_LINKEDBTREELEAFNODE_H - -#include "mementar/core/memGraphs/Btree/BtreeLeafNode.h" -#include "mementar/core/Data/LinkedFact.h" - -#include "mementar/core/utility/Display.h" - -namespace mementar -{ - -template -class LinkedBtreeLeafNode : public BtreeLeafNode> -{ - typedef LinkedFact LinkedFact_; - typedef BtreeLeaf LinkedBtreeLeaf_; -public: - LinkedBtreeLeafNode(size_t order = 10) : BtreeLeafNode(order) - {} - - BtreeLeaf* insert(LinkedFact_* data); - bool remove(const LinkedFact_& data); - -private: - void split(); - - LinkedFact_* getPrev(LinkedBtreeLeaf_* current, LinkedFact_* data); - std::vector getPrevs(LinkedBtreeLeaf_* current, LinkedFact_* data); - LinkedFact_* getNext(LinkedBtreeLeaf_* current, LinkedFact_* data); - std::vector getNexts(LinkedBtreeLeaf_* current, LinkedFact_* data); - - void linkPrev(LinkedFact_* current, LinkedFact_* prev, LinkedFact_* next); - void linkNext(LinkedFact_* current, LinkedFact_* next, LinkedFact_* prev); - - void unlink(LinkedFact_* current_data, LinkedBtreeLeaf_* current_leaf); - void unlinkPrev(LinkedFact_* current, std::vector prev, LinkedFact_* next); - void unlinkNext(LinkedFact_* current, std::vector next, LinkedFact_* prev); -}; - -template -BtreeLeaf>* LinkedBtreeLeafNode::insert(LinkedFact* data) -{ - LinkedBtreeLeaf_* res = BtreeLeafNode>::insert(data); - - if(res != nullptr) - { - auto next = getNext(res, data); - auto prev = getPrev(res, data); - - linkPrev(data, prev, next); - linkNext(data, next, prev); - } - - return res; -} - -template -bool LinkedBtreeLeafNode::remove( const LinkedFact& data) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] == data.getStamp()) - { - LinkedFact_* current_data = this->leafs_[i]->getData(data); - unlink(current_data, this->leafs_[i]); - this->leafs_[i]->remove(data); - if(this->leafs_[i]->getData().size() == 0) - { - if(this->leafs_[i]->prev_ != nullptr) - this->leafs_[i]->prev_->next_ = this->leafs_[i]->next_; - if(this->leafs_[i]->next_ != nullptr) - this->leafs_[i]->next_->prev_ = this->leafs_[i]->prev_; - delete this->leafs_[i]; - this->leafs_.erase(this->leafs_.begin() + i); - this->keys_.erase(this->keys_.begin() + i); - - if(this->leafs_.size() == 0) - Display::Info("a node is empty but will not be destroyed"); - } - return true; - } - } - return false; -} - -template -void LinkedBtreeLeafNode::split() -{ - LinkedBtreeLeafNode* new_node = new LinkedBtreeLeafNode(this->order_); - - size_t half_order = this->order_/2; - for(size_t i = 0; i < half_order; i++) - { - new_node->leafs_.insert(new_node->leafs_.begin(), this->leafs_[this->leafs_.size() - 1]); - this->leafs_.erase(this->leafs_.begin() + this->leafs_.size() - 1); - new_node->leafs_[i]->setMother(new_node); - - new_node->keys_.insert(new_node->keys_.begin(), this->keys_[this->keys_.size() - 1]); - this->keys_.erase(this->keys_.begin() + this->keys_.size() - 1); - } - - if(this->mother_ != nullptr) - { - this->mother_->insert(new_node, new_node->keys_[0]); - } - else - { - BtreeNode* new_mother = new BtreeNode(this->order_); - new_mother->setLevel(this->level_ + 1); - new_mother->insert(this, this->keys_[0]); - new_mother->insert(new_node, new_node->keys_[0]); - } -} - -template -LinkedFact* LinkedBtreeLeafNode::getPrev(BtreeLeaf>* current, LinkedFact* data) -{ - LinkedFact_* res = nullptr; - - LinkedBtreeLeaf_* leaf = current->prev_; - while(leaf != nullptr) - { - for(auto ld : leaf->getData()) - { - if(data->isEventPart(*ld)) - return ld; - } - leaf = leaf->prev_; - } - - return res; -} - -template -std::vector*> LinkedBtreeLeafNode::getPrevs(BtreeLeaf>* current, LinkedFact* data) -{ - std::vector res; - bool end = false; - - LinkedBtreeLeaf_* leaf = current->prev_; - if(leaf == nullptr) - end = true; - - while(!end) - { - for(auto ld : leaf->getData()) - { - if(data->isEventPart(*ld)) - { - res.push_back(ld); - if(ld->prev_->next_ == ld) - end = true; - break; - } - } - - leaf = leaf->prev_; - if(leaf == nullptr) - end = true; - } - - return res; -} - -template -LinkedFact* LinkedBtreeLeafNode::getNext(BtreeLeaf>* current, LinkedFact* data) -{ - LinkedFact_* res = nullptr; - - LinkedBtreeLeaf_* leaf = current->next_; - while(leaf != nullptr) - { - for(auto ld : leaf->getData()) - { - if(data->isEventPart(*ld)) - return ld; - } - leaf = leaf->next_; - } - - return res; -} - -template -std::vector*> LinkedBtreeLeafNode::getNexts(BtreeLeaf>* current, LinkedFact* data) -{ - std::vector res; - bool end = false; - - LinkedBtreeLeaf_* leaf = current->next_; - if(leaf == nullptr) - end = true; - - while(!end) - { - for(auto ld : leaf->getData()) - { - if(data->isEventPart(*ld)) - { - res.push_back(ld); - if(ld->next_->prev_ == ld) - end = true; - break; - } - } - - leaf = leaf->next_; - if(leaf == nullptr) - end = true; - } - - return res; -} - -template -void LinkedBtreeLeafNode::linkPrev(LinkedFact* current, LinkedFact* prev, LinkedFact* next) -{ - if(prev == nullptr) - return; - - if(current->operator==(*prev)) - { - if(next == nullptr) - { - current->toLinkNext = prev->toLinkNext; - prev->toLinkNext.clear(); - current->toLinkNext.push_back(prev); - } - current->prev_ = prev->prev_; - } - else - { - current->prev_ = prev; - prev->next_ = current; - if(prev->toLinkNext.size()) - { - for(auto d : prev->toLinkNext) - d->next_ = current; - prev->toLinkNext.clear(); - } - } -} - -template -void LinkedBtreeLeafNode::linkNext(LinkedFact* current, LinkedFact* next, LinkedFact* prev) -{ - if(next == nullptr) - return; - - if(current->operator==(*next)) - { - if(prev == nullptr) - { - current->toLinkPrev = next->toLinkPrev; - next->toLinkPrev.clear(); - current->toLinkPrev.push_back(next); - } - current->next_ = next->next_; - } - else - { - current->next_ = next; - next->prev_ = current; - if(next->toLinkPrev.size()) - { - for(auto d : next->toLinkPrev) - d->prev_ = current; - next->toLinkPrev.clear(); - } - } -} - -template -void LinkedBtreeLeafNode::unlink(LinkedFact* current_data, BtreeLeaf>* current_leaf) -{ - std::vector prev; - std::vector next; - - prev = getPrevs(current_leaf, current_data); - next = getNexts(current_leaf, current_data); - - unlinkPrev(current_data, prev, next.size() ? next[0] : nullptr); - unlinkNext(current_data, next, prev.size() ? prev[0] : nullptr); -} - -template -void LinkedBtreeLeafNode::unlinkPrev(LinkedFact* current, std::vector*> prev, LinkedFact* next) -{ - if(prev.size()) - { - if(!current->operator==(*prev[0])) - { - if(!current->operator==(*next)) - { - for(auto p : prev) - p->next_ = current->next_; - } - else - { - for(auto p : prev) - p->next_ = next; - } - } - } - else if(current->toLinkPrev.size()) - { - if(current->operator==(*next)) - { - next->toLinkPrev = std::move(current->toLinkPrev); - next->toLinkPrev.pop_back(); - } - } -} - -template -void LinkedBtreeLeafNode::unlinkNext(LinkedFact* current, std::vector*> next, LinkedFact* prev) -{ - if(next.size()) - { - if(!current->operator==(*next[0])) - { - if(!current->operator==(*prev)) - { - for(auto n : next) - n->prev_ = current->prev_; - } - else - { - for(auto n : next) - n->prev_ = prev; - } - } - } - else if(current->toLinkNext.size()) - { - if(current->operator==(*prev)) - { - prev->toLinkNext = std::move(current->toLinkNext); - prev->toLinkNext.pop_back(); - } - } -} - -} // namespace mementar - -#endif // MEMENTAR_LINKEDBTREELEAFNODE_H From 865933ced01d7d92d1e8412a1a3d6aa4a6698594 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 22 Jun 2020 09:38:37 +0200 Subject: [PATCH 37/95] [REFACT] LtManagement folder --- CMakeLists.txt | 28 +++++++++---------- include/mementar/RosInterface.h | 2 +- .../EpisodicTree/ArchivedLeaf.h | 2 +- .../EpisodicTree/ArchivedLeafNode.h | 6 ++-- .../EpisodicTree/CompressedLeaf.h | 0 .../EpisodicTree/CompressedLeafNode.h | 4 +-- .../EpisodicTree/CompressedLeafNodeSession.h | 8 +++--- .../EpisodicTree/CompressedLeafSession.h | 4 +-- .../{ => LtManagement}/EpisodicTree/Context.h | 0 .../archiving_compressing/archiving/Archive.h | 4 +-- .../archiving_compressing/archiving/Header.h | 0 .../binaryManagement/BinaryManager.h | 0 .../binaryManagement/BitFileGenerator.h | 0 .../binaryManagement/BitFileGetter.h | 0 .../compressing/Huffman.h | 2 +- .../compressing/Huffman_old.h | 2 +- .../compressing/LzCompress.h | 4 +-- .../compressing/LzUncompress.h | 4 +-- .../EpisodicTree/ArchivedLeaf.cpp | 8 +++--- .../EpisodicTree/ArchivedLeafNode.cpp | 2 +- .../EpisodicTree/CMakeLists.txt | 2 +- .../EpisodicTree/CompressedLeaf.cpp | 6 ++-- .../EpisodicTree/CompressedLeafNode.cpp | 2 +- .../CompressedLeafNodeSession.cpp | 4 +-- .../EpisodicTree/CompressedLeafSession.cpp | 4 +-- .../EpisodicTree/Context.cpp | 2 +- .../EpisodicTree/tests/archived_tree.cpp | 2 +- .../EpisodicTree/tests/episodic_tree.cpp | 4 +-- .../archiving_compressing/CMakeLists.txt | 2 +- .../archiving/Archive.cpp | 8 +++--- .../archiving/Header.cpp | 6 ++-- .../binaryManagement/BitFileGenerator.cpp | 2 +- .../binaryManagement/BitFileGetter.cpp | 2 +- .../compressing/Huffman.cpp | 6 ++-- .../compressing/Huffman_old.cpp | 6 ++-- .../compressing/LzCompress.cpp | 2 +- .../compressing/LzUncompress.cpp | 2 +- .../archiving_compressing/tests/archive.cpp | 4 +-- .../archiving_compressing/tests/compress.cpp | 4 +-- .../tests/perfs/huffman_in.cpp | 4 +-- .../tests/perfs/huffman_out.cpp | 4 +-- .../tests/perfs/lz_in.cpp | 2 +- .../tests/perfs/lz_out.cpp | 2 +- .../tests/uncompress.cpp | 4 +-- 44 files changed, 83 insertions(+), 83 deletions(-) rename include/mementar/core/{ => LtManagement}/EpisodicTree/ArchivedLeaf.h (89%) rename include/mementar/core/{ => LtManagement}/EpisodicTree/ArchivedLeafNode.h (87%) rename include/mementar/core/{ => LtManagement}/EpisodicTree/CompressedLeaf.h (100%) rename include/mementar/core/{ => LtManagement}/EpisodicTree/CompressedLeafNode.h (94%) rename include/mementar/core/{ => LtManagement}/EpisodicTree/CompressedLeafNodeSession.h (83%) rename include/mementar/core/{ => LtManagement}/EpisodicTree/CompressedLeafSession.h (79%) rename include/mementar/core/{ => LtManagement}/EpisodicTree/Context.h (100%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/archiving/Archive.h (86%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/archiving/Header.h (100%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/binaryManagement/BinaryManager.h (100%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/binaryManagement/BitFileGenerator.h (100%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/binaryManagement/BitFileGetter.h (100%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/compressing/Huffman.h (94%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/compressing/Huffman_old.h (92%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/compressing/LzCompress.h (73%) rename include/mementar/core/{ => LtManagement}/archiving_compressing/compressing/LzUncompress.h (63%) rename src/core/{ => LtManagement}/EpisodicTree/ArchivedLeaf.cpp (89%) rename src/core/{ => LtManagement}/EpisodicTree/ArchivedLeafNode.cpp (99%) rename src/core/{ => LtManagement}/EpisodicTree/CMakeLists.txt (97%) rename src/core/{ => LtManagement}/EpisodicTree/CompressedLeaf.cpp (89%) rename src/core/{ => LtManagement}/EpisodicTree/CompressedLeafNode.cpp (99%) rename src/core/{ => LtManagement}/EpisodicTree/CompressedLeafNodeSession.cpp (96%) rename src/core/{ => LtManagement}/EpisodicTree/CompressedLeafSession.cpp (88%) rename src/core/{ => LtManagement}/EpisodicTree/Context.cpp (99%) rename src/core/{ => LtManagement}/EpisodicTree/tests/archived_tree.cpp (96%) rename src/core/{ => LtManagement}/EpisodicTree/tests/episodic_tree.cpp (91%) rename src/core/{ => LtManagement}/archiving_compressing/CMakeLists.txt (98%) rename src/core/{ => LtManagement}/archiving_compressing/archiving/Archive.cpp (92%) rename src/core/{ => LtManagement}/archiving_compressing/archiving/Header.cpp (89%) rename src/core/{ => LtManagement}/archiving_compressing/binaryManagement/BitFileGenerator.cpp (97%) rename src/core/{ => LtManagement}/archiving_compressing/binaryManagement/BitFileGetter.cpp (98%) rename src/core/{ => LtManagement}/archiving_compressing/compressing/Huffman.cpp (97%) rename src/core/{ => LtManagement}/archiving_compressing/compressing/Huffman_old.cpp (94%) rename src/core/{ => LtManagement}/archiving_compressing/compressing/LzCompress.cpp (96%) rename src/core/{ => LtManagement}/archiving_compressing/compressing/LzUncompress.cpp (93%) rename src/core/{ => LtManagement}/archiving_compressing/tests/archive.cpp (95%) rename src/core/{ => LtManagement}/archiving_compressing/tests/compress.cpp (94%) rename src/core/{ => LtManagement}/archiving_compressing/tests/perfs/huffman_in.cpp (94%) rename src/core/{ => LtManagement}/archiving_compressing/tests/perfs/huffman_out.cpp (94%) rename src/core/{ => LtManagement}/archiving_compressing/tests/perfs/lz_in.cpp (95%) rename src/core/{ => LtManagement}/archiving_compressing/tests/perfs/lz_out.cpp (94%) rename src/core/{ => LtManagement}/archiving_compressing/tests/uncompress.cpp (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a60827..939be04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,13 +85,13 @@ include_directories( ## CORE ############################## add_library(mementar_compression_lib - src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp - src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp - src/core/archiving_compressing/compressing/LzCompress.cpp - src/core/archiving_compressing/compressing/LzUncompress.cpp - src/core/archiving_compressing/compressing/Huffman.cpp - src/core/archiving_compressing/archiving/Header.cpp - src/core/archiving_compressing/archiving/Archive.cpp + src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp + src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp + src/core/LtManagement/archiving_compressing/compressing/LzCompress.cpp + src/core/LtManagement/archiving_compressing/compressing/LzUncompress.cpp + src/core/LtManagement/archiving_compressing/compressing/Huffman.cpp + src/core/LtManagement/archiving_compressing/archiving/Header.cpp + src/core/LtManagement/archiving_compressing/archiving/Archive.cpp ) add_library(mementar_memGraphs_lib @@ -106,13 +106,13 @@ add_library(mementar_memGraphs_lib ) add_library(mementar_core_lib - src/core/EpisodicTree/CompressedLeaf.cpp - src/core/EpisodicTree/CompressedLeafNode.cpp - src/core/EpisodicTree/Context.cpp - src/core/EpisodicTree/CompressedLeafSession.cpp - src/core/EpisodicTree/CompressedLeafNodeSession.cpp - src/core/EpisodicTree/ArchivedLeaf.cpp - src/core/EpisodicTree/ArchivedLeafNode.cpp + src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp + src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp + src/core/LtManagement/EpisodicTree/Context.cpp + src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp + src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp + src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp + src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp ) target_link_libraries(mementar_core_lib mementar_compression_lib diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index 40101d8..70f6f56 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -10,7 +10,7 @@ #include "mementar/MementarService.h" #include "mementar/StampedString.h" -#include "mementar/core/EpisodicTree/ArchivedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h" #include "mementar/core/Occasions/OccasionsManager.h" namespace mementar diff --git a/include/mementar/core/EpisodicTree/ArchivedLeaf.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h similarity index 89% rename from include/mementar/core/EpisodicTree/ArchivedLeaf.h rename to include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h index 58cd845..ff15b06 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeaf.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h @@ -4,7 +4,7 @@ #include #include -#include "mementar/core/EpisodicTree/CompressedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h" namespace mementar { diff --git a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h similarity index 87% rename from include/mementar/core/EpisodicTree/ArchivedLeafNode.h rename to include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h index 6e2fc17..9f7c7d2 100644 --- a/include/mementar/core/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h @@ -1,9 +1,9 @@ #ifndef MEMENTAR_ARCHIVEDLEAFNODE_H #define MEMENTAR_ARCHIVEDLEAFNODE_H -#include "mementar/core/EpisodicTree/ArchivedLeaf.h" -#include "mementar/core/EpisodicTree/CompressedLeafNode.h" -#include "mementar/core/EpisodicTree/CompressedLeafNodeSession.h" +#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h" namespace mementar { diff --git a/include/mementar/core/EpisodicTree/CompressedLeaf.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h similarity index 100% rename from include/mementar/core/EpisodicTree/CompressedLeaf.h rename to include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h similarity index 94% rename from include/mementar/core/EpisodicTree/CompressedLeafNode.h rename to include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h index 53f3288..1fd8760 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h @@ -8,8 +8,8 @@ #include "mementar/core/memGraphs/Branchs/types/Event.h" #include "mementar/core/memGraphs/Btree/Btree.h" -#include "mementar/core/EpisodicTree/CompressedLeaf.h" -#include "mementar/core/EpisodicTree/Context.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h" +#include "mementar/core/LtManagement/EpisodicTree/Context.h" namespace mementar { diff --git a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h similarity index 83% rename from include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h rename to include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h index 8039bbd..be95d5a 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h @@ -8,11 +8,11 @@ #include "mementar/core/memGraphs/Branchs/types/Event.h" #include "mementar/core/memGraphs/Btree/Btree.h" -#include "mementar/core/EpisodicTree/CompressedLeafSession.h" -#include "mementar/core/EpisodicTree/Context.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h" +#include "mementar/core/LtManagement/EpisodicTree/Context.h" -#include "mementar/core/archiving_compressing/archiving/Archive.h" -#include "mementar/core/archiving_compressing/archiving/Header.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Archive.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" namespace mementar { diff --git a/include/mementar/core/EpisodicTree/CompressedLeafSession.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h similarity index 79% rename from include/mementar/core/EpisodicTree/CompressedLeafSession.h rename to include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h index e113ccc..66c921b 100644 --- a/include/mementar/core/EpisodicTree/CompressedLeafSession.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h @@ -1,8 +1,8 @@ #ifndef MEMENTAR_COMPRESSEDLEAFSESSION_H #define MEMENTAR_COMPRESSEDLEAFSESSION_H -#include "mementar/core/archiving_compressing/archiving/Archive.h" -#include "mementar/core/archiving_compressing/archiving/Header.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Archive.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" #include "mementar/core/memGraphs/Btree/Btree.h" #include "mementar/core/memGraphs/Branchs/types/Event.h" diff --git a/include/mementar/core/EpisodicTree/Context.h b/include/mementar/core/LtManagement/EpisodicTree/Context.h similarity index 100% rename from include/mementar/core/EpisodicTree/Context.h rename to include/mementar/core/LtManagement/EpisodicTree/Context.h diff --git a/include/mementar/core/archiving_compressing/archiving/Archive.h b/include/mementar/core/LtManagement/archiving_compressing/archiving/Archive.h similarity index 86% rename from include/mementar/core/archiving_compressing/archiving/Archive.h rename to include/mementar/core/LtManagement/archiving_compressing/archiving/Archive.h index b0dfcfa..5d64b86 100644 --- a/include/mementar/core/archiving_compressing/archiving/Archive.h +++ b/include/mementar/core/LtManagement/archiving_compressing/archiving/Archive.h @@ -1,8 +1,8 @@ #ifndef MEMENTAR_ARCHIVE_H #define MEMENTAR_ARCHIVE_H -#include "mementar/core/archiving_compressing/archiving/Header.h" -#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h" namespace mementar { diff --git a/include/mementar/core/archiving_compressing/archiving/Header.h b/include/mementar/core/LtManagement/archiving_compressing/archiving/Header.h similarity index 100% rename from include/mementar/core/archiving_compressing/archiving/Header.h rename to include/mementar/core/LtManagement/archiving_compressing/archiving/Header.h diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h b/include/mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h similarity index 100% rename from include/mementar/core/archiving_compressing/binaryManagement/BinaryManager.h rename to include/mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h b/include/mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h similarity index 100% rename from include/mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h rename to include/mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h diff --git a/include/mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h b/include/mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h similarity index 100% rename from include/mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h rename to include/mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman.h b/include/mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h similarity index 94% rename from include/mementar/core/archiving_compressing/compressing/Huffman.h rename to include/mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h index 09276bb..7d1c595 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman.h +++ b/include/mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h @@ -5,7 +5,7 @@ #include #include -#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h" namespace mementar { diff --git a/include/mementar/core/archiving_compressing/compressing/Huffman_old.h b/include/mementar/core/LtManagement/archiving_compressing/compressing/Huffman_old.h similarity index 92% rename from include/mementar/core/archiving_compressing/compressing/Huffman_old.h rename to include/mementar/core/LtManagement/archiving_compressing/compressing/Huffman_old.h index 1a156f1..dd636db 100644 --- a/include/mementar/core/archiving_compressing/compressing/Huffman_old.h +++ b/include/mementar/core/LtManagement/archiving_compressing/compressing/Huffman_old.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h" namespace mementar { diff --git a/include/mementar/core/archiving_compressing/compressing/LzCompress.h b/include/mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h similarity index 73% rename from include/mementar/core/archiving_compressing/compressing/LzCompress.h rename to include/mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h index 1ec25e3..14b6622 100644 --- a/include/mementar/core/archiving_compressing/compressing/LzCompress.h +++ b/include/mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h @@ -4,8 +4,8 @@ #include #include -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" -#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h" namespace mementar { diff --git a/include/mementar/core/archiving_compressing/compressing/LzUncompress.h b/include/mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h similarity index 63% rename from include/mementar/core/archiving_compressing/compressing/LzUncompress.h rename to include/mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h index d720dc7..ab0632c 100644 --- a/include/mementar/core/archiving_compressing/compressing/LzUncompress.h +++ b/include/mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h @@ -1,8 +1,8 @@ #ifndef MEMENTAR_LZUNCOMPRESS_H #define MEMENTAR_LZUNCOMPRESS_H -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" -#include "mementar/core/archiving_compressing/binaryManagement/BinaryManager.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BinaryManager.h" namespace mementar { diff --git a/src/core/EpisodicTree/ArchivedLeaf.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp similarity index 89% rename from src/core/EpisodicTree/ArchivedLeaf.cpp rename to src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp index ea88b37..466cb1d 100644 --- a/src/core/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp @@ -2,11 +2,11 @@ #include #include -#include "mementar/core/EpisodicTree/ArchivedLeaf.h" +#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h" -#include "mementar/core/archiving_compressing/archiving/Archive.h" -#include "mementar/core/archiving_compressing/archiving/Header.h" -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Archive.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" namespace mementar { diff --git a/src/core/EpisodicTree/ArchivedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp similarity index 99% rename from src/core/EpisodicTree/ArchivedLeafNode.cpp rename to src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp index d892b49..d1c3463 100644 --- a/src/core/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/EpisodicTree/ArchivedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h" #include #include diff --git a/src/core/EpisodicTree/CMakeLists.txt b/src/core/LtManagement/EpisodicTree/CMakeLists.txt similarity index 97% rename from src/core/EpisodicTree/CMakeLists.txt rename to src/core/LtManagement/EpisodicTree/CMakeLists.txt index cd57f02..1c71b93 100644 --- a/src/core/EpisodicTree/CMakeLists.txt +++ b/src/core/LtManagement/EpisodicTree/CMakeLists.txt @@ -5,7 +5,7 @@ add_compile_options(-std=c++1z -Wall) link_libraries(stdc++fs) include_directories( - ../../../include + ../../../../include ) add_library(mementar_compression_lib diff --git a/src/core/EpisodicTree/CompressedLeaf.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp similarity index 89% rename from src/core/EpisodicTree/CompressedLeaf.cpp rename to src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp index 25173cd..307b718 100644 --- a/src/core/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp @@ -2,10 +2,10 @@ #include #include -#include "mementar/core/EpisodicTree/CompressedLeaf.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h" -#include "mementar/core/archiving_compressing/compressing/LzCompress.h" -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" namespace mementar { diff --git a/src/core/EpisodicTree/CompressedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp similarity index 99% rename from src/core/EpisodicTree/CompressedLeafNode.cpp rename to src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp index 0b3646e..7906aff 100644 --- a/src/core/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp @@ -1,7 +1,7 @@ #include #include -#include "mementar/core/EpisodicTree/CompressedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h" #include "mementar/core/utility/Display.h" namespace mementar diff --git a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp similarity index 96% rename from src/core/EpisodicTree/CompressedLeafNodeSession.cpp rename to src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp index db1d172..aa94140 100644 --- a/src/core/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp @@ -1,7 +1,7 @@ -#include "mementar/core/EpisodicTree/CompressedLeafNodeSession.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h" #include "mementar/core/utility/Display.h" -#include "mementar/core/archiving_compressing/compressing/LzCompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" namespace mementar { diff --git a/src/core/EpisodicTree/CompressedLeafSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp similarity index 88% rename from src/core/EpisodicTree/CompressedLeafSession.cpp rename to src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp index 151aec2..2fd8bbb 100644 --- a/src/core/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp @@ -1,9 +1,9 @@ -#include "mementar/core/EpisodicTree/CompressedLeafSession.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h" #include #include -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" namespace mementar { diff --git a/src/core/EpisodicTree/Context.cpp b/src/core/LtManagement/EpisodicTree/Context.cpp similarity index 99% rename from src/core/EpisodicTree/Context.cpp rename to src/core/LtManagement/EpisodicTree/Context.cpp index 1b21f95..a7e8b9d 100644 --- a/src/core/EpisodicTree/Context.cpp +++ b/src/core/LtManagement/EpisodicTree/Context.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/EpisodicTree/Context.h" +#include "mementar/core/LtManagement/EpisodicTree/Context.h" #include #include diff --git a/src/core/EpisodicTree/tests/archived_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp similarity index 96% rename from src/core/EpisodicTree/tests/archived_tree.cpp rename to src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp index dde9cbd..50fee60 100644 --- a/src/core/EpisodicTree/tests/archived_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp @@ -5,7 +5,7 @@ #include #include "mementar/core/memGraphs/Btree/Btree.h" -#include "mementar/core/EpisodicTree/ArchivedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h" using namespace std::chrono; diff --git a/src/core/EpisodicTree/tests/episodic_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp similarity index 91% rename from src/core/EpisodicTree/tests/episodic_tree.cpp rename to src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp index 7e704ae..b97d052 100644 --- a/src/core/EpisodicTree/tests/episodic_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp @@ -4,9 +4,9 @@ #include /* time */ #include -#include "mementar/core/EpisodicTree/CompressedLeaf.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h" #include "mementar/core/memGraphs/Btree/Btree.h" -#include "mementar/core/EpisodicTree/CompressedLeafNode.h" +#include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h" using namespace std::chrono; diff --git a/src/core/archiving_compressing/CMakeLists.txt b/src/core/LtManagement/archiving_compressing/CMakeLists.txt similarity index 98% rename from src/core/archiving_compressing/CMakeLists.txt rename to src/core/LtManagement/archiving_compressing/CMakeLists.txt index ccda8fb..345bab5 100644 --- a/src/core/archiving_compressing/CMakeLists.txt +++ b/src/core/LtManagement/archiving_compressing/CMakeLists.txt @@ -4,7 +4,7 @@ project (mementar) add_compile_options(-std=c++14 -Wall) include_directories( - ../../../include + ../../../../include ) add_library(mementar_compression_lib diff --git a/src/core/archiving_compressing/archiving/Archive.cpp b/src/core/LtManagement/archiving_compressing/archiving/Archive.cpp similarity index 92% rename from src/core/archiving_compressing/archiving/Archive.cpp rename to src/core/LtManagement/archiving_compressing/archiving/Archive.cpp index 4a78a96..ddd6fe1 100644 --- a/src/core/archiving_compressing/archiving/Archive.cpp +++ b/src/core/LtManagement/archiving_compressing/archiving/Archive.cpp @@ -1,8 +1,8 @@ -#include "mementar/core/archiving_compressing/archiving/Archive.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Archive.h" -#include "mementar/core/archiving_compressing/compressing/LzCompress.h" -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" -#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" namespace mementar { diff --git a/src/core/archiving_compressing/archiving/Header.cpp b/src/core/LtManagement/archiving_compressing/archiving/Header.cpp similarity index 89% rename from src/core/archiving_compressing/archiving/Header.cpp rename to src/core/LtManagement/archiving_compressing/archiving/Header.cpp index 95efafd..f06e90f 100644 --- a/src/core/archiving_compressing/archiving/Header.cpp +++ b/src/core/LtManagement/archiving_compressing/archiving/Header.cpp @@ -1,7 +1,7 @@ -#include "mementar/core/archiving_compressing/archiving/Header.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h" namespace mementar { diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp similarity index 97% rename from src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp rename to src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp index 35d0b5c..268c114 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGenerator.cpp +++ b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h" namespace mementar { diff --git a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp similarity index 98% rename from src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp rename to src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp index 46ae935..ef85366 100644 --- a/src/core/archiving_compressing/binaryManagement/BitFileGetter.cpp +++ b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h" #include diff --git a/src/core/archiving_compressing/compressing/Huffman.cpp b/src/core/LtManagement/archiving_compressing/compressing/Huffman.cpp similarity index 97% rename from src/core/archiving_compressing/compressing/Huffman.cpp rename to src/core/LtManagement/archiving_compressing/compressing/Huffman.cpp index ddd925a..31a9ce1 100644 --- a/src/core/archiving_compressing/compressing/Huffman.cpp +++ b/src/core/LtManagement/archiving_compressing/compressing/Huffman.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" #include #include @@ -6,8 +6,8 @@ #include #include -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h" #define TREE_CHAR_SIZE 8 #define TREE_VALUE_SIZE 6 diff --git a/src/core/archiving_compressing/compressing/Huffman_old.cpp b/src/core/LtManagement/archiving_compressing/compressing/Huffman_old.cpp similarity index 94% rename from src/core/archiving_compressing/compressing/Huffman_old.cpp rename to src/core/LtManagement/archiving_compressing/compressing/Huffman_old.cpp index 0703de0..4b271b5 100644 --- a/src/core/archiving_compressing/compressing/Huffman_old.cpp +++ b/src/core/LtManagement/archiving_compressing/compressing/Huffman_old.cpp @@ -1,10 +1,10 @@ -#include "mementar/core/archiving_compressing/compressing/Huffman_old.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman_old.h" #include #include -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGenerator.h" -#include "mementar/core/archiving_compressing/binaryManagement/BitFileGetter.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.h" +#include "mementar/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.h" namespace mementar { diff --git a/src/core/archiving_compressing/compressing/LzCompress.cpp b/src/core/LtManagement/archiving_compressing/compressing/LzCompress.cpp similarity index 96% rename from src/core/archiving_compressing/compressing/LzCompress.cpp rename to src/core/LtManagement/archiving_compressing/compressing/LzCompress.cpp index ecad5a9..b36b8f0 100644 --- a/src/core/archiving_compressing/compressing/LzCompress.cpp +++ b/src/core/LtManagement/archiving_compressing/compressing/LzCompress.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/archiving_compressing/compressing/LzCompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" #include #include diff --git a/src/core/archiving_compressing/compressing/LzUncompress.cpp b/src/core/LtManagement/archiving_compressing/compressing/LzUncompress.cpp similarity index 93% rename from src/core/archiving_compressing/compressing/LzUncompress.cpp rename to src/core/LtManagement/archiving_compressing/compressing/LzUncompress.cpp index b10ad5f..bfd5746 100644 --- a/src/core/archiving_compressing/compressing/LzUncompress.cpp +++ b/src/core/LtManagement/archiving_compressing/compressing/LzUncompress.cpp @@ -1,4 +1,4 @@ -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" #include #include diff --git a/src/core/archiving_compressing/tests/archive.cpp b/src/core/LtManagement/archiving_compressing/tests/archive.cpp similarity index 95% rename from src/core/archiving_compressing/tests/archive.cpp rename to src/core/LtManagement/archiving_compressing/tests/archive.cpp index 8007589..20c97d4 100644 --- a/src/core/archiving_compressing/tests/archive.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/archive.cpp @@ -8,8 +8,8 @@ #include -#include "mementar/core/archiving_compressing/archiving/Header.h" -#include "mementar/core/archiving_compressing/archiving/Archive.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" +#include "mementar/core/LtManagement/archiving_compressing/archiving/Archive.h" using namespace std::chrono; diff --git a/src/core/archiving_compressing/tests/compress.cpp b/src/core/LtManagement/archiving_compressing/tests/compress.cpp similarity index 94% rename from src/core/archiving_compressing/tests/compress.cpp rename to src/core/LtManagement/archiving_compressing/tests/compress.cpp index 310625f..3a9782e 100644 --- a/src/core/archiving_compressing/tests/compress.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/compress.cpp @@ -6,8 +6,8 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/archiving_compressing/compressing/LzCompress.h" -#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" using namespace std::chrono; diff --git a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp b/src/core/LtManagement/archiving_compressing/tests/perfs/huffman_in.cpp similarity index 94% rename from src/core/archiving_compressing/tests/perfs/huffman_in.cpp rename to src/core/LtManagement/archiving_compressing/tests/perfs/huffman_in.cpp index d0d9be3..8798831 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_in.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/perfs/huffman_in.cpp @@ -6,8 +6,8 @@ #include /* srand, rand */ #include /* time */ -//#include "mementar/core/archiving_compressing/compressing/Huffman.h" -#include "mementar/core/archiving_compressing/compressing/Huffman.h" +//#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" using namespace std::chrono; diff --git a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp b/src/core/LtManagement/archiving_compressing/tests/perfs/huffman_out.cpp similarity index 94% rename from src/core/archiving_compressing/tests/perfs/huffman_out.cpp rename to src/core/LtManagement/archiving_compressing/tests/perfs/huffman_out.cpp index 8fe7f6c..bc1e60d 100644 --- a/src/core/archiving_compressing/tests/perfs/huffman_out.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/perfs/huffman_out.cpp @@ -9,9 +9,9 @@ #define NEW_V #ifdef NEW_V -#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" #else -#include "mementar/core/archiving_compressing/compressing/Huffman_old.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman_old.h" #endif diff --git a/src/core/archiving_compressing/tests/perfs/lz_in.cpp b/src/core/LtManagement/archiving_compressing/tests/perfs/lz_in.cpp similarity index 95% rename from src/core/archiving_compressing/tests/perfs/lz_in.cpp rename to src/core/LtManagement/archiving_compressing/tests/perfs/lz_in.cpp index 75fdb79..c233430 100644 --- a/src/core/archiving_compressing/tests/perfs/lz_in.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/perfs/lz_in.cpp @@ -6,7 +6,7 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/archiving_compressing/compressing/LzCompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" using namespace std::chrono; diff --git a/src/core/archiving_compressing/tests/perfs/lz_out.cpp b/src/core/LtManagement/archiving_compressing/tests/perfs/lz_out.cpp similarity index 94% rename from src/core/archiving_compressing/tests/perfs/lz_out.cpp rename to src/core/LtManagement/archiving_compressing/tests/perfs/lz_out.cpp index b80bcd8..5b497cb 100644 --- a/src/core/archiving_compressing/tests/perfs/lz_out.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/perfs/lz_out.cpp @@ -6,7 +6,7 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" using namespace std::chrono; diff --git a/src/core/archiving_compressing/tests/uncompress.cpp b/src/core/LtManagement/archiving_compressing/tests/uncompress.cpp similarity index 94% rename from src/core/archiving_compressing/tests/uncompress.cpp rename to src/core/LtManagement/archiving_compressing/tests/uncompress.cpp index 9842bfc..4b09282 100644 --- a/src/core/archiving_compressing/tests/uncompress.cpp +++ b/src/core/LtManagement/archiving_compressing/tests/uncompress.cpp @@ -6,8 +6,8 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/archiving_compressing/compressing/LzUncompress.h" -#include "mementar/core/archiving_compressing/compressing/Huffman.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/LzUncompress.h" +#include "mementar/core/LtManagement/archiving_compressing/compressing/Huffman.h" using namespace std::chrono; From 1e1c7b117ee2097b3648001bcd3bd6973659993a Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 22 Jun 2020 14:41:30 +0200 Subject: [PATCH 38/95] [REFACT] Event and Fact serialization and deserialization --- CMakeLists.txt | 2 + .../core/memGraphs/Branchs/types/Event.h | 50 +++++++++++++++++ .../core/memGraphs/Branchs/types/Fact.h | 54 ++++++++++++++++--- .../EpisodicTree/ArchivedLeaf.cpp | 13 +---- .../LtManagement/EpisodicTree/CMakeLists.txt | 2 + .../EpisodicTree/CompressedLeaf.cpp | 15 ++---- .../CompressedLeafNodeSession.cpp | 2 +- .../EpisodicTree/CompressedLeafSession.cpp | 13 +---- .../EpisodicTree/tests/episodic_tree.cpp | 44 ++++++++++----- src/core/memGraphs/Branchs/types/Event.cpp | 8 +++ src/core/memGraphs/Branchs/types/Fact.cpp | 8 +++ 11 files changed, 154 insertions(+), 57 deletions(-) create mode 100644 src/core/memGraphs/Branchs/types/Event.cpp create mode 100644 src/core/memGraphs/Branchs/types/Fact.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 939be04..f64af1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,8 @@ add_library(mementar_compression_lib add_library(mementar_memGraphs_lib src/core/memGraphs/Branchs/ValuedNode.cpp src/core/memGraphs/Branchs/types/Action.cpp + src/core/memGraphs/Branchs/types/Fact.cpp + src/core/memGraphs/Branchs/types/Event.cpp src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp src/core/memGraphs/EventLinkedList/EllElement.cpp diff --git a/include/mementar/core/memGraphs/Branchs/types/Event.h b/include/mementar/core/memGraphs/Branchs/types/Event.h index dd05fc6..6e164e7 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Event.h +++ b/include/mementar/core/memGraphs/Branchs/types/Event.h @@ -29,6 +29,53 @@ class Event : public SoftPoint, public Fact { } + static std::string serialize(const Event& event) + { + if(event.isInstantaneous()) + return "[" + std::to_string(event.getTimeStart()) + "]{" + Fact::serialize(&event) + "}"; + else + return "[" + std::to_string(event.getTimeStart()) + "," + std::to_string(event.getTimeEnd()) + "]{" + Fact::serialize(&event) + "}"; + } + + static std::string serialize(const Event* event) + { + if(event->isInstantaneous()) + return "[" + std::to_string(event->getTimeStart()) + "]{" + Fact::serialize(event) + "}"; + else + return "[" + std::to_string(event->getTimeStart()) + "," + std::to_string(event->getTimeEnd()) + "]{" + Fact::serialize(event) + "}"; + } + + static Event deserialize(const std::string& str) + { + if(std::regex_match(str, match, regex)) + { + if(match[3].str() == "") + return Event(Fact::deserialize(match[4].str()), std::stoul(match[1].str())); + else + return Event(Fact::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); + } + else + return Event("", 0); + } + + static Event* deserializePtr(const std::string& str) + { + if(std::regex_match(str, match, regex)) + { + if(match[3].str() == "") + return new Event(Fact::deserialize(match[4].str()), std::stoul(match[1].str())); + else + return new Event(Fact::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); + + /*if(match[3].str() == "") + return new Event(Fact(match[4].str(), match[5].str(), match[6].str(), match[7].str() == "A"), std::stoul(match[1].str())); + else + return new Event(Fact(match[4].str(), match[5].str(), match[6].str(), match[7].str() == "A"), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str())));*/ + } + else + return nullptr; + } + std::string getData() { return Fact::toString(); } friend std::ostream& operator<<(std::ostream& os, Event* event) @@ -49,6 +96,9 @@ class Event : public SoftPoint, public Fact } protected: + + static std::regex regex; + static std::smatch match; }; } // namespace mementar diff --git a/include/mementar/core/memGraphs/Branchs/types/Fact.h b/include/mementar/core/memGraphs/Branchs/types/Fact.h index ea13e00..6404736 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Fact.h +++ b/include/mementar/core/memGraphs/Branchs/types/Fact.h @@ -3,6 +3,8 @@ #include #include +#include +#include namespace mementar { @@ -10,14 +12,15 @@ namespace mementar class Fact { public: - Fact(const std::string& subject, const std::string& predicat, const std::string& object) + Fact(const std::string& subject, const std::string& predicat, const std::string& object, bool add = true) { subject_ = subject; predicat_ = predicat; object_ = object; + add_ = add; } - Fact(const std::string& triplet = "") + Fact(const std::string& triplet = "", bool add = true) { std::vector splitted = split(triplet, "|"); if(splitted.size() >= 1) @@ -26,6 +29,7 @@ class Fact predicat_ = splitted[1]; if(splitted.size() >= 3) object_ = splitted[2]; + add_ = add; } Fact(const Fact& other) @@ -33,6 +37,33 @@ class Fact subject_ = other.subject_; predicat_ = other.predicat_; object_ = other.object_; + add_ = other.add_; + } + + static std::string serialize(const Fact& fact) + { + return (fact.add_ ? "A|" : "D|") + fact.subject_ + "|" + fact.predicat_ + "|" + fact.object_; + } + + static std::string serialize(const Fact* fact) + { + return (fact->add_ ? "A|" : "D|") + fact->subject_ + "|" + fact->predicat_ + "|" + fact->object_; + } + + static Fact deserialize(const std::string& str) + { + if(std::regex_match(str, match, regex)) + return Fact(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + else + return Fact(); + } + + static Fact* deserializePtr(const std::string& str) + { + if(std::regex_match(str, match, regex)) + return new Fact(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + else + return nullptr; } bool valid() const @@ -42,40 +73,47 @@ class Fact std::string toString() const { - return subject_ + " | " + predicat_ + " | " + object_; + return (add_ ? "[add]" : "[del]") + subject_ + " | " + predicat_ + " | " + object_; } bool operator==(const Fact& other) const { - return ((subject_ == other.subject_) + return ( (add_ == other.add_) + && (subject_ == other.subject_) && (predicat_ == other.predicat_) && (object_ == other.object_)); } bool operator==(const Fact* other) const { - return ((subject_ == other->subject_) + return ( (add_ == other->add_) + && (subject_ == other->subject_) && (predicat_ == other->predicat_) && (object_ == other->object_)); } bool fit(const Fact& other) const { - return (((subject_ == other.subject_) || (subject_ == "?") || (other.subject_ == "?")) + return ( (add_ == other.add_) + && ((subject_ == other.subject_) || (subject_ == "?") || (other.subject_ == "?")) && ((predicat_ == other.predicat_) || (predicat_ == "?") || (other.predicat_ == "?")) && ((object_ == other.object_) || (object_ == "?") || (other.object_ == "?"))); } friend std::ostream& operator<<(std::ostream& os, const Fact& fact) { - std::string space = " "; - os << fact.subject_ << space << fact.predicat_ << space << fact.object_; + os << fact.toString(); return os; } std::string subject_; std::string predicat_; std::string object_; + bool add_; + +protected: + static std::regex regex; + static std::smatch match; private: diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp index 466cb1d..08620e7 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp @@ -71,22 +71,13 @@ Btree* ArchivedLeaf::getTree(size_t i) std::string out = lz.uncompress(comp_data); Btree* tree = new Btree(); - std::regex regex("\\[(\\d+)\\](\\w+)\\s*\\|\\s*(\\w+)\\s*\\|\\s*(\\w+)"); - std::smatch match; - std::istringstream iss(out); std::string line; while(std::getline(iss, line)) { - if(std::regex_match(line, match, regex)) - { - time_t key; - std::istringstream iss(match[1].str()); - iss >> key; - Event* event = new Event(Fact(match[2].str(), match[3].str(), match[4].str()), key); - + Event* event = Event::deserializePtr(line); + if(event != nullptr) tree->insert(event->getTime(), event); - } } return tree; diff --git a/src/core/LtManagement/EpisodicTree/CMakeLists.txt b/src/core/LtManagement/EpisodicTree/CMakeLists.txt index 1c71b93..7499034 100644 --- a/src/core/LtManagement/EpisodicTree/CMakeLists.txt +++ b/src/core/LtManagement/EpisodicTree/CMakeLists.txt @@ -19,6 +19,8 @@ add_library(mementar_compression_lib ) add_library(mementar_tree_lib + ../../memGraphs/Branchs/types/Event.cpp + ../../memGraphs/Branchs/types/Fact.cpp CompressedLeaf.cpp CompressedLeafNode.cpp Context.cpp diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp index 307b718..fba3df1 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp @@ -42,22 +42,13 @@ Btree* CompressedLeaf::getTree() std::string out = lz.uncompress(data); Btree* tree = new Btree(); - std::regex regex("\\[(\\d+)\\](\\w+)\\s*\\|\\s*(\\w+)\\s*\\|\\s*(\\w+)"); - std::smatch match; - std::istringstream iss(out); std::string line; while(std::getline(iss, line)) { - if(std::regex_match(line, match, regex)) - { - time_t key; - std::istringstream iss(match[1].str()); - iss >> key; - Event* event = new Event(Fact(match[2].str(), match[3].str(), match[4].str()), key); - + Event* event = Event::deserializePtr(line); + if(event != nullptr) tree->insert(event->getTime(), event); - } } return tree; @@ -75,7 +66,7 @@ std::string CompressedLeaf::treeToString(Btree* tree) { tmp_data = it->getData(); for(auto& data : tmp_data) - res += "[" + std::to_string(it->getKey()) + "]" + data->Fact::toString() + "\n"; + res += Event::serialize(data) + "\n"; it = static_cast*>(it->getNextNode()); } diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp index aa94140..7f0f1e4 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp @@ -214,7 +214,7 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) { tmp_data = it->getData(); for(auto& data : tmp_data) - res += "[" + std::to_string(it->getKey()) + "]" + data->Fact::toString() + "\n"; + res += Event::serialize(data) + "\n"; it = static_cast*>(it->getNextNode()); } diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp index 2fd8bbb..ebf7cb5 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp @@ -23,22 +23,13 @@ Btree* CompressedLeafSession::getTree(Header& header, Archive& a std::string out = lz.uncompress(comp_data); Btree* tree = new Btree(); - std::regex regex("\\[(\\d+)\\](\\w+)\\s*\\|\\s*(\\w+)\\s*\\|\\s*(\\w+)"); - std::smatch match; - std::istringstream iss(out); std::string line; while(std::getline(iss, line)) { - if(std::regex_match(line, match, regex)) - { - time_t key; - std::istringstream iss(match[1].str()); - iss >> key; - Event* event = new Event(Fact(match[2].str(), match[3].str(), match[4].str()), key); - + Event* event = Event::deserializePtr(line); + if(event != nullptr) tree->insert(event->getTime(), event); - } } return tree; diff --git a/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp index b97d052..51f723e 100644 --- a/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp @@ -14,25 +14,41 @@ int main() { high_resolution_clock::time_point t1 = high_resolution_clock::now(); - mementar::CompressedLeafNode compressed_node("/home/gsarthou/Desktop/test"); - - std::cout << " *************" << std::endl; - for(size_t i = 0; i < 400000; i++) { - //std::cout << i << std::endl; - compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(i)), i)); - //usleep(1); + mementar::CompressedLeafNode compressed_node("/home/gsarthou/Desktop/test"); + + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + std::cout << "took " << time_span.count() << " to load" << std::endl; + + std::cout << " *************" << std::endl; + for(size_t i = 0; i < 400000; i++) + { + //std::cout << i << std::endl; + compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(i)), i)); + //usleep(1); + } + std::cout << " *************" << std::endl; + + high_resolution_clock::time_point t3 = high_resolution_clock::now(); + time_span = duration_cast>(t3 - t2); + std::cout << "took " << time_span.count() << " to insert" << std::endl; + + compressed_node.remove(compressed_node.find(102)->getData()[0]); + compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 0)); + + std::cout << " *************" << std::endl; + + high_resolution_clock::time_point t4 = high_resolution_clock::now(); + time_span = duration_cast>(t4 - t3); + std::cout << "took " << time_span.count() << " to modify" << std::endl; } - std::cout << " *************" << std::endl; - high_resolution_clock::time_point t2 = high_resolution_clock::now(); - duration time_span = duration_cast>(t2 - t1); - std::cout << "took " << time_span.count() << std::endl; + high_resolution_clock::time_point t5 = high_resolution_clock::now(); + duration time_span = duration_cast>(t5 - t1); + std::cout << "took " << time_span.count() << " for all process" << std::endl; - compressed_node.remove(compressed_node.find(102)->getData()[0]); - compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 0)); - std::cout << " *************" << std::endl; /*//compressed_node.display(150000); std::cout << "first key = " << compressed_node.getFirst()->getKey() << std::endl; diff --git a/src/core/memGraphs/Branchs/types/Event.cpp b/src/core/memGraphs/Branchs/types/Event.cpp new file mode 100644 index 0000000..5e046bc --- /dev/null +++ b/src/core/memGraphs/Branchs/types/Event.cpp @@ -0,0 +1,8 @@ +#include "mementar/core/memGraphs/Branchs/types/Event.h" + +namespace mementar { + +std::regex Event::regex("\\[(\\d*)(,(\\d*))?\\]\\{([^\\}]*)\\}"); +std::smatch Event::match; + +} // namespace mementar diff --git a/src/core/memGraphs/Branchs/types/Fact.cpp b/src/core/memGraphs/Branchs/types/Fact.cpp new file mode 100644 index 0000000..7566b86 --- /dev/null +++ b/src/core/memGraphs/Branchs/types/Fact.cpp @@ -0,0 +1,8 @@ +#include "mementar/core/memGraphs/Branchs/types/Fact.h" + +namespace mementar { + +std::regex Fact::regex("(\\w)\\|(\\w+)\\|(\\w+)\\|(\\w+)"); +std::smatch Fact::match; + +} // namespace mementar From 2b9ef1715e3149436ecd3e6aa96f69a766b09e06 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jun 2020 17:05:35 +0200 Subject: [PATCH 39/95] [ADD] graphical timeline generation --- CMakeLists.txt | 25 +++ .../memGraphs/Branchs/ContextualizedEvent.h | 2 +- .../core/memGraphs/Branchs/types/Event.h | 5 - include/mementar/core/memGraphs/Timeline.h | 21 +++ .../graphical/timeline/ActionReader.h | 48 +++++ .../mementar/graphical/timeline/EventReader.h | 34 ++++ .../graphical/timeline/TimelineDrawer.h | 34 ++++ src/graphical/timeline/ActionReader.cpp | 83 +++++++++ src/graphical/timeline/EventReader.cpp | 45 +++++ src/graphical/timeline/TimelineDrawer.cpp | 152 ++++++++++++++++ src/graphical/timeline/main.cpp | 169 ++++++++++++++++++ 11 files changed, 612 insertions(+), 6 deletions(-) create mode 100644 include/mementar/core/memGraphs/Timeline.h create mode 100644 include/mementar/graphical/timeline/ActionReader.h create mode 100644 include/mementar/graphical/timeline/EventReader.h create mode 100644 include/mementar/graphical/timeline/TimelineDrawer.h create mode 100644 src/graphical/timeline/ActionReader.cpp create mode 100644 src/graphical/timeline/EventReader.cpp create mode 100644 src/graphical/timeline/TimelineDrawer.cpp create mode 100644 src/graphical/timeline/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f64af1f..a56be20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ find_package(Boost REQUIRED COMPONENTS system) find_package(cmake_modules REQUIRED) find_package(pluginlib REQUIRED) find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport) +find_package(OpenCV REQUIRED) ################################################ @@ -61,6 +62,7 @@ catkin_package( INCLUDE_DIRS include LIBRARIES mementar_lib CATKIN_DEPENDS roscpp rospy std_msgs + DEPENDS OpenCV ) ########### @@ -133,6 +135,24 @@ add_library(mementar_events_lib target_link_libraries(mementar_events_lib ${catkin_LIBRARIES}) add_dependencies(mementar_events_lib ${catkin_EXPORTED_TARGETS} mementar_gencpp) +############################## +## DRAWER +############################## + +add_library(mementar_drawer_lib + src/graphical/timeline/ActionReader.cpp + src/graphical/timeline/EventReader.cpp + src/graphical/timeline/TimelineDrawer.cpp +) +target_include_directories(mementar_drawer_lib +PUBLIC + ${OpenCV_INCLUDE_DIRS} +) +target_link_libraries(mementar_drawer_lib + mementar_memGraphs_lib + ${OpenCV_LIBS} +) + ############################## ## API ############################## @@ -175,6 +195,11 @@ target_link_libraries(mementar_multi mementar_interface) target_link_libraries(mementar_multi ${catkin_LIBRARIES}) add_dependencies(mementar_multi ${catkin_EXPORTED_TARGETS}) +add_executable(mementar_timeline src/graphical/timeline/main.cpp) +target_link_libraries(mementar_timeline mementar_core_lib mementar_drawer_lib) +target_link_libraries(mementar_timeline ${catkin_LIBRARIES}) +add_dependencies(mementar_timeline ${catkin_EXPORTED_TARGETS}) + ############################## ## Test executables ############################## diff --git a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h index 2c7f16c..220ddb4 100644 --- a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h +++ b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h @@ -32,7 +32,7 @@ class ContextualizedEvent : public Event, public ValuedNode, public EllElement bool isPartOfAction() { return action_ != nullptr; } Action* getActionPart() { return action_; } - std::string toString() { return getValue() + " " + SoftPoint::toString() + " : " + getData() + std::string(action_ ? " is part of action " + action_->getName() : ""); } + std::string toString() { return getValue() + " " + SoftPoint::toString() + " : " + getData() + std::string(action_ ? " => part of action " + action_->getName() : ""); } virtual void print(std::ostream& os) const { diff --git a/include/mementar/core/memGraphs/Branchs/types/Event.h b/include/mementar/core/memGraphs/Branchs/types/Event.h index 6e164e7..c295377 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Event.h +++ b/include/mementar/core/memGraphs/Branchs/types/Event.h @@ -66,11 +66,6 @@ class Event : public SoftPoint, public Fact return new Event(Fact::deserialize(match[4].str()), std::stoul(match[1].str())); else return new Event(Fact::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); - - /*if(match[3].str() == "") - return new Event(Fact(match[4].str(), match[5].str(), match[6].str(), match[7].str() == "A"), std::stoul(match[1].str())); - else - return new Event(Fact(match[4].str(), match[5].str(), match[6].str(), match[7].str() == "A"), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str())));*/ } else return nullptr; diff --git a/include/mementar/core/memGraphs/Timeline.h b/include/mementar/core/memGraphs/Timeline.h new file mode 100644 index 0000000..751b315 --- /dev/null +++ b/include/mementar/core/memGraphs/Timeline.h @@ -0,0 +1,21 @@ +#ifndef MEMENTAR_TIMELINE_H +#define MEMENTAR_TIMELINE_H + +#include "mementar/core/memGraphs/Graphs/EventGraph.h" +#include "mementar/core/memGraphs/Graphs/ActionGraph.h" + +namespace mementar { + +class Timeline +{ +public: + Timeline() : actions(&events) {} + + EventGraph events; + ActionGraph actions; +private: +}; + +} // namespace mementar + +#endif // MEMENTAR_TIMELINE_H diff --git a/include/mementar/graphical/timeline/ActionReader.h b/include/mementar/graphical/timeline/ActionReader.h new file mode 100644 index 0000000..206fbea --- /dev/null +++ b/include/mementar/graphical/timeline/ActionReader.h @@ -0,0 +1,48 @@ +#ifndef MEMENTAR_ACTIONREADER_H +#define MEMENTAR_ACTIONREADER_H + +#include +#include +#include + +#include + +#include "mementar/core/memGraphs/Graphs/EventGraph.h" + +namespace mementar { + +struct action_t +{ + action_t(const SoftPoint& point) : start(point) {} + + std::string name; + SoftPoint start; + std::experimental::optional end; + + size_t level; +}; + +class ActionReader +{ +public: + ActionReader(); + + void read(EventGraph* graph, CvFont* font); + + std::map actions_; + size_t max_level_; + size_t max_text_size_; + +private: + std::vector levels_; + + action_t getAction(Action* action); + void closeAction(Action* action); + + size_t getMinLevel(); + void getTextSize(const std::string& txt, CvFont* font); +}; + +} // namespace mementar + +#endif // MEMENTAR_ACTIONREADER_H diff --git a/include/mementar/graphical/timeline/EventReader.h b/include/mementar/graphical/timeline/EventReader.h new file mode 100644 index 0000000..50d17ca --- /dev/null +++ b/include/mementar/graphical/timeline/EventReader.h @@ -0,0 +1,34 @@ +#ifndef MEMENTAR_EVENTREADER_H +#define MEMENTAR_EVENTREADER_H + +#include +#include + +#include + +#include "mementar/core/memGraphs/Graphs/EventGraph.h" + +namespace mementar { + +struct event_t +{ + std::string data; + size_t time_point; +}; + +class EventReader +{ +public: + + void read(EventGraph* graph, CvFont* font); + + std::vector events; + size_t max_text_size_; + +private: + void getTextSize(const std::string& txt, CvFont* font); +}; + +} // namespace mementar + +#endif // MEMENTAR_EVENTREADER_H diff --git a/include/mementar/graphical/timeline/TimelineDrawer.h b/include/mementar/graphical/timeline/TimelineDrawer.h new file mode 100644 index 0000000..f8df8ff --- /dev/null +++ b/include/mementar/graphical/timeline/TimelineDrawer.h @@ -0,0 +1,34 @@ +#ifndef MEMENTAR_TIMELINEDRAWER_H +#define MEMENTAR_TIMELINEDRAWER_H + +#include + +#include +#include + +#include "mementar/core/memGraphs/Timeline.h" +#include "mementar/graphical/timeline/ActionReader.h" +#include "mementar/graphical/timeline/EventReader.h" + +namespace mementar { + +class TimelineDrawer +{ +public: + + void draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, EventReader* events); +private: + IplImage* image_; + + void drawVector(size_t start, size_t end, size_t pose); + void drawAction(const action_t& action, size_t line_pose, size_t max_level, size_t start_time); + void drawEvent(const event_t& event, size_t line_pose, size_t start_time); + + size_t getTextSize(const std::string& txt, CvFont* font); + void drawElipseStart(size_t x, size_t y); + void drawElipseEnd(size_t x, size_t y); +}; + +} // namespace mementar + +#endif // MEMENTAR_TIMELINEDRAWER_H diff --git a/src/graphical/timeline/ActionReader.cpp b/src/graphical/timeline/ActionReader.cpp new file mode 100644 index 0000000..219f862 --- /dev/null +++ b/src/graphical/timeline/ActionReader.cpp @@ -0,0 +1,83 @@ +#include "mementar/graphical/timeline/ActionReader.h" + +namespace mementar { + +ActionReader::ActionReader() +{ + actions_.clear(); + levels_.clear(); + max_level_ = 0; + max_text_size_ = 0; +} + +void ActionReader::read(EventGraph* graph, CvFont* font) +{ + auto tree = graph->getTimeline(); + DllNode* node = tree->getFirst(); + + while(node != nullptr) + { + for(auto evt : node->getData()) + { + if(dynamic_cast(evt)->isPartOfAction()) + { + auto action = dynamic_cast(evt)->getActionPart(); + if(actions_.find(action->getValue()) == actions_.end()) + { + action_t act = getAction(action); + actions_.insert(std::pair(act.name, act)); + getTextSize(act.name, font); + } + else + closeAction(action); + } + } + + node = node->getNextNode(); + } + + std::cout << "max_level_ = " << max_level_ << std::endl; + std::cout << "max_text_size_ = " << max_text_size_ << std::endl; +} + +action_t ActionReader::getAction(Action* action) +{ + action_t new_action(*action->getStartEvent()); + new_action.name = action->getValue(); + new_action.level = getMinLevel(); + + levels_.push_back(new_action.level); + if(new_action.level > max_level_) + max_level_ = new_action.level; + + return new_action; +} + +void ActionReader::closeAction(Action* action) +{ + auto act_it = actions_.find(action->getValue()); + auto level_it = std::find(levels_.begin(), levels_.end(), act_it->second.level); + levels_.erase(level_it); + act_it->second.end = SoftPoint(*action->getEndEvent()); +} + +size_t ActionReader::getMinLevel() +{ + for(size_t l = 1; ; l++) + { + if(std::find(levels_.begin(), levels_.end(), l) == levels_.end()) + return l; + } +} + +void ActionReader::getTextSize(const std::string& txt, CvFont* font) +{ + CvSize size; + int baseline; + cvGetTextSize(txt.c_str(), font, &size, &baseline); + size_t text_width = size.width; + if(text_width > max_text_size_) + max_text_size_ = text_width; +} + +} // namespace mementar diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/EventReader.cpp new file mode 100644 index 0000000..e039050 --- /dev/null +++ b/src/graphical/timeline/EventReader.cpp @@ -0,0 +1,45 @@ +#include "mementar/graphical/timeline/EventReader.h" + +namespace mementar { + +void EventReader::read(EventGraph* graph, CvFont* font) +{ + max_text_size_ = 0; + + auto tree = graph->getTimeline(); + auto node = tree->getFirst(); + + while(node != nullptr) + { + event_t group_evt; + group_evt.time_point = node->getKey(); + for(auto evt : node->getData()) + { + if(dynamic_cast(evt)->isPartOfAction() == false) + { + auto event = dynamic_cast(evt); + group_evt.data += (group_evt.data == "" ? "" : " -- ") + event->Fact::toString(); + } + } + + if(group_evt.data != "") + { + events.push_back(group_evt); + getTextSize(group_evt.data, font); + } + + node = dynamic_cast*>(node->getNextNode()); + } +} + +void EventReader::getTextSize(const std::string& txt, CvFont* font) +{ + CvSize size; + int baseline; + cvGetTextSize(txt.c_str(), font, &size, &baseline); + size_t text_width = size.width; + if(text_width > max_text_size_) + max_text_size_ = text_width; +} + +} // namespace mementar diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp new file mode 100644 index 0000000..11c9142 --- /dev/null +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -0,0 +1,152 @@ +#include "mementar/graphical/timeline/TimelineDrawer.h" + +#define UNIT_SPACE 70 +#define SIDE_SPACE 100 +#define EDGE_RADIUS 30 +#define TEXT_WIDTH 750 +#define MARK_WIDTH 20 +#define MARGIN 50 + +namespace mementar { + +void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, EventReader* events) +{ + size_t start = timeline->events.getTimeline()->getFirst()->getKey(); + size_t end = timeline->events.getTimeline()->getLast()->getKey(); + size_t width = (actions->max_level_ + 1) * SIDE_SPACE + actions->max_text_size_ + MARGIN * 3 + SIDE_SPACE + events->max_text_size_; + size_t height = (end - start) * UNIT_SPACE + MARGIN * 2; + + std::cout << "image size = " << width << " : " << height << std::endl; + image_ = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); + cvSet(image_, cvScalar(255,255,255)); + + size_t line_pose = (actions->max_level_ + 1) * SIDE_SPACE + actions->max_text_size_ + MARGIN * 2; + + drawVector(start, end, line_pose); + + for(auto act : actions->actions_) + drawAction(act.second, line_pose, actions->max_level_, start); + + for(auto evt : events->events) + drawEvent(evt, line_pose, start); + + if(file_name != "") + { + std::cout << "Save image " << file_name << std::endl; + + if((height != 1) && (width != 1)) + cv::imwrite(file_name.c_str(), cv::cvarrToMat(image_)); + } + + if(image_ != nullptr) + cvReleaseImage(&image_); +} + +void TimelineDrawer::drawVector(size_t start, size_t end, size_t pose) +{ + cvLine(image_, cvPoint(pose, MARGIN), + cvPoint(pose, MARGIN + (end - start) * UNIT_SPACE), + cvScalar(50,50,50), 2); + + CvFont font; + cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); + + for(size_t i = 0; i < (end - start) + 1; i++) + { + cvLine(image_, cvPoint(pose - MARK_WIDTH/2, MARGIN + i * UNIT_SPACE), + cvPoint(pose + MARK_WIDTH/2, MARGIN + i * UNIT_SPACE), + cvScalar(50,50,50), 2); + + std::string txt_num = std::to_string(start + i); + + cvPutText(image_, txt_num.c_str(), cvPoint(pose - getTextSize(txt_num, &font) - 2,MARGIN + i * UNIT_SPACE - 2), &font, + cvScalar(50,50,50)); + } +} + +void TimelineDrawer::drawAction(const action_t& action, size_t line_pose, size_t max_level, size_t start_time) +{ + std::cout << "draw action " << action.name << std::endl; + size_t x_end_pose = line_pose; + size_t x_mid_pose = x_end_pose - action.level * SIDE_SPACE; + size_t x_start_pose = x_end_pose - (max_level + 1) * SIDE_SPACE; + + size_t y_start_pose = MARGIN + (action.start.getTime() - start_time) * UNIT_SPACE; + size_t y_end_pose = MARGIN + (action.end.value().getTime() - start_time) * UNIT_SPACE; + size_t y_mid_pose = y_start_pose + EDGE_RADIUS; + + if(action.start.getTime() != action.end.value().getTime()) + { + cvLine(image_, cvPoint(x_end_pose, y_end_pose), + cvPoint(x_mid_pose + EDGE_RADIUS, y_end_pose), + cvScalar(32, 20, 122), 4); + + cvLine(image_, cvPoint(x_end_pose, y_start_pose), + cvPoint(x_mid_pose + EDGE_RADIUS, y_start_pose), + cvScalar(32, 20, 122), 4); + + cvLine(image_, cvPoint(x_mid_pose, y_start_pose + EDGE_RADIUS), + cvPoint(x_mid_pose, y_end_pose - EDGE_RADIUS), + cvScalar(32, 20, 122), 4); + + drawElipseStart(x_mid_pose, y_start_pose); + drawElipseEnd(x_mid_pose, y_end_pose); + + cvLine(image_, cvPoint(x_start_pose, y_mid_pose), + cvPoint(x_mid_pose, y_mid_pose), + cvScalar(32, 20, 122), 4); + } + else + { + cvLine(image_, cvPoint(x_end_pose, y_end_pose), + cvPoint(x_mid_pose, y_end_pose), + cvScalar(32, 20, 122), 4); + + y_mid_pose = y_start_pose; + cvLine(image_, cvPoint(x_start_pose, y_mid_pose), + cvPoint(x_mid_pose, y_mid_pose), + cvScalar(32, 20, 122), 4); + } + + CvFont font; + cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); + cvPutText(image_, action.name.c_str(), cvPoint(x_start_pose - getTextSize(action.name, &font) - 2, y_mid_pose), &font, + cvScalar(32, 20, 122)); +} + +void TimelineDrawer::drawEvent(const event_t& event, size_t line_pose, size_t start_time) +{ + size_t x_start_pose = line_pose; + size_t x_end_pose = x_start_pose + SIDE_SPACE; + + size_t y_pose = MARGIN + (event.time_point - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(x_start_pose, y_pose), + cvPoint(x_end_pose, y_pose), + cvScalar(89, 26, 16), 4); + + CvFont font; + cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); + cvPutText(image_, event.data.c_str(), cvPoint(x_end_pose + 2, y_pose), &font, + cvScalar(89, 26, 16)); +} + +size_t TimelineDrawer::getTextSize(const std::string& txt, CvFont* font) +{ + CvSize size; + int baseline; + cvGetTextSize(txt.c_str(), font, &size, &baseline); + return size.width; +} + +void TimelineDrawer::drawElipseStart(size_t x, size_t y) +{ + cvEllipse(image_, cvPoint(x+EDGE_RADIUS,y+EDGE_RADIUS), cvSize(EDGE_RADIUS, EDGE_RADIUS), 180, 0, 90, cvScalar(32, 20, 122), 4); +} + +void TimelineDrawer::drawElipseEnd(size_t x, size_t y) +{ + cvEllipse(image_, cvPoint(x+EDGE_RADIUS,y-EDGE_RADIUS), cvSize(EDGE_RADIUS, EDGE_RADIUS), 90, 0, 90, cvScalar(32, 20, 122), 4); +} + +} // namespace mementar diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp new file mode 100644 index 0000000..6afbb19 --- /dev/null +++ b/src/graphical/timeline/main.cpp @@ -0,0 +1,169 @@ +#include "mementar/core/memGraphs/Timeline.h" + +#include "mementar/graphical/timeline/ActionReader.h" +#include "mementar/graphical/timeline/EventReader.h" +#include "mementar/graphical/timeline/TimelineDrawer.h" + +/*mementar::Timeline* getTimeline() +{ + mementar::Timeline* timeline = new mementar::Timeline(); + + timeline->actions.add(new mementar::Action("blue_pick_1", mementar::SoftPoint(35, 36), 37)); + timeline->actions.add(new mementar::Action("blue_place_1", 37, mementar::SoftPoint(41, 42))); + timeline->actions.add(new mementar::Action("monitor_1", 43, 51)); + timeline->actions.add(new mementar::Action("explain_goal_1", 69, 72)); + timeline->actions.add(new mementar::Action("explain_action_1", 74, 76)); + timeline->actions.add(new mementar::Action("rob_pick_1", 76, 91)); + timeline->actions.add(new mementar::Action("rob_ack_1", 91, 91)); + timeline->actions.add(new mementar::Action("explain_action_2", 95, 98)); + timeline->actions.add(new mementar::Action("rob_drop_1", 100, 110)); + timeline->actions.add(new mementar::Action("rob_ack_2", 110, 110)); + timeline->actions.add(new mementar::Action("explain_loc_1", 116, 119)); + timeline->actions.add(new mementar::Action("explain_action_3", 131, 134)); + timeline->actions.add(new mementar::Action("green_pick_1", mementar::SoftPoint(132, 133), mementar::SoftPoint(134, 135))); + timeline->actions.add(new mementar::Action("explain_action_4", 142, 144)); + timeline->actions.add(new mementar::Action("green_place_1", mementar::SoftPoint(143, 144), 145)); + timeline->actions.add(new mementar::Action("rob_ack_3", 148, 149)); + timeline->actions.add(new mementar::Action("explain_action_5", 157, 159)); + timeline->actions.add(new mementar::Action("rob_pick_2", 158, 163)); + timeline->actions.add(new mementar::Action("rob_ack_4", 165, 165)); + timeline->actions.add(new mementar::Action("explain_action_6", 167, 170)); + timeline->actions.add(new mementar::Action("rob_drop_2", 170, 174)); + timeline->actions.add(new mementar::Action("rob_ack_5", 176, 176)); + + timeline->events.add(new mementar::ContextualizedEvent("e0", mementar::Event("pr2|isInRoom|expe_room", 4))); + timeline->events.add(new mementar::ContextualizedEvent("e1", mementar::Event("grey_box|isOn|Table_1", 5))); + timeline->events.add(new mementar::ContextualizedEvent("e2", mementar::Event("tape_1|isOn|Table_1", 5))); + timeline->events.add(new mementar::ContextualizedEvent("e3", mementar::Event("tape_2|isIn|storage_area", 5))); + timeline->events.add(new mementar::ContextualizedEvent("e4", mementar::Event("hum_green|isInRoom|expe_room", 6,7))); + timeline->events.add(new mementar::ContextualizedEvent("e5", mementar::Event(mementar::Fact("hum_green|isInRoom|expe_room", false), mementar::SoftPoint(25,26)))); + timeline->events.add(new mementar::ContextualizedEvent("e6", mementar::Event("hum_blue|isInRoom|expe_room", 30,31))); + timeline->events.add(new mementar::ContextualizedEvent("e7", mementar::Event("tape_1|isInHand|hum_blue", 37))); + timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); + timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); + timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); + timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), 42))); + timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); + timeline->events.add(new mementar::ContextualizedEvent("e13", mementar::Event("hum_green|isInRoom|expe_room", 53))); + timeline->events.add(new mementar::ContextualizedEvent("e14", mementar::Event("tape_2|isInGripper|pr2", 86))); + timeline->events.add(new mementar::ContextualizedEvent("e15", mementar::Event(mementar::Fact("tape_2|isIn|storage_area", false), 101))); + timeline->events.add(new mementar::ContextualizedEvent("e16", mementar::Event(mementar::Fact("tape_2|isInGripper|pr2", false), 107))); + timeline->events.add(new mementar::ContextualizedEvent("e17", mementar::Event("tape_2|isIn|pink_box", 107,110))); + timeline->events.add(new mementar::ContextualizedEvent("e18", mementar::Event("tape_1|isInHand|hum_green", 133, 134))); + timeline->events.add(new mementar::ContextualizedEvent("e19", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 134))); + timeline->events.add(new mementar::ContextualizedEvent("e20", mementar::Event(mementar::Fact("tape_1|isBehind|grey_box", false), 134))); + timeline->events.add(new mementar::ContextualizedEvent("e21", mementar::Event("tape_1|isIn|storage_area", 145))); + timeline->events.add(new mementar::ContextualizedEvent("e23", mementar::Event(mementar::Fact("tape_1|isInHand|hum_green", false), 145))); + timeline->events.add(new mementar::ContextualizedEvent("e24", mementar::Event("tape_1|isInGripper|pr2", 162))); + timeline->events.add(new mementar::ContextualizedEvent("e25", mementar::Event(mementar::Fact("tape_1|isIn|storage_area", false), 170))); + timeline->events.add(new mementar::ContextualizedEvent("e26", mementar::Event(mementar::Fact("tape_1|isInGripper|pr2", false), 173))); + timeline->events.add(new mementar::ContextualizedEvent("e27", mementar::Event("tape_1|isIn|pink_box", 173,175))); + + return timeline; +}*/ + + +/* HUMAN GREEN*/ +/*mementar::Timeline* getTimeline() +{ + mementar::Timeline* timeline = new mementar::Timeline(); + + timeline->actions.add(new mementar::Action("explain_goal_1", 69, 72)); + timeline->actions.add(new mementar::Action("explain_action_1", 74, 76)); + timeline->actions.add(new mementar::Action("rob_pick_1", 76, 91)); + timeline->actions.add(new mementar::Action("rob_ack_1", 91, 91)); + timeline->actions.add(new mementar::Action("explain_action_2", 95, 98)); + timeline->actions.add(new mementar::Action("rob_drop_1", 100, 110)); + timeline->actions.add(new mementar::Action("rob_ack_2", 110, 110)); + timeline->actions.add(new mementar::Action("explain_loc_1", 116, 119)); + timeline->actions.add(new mementar::Action("explain_action_3", 131, 134)); + timeline->actions.add(new mementar::Action("green_pick_1", mementar::SoftPoint(132, 133), mementar::SoftPoint(134, 135))); + timeline->actions.add(new mementar::Action("explain_action_4", 142, 144)); + timeline->actions.add(new mementar::Action("green_place_1", mementar::SoftPoint(143, 144), 145)); + timeline->actions.add(new mementar::Action("rob_ack_3", 148, 149)); + timeline->actions.add(new mementar::Action("explain_action_5", 157, 159)); + timeline->actions.add(new mementar::Action("rob_pick_2", 158, 163)); + timeline->actions.add(new mementar::Action("rob_ack_4", 165, 165)); + timeline->actions.add(new mementar::Action("explain_action_6", 167, 170)); + timeline->actions.add(new mementar::Action("rob_drop_2", 170, 174)); + timeline->actions.add(new mementar::Action("rob_ack_5", 176, 176)); + + timeline->events.add(new mementar::ContextualizedEvent("e0", mementar::Event("pr2|isInRoom|expe_room", 6,7))); + timeline->events.add(new mementar::ContextualizedEvent("e1", mementar::Event("grey_box|isOn|Table_1", 7, 8))); + timeline->events.add(new mementar::ContextualizedEvent("e2", mementar::Event("tape_1|isOn|Table_1", 7, 8))); + timeline->events.add(new mementar::ContextualizedEvent("e3", mementar::Event("tape_2|isIn|storage_area", 7.8))); + timeline->events.add(new mementar::ContextualizedEvent("e4", mementar::Event("hum_green|isInRoom|expe_room", 6,7))); + timeline->events.add(new mementar::ContextualizedEvent("e5", mementar::Event(mementar::Fact("hum_green|isInRoom|expe_room", false), mementar::SoftPoint(25,26)))); + + timeline->events.add(new mementar::ContextualizedEvent("e13", mementar::Event("hum_green|isInRoom|expe_room", 53))); + timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 54))); + timeline->events.add(new mementar::ContextualizedEvent("e14", mementar::Event("tape_2|isInGripper|pr2", 86))); + timeline->events.add(new mementar::ContextualizedEvent("e15", mementar::Event(mementar::Fact("tape_2|isIn|storage_area", false), 101))); + timeline->events.add(new mementar::ContextualizedEvent("e16", mementar::Event(mementar::Fact("tape_2|isInGripper|pr2", false), 107))); + timeline->events.add(new mementar::ContextualizedEvent("e17", mementar::Event("tape_2|isIn|pink_box", 107,110))); + + timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 117, 119))); + timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 117, 119))); + + timeline->events.add(new mementar::ContextualizedEvent("e18", mementar::Event("tape_1|isInHand|hum_green", 133, 134))); + timeline->events.add(new mementar::ContextualizedEvent("e19", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 134))); + timeline->events.add(new mementar::ContextualizedEvent("e20", mementar::Event(mementar::Fact("tape_1|isBehind|grey_box", false), 134))); + timeline->events.add(new mementar::ContextualizedEvent("e21", mementar::Event("tape_1|isIn|storage_area", 145))); + timeline->events.add(new mementar::ContextualizedEvent("e23", mementar::Event(mementar::Fact("tape_1|isInHand|hum_green", false), 145))); + timeline->events.add(new mementar::ContextualizedEvent("e24", mementar::Event("tape_1|isInGripper|pr2", 162))); + timeline->events.add(new mementar::ContextualizedEvent("e25", mementar::Event(mementar::Fact("tape_1|isIn|storage_area", false), 170))); + timeline->events.add(new mementar::ContextualizedEvent("e26", mementar::Event(mementar::Fact("tape_1|isInGripper|pr2", false), 173))); + timeline->events.add(new mementar::ContextualizedEvent("e27", mementar::Event("tape_1|isIn|pink_box", 173,175))); + + return timeline; +}*/ + + +// Human bleu +/*mementar::Timeline* getTimeline() +{ + mementar::Timeline* timeline = new mementar::Timeline(); + + timeline->actions.add(new mementar::Action("blue_pick_1", mementar::SoftPoint(35, 36), 37)); + timeline->actions.add(new mementar::Action("blue_place_1", 37, mementar::SoftPoint(41, 42))); + timeline->actions.add(new mementar::Action("monitor_1", 43, 51)); + + timeline->events.add(new mementar::ContextualizedEvent("e0", mementar::Event("pr2|isInRoom|expe_room", 30, 31))); + timeline->events.add(new mementar::ContextualizedEvent("e1", mementar::Event("grey_box|isOn|Table_1", 32,34))); + timeline->events.add(new mementar::ContextualizedEvent("e2", mementar::Event("tape_1|isOn|Table_1", 32,34))); + timeline->events.add(new mementar::ContextualizedEvent("e3", mementar::Event("tape_2|isIn|storage_area", 32,34))); + timeline->events.add(new mementar::ContextualizedEvent("e6", mementar::Event("hum_blue|isInRoom|expe_room", 30,31))); + timeline->events.add(new mementar::ContextualizedEvent("e7", mementar::Event("tape_1|isInHand|hum_blue", 37))); + timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); + timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); + timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); + timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), 42))); + timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); + + return timeline; +}*/ + +int main(int argc, char** argv) +{ + mementar::Timeline* timeline = getTimeline(); + + CvFont font; + cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); + + mementar::ActionReader actions; + actions.read(&timeline->events, &font); + + mementar::EventReader events; + events.read(&timeline->events, &font); + + mementar::TimelineDrawer drawer; + drawer.draw("human_bleu.png", timeline, &actions, &events); + + /*std::cout << "width = " << ontologenius::commit_t::global_width << std::endl; + std::cout << "height = " << ontologenius::commit_t::global_height << std::endl; + + ontologenius::TreeDrawer drawer; + drawer.draw(getFileName(path), commit, commit_only);*/ + + return 0; +} From b81e055e394ce42b20d357ef1146b7044b947eca Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jun 2020 17:06:55 +0200 Subject: [PATCH 40/95] [FIX] timeline drawing test file --- src/graphical/timeline/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index 6afbb19..cb6a198 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -4,7 +4,7 @@ #include "mementar/graphical/timeline/EventReader.h" #include "mementar/graphical/timeline/TimelineDrawer.h" -/*mementar::Timeline* getTimeline() +mementar::Timeline* getTimeline() { mementar::Timeline* timeline = new mementar::Timeline(); @@ -60,7 +60,7 @@ timeline->events.add(new mementar::ContextualizedEvent("e27", mementar::Event("tape_1|isIn|pink_box", 173,175))); return timeline; -}*/ +} /* HUMAN GREEN*/ From 90172ff87967c7933bc8907c532de9c5c8f3e5ad Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 23 Jun 2020 17:29:36 +0200 Subject: [PATCH 41/95] [REFACT] use SoftPoint::Ttime --- .../mementar/core/memGraphs/Branchs/types/Event.h | 2 +- .../core/memGraphs/Branchs/types/SoftPoint.h | 14 ++++++++------ src/graphical/timeline/EventReader.cpp | 2 +- src/graphical/timeline/main.cpp | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/mementar/core/memGraphs/Branchs/types/Event.h b/include/mementar/core/memGraphs/Branchs/types/Event.h index c295377..d2ee685 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Event.h +++ b/include/mementar/core/memGraphs/Branchs/types/Event.h @@ -12,7 +12,7 @@ namespace mementar { class Event : public SoftPoint, public Fact { public: - Event(const std::string& data, size_t t_start, std::experimental::optional t_end = std::experimental::nullopt) : SoftPoint(t_start, t_end), Fact(data) + Event(const std::string& data, SoftPoint::Ttime t_start, std::experimental::optional t_end = std::experimental::nullopt) : SoftPoint(t_start, t_end), Fact(data) { } diff --git a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h index b2717c0..95acc6f 100644 --- a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h +++ b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h @@ -9,7 +9,10 @@ namespace mementar { class SoftPoint { public: - SoftPoint(size_t t_start, std::experimental::optional t_end = std::experimental::nullopt) + //typedef size_t Ttime; + typedef float Ttime; + + SoftPoint(Ttime t_start, std::experimental::optional t_end = std::experimental::nullopt) { t_start_ = t_start; t_end_ = t_end; @@ -24,14 +27,13 @@ class SoftPoint } bool isInstantaneous() const { return t_end_ == std::experimental::nullopt; } - size_t getTime() const { return t_; } - size_t getTimeStart() const { return t_start_; } - size_t getTimeEnd() const { return t_end_.value_or(t_start_); } - size_t getTransitionDuration() const { return t_end_.value_or(t_start_) - t_start_; } + Ttime getTime() const { return t_; } + Ttime getTimeStart() const { return t_start_; } + Ttime getTimeEnd() const { return t_end_.value_or(t_start_); } + Ttime getTransitionDuration() const { return t_end_.value_or(t_start_) - t_start_; } std::string toString() const { return "[" + std::to_string(t_start_) + std::string(t_end_ ? "," + std::to_string(t_end_.value()) : "") + "]"; } - typedef size_t Ttime; protected: Ttime t_start_; diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/EventReader.cpp index e039050..47cc5e7 100644 --- a/src/graphical/timeline/EventReader.cpp +++ b/src/graphical/timeline/EventReader.cpp @@ -28,7 +28,7 @@ void EventReader::read(EventGraph* graph, CvFont* font) getTextSize(group_evt.data, font); } - node = dynamic_cast*>(node->getNextNode()); + node = dynamic_cast*>(node->getNextNode()); } } diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index cb6a198..5feefa2 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -157,7 +157,7 @@ int main(int argc, char** argv) events.read(&timeline->events, &font); mementar::TimelineDrawer drawer; - drawer.draw("human_bleu.png", timeline, &actions, &events); + drawer.draw("out.png", timeline, &actions, &events); /*std::cout << "width = " << ontologenius::commit_t::global_width << std::endl; std::cout << "height = " << ontologenius::commit_t::global_height << std::endl; From 1256632c9ca0565bf026e7668bd8c4a7385ed2fe Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 24 Jun 2020 09:15:20 +0200 Subject: [PATCH 42/95] [REFACT] move Display in graphical folder --- include/mementar/{core/utility => graphical}/Display.h | 0 src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp | 2 +- src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp | 2 +- .../LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp | 2 +- src/core/LtManagement/EpisodicTree/Context.cpp | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename include/mementar/{core/utility => graphical}/Display.h (100%) diff --git a/include/mementar/core/utility/Display.h b/include/mementar/graphical/Display.h similarity index 100% rename from include/mementar/core/utility/Display.h rename to include/mementar/graphical/Display.h diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp index d1c3463..0095c25 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp @@ -3,7 +3,7 @@ #include #include -#include "mementar/core/utility/Display.h" +#include "mementar/graphical/Display.h" namespace mementar { diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp index 7906aff..43bffb7 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp @@ -2,7 +2,7 @@ #include #include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h" -#include "mementar/core/utility/Display.h" +#include "mementar/graphical/Display.h" namespace mementar { diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp index 7f0f1e4..5b220eb 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp @@ -1,7 +1,7 @@ #include "mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h" -#include "mementar/core/utility/Display.h" #include "mementar/core/LtManagement/archiving_compressing/compressing/LzCompress.h" +#include "mementar/graphical/Display.h" namespace mementar { diff --git a/src/core/LtManagement/EpisodicTree/Context.cpp b/src/core/LtManagement/EpisodicTree/Context.cpp index a7e8b9d..0c3518f 100644 --- a/src/core/LtManagement/EpisodicTree/Context.cpp +++ b/src/core/LtManagement/EpisodicTree/Context.cpp @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/utility/Display.h" +#include "mementar/graphical/Display.h" namespace mementar { From 97073140a16caa6b9ea6b63f946f136363a8ef27 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 24 Jun 2020 11:14:12 +0200 Subject: [PATCH 43/95] [UPDATE] draw softpoint intervals --- .../core/memGraphs/Branchs/types/SoftPoint.h | 7 ++++ .../mementar/graphical/timeline/EventReader.h | 4 ++- src/graphical/timeline/EventReader.cpp | 5 +-- src/graphical/timeline/TimelineDrawer.cpp | 32 ++++++++++++++++++- src/graphical/timeline/main.cpp | 4 +-- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h index 95acc6f..e4dbca5 100644 --- a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h +++ b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h @@ -26,6 +26,13 @@ class SoftPoint t_ = t_start_ + (t_end_.value_or(t_start_) - t_start_) / 2; } + SoftPoint(const SoftPoint* other) + { + t_start_ = other->t_start_; + t_end_ = other->t_end_; + t_ = t_start_ + (t_end_.value_or(t_start_) - t_start_) / 2; + } + bool isInstantaneous() const { return t_end_ == std::experimental::nullopt; } Ttime getTime() const { return t_; } Ttime getTimeStart() const { return t_start_; } diff --git a/include/mementar/graphical/timeline/EventReader.h b/include/mementar/graphical/timeline/EventReader.h index 50d17ca..23320dc 100644 --- a/include/mementar/graphical/timeline/EventReader.h +++ b/include/mementar/graphical/timeline/EventReader.h @@ -12,8 +12,10 @@ namespace mementar { struct event_t { + event_t(SoftPoint::Ttime time) : time_point(time) {} + std::string data; - size_t time_point; + SoftPoint time_point; }; class EventReader diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/EventReader.cpp index 47cc5e7..45d48ee 100644 --- a/src/graphical/timeline/EventReader.cpp +++ b/src/graphical/timeline/EventReader.cpp @@ -11,14 +11,15 @@ void EventReader::read(EventGraph* graph, CvFont* font) while(node != nullptr) { - event_t group_evt; - group_evt.time_point = node->getKey(); + event_t group_evt(node->getKey()); for(auto evt : node->getData()) { if(dynamic_cast(evt)->isPartOfAction() == false) { auto event = dynamic_cast(evt); group_evt.data += (group_evt.data == "" ? "" : " -- ") + event->Fact::toString(); + if(event->getTransitionDuration() > group_evt.time_point.getTransitionDuration()) + group_evt.time_point = SoftPoint(event); } } diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index 11c9142..2469ba6 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -108,6 +108,26 @@ void TimelineDrawer::drawAction(const action_t& action, size_t line_pose, size_t cvScalar(32, 20, 122), 4); } + if(action.start.isInstantaneous() == false) + { + size_t y_soft_start_pose = MARGIN + (action.start.getTimeStart() - start_time) * UNIT_SPACE; + size_t y_soft_end_pose = MARGIN + (action.start.getTimeEnd() - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(line_pose - 4, y_soft_start_pose), + cvPoint(line_pose - 4, y_soft_end_pose), + cvScalar(114,102,204), 8); + } + + if(action.end.value().isInstantaneous() == false) + { + size_t y_soft_start_pose = MARGIN + (action.end.value().getTimeStart() - start_time) * UNIT_SPACE; + size_t y_soft_end_pose = MARGIN + (action.end.value().getTimeEnd() - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(line_pose - 4, y_soft_start_pose), + cvPoint(line_pose - 4, y_soft_end_pose), + cvScalar(114,102,204), 8); + } + CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); cvPutText(image_, action.name.c_str(), cvPoint(x_start_pose - getTextSize(action.name, &font) - 2, y_mid_pose), &font, @@ -119,12 +139,22 @@ void TimelineDrawer::drawEvent(const event_t& event, size_t line_pose, size_t st size_t x_start_pose = line_pose; size_t x_end_pose = x_start_pose + SIDE_SPACE; - size_t y_pose = MARGIN + (event.time_point - start_time) * UNIT_SPACE; + size_t y_pose = MARGIN + (event.time_point.getTime() - start_time) * UNIT_SPACE; cvLine(image_, cvPoint(x_start_pose, y_pose), cvPoint(x_end_pose, y_pose), cvScalar(89, 26, 16), 4); + if(event.time_point.isInstantaneous() == false) + { + size_t y_soft_start_pose = MARGIN + (event.time_point.getTimeStart() - start_time) * UNIT_SPACE; + size_t y_soft_end_pose = MARGIN + (event.time_point.getTimeEnd() - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(line_pose + 4, y_soft_start_pose), + cvPoint(line_pose + 4, y_soft_end_pose), + cvScalar(149,86,86), 8); + } + CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); cvPutText(image_, event.data.c_str(), cvPoint(x_end_pose + 2, y_pose), &font, diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index 5feefa2..03498e7 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -42,7 +42,7 @@ mementar::Timeline* getTimeline() timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); - timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), 42))); + timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); timeline->events.add(new mementar::ContextualizedEvent("e13", mementar::Event("hum_green|isInRoom|expe_room", 53))); timeline->events.add(new mementar::ContextualizedEvent("e14", mementar::Event("tape_2|isInGripper|pr2", 86))); @@ -137,7 +137,7 @@ mementar::Timeline* getTimeline() timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); - timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), 42))); + timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); return timeline; From 7d5325d2b253abc9189375250a0c85d47588228e Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Sun, 12 Jul 2020 15:57:47 +0200 Subject: [PATCH 44/95] [REFACT] Btree and Btree extensions --- CMakeLists.txt | 4 - .../mementar/core/memGraphs/Btree/BplusTree.h | 141 ++++++ include/mementar/core/memGraphs/Btree/Btree.h | 474 +++++++++++++++--- .../mementar/core/memGraphs/Btree/BtreeLeaf.h | 52 -- .../core/memGraphs/Btree/BtreeLeafBase.h | 41 ++ .../core/memGraphs/Btree/BtreeLeafNode.h | 214 -------- .../mementar/core/memGraphs/Btree/BtreeNode.h | 205 +------- .../memGraphs/DoublyLinkedList/DllCargoNode.h | 25 - .../DoublyLinkedList/DllLinkedElement.h | 32 -- .../core/memGraphs/DoublyLinkedList/DllNode.h | 57 --- .../memGraphs/EventLinkedList/EllElement.h | 33 -- .../core/memGraphs/EventLinkedList/EllNode.h | 41 -- .../core/memGraphs/ExtendedBtree/DlBtree.h | 116 +++++ .../memGraphs/ExtendedBtree/EventLinkedLeaf.h | 336 +++++++++++++ src/core/memGraphs/Btree/CMakeLists.txt | 6 - src/core/memGraphs/Btree/tests/btree_test.cpp | 76 ++- src/core/memGraphs/Btree/tests/cargo.cpp | 69 +-- .../memGraphs/Btree/tests/max_insertion.cpp | 8 +- .../DoublyLinkedList/DllCargoNode.cpp | 38 -- .../DoublyLinkedList/DllLinkedElement.cpp | 52 -- .../memGraphs/EventLinkedList/EllElement.cpp | 11 - .../memGraphs/EventLinkedList/EllNode.cpp | 260 ---------- 22 files changed, 1121 insertions(+), 1170 deletions(-) create mode 100644 include/mementar/core/memGraphs/Btree/BplusTree.h delete mode 100644 include/mementar/core/memGraphs/Btree/BtreeLeaf.h create mode 100644 include/mementar/core/memGraphs/Btree/BtreeLeafBase.h delete mode 100644 include/mementar/core/memGraphs/Btree/BtreeLeafNode.h delete mode 100644 include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h delete mode 100644 include/mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h delete mode 100644 include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h delete mode 100644 include/mementar/core/memGraphs/EventLinkedList/EllElement.h delete mode 100644 include/mementar/core/memGraphs/EventLinkedList/EllNode.h create mode 100644 include/mementar/core/memGraphs/ExtendedBtree/DlBtree.h create mode 100644 include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h delete mode 100644 src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp delete mode 100644 src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp delete mode 100644 src/core/memGraphs/EventLinkedList/EllElement.cpp delete mode 100644 src/core/memGraphs/EventLinkedList/EllNode.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a56be20..027167f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,10 +101,6 @@ add_library(mementar_memGraphs_lib src/core/memGraphs/Branchs/types/Action.cpp src/core/memGraphs/Branchs/types/Fact.cpp src/core/memGraphs/Branchs/types/Event.cpp - src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp - src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp - src/core/memGraphs/EventLinkedList/EllElement.cpp - src/core/memGraphs/EventLinkedList/EllNode.cpp src/core/memGraphs/Graphs/ActionGraph.cpp src/core/memGraphs/Graphs/EventGraph.cpp ) diff --git a/include/mementar/core/memGraphs/Btree/BplusTree.h b/include/mementar/core/memGraphs/Btree/BplusTree.h new file mode 100644 index 0000000..a82ebcc --- /dev/null +++ b/include/mementar/core/memGraphs/Btree/BplusTree.h @@ -0,0 +1,141 @@ +#ifndef MEMENTAR_BPLUSTREE_H +#define MEMENTAR_BPLUSTREE_H + +#include "mementar/core/memGraphs/Btree/Btree.h" + +namespace mementar { + +template +class BplusLeaf +{ + using LeafType = BtreeLeafBase >; +public: + using DataType = Tdata; + + BplusLeaf() + { + prev_ = nullptr; + next_ = nullptr; + } + + void insert(LeafType* leaf, DataType data) + { + (void)leaf; + payload_.push_back(data); + } + void remove(LeafType* leaf, DataType data) + { + (void)leaf; + for(size_t i = 0; i < payload_.size();) + { + if(payload_[i] == data) + payload_.erase(payload_.begin() + i); + else + i++; + } + } + bool hasData() + { + return (payload_.size() != 0); + } + + std::vector getData() + { + return payload_; + } + + BplusLeaf* getPreviousLeaf() { return prev_; } + BplusLeaf* getNextLeaf() { return next_; } + + void setPreviousLeaf(BplusLeaf* prev) { prev_ = prev; } + void setNextLeaf(BplusLeaf* next) { next_ = next; } + + std::vector payload_; + BplusLeaf* prev_; + BplusLeaf* next_; +private: +}; + +template +class BplusTree : public Btree, N> +{ +public: + template + class BtreeIterator + { + public: + using iterator_category = std::bidirectional_iterator_tag; + using value_type = T; + using pointer = T*; + using reference = T&; + + BtreeIterator(T* ptr = nullptr){ ptr_ = ptr;} + BtreeIterator(const BtreeIterator& other) = default; + + BtreeIterator& operator=(const BtreeIterator& other) = default; + BtreeIterator& operator=(BtreeIterator* other){ ptr_ = other->ptr; return (*this); } + + operator bool() const + { + if(ptr_) + return true; + else + return false; + } + + bool operator==(const BtreeIterator& other)const{ return (ptr_ == other.ptr_); } + bool operator!=(const BtreeIterator& other)const{ return (ptr_ != other.ptr_); } + + BtreeIterator& operator++() { ptr_ = ptr_->getNextLeaf(); return (*this); } + BtreeIterator& operator--() { ptr_ = ptr_->getPreviousLeaf(); return (*this); } + + T& operator*() { return *ptr_; } + const T& operator*() const { return *ptr_; } + T* operator->() { return ptr_; } + + protected: + + T* ptr_; + }; + + template + class BtreeReverseIterator : public BtreeIterator + { + public: + + BtreeReverseIterator(T* ptr = nullptr):BtreeIterator(ptr) {} + BtreeReverseIterator(const BtreeIterator& forward_iterator) { this->ptr_ = *forward_iterator; } + BtreeReverseIterator(const BtreeReverseIterator& other) = default; + + BtreeReverseIterator& operator=(const BtreeReverseIterator& other) = default; + BtreeReverseIterator& operator=(const BtreeIterator& forward_iterator){ this->ptr_ = *forward_iterator; return (*this); } + BtreeReverseIterator& operator=(T* ptr) { this->ptr_ = ptr; return (*this); } + + BtreeReverseIterator& operator++(){ this->ptr_ = this->ptr_->getPreviousLeaf(); return (*this);} + BtreeReverseIterator& operator--(){ this->ptr_ = this->ptr_->getNextLeaf(); return (*this);} + + BtreeIterator base(){BtreeIterator forwardIterator(this->ptr_); ++forwardIterator; return forwardIterator;} + }; + + using iterator = BtreeIterator>; + using const_iterator = BtreeIterator>; + + using reverse_iterator = BtreeReverseIterator>; + using const_reverse_iterator = BtreeReverseIterator>; + + iterator begin() { return iterator(this->getFirst()); } + iterator end() { return iterator(nullptr); } + + const_iterator cbegin() { return const_iterator(this->getFirst()); } + const_iterator cend() { return const_iterator(nullptr); } + + reverse_iterator rbegin() { return reverse_iterator(this->getLast()); } + reverse_iterator rend() { return reverse_iterator(nullptr); } + + const_reverse_iterator crbegin() { return const_reverse_iterator(this->getLast()); } + const_reverse_iterator crend() { return const_reverse_iterator(nullptr); } +}; + +} // namespace mementar + +#endif // MEMENTAR_BPLUSTREE_H diff --git a/include/mementar/core/memGraphs/Btree/Btree.h b/include/mementar/core/memGraphs/Btree/Btree.h index 265160f..679e360 100644 --- a/include/mementar/core/memGraphs/Btree/Btree.h +++ b/include/mementar/core/memGraphs/Btree/Btree.h @@ -1,29 +1,21 @@ #ifndef MEMENTAR_BTREE_H #define MEMENTAR_BTREE_H -#include -#include - +#include "mementar/core/memGraphs/Btree/BtreeLeafBase.h" #include "mementar/core/memGraphs/Btree/BtreeNode.h" -#include "mementar/core/memGraphs/Btree/BtreeLeafNode.h" -#include "mementar/core/memGraphs/Btree/BtreeLeaf.h" - -#include "mementar/core/memGraphs/DoublyLinkedList/DllNode.h" -namespace mementar -{ +namespace mementar { -template> +template class Btree { - //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); + using Tdata = typename Tleaf::DataType; public: - Btree(size_t order = 10) + Btree() { root_ = nullptr; + first_ = nullptr; last_ = nullptr; - order_ = order; - level_ = 0; nb_data_ = 0; } @@ -31,79 +23,83 @@ class Btree { if(root_ != nullptr) delete root_; - - BtreeLeaf* tmp; - while(last_ != nullptr) - { - tmp = last_; - last_ = static_cast*>(last_->getPreviousNode()); - delete tmp; - } } size_t insert(const Tkey& key, const Tdata& data); bool remove(const Tkey& key, const Tdata& data); - BtreeLeaf* find(const Tkey& key); - BtreeLeaf* findNear(const Tkey& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast() { return last_; } + BtreeLeafBase* find(const Tkey& key); + BtreeLeafBase* findNear(const Tkey& key); + BtreeLeafBase* getFirst() { return first_; } + BtreeLeafBase* getLast() { return last_; } - size_t estimateMinLeaves() - { - return pow((double)order_/2. + 1., (double)level_ - 1.) * root_->getNbChilds(); - } - - size_t estimateMaxLevel(size_t nbLeafs) - { - return log((double)nbLeafs/2.) / log((double)order_/2. + 1) + 1; - } + void displayLinear(int count = -1); + void displayTree(); - size_t getCurrentLevel() { return level_; } +private: + BtreeNode* root_; + BtreeLeafBase* first_; + BtreeLeafBase* last_; - void display(int count = -1); + std::vector*> nodes_; + std::vector*> leafs_; -private: - BtreeNode* root_; - BtreeLeaf* last_; - size_t order_; - size_t level_; size_t nb_data_; + + BtreeLeafBase* insertInLeaf(BtreeNode* node, const Tkey& key, const Tdata& data); + BtreeLeafBase* insertInNode(BtreeNode* node, const Tkey& key, const Tdata& data); + void insertNode(BtreeNode* node, BtreeNode* new_node, const Tkey& key); + bool needBalancing(BtreeNode* node); + void splitLeafNode(BtreeNode* node); + void splitNode(BtreeNode* node); + + bool removeInNode(BtreeNode* node, const Tkey& key, const Tdata& data); + bool removeInLeafNode(BtreeNode* node, const Tkey& key, const Tdata& data); + + BtreeLeafBase* findNearInNode(BtreeNode* node, const Tkey& key); + BtreeLeafBase* findInNode(BtreeNode* node, const Tkey& key); + BtreeLeafBase* findNearInLeafNode(BtreeNode* node, const Tkey& key); + BtreeLeafBase* findInLeafNode(BtreeNode* node, const Tkey& key); + + void displayNode(BtreeNode* node, size_t depth = 0); + void displayLeafNode(BtreeNode* node, size_t depth); }; -template -size_t Btree::insert(const Tkey& key, const Tdata& data) +template +size_t Btree::insert(const Tkey& key, const Tdata& data) { nb_data_++; if(last_ == nullptr) { - root_ = new BtreeLeafNode(order_); - level_ = root_->getLevel(); - last_ = root_->insert(key, data); + root_ = new BtreeNode(); + first_ = insertInLeaf(root_, key, data); + last_ = first_; + leafs_.push_back(first_); + nodes_.push_back(root_); } else { - BtreeLeaf* tmp = root_->insert(key, data); + BtreeLeafBase* tmp = insertInNode(root_, key, data); if(tmp != nullptr) { - if(tmp->operator>(last_)) + leafs_.push_back(tmp); + if(tmp->operator>(*last_)) last_ = tmp; + else if(tmp->operator<(*first_)) + first_ = tmp; if(root_->getMother() != nullptr) - { root_ = root_->getMother(); - level_ = root_->getLevel(); - } } } return nb_data_; } -template -bool Btree::remove(const Tkey& key, const Tdata& data) +template +bool Btree::remove(const Tkey& key, const Tdata& data) { nb_data_--; if(root_ != nullptr) - if(root_->remove(key, data)) + if(removeInNode(root_, key, data)) { nb_data_--; return true; @@ -111,37 +107,332 @@ bool Btree::remove(const Tkey& key, const Tdata& data) return false; } -template -BtreeLeaf* Btree::find(const Tkey& key) +template +BtreeLeafBase* Btree::findNear(const Tkey& key) { if(root_ != nullptr) - return root_->find(key); + return findNearInNode(root_, key); else return nullptr; } -template -BtreeLeaf* Btree::findNear(const Tkey& key) +template +BtreeLeafBase* Btree::find(const Tkey& key) { if(root_ != nullptr) - return root_->findNear(key); + return findInNode(root_, key); else return nullptr; } -template -BtreeLeaf* Btree::getFirst() +template +BtreeLeafBase* Btree::findNearInNode(BtreeNode* node, const Tkey& key) { - if(root_ != nullptr) - return root_->getFirst(); + if(node->isLeafNode()) + return findNearInLeafNode(node, key); + + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] > key) + return findNearInNode(node->childs_[i], key); + } + return findNearInNode(node->childs_.back(), key); +} + +template +BtreeLeafBase* Btree::findInNode(BtreeNode* node, const Tkey& key) +{ + if(node->isLeafNode()) + return findInLeafNode(node, key); + + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] > key) + return findInNode(node->childs_[i], key); + } + return findInNode(node->childs_.back(), key); +} + +template +BtreeLeafBase* Btree::findNearInLeafNode(BtreeNode* node, const Tkey& key) +{ + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] >= key) + return node->leafs_[i]; + } + return node->leafs_.back(); +} + +template +BtreeLeafBase* Btree::findInLeafNode(BtreeNode* node, const Tkey& key) +{ + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] == key) + return node->leafs_[i]; + } + return nullptr; +} + +template +bool Btree::removeInNode(BtreeNode* node, const Tkey& key, const Tdata& data) +{ + if(node->isLeafNode()) + return removeInLeafNode(node, key, data); + + size_t index = node->keys_.size(); + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] > key) + { + index = i; + break; + } + } + return removeInNode(node->childs_[index], key, data); +} + +template +bool Btree::removeInLeafNode(BtreeNode* node, const Tkey& key, const Tdata& data) +{ + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] == key) + { + node->leafs_[i]->remove(node->leafs_[i], data); + if(node->leafs_[i]->hasData() == false) + { + if(node->leafs_[i]->getPreviousLeaf() != nullptr) + node->leafs_[i]->getPreviousLeaf()->setNextLeaf(node->leafs_[i]->getNextLeaf()); + if(node->leafs_[i]->getNextLeaf() != nullptr) + node->leafs_[i]->getNextLeaf()->setPreviousLeaf(node->leafs_[i]->getPreviousLeaf()); + + delete node->leafs_[i]; + node->leafs_.erase(node->leafs_.begin() + i); + node->keys_.erase(node->keys_.begin() + i); + + if(node->leafs_.size() == 0) + std::cout << "a node is empty but will not be destroyed" << std::endl; + } + return true; + } + } + return false; +} + +template +BtreeLeafBase* Btree::insertInLeaf(BtreeNode* node, const Tkey& key, const Tdata& data) +{ + BtreeLeafBase* res = nullptr; + + if(node->leafs_.size() == 0) + { + node->keys_.push_back(key); + res = new BtreeLeafBase(key); + node->leafs_.push_back(res); + res->setMother(node); + res->insert(res, data); + return res; + } else - return nullptr; + { + BtreeLeafBase* last = nullptr; + if(node->leafs_.size()) + last = node->leafs_.back(); + + if(key > node->keys_.back()) + { + node->keys_.push_back(key); + res = new BtreeLeafBase(key); + node->leafs_.push_back(res); + res->setNextLeaf(last->getNextLeaf()); + last->setNextLeaf(res); + res->setPreviousLeaf(last); + res->setMother(node); + res->insert(res, data); + } + else if(node->keys_.back() == key) + { + last->insert(last, data); + } + else + { + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(node->keys_[i] == key) + { + node->leafs_[i]->insert(node->leafs_[i], data); + } + else if(node->keys_[i] > key) + { + res = new BtreeLeafBase(key); + // here last is the next node of res + last = node->leafs_[i]; + res->setNextLeaf(last); + res->setPreviousLeaf(last->getPreviousLeaf()); + if(res->getPreviousLeaf()) + res->getPreviousLeaf()->setNextLeaf(res); + if(res->getNextLeaf()) + res->getNextLeaf()->setPreviousLeaf(res); + node->keys_.insert(node->keys_.begin() + i, key); + node->leafs_.insert(node->leafs_.begin() + i, res); + res->setMother(node); + res->insert(res, data); + } + break; + } + } + } + + if(needBalancing(node)) + { + if(node->isLeafNode()) + splitLeafNode(node); + else + splitNode(node); + } + + return res; +} + +template +BtreeLeafBase* Btree::insertInNode(BtreeNode* node, const Tkey& key, const Tdata& data) +{ + if(node->isLeafNode()) + return insertInLeaf(node, key, data); + else + { + size_t index; + for(index = 0; index < node->keys_.size(); index++) + { + if(key < node->keys_[index]) + break; + } + return insertInNode(node->childs_[index], key, data); + } +} + +template +void Btree::insertNode(BtreeNode* node, BtreeNode* new_node, const Tkey& key) +{ + if(node->childs_.size() == 0) + { + node->childs_.push_back(new_node); + new_node->setMother(node); + return; + } + else + { + if(node->keys_.size() == 0) + { + node->keys_.push_back(key); + node->childs_.push_back(new_node); + new_node->setMother(node); + } + else if(key > node->keys_.back()) + { + node->keys_.push_back(key); + node->childs_.push_back(new_node); + new_node->setMother(node); + } + else + { + for(size_t i = 0; i < node->keys_.size(); i++) + { + if(key < node->keys_[i]) + { + node->keys_.insert(node->keys_.begin() + i, key); + node->childs_.insert(node->childs_.begin() + i + 1, new_node); + new_node->setMother(node); + break; + } + } + } + } + + if(needBalancing(node)) + splitNode(node); +} + +template +bool Btree::needBalancing(BtreeNode* node) +{ + if(node->isLeafNode()) + return node->leafs_.size() > N; + else + return node->childs_.size() > N; } -template -void Btree::display(int count) +template +void Btree::splitLeafNode(BtreeNode* node) { - BtreeLeaf* tmp = last_; + BtreeNode* new_leaf_node = new BtreeNode(); + + size_t half_order = N/2; + for(size_t i = 0; i < half_order; i++) + { + new_leaf_node->leafs_.insert(new_leaf_node->leafs_.begin(), node->leafs_.back()); + node->leafs_.pop_back(); + new_leaf_node->leafs_[i]->setMother(new_leaf_node); + + new_leaf_node->keys_.insert(new_leaf_node->keys_.begin(), node->keys_.back()); + node->keys_.pop_back(); + } + + if(node->mother_ != nullptr) + { + insertNode(node->mother_, new_leaf_node, new_leaf_node->keys_[0]); + } + else + { + BtreeNode* new_mother = new BtreeNode(); + nodes_.push_back(new_mother); + insertNode(new_mother, node, node->keys_[0]); + insertNode(new_mother, new_leaf_node, new_leaf_node->keys_[0]); + } +} + +template +void Btree::splitNode(BtreeNode* node) +{ + BtreeNode* new_node = new BtreeNode(); + nodes_.push_back(new_node); + + size_t half_order = N/2 - 1; + for(size_t i = 0; i < half_order; i++) + { + new_node->childs_.insert(new_node->childs_.begin(), node->childs_.back()); + node->childs_.pop_back(); + new_node->childs_[i]->setMother(new_node); + + new_node->keys_.insert(new_node->keys_.begin(), node->keys_.back()); + node->keys_.pop_back(); + } + + new_node->childs_.insert(new_node->childs_.begin(), node->childs_.back()); + node->childs_.pop_back(); + new_node->childs_[half_order]->setMother(new_node); + + if(node->mother_ != nullptr) + { + insertNode(node->mother_, new_node, node->keys_.back()); + node->keys_.pop_back(); + } + else + { + BtreeNode* new_mother = new BtreeNode(); + nodes_.push_back(new_mother); + insertNode(new_mother, node, node->keys_.back()); + insertNode(new_mother, new_node, node->keys_.back()); + node->keys_.pop_back(); + } +} + +template +void Btree::displayLinear(int count) +{ + BtreeLeafBase* tmp = first_; int cpt = 0; std::cout << "******" << std::endl; while((tmp != nullptr) && ((cpt < count) || (count == -1))) @@ -150,12 +441,53 @@ void Btree::display(int count) for(auto data : tmp->getData()) std::cout << data << " : "; std::cout << std::endl; - tmp = static_cast*>(tmp->getPreviousNode()); + tmp = tmp->getNextLeaf(); cpt++; } std::cout << "******" << std::endl; +} + +template +void Btree::displayTree() +{ + std::cout << "******" << std::endl; if(root_) - root_->display(); + displayNode(root_); + std::cout << "******" << std::endl; +} + +template +void Btree::displayNode(BtreeNode* node, size_t depth) +{ + size_t depth_1 = depth + 1; + + if(node->isLeafNode()) + displayLeafNode(node, depth_1); + else + { + for(size_t i = 0; i < node->keys_.size(); i++) + { + displayNode(node->childs_[i], depth_1); + for(size_t j = 0; j < depth; j++) + std::cout << "\t"; + std::cout << node->keys_[i] << std::endl; + } + displayNode(node->childs_[node->keys_.size()], depth_1); + } +} + +template +void Btree::displayLeafNode(BtreeNode* node, size_t depth) +{ + for(size_t i = 0; i < node->keys_.size(); i++) + { + for(size_t j = 0; j < depth; j++) + std::cout << "\t"; + std::cout << node->keys_[i] << " => "; + for(auto data : node->leafs_[i]->getData()) + std::cout << data << " : "; + std::cout << std::endl; + } } } // namespace mementar diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeaf.h b/include/mementar/core/memGraphs/Btree/BtreeLeaf.h deleted file mode 100644 index 251c175..0000000 --- a/include/mementar/core/memGraphs/Btree/BtreeLeaf.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MEMENTAR_BTREELEAF_H -#define MEMENTAR_BTREELEAF_H - -#include - -#include "mementar/core/memGraphs/DoublyLinkedList/DllNode.h" - -namespace mementar -{ - -template -class BtreeLeafNode; - -template> -class BtreeLeaf : public Tnode -{ - //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); -public: - BtreeLeaf(const Tkey& key) : Tnode() - { - mother_ = nullptr; - - key_ = key; - } - - ~BtreeLeaf() { } - - bool operator==(const Tkey& other) { return key_ == other; } - bool operator>(const Tkey& other) { return key_ > other; } - bool operator<(const Tkey& other) { return key_ < other; } - bool operator>=(const Tkey& other) { return ((key_ > other) || (key_ == other)); } - bool operator<=(const Tkey& other) { return ((key_ < other) || (key_ == other)); } - - bool operator==(const BtreeLeaf* other) { return key_ == other->key_; } - bool operator>(const BtreeLeaf* other) { return key_ > other->key_; } - bool operator<(const BtreeLeaf* other) { return key_ < other->key_; } - bool operator>=(const BtreeLeaf* other) { return ((key_ > other->key_) || (key_ == other->key_)); } - bool operator<=(const BtreeLeaf* other) { return ((key_ < other->key_) || (key_ == other->key_)); } - - Tkey getKey() const { return key_; } - - void setMother(BtreeLeafNode* mother) { mother_ = mother; } - BtreeLeafNode* getMother() { return mother_; } - -private: - Tkey key_; - BtreeLeafNode* mother_; -}; - -} // mementar - -#endif // MEMENTAR_BTREELEAF_H diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeafBase.h b/include/mementar/core/memGraphs/Btree/BtreeLeafBase.h new file mode 100644 index 0000000..2c4cd26 --- /dev/null +++ b/include/mementar/core/memGraphs/Btree/BtreeLeafBase.h @@ -0,0 +1,41 @@ +#ifndef MEMENTAR_BTREELEAF_H +#define MEMENTAR_BTREELEAF_H + +#include + +namespace mementar { + +template +class BtreeNode; + +template +class BtreeLeafBase : public Tleaf +{ + using Tdata = typename Tleaf::DataType; +public: + BtreeLeafBase(const Tkey& key) + { + mother_ = nullptr; + + key_ = key; + } + + bool operator==(const BtreeLeafBase& other) { return key_ == other.key_; } + bool operator>(const BtreeLeafBase& other) { return key_ > other.key_; } + bool operator<(const BtreeLeafBase& other) { return key_ < other.key_; } + bool operator>=(const BtreeLeafBase& other) { return ((key_ > other.key_) || (key_ == other.key_)); } + bool operator<=(const BtreeLeafBase& other) { return ((key_ < other.key_) || (key_ == other.key_)); } + + Tkey getKey() const { return key_; } + + void setMother(BtreeNode* mother) { mother_ = mother; } + BtreeNode* getMother() { return mother_; } + +private: + Tkey key_; + BtreeNode* mother_; +}; + +} // namespace mementar + +#endif // MEMENTAR_BTREELEAF_H diff --git a/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h b/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h deleted file mode 100644 index 36c31fa..0000000 --- a/include/mementar/core/memGraphs/Btree/BtreeLeafNode.h +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef MEMENTAR_BTREELEAFNODE_H -#define MEMENTAR_BTREELEAFNODE_H - -#include "mementar/core/memGraphs/Btree/BtreeNode.h" -#include "mementar/core/memGraphs/Btree/BtreeLeaf.h" - -namespace mementar -{ - -template -class BtreeLeafNode : public BtreeNode -{ - //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); -public: - BtreeLeafNode(size_t order = 10) : BtreeNode(order) - {} - - ~BtreeLeafNode() {} - - BtreeLeaf* insert(const Tkey& key, const Tdata& data); - bool remove(const Tkey& key, const Tdata& data); - BtreeLeaf* find(const Tkey& key); - BtreeLeaf* findNear(const Tkey& key); - BtreeLeaf* getFirst(); - - virtual void display(size_t depth = 0); -private: - std::vector*> leafs_; - - virtual bool needBalancing(); - virtual void split(); -}; - -template -BtreeLeaf* BtreeLeafNode::insert(const Tkey& key, const Tdata& data) -{ - BtreeLeaf* res = nullptr; - - if(leafs_.size() == 0) - { - this->keys_.push_back(key); - res = new BtreeLeaf(key); - leafs_.push_back(res); - res->setMother(this); - res->push_back(data); - return res; - } - else - { - BtreeLeaf* last = nullptr; - if(leafs_.size()) - last = leafs_.back(); - - if(key > this->keys_.back()) - { - this->keys_.push_back(key); - res = new BtreeLeaf(key); - leafs_.push_back(res); - res->setNextNode(last->getNextNode()); - last->setNextNode(res); - res->setPreviousNode(last); - res->setMother(this); - res->push_back(data); - } - else if(this->keys_.back() == key) - { - last->push_back(data); - } - else - { - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] >= key) - { - if(this->keys_[i] == key) - { - leafs_[i]->push_back(data); - } - else - { - res = new BtreeLeaf(key); - // here last is the next node of res - last = leafs_[i]; - res->setNextNode(last); - res->setPreviousNode(last->getPreviousNode()); - if(res->getPreviousNode()) - res->getPreviousNode()->setNextNode(res); - if(res->getNextNode()) - res->getNextNode()->setPreviousNode(res); - this->keys_.insert(this->keys_.begin() + i, key); - this->leafs_.insert(this->leafs_.begin() + i, res); - res->setMother(this); - res->push_back(data); - } - break; - } - } - } - } - - if(needBalancing()) - split(); - - return res; -} - -template -bool BtreeLeafNode::remove(const Tkey& key, const Tdata& data) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] == key) - { - leafs_[i]->remove(data); - if(leafs_[i]->getData().size() == 0) - { - if(leafs_[i]->getPreviousNode() != nullptr) - leafs_[i]->getPreviousNode()->setNextNode(leafs_[i]->getNextNode()); - if(leafs_[i]->getNextNode() != nullptr) - leafs_[i]->getNextNode()->setPreviousNode(leafs_[i]->getPreviousNode()); - delete leafs_[i]; - leafs_.erase(leafs_.begin() + i); - this->keys_.erase(this->keys_.begin() + i); - - if(leafs_.size() == 0) - std::cout << "a node is empty but will not be destroyed" << std::endl; - } - return true; - } - } - return false; -} - -template -BtreeLeaf* BtreeLeafNode::find(const Tkey& key) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] == key) - return leafs_[i]; - } - return nullptr; -} - -template -BtreeLeaf* BtreeLeafNode::findNear(const Tkey& key) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] >= key) - return leafs_[i]; - } - return static_cast*>(leafs_[leafs_.size() - 1]->getNextNode()); -} - -template -BtreeLeaf* BtreeLeafNode::getFirst() -{ - return leafs_[0]; -} - -template -bool BtreeLeafNode::needBalancing() -{ - return (leafs_.size() > this->order_); -} - -template -void BtreeLeafNode::split() -{ - BtreeLeafNode* new_node = new BtreeLeafNode(this->order_); - - size_t half_order = this->order_/2; - for(size_t i = 0; i < half_order; i++) - { - new_node->leafs_.insert(new_node->leafs_.begin(), leafs_.back()); - leafs_.pop_back(); - new_node->leafs_[i]->setMother(new_node); - - new_node->keys_.insert(new_node->keys_.begin(), this->keys_.back()); - this->keys_.pop_back(); - } - - if(this->mother_ != nullptr) - { - this->mother_->insert(new_node, new_node->keys_[0]); - } - else - { - BtreeNode* new_mother = new BtreeNode(this->order_); - new_mother->setLevel(this->level_ + 1); - new_mother->insert(this, this->keys_[0]); - new_mother->insert(new_node, new_node->keys_[0]); - } -} - -template -void BtreeLeafNode::display(size_t depth) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - for(size_t j = 0; j < depth; j++) - std::cout << "\t"; - //std::vector datas = ; - std::cout << this->keys_[i] << " => "; - for(auto data : leafs_[i]->getData()) - std::cout << data << " : "; - std::cout << std::endl; - } -} - -} // namespace mementar - -#endif // MEMENTAR_BTREELEAFNODE_H diff --git a/include/mementar/core/memGraphs/Btree/BtreeNode.h b/include/mementar/core/memGraphs/Btree/BtreeNode.h index ba89da6..2ca621b 100644 --- a/include/mementar/core/memGraphs/Btree/BtreeNode.h +++ b/include/mementar/core/memGraphs/Btree/BtreeNode.h @@ -3,212 +3,35 @@ #include -#include "mementar/core/memGraphs/Btree/BtreeLeaf.h" +namespace mementar { -namespace mementar -{ +template +class BtreeLeafBase; -template +template class BtreeNode { - //static_assert(std::is_base_of,Tnode>::value, "Tnode must be derived from DllNode"); public: - BtreeNode(size_t order = 10) - { - order_ = order; - level_ = 1; - mother_ = nullptr; - } - - virtual ~BtreeNode() + ~BtreeNode() { for(auto child : childs_) delete child; - } - - virtual BtreeLeaf* insert(const Tkey& key, const Tdata& data); - void insert(BtreeNode* new_node, const Tkey& key); - virtual bool remove(const Tkey& key, const Tdata& data); - virtual BtreeLeaf* find(const Tkey& key); - virtual BtreeLeaf* findNear(const Tkey& key); - virtual BtreeLeaf* getFirst(); - void setMother(BtreeNode* mother) { mother_ = mother; } - BtreeNode* getMother() { return mother_; } + for(auto leaf : leafs_) + delete leaf; + } - void setLevel(size_t level) { level_ = level; } - size_t getLevel() { return level_; } + bool isLeafNode() { return leafs_.size() != 0; } - size_t getNbChilds() { return childs_.size(); } + void setMother(BtreeNode* mother) { mother_ = mother; } + BtreeNode* getMother() { return mother_; } - virtual void display(size_t depth = 0); -protected: std::vector keys_; - std::vector*> childs_; - BtreeNode* mother_; - size_t order_; - size_t level_; - - virtual bool needBalancing(); - virtual void split(); + BtreeNode* mother_; + std::vector*> childs_; + std::vector*> leafs_; }; -template -BtreeLeaf* BtreeNode::insert(const Tkey& key, const Tdata& data) -{ - size_t index; - for(index = 0; index < this->keys_.size(); index++) - { - if(key < this->keys_[index]) - break; - } - return childs_[index]->insert(key, data); -} - -template -void BtreeNode::insert(BtreeNode* new_node, const Tkey& key) -{ - if(childs_.size() == 0) - { - childs_.push_back(new_node); - new_node->setMother(this); - return; - } - else - { - if(this->keys_.size() == 0) - { - this->keys_.push_back(key); - childs_.push_back(new_node); - new_node->setMother(this); - } - else if(key > this->keys_[this->keys_.size() - 1]) - { - this->keys_.push_back(key); - childs_.push_back(new_node); - new_node->setMother(this); - } - else - { - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(key < this->keys_[i]) - { - this->keys_.insert(this->keys_.begin() + i, key); - this->childs_.insert(this->childs_.begin() + i + 1, new_node); - new_node->setMother(this); - break; - } - } - } - } - - if(needBalancing()) - split(); -} - -template -bool BtreeNode::remove(const Tkey& key, const Tdata& data) -{ - size_t index = this->keys_.size(); - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] > key) - { - index = i; - break; - } - } - return this->childs_[index]->remove(key, data); - - if(this->keys_.size() == 0) - std::cout << "a node is empty but will not be destroyed" << std::endl; -} - -template -BtreeLeaf* BtreeNode::find(const Tkey& key) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] > key) - return this->childs_[i]->find(key); - } - return this->childs_[this->keys_.size()]->find(key); -} - -template -BtreeLeaf* BtreeNode::findNear(const Tkey& key) -{ - for(size_t i = 0; i < this->keys_.size(); i++) - { - if(this->keys_[i] > key) - return this->childs_[i]->findNear(key); - } - return this->childs_[this->keys_.size()]->findNear(key); -} - -template -BtreeLeaf* BtreeNode::getFirst() -{ - return this->childs_[0]->getFirst(); -} - -template -bool BtreeNode::needBalancing() -{ - return (childs_.size() > order_); -} - -template -void BtreeNode::split() -{ - BtreeNode* new_node = new BtreeNode(order_); - - size_t half_order = order_/2 - 1; - for(size_t i = 0; i < half_order; i++) - { - new_node->childs_.insert(new_node->childs_.begin(), childs_.back()); - childs_.pop_back(); - new_node->childs_[i]->setMother(new_node); - - new_node->keys_.insert(new_node->keys_.begin(), keys_.back()); - keys_.pop_back(); - } - - new_node->childs_.insert(new_node->childs_.begin(), childs_.back()); - childs_.pop_back(); - new_node->childs_[half_order]->setMother(new_node); - - if(mother_ != nullptr) - { - mother_->insert(new_node, keys_.back()); - keys_.pop_back(); - } - else - { - BtreeNode* new_mother = new BtreeNode(order_); - new_mother->setLevel(this->level_ + 1); - new_mother->insert(this, keys_.back()); - new_mother->insert(new_node, keys_.back()); - keys_.pop_back(); - } -} - -template -void BtreeNode::display(size_t depth) -{ - size_t depth_1 = depth + 1; - - for(size_t i = 0; i < keys_.size(); i++) - { - childs_[i]->display(depth_1); - for(size_t j = 0; j < depth; j++) - std::cout << "\t"; - std::cout << keys_[i] << std::endl; - } - childs_[keys_.size()]->display(depth_1); -} - } // namespace mementar #endif // MEMENTAR_BTREENODE_H diff --git a/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h b/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h deleted file mode 100644 index ae5b2df..0000000 --- a/include/mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MEMENTAR_DLLCARGONODE_H -#define MEMENTAR_DLLCARGONODE_H - -#include "mementar/core/memGraphs/DoublyLinkedList/DllNode.h" - -namespace mementar { - -class DllLinkedElement; - -class DllCargoNode : public DllNode -{ -public: - DllCargoNode(); - virtual ~DllCargoNode() {} - - virtual void push_back(DllLinkedElement* data); - virtual void remove(DllLinkedElement* data); - -protected: - void unlinkDll(size_t i); -}; - -} // namespace mementar - -#endif // MEMENTAR_DLLCARGONODE_H diff --git a/include/mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h b/include/mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h deleted file mode 100644 index ae4f1a9..0000000 --- a/include/mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MEMENTAR_DLLLINKEDELEMENT_H -#define MEMENTAR_DLLLINKEDELEMENT_H - -#include "mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h" - -#include - -namespace mementar { - -class DllLinkedElement -{ - friend DllCargoNode; -public: - DllLinkedElement(); - - DllCargoNode* getPreviousDllNode(); - DllCargoNode* getNextDllNode(); - - std::vector getPreviousDllData(); - std::vector getNextDllData(); - - virtual bool operator==(const DllLinkedElement*) = 0; - virtual void print(std::ostream& os) const { os << this; } - friend std::ostream& operator<<(std::ostream& os, DllLinkedElement* elem) { elem->print(os); return os;} - -private: - DllCargoNode* dll_node_; -}; - -} // namespace mementar - -#endif // MEMENTAR_DLLLINKEDELEMENT_H diff --git a/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h b/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h deleted file mode 100644 index b9e4f90..0000000 --- a/include/mementar/core/memGraphs/DoublyLinkedList/DllNode.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef MEMENTAR_DLLNODE_H -#define MEMENTAR_DLLNODE_H - -#include -#include -#include - -namespace mementar { - -template -class DllNode -{ -std::false_type is_dllnode_impl(...); -template -std::true_type is_dllnode_impl(DllNode*); -template -using is_dllnode = decltype(is_dllnode_impl(std::declval())); - -public: - DllNode() - { - prev_ = nullptr; - next_ = nullptr; - } - - virtual ~DllNode() {} - - virtual void push_back(const Tdata& data) { payload_.push_back(data); } - virtual void remove(const Tdata& data) - { - for(size_t i = 0; i < payload_.size();) - { - if(payload_[i] == data) - payload_.erase(payload_.begin() + i); - else - i++; - } - } - - std::vector getData() const { return payload_; } - void getData(std::vector& data) { data = payload_; } - - inline DllNode* getPreviousNode() { return prev_; } - inline DllNode* getNextNode() { return next_; } - - virtual void setPreviousNode(DllNode* prev) { prev_ = prev; } - virtual void setNextNode(DllNode* next) { next_ = next; } - -protected: - DllNode* prev_; - DllNode* next_; - std::vector payload_; -}; - -} // namespace mementar - -#endif // MEMENTAR_DLLNODE_H diff --git a/include/mementar/core/memGraphs/EventLinkedList/EllElement.h b/include/mementar/core/memGraphs/EventLinkedList/EllElement.h deleted file mode 100644 index a702d68..0000000 --- a/include/mementar/core/memGraphs/EventLinkedList/EllElement.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MEMENTAR_ELLELEMENT_H -#define MEMENTAR_ELLELEMENT_H - -#include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" -#include "mementar/core/memGraphs/EventLinkedList/EllNode.h" - -namespace mementar { - -class EllElement : public DllLinkedElement -{ - friend EllNode; -public: - EllElement(); - ~EllElement() {} - - EllElement* getPreviousEllElement() { return prev_elem_; } - EllElement* getNextEllElement() { return next_elem_; } - - virtual bool operator==(const DllLinkedElement*) = 0; - virtual bool isEventPart(const DllLinkedElement* other) = 0; - virtual void print(std::ostream& os) const { os << this; } - -private: - EllElement* prev_elem_; - EllElement* next_elem_; - - std::vector to_link_prev; - std::vector to_link_next; -}; - -} // namespace mementar - -#endif // MEMENTAR_ELLELEMENT_H diff --git a/include/mementar/core/memGraphs/EventLinkedList/EllNode.h b/include/mementar/core/memGraphs/EventLinkedList/EllNode.h deleted file mode 100644 index c5461dc..0000000 --- a/include/mementar/core/memGraphs/EventLinkedList/EllNode.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MEMENTAR_ELLNODE_H -#define MEMENTAR_ELLNODE_H - -#include "mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h" - -#include - -namespace mementar { - -class EllElement; - -class EllNode : public DllCargoNode -{ -public: - EllNode(); - ~EllNode() {} - - void push_back(EllElement* data); - void remove(EllElement* data); -private: - - void link(EllElement* data); - - EllElement* getPrev(EllElement* data); - std::vector getPrevs(EllElement* data); - - EllElement* getNext(EllElement* data); - std::vector getNexts(EllElement* data); - - void linkPrev(EllElement* current, EllElement* prev, EllElement* next); - void linkNext(EllElement* current, EllElement* next, EllElement* prev); - - void unlink(EllElement* current_data); - - void unlinkPrev(EllElement* current, std::vector prev, EllElement* next); - void unlinkNext(EllElement* current, std::vector next, EllElement* prev); -}; - -} // namespace mementar - -#endif // MEMENTAR_ELLNODE_H diff --git a/include/mementar/core/memGraphs/ExtendedBtree/DlBtree.h b/include/mementar/core/memGraphs/ExtendedBtree/DlBtree.h new file mode 100644 index 0000000..4287346 --- /dev/null +++ b/include/mementar/core/memGraphs/ExtendedBtree/DlBtree.h @@ -0,0 +1,116 @@ +#ifndef MEMENTAR_DLBTREE_H +#define MEMENTAR_DLBTREE_H + +#include + +#include "mementar/core/memGraphs/Btree/BplusTree.h" + +namespace mementar { + +template +class LinkedData +{ +public: + using LeafType = Tleaf; + + LinkedData(Tvalue value) : value_(value) + { + leaf_ = nullptr; + } + + LeafType* getNextLeaf() + { + if(leaf_ == nullptr) + return nullptr; + else + return static_cast(leaf_->getNextLeaf()); + } + + LeafType* getPreviousLeaf() + { + if(leaf_ == nullptr) + return nullptr; + else + return static_cast(leaf_->getPreviousLeaf()); + } + + friend std::ostream& operator<<(std::ostream& os, const LinkedData& data) + { + os << data.value_; + return os; + } + + bool operator==(const LinkedData& other) const + { + return value_ == other.value_; + } + + Tvalue value_; + LeafType* leaf_; +}; + +template +class DataLinkedLeaf : public BplusLeaf +{ +public: + using LeafType = typename Tdata::LeafType; + + void insert(LeafType* leaf, Tdata data) + { + this->payload_.emplace_back(data); + this->payload_.back().leaf_ = leaf; + } + void remove(LeafType* leaf, Tdata data) + { + (void)leaf; + for(size_t i = 0; i < this->payload_.size();) + { + if(this->payload_[i] == data) + { + this->payload_[i].leaf_ = nullptr; + this->payload_.erase(this->payload_.begin() + i); + } + else + i++; + } + } +}; + +template +class DataLinkedLeaf : public BplusLeaf +{ +public: + using LeafType = typename Tdata::LeafType; + + void insert(LeafType* leaf, Tdata* data) + { + this->payload_.emplace_back(data); + data->leaf_ = leaf; + } + void remove(LeafType* leaf, Tdata* data) + { + (void)leaf; + for(size_t i = 0; i < this->payload_.size();) + { + if(this->payload_[i] == *data) + { + this->payload_[i].leaf_ = nullptr; + this->payload_.erase(this->payload_.begin() + i); + } + else + i++; + } + } +}; + +template +class DlLeaf : public DataLinkedLeaf>> +{ +}; + +template +using DlBtree = Btree, N>; + +} // namespace mementar + +#endif // MEMENTAR_DLBTREE_H diff --git a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h new file mode 100644 index 0000000..4d2ee4b --- /dev/null +++ b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h @@ -0,0 +1,336 @@ +#ifndef MEMENTAR_EVENTLINKEDLEAF_H +#define MEMENTAR_EVENTLINKEDLEAF_H + +#include "mementar/core/memGraphs/ExtendedBtree/DlBtree.h" + +namespace mementar { + +template +class EventLinkedLeaf; + +template +class LinkedEvent +{ + template + friend class EventLinkedLeaf; + +public: + LinkedEvent() + { + prev_elem_ = nullptr; + next_elem_ = nullptr; + leaf_ = nullptr; + } + + SelfType* getNextEvent() { return next_elem_; } + SelfType* getPreviousEvent() { return prev_elem_; } + + Tleaf* getNextLeaf() + { + if(leaf_ == nullptr) + return nullptr; + else + return static_cast(leaf_->getNextLeaf()); + } + + Tleaf* getPreviousLeaf() + { + if(leaf_ == nullptr) + return nullptr; + else + return static_cast(leaf_->getPreviousLeaf()); + } + + Tleaf* leaf_; + +protected: + SelfType* prev_elem_; + SelfType* next_elem_; + + std::vector to_link_prev; + std::vector to_link_next; +}; + +template +class EventLinkedLeaf : public DataLinkedLeaf +{ + using DLF = DataLinkedLeaf; +public: + void insert(typename DLF::LeafType* leaf, Tdata data) + { + DLF::insert(leaf, data); + link(this->payload_.back()); + } + void remove(typename DLF::LeafType* leaf, Tdata data) + { + (void)leaf; + for(size_t i = 0; i < this->payload_.size();) + { + if(this->payload_[i] == data) + { + unlink(this->payload_[i]); + this->payload_[i]->leaf_ = nullptr; + this->payload_.erase(this->payload_.begin() + i); + } + else + i++; + } + } +private: + void link(Tdata data); + void unlink(Tdata current_data); + + Tdata getPrev(Tdata data); + std::vector getPrevs(Tdata data); + + Tdata getNext(Tdata data); + std::vector getNexts(Tdata data); + + void linkPrev(Tdata current, Tdata prev, Tdata next); + void linkNext(Tdata current, Tdata next, Tdata prev); + + void unlinkPrev(Tdata current, const std::vector& prev, Tdata next); + void unlinkNext(Tdata current, const std::vector& next, Tdata prev); +}; + +template +void EventLinkedLeaf::link(Tdata data) +{ + auto next = getNext(data); + auto prev = getPrev(data); + + linkPrev(data, prev, next); + linkNext(data, next, prev); +} + +template +void EventLinkedLeaf::unlink(Tdata current_data) +{ + std::vector prev = getPrevs(current_data); + std::vector next = getNexts(current_data); + + unlinkPrev(current_data, prev, next.size() ? next[0] : nullptr); + unlinkNext(current_data, next, prev.size() ? prev[0] : nullptr); + + current_data->prev_elem_ = nullptr; + current_data->next_elem_ = nullptr; + + current_data->to_link_prev.clear(); + current_data->to_link_next.clear(); +} + +template +Tdata EventLinkedLeaf::getPrev(Tdata data) +{ + Tdata res = nullptr; + + auto prev_node = static_cast*>(data->getPreviousLeaf()); + while(prev_node != nullptr) + { + for(auto& ld : prev_node->payload_) + { + if(data->isPartOf(*ld)) + return ld; + } + prev_node = static_cast*>(prev_node->getPreviousLeaf()); + } + + return res; +} + +template +std::vector EventLinkedLeaf::getPrevs(Tdata data) +{ + std::vector res; + + auto prev_node = static_cast*>(data->getPreviousLeaf()); + if(prev_node == nullptr) + return res; + + for(;;) + { + for(auto& ld : prev_node->payload_) + { + if(data->isPartOf(*ld)) + { + res.push_back(ld); + if(ld->prev_elem_ != nullptr) + if(ld->prev_elem_->next_elem_->operator==(*ld)) + return res; + break; + } + } + + prev_node = static_cast*>(prev_node->getPreviousLeaf()); + if(prev_node == nullptr) + return res; + } +} + +template +Tdata EventLinkedLeaf::getNext(Tdata data) +{ + Tdata res = nullptr; + + auto next_node = static_cast*>(data->getNextLeaf()); + while(next_node != nullptr) + { + for(auto ld : next_node->payload_) + { + if(data->isPartOf(*ld)) + return ld; + } + next_node = static_cast*>(next_node->getNextLeaf()); + } + + return res; +} + +template +std::vector EventLinkedLeaf::getNexts(Tdata data) +{ + std::vector res; + + auto next_node = static_cast*>(data->getNextLeaf()); + if(next_node == nullptr) + return res; + + for(;;) + { + for(auto& ld : next_node->payload_) + { + if(data->isPartOf(*ld)) + { + res.push_back(ld); + if(ld->next_elem_ != nullptr) + if(ld->next_elem_->prev_elem_->operator==(*ld)) + return res; + break; + } + } + + next_node = static_cast*>(next_node->getNextLeaf()); + if(next_node == nullptr) + return res; + } +} + +template +void EventLinkedLeaf::linkPrev(Tdata current, Tdata prev, Tdata next) +{ + if(prev == nullptr) + return; + + if(current->operator==(*prev)) + { + if(next == nullptr) + { + current->to_link_next = prev->to_link_next; + prev->to_link_next.clear(); + current->to_link_next.push_back(prev); + } + current->prev_elem_ = prev->prev_elem_; + } + else + { + current->prev_elem_ = prev; + prev->next_elem_ = current; + if(prev->to_link_next.size()) + { + for(auto& d : prev->to_link_next) + d->next_elem_ = current; + prev->to_link_next.clear(); + } + } +} + +template +void EventLinkedLeaf::linkNext(Tdata current, Tdata next, Tdata prev) +{ + if(next == nullptr) + return; + + if(current->operator==(*next)) + { + if(prev == nullptr) + { + current->to_link_prev = next->to_link_prev; + next->to_link_prev.clear(); + current->to_link_prev.push_back(next); + } + current->next_elem_ = next->next_elem_; + } + else + { + current->next_elem_ = next; + next->prev_elem_ = current; + if(next->to_link_prev.size()) + { + for(auto& d : next->to_link_prev) + d->prev_elem_ = current; + next->to_link_prev.clear(); + } + } +} + +template +void EventLinkedLeaf::unlinkPrev(Tdata current, const std::vector& prev, Tdata next) +{ + if(prev.size()) + { + if(!current->operator==(*prev[0])) + { + if((next != nullptr) && !current->operator==(*next)) + { + for(auto& p : prev) + p->next_elem_ = current->next_elem_; + } + else + { + for(auto& p : prev) + p->next_elem_ = next; + } + } + } + else if(current->to_link_prev.size()) + { + if((next != nullptr) && current->operator==(*next)) + { + next->to_link_prev = std::move(current->to_link_prev); + next->to_link_prev.pop_back(); + } + } +} + +template +void EventLinkedLeaf::unlinkNext(Tdata current, const std::vector& next, Tdata prev) +{ + if(next.size()) + { + if(!current->operator==(*next[0])) + { + if((prev != nullptr) && !current->operator==(*prev)) + { + for(auto& n : next) + n->prev_elem_ = current->prev_elem_; + } + else + { + for(auto& n : next) + n->prev_elem_ = prev; + } + } + } + else if(current->to_link_next.size()) + { + if((prev != nullptr) && current->operator==(*prev)) + { + prev->to_link_next = std::move(current->to_link_next); + prev->to_link_next.pop_back(); + } + } +} + +} // namespace mementar + +#endif // MEMENTAR_EVENTLINKEDLEAF_H diff --git a/src/core/memGraphs/Btree/CMakeLists.txt b/src/core/memGraphs/Btree/CMakeLists.txt index 6f79461..083e0f8 100644 --- a/src/core/memGraphs/Btree/CMakeLists.txt +++ b/src/core/memGraphs/Btree/CMakeLists.txt @@ -8,12 +8,6 @@ include_directories( ../../../../include ) -add_library(mementar_dll_lib - ../DoublyLinkedList/DllCargoNode.cpp - ../DoublyLinkedList/DllLinkedElement.cpp -) - add_executable(btree tests/btree_test.cpp) add_executable(max tests/max_insertion.cpp) add_executable(cargo tests/cargo.cpp) -target_link_libraries(cargo mementar_dll_lib) diff --git a/src/core/memGraphs/Btree/tests/btree_test.cpp b/src/core/memGraphs/Btree/tests/btree_test.cpp index 50802f8..a2aaa46 100644 --- a/src/core/memGraphs/Btree/tests/btree_test.cpp +++ b/src/core/memGraphs/Btree/tests/btree_test.cpp @@ -3,33 +3,72 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/memGraphs/DoublyLinkedList/DllNode.h" -#include "mementar/core/memGraphs/Btree/BtreeLeaf.h" -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/Btree/BplusTree.h" using namespace std::chrono; int main() { - mementar::BtreeLeaf> leaf1(0, 2); - mementar::BtreeLeaf> leaf2(1, 3); + mementar::BtreeLeafBase> leaf1(0); + mementar::BtreeLeafBase> leaf2(1); - if(leaf1.operator<(&leaf2)) + if(leaf1.operator<(leaf2)) std::cout << "inf" << std::endl; else std::cout << "sup" << std::endl; - std::vector sizes = {50}; - std::vector times; + std::vector sizes = {10,100,1000,10000,100000,1000000,10000000}; + std::vector insert; + std::vector removed; + std::vector find; for(auto nb : sizes) + //size_t nb = 0; { high_resolution_clock::time_point t1 = high_resolution_clock::now(); - mementar::Btree tree(3); + mementar::BplusTree tree; for(size_t i = 0; i < nb; i++) tree.insert(i, i); - //tree.display(); + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i++) + tree.find(i); + + high_resolution_clock::time_point t3 = high_resolution_clock::now(); + + for(size_t i = 0; i < nb; i+=2) + tree.remove(i, i); + + high_resolution_clock::time_point t4 = high_resolution_clock::now(); + + duration time_span = duration_cast>(t2 - t1); + insert.push_back(time_span.count()); + time_span = duration_cast>(t3 - t2); + find.push_back(time_span.count()); + time_span = duration_cast>(t4 - t3); + removed.push_back(time_span.count()); + + for(size_t i = 0; i < sizes.size(); i++) + std::cout << sizes[i] << ";"; + std::cout << std::endl; + for(size_t i = 0; i < insert.size(); i++) + std::cout << insert[i] << ";"; + std::cout << std::endl; + for(size_t i = 0; i < find.size(); i++) + std::cout << find[i] << ";"; + std::cout << std::endl; + for(size_t i = 0; i < removed.size(); i++) + std::cout << removed[i] << ";"; + std::cout << std::endl; + } + + { + mementar::BplusTree tree; + for(size_t i = 0; i < 50; i++) + tree.insert(i, i); + + //tree.displayTree(); auto res = tree.find(10); if(res) std::cout << res->getKey() << std::endl; else std::cout << "-" << std::endl; @@ -46,22 +85,7 @@ int main() tree.remove(49, 49); tree.insert(50, 0); - tree.display(); - - std::cout << "estimation = " << tree.estimateMinLeaves() << std::endl; - std::cout << "level = " << tree.estimateMaxLevel(nb) << ">=" << tree.getCurrentLevel() << std::endl; - - high_resolution_clock::time_point t2 = high_resolution_clock::now(); - duration time_span = duration_cast>(t2 - t1); - std::cout << "took " << time_span.count() << std::endl; - times.push_back(time_span.count()); - - for(size_t i = 0; i < times.size(); i++) - std::cout << sizes[i] << ";"; - std::cout << std::endl; - for(size_t i = 0; i < times.size(); i++) - std::cout << times[i] << ";"; - std::cout << std::endl; + tree.displayTree(); } return 0; diff --git a/src/core/memGraphs/Btree/tests/cargo.cpp b/src/core/memGraphs/Btree/tests/cargo.cpp index 7eb4459..f8fca4a 100644 --- a/src/core/memGraphs/Btree/tests/cargo.cpp +++ b/src/core/memGraphs/Btree/tests/cargo.cpp @@ -3,72 +3,39 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/memGraphs/Btree/Btree.h" -#include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" -#include "mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h" +#include "mementar/core/memGraphs/ExtendedBtree/DlBtree.h" using namespace std::chrono; -using namespace mementar; - -class DllElem : public DllLinkedElement -{ -public: - DllElem(int data) { elem_data = data; } - int elem_data; - - virtual void print(std::ostream& os) const - { - os << elem_data; - } - -private: - bool operator==(const DllLinkedElement* other) - { - return elem_data == static_cast(other)->elem_data; - } -}; - -void displayNext(DllElem* elem) -{ - std::cout << "-" << elem->elem_data << std::endl; - for(auto d : elem->getNextDllData()) - displayNext(static_cast(d)); -} int main() { - high_resolution_clock::time_point t1 = high_resolution_clock::now(); - std::vector container; + mementar::DlBtree tree; - mementar::Btree tree(3); for(size_t i = 0; i < 10; i++) - { - container.push_back(new DllElem(i)); - tree.insert(i, container.back()); - } + tree.insert(i, i); std::cout << "*****" << std::endl; - container.push_back(new DllElem(10)); - tree.insert(3, container.back()); - - tree.remove(3, container[3]); + tree.insert(3, 10); - tree.display(); + tree.remove(3, 3); - high_resolution_clock::time_point t2 = high_resolution_clock::now(); - duration time_span = duration_cast>(t2 - t1); - std::cout << "took " << time_span.count() << std::endl; + tree.displayTree(); - for(auto elem : container) + using LeafTyep = mementar::BplusLeaf > >; + for(LeafTyep* leaf = tree.getFirst(); leaf != nullptr; leaf = leaf->getNextLeaf()) { - std::cout << elem->elem_data << " -> "; - for(auto d : elem->getNextDllData()) - std::cout << static_cast(d)->elem_data << " : "; - std::cout << std::endl; + for(auto data : leaf->payload_) + { + std::cout << data.value_ << " -> "; + if(data.getNextLeaf() != nullptr) + { + for(auto d : data.getNextLeaf()->getData()) + std::cout << d.value_ << " : "; + } + std::cout << std::endl; + } } - displayNext(container[0]); - return 0; } diff --git a/src/core/memGraphs/Btree/tests/max_insertion.cpp b/src/core/memGraphs/Btree/tests/max_insertion.cpp index 0553798..29b4332 100644 --- a/src/core/memGraphs/Btree/tests/max_insertion.cpp +++ b/src/core/memGraphs/Btree/tests/max_insertion.cpp @@ -3,8 +3,7 @@ #include /* srand, rand */ #include /* time */ -#include "mementar/core/memGraphs/Btree/BtreeLeaf.h" -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/Btree/BplusTree.h" using namespace std::chrono; @@ -16,7 +15,7 @@ int main() high_resolution_clock::time_point t1 = high_resolution_clock::now(); - mementar::Btree tree(5); + mementar::BplusTree tree; for(size_t i = 0; true; i+=2) if(tree.insert(i, i) >= nb/2) break; @@ -36,8 +35,5 @@ int main() time_span = duration_cast>(t2 - t1); std::cout << "took " << time_span.count()*1000 << " for " << nb/2 << std::endl; - //tree.display(); - std::cout << "level = " << tree.estimateMaxLevel(nb) << ">=" << tree.getCurrentLevel() << std::endl; - return 0; } diff --git a/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp b/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp deleted file mode 100644 index ca27b0e..0000000 --- a/src/core/memGraphs/DoublyLinkedList/DllCargoNode.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "mementar/core/memGraphs/DoublyLinkedList/DllCargoNode.h" - -#include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" - -#include - -namespace mementar { - -DllCargoNode::DllCargoNode() : DllNode() -{ -} - -void DllCargoNode::push_back(DllLinkedElement* data) -{ - data->dll_node_ = this; - DllNode::push_back(data); -} - -void DllCargoNode::remove(DllLinkedElement* data) -{ - for(size_t i = 0; i < payload_.size();) - { - if(payload_[i]->operator==(data)) - { - unlinkDll(i); - payload_.erase(payload_.begin() + i); - } - else - i++; - } -} - -void DllCargoNode::unlinkDll(size_t i) -{ - payload_[i]->dll_node_ = nullptr; -} - -} // namespace mementar diff --git a/src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp b/src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp deleted file mode 100644 index 597d96d..0000000 --- a/src/core/memGraphs/DoublyLinkedList/DllLinkedElement.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" - -namespace mementar { - -DllLinkedElement::DllLinkedElement() -{ - dll_node_ = nullptr; -} - -DllCargoNode* DllLinkedElement::getPreviousDllNode() -{ - if(dll_node_ != nullptr) - return static_cast(dll_node_->getPreviousNode()); - else - return nullptr; -} - -DllCargoNode* DllLinkedElement::getNextDllNode() -{ - if(dll_node_ != nullptr) - return static_cast(dll_node_->getNextNode()); - else - return nullptr; -} - -std::vector DllLinkedElement::getPreviousDllData() -{ - if(dll_node_ != nullptr) - { - if(dll_node_->getPreviousNode() != nullptr) - return dll_node_->getPreviousNode()->getData(); - else - return {}; - } - else - return {}; -} - -std::vector DllLinkedElement::getNextDllData() -{ - if(dll_node_ != nullptr) - { - if(dll_node_->getNextNode() != nullptr) - return dll_node_->getNextNode()->getData(); - else - return {}; - } - else - return {}; -} - -} // namespace mementar diff --git a/src/core/memGraphs/EventLinkedList/EllElement.cpp b/src/core/memGraphs/EventLinkedList/EllElement.cpp deleted file mode 100644 index 0f1f5fe..0000000 --- a/src/core/memGraphs/EventLinkedList/EllElement.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "mementar/core/memGraphs/EventLinkedList/EllElement.h" - -namespace mementar { - -EllElement::EllElement() -{ - prev_elem_ = nullptr; - next_elem_ = nullptr; -} - -} diff --git a/src/core/memGraphs/EventLinkedList/EllNode.cpp b/src/core/memGraphs/EventLinkedList/EllNode.cpp deleted file mode 100644 index bf4aa41..0000000 --- a/src/core/memGraphs/EventLinkedList/EllNode.cpp +++ /dev/null @@ -1,260 +0,0 @@ -#include "mementar/core/memGraphs/EventLinkedList/EllNode.h" - -#include "mementar/core/memGraphs/EventLinkedList/EllElement.h" - -namespace mementar { - -EllNode::EllNode() : DllCargoNode() -{ -} - -void EllNode::push_back(EllElement* data) -{ - DllCargoNode::push_back(data); - link(data); -} - -void EllNode::remove(EllElement* data) -{ - for(size_t i = 0; i < payload_.size();) - { - if(payload_[i]->operator==(data)) - { - unlinkDll(i); - - unlink(dynamic_cast(payload_[i])); - - payload_.erase(payload_.begin() + i); - } - else - i++; - } -} - -void EllNode::link(EllElement* data) -{ - auto next = getNext(data); - auto prev = getPrev(data); - - linkPrev(data, prev, next); - linkNext(data, next, prev); -} - -EllElement* EllNode::getPrev(EllElement* data) -{ - EllElement* res = nullptr; - - DllCargoNode* prev_node = dynamic_cast(data->getPreviousDllNode()); - while(prev_node != nullptr) - { - for(auto ld : prev_node->getData()) - { - if(data->isEventPart(ld)) - return dynamic_cast(ld); - } - prev_node = dynamic_cast(prev_node->getPreviousNode()); - } - - return res; -} - -std::vector EllNode::getPrevs(EllElement* data) -{ - std::vector res; - bool end = false; - - DllCargoNode* prev_node = dynamic_cast(data->getPreviousDllNode()); - if(prev_node == nullptr) - end = true; - - while(!end) - { - for(auto ld : prev_node->getData()) - { - if(data->isEventPart(ld)) - { - res.push_back(dynamic_cast(ld)); - if(dynamic_cast(ld)->prev_elem_->next_elem_ == ld) - end = true; - break; - } - } - - prev_node = dynamic_cast(prev_node->getPreviousNode()); - if(prev_node == nullptr) - end = true; - } - - return res; -} - -EllElement* EllNode::getNext(EllElement* data) -{ - EllElement* res = nullptr; - - DllCargoNode* next_node = dynamic_cast(data->getNextDllNode()); - while(next_node != nullptr) - { - for(auto ld : next_node->getData()) - { - if(data->isEventPart(ld)) - return dynamic_cast(ld); - } - next_node = dynamic_cast(next_node->getNextNode()); - } - - return res; -} - -std::vector EllNode::getNexts(EllElement* data) -{ - std::vector res; - bool end = false; - - DllCargoNode* next_node = dynamic_cast(data->getNextDllNode()); - if(next_node == nullptr) - end = true; - - while(!end) - { - for(auto ld : next_node->getData()) - { - if(data->isEventPart(ld)) - { - res.push_back(dynamic_cast(ld)); - if(dynamic_cast(ld)->next_elem_->prev_elem_ == ld) - end = true; - break; - } - } - - next_node = dynamic_cast(next_node->getNextNode()); - if(next_node == nullptr) - end = true; - } - - return res; -} - -void EllNode::linkPrev(EllElement* current, EllElement* prev, EllElement* next) -{ - if(prev == nullptr) - return; - - if(current->operator==(prev)) - { - if(next == nullptr) - { - current->to_link_next = prev->to_link_next; - prev->to_link_next.clear(); - current->to_link_next.push_back(prev); - } - current->prev_elem_ = prev->prev_elem_; - } - else - { - current->prev_elem_ = prev; - prev->next_elem_ = current; - if(prev->to_link_next.size()) - { - for(auto d : prev->to_link_next) - d->next_elem_ = current; - prev->to_link_next.clear(); - } - } -} - -void EllNode::linkNext(EllElement* current, EllElement* next, EllElement* prev) -{ - if(next == nullptr) - return; - - if(current->operator==(next)) - { - if(prev == nullptr) - { - current->to_link_prev = next->to_link_prev; - next->to_link_prev.clear(); - current->to_link_prev.push_back(next); - } - current->next_elem_ = next->next_elem_; - } - else - { - current->next_elem_ = next; - next->prev_elem_ = current; - if(next->to_link_prev.size()) - { - for(auto d : next->to_link_prev) - d->prev_elem_ = current; - next->to_link_prev.clear(); - } - } -} - -void EllNode::unlink(EllElement* current_data) -{ - std::vector prev = getPrevs(current_data); - std::vector next = getNexts(current_data); - - unlinkPrev(current_data, prev, next.size() ? next[0] : nullptr); - unlinkNext(current_data, next, prev.size() ? prev[0] : nullptr); -} - -void EllNode::unlinkPrev(EllElement* current, std::vector prev, EllElement* next) -{ - if(prev.size()) - { - if(!current->operator==(prev[0])) - { - if(!current->operator==(next)) - { - for(auto p : prev) - p->next_elem_ = current->next_elem_; - } - else - { - for(auto p : prev) - p->next_elem_ = next; - } - } - } - else if(current->to_link_prev.size()) - { - if(current->operator==(next)) - { - next->to_link_prev = std::move(current->to_link_prev); - next->to_link_prev.pop_back(); - } - } -} - -void EllNode::unlinkNext(EllElement* current, std::vector next, EllElement* prev) -{ - if(next.size()) - { - if(!current->operator==(next[0])) - { - if(!current->operator==(prev)) - { - for(auto n : next) - n->prev_elem_ = current->prev_elem_; - } - else - { - for(auto n : next) - n->prev_elem_ = prev; - } - } - } - else if(current->to_link_next.size()) - { - if(current->operator==(prev)) - { - prev->to_link_next = std::move(current->to_link_next); - prev->to_link_next.pop_back(); - } - } -} - -} // namespace mementar From db8b00f24448fe09555f4e91709a2e5352720c24 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 13 Jul 2020 15:36:19 +0200 Subject: [PATCH 45/95] [REFACT] LT with BplusTree extensions --- .../LtManagement/EpisodicTree/ArchivedLeaf.h | 2 +- .../EpisodicTree/ArchivedLeafNode.h | 9 ++-- .../EpisodicTree/CompressedLeaf.h | 8 +-- .../EpisodicTree/CompressedLeafNode.h | 18 +++---- .../EpisodicTree/CompressedLeafNodeSession.h | 13 ++--- .../EpisodicTree/CompressedLeafSession.h | 4 +- .../core/memGraphs/Branchs/types/SoftPoint.h | 4 +- .../mementar/core/memGraphs/Btree/BplusTree.h | 53 ++++++++++++++++++- include/mementar/core/memGraphs/Btree/Btree.h | 4 ++ .../EpisodicTree/ArchivedLeaf.cpp | 4 +- .../EpisodicTree/ArchivedLeafNode.cpp | 20 +++---- .../EpisodicTree/CompressedLeaf.cpp | 12 ++--- .../EpisodicTree/CompressedLeafNode.cpp | 24 ++++----- .../CompressedLeafNodeSession.cpp | 20 +++---- .../EpisodicTree/CompressedLeafSession.cpp | 4 +- .../EpisodicTree/tests/archived_tree.cpp | 2 +- .../EpisodicTree/tests/episodic_tree.cpp | 2 +- 17 files changed, 129 insertions(+), 74 deletions(-) diff --git a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h index ff15b06..c1caebf 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h @@ -18,7 +18,7 @@ class ArchivedLeaf std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - Btree* getTree(size_t i); + BplusTree* getTree(size_t i); std::vector getContexts(); private: diff --git a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h index 9f7c7d2..2a08555 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h @@ -10,16 +10,17 @@ namespace mementar class ArchivedLeafNode { + using LeafType = typename BplusLeaf::LeafType; public: ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); void insert(Event* data); void remove(Event* data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + LeafType* find(const time_t& key); + LeafType* findNear(const time_t& key); + LeafType* getFirst(); + LeafType* getLast(); void display(time_t key); diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h index df3212d..ff38f10 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h @@ -4,7 +4,7 @@ #include #include -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/Btree/BplusTree.h" #include "mementar/core/memGraphs/Branchs/types/Event.h" namespace mementar @@ -13,18 +13,18 @@ namespace mementar class CompressedLeaf { public: - CompressedLeaf(Btree* tree, const std::string& directory); + CompressedLeaf(BplusTree* tree, const std::string& directory); CompressedLeaf(const time_t& key, const std::string& directory); std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - Btree* getTree(); + BplusTree* getTree(); private: time_t key_; std::string directory_; - std::string treeToString(Btree* tree); + std::string treeToString(BplusTree* tree); }; } // namespace mementar diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h index 1fd8760..76884c9 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h @@ -7,7 +7,7 @@ #include #include "mementar/core/memGraphs/Branchs/types/Event.h" -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/Btree/BplusTree.h" #include "mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h" #include "mementar/core/LtManagement/EpisodicTree/Context.h" @@ -19,18 +19,19 @@ class ArchivedLeaf; class CompressedLeafNode { friend ArchivedLeaf; + using LeafType = typename BplusLeaf::LeafType; public: - CompressedLeafNode(std::string directory, size_t order = 10); + CompressedLeafNode(const std::string& directory); ~CompressedLeafNode(); CompressedLeafNode* split(); void insert(Event* data); void remove(Event* data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + LeafType* find(const time_t& key); + LeafType* findNear(const time_t& key); + LeafType* getFirst(); + LeafType* getLast(); void display(time_t key); size_t size() { return keys_.size(); } @@ -51,16 +52,15 @@ class CompressedLeafNode void init(); std::string directory_; - size_t order_; mutable std::shared_timed_mutex mut_; // keys_.size() == btree_childs_.size() + compressed_childs_.size() // keys_[i] correspond to the first key of child i std::vector keys_; std::vector contexts_; - std::vector*> btree_childs_; + std::vector*> btree_childs_; std::vector compressed_childs_; - std::vector*> compressed_sessions_tree_; + std::vector*> compressed_sessions_tree_; std::vector compressed_sessions_timeout_; //ms std::vector modified_; diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h index be95d5a..9bb13a4 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h @@ -7,7 +7,7 @@ #include #include "mementar/core/memGraphs/Branchs/types/Event.h" -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/Btree/BplusTree.h" #include "mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h" #include "mementar/core/LtManagement/EpisodicTree/Context.h" @@ -19,16 +19,17 @@ namespace mementar class CompressedLeafNodeSession { + using LeafType = typename BplusLeaf::LeafType; public: CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); void insert(Event* data); bool remove(Event* data); - BtreeLeaf* find(const time_t& key); - BtreeLeaf* findNear(const time_t& key); - BtreeLeaf* getFirst(); - BtreeLeaf* getLast(); + LeafType* find(const time_t& key); + LeafType* findNear(const time_t& key); + LeafType* getFirst(); + LeafType* getLast(); time_t getKey() { @@ -49,7 +50,7 @@ class CompressedLeafNodeSession // keys_[i] correspond to the first key of child i std::vector contexts_; std::vector childs_; - std::vector*> sessions_tree_; + std::vector*> sessions_tree_; std::vector modified_; time_t earlier_key_; diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h index 66c921b..1c2c45b 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h @@ -4,7 +4,7 @@ #include "mementar/core/LtManagement/archiving_compressing/archiving/Archive.h" #include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/Btree/BplusTree.h" #include "mementar/core/memGraphs/Branchs/types/Event.h" namespace mementar @@ -18,7 +18,7 @@ class CompressedLeafSession time_t getKey() { return key_; } size_t getIndex() { return index_; } - Btree* getTree(Header& header, Archive& arch); + BplusTree* getTree(Header& header, Archive& arch); std::vector getRawData(Header& header, Archive& arch); private: time_t key_; diff --git a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h index e4dbca5..82fe4a8 100644 --- a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h +++ b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h @@ -9,8 +9,8 @@ namespace mementar { class SoftPoint { public: - //typedef size_t Ttime; - typedef float Ttime; + typedef size_t Ttime; + //typedef float Ttime; SoftPoint(Ttime t_start, std::experimental::optional t_end = std::experimental::nullopt) { diff --git a/include/mementar/core/memGraphs/Btree/BplusTree.h b/include/mementar/core/memGraphs/Btree/BplusTree.h index a82ebcc..62c658d 100644 --- a/include/mementar/core/memGraphs/Btree/BplusTree.h +++ b/include/mementar/core/memGraphs/Btree/BplusTree.h @@ -8,8 +8,8 @@ namespace mementar { template class BplusLeaf { - using LeafType = BtreeLeafBase >; public: + using LeafType = BtreeLeafBase >; using DataType = Tdata; BplusLeaf() @@ -56,6 +56,57 @@ class BplusLeaf private: }; +template +class BplusLeaf +{ +public: + using LeafType = BtreeLeafBase >; + using DataType = Tdata*; + + BplusLeaf() + { + prev_ = nullptr; + next_ = nullptr; + } + + void insert(LeafType* leaf, DataType data) + { + (void)leaf; + payload_.push_back(data); + } + void remove(LeafType* leaf, DataType data) + { + (void)leaf; + for(size_t i = 0; i < payload_.size();) + { + if(payload_[i]->operator==(*data)) + payload_.erase(payload_.begin() + i); + else + i++; + } + } + bool hasData() + { + return (payload_.size() != 0); + } + + std::vector getData() + { + return payload_; + } + + BplusLeaf* getPreviousLeaf() { return prev_; } + BplusLeaf* getNextLeaf() { return next_; } + + void setPreviousLeaf(BplusLeaf* prev) { prev_ = prev; } + void setNextLeaf(BplusLeaf* next) { next_ = next; } + + std::vector payload_; + BplusLeaf* prev_; + BplusLeaf* next_; +private: +}; + template class BplusTree : public Btree, N> { diff --git a/include/mementar/core/memGraphs/Btree/Btree.h b/include/mementar/core/memGraphs/Btree/Btree.h index 679e360..c889164 100644 --- a/include/mementar/core/memGraphs/Btree/Btree.h +++ b/include/mementar/core/memGraphs/Btree/Btree.h @@ -4,6 +4,8 @@ #include "mementar/core/memGraphs/Btree/BtreeLeafBase.h" #include "mementar/core/memGraphs/Btree/BtreeNode.h" +#include + namespace mementar { template @@ -35,6 +37,8 @@ class Btree void displayLinear(int count = -1); void displayTree(); + size_t size() { return nb_data_; } + private: BtreeNode* root_; BtreeLeafBase* first_; diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp index 08620e7..8baca28 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp @@ -57,7 +57,7 @@ ArchivedLeaf::ArchivedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -Btree* ArchivedLeaf::getTree(size_t i) +BplusTree* ArchivedLeaf::getTree(size_t i) { mementar::Archive arch; std::cout << "ArchivedLeaf::getTree READ BINARY FILE " << directory_ << ".mar" << std::endl; @@ -69,7 +69,7 @@ Btree* ArchivedLeaf::getTree(size_t i) LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); std::string out = lz.uncompress(comp_data); - Btree* tree = new Btree(); + BplusTree* tree = new BplusTree(); std::istringstream iss(out); std::string line; diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp index 0095c25..11df5d5 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp @@ -137,9 +137,9 @@ void ArchivedLeafNode::remove(Event* data) mut_.unlock_shared(); } -BtreeLeaf* ArchivedLeafNode::find(const time_t& key) +ArchivedLeafNode::LeafType* ArchivedLeafNode::find(const time_t& key) { - BtreeLeaf* res = nullptr; + ArchivedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -159,9 +159,9 @@ BtreeLeaf* ArchivedLeafNode::find(const time_t& key) return res; } -BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) +ArchivedLeafNode::LeafType* ArchivedLeafNode::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + ArchivedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -182,9 +182,9 @@ BtreeLeaf* ArchivedLeafNode::findNear(const time_t& key) return res; } -BtreeLeaf* ArchivedLeafNode::getFirst() +ArchivedLeafNode::LeafType* ArchivedLeafNode::getFirst() { - BtreeLeaf* res = nullptr; + ArchivedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); if(archived_childs_.size()) @@ -201,9 +201,9 @@ BtreeLeaf* ArchivedLeafNode::getFirst() return res; } -BtreeLeaf* ArchivedLeafNode::getLast() +ArchivedLeafNode::LeafType* ArchivedLeafNode::getLast() { - BtreeLeaf* res = nullptr; + ArchivedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); if(compressed_childs_.size()) @@ -244,7 +244,7 @@ void ArchivedLeafNode::newSession() void ArchivedLeafNode::createNewCompressedChild(const time_t& key) { mut_.lock(); - compressed_childs_.push_back(new CompressedLeafNode(directory_, order_)); + compressed_childs_.push_back(new CompressedLeafNode(directory_)); keys_.push_back(key); mut_.unlock(); } @@ -309,7 +309,7 @@ void ArchivedLeafNode::loadStoredData() Display::Percent(100); Display::Debug(""); - CompressedLeafNode* comp = new CompressedLeafNode(directory_, order_); + CompressedLeafNode* comp = new CompressedLeafNode(directory_); if(comp->getKey() != time_t(-1)) { compressed_childs_.push_back(comp); diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp index fba3df1..b311664 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp @@ -10,7 +10,7 @@ namespace mementar { -CompressedLeaf::CompressedLeaf(Btree* tree, const std::string& directory) +CompressedLeaf::CompressedLeaf(BplusTree* tree, const std::string& directory) { if(tree == nullptr) return; @@ -33,14 +33,14 @@ CompressedLeaf::CompressedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -Btree* CompressedLeaf::getTree() +BplusTree* CompressedLeaf::getTree() { LzUncompress lz; std::vector data; if(lz.readBinaryFile(data, directory_ + ".mlz")) { std::string out = lz.uncompress(data); - Btree* tree = new Btree(); + BplusTree* tree = new BplusTree(); std::istringstream iss(out); std::string line; @@ -57,17 +57,17 @@ Btree* CompressedLeaf::getTree() return nullptr; } -std::string CompressedLeaf::treeToString(Btree* tree) +std::string CompressedLeaf::treeToString(BplusTree* tree) { std::string res; std::vector tmp_data; - BtreeLeaf* it = tree->getFirst(); + BplusLeaf* it = tree->getFirst(); while(it != nullptr) { tmp_data = it->getData(); for(auto& data : tmp_data) res += Event::serialize(data) + "\n"; - it = static_cast*>(it->getNextNode()); + it = static_cast*>(it->getNextLeaf()); } return std::move(res); diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp index 43bffb7..e2d68cf 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp @@ -7,10 +7,9 @@ namespace mementar { -CompressedLeafNode::CompressedLeafNode(std::string directory, size_t order) +CompressedLeafNode::CompressedLeafNode(const std::string& directory) { directory_ = directory; - order_ = order; last_tree_nb_leafs_ = 0; earlier_key_ = 0; @@ -62,7 +61,6 @@ CompressedLeafNode* CompressedLeafNode::split() mut_.lock(); CompressedLeafNode* new_one = new CompressedLeafNode(); new_one->directory_ = directory_; - new_one->order_ = order_; size_t nb = keys_.size()/2; for(size_t i = 0; i < nb; i++) @@ -188,9 +186,9 @@ void CompressedLeafNode::remove(Event* data) mut_.unlock_shared(); } -BtreeLeaf* CompressedLeafNode::find(const time_t& key) +CompressedLeafNode::LeafType* CompressedLeafNode::find(const time_t& key) { - BtreeLeaf* res = nullptr; + CompressedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -210,9 +208,9 @@ BtreeLeaf* CompressedLeafNode::find(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) +CompressedLeafNode::LeafType* CompressedLeafNode::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + CompressedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -233,9 +231,9 @@ BtreeLeaf* CompressedLeafNode::findNear(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNode::getFirst() +CompressedLeafNode::LeafType* CompressedLeafNode::getFirst() { - BtreeLeaf* res = nullptr; + CompressedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); if(compressed_childs_.size()) @@ -252,9 +250,9 @@ BtreeLeaf* CompressedLeafNode::getFirst() return res; } -BtreeLeaf* CompressedLeafNode::getLast() +CompressedLeafNode::LeafType* CompressedLeafNode::getLast() { - BtreeLeaf* res = nullptr; + CompressedLeafNode::LeafType* res = nullptr; mut_.lock_shared(); if(btree_childs_.size()) @@ -281,7 +279,7 @@ void CompressedLeafNode::display(time_t key) if((size_t)index < compressed_childs_.size()) std::cout << compressed_childs_[index].getDirectory() << std::endl; else - btree_childs_[index - compressed_childs_.size()]->display(); + btree_childs_[index - compressed_childs_.size()]->displayTree(); } mut_.unlock_shared(); } @@ -295,7 +293,7 @@ void CompressedLeafNode::init() void CompressedLeafNode::createNewTreeChild(const time_t& key) { mut_.lock(); - btree_childs_.push_back(new Btree(order_)); + btree_childs_.push_back(new BplusTree()); keys_.push_back(key); contexts_.push_back(Context(key)); mut_.unlock(); diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp index 5b220eb..0f0b9a3 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp @@ -114,9 +114,9 @@ bool CompressedLeafNodeSession::remove(Event* data) return res; } -BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key) +CompressedLeafNodeSession::LeafType* CompressedLeafNodeSession::find(const time_t& key) { - BtreeLeaf* res = nullptr; + CompressedLeafNodeSession::LeafType* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -131,9 +131,9 @@ BtreeLeaf* CompressedLeafNodeSession::find(const time_t& key) return res; } -BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& key) +CompressedLeafNodeSession::LeafType* CompressedLeafNodeSession::findNear(const time_t& key) { - BtreeLeaf* res = nullptr; + CompressedLeafNodeSession::LeafType* res = nullptr; mut_.lock_shared(); int index = getKeyIndex(key); @@ -149,9 +149,9 @@ BtreeLeaf* CompressedLeafNodeSession::findNear(const time_t& key return res; } -BtreeLeaf* CompressedLeafNodeSession::getFirst() +CompressedLeafNodeSession::LeafType* CompressedLeafNodeSession::getFirst() { - BtreeLeaf* res = nullptr; + CompressedLeafNodeSession::LeafType* res = nullptr; createSession(0); mut_.lock_shared(); @@ -161,9 +161,9 @@ BtreeLeaf* CompressedLeafNodeSession::getFirst() return res; } -BtreeLeaf* CompressedLeafNodeSession::getLast() +CompressedLeafNodeSession::LeafType* CompressedLeafNodeSession::getLast() { - BtreeLeaf* res = nullptr; + CompressedLeafNodeSession::LeafType* res = nullptr; createSession(childs_.size() - 1); mut_.lock_shared(); @@ -209,13 +209,13 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) std::string res; std::vector tmp_data; - BtreeLeaf* it = sessions_tree_[index]->getFirst(); + BplusLeaf* it = sessions_tree_[index]->getFirst(); while(it != nullptr) { tmp_data = it->getData(); for(auto& data : tmp_data) res += Event::serialize(data) + "\n"; - it = static_cast*>(it->getNextNode()); + it = static_cast*>(it->getNextLeaf()); } mementar::LzCompress lz_comp; diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp index ebf7cb5..2c2a380 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp @@ -14,14 +14,14 @@ CompressedLeafSession::CompressedLeafSession(const time_t& key, size_t index) index_ = index; } -Btree* CompressedLeafSession::getTree(Header& header, Archive& arch) +BplusTree* CompressedLeafSession::getTree(Header& header, Archive& arch) { std::string comp = arch.extractFile(index_, header); LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); std::string out = lz.uncompress(comp_data); - Btree* tree = new Btree(); + BplusTree* tree = new BplusTree(); std::istringstream iss(out); std::string line; diff --git a/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp index 50fee60..8205a9f 100644 --- a/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp @@ -32,7 +32,7 @@ int main() //archived_node.remove(mementar::LinkedFact(102, "bob", "hasValue", std::to_string(102))); archived_node.remove(archived_node.find(102)->getData()[0]); std::cout << "removed" << std::endl; - archived_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 0)); + archived_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 102)); std::cout << "inserted" << std::endl; std::cout << " *************" << std::endl; diff --git a/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp index 51f723e..fab53f0 100644 --- a/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp @@ -35,7 +35,7 @@ int main() std::cout << "took " << time_span.count() << " to insert" << std::endl; compressed_node.remove(compressed_node.find(102)->getData()[0]); - compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 0)); + compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 102)); std::cout << " *************" << std::endl; From 2a12a4ae97185a07278152f5f0b4c6e262e09309 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 15 Jul 2020 08:19:46 +0200 Subject: [PATCH 46/95] [REFACT] all project with new BplusTree --- .../memGraphs/Branchs/ContextualizedEvent.h | 43 ++++++++++++------- .../core/memGraphs/Branchs/types/Event.h | 6 +-- .../core/memGraphs/Graphs/EventGraph.h | 7 +-- src/graphical/timeline/ActionReader.cpp | 8 ++-- src/graphical/timeline/EventReader.cpp | 15 +++---- src/test/graphs.cpp | 16 +++---- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h index 220ddb4..714b9c0 100644 --- a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h +++ b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h @@ -5,16 +5,17 @@ #include "mementar/core/memGraphs/Branchs/types/Action.h" #include "mementar/core/memGraphs/Branchs/ValuedNode.h" -#include "mementar/core/memGraphs/DoublyLinkedList/DllLinkedElement.h" -#include "mementar/core/memGraphs/EventLinkedList/EllElement.h" +#include "mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h" #include namespace mementar { -class ContextualizedEvent : public Event, public ValuedNode, public EllElement +class ContextualizedEvent : public Event, public ValuedNode, public LinkedEvent, ContextualizedEvent> { public: + using LeafType = EventLinkedLeaf; + ContextualizedEvent(const std::string& id, const Event& other, Action* action = nullptr) : Event(other), ValuedNode(id) { action_ = action; @@ -27,31 +28,43 @@ class ContextualizedEvent : public Event, public ValuedNode, public EllElement virtual ~ContextualizedEvent() {} - std::string getId() { return getValue(); } + std::string getId() const { return getValue(); } - bool isPartOfAction() { return action_ != nullptr; } + bool isPartOfAction() const { return action_ != nullptr; } Action* getActionPart() { return action_; } - std::string toString() { return getValue() + " " + SoftPoint::toString() + " : " + getData() + std::string(action_ ? " => part of action " + action_->getName() : ""); } + std::string toString() const { return getValue() + " " + SoftPoint::toString() + " : " + getData() + std::string(action_ ? " => part of action " + action_->getName() : ""); } - virtual void print(std::ostream& os) const + bool operator==(const ContextualizedEvent& other) { - os << getValue(); + return this->Event::operator==(other); } -private: - Action* action_; + bool isPartOf(const ContextualizedEvent& other) + { + return ( (subject_ == other.subject_) && + (predicat_ == other.predicat_) ); + } - bool operator==(const DllLinkedElement* other) + friend std::ostream& operator<<(std::ostream& os, const ContextualizedEvent& evt) { - return this->Event::operator==(static_cast(other)); + os << evt.toString(); + return os; } - virtual bool isEventPart(const DllLinkedElement* other) + std::vector getNextData() { - return ( (subject_ == static_cast(other)->subject_) && - (predicat_ == static_cast(other)->predicat_)); + std::vector res; + auto nextLeaf = getNextLeaf(); + if(nextLeaf != nullptr) + { + res = nextLeaf->getData(); + } + return res; } + +private: + Action* action_; }; } // namespace mementar diff --git a/include/mementar/core/memGraphs/Branchs/types/Event.h b/include/mementar/core/memGraphs/Branchs/types/Event.h index d2ee685..fef4175 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Event.h +++ b/include/mementar/core/memGraphs/Branchs/types/Event.h @@ -71,7 +71,7 @@ class Event : public SoftPoint, public Fact return nullptr; } - std::string getData() { return Fact::toString(); } + std::string getData() const { return Fact::toString(); } friend std::ostream& operator<<(std::ostream& os, Event* event) { @@ -80,12 +80,12 @@ class Event : public SoftPoint, public Fact return os; } - bool operator==(const Event& other) + bool operator==(const Event& other) const { return Fact::operator==(other); } - bool operator==(const Event* other) + bool operator==(const Event* other) const { return Fact::operator==(other); } diff --git a/include/mementar/core/memGraphs/Graphs/EventGraph.h b/include/mementar/core/memGraphs/Graphs/EventGraph.h index e09a0ae..d955d26 100644 --- a/include/mementar/core/memGraphs/Graphs/EventGraph.h +++ b/include/mementar/core/memGraphs/Graphs/EventGraph.h @@ -4,12 +4,13 @@ #include "mementar/core/memGraphs/Graphs/Graph.h" #include "mementar/core/memGraphs/Branchs/ContextualizedEvent.h" -#include "mementar/core/memGraphs/Btree/Btree.h" +#include "mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h" namespace mementar { class EventGraph : public Graph { + using ElBTree = Btree, 10>; public: ~EventGraph(); @@ -28,11 +29,11 @@ class EventGraph : public Graph return all_events_; } - Btree* getTimeline() { return &timeline; } + ElBTree* getTimeline() { return &timeline; } private: std::vector all_events_; - Btree timeline; + ElBTree timeline; }; } // namespace mementar diff --git a/src/graphical/timeline/ActionReader.cpp b/src/graphical/timeline/ActionReader.cpp index 219f862..d3efa7a 100644 --- a/src/graphical/timeline/ActionReader.cpp +++ b/src/graphical/timeline/ActionReader.cpp @@ -13,15 +13,15 @@ ActionReader::ActionReader() void ActionReader::read(EventGraph* graph, CvFont* font) { auto tree = graph->getTimeline(); - DllNode* node = tree->getFirst(); + auto node = static_cast*>(tree->getFirst()); while(node != nullptr) { for(auto evt : node->getData()) { - if(dynamic_cast(evt)->isPartOfAction()) + if(evt->isPartOfAction()) { - auto action = dynamic_cast(evt)->getActionPart(); + auto action = evt->getActionPart(); if(actions_.find(action->getValue()) == actions_.end()) { action_t act = getAction(action); @@ -33,7 +33,7 @@ void ActionReader::read(EventGraph* graph, CvFont* font) } } - node = node->getNextNode(); + node = node->getNextLeaf(); } std::cout << "max_level_ = " << max_level_ << std::endl; diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/EventReader.cpp index 45d48ee..5cd67ae 100644 --- a/src/graphical/timeline/EventReader.cpp +++ b/src/graphical/timeline/EventReader.cpp @@ -7,19 +7,18 @@ void EventReader::read(EventGraph* graph, CvFont* font) max_text_size_ = 0; auto tree = graph->getTimeline(); - auto node = tree->getFirst(); + auto node = static_cast*>(tree->getFirst()); while(node != nullptr) { - event_t group_evt(node->getKey()); + event_t group_evt(node->getData()[0]->getTime()); for(auto evt : node->getData()) { - if(dynamic_cast(evt)->isPartOfAction() == false) + if(evt->isPartOfAction() == false) { - auto event = dynamic_cast(evt); - group_evt.data += (group_evt.data == "" ? "" : " -- ") + event->Fact::toString(); - if(event->getTransitionDuration() > group_evt.time_point.getTransitionDuration()) - group_evt.time_point = SoftPoint(event); + group_evt.data += (group_evt.data == "" ? "" : " -- ") + evt->Fact::toString(); + if(evt->getTransitionDuration() > group_evt.time_point.getTransitionDuration()) + group_evt.time_point = SoftPoint(evt); } } @@ -29,7 +28,7 @@ void EventReader::read(EventGraph* graph, CvFont* font) getTextSize(group_evt.data, font); } - node = dynamic_cast*>(node->getNextNode()); + node = node->getNextLeaf(); } } diff --git a/src/test/graphs.cpp b/src/test/graphs.cpp index 9f48738..bf3fd4e 100644 --- a/src/test/graphs.cpp +++ b/src/test/graphs.cpp @@ -10,24 +10,24 @@ void printNext(mementar::ContextualizedEvent* evt) { - auto nexts = evt->getNextDllData(); + auto nexts = evt->getNextData(); for(auto n : nexts) - std::cout << static_cast(n)->toString() << std::endl; + std::cout << n->toString() << std::endl; if(nexts.size()) - printNext( static_cast(nexts[0])); + printNext(nexts[0]); } void print(mementar::ContextualizedEvent* evt) { std::cout << evt->toString() << std::endl; - auto nexts = evt->getNextDllData(); + auto nexts = evt->getNextData(); for(auto n : nexts) - std::cout << static_cast(n)->toString() << std::endl; + std::cout << n->toString() << std::endl; if(nexts.size()) - printNext( static_cast(nexts[0])); + printNext(nexts[0]); } void printEventList(mementar::ContextualizedEvent* evt) @@ -35,7 +35,7 @@ void printEventList(mementar::ContextualizedEvent* evt) if(evt) { std::cout << evt->toString() << std::endl; - printEventList(dynamic_cast(evt->getNextEllElement())); + printEventList(evt->getNextEvent()); } } @@ -73,7 +73,7 @@ int main() std::cout << event->toString() << std::endl; auto timeline = event_graph.getTimeline(); - timeline->display(); + timeline->displayTree(); std::cout << "********" << std::endl; auto first_evt = event_graph.findBranch("pick_1_start"); From 2c24573437f19f982a7a0cb527283405642458e7 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 15 Jul 2020 09:36:23 +0200 Subject: [PATCH 47/95] [FIX] Btree insert in middle --- include/mementar/core/memGraphs/Btree/Btree.h | 3 ++- .../mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h | 1 + src/core/memGraphs/Graphs/ActionGraph.cpp | 1 - src/graphical/timeline/TimelineDrawer.cpp | 3 ++- src/graphical/timeline/main.cpp | 4 +++- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/mementar/core/memGraphs/Btree/Btree.h b/include/mementar/core/memGraphs/Btree/Btree.h index c889164..def74c3 100644 --- a/include/mementar/core/memGraphs/Btree/Btree.h +++ b/include/mementar/core/memGraphs/Btree/Btree.h @@ -267,6 +267,7 @@ BtreeLeafBase* Btree::insertInLeaf(BtreeNodekeys_[i] == key) { node->leafs_[i]->insert(node->leafs_[i], data); + break; } else if(node->keys_[i] > key) { @@ -283,8 +284,8 @@ BtreeLeafBase* Btree::insertInLeaf(BtreeNodeleafs_.insert(node->leafs_.begin() + i, res); res->setMother(node); res->insert(res, data); + break; } - break; } } } diff --git a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h index 4d2ee4b..5bda5d6 100644 --- a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h +++ b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h @@ -61,6 +61,7 @@ class EventLinkedLeaf : public DataLinkedLeaf DLF::insert(leaf, data); link(this->payload_.back()); } + void remove(typename DLF::LeafType* leaf, Tdata data) { (void)leaf; diff --git a/src/core/memGraphs/Graphs/ActionGraph.cpp b/src/core/memGraphs/Graphs/ActionGraph.cpp index d88a99b..d3ac576 100644 --- a/src/core/memGraphs/Graphs/ActionGraph.cpp +++ b/src/core/memGraphs/Graphs/ActionGraph.cpp @@ -19,7 +19,6 @@ namespace mementar { all_actions_.push_back(action); container_.insert(action); event_graph_->add(action->getStartEvent()); - if(action->isPending()) pending_actions_[action->getName()] = action; else diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index 2469ba6..a07d00e 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -24,9 +24,11 @@ void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline, Acti drawVector(start, end, line_pose); + std::cout << "---ACTIONS----" << std::endl; for(auto act : actions->actions_) drawAction(act.second, line_pose, actions->max_level_, start); + std::cout << "---EVENTS----" << std::endl; for(auto evt : events->events) drawEvent(evt, line_pose, start); @@ -66,7 +68,6 @@ void TimelineDrawer::drawVector(size_t start, size_t end, size_t pose) void TimelineDrawer::drawAction(const action_t& action, size_t line_pose, size_t max_level, size_t start_time) { - std::cout << "draw action " << action.name << std::endl; size_t x_end_pose = line_pose; size_t x_mid_pose = x_end_pose - action.level * SIDE_SPACE; size_t x_start_pose = x_end_pose - (max_level + 1) * SIDE_SPACE; diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index 03498e7..88a5997 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -150,11 +150,13 @@ int main(int argc, char** argv) CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); + std::cout << "-------- READ ACTIONS---------" << std::endl; mementar::ActionReader actions; actions.read(&timeline->events, &font); - + std::cout << "-------- READ EVENTS---------" << std::endl; mementar::EventReader events; events.read(&timeline->events, &font); + std::cout << "-------- DRAW---------" << std::endl; mementar::TimelineDrawer drawer; drawer.draw("out.png", timeline, &actions, &events); From 914c951a0f9a7f8f51f7bf90abcedd4df819ca7c Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Thu, 20 Aug 2020 15:52:48 +0200 Subject: [PATCH 48/95] [REFACT] events to facts in low level structures --- CMakeLists.txt | 4 +- .../LtManagement/EpisodicTree/ArchivedLeaf.h | 2 +- .../EpisodicTree/ArchivedLeafNode.h | 6 +- .../EpisodicTree/CompressedLeaf.h | 8 +- .../EpisodicTree/CompressedLeafNode.h | 12 +- .../EpisodicTree/CompressedLeafNodeSession.h | 10 +- .../EpisodicTree/CompressedLeafSession.h | 4 +- .../core/LtManagement/EpisodicTree/Context.h | 6 +- .../core/Occasions/OccasionsManager.h | 10 +- .../mementar/core/Occasions/Subscription.h | 10 +- .../memGraphs/Branchs/ContextualizedEvent.h | 72 --------- .../memGraphs/Branchs/ContextualizedFact.h | 81 ++++++++++ .../core/memGraphs/Branchs/types/Action.h | 10 +- .../core/memGraphs/Branchs/types/Event.h | 101 ------------ .../core/memGraphs/Branchs/types/Fact.h | 129 ++++++---------- .../core/memGraphs/Branchs/types/Triplet.h | 144 ++++++++++++++++++ .../memGraphs/ExtendedBtree/EventLinkedLeaf.h | 4 +- .../core/memGraphs/Graphs/ActionGraph.h | 8 +- .../core/memGraphs/Graphs/EventGraph.h | 41 ----- .../core/memGraphs/Graphs/FactGraph.h | 41 +++++ include/mementar/core/memGraphs/Timeline.h | 6 +- .../graphical/timeline/ActionReader.h | 4 +- .../mementar/graphical/timeline/EventReader.h | 4 +- src/RosInterface.cpp | 22 +-- .../EpisodicTree/ArchivedLeaf.cpp | 10 +- .../EpisodicTree/ArchivedLeafNode.cpp | 4 +- .../LtManagement/EpisodicTree/CMakeLists.txt | 2 +- .../EpisodicTree/CompressedLeaf.cpp | 18 +-- .../EpisodicTree/CompressedLeafNode.cpp | 6 +- .../CompressedLeafNodeSession.cpp | 12 +- .../EpisodicTree/CompressedLeafSession.cpp | 6 +- .../LtManagement/EpisodicTree/Context.cpp | 24 +-- .../EpisodicTree/tests/archived_tree.cpp | 4 +- .../EpisodicTree/tests/episodic_tree.cpp | 4 +- src/core/Occasions/OccasionsManager.cpp | 24 +-- src/core/Occasions/Subscription.cpp | 12 +- src/core/memGraphs/Branchs/types/Action.cpp | 12 +- src/core/memGraphs/Branchs/types/Event.cpp | 8 - src/core/memGraphs/Branchs/types/Fact.cpp | 2 +- src/core/memGraphs/Branchs/types/Triplet.cpp | 8 + src/core/memGraphs/Graphs/ActionGraph.cpp | 10 +- src/core/memGraphs/Graphs/EventGraph.cpp | 19 --- src/core/memGraphs/Graphs/FactGraph.cpp | 19 +++ src/graphical/timeline/ActionReader.cpp | 14 +- src/graphical/timeline/EventReader.cpp | 22 +-- src/graphical/timeline/TimelineDrawer.cpp | 4 +- src/graphical/timeline/main.cpp | 136 ++++++++--------- src/test/graphs.cpp | 46 +++--- 48 files changed, 587 insertions(+), 578 deletions(-) delete mode 100644 include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h create mode 100644 include/mementar/core/memGraphs/Branchs/ContextualizedFact.h delete mode 100644 include/mementar/core/memGraphs/Branchs/types/Event.h create mode 100644 include/mementar/core/memGraphs/Branchs/types/Triplet.h delete mode 100644 include/mementar/core/memGraphs/Graphs/EventGraph.h create mode 100644 include/mementar/core/memGraphs/Graphs/FactGraph.h delete mode 100644 src/core/memGraphs/Branchs/types/Event.cpp create mode 100644 src/core/memGraphs/Branchs/types/Triplet.cpp delete mode 100644 src/core/memGraphs/Graphs/EventGraph.cpp create mode 100644 src/core/memGraphs/Graphs/FactGraph.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 027167f..fbf6afb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,9 +100,9 @@ add_library(mementar_memGraphs_lib src/core/memGraphs/Branchs/ValuedNode.cpp src/core/memGraphs/Branchs/types/Action.cpp src/core/memGraphs/Branchs/types/Fact.cpp - src/core/memGraphs/Branchs/types/Event.cpp + src/core/memGraphs/Branchs/types/Triplet.cpp src/core/memGraphs/Graphs/ActionGraph.cpp - src/core/memGraphs/Graphs/EventGraph.cpp + src/core/memGraphs/Graphs/FactGraph.cpp ) add_library(mementar_core_lib diff --git a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h index c1caebf..9fdf421 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeaf.h @@ -18,7 +18,7 @@ class ArchivedLeaf std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - BplusTree* getTree(size_t i); + BplusTree* getTree(size_t i); std::vector getContexts(); private: diff --git a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h index 2a08555..6668d73 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h @@ -10,13 +10,13 @@ namespace mementar class ArchivedLeafNode { - using LeafType = typename BplusLeaf::LeafType; + using LeafType = typename BplusLeaf::LeafType; public: ArchivedLeafNode(const std::string& directory, size_t order = 10); ~ArchivedLeafNode(); - void insert(Event* data); - void remove(Event* data); + void insert(Fact* data); + void remove(Fact* data); LeafType* find(const time_t& key); LeafType* findNear(const time_t& key); LeafType* getFirst(); diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h index ff38f10..0e11d85 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h @@ -5,7 +5,7 @@ #include #include "mementar/core/memGraphs/Btree/BplusTree.h" -#include "mementar/core/memGraphs/Branchs/types/Event.h" +#include "mementar/core/memGraphs/Branchs/types/Fact.h" namespace mementar { @@ -13,18 +13,18 @@ namespace mementar class CompressedLeaf { public: - CompressedLeaf(BplusTree* tree, const std::string& directory); + CompressedLeaf(BplusTree* tree, const std::string& directory); CompressedLeaf(const time_t& key, const std::string& directory); std::string getDirectory() { return directory_; } time_t getKey() { return key_; } - BplusTree* getTree(); + BplusTree* getTree(); private: time_t key_; std::string directory_; - std::string treeToString(BplusTree* tree); + std::string treeToString(BplusTree* tree); }; } // namespace mementar diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h index 76884c9..14259e9 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNode.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/memGraphs/Branchs/types/Event.h" +#include "mementar/core/memGraphs/Branchs/types/Fact.h" #include "mementar/core/memGraphs/Btree/BplusTree.h" #include "mementar/core/LtManagement/EpisodicTree/CompressedLeaf.h" #include "mementar/core/LtManagement/EpisodicTree/Context.h" @@ -19,15 +19,15 @@ class ArchivedLeaf; class CompressedLeafNode { friend ArchivedLeaf; - using LeafType = typename BplusLeaf::LeafType; + using LeafType = typename BplusLeaf::LeafType; public: CompressedLeafNode(const std::string& directory); ~CompressedLeafNode(); CompressedLeafNode* split(); - void insert(Event* data); - void remove(Event* data); + void insert(Fact* data); + void remove(Fact* data); LeafType* find(const time_t& key); LeafType* findNear(const time_t& key); LeafType* getFirst(); @@ -58,9 +58,9 @@ class CompressedLeafNode // keys_[i] correspond to the first key of child i std::vector keys_; std::vector contexts_; - std::vector*> btree_childs_; + std::vector*> btree_childs_; std::vector compressed_childs_; - std::vector*> compressed_sessions_tree_; + std::vector*> compressed_sessions_tree_; std::vector compressed_sessions_timeout_; //ms std::vector modified_; diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h index 9bb13a4..e8b44bc 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.h @@ -6,7 +6,7 @@ #include #include -#include "mementar/core/memGraphs/Branchs/types/Event.h" +#include "mementar/core/memGraphs/Branchs/types/Fact.h" #include "mementar/core/memGraphs/Btree/BplusTree.h" #include "mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h" #include "mementar/core/LtManagement/EpisodicTree/Context.h" @@ -19,13 +19,13 @@ namespace mementar class CompressedLeafNodeSession { - using LeafType = typename BplusLeaf::LeafType; + using LeafType = typename BplusLeaf::LeafType; public: CompressedLeafNodeSession(const std::string& file_name); ~CompressedLeafNodeSession(); - void insert(Event* data); - bool remove(Event* data); + void insert(Fact* data); + bool remove(Fact* data); LeafType* find(const time_t& key); LeafType* findNear(const time_t& key); LeafType* getFirst(); @@ -50,7 +50,7 @@ class CompressedLeafNodeSession // keys_[i] correspond to the first key of child i std::vector contexts_; std::vector childs_; - std::vector*> sessions_tree_; + std::vector*> sessions_tree_; std::vector modified_; time_t earlier_key_; diff --git a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h index 1c2c45b..e80b8bd 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h +++ b/include/mementar/core/LtManagement/EpisodicTree/CompressedLeafSession.h @@ -5,7 +5,7 @@ #include "mementar/core/LtManagement/archiving_compressing/archiving/Header.h" #include "mementar/core/memGraphs/Btree/BplusTree.h" -#include "mementar/core/memGraphs/Branchs/types/Event.h" +#include "mementar/core/memGraphs/Branchs/types/Fact.h" namespace mementar { @@ -18,7 +18,7 @@ class CompressedLeafSession time_t getKey() { return key_; } size_t getIndex() { return index_; } - BplusTree* getTree(Header& header, Archive& arch); + BplusTree* getTree(Header& header, Archive& arch); std::vector getRawData(Header& header, Archive& arch); private: time_t key_; diff --git a/include/mementar/core/LtManagement/EpisodicTree/Context.h b/include/mementar/core/LtManagement/EpisodicTree/Context.h index 96b711f..ee108b2 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/Context.h +++ b/include/mementar/core/LtManagement/EpisodicTree/Context.h @@ -5,7 +5,7 @@ #include #include -#include "mementar/core/memGraphs/Branchs/types/Fact.h" +#include "mementar/core/memGraphs/Branchs/types/Triplet.h" namespace mementar { @@ -15,8 +15,8 @@ class Context public: Context(time_t key) { key_ = key; } - void insert(const Fact* fact); - void remove(const Fact* fact); + void insert(const Triplet* triplet); + void remove(const Triplet* triplet); bool exist(const std::string& name); bool subjectExist(const std::string& subject); diff --git a/include/mementar/core/Occasions/OccasionsManager.h b/include/mementar/core/Occasions/OccasionsManager.h index ef0b962..71e2e0d 100644 --- a/include/mementar/core/Occasions/OccasionsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -11,7 +11,7 @@ #include "mementar/MementarOcassionUnsubscription.h" #include "mementar/core/Occasions/Subscription.h" -#include "mementar/core/memGraphs/Branchs/types/Fact.h" +#include "mementar/core/memGraphs/Branchs/types/Triplet.h" namespace mementar { @@ -23,7 +23,7 @@ class OccasionsManager void run(); - void add(const Fact* fact); + void add(const Triplet* triplet); void stop() {run_ = false; } inline bool isRunning() {return run_; } @@ -40,15 +40,15 @@ class OccasionsManager std::mutex mutex_; bool queue_choice_; - std::queue fifo_1; - std::queue fifo_2; + std::queue fifo_1; + std::queue fifo_2; bool SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res); bool UnsubscribeCallback(mementar::MementarOcassionUnsubscription::Request &req, mementar::MementarOcassionUnsubscription::Response &res); - const Fact* get(); + const Triplet* get(); bool empty(); }; diff --git a/include/mementar/core/Occasions/Subscription.h b/include/mementar/core/Occasions/Subscription.h index 57609cb..ba019b5 100644 --- a/include/mementar/core/Occasions/Subscription.h +++ b/include/mementar/core/Occasions/Subscription.h @@ -5,7 +5,7 @@ #include #include -#include "mementar/core/memGraphs/Branchs/types/Fact.h" +#include "mementar/core/memGraphs/Branchs/types/Triplet.h" #include "mementar/core/Occasions/IdManager.h" namespace mementar @@ -14,16 +14,16 @@ namespace mementar class Subscription { public: - size_t subscribe(const Fact& patern, size_t count); + size_t subscribe(const Triplet& patern, size_t count); bool unsubscribe(size_t id); bool isFinished(size_t id); - bool empty() { return fact_paterns_.size() == 0; } + bool empty() { return triplet_paterns_.size() == 0; } - std::vector evaluate(const Fact* fact); + std::vector evaluate(const Triplet* triplet); private: - std::map fact_paterns_; + std::map triplet_paterns_; std::map counts_; std::mutex map_mut_; diff --git a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h b/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h deleted file mode 100644 index 714b9c0..0000000 --- a/include/mementar/core/memGraphs/Branchs/ContextualizedEvent.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef MEMENTAR_CONTEXTUALIZEDEVENT_H -#define MEMENTAR_CONTEXTUALIZEDEVENT_H - -#include "mementar/core/memGraphs/Branchs/types/Event.h" -#include "mementar/core/memGraphs/Branchs/types/Action.h" -#include "mementar/core/memGraphs/Branchs/ValuedNode.h" - -#include "mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h" - -#include - -namespace mementar { - -class ContextualizedEvent : public Event, public ValuedNode, public LinkedEvent, ContextualizedEvent> -{ -public: - using LeafType = EventLinkedLeaf; - - ContextualizedEvent(const std::string& id, const Event& other, Action* action = nullptr) : Event(other), ValuedNode(id) - { - action_ = action; - } - - ContextualizedEvent(const std::string& id, const std::string& data, const SoftPoint& soft_point, Action* action = nullptr) : Event(data, soft_point), ValuedNode(id) - { - action_ = action; - } - - virtual ~ContextualizedEvent() {} - - std::string getId() const { return getValue(); } - - bool isPartOfAction() const { return action_ != nullptr; } - Action* getActionPart() { return action_; } - - std::string toString() const { return getValue() + " " + SoftPoint::toString() + " : " + getData() + std::string(action_ ? " => part of action " + action_->getName() : ""); } - - bool operator==(const ContextualizedEvent& other) - { - return this->Event::operator==(other); - } - - bool isPartOf(const ContextualizedEvent& other) - { - return ( (subject_ == other.subject_) && - (predicat_ == other.predicat_) ); - } - - friend std::ostream& operator<<(std::ostream& os, const ContextualizedEvent& evt) - { - os << evt.toString(); - return os; - } - - std::vector getNextData() - { - std::vector res; - auto nextLeaf = getNextLeaf(); - if(nextLeaf != nullptr) - { - res = nextLeaf->getData(); - } - return res; - } - -private: - Action* action_; -}; - -} // namespace mementar - -#endif // MEMENTAR_CONTEXTUALIZEDEVENT_H diff --git a/include/mementar/core/memGraphs/Branchs/ContextualizedFact.h b/include/mementar/core/memGraphs/Branchs/ContextualizedFact.h new file mode 100644 index 0000000..091fe74 --- /dev/null +++ b/include/mementar/core/memGraphs/Branchs/ContextualizedFact.h @@ -0,0 +1,81 @@ +#ifndef MEMENTAR_CONTEXTUALIZEDFACT_H +#define MEMENTAR_CONTEXTUALIZEDFACT_H + +#include "mementar/core/memGraphs/Branchs/types/Fact.h" +#include "mementar/core/memGraphs/Branchs/types/Action.h" +#include "mementar/core/memGraphs/Branchs/ValuedNode.h" + +#include "mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h" + +#include + +namespace mementar { + +class ContextualizedFact : public Fact, public ValuedNode, public LinkedEvent, ContextualizedFact> +{ +public: + using LeafType = EventLinkedLeaf; + + ContextualizedFact(const std::string& id, const Fact& other, Action* action = nullptr) : Fact(other), ValuedNode(id) + { + action_ = action; + } + + ContextualizedFact(const std::string& id, const std::string& data, const SoftPoint& soft_point, Action* action = nullptr) : Fact(data, soft_point), ValuedNode(id) + { + action_ = action; + } + + virtual ~ContextualizedFact() {} + + std::string getId() const { return getValue(); } + + bool isPartOfAction() const { return action_ != nullptr; } + Action* getActionPart() { return action_; } + + std::string toString() const { return getValue() + " " + SoftPoint::toString() + " : " + getData() + std::string(action_ ? " => part of action " + action_->getName() : ""); } + + bool operator==(const ContextualizedFact& other) + { + return this->Fact::operator==(other); + } + + bool isPartOf(const ContextualizedFact& other) + { + return ( (subject_ == other.subject_) && + (predicat_ == other.predicat_) ); + } + + friend std::ostream& operator<<(std::ostream& os, const ContextualizedFact& ctx_fact) + { + os << ctx_fact.toString(); + return os; + } + + std::vector getNextData() + { + std::vector res; + auto next_leaf = getNextLeaf(); + if(next_leaf != nullptr) + res = next_leaf->getData(); + + return res; + } + + std::vector getPreviousData() + { + std::vector res; + auto prev_leaf = getPreviousLeaf(); + if(prev_leaf != nullptr) + res = prev_leaf->getData(); + + return res; + } + +private: + Action* action_; +}; + +} // namespace mementar + +#endif // MEMENTAR_CONTEXTUALIZEDFACT_H diff --git a/include/mementar/core/memGraphs/Branchs/types/Action.h b/include/mementar/core/memGraphs/Branchs/types/Action.h index 4da4167..e8019bd 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Action.h +++ b/include/mementar/core/memGraphs/Branchs/types/Action.h @@ -8,7 +8,7 @@ namespace mementar { -class ContextualizedEvent; +class ContextualizedFact; class Action : public ValuedNode { @@ -27,12 +27,12 @@ class Action : public ValuedNode bool isSoft(); bool isPending() { return !end_; } - ContextualizedEvent* getStartEvent() { return start_; } - ContextualizedEvent* getEndEvent() { return end_.value(); } + ContextualizedFact* getStartFact() { return start_; } + ContextualizedFact* getEndFact() { return end_.value(); } private: - ContextualizedEvent* start_; - std::experimental::optional end_; + ContextualizedFact* start_; + std::experimental::optional end_; }; } // namespace mementar diff --git a/include/mementar/core/memGraphs/Branchs/types/Event.h b/include/mementar/core/memGraphs/Branchs/types/Event.h deleted file mode 100644 index fef4175..0000000 --- a/include/mementar/core/memGraphs/Branchs/types/Event.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef MEMENTAR_EVENT_H -#define MEMENTAR_EVENT_H - -#include -#include - -#include "mementar/core/memGraphs/Branchs/types/SoftPoint.h" -#include "mementar/core/memGraphs/Branchs/types/Fact.h" - -namespace mementar { - -class Event : public SoftPoint, public Fact -{ -public: - Event(const std::string& data, SoftPoint::Ttime t_start, std::experimental::optional t_end = std::experimental::nullopt) : SoftPoint(t_start, t_end), Fact(data) - { - } - - Event(const std::string& data, const SoftPoint& soft_point) : SoftPoint(soft_point), Fact(data) - { - } - - Event(const Fact& fact, const SoftPoint& soft_point) : SoftPoint(soft_point), Fact(fact) - { - } - - - Event(const Event& other) : SoftPoint(other), Fact(other) - { - } - - static std::string serialize(const Event& event) - { - if(event.isInstantaneous()) - return "[" + std::to_string(event.getTimeStart()) + "]{" + Fact::serialize(&event) + "}"; - else - return "[" + std::to_string(event.getTimeStart()) + "," + std::to_string(event.getTimeEnd()) + "]{" + Fact::serialize(&event) + "}"; - } - - static std::string serialize(const Event* event) - { - if(event->isInstantaneous()) - return "[" + std::to_string(event->getTimeStart()) + "]{" + Fact::serialize(event) + "}"; - else - return "[" + std::to_string(event->getTimeStart()) + "," + std::to_string(event->getTimeEnd()) + "]{" + Fact::serialize(event) + "}"; - } - - static Event deserialize(const std::string& str) - { - if(std::regex_match(str, match, regex)) - { - if(match[3].str() == "") - return Event(Fact::deserialize(match[4].str()), std::stoul(match[1].str())); - else - return Event(Fact::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); - } - else - return Event("", 0); - } - - static Event* deserializePtr(const std::string& str) - { - if(std::regex_match(str, match, regex)) - { - if(match[3].str() == "") - return new Event(Fact::deserialize(match[4].str()), std::stoul(match[1].str())); - else - return new Event(Fact::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); - } - else - return nullptr; - } - - std::string getData() const { return Fact::toString(); } - - friend std::ostream& operator<<(std::ostream& os, Event* event) - { - std::string space = " "; - os << event->getData(); - return os; - } - - bool operator==(const Event& other) const - { - return Fact::operator==(other); - } - - bool operator==(const Event* other) const - { - return Fact::operator==(other); - } - -protected: - - static std::regex regex; - static std::smatch match; -}; - -} // namespace mementar - -#endif // MEMENTAR_EVENT_H diff --git a/include/mementar/core/memGraphs/Branchs/types/Fact.h b/include/mementar/core/memGraphs/Branchs/types/Fact.h index 6404736..b32fbfe 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Fact.h +++ b/include/mementar/core/memGraphs/Branchs/types/Fact.h @@ -2,141 +2,98 @@ #define MEMENTAR_FACT_H #include -#include -#include -#include +#include -namespace mementar -{ +#include "mementar/core/memGraphs/Branchs/types/SoftPoint.h" +#include "mementar/core/memGraphs/Branchs/types/Triplet.h" + +namespace mementar { -class Fact +class Fact : public SoftPoint, public Triplet { public: - Fact(const std::string& subject, const std::string& predicat, const std::string& object, bool add = true) + Fact(const std::string& data, SoftPoint::Ttime t_start, std::experimental::optional t_end = std::experimental::nullopt) : SoftPoint(t_start, t_end), Triplet(data) { - subject_ = subject; - predicat_ = predicat; - object_ = object; - add_ = add; } - Fact(const std::string& triplet = "", bool add = true) + Fact(const std::string& data, const SoftPoint& soft_point) : SoftPoint(soft_point), Triplet(data) { - std::vector splitted = split(triplet, "|"); - if(splitted.size() >= 1) - subject_ = splitted[0]; - if(splitted.size() >= 2) - predicat_ = splitted[1]; - if(splitted.size() >= 3) - object_ = splitted[2]; - add_ = add; } - Fact(const Fact& other) + Fact(const Triplet& triplet, const SoftPoint& soft_point) : SoftPoint(soft_point), Triplet(triplet) + { + } + + + Fact(const Fact& other) : SoftPoint(other), Triplet(other) { - subject_ = other.subject_; - predicat_ = other.predicat_; - object_ = other.object_; - add_ = other.add_; } static std::string serialize(const Fact& fact) { - return (fact.add_ ? "A|" : "D|") + fact.subject_ + "|" + fact.predicat_ + "|" + fact.object_; + if(fact.isInstantaneous()) + return "[" + std::to_string(fact.getTimeStart()) + "]{" + Triplet::serialize(&fact) + "}"; + else + return "[" + std::to_string(fact.getTimeStart()) + "," + std::to_string(fact.getTimeEnd()) + "]{" + Triplet::serialize(&fact) + "}"; } static std::string serialize(const Fact* fact) { - return (fact->add_ ? "A|" : "D|") + fact->subject_ + "|" + fact->predicat_ + "|" + fact->object_; + if(fact->isInstantaneous()) + return "[" + std::to_string(fact->getTimeStart()) + "]{" + Triplet::serialize(fact) + "}"; + else + return "[" + std::to_string(fact->getTimeStart()) + "," + std::to_string(fact->getTimeEnd()) + "]{" + Triplet::serialize(fact) + "}"; } static Fact deserialize(const std::string& str) { if(std::regex_match(str, match, regex)) - return Fact(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + { + if(match[3].str() == "") + return Fact(Triplet::deserialize(match[4].str()), std::stoul(match[1].str())); + else + return Fact(Triplet::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); + } else - return Fact(); + return Fact("", 0); } static Fact* deserializePtr(const std::string& str) { if(std::regex_match(str, match, regex)) - return new Fact(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + { + if(match[3].str() == "") + return new Fact(Triplet::deserialize(match[4].str()), std::stoul(match[1].str())); + else + return new Fact(Triplet::deserialize(match[4].str()), SoftPoint(std::stoul(match[1].str()), std::stoul(match[3].str()))); + } else return nullptr; } - bool valid() const - { - return((subject_ != "") && (predicat_ != "") && (object_ != "")); - } + std::string getData() const { return Triplet::toString(); } - std::string toString() const + friend std::ostream& operator<<(std::ostream& os, Fact* fact) { - return (add_ ? "[add]" : "[del]") + subject_ + " | " + predicat_ + " | " + object_; + std::string space = " "; + os << fact->getData(); + return os; } bool operator==(const Fact& other) const { - return ( (add_ == other.add_) - && (subject_ == other.subject_) - && (predicat_ == other.predicat_) - && (object_ == other.object_)); + return Triplet::operator==(other); } bool operator==(const Fact* other) const { - return ( (add_ == other->add_) - && (subject_ == other->subject_) - && (predicat_ == other->predicat_) - && (object_ == other->object_)); + return Triplet::operator==(other); } - bool fit(const Fact& other) const - { - return ( (add_ == other.add_) - && ((subject_ == other.subject_) || (subject_ == "?") || (other.subject_ == "?")) - && ((predicat_ == other.predicat_) || (predicat_ == "?") || (other.predicat_ == "?")) - && ((object_ == other.object_) || (object_ == "?") || (other.object_ == "?"))); - } - - friend std::ostream& operator<<(std::ostream& os, const Fact& fact) - { - os << fact.toString(); - return os; - } - - std::string subject_; - std::string predicat_; - std::string object_; - bool add_; - protected: + static std::regex regex; static std::smatch match; - -private: - - std::vector split(const std::string& str, const std::string& delim) - { - std::vector tokens; - size_t prev = 0, pos = 0; - do - { - pos = str.find(delim, prev); - if (pos == std::string::npos) - pos = str.length(); - - std::string token = str.substr(prev, pos-prev); - - if (!token.empty()) - tokens.push_back(token); - prev = pos + delim.length(); - } - while ((pos < str.length()) && (prev < str.length())); - - return tokens; - } }; } // namespace mementar diff --git a/include/mementar/core/memGraphs/Branchs/types/Triplet.h b/include/mementar/core/memGraphs/Branchs/types/Triplet.h new file mode 100644 index 0000000..f56ed99 --- /dev/null +++ b/include/mementar/core/memGraphs/Branchs/types/Triplet.h @@ -0,0 +1,144 @@ +#ifndef MEMENTAR_TRIPLET_H +#define MEMENTAR_TRIPLET_H + +#include +#include +#include +#include + +namespace mementar +{ + +class Triplet +{ +public: + Triplet(const std::string& subject, const std::string& predicat, const std::string& object, bool add = true) + { + subject_ = subject; + predicat_ = predicat; + object_ = object; + add_ = add; + } + + Triplet(const std::string& str_triplet = "", bool add = true) + { + std::vector splitted = split(str_triplet, "|"); + if(splitted.size() >= 1) + subject_ = splitted[0]; + if(splitted.size() >= 2) + predicat_ = splitted[1]; + if(splitted.size() >= 3) + object_ = splitted[2]; + add_ = add; + } + + Triplet(const Triplet& other) + { + subject_ = other.subject_; + predicat_ = other.predicat_; + object_ = other.object_; + add_ = other.add_; + } + + static std::string serialize(const Triplet& triplet) + { + return (triplet.add_ ? "A|" : "D|") + triplet.subject_ + "|" + triplet.predicat_ + "|" + triplet.object_; + } + + static std::string serialize(const Triplet* triplet) + { + return (triplet->add_ ? "A|" : "D|") + triplet->subject_ + "|" + triplet->predicat_ + "|" + triplet->object_; + } + + static Triplet deserialize(const std::string& str) + { + if(std::regex_match(str, match, regex)) + return Triplet(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + else + return Triplet(); + } + + static Triplet* deserializePtr(const std::string& str) + { + if(std::regex_match(str, match, regex)) + return new Triplet(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + else + return nullptr; + } + + bool valid() const + { + return((subject_ != "") && (predicat_ != "") && (object_ != "")); + } + + std::string toString() const + { + return (add_ ? "[add]" : "[del]") + subject_ + " | " + predicat_ + " | " + object_; + } + + bool operator==(const Triplet& other) const + { + return ( (add_ == other.add_) + && (subject_ == other.subject_) + && (predicat_ == other.predicat_) + && (object_ == other.object_)); + } + + bool operator==(const Triplet* other) const + { + return ( (add_ == other->add_) + && (subject_ == other->subject_) + && (predicat_ == other->predicat_) + && (object_ == other->object_)); + } + + bool fit(const Triplet& other) const + { + return ( (add_ == other.add_) + && ((subject_ == other.subject_) || (subject_ == "?") || (other.subject_ == "?")) + && ((predicat_ == other.predicat_) || (predicat_ == "?") || (other.predicat_ == "?")) + && ((object_ == other.object_) || (object_ == "?") || (other.object_ == "?"))); + } + + friend std::ostream& operator<<(std::ostream& os, const Triplet& triplet) + { + os << triplet.toString(); + return os; + } + + std::string subject_; + std::string predicat_; + std::string object_; + bool add_; + +protected: + static std::regex regex; + static std::smatch match; + +private: + + std::vector split(const std::string& str, const std::string& delim) + { + std::vector tokens; + size_t prev = 0, pos = 0; + do + { + pos = str.find(delim, prev); + if (pos == std::string::npos) + pos = str.length(); + + std::string token = str.substr(prev, pos-prev); + + if (!token.empty()) + tokens.push_back(token); + prev = pos + delim.length(); + } + while ((pos < str.length()) && (prev < str.length())); + + return tokens; + } +}; + +} // namespace mementar + +#endif // MEMENTAR_TRIPLET_H diff --git a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h index 5bda5d6..1005cc0 100644 --- a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h +++ b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h @@ -22,8 +22,8 @@ class LinkedEvent leaf_ = nullptr; } - SelfType* getNextEvent() { return next_elem_; } - SelfType* getPreviousEvent() { return prev_elem_; } + SelfType* getNext() { return next_elem_; } + SelfType* getPrevious() { return prev_elem_; } Tleaf* getNextLeaf() { diff --git a/include/mementar/core/memGraphs/Graphs/ActionGraph.h b/include/mementar/core/memGraphs/Graphs/ActionGraph.h index c4626c1..1ce2d97 100644 --- a/include/mementar/core/memGraphs/Graphs/ActionGraph.h +++ b/include/mementar/core/memGraphs/Graphs/ActionGraph.h @@ -2,8 +2,8 @@ #define MEMENTAR_ACTIONGRAPH_H #include "mementar/core/memGraphs/Graphs/Graph.h" -#include "mementar/core/memGraphs/Graphs/EventGraph.h" -#include "mementar/core/memGraphs/Branchs/ContextualizedEvent.h" +#include "mementar/core/memGraphs/Graphs/FactGraph.h" +#include "mementar/core/memGraphs/Branchs/ContextualizedFact.h" #include "mementar/core/memGraphs/Branchs/types/Action.h" #include @@ -15,7 +15,7 @@ namespace mementar { class ActionGraph : public Graph { public: - ActionGraph(EventGraph* event_graph); + ActionGraph(FactGraph* fact_graph); ~ActionGraph(); void add(Action* action); @@ -41,7 +41,7 @@ class ActionGraph : public Graph private: - EventGraph* event_graph_; + FactGraph* fact_graph_; std::vector all_actions_; std::map pending_actions_; }; diff --git a/include/mementar/core/memGraphs/Graphs/EventGraph.h b/include/mementar/core/memGraphs/Graphs/EventGraph.h deleted file mode 100644 index d955d26..0000000 --- a/include/mementar/core/memGraphs/Graphs/EventGraph.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MEMENTAR_EVENTGRAPH_H -#define MEMENTAR_EVENTGRAPH_H - -#include "mementar/core/memGraphs/Graphs/Graph.h" -#include "mementar/core/memGraphs/Branchs/ContextualizedEvent.h" - -#include "mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h" - -namespace mementar { - -class EventGraph : public Graph -{ - using ElBTree = Btree, 10>; -public: - - ~EventGraph(); - - void add(ContextualizedEvent* event); - - std::vector get() - { - return all_events_; - } - - std::vector getSafe() - { - std::shared_lock lock(Graph::mutex_); - - return all_events_; - } - - ElBTree* getTimeline() { return &timeline; } - -private: - std::vector all_events_; - ElBTree timeline; -}; - -} // namespace mementar - -#endif // MEMENTAR_EVENTGRAPH_H diff --git a/include/mementar/core/memGraphs/Graphs/FactGraph.h b/include/mementar/core/memGraphs/Graphs/FactGraph.h new file mode 100644 index 0000000..9faec37 --- /dev/null +++ b/include/mementar/core/memGraphs/Graphs/FactGraph.h @@ -0,0 +1,41 @@ +#ifndef MEMENTAR_FACTGRAPH_H +#define MEMENTAR_FACTGRAPH_H + +#include "mementar/core/memGraphs/Graphs/Graph.h" +#include "mementar/core/memGraphs/Branchs/ContextualizedFact.h" + +#include "mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h" + +namespace mementar { + +class FactGraph : public Graph +{ + using ElBTree = Btree, 10>; +public: + + ~FactGraph(); + + void add(ContextualizedFact* fact); + + std::vector get() + { + return all_facts_; + } + + std::vector getSafe() + { + std::shared_lock lock(Graph::mutex_); + + return all_facts_; + } + + ElBTree* getTimeline() { return &timeline; } + +private: + std::vector all_facts_; + ElBTree timeline; +}; + +} // namespace mementar + +#endif // MEMENTAR_FACTGRAPH_H diff --git a/include/mementar/core/memGraphs/Timeline.h b/include/mementar/core/memGraphs/Timeline.h index 751b315..d02baf4 100644 --- a/include/mementar/core/memGraphs/Timeline.h +++ b/include/mementar/core/memGraphs/Timeline.h @@ -1,7 +1,7 @@ #ifndef MEMENTAR_TIMELINE_H #define MEMENTAR_TIMELINE_H -#include "mementar/core/memGraphs/Graphs/EventGraph.h" +#include "mementar/core/memGraphs/Graphs/FactGraph.h" #include "mementar/core/memGraphs/Graphs/ActionGraph.h" namespace mementar { @@ -9,9 +9,9 @@ namespace mementar { class Timeline { public: - Timeline() : actions(&events) {} + Timeline() : actions(&facts) {} - EventGraph events; + FactGraph facts; ActionGraph actions; private: }; diff --git a/include/mementar/graphical/timeline/ActionReader.h b/include/mementar/graphical/timeline/ActionReader.h index 206fbea..9559d13 100644 --- a/include/mementar/graphical/timeline/ActionReader.h +++ b/include/mementar/graphical/timeline/ActionReader.h @@ -7,7 +7,7 @@ #include -#include "mementar/core/memGraphs/Graphs/EventGraph.h" +#include "mementar/core/memGraphs/Graphs/FactGraph.h" namespace mementar { @@ -27,7 +27,7 @@ class ActionReader public: ActionReader(); - void read(EventGraph* graph, CvFont* font); + void read(FactGraph* graph, CvFont* font); std::map actions_; size_t max_level_; diff --git a/include/mementar/graphical/timeline/EventReader.h b/include/mementar/graphical/timeline/EventReader.h index 23320dc..2758883 100644 --- a/include/mementar/graphical/timeline/EventReader.h +++ b/include/mementar/graphical/timeline/EventReader.h @@ -6,7 +6,7 @@ #include -#include "mementar/core/memGraphs/Graphs/EventGraph.h" +#include "mementar/core/memGraphs/Graphs/FactGraph.h" namespace mementar { @@ -22,7 +22,7 @@ class EventReader { public: - void read(EventGraph* graph, CvFont* font); + void read(FactGraph* graph, CvFont* font); std::vector events; size_t max_text_size_; diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index ef6ba51..6065704 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -77,25 +77,25 @@ void RosInterface::reset() void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { - Event* event = new Event(msg->data, time(0)); - if(event->valid()) + Fact* fact = new Fact(msg->data, time(0)); + if(fact->valid()) { mut_.lock_shared(); - tree_->insert(event); + tree_->insert(fact); mut_.unlock_shared(); - occasions_.add(event); + occasions_.add(fact); } } void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { - Event* event = new Event(msg->data, msg->stamp.sec); - if(event->valid()) + Fact* fact = new Fact(msg->data, msg->stamp.sec); + if(fact->valid()) { mut_.lock_shared(); - tree_->insert(event); + tree_->insert(fact); mut_.unlock_shared(); - occasions_.add(event); + occasions_.add(fact); } } @@ -109,11 +109,11 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, if(req.action == "remove") { - Event event(req.param, req.stamp.sec); - if(event.valid()) + Fact fact(req.param, req.stamp.sec); + if(fact.valid()) { mut_.lock_shared(); - tree_->remove(&event); + tree_->remove(&fact); mut_.unlock_shared(); } else diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp index 8baca28..0dcad33 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeaf.cpp @@ -57,7 +57,7 @@ ArchivedLeaf::ArchivedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -BplusTree* ArchivedLeaf::getTree(size_t i) +BplusTree* ArchivedLeaf::getTree(size_t i) { mementar::Archive arch; std::cout << "ArchivedLeaf::getTree READ BINARY FILE " << directory_ << ".mar" << std::endl; @@ -69,15 +69,15 @@ BplusTree* ArchivedLeaf::getTree(size_t i) LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); std::string out = lz.uncompress(comp_data); - BplusTree* tree = new BplusTree(); + BplusTree* tree = new BplusTree(); std::istringstream iss(out); std::string line; while(std::getline(iss, line)) { - Event* event = Event::deserializePtr(line); - if(event != nullptr) - tree->insert(event->getTime(), event); + Fact* fact = Fact::deserializePtr(line); + if(fact != nullptr) + tree->insert(fact->getTime(), fact); } return tree; diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp index 11df5d5..4a97482 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp @@ -50,7 +50,7 @@ ArchivedLeafNode::~ArchivedLeafNode() mut_.unlock(); } -void ArchivedLeafNode::insert(Event* data) +void ArchivedLeafNode::insert(Fact* data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -117,7 +117,7 @@ void ArchivedLeafNode::insert(Event* data) earlier_key_ = data->getTime(); } -void ArchivedLeafNode::remove(Event* data) +void ArchivedLeafNode::remove(Fact* data) { mut_.lock_shared(); int index = getKeyIndex(data->getTime()); diff --git a/src/core/LtManagement/EpisodicTree/CMakeLists.txt b/src/core/LtManagement/EpisodicTree/CMakeLists.txt index 7499034..57538e9 100644 --- a/src/core/LtManagement/EpisodicTree/CMakeLists.txt +++ b/src/core/LtManagement/EpisodicTree/CMakeLists.txt @@ -19,8 +19,8 @@ add_library(mementar_compression_lib ) add_library(mementar_tree_lib - ../../memGraphs/Branchs/types/Event.cpp ../../memGraphs/Branchs/types/Fact.cpp + ../../memGraphs/Branchs/types/Triplet.cpp CompressedLeaf.cpp CompressedLeafNode.cpp Context.cpp diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp index b311664..ed5171b 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeaf.cpp @@ -10,7 +10,7 @@ namespace mementar { -CompressedLeaf::CompressedLeaf(BplusTree* tree, const std::string& directory) +CompressedLeaf::CompressedLeaf(BplusTree* tree, const std::string& directory) { if(tree == nullptr) return; @@ -33,20 +33,20 @@ CompressedLeaf::CompressedLeaf(const time_t& key, const std::string& directory) directory_ = directory.substr(0, dot_pose); } -BplusTree* CompressedLeaf::getTree() +BplusTree* CompressedLeaf::getTree() { LzUncompress lz; std::vector data; if(lz.readBinaryFile(data, directory_ + ".mlz")) { std::string out = lz.uncompress(data); - BplusTree* tree = new BplusTree(); + BplusTree* tree = new BplusTree(); std::istringstream iss(out); std::string line; while(std::getline(iss, line)) { - Event* event = Event::deserializePtr(line); + Fact* event = Fact::deserializePtr(line); if(event != nullptr) tree->insert(event->getTime(), event); } @@ -57,17 +57,17 @@ BplusTree* CompressedLeaf::getTree() return nullptr; } -std::string CompressedLeaf::treeToString(BplusTree* tree) +std::string CompressedLeaf::treeToString(BplusTree* tree) { std::string res; - std::vector tmp_data; - BplusLeaf* it = tree->getFirst(); + std::vector tmp_data; + BplusLeaf* it = tree->getFirst(); while(it != nullptr) { tmp_data = it->getData(); for(auto& data : tmp_data) - res += Event::serialize(data) + "\n"; - it = static_cast*>(it->getNextLeaf()); + res += Fact::serialize(data) + "\n"; + it = static_cast*>(it->getNextLeaf()); } return std::move(res); diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp index e2d68cf..aee0245 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp @@ -86,7 +86,7 @@ CompressedLeafNode* CompressedLeafNode::split() return new_one; } -void CompressedLeafNode::insert(Event* data) +void CompressedLeafNode::insert(Fact* data) { mut_.lock_shared(); if(keys_.size() == 0) @@ -160,7 +160,7 @@ void CompressedLeafNode::insert(Event* data) earlier_key_ = data->getTime(); } -void CompressedLeafNode::remove(Event* data) +void CompressedLeafNode::remove(Fact* data) { mut_.lock_shared(); int index = getKeyIndex(data->getTime()); @@ -293,7 +293,7 @@ void CompressedLeafNode::init() void CompressedLeafNode::createNewTreeChild(const time_t& key) { mut_.lock(); - btree_childs_.push_back(new BplusTree()); + btree_childs_.push_back(new BplusTree()); keys_.push_back(key); contexts_.push_back(Context(key)); mut_.unlock(); diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp index 0f0b9a3..a980732 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp @@ -66,7 +66,7 @@ int CompressedLeafNodeSession::getKeyIndex(const time_t& key) return index; } -void CompressedLeafNodeSession::insert(Event* data) +void CompressedLeafNodeSession::insert(Fact* data) { mut_.lock_shared(); if(contexts_.size() == 0) @@ -93,7 +93,7 @@ void CompressedLeafNodeSession::insert(Event* data) mut_.unlock_shared(); } -bool CompressedLeafNodeSession::remove(Event* data) +bool CompressedLeafNodeSession::remove(Fact* data) { bool res = false; mut_.lock_shared(); @@ -208,14 +208,14 @@ std::vector CompressedLeafNodeSession::treeToRaw(size_t index) { std::string res; - std::vector tmp_data; - BplusLeaf* it = sessions_tree_[index]->getFirst(); + std::vector tmp_data; + BplusLeaf* it = sessions_tree_[index]->getFirst(); while(it != nullptr) { tmp_data = it->getData(); for(auto& data : tmp_data) - res += Event::serialize(data) + "\n"; - it = static_cast*>(it->getNextLeaf()); + res += Fact::serialize(data) + "\n"; + it = static_cast*>(it->getNextLeaf()); } mementar::LzCompress lz_comp; diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp index 2c2a380..395e2bc 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafSession.cpp @@ -14,20 +14,20 @@ CompressedLeafSession::CompressedLeafSession(const time_t& key, size_t index) index_ = index; } -BplusTree* CompressedLeafSession::getTree(Header& header, Archive& arch) +BplusTree* CompressedLeafSession::getTree(Header& header, Archive& arch) { std::string comp = arch.extractFile(index_, header); LzUncompress lz; std::vector comp_data(comp.begin(), comp.end()); std::string out = lz.uncompress(comp_data); - BplusTree* tree = new BplusTree(); + BplusTree* tree = new BplusTree(); std::istringstream iss(out); std::string line; while(std::getline(iss, line)) { - Event* event = Event::deserializePtr(line); + Fact* event = Fact::deserializePtr(line); if(event != nullptr) tree->insert(event->getTime(), event); } diff --git a/src/core/LtManagement/EpisodicTree/Context.cpp b/src/core/LtManagement/EpisodicTree/Context.cpp index 0c3518f..e355388 100644 --- a/src/core/LtManagement/EpisodicTree/Context.cpp +++ b/src/core/LtManagement/EpisodicTree/Context.cpp @@ -11,45 +11,45 @@ namespace mementar { -void Context::insert(const Fact* fact) +void Context::insert(const Triplet* triplet) { std::map::iterator it; - it = subjects_.find(fact->subject_); + it = subjects_.find(triplet->subject_); if(it != subjects_.end()) it->second++; else - subjects_[fact->subject_] = 1; + subjects_[triplet->subject_] = 1; - it = predicats_.find(fact->predicat_); + it = predicats_.find(triplet->predicat_); if(it != predicats_.end()) it->second++; else - predicats_[fact->predicat_] = 1; + predicats_[triplet->predicat_] = 1; - if(fact->object_.find(":") == std::string::npos) + if(triplet->object_.find(":") == std::string::npos) { - it = objects_.find(fact->object_); + it = objects_.find(triplet->object_); if(it != objects_.end()) it->second++; else - objects_[fact->object_] = 1; + objects_[triplet->object_] = 1; } } -void Context::remove(const Fact* fact) +void Context::remove(const Triplet* triplet) { std::map::iterator it; - it = subjects_.find(fact->subject_); + it = subjects_.find(triplet->subject_); if(it != subjects_.end()) it->second--; - it = predicats_.find(fact->predicat_); + it = predicats_.find(triplet->predicat_); if(it != predicats_.end()) it->second--; - it = objects_.find(fact->object_); + it = objects_.find(triplet->object_); if(it != objects_.end()) it->second--; } diff --git a/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp index 8205a9f..4d19b77 100644 --- a/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/archived_tree.cpp @@ -18,7 +18,7 @@ int main() std::cout << " *************" << std::endl; for(size_t i = 0; i < 400000; i++) { - archived_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(i)), i)); + archived_node.insert(new mementar::Fact(mementar::Triplet("bob", "hasValue", std::to_string(i)), i)); if(i == 250000) archived_node.newSession(); } @@ -32,7 +32,7 @@ int main() //archived_node.remove(mementar::LinkedFact(102, "bob", "hasValue", std::to_string(102))); archived_node.remove(archived_node.find(102)->getData()[0]); std::cout << "removed" << std::endl; - archived_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 102)); + archived_node.insert(new mementar::Fact(mementar::Triplet("bob", "hasValue", std::to_string(0)), 102)); std::cout << "inserted" << std::endl; std::cout << " *************" << std::endl; diff --git a/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp index fab53f0..33e37a4 100644 --- a/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp +++ b/src/core/LtManagement/EpisodicTree/tests/episodic_tree.cpp @@ -25,7 +25,7 @@ int main() for(size_t i = 0; i < 400000; i++) { //std::cout << i << std::endl; - compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(i)), i)); + compressed_node.insert(new mementar::Fact(mementar::Triplet("bob", "hasValue", std::to_string(i)), i)); //usleep(1); } std::cout << " *************" << std::endl; @@ -35,7 +35,7 @@ int main() std::cout << "took " << time_span.count() << " to insert" << std::endl; compressed_node.remove(compressed_node.find(102)->getData()[0]); - compressed_node.insert(new mementar::Event(mementar::Fact("bob", "hasValue", std::to_string(0)), 102)); + compressed_node.insert(new mementar::Fact(mementar::Triplet("bob", "hasValue", std::to_string(0)), 102)); std::cout << " *************" << std::endl; diff --git a/src/core/Occasions/OccasionsManager.cpp b/src/core/Occasions/OccasionsManager.cpp index 3096bb3..88d6e6e 100644 --- a/src/core/Occasions/OccasionsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -27,15 +27,15 @@ void OccasionsManager::run() { while(!empty()) { - const Fact* fact = get(); - if(fact->valid()) + const Triplet* triplet = get(); + if(triplet->valid()) { - std::vector ids = subscription_.evaluate(fact); + std::vector ids = subscription_.evaluate(triplet); for(auto id : ids) { mementar::MementarOccasion msg; msg.id = id; - msg.data = fact->toString(); + msg.data = triplet->toString(); msg.last = subscription_.isFinished(id); pub_.publish(msg); } @@ -45,24 +45,24 @@ void OccasionsManager::run() } } -void OccasionsManager::add(const Fact* fact) +void OccasionsManager::add(const Triplet* triplet) { mutex_.lock(); if(queue_choice_ == true) - fifo_1.push(fact); + fifo_1.push(triplet); else - fifo_2.push(fact); + fifo_2.push(triplet); mutex_.unlock(); } bool OccasionsManager::SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res) { - Fact fact_patern(req.data); - if(!fact_patern.valid()) + Triplet triplet_patern(req.data); + if(!triplet_patern.valid()) return false; - res.id = subscription_.subscribe(fact_patern, req.count); + res.id = subscription_.subscribe(triplet_patern, req.count); return true; } @@ -78,9 +78,9 @@ bool OccasionsManager::UnsubscribeCallback(mementar::MementarOcassionUnsubscript return true; } -const Fact* OccasionsManager::get() +const Triplet* OccasionsManager::get() { - const Fact* res = nullptr; + const Triplet* res = nullptr; mutex_.lock(); if(queue_choice_ == true) { diff --git a/src/core/Occasions/Subscription.cpp b/src/core/Occasions/Subscription.cpp index d2fe29d..62e07bb 100644 --- a/src/core/Occasions/Subscription.cpp +++ b/src/core/Occasions/Subscription.cpp @@ -3,11 +3,11 @@ namespace mementar { -size_t Subscription::subscribe(const Fact& patern, size_t count) +size_t Subscription::subscribe(const Triplet& patern, size_t count) { map_mut_.lock(); size_t id = id_manager_.getNewId(); - fact_paterns_.insert(std::pair(id, patern)); + triplet_paterns_.insert(std::pair(id, patern)); counts_[id] = count; map_mut_.unlock(); @@ -20,7 +20,7 @@ bool Subscription::unsubscribe(size_t id) map_mut_.lock(); if(id_manager_.removeId(id)) { - fact_paterns_.erase(id); + triplet_paterns_.erase(id); counts_.erase(id); } else @@ -42,14 +42,14 @@ bool Subscription::isFinished(size_t id) return res; } -std::vector Subscription::evaluate(const Fact* fact) +std::vector Subscription::evaluate(const Triplet* triplet) { std::vector res; map_mut_.lock(); - for(auto it : fact_paterns_) + for(auto& it : triplet_paterns_) { - if(fact->fit(it.second)) + if(triplet->fit(it.second)) { if(counts_[it.first]) { diff --git a/src/core/memGraphs/Branchs/types/Action.cpp b/src/core/memGraphs/Branchs/types/Action.cpp index 3297bd0..7f26738 100644 --- a/src/core/memGraphs/Branchs/types/Action.cpp +++ b/src/core/memGraphs/Branchs/types/Action.cpp @@ -1,20 +1,20 @@ #include "mementar/core/memGraphs/Branchs/types/Action.h" -#include "mementar/core/memGraphs/Branchs/ContextualizedEvent.h" +#include "mementar/core/memGraphs/Branchs/ContextualizedFact.h" namespace mementar { Action::Action(const std::string& name, const SoftPoint& start, const std::experimental::optional& end) : ValuedNode(name) { - start_ = new ContextualizedEvent(std::string(name + "_start"), Event(name + "|_|start", start), this); + start_ = new ContextualizedFact(std::string(name + "_start"), Fact(name + "|_|start", start), this); if(end) - end_ = new ContextualizedEvent(std::string(name + "_end"), Event(name + "|_|end", end.value()), this); + end_ = new ContextualizedFact(std::string(name + "_end"), Fact(name + "|_|end", end.value()), this); } Action::Action(const std::string& name, const SoftPoint& start, const SoftPoint::Ttime& end) : ValuedNode(name) { - start_ = new ContextualizedEvent(std::string(name + "_start"), Event(name + "|_|start", start), this); - end_ = new ContextualizedEvent(std::string(name + "_end"), Event(name + "|_|end", end), this); + start_ = new ContextualizedFact(std::string(name + "_start"), Fact(name + "|_|start", start), this); + end_ = new ContextualizedFact(std::string(name + "_end"), Fact(name + "|_|end", end), this); } bool Action::setEnd(const SoftPoint& end) @@ -22,7 +22,7 @@ bool Action::setEnd(const SoftPoint& end) if(end_) return false; - end_ = new ContextualizedEvent(std::string(getValue() + "_end"), Event(getValue() + "|_|end", end), this); + end_ = new ContextualizedFact(std::string(getValue() + "_end"), Fact(getValue() + "|_|end", end), this); return true; } diff --git a/src/core/memGraphs/Branchs/types/Event.cpp b/src/core/memGraphs/Branchs/types/Event.cpp deleted file mode 100644 index 5e046bc..0000000 --- a/src/core/memGraphs/Branchs/types/Event.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "mementar/core/memGraphs/Branchs/types/Event.h" - -namespace mementar { - -std::regex Event::regex("\\[(\\d*)(,(\\d*))?\\]\\{([^\\}]*)\\}"); -std::smatch Event::match; - -} // namespace mementar diff --git a/src/core/memGraphs/Branchs/types/Fact.cpp b/src/core/memGraphs/Branchs/types/Fact.cpp index 7566b86..b6ad3ec 100644 --- a/src/core/memGraphs/Branchs/types/Fact.cpp +++ b/src/core/memGraphs/Branchs/types/Fact.cpp @@ -2,7 +2,7 @@ namespace mementar { -std::regex Fact::regex("(\\w)\\|(\\w+)\\|(\\w+)\\|(\\w+)"); +std::regex Fact::regex("\\[(\\d*)(,(\\d*))?\\]\\{([^\\}]*)\\}"); std::smatch Fact::match; } // namespace mementar diff --git a/src/core/memGraphs/Branchs/types/Triplet.cpp b/src/core/memGraphs/Branchs/types/Triplet.cpp new file mode 100644 index 0000000..8688165 --- /dev/null +++ b/src/core/memGraphs/Branchs/types/Triplet.cpp @@ -0,0 +1,8 @@ +#include "mementar/core/memGraphs/Branchs/types/Triplet.h" + +namespace mementar { + +std::regex Triplet::regex("(\\w)\\|(\\w+)\\|(\\w+)\\|(\\w+)"); +std::smatch Triplet::match; + +} // namespace mementar diff --git a/src/core/memGraphs/Graphs/ActionGraph.cpp b/src/core/memGraphs/Graphs/ActionGraph.cpp index d3ac576..90fc863 100644 --- a/src/core/memGraphs/Graphs/ActionGraph.cpp +++ b/src/core/memGraphs/Graphs/ActionGraph.cpp @@ -2,9 +2,9 @@ namespace mementar { - ActionGraph::ActionGraph(EventGraph* event_graph) + ActionGraph::ActionGraph(FactGraph* fact_graph) { - event_graph_ = event_graph; + fact_graph_ = fact_graph; } ActionGraph::~ActionGraph() @@ -18,11 +18,11 @@ namespace mementar { { all_actions_.push_back(action); container_.insert(action); - event_graph_->add(action->getStartEvent()); + fact_graph_->add(action->getStartFact()); if(action->isPending()) pending_actions_[action->getName()] = action; else - event_graph_->add(action->getEndEvent()); + fact_graph_->add(action->getEndFact()); } bool ActionGraph::setEnd(const std::string& action_name, const SoftPoint& end) @@ -35,7 +35,7 @@ namespace mementar { if(action_it->second->setEnd(end)) { pending_actions_.erase(action_it); - event_graph_->add(action_it->second->getEndEvent()); + fact_graph_->add(action_it->second->getEndFact()); return true; } else diff --git a/src/core/memGraphs/Graphs/EventGraph.cpp b/src/core/memGraphs/Graphs/EventGraph.cpp deleted file mode 100644 index 2ebd544..0000000 --- a/src/core/memGraphs/Graphs/EventGraph.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "mementar/core/memGraphs/Graphs/EventGraph.h" - -namespace mementar { - -EventGraph::~EventGraph() -{ - for(size_t i = 0; i < all_events_.size(); i++) - delete all_events_[i]; - all_events_.clear(); -} - -void EventGraph::add(ContextualizedEvent* event) -{ - all_events_.push_back(event); - container_.insert(event); - timeline.insert(event->getTime(), event); -} - -} // namespace mementar diff --git a/src/core/memGraphs/Graphs/FactGraph.cpp b/src/core/memGraphs/Graphs/FactGraph.cpp new file mode 100644 index 0000000..760a063 --- /dev/null +++ b/src/core/memGraphs/Graphs/FactGraph.cpp @@ -0,0 +1,19 @@ +#include "mementar/core/memGraphs/Graphs/FactGraph.h" + +namespace mementar { + +FactGraph::~FactGraph() +{ + for(size_t i = 0; i < all_facts_.size(); i++) + delete all_facts_[i]; + all_facts_.clear(); +} + +void FactGraph::add(ContextualizedFact* fact) +{ + all_facts_.push_back(fact); + container_.insert(fact); + timeline.insert(fact->getTime(), fact); +} + +} // namespace mementar diff --git a/src/graphical/timeline/ActionReader.cpp b/src/graphical/timeline/ActionReader.cpp index d3efa7a..0893b30 100644 --- a/src/graphical/timeline/ActionReader.cpp +++ b/src/graphical/timeline/ActionReader.cpp @@ -10,18 +10,18 @@ ActionReader::ActionReader() max_text_size_ = 0; } -void ActionReader::read(EventGraph* graph, CvFont* font) +void ActionReader::read(FactGraph* graph, CvFont* font) { auto tree = graph->getTimeline(); - auto node = static_cast*>(tree->getFirst()); + auto node = static_cast*>(tree->getFirst()); while(node != nullptr) { - for(auto evt : node->getData()) + for(auto fact : node->getData()) { - if(evt->isPartOfAction()) + if(fact->isPartOfAction()) { - auto action = evt->getActionPart(); + auto action = fact->getActionPart(); if(actions_.find(action->getValue()) == actions_.end()) { action_t act = getAction(action); @@ -42,7 +42,7 @@ void ActionReader::read(EventGraph* graph, CvFont* font) action_t ActionReader::getAction(Action* action) { - action_t new_action(*action->getStartEvent()); + action_t new_action(*action->getStartFact()); new_action.name = action->getValue(); new_action.level = getMinLevel(); @@ -58,7 +58,7 @@ void ActionReader::closeAction(Action* action) auto act_it = actions_.find(action->getValue()); auto level_it = std::find(levels_.begin(), levels_.end(), act_it->second.level); levels_.erase(level_it); - act_it->second.end = SoftPoint(*action->getEndEvent()); + act_it->second.end = SoftPoint(*action->getEndFact()); } size_t ActionReader::getMinLevel() diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/EventReader.cpp index 5cd67ae..1d02e9f 100644 --- a/src/graphical/timeline/EventReader.cpp +++ b/src/graphical/timeline/EventReader.cpp @@ -2,30 +2,30 @@ namespace mementar { -void EventReader::read(EventGraph* graph, CvFont* font) +void EventReader::read(FactGraph* graph, CvFont* font) { max_text_size_ = 0; auto tree = graph->getTimeline(); - auto node = static_cast*>(tree->getFirst()); + auto node = static_cast*>(tree->getFirst()); while(node != nullptr) { - event_t group_evt(node->getData()[0]->getTime()); - for(auto evt : node->getData()) + event_t group_fact(node->getData()[0]->getTime()); + for(auto fact : node->getData()) { - if(evt->isPartOfAction() == false) + if(fact->isPartOfAction() == false) { - group_evt.data += (group_evt.data == "" ? "" : " -- ") + evt->Fact::toString(); - if(evt->getTransitionDuration() > group_evt.time_point.getTransitionDuration()) - group_evt.time_point = SoftPoint(evt); + group_fact.data += (group_fact.data == "" ? "" : " -- ") + fact->Triplet::toString(); + if(fact->getTransitionDuration() > group_fact.time_point.getTransitionDuration()) + group_fact.time_point = SoftPoint(fact); } } - if(group_evt.data != "") + if(group_fact.data != "") { - events.push_back(group_evt); - getTextSize(group_evt.data, font); + events.push_back(group_fact); + getTextSize(group_fact.data, font); } node = node->getNextLeaf(); diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index a07d00e..5db81d1 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -11,8 +11,8 @@ namespace mementar { void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, EventReader* events) { - size_t start = timeline->events.getTimeline()->getFirst()->getKey(); - size_t end = timeline->events.getTimeline()->getLast()->getKey(); + size_t start = timeline->facts.getTimeline()->getFirst()->getKey(); + size_t end = timeline->facts.getTimeline()->getLast()->getKey(); size_t width = (actions->max_level_ + 1) * SIDE_SPACE + actions->max_text_size_ + MARGIN * 3 + SIDE_SPACE + events->max_text_size_; size_t height = (end - start) * UNIT_SPACE + MARGIN * 2; diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index 88a5997..474ebc3 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -31,33 +31,33 @@ mementar::Timeline* getTimeline() timeline->actions.add(new mementar::Action("rob_drop_2", 170, 174)); timeline->actions.add(new mementar::Action("rob_ack_5", 176, 176)); - timeline->events.add(new mementar::ContextualizedEvent("e0", mementar::Event("pr2|isInRoom|expe_room", 4))); - timeline->events.add(new mementar::ContextualizedEvent("e1", mementar::Event("grey_box|isOn|Table_1", 5))); - timeline->events.add(new mementar::ContextualizedEvent("e2", mementar::Event("tape_1|isOn|Table_1", 5))); - timeline->events.add(new mementar::ContextualizedEvent("e3", mementar::Event("tape_2|isIn|storage_area", 5))); - timeline->events.add(new mementar::ContextualizedEvent("e4", mementar::Event("hum_green|isInRoom|expe_room", 6,7))); - timeline->events.add(new mementar::ContextualizedEvent("e5", mementar::Event(mementar::Fact("hum_green|isInRoom|expe_room", false), mementar::SoftPoint(25,26)))); - timeline->events.add(new mementar::ContextualizedEvent("e6", mementar::Event("hum_blue|isInRoom|expe_room", 30,31))); - timeline->events.add(new mementar::ContextualizedEvent("e7", mementar::Event("tape_1|isInHand|hum_blue", 37))); - timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); - timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); - timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); - timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); - timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); - timeline->events.add(new mementar::ContextualizedEvent("e13", mementar::Event("hum_green|isInRoom|expe_room", 53))); - timeline->events.add(new mementar::ContextualizedEvent("e14", mementar::Event("tape_2|isInGripper|pr2", 86))); - timeline->events.add(new mementar::ContextualizedEvent("e15", mementar::Event(mementar::Fact("tape_2|isIn|storage_area", false), 101))); - timeline->events.add(new mementar::ContextualizedEvent("e16", mementar::Event(mementar::Fact("tape_2|isInGripper|pr2", false), 107))); - timeline->events.add(new mementar::ContextualizedEvent("e17", mementar::Event("tape_2|isIn|pink_box", 107,110))); - timeline->events.add(new mementar::ContextualizedEvent("e18", mementar::Event("tape_1|isInHand|hum_green", 133, 134))); - timeline->events.add(new mementar::ContextualizedEvent("e19", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 134))); - timeline->events.add(new mementar::ContextualizedEvent("e20", mementar::Event(mementar::Fact("tape_1|isBehind|grey_box", false), 134))); - timeline->events.add(new mementar::ContextualizedEvent("e21", mementar::Event("tape_1|isIn|storage_area", 145))); - timeline->events.add(new mementar::ContextualizedEvent("e23", mementar::Event(mementar::Fact("tape_1|isInHand|hum_green", false), 145))); - timeline->events.add(new mementar::ContextualizedEvent("e24", mementar::Event("tape_1|isInGripper|pr2", 162))); - timeline->events.add(new mementar::ContextualizedEvent("e25", mementar::Event(mementar::Fact("tape_1|isIn|storage_area", false), 170))); - timeline->events.add(new mementar::ContextualizedEvent("e26", mementar::Event(mementar::Fact("tape_1|isInGripper|pr2", false), 173))); - timeline->events.add(new mementar::ContextualizedEvent("e27", mementar::Event("tape_1|isIn|pink_box", 173,175))); + timeline->facts.add(new mementar::ContextualizedFact("e0", mementar::Fact("pr2|isInRoom|expe_room", 4))); + timeline->facts.add(new mementar::ContextualizedFact("e1", mementar::Fact("grey_box|isOn|Table_1", 5))); + timeline->facts.add(new mementar::ContextualizedFact("e2", mementar::Fact("tape_1|isOn|Table_1", 5))); + timeline->facts.add(new mementar::ContextualizedFact("e3", mementar::Fact("tape_2|isIn|storage_area", 5))); + timeline->facts.add(new mementar::ContextualizedFact("e4", mementar::Fact("hum_green|isInRoom|expe_room", 6,7))); + timeline->facts.add(new mementar::ContextualizedFact("e5", mementar::Fact(mementar::Triplet("hum_green|isInRoom|expe_room", false), mementar::SoftPoint(25,26)))); + timeline->facts.add(new mementar::ContextualizedFact("e6", mementar::Fact("hum_blue|isInRoom|expe_room", 30,31))); + timeline->facts.add(new mementar::ContextualizedFact("e7", mementar::Fact("tape_1|isInHand|hum_blue", 37))); + timeline->facts.add(new mementar::ContextualizedFact("e8", mementar::Fact(mementar::Triplet("tape_1|isOn|Table_1", false), 37))); + timeline->facts.add(new mementar::ContextualizedFact("e9", mementar::Fact("tape_1|isOn|Table_1", 38, 42))); + timeline->facts.add(new mementar::ContextualizedFact("e10", mementar::Fact("tape_1|isBehind|grey_box", 38))); + timeline->facts.add(new mementar::ContextualizedFact("e11", mementar::Fact(mementar::Triplet("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); + timeline->facts.add(new mementar::ContextualizedFact("e12", mementar::Fact(mementar::Triplet("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); + timeline->facts.add(new mementar::ContextualizedFact("e13", mementar::Fact("hum_green|isInRoom|expe_room", 53))); + timeline->facts.add(new mementar::ContextualizedFact("e14", mementar::Fact("tape_2|isInGripper|pr2", 86))); + timeline->facts.add(new mementar::ContextualizedFact("e15", mementar::Fact(mementar::Triplet("tape_2|isIn|storage_area", false), 101))); + timeline->facts.add(new mementar::ContextualizedFact("e16", mementar::Fact(mementar::Triplet("tape_2|isInGripper|pr2", false), 107))); + timeline->facts.add(new mementar::ContextualizedFact("e17", mementar::Fact("tape_2|isIn|pink_box", 107,110))); + timeline->facts.add(new mementar::ContextualizedFact("e18", mementar::Fact("tape_1|isInHand|hum_green", 133, 134))); + timeline->facts.add(new mementar::ContextualizedFact("e19", mementar::Fact(mementar::Triplet("tape_1|isOn|Table_1", false), 134))); + timeline->facts.add(new mementar::ContextualizedFact("e20", mementar::Fact(mementar::Triplet("tape_1|isBehind|grey_box", false), 134))); + timeline->facts.add(new mementar::ContextualizedFact("e21", mementar::Fact("tape_1|isIn|storage_area", 145))); + timeline->facts.add(new mementar::ContextualizedFact("e23", mementar::Fact(mementar::Triplet("tape_1|isInHand|hum_green", false), 145))); + timeline->facts.add(new mementar::ContextualizedFact("e24", mementar::Fact("tape_1|isInGripper|pr2", 162))); + timeline->facts.add(new mementar::ContextualizedFact("e25", mementar::Fact(mementar::Triplet("tape_1|isIn|storage_area", false), 170))); + timeline->facts.add(new mementar::ContextualizedFact("e26", mementar::Fact(mementar::Triplet("tape_1|isInGripper|pr2", false), 173))); + timeline->facts.add(new mementar::ContextualizedFact("e27", mementar::Fact("tape_1|isIn|pink_box", 173,175))); return timeline; } @@ -88,32 +88,32 @@ mementar::Timeline* getTimeline() timeline->actions.add(new mementar::Action("rob_drop_2", 170, 174)); timeline->actions.add(new mementar::Action("rob_ack_5", 176, 176)); - timeline->events.add(new mementar::ContextualizedEvent("e0", mementar::Event("pr2|isInRoom|expe_room", 6,7))); - timeline->events.add(new mementar::ContextualizedEvent("e1", mementar::Event("grey_box|isOn|Table_1", 7, 8))); - timeline->events.add(new mementar::ContextualizedEvent("e2", mementar::Event("tape_1|isOn|Table_1", 7, 8))); - timeline->events.add(new mementar::ContextualizedEvent("e3", mementar::Event("tape_2|isIn|storage_area", 7.8))); - timeline->events.add(new mementar::ContextualizedEvent("e4", mementar::Event("hum_green|isInRoom|expe_room", 6,7))); - timeline->events.add(new mementar::ContextualizedEvent("e5", mementar::Event(mementar::Fact("hum_green|isInRoom|expe_room", false), mementar::SoftPoint(25,26)))); - - timeline->events.add(new mementar::ContextualizedEvent("e13", mementar::Event("hum_green|isInRoom|expe_room", 53))); - timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 54))); - timeline->events.add(new mementar::ContextualizedEvent("e14", mementar::Event("tape_2|isInGripper|pr2", 86))); - timeline->events.add(new mementar::ContextualizedEvent("e15", mementar::Event(mementar::Fact("tape_2|isIn|storage_area", false), 101))); - timeline->events.add(new mementar::ContextualizedEvent("e16", mementar::Event(mementar::Fact("tape_2|isInGripper|pr2", false), 107))); - timeline->events.add(new mementar::ContextualizedEvent("e17", mementar::Event("tape_2|isIn|pink_box", 107,110))); - - timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 117, 119))); - timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 117, 119))); - - timeline->events.add(new mementar::ContextualizedEvent("e18", mementar::Event("tape_1|isInHand|hum_green", 133, 134))); - timeline->events.add(new mementar::ContextualizedEvent("e19", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 134))); - timeline->events.add(new mementar::ContextualizedEvent("e20", mementar::Event(mementar::Fact("tape_1|isBehind|grey_box", false), 134))); - timeline->events.add(new mementar::ContextualizedEvent("e21", mementar::Event("tape_1|isIn|storage_area", 145))); - timeline->events.add(new mementar::ContextualizedEvent("e23", mementar::Event(mementar::Fact("tape_1|isInHand|hum_green", false), 145))); - timeline->events.add(new mementar::ContextualizedEvent("e24", mementar::Event("tape_1|isInGripper|pr2", 162))); - timeline->events.add(new mementar::ContextualizedEvent("e25", mementar::Event(mementar::Fact("tape_1|isIn|storage_area", false), 170))); - timeline->events.add(new mementar::ContextualizedEvent("e26", mementar::Event(mementar::Fact("tape_1|isInGripper|pr2", false), 173))); - timeline->events.add(new mementar::ContextualizedEvent("e27", mementar::Event("tape_1|isIn|pink_box", 173,175))); + timeline->facts.add(new mementar::ContextualizedFact("e0", mementar::Fact("pr2|isInRoom|expe_room", 6,7))); + timeline->facts.add(new mementar::ContextualizedFact("e1", mementar::Fact("grey_box|isOn|Table_1", 7, 8))); + timeline->facts.add(new mementar::ContextualizedFact("e2", mementar::Fact("tape_1|isOn|Table_1", 7, 8))); + timeline->facts.add(new mementar::ContextualizedFact("e3", mementar::Fact("tape_2|isIn|storage_area", 7.8))); + timeline->facts.add(new mementar::ContextualizedFact("e4", mementar::Fact("hum_green|isInRoom|expe_room", 6,7))); + timeline->facts.add(new mementar::ContextualizedFact("e5", mementar::Fact(mementar::Triplet("hum_green|isInRoom|expe_room", false), mementar::SoftPoint(25,26)))); + + timeline->facts.add(new mementar::ContextualizedFact("e13", mementar::Fact("hum_green|isInRoom|expe_room", 53))); + timeline->facts.add(new mementar::ContextualizedFact("e8", mementar::Fact(mementar::Triplet("tape_1|isOn|Table_1", false), 54))); + timeline->facts.add(new mementar::ContextualizedFact("e14", mementar::Fact("tape_2|isInGripper|pr2", 86))); + timeline->facts.add(new mementar::ContextualizedFact("e15", mementar::Fact(mementar::Triplet("tape_2|isIn|storage_area", false), 101))); + timeline->facts.add(new mementar::ContextualizedFact("e16", mementar::Fact(mementar::Triplet("tape_2|isInGripper|pr2", false), 107))); + timeline->facts.add(new mementar::ContextualizedFact("e17", mementar::Fact("tape_2|isIn|pink_box", 107,110))); + + timeline->facts.add(new mementar::ContextualizedFact("e9", mementar::Fact("tape_1|isOn|Table_1", 117, 119))); + timeline->facts.add(new mementar::ContextualizedFact("e10", mementar::Fact("tape_1|isBehind|grey_box", 117, 119))); + + timeline->facts.add(new mementar::ContextualizedFact("e18", mementar::Fact("tape_1|isInHand|hum_green", 133, 134))); + timeline->facts.add(new mementar::ContextualizedFact("e19", mementar::Fact(mementar::Triplet("tape_1|isOn|Table_1", false), 134))); + timeline->facts.add(new mementar::ContextualizedFact("e20", mementar::Fact(mementar::Triplet("tape_1|isBehind|grey_box", false), 134))); + timeline->facts.add(new mementar::ContextualizedFact("e21", mementar::Fact("tape_1|isIn|storage_area", 145))); + timeline->facts.add(new mementar::ContextualizedFact("e23", mementar::Fact(mementar::Triplet("tape_1|isInHand|hum_green", false), 145))); + timeline->facts.add(new mementar::ContextualizedFact("e24", mementar::Fact("tape_1|isInGripper|pr2", 162))); + timeline->facts.add(new mementar::ContextualizedFact("e25", mementar::Fact(mementar::Triplet("tape_1|isIn|storage_area", false), 170))); + timeline->facts.add(new mementar::ContextualizedFact("e26", mementar::Fact(mementar::Triplet("tape_1|isInGripper|pr2", false), 173))); + timeline->facts.add(new mementar::ContextualizedFact("e27", mementar::Fact("tape_1|isIn|pink_box", 173,175))); return timeline; }*/ @@ -128,17 +128,17 @@ mementar::Timeline* getTimeline() timeline->actions.add(new mementar::Action("blue_place_1", 37, mementar::SoftPoint(41, 42))); timeline->actions.add(new mementar::Action("monitor_1", 43, 51)); - timeline->events.add(new mementar::ContextualizedEvent("e0", mementar::Event("pr2|isInRoom|expe_room", 30, 31))); - timeline->events.add(new mementar::ContextualizedEvent("e1", mementar::Event("grey_box|isOn|Table_1", 32,34))); - timeline->events.add(new mementar::ContextualizedEvent("e2", mementar::Event("tape_1|isOn|Table_1", 32,34))); - timeline->events.add(new mementar::ContextualizedEvent("e3", mementar::Event("tape_2|isIn|storage_area", 32,34))); - timeline->events.add(new mementar::ContextualizedEvent("e6", mementar::Event("hum_blue|isInRoom|expe_room", 30,31))); - timeline->events.add(new mementar::ContextualizedEvent("e7", mementar::Event("tape_1|isInHand|hum_blue", 37))); - timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); - timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); - timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); - timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); - timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); + timeline->facts.add(new mementar::ContextualizedFact("e0", mementar::Fact("pr2|isInRoom|expe_room", 30, 31))); + timeline->facts.add(new mementar::ContextualizedFact("e1", mementar::Fact("grey_box|isOn|Table_1", 32,34))); + timeline->facts.add(new mementar::ContextualizedFact("e2", mementar::Fact("tape_1|isOn|Table_1", 32,34))); + timeline->facts.add(new mementar::ContextualizedFact("e3", mementar::Fact("tape_2|isIn|storage_area", 32,34))); + timeline->facts.add(new mementar::ContextualizedFact("e6", mementar::Fact("hum_blue|isInRoom|expe_room", 30,31))); + timeline->facts.add(new mementar::ContextualizedFact("e7", mementar::Fact("tape_1|isInHand|hum_blue", 37))); + timeline->facts.add(new mementar::ContextualizedFact("e8", mementar::Fact(mementar::Triplet("tape_1|isOn|Table_1", false), 37))); + timeline->facts.add(new mementar::ContextualizedFact("e9", mementar::Fact("tape_1|isOn|Table_1", 38, 42))); + timeline->facts.add(new mementar::ContextualizedFact("e10", mementar::Fact("tape_1|isBehind|grey_box", 38))); + timeline->facts.add(new mementar::ContextualizedFact("e11", mementar::Fact(mementar::Triplet("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); + timeline->facts.add(new mementar::ContextualizedFact("e12", mementar::Fact(mementar::Triplet("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); return timeline; }*/ @@ -152,14 +152,14 @@ int main(int argc, char** argv) std::cout << "-------- READ ACTIONS---------" << std::endl; mementar::ActionReader actions; - actions.read(&timeline->events, &font); + actions.read(&timeline->facts, &font); std::cout << "-------- READ EVENTS---------" << std::endl; - mementar::EventReader events; - events.read(&timeline->events, &font); + mementar::EventReader facts; + facts.read(&timeline->facts, &font); std::cout << "-------- DRAW---------" << std::endl; mementar::TimelineDrawer drawer; - drawer.draw("out.png", timeline, &actions, &events); + drawer.draw("out.png", timeline, &actions, &facts); /*std::cout << "width = " << ontologenius::commit_t::global_width << std::endl; std::cout << "height = " << ontologenius::commit_t::global_height << std::endl; diff --git a/src/test/graphs.cpp b/src/test/graphs.cpp index bf3fd4e..8eca4ab 100644 --- a/src/test/graphs.cpp +++ b/src/test/graphs.cpp @@ -1,16 +1,16 @@ #include "mementar/core/memGraphs/Branchs/types/Action.h" -#include "mementar/core/memGraphs/Branchs/types/Event.h" +#include "mementar/core/memGraphs/Branchs/types/Fact.h" -#include "mementar/core/memGraphs/Branchs/ContextualizedEvent.h" +#include "mementar/core/memGraphs/Branchs/ContextualizedFact.h" -#include "mementar/core/memGraphs/Graphs/EventGraph.h" +#include "mementar/core/memGraphs/Graphs/FactGraph.h" #include "mementar/core/memGraphs/Graphs/ActionGraph.h" #include -void printNext(mementar::ContextualizedEvent* evt) +void printNext(mementar::ContextualizedFact* fact) { - auto nexts = evt->getNextData(); + auto nexts = fact->getNextData(); for(auto n : nexts) std::cout << n->toString() << std::endl; @@ -18,11 +18,11 @@ void printNext(mementar::ContextualizedEvent* evt) printNext(nexts[0]); } -void print(mementar::ContextualizedEvent* evt) +void print(mementar::ContextualizedFact* fact) { - std::cout << evt->toString() << std::endl; + std::cout << fact->toString() << std::endl; - auto nexts = evt->getNextData(); + auto nexts = fact->getNextData(); for(auto n : nexts) std::cout << n->toString() << std::endl; @@ -30,22 +30,22 @@ void print(mementar::ContextualizedEvent* evt) printNext(nexts[0]); } -void printEventList(mementar::ContextualizedEvent* evt) +void printEventList(mementar::ContextualizedFact* fact) { - if(evt) + if(fact) { - std::cout << evt->toString() << std::endl; - printEventList(evt->getNextEvent()); + std::cout << fact->toString() << std::endl; + printEventList(fact->getNext()); } } int main() { - mementar::EventGraph event_graph; - mementar::ActionGraph action_graph(&event_graph); + mementar::FactGraph fact_graph; + mementar::ActionGraph action_graph(&fact_graph); - mementar::Event e1("cube12|isOn|Table_1", 2,4); - mementar::Event e2("cube12|isOn|Table_2", 8); + mementar::Fact e1("cube12|isOn|Table_1", 2,4); + mementar::Fact e2("cube12|isOn|Table_2", 8); action_graph.add(new mementar::Action("pick_1", mementar::SoftPoint(1, 3), 7)); action_graph.add(new mementar::Action("place_1", 7, mementar::SoftPoint(9, 10))); @@ -58,29 +58,29 @@ int main() action_graph.setEnd("pick_2", 15); action_graph.setEnd("pick_1", 17); - event_graph.add(new mementar::ContextualizedEvent("ce3", e1)); - event_graph.add(new mementar::ContextualizedEvent("ce4", e2)); + fact_graph.add(new mementar::ContextualizedFact("ce3", e1)); + fact_graph.add(new mementar::ContextualizedFact("ce4", e2)); for(size_t i = 10; i < 20; i++) - event_graph.add(new mementar::ContextualizedEvent("ce" + std::to_string(i), mementar::Event("cube" + std::to_string(i) + "|isOn|Table_3", i))); + fact_graph.add(new mementar::ContextualizedFact("ce" + std::to_string(i), mementar::Fact("cube" + std::to_string(i) + "|isOn|Table_3", i))); auto actions = action_graph.getSafe(); for(auto action : actions) std::cout << action->getName() << " D=" << action->getDuration() << " Dmin=" << action->getMinDuration() << " Dmax=" << action->getMaxDuration() << std::endl; - auto events = event_graph.getSafe(); + auto events = fact_graph.getSafe(); for(auto event : events) std::cout << event->toString() << std::endl; - auto timeline = event_graph.getTimeline(); + auto timeline = fact_graph.getTimeline(); timeline->displayTree(); std::cout << "********" << std::endl; - auto first_evt = event_graph.findBranch("pick_1_start"); + auto first_evt = fact_graph.findBranch("pick_1_start"); print(first_evt); std::cout << "********" << std::endl; - auto cube12_ison_evt = event_graph.findBranch("ce3"); + auto cube12_ison_evt = fact_graph.findBranch("ce3"); printEventList(cube12_ison_evt); return 0; From d2a6c6d0c2d9cd5ba30fc6c31f875232d34672ec Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 25 Aug 2020 08:33:02 +0200 Subject: [PATCH 49/95] [REFACT] events to facts in timeline drawer --- CMakeLists.txt | 2 +- .../graphical/timeline/{EventReader.h => FactReader.h} | 8 ++++---- include/mementar/graphical/timeline/TimelineDrawer.h | 6 +++--- .../timeline/{EventReader.cpp => FactReader.cpp} | 10 +++++----- src/graphical/timeline/TimelineDrawer.cpp | 10 +++++----- src/graphical/timeline/main.cpp | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) rename include/mementar/graphical/timeline/{EventReader.h => FactReader.h} (80%) rename src/graphical/timeline/{EventReader.cpp => FactReader.cpp} (76%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbf6afb..6ad3db8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ add_dependencies(mementar_events_lib ${catkin_EXPORTED_TARGETS} mementar_gencpp) add_library(mementar_drawer_lib src/graphical/timeline/ActionReader.cpp - src/graphical/timeline/EventReader.cpp + src/graphical/timeline/FactReader.cpp src/graphical/timeline/TimelineDrawer.cpp ) target_include_directories(mementar_drawer_lib diff --git a/include/mementar/graphical/timeline/EventReader.h b/include/mementar/graphical/timeline/FactReader.h similarity index 80% rename from include/mementar/graphical/timeline/EventReader.h rename to include/mementar/graphical/timeline/FactReader.h index 2758883..5e36f88 100644 --- a/include/mementar/graphical/timeline/EventReader.h +++ b/include/mementar/graphical/timeline/FactReader.h @@ -10,21 +10,21 @@ namespace mementar { -struct event_t +struct fact_t { - event_t(SoftPoint::Ttime time) : time_point(time) {} + fact_t(SoftPoint::Ttime time) : time_point(time) {} std::string data; SoftPoint time_point; }; -class EventReader +class FactReader { public: void read(FactGraph* graph, CvFont* font); - std::vector events; + std::vector facts; size_t max_text_size_; private: diff --git a/include/mementar/graphical/timeline/TimelineDrawer.h b/include/mementar/graphical/timeline/TimelineDrawer.h index f8df8ff..3a9ea2b 100644 --- a/include/mementar/graphical/timeline/TimelineDrawer.h +++ b/include/mementar/graphical/timeline/TimelineDrawer.h @@ -8,7 +8,7 @@ #include "mementar/core/memGraphs/Timeline.h" #include "mementar/graphical/timeline/ActionReader.h" -#include "mementar/graphical/timeline/EventReader.h" +#include "mementar/graphical/timeline/FactReader.h" namespace mementar { @@ -16,13 +16,13 @@ class TimelineDrawer { public: - void draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, EventReader* events); + void draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, FactReader* facts); private: IplImage* image_; void drawVector(size_t start, size_t end, size_t pose); void drawAction(const action_t& action, size_t line_pose, size_t max_level, size_t start_time); - void drawEvent(const event_t& event, size_t line_pose, size_t start_time); + void drawEvent(const fact_t& event, size_t line_pose, size_t start_time); size_t getTextSize(const std::string& txt, CvFont* font); void drawElipseStart(size_t x, size_t y); diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/FactReader.cpp similarity index 76% rename from src/graphical/timeline/EventReader.cpp rename to src/graphical/timeline/FactReader.cpp index 1d02e9f..813549c 100644 --- a/src/graphical/timeline/EventReader.cpp +++ b/src/graphical/timeline/FactReader.cpp @@ -1,8 +1,8 @@ -#include "mementar/graphical/timeline/EventReader.h" +#include "mementar/graphical/timeline/FactReader.h" namespace mementar { -void EventReader::read(FactGraph* graph, CvFont* font) +void FactReader::read(FactGraph* graph, CvFont* font) { max_text_size_ = 0; @@ -11,7 +11,7 @@ void EventReader::read(FactGraph* graph, CvFont* font) while(node != nullptr) { - event_t group_fact(node->getData()[0]->getTime()); + fact_t group_fact(node->getData()[0]->getTime()); for(auto fact : node->getData()) { if(fact->isPartOfAction() == false) @@ -24,7 +24,7 @@ void EventReader::read(FactGraph* graph, CvFont* font) if(group_fact.data != "") { - events.push_back(group_fact); + facts.push_back(group_fact); getTextSize(group_fact.data, font); } @@ -32,7 +32,7 @@ void EventReader::read(FactGraph* graph, CvFont* font) } } -void EventReader::getTextSize(const std::string& txt, CvFont* font) +void FactReader::getTextSize(const std::string& txt, CvFont* font) { CvSize size; int baseline; diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index 5db81d1..c3f424b 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -9,11 +9,11 @@ namespace mementar { -void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, EventReader* events) +void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline, ActionReader* actions, FactReader* facts) { size_t start = timeline->facts.getTimeline()->getFirst()->getKey(); size_t end = timeline->facts.getTimeline()->getLast()->getKey(); - size_t width = (actions->max_level_ + 1) * SIDE_SPACE + actions->max_text_size_ + MARGIN * 3 + SIDE_SPACE + events->max_text_size_; + size_t width = (actions->max_level_ + 1) * SIDE_SPACE + actions->max_text_size_ + MARGIN * 3 + SIDE_SPACE + facts->max_text_size_; size_t height = (end - start) * UNIT_SPACE + MARGIN * 2; std::cout << "image size = " << width << " : " << height << std::endl; @@ -28,8 +28,8 @@ void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline, Acti for(auto act : actions->actions_) drawAction(act.second, line_pose, actions->max_level_, start); - std::cout << "---EVENTS----" << std::endl; - for(auto evt : events->events) + std::cout << "---FACTS----" << std::endl; + for(auto evt : facts->facts) drawEvent(evt, line_pose, start); if(file_name != "") @@ -135,7 +135,7 @@ void TimelineDrawer::drawAction(const action_t& action, size_t line_pose, size_t cvScalar(32, 20, 122)); } -void TimelineDrawer::drawEvent(const event_t& event, size_t line_pose, size_t start_time) +void TimelineDrawer::drawEvent(const fact_t& event, size_t line_pose, size_t start_time) { size_t x_start_pose = line_pose; size_t x_end_pose = x_start_pose + SIDE_SPACE; diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index 474ebc3..dde4aa0 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -1,7 +1,7 @@ #include "mementar/core/memGraphs/Timeline.h" #include "mementar/graphical/timeline/ActionReader.h" -#include "mementar/graphical/timeline/EventReader.h" +#include "mementar/graphical/timeline/FactReader.h" #include "mementar/graphical/timeline/TimelineDrawer.h" mementar::Timeline* getTimeline() @@ -154,7 +154,7 @@ int main(int argc, char** argv) mementar::ActionReader actions; actions.read(&timeline->facts, &font); std::cout << "-------- READ EVENTS---------" << std::endl; - mementar::EventReader facts; + mementar::FactReader facts; facts.read(&timeline->facts, &font); std::cout << "-------- DRAW---------" << std::endl; From b07da4aefdd895680547fcb2acd13c0efc442532 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 30 Oct 2020 15:37:37 +0100 Subject: [PATCH 50/95] [ADD] Feeder with stamped facts and explanations --- CMakeLists.txt | 4 + include/mementar/RosInterface.h | 28 +++- include/mementar/core/feeder/FeedStorage.h | 56 ++++++++ include/mementar/core/feeder/Feeder.h | 44 ++++++ .../core/memGraphs/Branchs/types/SoftPoint.h | 1 + launch/mementar_ontologenius.launch | 9 ++ msg/MementarExplanation.msg | 2 + src/RosInterface.cpp | 129 ++++++++++++------ src/core/feeder/FeedStorage.cpp | 112 +++++++++++++++ src/core/feeder/Feeder.cpp | 67 +++++++++ .../memGraphs/Branchs/types/SoftPoint.cpp | 7 + 11 files changed, 414 insertions(+), 45 deletions(-) create mode 100644 include/mementar/core/feeder/FeedStorage.h create mode 100644 include/mementar/core/feeder/Feeder.h create mode 100644 launch/mementar_ontologenius.launch create mode 100644 msg/MementarExplanation.msg create mode 100644 src/core/feeder/FeedStorage.cpp create mode 100644 src/core/feeder/Feeder.cpp create mode 100644 src/core/memGraphs/Branchs/types/SoftPoint.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ad3db8..44d0e2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ find_package(OpenCV REQUIRED) ## Generate messages in the 'msg' folder add_message_files( FILES + MementarExplanation.msg MementarOccasion.msg StampedString.msg ) @@ -100,6 +101,7 @@ add_library(mementar_memGraphs_lib src/core/memGraphs/Branchs/ValuedNode.cpp src/core/memGraphs/Branchs/types/Action.cpp src/core/memGraphs/Branchs/types/Fact.cpp + src/core/memGraphs/Branchs/types/SoftPoint.cpp src/core/memGraphs/Branchs/types/Triplet.cpp src/core/memGraphs/Graphs/ActionGraph.cpp src/core/memGraphs/Graphs/FactGraph.cpp @@ -169,6 +171,8 @@ add_dependencies(mementar_lib ${catkin_EXPORTED_TARGETS} mementar_gencpp) ############################## add_library(mementar_interface + src/core/feeder/FeedStorage.cpp + src/core/feeder/Feeder.cpp src/RosInterface.cpp ) target_link_libraries(mementar_interface mementar_core_lib mementar_events_lib) diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index 70f6f56..7d93751 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -8,10 +8,13 @@ #include "std_msgs/String.h" #include "mementar/MementarService.h" +#include "mementar/MementarExplanation.h" #include "mementar/StampedString.h" -#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h" +//#include "mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h" +#include "mementar/core/memGraphs/Timeline.h" #include "mementar/core/Occasions/OccasionsManager.h" +#include "mementar/core/feeder/Feeder.h" namespace mementar { @@ -24,29 +27,46 @@ class RosInterface void run(); void stop() {run_ = false; } - inline bool isRunning() {return run_; } - ArchivedLeafNode* getTree() {return tree_; } + inline bool isRunning() { return run_; } + + void lock(); + void release(); private: ros::NodeHandle* n_; std::string directory_; size_t order_; - ArchivedLeafNode* tree_; + Timeline* timeline_; + Feeder feeder_; OccasionsManager occasions_; std::string name_; std::atomic run_; std::shared_timed_mutex mut_; + std::mutex feeder_mutex_; void reset(); void knowledgeCallback(const std_msgs::String::ConstPtr& msg); void stampedKnowledgeCallback(const StampedString::ConstPtr& msg); + void explanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg); bool actionsHandle(mementar::MementarService::Request &req, mementar::MementarService::Response &res); + void feedThread(); + void removeUselessSpace(std::string& text); + + std::string getTopicName(const std::string& topic_name) + { + return getTopicName(topic_name, name_); + } + + std::string getTopicName(const std::string& topic_name, const std::string& onto_name) + { + return (onto_name == "") ? "/mementar/" + topic_name : "/mementar/" + topic_name + "/" + onto_name; + } }; } // namespace mementar diff --git a/include/mementar/core/feeder/FeedStorage.h b/include/mementar/core/feeder/FeedStorage.h new file mode 100644 index 0000000..a72199a --- /dev/null +++ b/include/mementar/core/feeder/FeedStorage.h @@ -0,0 +1,56 @@ +#ifndef MEMENTER_FEEDSTORAGE_H +#define MEMENTER_FEEDSTORAGE_H + +#include +#include +#include +#include + +#include "mementar/core/memGraphs/Branchs/types/Fact.h" + +namespace mementar { + +enum action_t +{ + action_add, + action_del, + action_commit, + action_checkout, + action_nop +}; + +struct feed_t +{ + action_t action_; + std::experimental::optional fact_; + std::experimental::optional expl_; + bool checkout_; + + feed_t() { checkout_ = false; } +}; + +class FeedStorage +{ +public: + FeedStorage(); + + void insert(const std::string& regex, const SoftPoint::Ttime& stamp); + void insert(const std::string& regex, const std::string& expl_regex); + void insert(std::vector& datas); + std::queue get(); + size_t size() { return fifo_1.size() + fifo_2.size(); } + +private: + std::regex base_regex; + std::mutex mutex_; + + bool queue_choice_; + std::queue fifo_1; + std::queue fifo_2; + + feed_t getFeed(const std::string& regex, const SoftPoint::Ttime& stamp = SoftPoint::default_time); +}; + +} // namespace mementar + +#endif // MEMENTER_FEEDSTORAGE_H diff --git a/include/mementar/core/feeder/Feeder.h b/include/mementar/core/feeder/Feeder.h new file mode 100644 index 0000000..5b1af41 --- /dev/null +++ b/include/mementar/core/feeder/Feeder.h @@ -0,0 +1,44 @@ +#ifndef MEMENTAR_FEEDER_H +#define MEMENTAR_FEEDER_H + +#include "mementar/core/feeder/FeedStorage.h" +//#include "ontologenius/core/feeder/Versionor.h" + +namespace mementar { + +class Timeline; + +class Feeder +{ +public: + Feeder(Timeline* timeline = nullptr); + + void store(const std::string& feed, const SoftPoint::Ttime& stamp) { feed_storage_.insert(feed, stamp); } + void store(const std::string& feed, const std::string& expl) { feed_storage_.insert(feed, expl); } + bool run(); + void link(Timeline* timeline) {timeline_ = timeline; } + + std::vector getNotifications() + { + auto tmp = std::move(notifications_); + notifications_.clear(); + return tmp; + } + + //void activateVersionning(bool activated) { versionor_.activate(activated); } + //void exportToXml(const std::string& path) { versionor_.exportToXml(path); } + + size_t size() { return feed_storage_.size(); } + +private: + FeedStorage feed_storage_; + //Versionor versionor_; + Timeline* timeline_; + + // Here the notifications are about miss formed queries + std::vector notifications_; +}; + +} // namespace mementar + +#endif // MEMENTAR_FEEDER_H diff --git a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h index 82fe4a8..206c57c 100644 --- a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h +++ b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h @@ -10,6 +10,7 @@ class SoftPoint { public: typedef size_t Ttime; + static Ttime default_time; //typedef float Ttime; SoftPoint(Ttime t_start, std::experimental::optional t_end = std::experimental::nullopt) diff --git a/launch/mementar_ontologenius.launch b/launch/mementar_ontologenius.launch new file mode 100644 index 0000000..580ae9f --- /dev/null +++ b/launch/mementar_ontologenius.launch @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/msg/MementarExplanation.msg b/msg/MementarExplanation.msg new file mode 100644 index 0000000..43d7255 --- /dev/null +++ b/msg/MementarExplanation.msg @@ -0,0 +1,2 @@ +string fact +string cause diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 6065704..d4d53d4 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -21,32 +21,32 @@ RosInterface::RosInterface(ros::NodeHandle* n, const std::string& directory, siz else directory_ += "/" + name; - std::experimental::filesystem::create_directories(directory_); - tree_ = new ArchivedLeafNode(directory_, order_); + //std::experimental::filesystem::create_directories(directory_); + timeline_ = new Timeline(); + feeder_.link(timeline_); name_ = name; } RosInterface::~RosInterface() { - delete tree_; + delete timeline_; } void RosInterface::run() { std::string service_name; - service_name = (name_ == "") ? "insert" : "insert/" + name_; - ros::Subscriber knowledge_subscriber = n_->subscribe(service_name, 1000, &RosInterface::knowledgeCallback, this); - - service_name = (name_ == "") ? "insert_stamped" : "insert_stamped/" + name_; - ros::Subscriber stamped_knowledge_subscriber = n_->subscribe(service_name, 1000, &RosInterface::stampedKnowledgeCallback, this); + ros::Subscriber knowledge_subscriber = n_->subscribe(getTopicName("insert"), 1000, &RosInterface::knowledgeCallback, this); + ros::Subscriber stamped_knowledge_subscriber = n_->subscribe(getTopicName("insert_stamped"), 1000, &RosInterface::stampedKnowledgeCallback, this); + ros::Subscriber explanation_knowledge_subscriber = n_->subscribe(getTopicName("insert_explanations"), 1000, &RosInterface::explanationKnowledgeCallback, this); // Start up ROS service with callbacks service_name = (name_ == "") ? "actions" : "actions/" + name_; ros::ServiceServer service = n_->advertiseService(service_name, &RosInterface::actionsHandle, this); std::thread occasions_thread(&OccasionsManager::run, &occasions_); + std::thread feed_thread(&RosInterface::feedThread, this); ROS_DEBUG("%s mementar ready", name_.c_str()); @@ -62,13 +62,25 @@ void RosInterface::run() void RosInterface::reset() { mut_.lock(); - delete tree_; + delete timeline_; std::experimental::filesystem::remove_all(directory_); std::experimental::filesystem::create_directories(directory_); - tree_ = new ArchivedLeafNode(directory_, order_); + timeline_ = new Timeline(); + feeder_.link(timeline_); mut_.unlock(); } +void RosInterface::lock() +{ + feeder_mutex_.lock(); +} + +void RosInterface::release() +{ + feeder_mutex_.unlock(); +} + + /*************** * * Callbacks @@ -77,26 +89,33 @@ void RosInterface::reset() void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { - Fact* fact = new Fact(msg->data, time(0)); - if(fact->valid()) - { - mut_.lock_shared(); - tree_->insert(fact); - mut_.unlock_shared(); - occasions_.add(fact); - } + feeder_.store(msg->data, time(0)); } - +/* +data: "[ADD]blop|isOnTopOf|table_l_0" +stamp: + secs: 1603977394 + nsecs: 892413051 +--- +data: "[DEL]blop|isOnTopOf|table_l_0" +stamp: + secs: 1603977408 + nsecs: 428956909 +*/ void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { - Fact* fact = new Fact(msg->data, msg->stamp.sec); - if(fact->valid()) - { - mut_.lock_shared(); - tree_->insert(fact); - mut_.unlock_shared(); - occasions_.add(fact); - } + feeder_.store(msg->data, msg->stamp.sec); +} +/* +fact: "[ADD]table_l_0|isUnder|blop" +cause: "[ADD]blop|isOnTopOf|table_l_0" +--- +fact: "[DEL]table_l_0|isUnder|blop" +cause: "[DEL]blop|isOnTopOf|table_l_0" +*/ +void RosInterface::explanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg) +{ + feeder_.store(msg->fact, msg->cause); } bool RosInterface::actionsHandle(mementar::MementarService::Request &req, @@ -107,25 +126,13 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, removeUselessSpace(req.action); removeUselessSpace(req.param); - if(req.action == "remove") - { - Fact fact(req.param, req.stamp.sec); - if(fact.valid()) - { - mut_.lock_shared(); - tree_->remove(&fact); - mut_.unlock_shared(); - } - else - res.code = REQUEST_ERROR; - } - else if(req.action == "newSession") + /*if(req.action == "newSession") { mut_.lock_shared(); tree_->newSession(); mut_.unlock_shared(); } - else if(req.action == "reset") + else */if(req.action == "reset") reset(); else res.code = UNKNOW_ACTION; @@ -133,6 +140,46 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, return true; } +/*************** +* +* Threads +* +***************/ + +void RosInterface::feedThread() +{ + ros::Publisher feeder_publisher = n_->advertise(getTopicName("feeder_notifications"), 1000); + + ros::Rate wait(100); + /*while((ros::ok()) && (onto_->isInit(false) == false) && (run_ == true)) + { + wait.sleep(); + }*/ + + std_msgs::String msg; + while(ros::ok() && (run_ == true)) + { + feeder_mutex_.lock(); + bool run = feeder_.run(); + if(run == true) + { + std::vector notifications = feeder_.getNotifications(); + for(auto notif : notifications) + { + //Display::error(notif); + if(name_ != "") + notif = "[" + name_ + "]" + notif; + msg.data = notif; + feeder_publisher.publish(msg); + } + } + feeder_mutex_.unlock(); + + if(ros::ok() && (run_ == true)) + wait.sleep(); + } +} + /*************** * * Utility diff --git a/src/core/feeder/FeedStorage.cpp b/src/core/feeder/FeedStorage.cpp new file mode 100644 index 0000000..00c75a4 --- /dev/null +++ b/src/core/feeder/FeedStorage.cpp @@ -0,0 +1,112 @@ +#include "mementar/core/feeder/FeedStorage.h" + +#include + +namespace mementar { + +FeedStorage::FeedStorage() : base_regex(R"(^\[(\w+)\](.*)$)") +{ + queue_choice_ = true; +} + +void FeedStorage::insert(const std::string& regex, const SoftPoint::Ttime& stamp) +{ + feed_t feed = getFeed(regex, stamp); + + mutex_.lock(); + if(queue_choice_ == true) + fifo_1.push(feed); + else + fifo_2.push(feed); + mutex_.unlock(); +} + +void FeedStorage::insert(const std::string& regex, const std::string& expl_regex) +{ + feed_t feed = getFeed(regex); + feed.expl_ = getFeed(expl_regex).fact_; + + mutex_.lock(); + if(queue_choice_ == true) + fifo_1.push(feed); + else + fifo_2.push(feed); + mutex_.unlock(); +} + +void FeedStorage::insert(std::vector& datas) +{ + mutex_.lock(); + if(queue_choice_ == true) + { + for(auto& data : datas) + fifo_1.push(data); + } + else + { + for(auto& data : datas) + fifo_2.push(data); + } + mutex_.unlock(); +} + +std::queue FeedStorage::get() +{ + std::queue tmp; + mutex_.lock(); + if(queue_choice_ == true) + { + while(!fifo_2.empty()) + fifo_2.pop(); + queue_choice_ = false; + tmp = fifo_1; + } + else + { + while(!fifo_1.empty()) + fifo_1.pop(); + queue_choice_ = true; + tmp = fifo_2; + } + mutex_.unlock(); + return tmp; +} + +feed_t FeedStorage::getFeed(const std::string& regex, const SoftPoint::Ttime& stamp) +{ + std::smatch base_match; + feed_t feed; + feed.action_ = action_nop; + + if (std::regex_match(regex, base_match, base_regex)) + { + if (base_match.size() == 3) + { + std::string action = base_match[1].str(); + std::transform(action.begin(), action.end(), action.begin(), ::tolower); + if(action == "add") + feed.action_ = action_add; + else if(action == "del") + feed.action_ = action_del; + else if(action == "nop") + return feed; + else + { + std::cout << "data do not match" << std::endl; + return feed; + } + } + } + else if(regex == "[nop]") + return feed; + else + { + std::cout << "data do not match" << std::endl; + return feed; + } + + feed.fact_ = Fact(Triplet(base_match[2].str(), feed.action_ == action_add), stamp); + return feed; +} + +} // namespace mementar diff --git a/src/core/feeder/Feeder.cpp b/src/core/feeder/Feeder.cpp new file mode 100644 index 0000000..b2b8e70 --- /dev/null +++ b/src/core/feeder/Feeder.cpp @@ -0,0 +1,67 @@ +#include "mementar/core/feeder/Feeder.h" + +#include + +#include "mementar/core/memGraphs/Timeline.h" + +namespace mementar { + +Feeder::Feeder(Timeline* timeline)// : versionor_(&feed_storage_) +{ + timeline_ = timeline; +} + +bool Feeder::run() +{ + if(timeline_ == nullptr) + return false; + + bool has_run = false; + std::queue feeds = feed_storage_.get(); + + while(feeds.empty() == false) + { + has_run = true; + feed_t feed = feeds.front(); + feeds.pop(); + + if((feed.action_ != action_add) && (feed.action_ != action_del)) + { + /*if(feed.action_ == action_commit) + { + if(!versionor_.commit(feed.from_)) + notifications_.push_back("[FAIL][commit]" + feed.from_); + } + else if(feed.action_ == action_checkout) + { + if(!versionor_.checkout(feed.from_)) + notifications_.push_back("[FAIL][checkout]" + feed.from_); + }*/ + continue; + } + + /*if(!feed.checkout_) + versionor_.insert(feed);*/ + + if(feed.fact_.value().valid() == false) + { + notifications_.push_back("[FAIL][fact poorly formed]" + feed.fact_.value().Triplet::toString()); + } + else if(feed.expl_ && (feed.expl_.value().valid() == false)) + { + notifications_.push_back("[FAIL][explanation poorly formed]" + feed.expl_.value().Triplet::toString()); + } + else + { + if(feed.expl_) + std::cout << "got explanation : " << feed.fact_.value().Triplet::toString() << " <= " << feed.expl_.value().Triplet::toString() << std::endl; + else + std::cout << "got fact : " << feed.fact_.value().Triplet::toString() << std::endl; + } + + } + + return has_run; +} + +} // namespace mementar diff --git a/src/core/memGraphs/Branchs/types/SoftPoint.cpp b/src/core/memGraphs/Branchs/types/SoftPoint.cpp new file mode 100644 index 0000000..366eb0e --- /dev/null +++ b/src/core/memGraphs/Branchs/types/SoftPoint.cpp @@ -0,0 +1,7 @@ +#include "mementar/core/memGraphs/Branchs/types/SoftPoint.h" + +namespace mementar { + +SoftPoint::Ttime SoftPoint::default_time = 0; + +} //namespace mementar From 8d798e01eab200b262c62eaa3aa62df5a3de05e1 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 30 Oct 2020 18:45:47 +0100 Subject: [PATCH 51/95] [UPDATE] insert facts in timeline --- include/mementar/core/feeder/Feeder.h | 2 + include/mementar/core/feeder/IdGenerator.h | 39 +++++++++++++++++++ .../core/memGraphs/Graphs/FactGraph.h | 6 ++- src/RosInterface.cpp | 20 +--------- src/core/feeder/Feeder.cpp | 10 ++++- src/core/memGraphs/Graphs/FactGraph.cpp | 20 +++++++++- 6 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 include/mementar/core/feeder/IdGenerator.h diff --git a/include/mementar/core/feeder/Feeder.h b/include/mementar/core/feeder/Feeder.h index 5b1af41..85b3376 100644 --- a/include/mementar/core/feeder/Feeder.h +++ b/include/mementar/core/feeder/Feeder.h @@ -2,6 +2,7 @@ #define MEMENTAR_FEEDER_H #include "mementar/core/feeder/FeedStorage.h" +#include "mementar/core/feeder/IdGenerator.h" //#include "ontologenius/core/feeder/Versionor.h" namespace mementar { @@ -32,6 +33,7 @@ class Feeder private: FeedStorage feed_storage_; + IdGenerator id_generator_; //Versionor versionor_; Timeline* timeline_; diff --git a/include/mementar/core/feeder/IdGenerator.h b/include/mementar/core/feeder/IdGenerator.h new file mode 100644 index 0000000..9e6a93c --- /dev/null +++ b/include/mementar/core/feeder/IdGenerator.h @@ -0,0 +1,39 @@ +#ifndef MEMENTAR_IDGENERATOR_H +#define MEMENTAR_IDGENERATOR_H + +#include +#include + +namespace mementar { + +class IdGenerator +{ +public: + IdGenerator() { id_ = 0; } + + void inspect(const std::string& str_id) + { + std::stringstream convertor; + size_t id; + convertor << str_id; + convertor >> id; + + if(convertor.fail() == false) + { + if(id >= id_) + id_ = id + 1; + } + } + + std::string get() + { + return std::to_string(id_++); + } + +private: + size_t id_; +}; + +} // namespace mementar + +#endif // MEMENTAR_IDGENERATOR_H diff --git a/include/mementar/core/memGraphs/Graphs/FactGraph.h b/include/mementar/core/memGraphs/Graphs/FactGraph.h index 9faec37..e5c1631 100644 --- a/include/mementar/core/memGraphs/Graphs/FactGraph.h +++ b/include/mementar/core/memGraphs/Graphs/FactGraph.h @@ -29,11 +29,13 @@ class FactGraph : public Graph return all_facts_; } - ElBTree* getTimeline() { return &timeline; } + ElBTree* getTimeline() { return &timeline_; } + + ContextualizedFact* findRecent(const Triplet& triplet, SoftPoint::Ttime until = SoftPoint::default_time); private: std::vector all_facts_; - ElBTree timeline; + ElBTree timeline_; }; } // namespace mementar diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index d4d53d4..91ea7a2 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -91,28 +91,12 @@ void RosInterface::knowledgeCallback(const std_msgs::String::ConstPtr& msg) { feeder_.store(msg->data, time(0)); } -/* -data: "[ADD]blop|isOnTopOf|table_l_0" -stamp: - secs: 1603977394 - nsecs: 892413051 ---- -data: "[DEL]blop|isOnTopOf|table_l_0" -stamp: - secs: 1603977408 - nsecs: 428956909 -*/ + void RosInterface::stampedKnowledgeCallback(const StampedString::ConstPtr& msg) { feeder_.store(msg->data, msg->stamp.sec); } -/* -fact: "[ADD]table_l_0|isUnder|blop" -cause: "[ADD]blop|isOnTopOf|table_l_0" ---- -fact: "[DEL]table_l_0|isUnder|blop" -cause: "[DEL]blop|isOnTopOf|table_l_0" -*/ + void RosInterface::explanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg) { feeder_.store(msg->fact, msg->cause); diff --git a/src/core/feeder/Feeder.cpp b/src/core/feeder/Feeder.cpp index b2b8e70..7e41dd6 100644 --- a/src/core/feeder/Feeder.cpp +++ b/src/core/feeder/Feeder.cpp @@ -54,9 +54,15 @@ bool Feeder::run() else { if(feed.expl_) - std::cout << "got explanation : " << feed.fact_.value().Triplet::toString() << " <= " << feed.expl_.value().Triplet::toString() << std::endl; + { + auto explanation = timeline_->facts.findRecent(feed.expl_.value()); + if(explanation == nullptr) + notifications_.push_back("[FAIL][explanation does not exist]" + feed.expl_.value().Triplet::toString()); + else + timeline_->facts.add(new mementar::ContextualizedFact(id_generator_.get(), {feed.fact_.value(), *explanation})); + } else - std::cout << "got fact : " << feed.fact_.value().Triplet::toString() << std::endl; + timeline_->facts.add(new mementar::ContextualizedFact(id_generator_.get(), feed.fact_.value())); } } diff --git a/src/core/memGraphs/Graphs/FactGraph.cpp b/src/core/memGraphs/Graphs/FactGraph.cpp index 760a063..8f63718 100644 --- a/src/core/memGraphs/Graphs/FactGraph.cpp +++ b/src/core/memGraphs/Graphs/FactGraph.cpp @@ -11,9 +11,27 @@ FactGraph::~FactGraph() void FactGraph::add(ContextualizedFact* fact) { + std::cout << "ADD fact " << fact->toString() << std::endl; all_facts_.push_back(fact); container_.insert(fact); - timeline.insert(fact->getTime(), fact); + timeline_.insert(fact->getTime(), fact); +} + +ContextualizedFact* FactGraph::findRecent(const Triplet& triplet, SoftPoint::Ttime until) +{ + for(BplusLeaf* leaf = timeline_.getLast(); leaf != nullptr; leaf = leaf->getPreviousLeaf()) + { + for(auto data : leaf->payload_) + { + if(data->getTime() < until) + return nullptr; + else if(data->fit(triplet)) + { + return data; + } + } + } + return nullptr; } } // namespace mementar From 3e235651f10c8a32ba0e1e28f5669119ee20e9c1 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 2 Nov 2020 14:28:49 +0100 Subject: [PATCH 52/95] [REFACT] display class functions format --- include/mementar/graphical/Display.h | 10 +++---- src/RosInterface.cpp | 3 +- .../EpisodicTree/ArchivedLeafNode.cpp | 24 +++++++-------- .../EpisodicTree/CompressedLeafNode.cpp | 24 +++++++-------- .../CompressedLeafNodeSession.cpp | 4 +-- .../LtManagement/EpisodicTree/Context.cpp | 30 +++++++++---------- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/include/mementar/graphical/Display.h b/include/mementar/graphical/Display.h index b2d2c45..2474b1d 100644 --- a/include/mementar/graphical/Display.h +++ b/include/mementar/graphical/Display.h @@ -26,27 +26,27 @@ namespace mementar class Display { public: - static void Error(const std::string& text) + static void error(const std::string& text) { std::cout << COLOR_RED << "[ERROR]" << text << COLOR_OFF << std::endl; } - static void Warning(const std::string& text) + static void warning(const std::string& text) { std::cout << COLOR_ORANGE << "[WARNING]" << text << COLOR_OFF << std::endl; } - static void Info(const std::string& text) + static void info(const std::string& text) { std::cout << COLOR_BLUE << text << COLOR_OFF << std::endl; } - static void Debug(const std::string& text) + static void debug(const std::string& text) { std::cout << text << std::endl; } - static void Percent(size_t percent) + static void percent(size_t percent) { std::cout << "=>" << std::setw(3) << percent << "%\r" << std::flush; } diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 91ea7a2..7c448fc 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -6,6 +6,7 @@ #include #include "mementar/core/utility/error_code.h" +#include "mementar/graphical/Display.h" namespace mementar { @@ -150,7 +151,7 @@ void RosInterface::feedThread() std::vector notifications = feeder_.getNotifications(); for(auto notif : notifications) { - //Display::error(notif); + Display::error(notif); if(name_ != "") notif = "[" + name_ + "]" + notif; msg.data = notif; diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp index 4a97482..b11d2bd 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp @@ -34,19 +34,19 @@ ArchivedLeafNode::~ArchivedLeafNode() delete tree; } - Display::Info("Archive trees:"); + Display::info("Archive trees:"); size_t nb_leafs = archived_sessions_tree_.size(); size_t leafs_cpt = 0; - Display::Percent(0); + Display::percent(0); for(auto tree : archived_sessions_tree_) { if(tree != nullptr) delete tree; - Display::Percent((++leafs_cpt)*100/nb_leafs); + Display::percent((++leafs_cpt)*100/nb_leafs); } - Display::Debug(""); + Display::debug(""); mut_.unlock(); } @@ -64,7 +64,7 @@ void ArchivedLeafNode::insert(Fact* data) { if((time_t)data->getTime() < keys_[0]) { - Display::Error("try to insert fact in past that do not exist"); + Display::error("try to insert fact in past that do not exist"); return; } @@ -276,10 +276,10 @@ int ArchivedLeafNode::getKeyIndex(const time_t& key) void ArchivedLeafNode::loadStoredData() { - Display::Info("Load archived files:"); + Display::info("Load archived files:"); size_t nb_file = std::distance(std::experimental::filesystem::directory_iterator(directory_), std::experimental::filesystem::directory_iterator{}); size_t cpt_file = 0; - Display::Percent(0); + Display::percent(0); for(const auto& entry : std::experimental::filesystem::directory_iterator(directory_)) { @@ -299,15 +299,15 @@ void ArchivedLeafNode::loadStoredData() iss >> key; insert(key, ArchivedLeaf(key, complete_dir)); - Display::Debug(complete_dir); + Display::debug(complete_dir); } } cpt_file++; - Display::Percent(cpt_file*100/nb_file); + Display::percent(cpt_file*100/nb_file); } - Display::Percent(100); - Display::Debug(""); + Display::percent(100); + Display::debug(""); CompressedLeafNode* comp = new CompressedLeafNode(directory_); if(comp->getKey() != time_t(-1)) @@ -319,7 +319,7 @@ void ArchivedLeafNode::loadStoredData() modified_.push_back(false); } else - Display::Warning("No compressed data loaded"); + Display::warning("No compressed data loaded"); if(archived_childs_.size()) { diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp index aee0245..bfd20da 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp @@ -30,16 +30,16 @@ CompressedLeafNode::~CompressedLeafNode() Context::storeContexts(contexts_, directory_); mut_.lock(); - Display::Info("Compress trees:"); + Display::info("Compress trees:"); size_t nb_leafs = keys_.size(); size_t leafs_cpt = 0; - Display::Percent(0); + Display::percent(0); for(auto tree : btree_childs_) { compressed_childs_.push_back(CompressedLeaf(tree, directory_)); delete tree; - Display::Percent((++leafs_cpt)*100/nb_leafs); + Display::percent((++leafs_cpt)*100/nb_leafs); } for(size_t i = 0; i < compressed_sessions_tree_.size(); i++) @@ -50,9 +50,9 @@ CompressedLeafNode::~CompressedLeafNode() compressed_childs_[i] = std::move(CompressedLeaf(compressed_sessions_tree_[i], directory_)); delete compressed_sessions_tree_[i]; } - Display::Percent((++leafs_cpt)*100/nb_leafs); + Display::percent((++leafs_cpt)*100/nb_leafs); } - Display::Debug(""); + Display::debug(""); mut_.unlock(); } @@ -101,7 +101,7 @@ void CompressedLeafNode::insert(Fact* data) { if((time_t)data->getTime() < keys_[0]) { - Display::Error("try to insert fact in past that do not exist"); + Display::error("try to insert fact in past that do not exist"); return; } @@ -330,12 +330,12 @@ bool CompressedLeafNode::loadStoredData() { size_t nb_file = std::distance(std::experimental::filesystem::directory_iterator(directory_), std::experimental::filesystem::directory_iterator{}); if(nb_file) - Display::Info("Load compressed files:"); + Display::info("Load compressed files:"); else return false; size_t cpt_file = 0; - Display::Percent(0); + Display::percent(0); for(const auto& entry : std::experimental::filesystem::directory_iterator(directory_)) { @@ -360,15 +360,15 @@ bool CompressedLeafNode::loadStoredData() iss >> key; insert(key, CompressedLeaf(key, complete_dir)); - Display::Debug(complete_dir); + Display::debug(complete_dir); } } cpt_file++; - Display::Percent(cpt_file*100/nb_file); + Display::percent(cpt_file*100/nb_file); } - Display::Percent(100); - Display::Debug(""); + Display::percent(100); + Display::debug(""); if(compressed_childs_.size()) { diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp index a980732..23b1256 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNodeSession.cpp @@ -71,13 +71,13 @@ void CompressedLeafNodeSession::insert(Fact* data) mut_.lock_shared(); if(contexts_.size() == 0) { - Display::Error("Can not insert in empty session"); + Display::error("Can not insert in empty session"); } else { if((time_t)data->getTime() < contexts_[0].getKey()) { - Display::Error("try to insert fact in past that do not exist"); + Display::error("try to insert fact in past that do not exist"); return; } diff --git a/src/core/LtManagement/EpisodicTree/Context.cpp b/src/core/LtManagement/EpisodicTree/Context.cpp index e355388..81a3588 100644 --- a/src/core/LtManagement/EpisodicTree/Context.cpp +++ b/src/core/LtManagement/EpisodicTree/Context.cpp @@ -147,9 +147,9 @@ void Context::fromString(const std::string& string) void Context::storeContexts(std::vector& contexts, const std::string& directory) { - Display::Info("Save contexts:"); + Display::info("Save contexts:"); - Display::Percent(0); + Display::percent(0); std::string res; res += "[" + std::to_string(contexts.size()) + "]\n"; for(size_t i = 0; i < contexts.size(); i++) @@ -157,7 +157,7 @@ void Context::storeContexts(std::vector& contexts, const std::string& d res += "{" + std::to_string(contexts[i].getKey()) + "}{\n"; res += contexts[i].toString(); res += "}\n"; - Display::Percent((i+1)*100/contexts.size()); + Display::percent((i+1)*100/contexts.size()); } std::ofstream file; @@ -165,15 +165,15 @@ void Context::storeContexts(std::vector& contexts, const std::string& d file << res; file.close(); - Display::Percent(100); - Display::Debug(""); + Display::percent(100); + Display::debug(""); } std::string Context::ContextsToString(std::vector& contexts) { - Display::Info("Convert contexts:"); + Display::info("Convert contexts:"); - Display::Percent(0); + Display::percent(0); std::string res; res += "[" + std::to_string(contexts.size()) + "]\n"; for(size_t i = 0; i < contexts.size(); i++) @@ -181,11 +181,11 @@ std::string Context::ContextsToString(std::vector& contexts) res += "{" + std::to_string(contexts[i].getKey()) + "}{\n"; res += contexts[i].toString(); res += "}\n"; - Display::Percent((i+1)*100/contexts.size()); + Display::percent((i+1)*100/contexts.size()); } - Display::Percent(100); - Display::Debug(""); + Display::percent(100); + Display::debug(""); return res; } @@ -193,7 +193,7 @@ std::string Context::ContextsToString(std::vector& contexts) void Context::loadContexts(std::vector& contexts, const std::string& directory) { //contexts must have a key - Display::Info("Load contexts:"); + Display::info("Load contexts:"); std::ifstream t(directory + "/context.txt"); if(t) { @@ -210,7 +210,7 @@ void Context::loadContexts(std::vector& contexts, const std::string& di std::istringstream iss(tmp); iss >> nb_contexts; - Display::Percent(0); + Display::percent(0); for(size_t i = 0; i < nb_contexts; i++) { @@ -234,12 +234,12 @@ void Context::loadContexts(std::vector& contexts, const std::string& di } } - Display::Percent((i+1)*100/nb_contexts); + Display::percent((i+1)*100/nb_contexts); } } - Display::Percent(100); - Display::Debug(""); + Display::percent(100); + Display::debug(""); } std::vector Context::StringToContext(const std::string& str) From 03fca817adb5f7cd02038fd13030270f49a7bd1d Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 2 Nov 2020 18:30:44 +0100 Subject: [PATCH 53/95] [UPDATE] occasion subscription --- include/mementar/API/Fact.h | 54 +++++++++++++------ .../core/Occasions/OccasionsManager.h | 8 +-- .../mementar/core/Occasions/Subscription.h | 2 +- include/mementar/core/feeder/Feeder.h | 6 +++ .../core/memGraphs/Branchs/types/Triplet.h | 5 ++ include/mementar/core/memGraphs/Timeline.h | 5 +- src/RosInterface.cpp | 5 +- src/core/Occasions/OccasionsManager.cpp | 14 ++--- src/core/Occasions/Subscription.cpp | 4 +- src/core/feeder/Feeder.cpp | 4 +- src/core/memGraphs/Branchs/types/Triplet.cpp | 1 + src/test/occasions_sub_pub.cpp | 5 ++ 12 files changed, 78 insertions(+), 35 deletions(-) diff --git a/include/mementar/API/Fact.h b/include/mementar/API/Fact.h index 53fcf1d..22d39a3 100644 --- a/include/mementar/API/Fact.h +++ b/include/mementar/API/Fact.h @@ -3,6 +3,7 @@ #include #include +#include namespace mementar { @@ -10,33 +11,50 @@ namespace mementar class Fact { public: - Fact(const std::string& fact) + Fact(const std::string& fact, bool add = true) { - std::vector splitted = split(fact, "|"); - if(splitted.size() >= 1) - subject_ = splitted[0]; - if(splitted.size() >= 2) - predicat_ = splitted[1]; - if(splitted.size() >= 3) - object_ = splitted[2]; + std::smatch match; + std::regex regex("\\[(\\w+)\\]([^|]+)\\|([^|]+)\\|([^|]+)"); + if(std::regex_match(fact, match, regex)) + { + subject_ = match[2].str(); + predicat_ = match[3].str(); + object_ = match[4].str(); + add_ = (match[1].str() == "ADD") || (match[1].str() == "add"); + } + else + { + std::vector splitted = split(fact, "|"); + if(splitted.size() >= 1) + subject_ = splitted[0]; + if(splitted.size() >= 2) + predicat_ = splitted[1]; + if(splitted.size() >= 3) + object_ = splitted[2]; + add_ = add; + } } - Fact(const std::string& subject, const std::string& predicat, const std::string& object) + Fact(const std::string& subject, const std::string& predicat, const std::string& object, bool add = true) { subject_ = subject; predicat_ = predicat; object_ = object; + add_ = true; } - std::string subject() const { return subject_; } - std::string predicat() const { return predicat_; } - std::string object() const { return object_; } - std::string operator()() const {return subject_ + "|" + predicat_ + "|" + object_; } + std::string getSubject() const { return subject_; } + std::string getPredicat() const { return predicat_; } + std::string getObject() const { return object_; } + bool getAdda() const { return add_; } + std::string operator()() const { return (add_ ? "[add]" : "[del]") + subject_ + "|" + predicat_ + "|" + object_; } + std::string to_string() const { return (add_ ? "[add]" : "[del]") + subject_ + "|" + predicat_ + "|" + object_; } - void subject(const std::string& subject) { subject_ = subject; } - void predicat(const std::string& predicat) { predicat_ = predicat; } - void object(const std::string& object) { object_ = object; } - void operator()(const std::string& fact) + void setSubject(const std::string& subject) { subject_ = subject; } + void setPredicat(const std::string& predicat) { predicat_ = predicat; } + void setObject(const std::string& object) { object_ = object; } + void setAdd(bool add) { add_ = add; } + void operator()(const std::string& fact, bool add = true) { std::vector splitted = split(fact, "|"); if(splitted.size() >= 1) @@ -45,12 +63,14 @@ class Fact predicat_ = splitted[1]; if(splitted.size() >= 3) object_ = splitted[2]; + add_ = add; } private: std::string subject_; std::string predicat_; std::string object_; + bool add_; std::vector split(const std::string& str, const std::string& delim) { diff --git a/include/mementar/core/Occasions/OccasionsManager.h b/include/mementar/core/Occasions/OccasionsManager.h index 71e2e0d..72ec861 100644 --- a/include/mementar/core/Occasions/OccasionsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -23,7 +23,7 @@ class OccasionsManager void run(); - void add(const Triplet* triplet); + void add(const Triplet& triplet); void stop() {run_ = false; } inline bool isRunning() {return run_; } @@ -40,15 +40,15 @@ class OccasionsManager std::mutex mutex_; bool queue_choice_; - std::queue fifo_1; - std::queue fifo_2; + std::queue fifo_1; + std::queue fifo_2; bool SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res); bool UnsubscribeCallback(mementar::MementarOcassionUnsubscription::Request &req, mementar::MementarOcassionUnsubscription::Response &res); - const Triplet* get(); + Triplet get(); bool empty(); }; diff --git a/include/mementar/core/Occasions/Subscription.h b/include/mementar/core/Occasions/Subscription.h index ba019b5..0274576 100644 --- a/include/mementar/core/Occasions/Subscription.h +++ b/include/mementar/core/Occasions/Subscription.h @@ -20,7 +20,7 @@ class Subscription bool isFinished(size_t id); bool empty() { return triplet_paterns_.size() == 0; } - std::vector evaluate(const Triplet* triplet); + std::vector evaluate(const Triplet& triplet); private: std::map triplet_paterns_; diff --git a/include/mementar/core/feeder/Feeder.h b/include/mementar/core/feeder/Feeder.h index 85b3376..7b595ea 100644 --- a/include/mementar/core/feeder/Feeder.h +++ b/include/mementar/core/feeder/Feeder.h @@ -5,6 +5,8 @@ #include "mementar/core/feeder/IdGenerator.h" //#include "ontologenius/core/feeder/Versionor.h" +#include + namespace mementar { class Timeline; @@ -18,6 +20,7 @@ class Feeder void store(const std::string& feed, const std::string& expl) { feed_storage_.insert(feed, expl); } bool run(); void link(Timeline* timeline) {timeline_ = timeline; } + void setCallback(const std::function& callback) { callback_ = callback; } std::vector getNotifications() { @@ -36,9 +39,12 @@ class Feeder IdGenerator id_generator_; //Versionor versionor_; Timeline* timeline_; + std::function callback_; // Here the notifications are about miss formed queries std::vector notifications_; + + void defaultCallback(const Triplet&) {} }; } // namespace mementar diff --git a/include/mementar/core/memGraphs/Branchs/types/Triplet.h b/include/mementar/core/memGraphs/Branchs/types/Triplet.h index f56ed99..11b70cd 100644 --- a/include/mementar/core/memGraphs/Branchs/types/Triplet.h +++ b/include/mementar/core/memGraphs/Branchs/types/Triplet.h @@ -54,6 +54,8 @@ class Triplet { if(std::regex_match(str, match, regex)) return Triplet(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + else if(std::regex_match(str, match, regex2)) + return Triplet(match[2].str(), match[3].str(), match[4].str(), (match[1].str() == "ADD") || (match[1].str() == "add")); else return Triplet(); } @@ -62,6 +64,8 @@ class Triplet { if(std::regex_match(str, match, regex)) return new Triplet(match[2].str(), match[3].str(), match[4].str(), match[1].str() == "A"); + else if(std::regex_match(str, match, regex2)) + return new Triplet(match[2].str(), match[3].str(), match[4].str(), (match[1].str() == "ADD") || (match[1].str() == "add")); else return nullptr; } @@ -113,6 +117,7 @@ class Triplet protected: static std::regex regex; + static std::regex regex2; static std::smatch match; private: diff --git a/include/mementar/core/memGraphs/Timeline.h b/include/mementar/core/memGraphs/Timeline.h index d02baf4..614c0b8 100644 --- a/include/mementar/core/memGraphs/Timeline.h +++ b/include/mementar/core/memGraphs/Timeline.h @@ -9,11 +9,14 @@ namespace mementar { class Timeline { public: - Timeline() : actions(&facts) {} + Timeline() : actions(&facts) { init_ = true; } FactGraph facts; ActionGraph actions; + + bool isInit() { return init_; } private: + bool init_; }; } // namespace mementar diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 7c448fc..bcea0cc 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -46,6 +46,7 @@ void RosInterface::run() service_name = (name_ == "") ? "actions" : "actions/" + name_; ros::ServiceServer service = n_->advertiseService(service_name, &RosInterface::actionsHandle, this); + feeder_.setCallback([this](const Triplet& triplet){ this->occasions_.add(triplet); }); std::thread occasions_thread(&OccasionsManager::run, &occasions_); std::thread feed_thread(&RosInterface::feedThread, this); @@ -136,10 +137,10 @@ void RosInterface::feedThread() ros::Publisher feeder_publisher = n_->advertise(getTopicName("feeder_notifications"), 1000); ros::Rate wait(100); - /*while((ros::ok()) && (onto_->isInit(false) == false) && (run_ == true)) + while((ros::ok()) && (timeline_->isInit() == false) && (run_ == true)) { wait.sleep(); - }*/ + } std_msgs::String msg; while(ros::ok() && (run_ == true)) diff --git a/src/core/Occasions/OccasionsManager.cpp b/src/core/Occasions/OccasionsManager.cpp index 88d6e6e..5e5c175 100644 --- a/src/core/Occasions/OccasionsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -27,15 +27,15 @@ void OccasionsManager::run() { while(!empty()) { - const Triplet* triplet = get(); - if(triplet->valid()) + Triplet triplet = get(); + if(triplet.valid()) { std::vector ids = subscription_.evaluate(triplet); for(auto id : ids) { mementar::MementarOccasion msg; msg.id = id; - msg.data = triplet->toString(); + msg.data = triplet.toString(); msg.last = subscription_.isFinished(id); pub_.publish(msg); } @@ -45,7 +45,7 @@ void OccasionsManager::run() } } -void OccasionsManager::add(const Triplet* triplet) +void OccasionsManager::add(const Triplet& triplet) { mutex_.lock(); if(queue_choice_ == true) @@ -58,7 +58,7 @@ void OccasionsManager::add(const Triplet* triplet) bool OccasionsManager::SubscribeCallback(mementar::MementarOccasionSubscription::Request &req, mementar::MementarOccasionSubscription::Response &res) { - Triplet triplet_patern(req.data); + Triplet triplet_patern = Triplet::deserialize(req.data); if(!triplet_patern.valid()) return false; @@ -78,9 +78,9 @@ bool OccasionsManager::UnsubscribeCallback(mementar::MementarOcassionUnsubscript return true; } -const Triplet* OccasionsManager::get() +Triplet OccasionsManager::get() { - const Triplet* res = nullptr; + Triplet res; mutex_.lock(); if(queue_choice_ == true) { diff --git a/src/core/Occasions/Subscription.cpp b/src/core/Occasions/Subscription.cpp index 62e07bb..59b7c30 100644 --- a/src/core/Occasions/Subscription.cpp +++ b/src/core/Occasions/Subscription.cpp @@ -42,14 +42,14 @@ bool Subscription::isFinished(size_t id) return res; } -std::vector Subscription::evaluate(const Triplet* triplet) +std::vector Subscription::evaluate(const Triplet& triplet) { std::vector res; map_mut_.lock(); for(auto& it : triplet_paterns_) { - if(triplet->fit(it.second)) + if(triplet.fit(it.second)) { if(counts_[it.first]) { diff --git a/src/core/feeder/Feeder.cpp b/src/core/feeder/Feeder.cpp index 7e41dd6..5c3e5fa 100644 --- a/src/core/feeder/Feeder.cpp +++ b/src/core/feeder/Feeder.cpp @@ -6,7 +6,7 @@ namespace mementar { -Feeder::Feeder(Timeline* timeline)// : versionor_(&feed_storage_) +Feeder::Feeder(Timeline* timeline) : callback_([this](auto triplet){ this->defaultCallback(triplet); }) //, versionor_(&feed_storage_) { timeline_ = timeline; } @@ -63,6 +63,8 @@ bool Feeder::run() } else timeline_->facts.add(new mementar::ContextualizedFact(id_generator_.get(), feed.fact_.value())); + + callback_(feed.fact_.value()); } } diff --git a/src/core/memGraphs/Branchs/types/Triplet.cpp b/src/core/memGraphs/Branchs/types/Triplet.cpp index 8688165..b927e22 100644 --- a/src/core/memGraphs/Branchs/types/Triplet.cpp +++ b/src/core/memGraphs/Branchs/types/Triplet.cpp @@ -3,6 +3,7 @@ namespace mementar { std::regex Triplet::regex("(\\w)\\|(\\w+)\\|(\\w+)\\|(\\w+)"); +std::regex Triplet::regex2("\\[(\\w+)\\]([^|]+)\\|([^|]+)\\|([^|]+)"); std::smatch Triplet::match; } // namespace mementar diff --git a/src/test/occasions_sub_pub.cpp b/src/test/occasions_sub_pub.cpp index a4b6600..336446f 100644 --- a/src/test/occasions_sub_pub.cpp +++ b/src/test/occasions_sub_pub.cpp @@ -24,10 +24,15 @@ int main(int argc, char** argv) mementar::TimelineManipulator manip(&n); manip.waitInit(); + std::cout << "init" << std::endl; + mementar::OccasionsSubscriber sub1(&callback_1, true); sub1.subscribe(mementar::Fact("bob", "eat", "?"), 2); mementar::OccasionsSubscriber sub2(&callback_2, true); sub2.subscribe(mementar::Fact("max", "eat", "?"), 3); + sub2.subscribe(mementar::Fact("bob", "eat", "?"), 4); + + std::cout << "sub" << std::endl; size_t cpt = 0; ros::Rate r(100); From 3e5ce66cf912e35f8ec29b01d3830ab2ca1638cc Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 4 Nov 2020 02:23:59 +0100 Subject: [PATCH 54/95] [ADD] configuration file management --- CMakeLists.txt | 5 + .../core/Parametrization/Configuration.h | 80 ++++++++++ src/core/Parametrization/Configuration.cpp | 147 ++++++++++++++++++ src/test/config.cpp | 26 ++++ 4 files changed, 258 insertions(+) create mode 100644 include/mementar/core/Parametrization/Configuration.h create mode 100644 src/core/Parametrization/Configuration.cpp create mode 100644 src/test/config.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 44d0e2a..663d593 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,7 @@ add_dependencies(mementar_lib ${catkin_EXPORTED_TARGETS} mementar_gencpp) add_library(mementar_interface src/core/feeder/FeedStorage.cpp src/core/feeder/Feeder.cpp + src/core/Parametrization/Configuration.cpp src/RosInterface.cpp ) target_link_libraries(mementar_interface mementar_core_lib mementar_events_lib) @@ -204,6 +205,10 @@ add_dependencies(mementar_timeline ${catkin_EXPORTED_TARGETS}) ## Test executables ############################## +add_executable(config src/test/config.cpp) +target_link_libraries(config ${catkin_LIBRARIES}) +target_link_libraries(config mementar_interface) + add_executable(event_sub_pub src/test/occasions_sub_pub.cpp) target_link_libraries(event_sub_pub ${catkin_LIBRARIES}) target_link_libraries(event_sub_pub mementar_lib) diff --git a/include/mementar/core/Parametrization/Configuration.h b/include/mementar/core/Parametrization/Configuration.h new file mode 100644 index 0000000..34f0987 --- /dev/null +++ b/include/mementar/core/Parametrization/Configuration.h @@ -0,0 +1,80 @@ +#ifndef MEMENTAR_CONFIGURATION_H +#define MEMENTAR_CONFIGURATION_H + +#include +#include +#include +#include + +namespace mementar +{ + +class ConfigElement +{ +public: + std::experimental::optional> data; + std::experimental::optional> subelem; + + ConfigElement operator[](const std::string& name) + { + if(subelem) + return subelem.value()[name]; + else + return ConfigElement(); + } + + bool exist(const std::string& name) + { + if(subelem) + return (subelem.value().find(name) != subelem.value().end()); + else + return false; + } + + std::vector value() + { + if(data) + return data.value(); + else + return {}; + } + + void push_back(const std::string& value) + { + data.value().push_back(value); + } +}; + +class Configuration +{ +public: + std::map config_; + + bool read(const std::string& path); + bool write(const std::string& path); + + void display(); + + ConfigElement& operator[](const std::string& name) + { + return config_[name]; + } + + bool exist(const std::string& name) + { + return (config_.find(name) != config_.end()); + } + +private: + void display(std::map& config, size_t nb = 0); + void displayTab(size_t nb); + + std::string getConfig(std::map& config, size_t nb = 0); + std::string getTabs(size_t nb); + + void removeComment(std::string& line); +}; + +} // namespace mementar + +#endif // MEMENTAR_CONFIGURATION_H diff --git a/src/core/Parametrization/Configuration.cpp b/src/core/Parametrization/Configuration.cpp new file mode 100644 index 0000000..2c2c72b --- /dev/null +++ b/src/core/Parametrization/Configuration.cpp @@ -0,0 +1,147 @@ +#include "mementar/core/Parametrization/Configuration.h" + +#include +#include +#include + +namespace mementar +{ + +bool Configuration::read(const std::string& path) +{ + std::ifstream config_file(path); + if(config_file.is_open()) + { + std::regex element_regex(R"(^\s*([^\s]*)\s*:\s*([^\n]*)\s*$)"); + std::regex list_regex(R"(^\s*-\s*(.*)\s*$)"); + std::smatch match; + + std::string line; + std::string element; + while(std::getline(config_file,line)) + { + removeComment(line); + if(std::regex_match(line, match, element_regex)) + { + if(match[2].str() == "") + { + config_[match[1].str()] = ConfigElement(); + element = match[1].str(); + } + else + { + auto tmp = std::pair(match[1].str(), ConfigElement()); + if(!config_[element].subelem) + config_[element].subelem = std::map(); + config_[element].subelem->insert(tmp); + if(!config_[element].subelem->at(match[1].str()).data) + config_[element].subelem->at(match[1].str()).data = std::vector(); + config_[element].subelem->at(match[1].str()).data->push_back(match[2].str()); + } + } + else if(std::regex_match(line, match, list_regex)) + { + if(!config_[element].data) + config_[element].data = std::vector(); + config_[element].data->push_back(match[1].str()); + } + } + config_file.close(); + return true; + } + else + return false; +} + +bool Configuration::write(const std::string& path) +{ + std::ofstream config_file(path, std::ofstream::out); + if(config_file.is_open()) + { + config_file << getConfig(config_); + config_file.close(); + return true; + } + else + return false; +} + +void Configuration::display() +{ + display(config_); +} + +void Configuration::display(std::map& config, size_t nb) +{ + for(auto& c : config) + { + displayTab(nb); + std::cout << c.first << " : " << std::endl; + if(c.second.data) + { + for(auto& d : c.second.data.value()) + { + displayTab(nb+1); + std::cout << "- " << d << std::endl; + } + } + else if(c.second.subelem) + display(c.second.subelem.value(), nb+1); + } +} + +void Configuration::displayTab(size_t nb) +{ + for(size_t i = 0; i < nb; i++) + std::cout << "\t"; +} + +std::string Configuration::getConfig(std::map& config, size_t nb) +{ + std::string str; + for(auto& c : config) + { + str += getTabs(nb); + str += c.first + " : "; + if(c.second.data) + { + if(c.second.data.value().size() == 0) + str += "\n"; + if(c.second.data.value().size() == 1) + { + str += c.second.data.value()[0] + "\n"; + } + else + { + str += "\n"; + for(auto& d : c.second.data.value()) + { + str += getTabs(nb+1); + str += "- " + d + "\n"; + } + } + } + else if(c.second.subelem) + { + str += "\n" + getConfig(c.second.subelem.value(), nb+1); + } + } + return str; +} + +std::string Configuration::getTabs(size_t nb) +{ + std::string str; + for(size_t i = 0; i < nb; i++) + str += " "; + return str; +} + +void Configuration::removeComment(std::string& line) +{ + size_t pose = line.find('#'); + if(pose != std::string::npos) + line = line.substr(0, pose); +} + +} // namespace mementar diff --git a/src/test/config.cpp b/src/test/config.cpp new file mode 100644 index 0000000..955cfdb --- /dev/null +++ b/src/test/config.cpp @@ -0,0 +1,26 @@ +#include "mementar/core/Parametrization/Configuration.h" + +#include + +int main() +{ + mementar::Configuration config; + bool ok = true; + ok = config.read("/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/file_intern/configuration.yaml"); + if(ok) + { + if(config.exist("WhiteListe")) + { + config["WhiteListe"].push_back("new property"); + config.display(); + ok = config.write("/home/gsarthou/Robots/Pr2/Semantic/catkin_ws/src/mementar/file_intern/new_configuration.yaml"); + if(!ok) + std::cout << "fail to write the new configuation file" << std::endl; + } + else + std::cout << "WhiteListe not found" << std::endl; + } + else + std::cout << "fail to read configuation file" << std::endl; + return 0; +} From 005694c83ea834658c21da314e9f8f685636a557 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 4 Nov 2020 03:04:59 +0100 Subject: [PATCH 55/95] [UPDATE] execution time measure from fact publication into ontology to callback call: max 60ms --- CMakeLists.txt | 3 ++- package.xml | 2 ++ src/test/occasions_sub_pub.cpp | 32 +++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 663d593..597347e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(catkin REQUIRED COMPONENTS genmsg message_generation pluginlib + ontologenius ) ## System dependencies are found with CMake's conventions @@ -62,7 +63,7 @@ find_package(OpenCV REQUIRED) catkin_package( INCLUDE_DIRS include LIBRARIES mementar_lib - CATKIN_DEPENDS roscpp rospy std_msgs + CATKIN_DEPENDS roscpp rospy std_msgs ontologenius DEPENDS OpenCV ) diff --git a/package.xml b/package.xml index e3fb494..a774967 100644 --- a/package.xml +++ b/package.xml @@ -23,6 +23,7 @@ pluginlib qtbase5-dev rostest + ontologenius message_runtime diagnostic_msgs @@ -30,6 +31,7 @@ roscpp std_msgs pluginlib + ontologenius + + + + 0 + + + + + + Feeder + + + + + + + + + + + + 130 + 30 + + + + + 130 + 30 + + + + + 0 + 0 + + + + Subject / Action : + + + + + + + + + + + + + + + + + + + + 130 + 30 + + + + + 130 + 30 + + + + + 0 + 0 + + + + Property : + + + + + + + + + + + + + + + + + + + + 130 + 30 + + + + + 130 + 30 + + + + + 0 + 0 + + + + Object : + + + + + + + + + + + + + + + + ADD / START + + + + + + + + REMOVE / END + + + + + + + + QFrame::Plain + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + + Commit + + + + + + + + Checkout + + + + + + + + + + + + 350 + 16777215 + + + + true + + + 1 + + + Qt::NoTextInteraction + + + + + + + + + + + Manager + + + + + + + + + + 0 + 0 + + + + This second can only be used with the "mementar_multi" executable + + + true + + + Qt::AlignCenter + + + + + + + + ADD(name) / COPY(dest=src) + + + + + + + + DELETE(name) + + + + + + + + + + + + + + + + + + QFrame::Plain + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + + + + + + 20 + 20 + + + + + :/darkstyle/icon_save.png + + + + + + + + + + + + + + + + + + + + + 20 + 20 + + + + + :/darkstyle/icon_draw.png + + + + + + + + + + + + + + + + + + 20 + 20 + + + + + :/darkstyle/icon_refresh.png + + + + + + + + + + + + + 250 + 16777215 + + + + true + + + 1 + + + Qt::NoTextInteraction + + + + + + + + + + + + + + + + + + + + + + 150 + 0 + + + + + 200 + 200 + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> + p, li { white-space: pre-wrap; } + </style></head><body style=" font-family:'Noto Sans'; font-size:9pt; font-weight:400; font-style:normal;"> + <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + + + + Name + + + + 50 + 16777215 + + + + + + + + + 145 + 16777215 + + + + + + + + + + + + + + + 0 + 0 + + + + Qt::Vertical + + + + + + + + + 16777215 + 260 + + + + true + + + + + + + + + + + + + + + + + QPushButtonExtended + QPushButton +
    include/mementar/graphical/mementarGUI/QPushButtonExtended.h
    +
    + + QCheckBoxExtended + QCheckBox +
    include/mementar/graphical/mementarGUI/QCheckBoxExtended.h
    +
    + + QLineEditExtended + QLineEdit +
    include/mementar/graphical/mementarGUI/QLineEditExtended.h
    +
    +
    + + + From ed928c6c538432481bef0702aa6421183c289076 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Fri, 11 Dec 2020 18:16:41 +0100 Subject: [PATCH 75/95] [FIX] timeline drawer when the timeline is empty --- .../mementar/graphical/timeline/TimelineDrawer.h | 2 +- src/RosInterface.cpp | 3 ++- src/graphical/mementarGUI/mementargui.cpp | 6 +++--- src/graphical/timeline/TimelineDrawer.cpp | 15 +++++++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/mementar/graphical/timeline/TimelineDrawer.h b/include/mementar/graphical/timeline/TimelineDrawer.h index 46c759d..1bf1d1d 100644 --- a/include/mementar/graphical/timeline/TimelineDrawer.h +++ b/include/mementar/graphical/timeline/TimelineDrawer.h @@ -16,7 +16,7 @@ class TimelineDrawer { public: - void draw(const std::string& file_name, Timeline* timeline); + bool draw(const std::string& file_name, Timeline* timeline); private: IplImage* image_; diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 8db00b9..2fb4a69 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -165,7 +165,8 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, if(req.action == "draw") { TimelineDrawer drawer; - drawer.draw(req.param, timeline_); + if(drawer.draw(req.param, timeline_) == false) + res.code = NO_EFFECT; } else res.code = UNKNOW_ACTION; diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index d07f3f6..74187c0 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -209,7 +209,7 @@ void mementarGUI::deleteInstanceSlot() { start(); if(srv.response.code == 4) - ui->static_result_editext->setText(QString::fromStdString(srv.request.param + " don't exist")); + ui->static_result_editext->setText(QString::fromStdString("Instance \'" + srv.request.param + "\' don't exist")); else ui->static_result_editext->setText(QString::fromStdString("")); displayInstancesList(); @@ -230,7 +230,7 @@ void mementarGUI::saveInstanceSlot() else { if(srv.response.code == 4) - ui->static_result_editext->setText(QString::fromStdString(srv.request.param + " don't exist")); + ui->static_result_editext->setText(QString::fromStdString("path \'" + srv.request.param + "\' don't exist")); else ui->static_result_editext->setText(QString::fromStdString("")); } @@ -250,7 +250,7 @@ void mementarGUI::drawInstanceSlot() else { if(srv.response.code == 4) - ui->static_result_editext->setText(QString::fromStdString(srv.request.param + " don't exist")); + ui->static_result_editext->setText(QString::fromStdString("path \'" + srv.request.param + "\' don't exist")); else ui->static_result_editext->setText(QString::fromStdString("")); } diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index b408c87..cd4f088 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -9,7 +9,7 @@ namespace mementar { -void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline) +bool TimelineDrawer::draw(const std::string& file_name, Timeline* timeline) { CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0, 0.5); @@ -19,6 +19,9 @@ void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline) FactReader facts_reader_; facts_reader_.read(&timeline->facts, &font); + if(timeline->facts.getTimeline()->getFirst() == nullptr) + return false; + size_t start = timeline->facts.getTimeline()->getFirst()->getKey(); size_t end = timeline->facts.getTimeline()->getLast()->getKey(); size_t width = (actions_reader_.max_level_ + 1) * SIDE_SPACE + actions_reader_.max_text_size_ + MARGIN * 3 + SIDE_SPACE + facts_reader_.max_text_size_; @@ -46,10 +49,14 @@ void TimelineDrawer::draw(const std::string& file_name, Timeline* timeline) if((height != 1) && (width != 1)) cv::imwrite(file_name.c_str(), cv::cvarrToMat(image_)); - } - if(image_ != nullptr) - cvReleaseImage(&image_); + if(image_ != nullptr) + cvReleaseImage(&image_); + + return true; + } + else + return false; } void TimelineDrawer::drawVector(size_t start, size_t end, size_t pose, CvFont* font) From 046c5ca896dbd1f62f89404fda1f4e15653f2a43 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 11:01:08 +0100 Subject: [PATCH 76/95] [UPDATE] mementarGUI with current time selection --- .../graphical/mementarGUI/CallBackTimer.h | 56 +++++++++++++++++++ .../graphical/mementarGUI/mementargui.h | 9 +++ src/graphical/mementarGUI/main.cpp | 41 +++++++------- src/graphical/mementarGUI/mementargui.cpp | 43 +++++++++++++- ui/mementargui.ui | 40 +++++++++++++ 5 files changed, 167 insertions(+), 22 deletions(-) create mode 100644 include/mementar/graphical/mementarGUI/CallBackTimer.h diff --git a/include/mementar/graphical/mementarGUI/CallBackTimer.h b/include/mementar/graphical/mementarGUI/CallBackTimer.h new file mode 100644 index 0000000..3a756f8 --- /dev/null +++ b/include/mementar/graphical/mementarGUI/CallBackTimer.h @@ -0,0 +1,56 @@ +#ifndef MEMENTAR_CALLBACKTIMER_H +#define MEMENTAR_CALLBACKTIMER_H + +#include +#include +#include + +class CallBackTimer +{ +public: + CallBackTimer() + :execute_(false) + {} + + ~CallBackTimer() + { + if(execute_.load(std::memory_order_acquire)) + stop(); + } + + void stop() + { + execute_.store(false, std::memory_order_release); + if(th_.joinable()) + th_.join(); + } + + void start(int interval, std::function func) + { + if(execute_.load(std::memory_order_acquire)) + stop(); + + execute_.store(true, std::memory_order_release); + th_ = std::thread([this, interval, func]() + { + while (execute_.load(std::memory_order_acquire)) + { + func(); + std::this_thread::sleep_for( + std::chrono::milliseconds(interval)); + } + }); + } + + bool isRunning() const noexcept + { + return (execute_.load(std::memory_order_acquire) && + th_.joinable()); + } + +private: + std::atomic execute_; + std::thread th_; +}; + +#endif // MEMENTAR_CALLBACKTIMER_H diff --git a/include/mementar/graphical/mementarGUI/mementargui.h b/include/mementar/graphical/mementarGUI/mementargui.h index 63a3b44..d88d1e0 100644 --- a/include/mementar/graphical/mementarGUI/mementargui.h +++ b/include/mementar/graphical/mementarGUI/mementargui.h @@ -3,6 +3,7 @@ #include #include "include/mementar/graphical/mementarGUI/QCheckBoxExtended.h" +#include "include/mementar/graphical/mementarGUI/CallBackTimer.h" #include #include @@ -36,12 +37,18 @@ class mementarGUI : public QMainWindow std::map feeder_notifications_subs_; std::string feeder_notifications_; + int time_source_; + std::atomic current_time_; + CallBackTimer timer_; + void displayInstancesList(); void displayErrorInfo(const std::string& text); std::string vector2string(const std::vector& vect); std::string vector2html(const std::vector& vect); + void updateTime(); + public slots: void nameEditingFinishedSlot(); void currentTabChangedSlot(int); @@ -53,6 +60,7 @@ public slots: void drawInstanceSlot(); void InstanceNameAddDelChangedSlot(const QString&); void InstanceNameChangedSlot(const QString&); + void timesourceChangedSlot(int index); void feederCallback(const std_msgs::String& msg); void feederAddSlot(); @@ -63,6 +71,7 @@ public slots: signals: void feederSetHtmlSignal(QString); + void setTimeSignal(QString); }; #endif // MEMENTAR_MEMENTARGUI_H diff --git a/src/graphical/mementarGUI/main.cpp b/src/graphical/mementarGUI/main.cpp index 3cfc73c..49f4c75 100644 --- a/src/graphical/mementarGUI/main.cpp +++ b/src/graphical/mementarGUI/main.cpp @@ -21,35 +21,36 @@ void spinThread(bool* run) int main(int argc, char *argv[]) { - QApplication a(argc, argv); + ros::init(argc, argv, "mementarGUI"); - a.setStyle(new DarkStyle); + ros::NodeHandle n; - std::string path = ros::package::getPath("mementar"); - path = path + "/docs/img/logo/mementar.ico"; - QIcon icon(QString::fromStdString(path)); - a.setWindowIcon(icon); + QApplication a(argc, argv); - mementarGUI w; - w.show(); + a.setStyle(new DarkStyle); - ros::init(argc, argv, "mementarGUI"); + std::string path = ros::package::getPath("mementar"); + path = path + "/docs/img/logo/mementar.ico"; + QIcon icon(QString::fromStdString(path)); + a.setWindowIcon(icon); - ros::NodeHandle n; - bool run = true; + mementarGUI w; + w.show(); - w.init(&n); - w.wait(); + bool run = true; - w.start(); + w.init(&n); + w.wait(); - std::thread spin_thread(spinThread,&run); + w.start(); - signal(SIGINT, SIG_DFL); - auto a_exec = a.exec(); + std::thread spin_thread(spinThread,&run); - run = false; - spin_thread.join(); + signal(SIGINT, SIG_DFL); + auto a_exec = a.exec(); - return a_exec; + run = false; + spin_thread.join(); + + return a_exec; } diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index 74187c0..af08ca9 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -16,7 +16,8 @@ mementarGUI::mementarGUI(QWidget *parent) : QMainWindow(parent), - ui(new Ui::mementarGUI) + ui(new Ui::mementarGUI), + current_time_(ros::Time::now()) { ui->setupUi(this); @@ -34,9 +35,11 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->manager_instance_name_editline, SIGNAL(textChanged(const QString&)), this, SLOT(InstanceNameAddDelChangedSlot(const QString&))); QObject::connect(ui->static_instance_name_editline, SIGNAL(textChanged(const QString&)), this, SLOT(InstanceNameChangedSlot(const QString&))); QObject::connect(ui->static_instance_name_editline, SIGNAL(editingFinished()),this, SLOT(nameEditingFinishedSlot())); + QObject::connect(ui->static_time_source_combobox, SIGNAL(currentIndexChanged(int)),this, SLOT(timesourceChangedSlot(int))); QObject::connect(ui->static_tab_widget, SIGNAL(currentChanged(int)),this, SLOT(currentTabChangedSlot(int))); - QObject::connect( this, SIGNAL( feederSetHtmlSignal(QString) ), ui->feeder_info_edittext, SLOT( setHtml(QString) ) ,Qt::BlockingQueuedConnection); + QObject::connect( this, SIGNAL( feederSetHtmlSignal(QString) ), ui->feeder_info_edittext, SLOT( setHtml(QString) ), Qt::BlockingQueuedConnection); + QObject::connect( this, SIGNAL( setTimeSignal(QString) ), ui->static_current_time_editline, SLOT( setText(QString) ), Qt::BlockingQueuedConnection); } mementarGUI::~mementarGUI() @@ -47,6 +50,8 @@ mementarGUI::~mementarGUI() void mementarGUI::init(ros::NodeHandle* n) { n_ = n; + timesourceChangedSlot(0); + facts_publishers_["_"] = n_->advertise("/mementar/insert_fact_stamped", QUEU_SIZE); actions_publishers_["_"] = n_->advertise("/mementar/insert_action", QUEU_SIZE); feeder_notifications_subs_["_"] = n_->subscribe("mementar/feeder_notifications", QUEU_SIZE, &mementarGUI::feederCallback, this); @@ -137,6 +142,23 @@ std::string mementarGUI::vector2html(const std::vector& vect) return res; } +void mementarGUI::updateTime() +{ + if(time_source_ == 0) + { + current_time_.store(ros::Time::now(), std::memory_order_release); + setTimeSignal(QString::fromStdString(std::to_string(current_time_.load(std::memory_order_acquire).sec))); + //ui->static_current_time_editline->setText(); + } + else if(time_source_ == 1) + { + struct timeval tp; + gettimeofday(&tp, NULL); + current_time_.store(ros::Time(tp.tv_sec, tp.tv_usec), std::memory_order_release); + setTimeSignal(QString::fromStdString(std::to_string(current_time_.load(std::memory_order_acquire).sec))); + } +} + void mementarGUI::currentTabChangedSlot(int index) { if(index == 1) @@ -268,6 +290,23 @@ void mementarGUI::InstanceNameChangedSlot(const QString& text) ui->manager_instance_name_editline->setText(text); } +void mementarGUI::timesourceChangedSlot(int index) +{ + time_source_ = index; + if(index == 2) // manual + { + if(timer_.isRunning()) + timer_.stop(); + ui->static_current_time_editline->setReadOnly(false); + } + else + { + ui->static_current_time_editline->setReadOnly(true); + if(timer_.isRunning() == false) + timer_.start(250, [this](){ this->updateTime(); }); + } +} + void mementarGUI::feederCallback(const std_msgs::String& msg) { feeder_notifications_ += "

    -" + msg.data + "

    "; diff --git a/ui/mementargui.ui b/ui/mementargui.ui index d9270f5..9910c00 100644 --- a/ui/mementargui.ui +++ b/ui/mementargui.ui @@ -454,6 +454,46 @@ + + + + + + + 80 + 16777215 + + + + + Ros + + + + + Epoch + + + + + Manual + + + + + + + + + 145 + 16777215 + + + + + + + From 5084379c582caba414a249563dfa2d2120455ec1 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 16:21:42 +0100 Subject: [PATCH 77/95] [UPDATE] mementarGUI publish events with gui time --- .../graphical/mementarGUI/mementargui.h | 1 + src/graphical/mementarGUI/mementargui.cpp | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/mementar/graphical/mementarGUI/mementargui.h b/include/mementar/graphical/mementarGUI/mementargui.h index d88d1e0..be5d781 100644 --- a/include/mementar/graphical/mementarGUI/mementargui.h +++ b/include/mementar/graphical/mementarGUI/mementargui.h @@ -61,6 +61,7 @@ public slots: void InstanceNameAddDelChangedSlot(const QString&); void InstanceNameChangedSlot(const QString&); void timesourceChangedSlot(int index); + void currentTimeEditingFinishedSlot(); void feederCallback(const std_msgs::String& msg); void feederAddSlot(); diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index af08ca9..7008473 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -40,6 +40,7 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect( this, SIGNAL( feederSetHtmlSignal(QString) ), ui->feeder_info_edittext, SLOT( setHtml(QString) ), Qt::BlockingQueuedConnection); QObject::connect( this, SIGNAL( setTimeSignal(QString) ), ui->static_current_time_editline, SLOT( setText(QString) ), Qt::BlockingQueuedConnection); + QObject::connect(ui->static_current_time_editline, SIGNAL( editingFinished() ), this, SLOT( currentTimeEditingFinishedSlot() )); } mementarGUI::~mementarGUI() @@ -307,6 +308,24 @@ void mementarGUI::timesourceChangedSlot(int index) } } +void mementarGUI::currentTimeEditingFinishedSlot() +{ + if(time_source_ == 2) + { + std::string time_str = ui->static_current_time_editline->text().toStdString(); + int time_int; + if(sscanf(time_str.c_str(), "%d", &time_int) == 1) + { + current_time_.store(ros::Time(time_int, 0), std::memory_order_release); + ui->static_result_editext->setText(QString::fromStdString("")); + } + else + { + ui->static_result_editext->setText(QString::fromStdString("impossible to convert " + time_str + " to integer")); + } + } +} + void mementarGUI::feederCallback(const std_msgs::String& msg) { feeder_notifications_ += "

    -" + msg.data + "

    "; @@ -342,7 +361,7 @@ void mementarGUI::feederAddSlot() { mementar::MementarAction msg; msg.name = subject; - msg.start_stamp = ros::Time::now(); + msg.start_stamp = current_time_; msg.end_stamp = ros::Time(0); actions_publishers_[instance_ns].publish(msg); } @@ -350,7 +369,7 @@ void mementarGUI::feederAddSlot() { mementar::StampedString msg; msg.data = "[ADD]" + subject + "|" + predicat + "|" + object; - msg.stamp = ros::Time::now(); + msg.stamp = current_time_; facts_publishers_[instance_ns].publish(msg); } } @@ -377,14 +396,14 @@ void mementarGUI::feederDelSlot() mementar::MementarAction msg; msg.name = subject; msg.start_stamp = ros::Time(0); - msg.end_stamp = ros::Time::now(); + msg.end_stamp = current_time_; actions_publishers_[instance_ns].publish(msg); } else { mementar::StampedString msg; msg.data = "[DEL]" + subject + "|" + predicat + "|" + object; - msg.stamp = ros::Time::now(); + msg.stamp = current_time_; facts_publishers_[instance_ns].publish(msg); } } From 94b6a59d0f6bb97eaa497f12c365782de4fd6f77 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 16:23:17 +0100 Subject: [PATCH 78/95] [FIX] mementarGUI draw and save eror message --- src/graphical/mementarGUI/mementargui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index 7008473..646e802 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -249,7 +249,7 @@ void mementarGUI::saveInstanceSlot() srv.request.param = ui->manager_save_path_editline->text().toStdString(); if(!client.call(srv)) - displayErrorInfo("mementar/manage client call failed"); + displayErrorInfo("mementar/actions client call failed"); else { if(srv.response.code == 4) @@ -269,7 +269,7 @@ void mementarGUI::drawInstanceSlot() srv.request.param = ui->manager_save_path_editline->text().toStdString(); if(!client.call(srv)) - displayErrorInfo("mementar/manage client call failed"); + displayErrorInfo("mementar/actions client call failed"); else { if(srv.response.code == 4) From 5e7a3808487592b71f956315a675af46c72ca0e8 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 16:49:52 +0100 Subject: [PATCH 79/95] [REFACT] service actions became service manage_instance --- src/API/TimelineManipulator.cpp | 2 +- src/RosInterface.cpp | 5 +---- src/graphical/mementarGUI/mementargui.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/API/TimelineManipulator.cpp b/src/API/TimelineManipulator.cpp index 4a7173c..85f52ba 100644 --- a/src/API/TimelineManipulator.cpp +++ b/src/API/TimelineManipulator.cpp @@ -12,7 +12,7 @@ TimelineManipulator::TimelineManipulator(ros::NodeHandle* n, const std::string& bool TimelineManipulator::waitInit(int32_t timeout) { - std::string servive_name = (name_ == "") ? "mementar/actions" : "mementar/actions/" + name_; + std::string servive_name = (name_ == "") ? "mementar/manage_instance" : "mementar/manage_instance/" + name_; return ros::service::waitForService(servive_name, timeout); } diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 2fb4a69..995c155 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -70,16 +70,13 @@ RosInterface::~RosInterface() void RosInterface::run() { - std::string service_name; - ros::Subscriber knowledge_subscriber = n_->subscribe(getTopicName("insert_fact"), 1000, &RosInterface::knowledgeCallback, this); ros::Subscriber stamped_knowledge_subscriber = n_->subscribe(getTopicName("insert_fact_stamped"), 1000, &RosInterface::stampedKnowledgeCallback, this); ros::Subscriber explanation_knowledge_subscriber = n_->subscribe(getTopicName("insert_fact_explanations"), 1000, &RosInterface::explanationKnowledgeCallback, this); ros::Subscriber action_knowledge_subscriber = n_->subscribe(getTopicName("insert_action"), 1000, &RosInterface::actionKnowledgeCallback, this); // Start up ROS service with callbacks - service_name = (name_ == "") ? "actions" : "actions/" + name_; - ros::ServiceServer service = n_->advertiseService(service_name, &RosInterface::actionsHandle, this); + ros::ServiceServer service = n_->advertiseService(getTopicName("manage_instance"), &RosInterface::actionsHandle, this); feeder_.setCallback([this](const Triplet& triplet){ this->occasions_.add(triplet); }); std::thread occasions_thread(&OccasionsManager::run, &occasions_); diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index 646e802..bf47d0a 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -241,7 +241,7 @@ void mementarGUI::deleteInstanceSlot() void mementarGUI::saveInstanceSlot() { - std::string service_name = (ui->manager_instance_name_editline->text().toStdString() == "") ? "mementar/actions" : "mementar/actions/" + ui->manager_instance_name_editline->text().toStdString(); + std::string service_name = (ui->manager_instance_name_editline->text().toStdString() == "") ? "mementar/manage_instance" : "mementar/manage_instance/" + ui->manager_instance_name_editline->text().toStdString(); ros::ServiceClient client = n_->serviceClient(service_name); mementar::MementarService srv; @@ -249,7 +249,7 @@ void mementarGUI::saveInstanceSlot() srv.request.param = ui->manager_save_path_editline->text().toStdString(); if(!client.call(srv)) - displayErrorInfo("mementar/actions client call failed"); + displayErrorInfo("mementar/manage_instance client call failed"); else { if(srv.response.code == 4) @@ -261,7 +261,7 @@ void mementarGUI::saveInstanceSlot() void mementarGUI::drawInstanceSlot() { - std::string service_name = (ui->manager_instance_name_editline->text().toStdString() == "") ? "mementar/actions" : "mementar/actions/" + ui->manager_instance_name_editline->text().toStdString(); + std::string service_name = (ui->manager_instance_name_editline->text().toStdString() == "") ? "mementar/manage_instance" : "mementar/manage_instance/" + ui->manager_instance_name_editline->text().toStdString(); ros::ServiceClient client = n_->serviceClient(service_name); mementar::MementarService srv; @@ -269,7 +269,7 @@ void mementarGUI::drawInstanceSlot() srv.request.param = ui->manager_save_path_editline->text().toStdString(); if(!client.call(srv)) - displayErrorInfo("mementar/actions client call failed"); + displayErrorInfo("mementar/manage_instance client call failed"); else { if(srv.response.code == 4) From 93ec679cfc613bf921c015a3178bd054e4607836 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 16:52:25 +0100 Subject: [PATCH 80/95] [FIX] ontoloGUI draw path line edit --- src/graphical/mementarGUI/mementargui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index bf47d0a..00da25d 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -266,7 +266,7 @@ void mementarGUI::drawInstanceSlot() mementar::MementarService srv; srv.request.action = "draw"; - srv.request.param = ui->manager_save_path_editline->text().toStdString(); + srv.request.param = ui->manager_draw_path_editline->text().toStdString(); if(!client.call(srv)) displayErrorInfo("mementar/manage_instance client call failed"); From c30d3d2e253de63f2e1765f555cb12e14d09152c Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 16:56:33 +0100 Subject: [PATCH 81/95] [REFACT] service manage became service manage_multi --- src/API/TimelinesManipulator.cpp | 2 +- src/graphical/mementarGUI/mementargui.cpp | 10 +++++----- src/nodes/mementar_multi.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/API/TimelinesManipulator.cpp b/src/API/TimelinesManipulator.cpp index 6f324b1..9aa60e3 100644 --- a/src/API/TimelinesManipulator.cpp +++ b/src/API/TimelinesManipulator.cpp @@ -17,7 +17,7 @@ TimelinesManipulator::~TimelinesManipulator() bool TimelinesManipulator::waitInit(int32_t timeout) { - return ros::service::waitForService("mementar/manage", timeout); + return ros::service::waitForService("mementar/manage_multi", timeout); } TimelineManipulator* TimelinesManipulator::operator[](const std::string& name) diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index 00da25d..abe1ad1 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -95,7 +95,7 @@ void mementarGUI::displayErrorInfo(const std::string& text) void mementarGUI::displayInstancesList() { - ros::ServiceClient client = n_->serviceClient("mementar/manage"); + ros::ServiceClient client = n_->serviceClient("mementar/manage_multi"); mementar::MementarService srv; srv.request.action = "list"; @@ -168,7 +168,7 @@ void mementarGUI::currentTabChangedSlot(int index) void mementarGUI::addInstanceSlot() { - ros::ServiceClient client = n_->serviceClient("mementar/manage"); + ros::ServiceClient client = n_->serviceClient("mementar/manage_multi"); mementar::MementarService srv; srv.request.action = "add"; @@ -204,7 +204,7 @@ void mementarGUI::addInstanceSlot() } if(!client.call(srv)) - displayErrorInfo("mementar/manage client call failed"); + displayErrorInfo("mementar/manage_multi client call failed"); else { start(); @@ -220,14 +220,14 @@ void mementarGUI::addInstanceSlot() void mementarGUI::deleteInstanceSlot() { - ros::ServiceClient client = n_->serviceClient("mementar/manage"); + ros::ServiceClient client = n_->serviceClient("mementar/manage_multi"); mementar::MementarService srv; srv.request.action = "delete"; srv.request.param = ui->manager_instance_name_editline->text().toStdString(); if(!client.call(srv)) - displayErrorInfo("mementar/manage client call failed"); + displayErrorInfo("mementar/manage_multi client call failed"); else { start(); diff --git a/src/nodes/mementar_multi.cpp b/src/nodes/mementar_multi.cpp index 5b81204..0cb6eb7 100644 --- a/src/nodes/mementar_multi.cpp +++ b/src/nodes/mementar_multi.cpp @@ -104,7 +104,7 @@ int main(int argc, char** argv) params.set(argc, argv); params.display(); - ros::ServiceServer service = n_->advertiseService("manage", managerHandle); + ros::ServiceServer service = n_->advertiseService("manage_multi", managerHandle); ros::spin(); From 08062523aea99e26b4ecc449ea538dca5d36515a Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 14 Dec 2020 17:11:22 +0100 Subject: [PATCH 82/95] [ADD] mementar full launch files --- launch/mementar_full.launch | 7 +++++++ launch/mementar_multi_full.launch | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 launch/mementar_full.launch create mode 100644 launch/mementar_multi_full.launch diff --git a/launch/mementar_full.launch b/launch/mementar_full.launch new file mode 100644 index 0000000..43ec468 --- /dev/null +++ b/launch/mementar_full.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/launch/mementar_multi_full.launch b/launch/mementar_multi_full.launch new file mode 100644 index 0000000..89d7d04 --- /dev/null +++ b/launch/mementar_multi_full.launch @@ -0,0 +1,7 @@ + + + + + + + From e6605c94bcf28907c584adaa847d14f8f8dff20a Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 15 Dec 2020 15:14:03 +0100 Subject: [PATCH 83/95] [UPDATE] rosInterface with actionHandle --- include/mementar/RosInterface.h | 16 +++- .../core/memGraphs/Graphs/ActionGraph.h | 14 ++- include/mementar/utils/String.h | 27 ++++++ src/RosInterface.cpp | 91 ++++++++++++++++++- src/core/memGraphs/Graphs/ActionGraph.cpp | 53 ++++++++++- src/test/graphs.cpp | 2 +- srv/MementarService.srv | 1 + 7 files changed, 194 insertions(+), 10 deletions(-) create mode 100644 include/mementar/utils/String.h diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index 60ac0f7..9776dde 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -23,6 +23,13 @@ namespace mementar { +struct param_t +{ + std::string base; + + std::string operator()() { return base; } +}; + class RosInterface { public: @@ -59,12 +66,17 @@ class RosInterface void explanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg); void actionKnowledgeCallback(const MementarAction::ConstPtr& msg); - bool actionsHandle(mementar::MementarService::Request &req, - mementar::MementarService::Response &res); + bool managerInstanceHandle(mementar::MementarService::Request &req, + mementar::MementarService::Response &res); + bool actionHandle(mementar::MementarService::Request &req, + mementar::MementarService::Response &res); void feedThread(); void removeUselessSpace(std::string& text); + void set2string(const std::unordered_set& word_set, std::string& result); + void set2vector(const std::unordered_set& word_set, std::vector& result); + param_t getParams(const std::string& param); std::string getTopicName(const std::string& topic_name) { diff --git a/include/mementar/core/memGraphs/Graphs/ActionGraph.h b/include/mementar/core/memGraphs/Graphs/ActionGraph.h index 79b6289..12953fc 100644 --- a/include/mementar/core/memGraphs/Graphs/ActionGraph.h +++ b/include/mementar/core/memGraphs/Graphs/ActionGraph.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace mementar { @@ -21,6 +22,13 @@ class ActionGraph : public Graph void add(Action* action); bool setEnd(const std::string& action_name, const SoftPoint& end); + bool exist(const std::string& action_name); + std::unordered_set getPending(); + bool isPending(const std::string& action_name); + SoftPoint::Ttime getStartStamp(const std::string& action_name); + SoftPoint::Ttime getEndStamp(const std::string& action_name); + SoftPoint::Ttime getDuration(const std::string& action_name); + std::vector get() { return all_actions_; @@ -32,11 +40,11 @@ class ActionGraph : public Graph return all_actions_; } - std::vector getPending(); - std::vector getPendingSafe() + std::vector getPendingPtr(); + std::vector getPendingPtrSafe() { std::shared_lock lock(Graph::mutex_); - return getPending(); + return getPendingPtr(); } Action* find(const std::string& action_name); diff --git a/include/mementar/utils/String.h b/include/mementar/utils/String.h new file mode 100644 index 0000000..36b82cc --- /dev/null +++ b/include/mementar/utils/String.h @@ -0,0 +1,27 @@ +#ifndef MEMENTAR_STRING_H +#define MEMENTAR_STRING_H + +#include +#include + +namespace mementar { + + inline std::vector split(const std::string& text, const std::string& delim) + { + std::vector res; + std::string tmp_text = text; + while(tmp_text.find(delim) != std::string::npos) + { + size_t pos = tmp_text.find(delim); + std::string part = tmp_text.substr(0, pos); + tmp_text = tmp_text.substr(pos + delim.size(), tmp_text.size() - pos - delim.size()); + if(part != "") + res.push_back(part); + } + res.push_back(tmp_text); + return res; + } + +} // namespace mementar + +#endif // MEMENTAR_STRING_H diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 995c155..2cfba2f 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -9,6 +9,8 @@ #include "mementar/graphical/Display.h" #include "mementar/graphical/timeline/TimelineDrawer.h" +#include "mementar/utils/String.h" + namespace mementar { @@ -76,7 +78,8 @@ void RosInterface::run() ros::Subscriber action_knowledge_subscriber = n_->subscribe(getTopicName("insert_action"), 1000, &RosInterface::actionKnowledgeCallback, this); // Start up ROS service with callbacks - ros::ServiceServer service = n_->advertiseService(getTopicName("manage_instance"), &RosInterface::actionsHandle, this); + ros::ServiceServer manage_instance_service = n_->advertiseService(getTopicName("manage_instance"), &RosInterface::managerInstanceHandle, this); + ros::ServiceServer action_service = n_->advertiseService(getTopicName("action"), &RosInterface::actionHandle, this); feeder_.setCallback([this](const Triplet& triplet){ this->occasions_.add(triplet); }); std::thread occasions_thread(&OccasionsManager::run, &occasions_); @@ -143,13 +146,14 @@ void RosInterface::actionKnowledgeCallback(const MementarAction::ConstPtr& msg) (msg->end_stamp.sec != 0) ? msg->end_stamp.sec : SoftPoint::default_time); } -bool RosInterface::actionsHandle(mementar::MementarService::Request &req, - mementar::MementarService::Response &res) +bool RosInterface::managerInstanceHandle(mementar::MementarService::Request &req, + mementar::MementarService::Response &res) { res.code = 0; removeUselessSpace(req.action); removeUselessSpace(req.param); + param_t params = getParams(req.param); /*if(req.action == "newSession") { @@ -171,6 +175,45 @@ bool RosInterface::actionsHandle(mementar::MementarService::Request &req, return true; } +bool RosInterface::actionHandle(mementar::MementarService::Request &req, + mementar::MementarService::Response &res) +{ + res.code = 0; + + removeUselessSpace(req.action); + removeUselessSpace(req.param); + param_t params = getParams(req.param); + + std::unordered_set set_res; + + if(req.action == "exist") + { + if(timeline_->actions.exist(params())) + res.values.push_back(params()); + } + else if(req.action == "getPending") + set_res = timeline_->actions.getPending(); + else if(req.action == "isPending") + { + if(timeline_->actions.isPending(params())) + res.values.push_back(params()); + } + else if(req.action == "getStartStamp") + res.time_value = ros::Time(timeline_->actions.getStartStamp(params())); + else if(req.action == "getEndStamp") + res.time_value = ros::Time(timeline_->actions.getEndStamp(params())); + else if(req.action == "getDuration") + res.time_value = ros::Time(timeline_->actions.getDuration(params())); + else + res.code = UNKNOW_ACTION; + + if(res.values.size() == 0) + set2vector(set_res, res.values); + + return true; +} + + /*************** * * Threads @@ -226,4 +269,46 @@ void RosInterface::removeUselessSpace(std::string& text) text.erase(text.size() - 1,1); } +void RosInterface::set2string(const std::unordered_set& word_set, std::string& result) +{ + for(const std::string& it : word_set) + result += it + " "; +} + +void RosInterface::set2vector(const std::unordered_set& word_set, std::vector& result) +{ + for(const std::string& it : word_set) + result.push_back(it); +} + +param_t RosInterface::getParams(const std::string& param) +{ + param_t parameters; + std::vector str_params = split(param, " "); + + if(str_params.size()) + parameters.base = str_params[0]; + + bool option_found = false; + for(size_t i = 1; i < str_params.size(); i++) + { + /*if((str_params[i] == "-i") || (str_params[i] == "--take_id")) + { + i++; + bool tmp = false; + if(str_params[i] == "true") + tmp = true; + + parameters.take_id = tmp; + option_found = true; + } + else if(option_found) + Display::warning("[WARNING] unknow parameter \"" + str_params[i] + "\""); + else*/ + parameters.base += " " + str_params[i]; + } + + return parameters; +} + } // namespace mementar diff --git a/src/core/memGraphs/Graphs/ActionGraph.cpp b/src/core/memGraphs/Graphs/ActionGraph.cpp index 6165250..266ce39 100644 --- a/src/core/memGraphs/Graphs/ActionGraph.cpp +++ b/src/core/memGraphs/Graphs/ActionGraph.cpp @@ -43,7 +43,58 @@ namespace mementar { } } - std::vector ActionGraph::getPending() + bool ActionGraph::exist(const std::string& action_name) + { + return (find(action_name) != nullptr); + } + + std::unordered_set ActionGraph::getPending() + { + std::unordered_set res; + for(auto act : pending_actions_) + res.insert(act.second->getName()); + return res; + } + + bool ActionGraph::isPending(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return false; + else + return action_branch->isPending(); + } + + SoftPoint::Ttime ActionGraph::getStartStamp(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return SoftPoint::default_time; + else + return action_branch->getStartFact()->getTime(); + } + + SoftPoint::Ttime ActionGraph::getEndStamp(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return SoftPoint::default_time; + else if(action_branch->isPending()) + return false; + else + return action_branch->getEndFact()->getTime(); + } + + SoftPoint::Ttime ActionGraph::getDuration(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return SoftPoint::default_time; + else + return action_branch->getDuration(); + } + + std::vector ActionGraph::getPendingPtr() { std::vector res; for(auto act : pending_actions_) diff --git a/src/test/graphs.cpp b/src/test/graphs.cpp index 8eca4ab..fa8113b 100644 --- a/src/test/graphs.cpp +++ b/src/test/graphs.cpp @@ -51,7 +51,7 @@ int main() action_graph.add(new mementar::Action("place_1", 7, mementar::SoftPoint(9, 10))); action_graph.add(new mementar::Action("pick_2", 12)); - auto pending = action_graph.getPendingSafe(); + auto pending = action_graph.getPendingPtrSafe(); for(auto action : pending) std::cout << action->getName() << " is a pending action" << std::endl; diff --git a/srv/MementarService.srv b/srv/MementarService.srv index d09c1cc..ab08770 100644 --- a/srv/MementarService.srv +++ b/srv/MementarService.srv @@ -3,4 +3,5 @@ string param time stamp --- string[] values +time time_value int16 code From 3e1520a078475757f4a0d9803b4a9a629a54d881 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 15 Dec 2020 17:26:15 +0100 Subject: [PATCH 84/95] [UPDATE] mementarGui with action tab --- .../graphical/mementarGUI/mementargui.h | 5 + src/graphical/mementarGUI/mementargui.cpp | 55 +++++++ ui/mementargui.ui | 135 ++++++++++++++++++ 3 files changed, 195 insertions(+) diff --git a/include/mementar/graphical/mementarGUI/mementargui.h b/include/mementar/graphical/mementarGUI/mementargui.h index be5d781..dc1c397 100644 --- a/include/mementar/graphical/mementarGUI/mementargui.h +++ b/include/mementar/graphical/mementarGUI/mementargui.h @@ -50,6 +50,11 @@ class mementarGUI : public QMainWindow void updateTime(); public slots: + void actionButtonHoverEnterSlot(); + void actionButtonHoverLeaveSlot(); + + void actionButtonClickedSlot(); + void nameEditingFinishedSlot(); void currentTabChangedSlot(int); diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index abe1ad1..c669013 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -21,6 +21,26 @@ mementarGUI::mementarGUI(QWidget *parent) : { ui->setupUi(this); + QObject::connect(ui->action_exist_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_exist_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getPending_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getPending_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_isPending_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_isPending_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getStartStamp_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getStartStamp_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getEndStamp_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getEndStamp_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getDuration_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getDuration_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + + QObject::connect(ui->action_exist_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_isPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getStartStamp_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getEndStamp_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getDuration_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->manager_refresh_button, SIGNAL(clicked()),this, SLOT(displayInstancesListSlot())); QObject::connect(ui->manager_add_instance_button, SIGNAL(clicked()),this, SLOT(addInstanceSlot())); QObject::connect(ui->manager_delete_instance_button, SIGNAL(clicked()),this, SLOT(deleteInstanceSlot())); @@ -78,6 +98,41 @@ void mementarGUI::start() ui->static_info_area->setHtml(html); } +void mementarGUI::actionButtonHoverEnterSlot() +{ + ui->action_description_textedit->setText(dynamic_cast(sender())->whatsThis()); +} + +void mementarGUI::actionButtonHoverLeaveSlot() +{ + ui->action_description_textedit->setText(""); +} + +void mementarGUI::actionButtonClickedSlot() +{ + std::string service_name = (ui->static_instance_name_editline->text().toStdString() == "") ? "mementar/action" : "mementar/action/" + ui->static_instance_name_editline->text().toStdString(); + ros::ServiceClient client = n_->serviceClient(service_name); + + mementar::MementarService srv; + srv.request.action = dynamic_cast(sender())->text().toStdString(); + srv.request.param = ui->action_parameter_editline->text().toStdString(); + QString text = dynamic_cast(sender())->text() + " : " + ui->action_parameter_editline->text(); + ui->action_description_textedit->setText(text); + + if(!client.call(srv)) + displayErrorInfo(service_name + " client call failed"); + else + { + start(); + std::string res; + if(srv.response.values.size()) + res = vector2string(srv.response.values); + else if(srv.response.time_value.sec != 0) + res = std::to_string(srv.response.time_value.sec); + ui->static_result_editext->setText(QString::fromStdString(res)); + } +} + void mementarGUI::nameEditingFinishedSlot() { diff --git a/ui/mementargui.ui b/ui/mementargui.ui index 9910c00..f5db25d 100644 --- a/ui/mementargui.ui +++ b/ui/mementargui.ui @@ -23,6 +23,141 @@ 0 + + + + Action + + + + + + + + + Parameter + + + + + + + <html><head/><body><p> Enter your parameters here.</p></body></html> + + + + + + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">exist</span> allows you to test whether the action provided in parameter exists in this timeline</p></body></html> + + + exist + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getPending</span> will give you all the pending actions (i.e. started but not yet finished)</p></body></html> + + + getPending + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">isPending</span> allows you to test whether the action provided in parameter is pending (i.e. started but not yet finished)</p></body></html> + + + isPending + + + + + + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getStartStamp</span> returns the timestamp of the start of the action provided in parameter</p></body></html> + + + getStartStamp + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getEndStamp</span> returns the timestamp of the end of the action provided in parameter</p></body></html> + + + getEndStamp + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getDuration</span> returns the duraction of the action provided in parameter</p></body></html> + + + getDuration + + + + + + + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + true + + + Qt::NoTextInteraction + + + + + + + + From c29f7ab312a2210f82c092c9f1783e7a401e7740 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Tue, 15 Dec 2020 18:20:28 +0100 Subject: [PATCH 85/95] [UPDATE] actionGraph getStartFact, getEndFact and getFactsDuring --- .../memGraphs/ExtendedBtree/EventLinkedLeaf.h | 8 +++ .../core/memGraphs/Graphs/ActionGraph.h | 3 + src/RosInterface.cpp | 14 +++++ src/core/memGraphs/Graphs/ActionGraph.cpp | 60 ++++++++++++++++++- src/graphical/mementarGUI/mementargui.cpp | 9 +++ ui/mementargui.ui | 44 ++++++++++++++ 6 files changed, 137 insertions(+), 1 deletion(-) diff --git a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h index 1005cc0..0d584d3 100644 --- a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h +++ b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h @@ -25,6 +25,14 @@ class LinkedEvent SelfType* getNext() { return next_elem_; } SelfType* getPrevious() { return prev_elem_; } + Tleaf* getLeaf() + { + if(leaf_ == nullptr) + return nullptr; + else + return static_cast(leaf_); + } + Tleaf* getNextLeaf() { if(leaf_ == nullptr) diff --git a/include/mementar/core/memGraphs/Graphs/ActionGraph.h b/include/mementar/core/memGraphs/Graphs/ActionGraph.h index 12953fc..326f764 100644 --- a/include/mementar/core/memGraphs/Graphs/ActionGraph.h +++ b/include/mementar/core/memGraphs/Graphs/ActionGraph.h @@ -28,6 +28,9 @@ class ActionGraph : public Graph SoftPoint::Ttime getStartStamp(const std::string& action_name); SoftPoint::Ttime getEndStamp(const std::string& action_name); SoftPoint::Ttime getDuration(const std::string& action_name); + std::string getStartFact(const std::string& action_name); + std::string getEndFact(const std::string& action_name); + std::unordered_set getFactsDuring(const std::string& action_name); std::vector get() { diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 2cfba2f..e2b9f54 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -204,6 +204,20 @@ bool RosInterface::actionHandle(mementar::MementarService::Request &req, res.time_value = ros::Time(timeline_->actions.getEndStamp(params())); else if(req.action == "getDuration") res.time_value = ros::Time(timeline_->actions.getDuration(params())); + else if(req.action == "getStartFact") + { + auto fact_name = timeline_->actions.getStartFact(params()); + if(fact_name != "") + res.values.push_back(fact_name); + } + else if(req.action == "getEndFact") + { + auto fact_name = timeline_->actions.getEndFact(params()); + if(fact_name != "") + res.values.push_back(fact_name); + } + else if(req.action == "getFactsDuring") + set_res = timeline_->actions.getFactsDuring(params()); else res.code = UNKNOW_ACTION; diff --git a/src/core/memGraphs/Graphs/ActionGraph.cpp b/src/core/memGraphs/Graphs/ActionGraph.cpp index 266ce39..f64eb10 100644 --- a/src/core/memGraphs/Graphs/ActionGraph.cpp +++ b/src/core/memGraphs/Graphs/ActionGraph.cpp @@ -80,7 +80,7 @@ namespace mementar { if(action_branch == nullptr) return SoftPoint::default_time; else if(action_branch->isPending()) - return false; + return SoftPoint::default_time; else return action_branch->getEndFact()->getTime(); } @@ -94,6 +94,64 @@ namespace mementar { return action_branch->getDuration(); } + std::string ActionGraph::getStartFact(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return ""; + else + return action_branch->getStartFact()->getValue(); + } + + std::string ActionGraph::getEndFact(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return ""; + else if(action_branch->isPending()) + return ""; + else + return action_branch->getEndFact()->getValue(); + } + + std::unordered_set ActionGraph::getFactsDuring(const std::string& action_name) + { + std::unordered_set res; + auto action_branch = find(action_name); + if(action_branch != nullptr) + { + auto start_fact = action_branch->getStartFact(); + auto leaf = start_fact->getLeaf()->getNextLeaf(); + if(action_branch->isPending()) + { + while(leaf != nullptr) + { + auto data = leaf->getData(); + for(auto& fact : data) + res.insert(fact->getValue()); + leaf = leaf->getNextLeaf(); + } + } + else + { + auto end_fact = action_branch->getEndFact(); + while(leaf != nullptr) + { + auto data = leaf->getData(); + if(data.size()) + if(data[0] >= end_fact) + break; + + for(auto& fact : data) + res.insert(fact->getValue()); + leaf = leaf->getNextLeaf(); + } + } + } + + return res; + } + std::vector ActionGraph::getPendingPtr() { std::vector res; diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index c669013..48f197a 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -33,6 +33,12 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->action_getEndStamp_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); QObject::connect(ui->action_getDuration_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); QObject::connect(ui->action_getDuration_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getStartFact_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getStartFact_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getEndFact_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getEndFact_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getFactsDuring_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getFactsDuring_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); QObject::connect(ui->action_exist_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); @@ -40,6 +46,9 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->action_getStartStamp_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getEndStamp_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getDuration_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getStartFact_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getEndFact_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getFactsDuring_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->manager_refresh_button, SIGNAL(clicked()),this, SLOT(displayInstancesListSlot())); QObject::connect(ui->manager_add_instance_button, SIGNAL(clicked()),this, SLOT(addInstanceSlot())); diff --git a/ui/mementargui.ui b/ui/mementargui.ui index f5db25d..f4121be 100644 --- a/ui/mementargui.ui +++ b/ui/mementargui.ui @@ -137,6 +137,50 @@ + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getStartFact</span> returns the identifier of the fact representing the start of the action provided as a parameter</p></body></html> + + + getStartFact + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getEndFact</span> returns the identifier of the fact representing the end of the action provided as a parameter</p></body></html> + + + getEndFact + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getFactsDuring</span> returns the identifiers of all the facts that took place during the execution of the action provided in parameter</p></body></html> + + + getFactsDuring + + + + + + From ce6f1819e09ef407bcb4d5ac9199f6e89739af4d Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 16 Dec 2020 10:26:24 +0100 Subject: [PATCH 86/95] [ADD] factHandle to the rosInterface --- include/mementar/RosInterface.h | 2 + .../core/memGraphs/Graphs/FactGraph.h | 6 +++ src/RosInterface.cpp | 42 +++++++++++++++++++ src/core/memGraphs/Graphs/FactGraph.cpp | 39 +++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index 9776dde..c968ae1 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -70,6 +70,8 @@ class RosInterface mementar::MementarService::Response &res); bool actionHandle(mementar::MementarService::Request &req, mementar::MementarService::Response &res); + bool factHandle(mementar::MementarService::Request &req, + mementar::MementarService::Response &res); void feedThread(); diff --git a/include/mementar/core/memGraphs/Graphs/FactGraph.h b/include/mementar/core/memGraphs/Graphs/FactGraph.h index e5c1631..8eed9ea 100644 --- a/include/mementar/core/memGraphs/Graphs/FactGraph.h +++ b/include/mementar/core/memGraphs/Graphs/FactGraph.h @@ -17,6 +17,11 @@ class FactGraph : public Graph void add(ContextualizedFact* fact); + bool exist(const std::string& fact_id); + bool isActionPart(const std::string& fact_id); + std::string getActionPart(const std::string& fact_id); + std::string getData(const std::string& fact_id); + std::vector get() { return all_facts_; @@ -31,6 +36,7 @@ class FactGraph : public Graph ElBTree* getTimeline() { return &timeline_; } + ContextualizedFact* find(const std::string& fact_id); ContextualizedFact* findRecent(const Triplet& triplet, SoftPoint::Ttime until = SoftPoint::default_time); private: diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index e2b9f54..c350d6d 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -80,6 +80,7 @@ void RosInterface::run() // Start up ROS service with callbacks ros::ServiceServer manage_instance_service = n_->advertiseService(getTopicName("manage_instance"), &RosInterface::managerInstanceHandle, this); ros::ServiceServer action_service = n_->advertiseService(getTopicName("action"), &RosInterface::actionHandle, this); + ros::ServiceServer fact_service = n_->advertiseService(getTopicName("fact"), &RosInterface::factHandle, this); feeder_.setCallback([this](const Triplet& triplet){ this->occasions_.add(triplet); }); std::thread occasions_thread(&OccasionsManager::run, &occasions_); @@ -227,6 +228,47 @@ bool RosInterface::actionHandle(mementar::MementarService::Request &req, return true; } +bool RosInterface::factHandle(mementar::MementarService::Request &req, + mementar::MementarService::Response &res) +{ + res.code = 0; + + removeUselessSpace(req.action); + removeUselessSpace(req.param); + param_t params = getParams(req.param); + + std::unordered_set set_res; + + if(req.action == "exist") + { + if(timeline_->facts.exist(params())) + res.values.push_back(params()); + } + else if(req.action == "isActionPart") + { + if(timeline_->facts.isActionPart(params())) + res.values.push_back(params()); + } + else if(req.action == "getActionPart") + { + auto action_name = timeline_->facts.getActionPart(params()); + if(action_name != "") + res.values.push_back(action_name); + } + else if(req.action == "getData") + { + auto fact_data = timeline_->facts.getData(params()); + if(fact_data != "") + res.values.push_back(fact_data); + } + else + res.code = UNKNOW_ACTION; + + if(res.values.size() == 0) + set2vector(set_res, res.values); + + return true; +} /*************** * diff --git a/src/core/memGraphs/Graphs/FactGraph.cpp b/src/core/memGraphs/Graphs/FactGraph.cpp index 8f63718..6eb15d4 100644 --- a/src/core/memGraphs/Graphs/FactGraph.cpp +++ b/src/core/memGraphs/Graphs/FactGraph.cpp @@ -17,6 +17,45 @@ void FactGraph::add(ContextualizedFact* fact) timeline_.insert(fact->getTime(), fact); } +bool FactGraph::exist(const std::string& fact_id) +{ + return (find(fact_id) != nullptr); +} + +bool FactGraph::isActionPart(const std::string& fact_id) +{ + auto fact = find(fact_id); + if(fact == nullptr) + return false; + else + return fact->isPartOfAction(); +} + +std::string FactGraph::getActionPart(const std::string& fact_id) +{ + auto fact = find(fact_id); + if(fact == nullptr) + return ""; + else if(fact->isPartOfAction()) + return fact->getActionPart()->getValue(); + else + return ""; +} + +std::string FactGraph::getData(const std::string& fact_id) +{ + auto fact = find(fact_id); + if(fact == nullptr) + return ""; + else + return fact->getData(); +} + +ContextualizedFact* FactGraph::find(const std::string& fact_id) +{ + return container_.find(fact_id); +} + ContextualizedFact* FactGraph::findRecent(const Triplet& triplet, SoftPoint::Ttime until) { for(BplusLeaf* leaf = timeline_.getLast(); leaf != nullptr; leaf = leaf->getPreviousLeaf()) From 884b7972fef0423d35738f729cae4cd6c875bb64 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 16 Dec 2020 11:35:34 +0100 Subject: [PATCH 87/95] [FIX] action getFactsDuring --- src/core/memGraphs/Graphs/ActionGraph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/memGraphs/Graphs/ActionGraph.cpp b/src/core/memGraphs/Graphs/ActionGraph.cpp index f64eb10..a2ea62e 100644 --- a/src/core/memGraphs/Graphs/ActionGraph.cpp +++ b/src/core/memGraphs/Graphs/ActionGraph.cpp @@ -139,7 +139,7 @@ namespace mementar { { auto data = leaf->getData(); if(data.size()) - if(data[0] >= end_fact) + if(data[0]->getTime() >= end_fact->getTime()) break; for(auto& fact : data) From f468a583fd230285e7707330a67b5016ed144d96 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 16 Dec 2020 11:36:37 +0100 Subject: [PATCH 88/95] [UPDATE] fact getStamp --- include/mementar/core/memGraphs/Graphs/FactGraph.h | 1 + src/RosInterface.cpp | 2 ++ src/core/memGraphs/Graphs/FactGraph.cpp | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/include/mementar/core/memGraphs/Graphs/FactGraph.h b/include/mementar/core/memGraphs/Graphs/FactGraph.h index 8eed9ea..202c7c4 100644 --- a/include/mementar/core/memGraphs/Graphs/FactGraph.h +++ b/include/mementar/core/memGraphs/Graphs/FactGraph.h @@ -21,6 +21,7 @@ class FactGraph : public Graph bool isActionPart(const std::string& fact_id); std::string getActionPart(const std::string& fact_id); std::string getData(const std::string& fact_id); + SoftPoint::Ttime getStamp(const std::string& fact_id); std::vector get() { diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index c350d6d..f68fd5e 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -261,6 +261,8 @@ bool RosInterface::factHandle(mementar::MementarService::Request &req, if(fact_data != "") res.values.push_back(fact_data); } + else if(req.action == "getStamp") + res.time_value = ros::Time(timeline_->facts.getStamp(params())); else res.code = UNKNOW_ACTION; diff --git a/src/core/memGraphs/Graphs/FactGraph.cpp b/src/core/memGraphs/Graphs/FactGraph.cpp index 6eb15d4..357b86b 100644 --- a/src/core/memGraphs/Graphs/FactGraph.cpp +++ b/src/core/memGraphs/Graphs/FactGraph.cpp @@ -51,6 +51,15 @@ std::string FactGraph::getData(const std::string& fact_id) return fact->getData(); } +SoftPoint::Ttime FactGraph::getStamp(const std::string& fact_id) +{ + auto fact = find(fact_id); + if(fact == nullptr) + return SoftPoint::default_time; + else + return fact->getTime(); +} + ContextualizedFact* FactGraph::find(const std::string& fact_id) { return container_.find(fact_id); From 2d595732bc194a681e8eaaba027e136700e87c32 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 16 Dec 2020 11:36:58 +0100 Subject: [PATCH 89/95] [ADD] mementarGUI fact tab --- .../graphical/mementarGUI/mementargui.h | 3 + src/graphical/mementarGUI/mementargui.cpp | 52 ++++++++ ui/mementargui.ui | 122 ++++++++++++++++++ 3 files changed, 177 insertions(+) diff --git a/include/mementar/graphical/mementarGUI/mementargui.h b/include/mementar/graphical/mementarGUI/mementargui.h index dc1c397..d8d5510 100644 --- a/include/mementar/graphical/mementarGUI/mementargui.h +++ b/include/mementar/graphical/mementarGUI/mementargui.h @@ -52,8 +52,11 @@ class mementarGUI : public QMainWindow public slots: void actionButtonHoverEnterSlot(); void actionButtonHoverLeaveSlot(); + void factButtonHoverEnterSlot(); + void factButtonHoverLeaveSlot(); void actionButtonClickedSlot(); + void factButtonClickedSlot(); void nameEditingFinishedSlot(); void currentTabChangedSlot(int); diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index 48f197a..f5fd88d 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -40,6 +40,17 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->action_getFactsDuring_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); QObject::connect(ui->action_getFactsDuring_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->fact_exist_button, SIGNAL(hoverEnter()),this, SLOT(factButtonHoverEnterSlot())); + QObject::connect(ui->fact_exist_button, SIGNAL(hoverLeave()),this, SLOT(factButtonHoverLeaveSlot())); + QObject::connect(ui->fact_getData_button, SIGNAL(hoverEnter()),this, SLOT(factButtonHoverEnterSlot())); + QObject::connect(ui->fact_getData_button, SIGNAL(hoverLeave()),this, SLOT(factButtonHoverLeaveSlot())); + QObject::connect(ui->fact_getActionPart_button, SIGNAL(hoverEnter()),this, SLOT(factButtonHoverEnterSlot())); + QObject::connect(ui->fact_getActionPart_button, SIGNAL(hoverLeave()),this, SLOT(factButtonHoverLeaveSlot())); + QObject::connect(ui->fact_isActionPart_button, SIGNAL(hoverEnter()),this, SLOT(factButtonHoverEnterSlot())); + QObject::connect(ui->fact_isActionPart_button, SIGNAL(hoverLeave()),this, SLOT(factButtonHoverLeaveSlot())); + QObject::connect(ui->fact_getStamp_button, SIGNAL(hoverEnter()),this, SLOT(factButtonHoverEnterSlot())); + QObject::connect(ui->fact_getStamp_button, SIGNAL(hoverLeave()),this, SLOT(factButtonHoverLeaveSlot())); + QObject::connect(ui->action_exist_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_isPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); @@ -50,6 +61,12 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->action_getEndFact_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getFactsDuring_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->fact_exist_button, SIGNAL(clicked()),this, SLOT(factButtonClickedSlot())); + QObject::connect(ui->fact_getData_button, SIGNAL(clicked()),this, SLOT(factButtonClickedSlot())); + QObject::connect(ui->fact_getActionPart_button, SIGNAL(clicked()),this, SLOT(factButtonClickedSlot())); + QObject::connect(ui->fact_isActionPart_button, SIGNAL(clicked()),this, SLOT(factButtonClickedSlot())); + QObject::connect(ui->fact_getStamp_button, SIGNAL(clicked()),this, SLOT(factButtonClickedSlot())); + QObject::connect(ui->manager_refresh_button, SIGNAL(clicked()),this, SLOT(displayInstancesListSlot())); QObject::connect(ui->manager_add_instance_button, SIGNAL(clicked()),this, SLOT(addInstanceSlot())); QObject::connect(ui->manager_delete_instance_button, SIGNAL(clicked()),this, SLOT(deleteInstanceSlot())); @@ -117,6 +134,16 @@ void mementarGUI::actionButtonHoverLeaveSlot() ui->action_description_textedit->setText(""); } +void mementarGUI::factButtonHoverEnterSlot() +{ + ui->fact_description_textedit->setText(dynamic_cast(sender())->whatsThis()); +} + +void mementarGUI::factButtonHoverLeaveSlot() +{ + ui->fact_description_textedit->setText(""); +} + void mementarGUI::actionButtonClickedSlot() { std::string service_name = (ui->static_instance_name_editline->text().toStdString() == "") ? "mementar/action" : "mementar/action/" + ui->static_instance_name_editline->text().toStdString(); @@ -142,6 +169,31 @@ void mementarGUI::actionButtonClickedSlot() } } +void mementarGUI::factButtonClickedSlot() +{ + std::string service_name = (ui->static_instance_name_editline->text().toStdString() == "") ? "mementar/fact" : "mementar/fact/" + ui->static_instance_name_editline->text().toStdString(); + ros::ServiceClient client = n_->serviceClient(service_name); + + mementar::MementarService srv; + srv.request.action = dynamic_cast(sender())->text().toStdString(); + srv.request.param = ui->fact_parameter_editline->text().toStdString(); + QString text = dynamic_cast(sender())->text() + " : " + ui->fact_parameter_editline->text(); + ui->fact_description_textedit->setText(text); + + if(!client.call(srv)) + displayErrorInfo(service_name + " client call failed"); + else + { + start(); + std::string res; + if(srv.response.values.size()) + res = vector2string(srv.response.values); + else if(srv.response.time_value.sec != 0) + res = std::to_string(srv.response.time_value.sec); + ui->static_result_editext->setText(QString::fromStdString(res)); + } +} + void mementarGUI::nameEditingFinishedSlot() { diff --git a/ui/mementargui.ui b/ui/mementargui.ui index f4121be..02c8f73 100644 --- a/ui/mementargui.ui +++ b/ui/mementargui.ui @@ -202,6 +202,128 @@ + + + + Fact + + + + + + + + + Parameter + + + + + + + <html><head/><body><p> Enter your parameters here.</p></body></html> + + + + + + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">exist</span> allows you to test whether the fact (fact id) provided in parameter exists in this timeline</p></body></html> + + + exist + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getData</span> returns the fact as a triplet for the fact (fact id) provided in parameter</p></body></html> + + + getData + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getStamp</span> returns the timestamp for the fact (fact id) provided in parameter</p></body></html> + + + getStamp + + + + + + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">isActionPart</span> allows you to test whether the fact (fact id) provided in parameter is part of an action.</p></body></html> + + + isActionPart + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getActionPart</span> returns the action to which the fact (fact id) provided in parameter refers</p></body></html> + + + getActionPart + + + + + + + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + true + + + Qt::NoTextInteraction + + + + + + + + From efc78160846870bfb80ccc0bd8147f09a92abb4b Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 21 Dec 2020 09:06:46 +0100 Subject: [PATCH 90/95] [UPDATE] RosInterface with ontologenius' subscribers --- include/mementar/RosInterface.h | 12 ++++++++++++ src/RosInterface.cpp | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index c968ae1..b269418 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -65,6 +65,8 @@ class RosInterface void stampedKnowledgeCallback(const StampedString::ConstPtr& msg); void explanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg); void actionKnowledgeCallback(const MementarAction::ConstPtr& msg); + void ontoStampedKnowledgeCallback(const StampedString::ConstPtr& msg); + void ontoExplanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg); bool managerInstanceHandle(mementar::MementarService::Request &req, mementar::MementarService::Response &res); @@ -89,6 +91,16 @@ class RosInterface { return (onto_name == "") ? "/mementar/" + topic_name : "/mementar/" + topic_name + "/" + onto_name; } + + std::string getOntoTopicName(const std::string& topic_name) + { + return getOntoTopicName(topic_name, name_); + } + + std::string getOntoTopicName(const std::string& topic_name, const std::string& onto_name) + { + return (onto_name == "") ? "/ontologenius/" + topic_name : "/ontologenius/" + topic_name + "/" + onto_name; + } }; } // namespace mementar diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index f68fd5e..371f684 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -76,6 +76,8 @@ void RosInterface::run() ros::Subscriber stamped_knowledge_subscriber = n_->subscribe(getTopicName("insert_fact_stamped"), 1000, &RosInterface::stampedKnowledgeCallback, this); ros::Subscriber explanation_knowledge_subscriber = n_->subscribe(getTopicName("insert_fact_explanations"), 1000, &RosInterface::explanationKnowledgeCallback, this); ros::Subscriber action_knowledge_subscriber = n_->subscribe(getTopicName("insert_action"), 1000, &RosInterface::actionKnowledgeCallback, this); + ros::Subscriber onto_stamped_knowledge_subscriber = n_->subscribe(getOntoTopicName("insert_echo"), 1000, &RosInterface::ontoStampedKnowledgeCallback, this); + ros::Subscriber onto_explanation_knowledge_subscriber = n_->subscribe(getOntoTopicName("insert_explanations"), 1000, &RosInterface::ontoExplanationKnowledgeCallback, this); // Start up ROS service with callbacks ros::ServiceServer manage_instance_service = n_->advertiseService(getTopicName("manage_instance"), &RosInterface::managerInstanceHandle, this); @@ -147,6 +149,22 @@ void RosInterface::actionKnowledgeCallback(const MementarAction::ConstPtr& msg) (msg->end_stamp.sec != 0) ? msg->end_stamp.sec : SoftPoint::default_time); } +void RosInterface::ontoStampedKnowledgeCallback(const StampedString::ConstPtr& msg) +{ + feeder_.storeFact(msg->data, msg->stamp.sec); +} + +void RosInterface::ontoExplanationKnowledgeCallback(const MementarExplanation::ConstPtr& msg) +{ + feeder_.storeFact(msg->fact, msg->cause); +} + +/*************** +* +* Services +* +****************/ + bool RosInterface::managerInstanceHandle(mementar::MementarService::Request &req, mementar::MementarService::Response &res) { From dba5653991c43dd008fa5770bc8fd407ac69d13c Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 21 Dec 2020 09:10:43 +0100 Subject: [PATCH 91/95] [UPDATE] mementar_ontologenius launch files --- launch/mementar_ontologenius.launch | 23 ++++++++++++++--------- launch/mementar_ontologenius_multi.launch | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 launch/mementar_ontologenius_multi.launch diff --git a/launch/mementar_ontologenius.launch b/launch/mementar_ontologenius.launch index fc1dd99..c8cc543 100644 --- a/launch/mementar_ontologenius.launch +++ b/launch/mementar_ontologenius.launch @@ -1,18 +1,23 @@ - - - + + + + + + + - - - + + + + - - - + + + diff --git a/launch/mementar_ontologenius_multi.launch b/launch/mementar_ontologenius_multi.launch new file mode 100644 index 0000000..f2c9885 --- /dev/null +++ b/launch/mementar_ontologenius_multi.launch @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + From 191533f46ae6ebf784a3b00577ce89b2d190e7fe Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 21 Dec 2020 10:14:49 +0100 Subject: [PATCH 92/95] [REFACT] mementarGUI darker style --- resources/darkstyle/darkstyle.qss | 32 ++++++++++++------------- src/graphical/mementarGUI/DarkStyle.cpp | 12 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/resources/darkstyle/darkstyle.qss b/resources/darkstyle/darkstyle.qss index 7181d5a..d72ba69 100644 --- a/resources/darkstyle/darkstyle.qss +++ b/resources/darkstyle/darkstyle.qss @@ -5,11 +5,11 @@ QToolTip{ border-radius:4px; } QStatusBar{ - background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); color:palette(mid); } QMenuBar{ - background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); border-bottom:2px solid rgba(25,25,25,75); } QMenuBar::item{ @@ -44,7 +44,7 @@ QMenu::item:selected{ background:palette(highlight); } QMenu::icon:checked{ - background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); border:1px solid palette(highlight); border-radius:2px; } @@ -75,20 +75,20 @@ QMenu::indicator:exclusive:unchecked{ padding-left:2px; } QToolBar::top{ - background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); - border-bottom:3px solid qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); + border-bottom:3px solid qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); } QToolBar::bottom{ - background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); - border-top:3px solid qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); + border-top:3px solid qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); } QToolBar::left{ - background-color:qlineargradient(x1:0,y1:0,x2:1,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); - border-right:3px solid qlineargradient(x1:0,y1:0,x2:1,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:0,x2:1,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); + border-right:3px solid qlineargradient(x1:0,y1:0,x2:1,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); } QToolBar::right{ - background-color:qlineargradient(x1:1,y1:0,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); - border-left:3px solid qlineargradient(x1:1,y1:0,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:1,y1:0,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); + border-left:3px solid qlineargradient(x1:1,y1:0,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); } QMainWindow::separator{ width:6px; @@ -106,7 +106,7 @@ QMainWindow::separator:hover,QSplitter::handle:hover{ } QDockWidget::title{ padding:4px; - background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); border:1px solid rgba(25,25,25,75); border-bottom:2px solid rgba(25,25,25,75); } @@ -141,7 +141,7 @@ QGroupBox::title{ subcontrol-position:left top; padding:4px 6px; margin-left:3px; - background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); border:1px solid rgba(25,25,25,75); border-top-left-radius:4px; border-top-right-radius:4px; @@ -161,13 +161,13 @@ QTabBar{ } QTabBar::tab{ padding:4px 6px; - background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); border:1px solid rgba(25,25,25,75); border-top-left-radius:4px; border-top-right-radius:4px; } QTabBar::tab:selected,QTabBar::tab:hover{ - background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(53,53,53,127),stop:1 rgba(66,66,66,50%)); + background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(33,37,43,127),stop:1 rgba(66,66,66,50%)); border-bottom-color:rgba(66,66,66,75%); } QTabBar::tab:selected{ @@ -236,7 +236,7 @@ QTreeView, QTableView{ } QTreeView QHeaderView::section, QTableView QHeaderView::section{ /*height:24px;*/ - background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); + background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(33,37,43,75)); border-style:none; border-bottom:1px solid palette(dark); padding-left:5px; diff --git a/src/graphical/mementarGUI/DarkStyle.cpp b/src/graphical/mementarGUI/DarkStyle.cpp index d1f5978..ac3cbb9 100644 --- a/src/graphical/mementarGUI/DarkStyle.cpp +++ b/src/graphical/mementarGUI/DarkStyle.cpp @@ -38,23 +38,23 @@ QStyle *DarkStyle::baseStyle() const void DarkStyle::polish(QPalette &palette) { // modify palette to dark - palette.setColor(QPalette::Window,QColor(53,53,53)); + palette.setColor(QPalette::Window,QColor(33,37,43)); palette.setColor(QPalette::WindowText,Qt::white); palette.setColor(QPalette::Disabled,QPalette::WindowText,QColor(127,127,127)); - palette.setColor(QPalette::Base,QColor(42,42,42)); + palette.setColor(QPalette::Base,QColor(27,29,35)); palette.setColor(QPalette::AlternateBase,QColor(66,66,66)); palette.setColor(QPalette::ToolTipBase,Qt::white); - palette.setColor(QPalette::ToolTipText,QColor(53,53,53)); + palette.setColor(QPalette::ToolTipText,QColor(33,37,43)); palette.setColor(QPalette::Text,Qt::white); palette.setColor(QPalette::Disabled,QPalette::Text,QColor(127,127,127)); palette.setColor(QPalette::Dark,QColor(35,35,35)); palette.setColor(QPalette::Shadow,QColor(20,20,20)); - palette.setColor(QPalette::Button,QColor(53,53,53)); + palette.setColor(QPalette::Button,QColor(33,37,43)); palette.setColor(QPalette::ButtonText,Qt::white); palette.setColor(QPalette::Disabled,QPalette::ButtonText,QColor(127,127,127)); palette.setColor(QPalette::BrightText,Qt::red); - palette.setColor(QPalette::Link,QColor(42,130,218)); - palette.setColor(QPalette::Highlight,QColor(42,130,218)); + palette.setColor(QPalette::Link,QColor(85,116,207)); + palette.setColor(QPalette::Highlight,QColor(85,116,207)); palette.setColor(QPalette::Disabled,QPalette::Highlight,QColor(80,80,80)); palette.setColor(QPalette::HighlightedText,Qt::white); palette.setColor(QPalette::Disabled,QPalette::HighlightedText,QColor(127,127,127)); From 6d2371c7e6b05d02fee5af056e728565626bd3ac Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 21 Dec 2020 10:18:22 +0100 Subject: [PATCH 93/95] [FIX] remove no interaction property to mementarGUI instance list text edit widget --- ui/mementargui.ui | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui/mementargui.ui b/ui/mementargui.ui index 02c8f73..ca417e8 100644 --- a/ui/mementargui.ui +++ b/ui/mementargui.ui @@ -681,9 +681,6 @@ 1 - - Qt::NoTextInteraction - From 84d6e9bedc869ec4b25a893ad16c172b17cb2bab Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 21 Dec 2020 11:08:52 +0100 Subject: [PATCH 94/95] [UPDATE] set to 0.0.3 --- README.md | 4 ++-- docs/Download.html | 25 +++++++++++++++++++++++++ docs/SetUp.html | 2 +- docs/index.html | 4 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4f47f52..01593c2 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ ``` G. Sarthou, mementar,” https://github.com/sarthou/mementar, -LAAS-CNRS, Toulouse, 2018 – 2019. +LAAS-CNRS, Toulouse, 2018 – 2020. ``` [Release-Url]: https://github.com/sarthou/mementar/releases -[Release-image]: http://img.shields.io/badge/release-v0.0.2-1eb0fc.svg +[Release-image]: http://img.shields.io/badge/release-v0.0.3-1eb0fc.svg diff --git a/docs/Download.html b/docs/Download.html index 1bcc3d5..69c33b5 100644 --- a/docs/Download.html +++ b/docs/Download.html @@ -78,6 +78,31 @@

    Download

    You have below the archives of the major versions of mementar:

    +

    V0.0.3

    +

    21 / 12 / 2020

    + + +

    V0.0.2

    10 / 07 / 2019

    diff --git a/docs/SetUp.html b/docs/SetUp.html index 09c91a9..9af5801 100644 --- a/docs/SetUp.html +++ b/docs/SetUp.html @@ -119,7 +119,7 @@

    Set Up Your Environnement

    The package.xml do not need to be modified. For the CMakeLists.txt, we will required a minimal version (optional) and include ontologenius API.

    -
    find_package(mementar 0.0.2 REQUIRED)
    +
    find_package(mementar 0.0.3 REQUIRED)
    ...
    catkin_package(
    # INCLUDE_DIRS include
    diff --git a/docs/index.html b/docs/index.html index f4a9cbc..cea4d1a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,7 +1,7 @@ - Mementar 0.0.2 + Mementar 0.0.3 @@ -90,7 +90,7 @@

    A long-term episodic memory for robotic agents

    From 195d0ead3bf5e8c313c56c7433f7d97ac20b72a1 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Mon, 21 Dec 2020 11:36:42 +0100 Subject: [PATCH 95/95] [REFACT] documentation --- docs/Download.html | 16 ++-- docs/InstallMementar.html | 26 ++--- docs/SetUp.html | 16 ++-- docs/Tutorials.html | 99 ++++++++++++++++++++ docs/construction.html | 16 ++-- docs/{ => cpp_API}/ClientBase.html | 22 ++--- docs/{ => cpp_API}/CppAPI.html | 22 ++--- docs/{ => cpp_API}/Fact.html | 22 ++--- docs/{ => cpp_API}/ManagerClient.html | 22 ++--- docs/{ => cpp_API}/OccasionsPublisher.html | 22 ++--- docs/{ => cpp_API}/OccasionsSubscriber.html | 22 ++--- docs/{ => cpp_API}/TimelineManipulator.html | 22 ++--- docs/{ => cpp_API}/TimelinesManipulator.html | 22 ++--- docs/index.html | 10 +- 14 files changed, 233 insertions(+), 126 deletions(-) create mode 100644 docs/Tutorials.html rename docs/{ => cpp_API}/ClientBase.html (90%) rename docs/{ => cpp_API}/CppAPI.html (83%) rename docs/{ => cpp_API}/Fact.html (92%) rename docs/{ => cpp_API}/ManagerClient.html (89%) rename docs/{ => cpp_API}/OccasionsPublisher.html (88%) rename docs/{ => cpp_API}/OccasionsSubscriber.html (92%) rename docs/{ => cpp_API}/TimelineManipulator.html (90%) rename docs/{ => cpp_API}/TimelinesManipulator.html (92%) diff --git a/docs/Download.html b/docs/Download.html index 69c33b5..4ea6a16 100644 --- a/docs/Download.html +++ b/docs/Download.html @@ -57,15 +57,15 @@

    Getting Start

    diff --git a/docs/InstallMementar.html b/docs/InstallMementar.html index af68208..4edaa12 100644 --- a/docs/InstallMementar.html +++ b/docs/InstallMementar.html @@ -57,15 +57,15 @@

    Getting Start

    @@ -74,9 +74,11 @@

    All C++ Classes

    Install Mementar

    Since Mementar is a ROS package, make sure that ROS is installed on your platform. Mementar is fully supported and maintained by ROS Kinetic Kame and ROS Melodic Morenia. Desktop ROS configuration is not required for use of mementar.

    +

    Mementar is strongly linked to the Ontologenius software to provide a semantic abstraction of the knowledge it stores.

    +

    Clone the package on your catkin workspace:

    -

    cd ~/catkin_ws/src/

    git clone https://github.com/sarthou/mementar.git

    cd ..

    catkin_make

    +

    cd ~/catkin_ws/src/
    git clone https://github.com/sarthou/mementar.git
    git clone https://github.com/sarthou/ontologenius.git
    cd ..
    catkin_make

    Troubles

    @@ -88,14 +90,14 @@

    Troubles

    sudo apt-get install ros-DISTRO-qt-build

    - + +