.. _cpp-flow/Solution: ********************************************************** flow/Solution.hpp ********************************************************** .. default-domain:: cpp .. default-role:: cpp:expr .. py:currentmodule:: mod .. cpp:namespace:: mod Class ``flow::SolutionRange`` -------------------------------------------------------------------------------------------------------------------------------- .. class:: flow::SolutionRange A range of solutions for a flow model. Synopsis ^^^^^^^^ .. code-block:: c++ struct MOD_DECL SolutionRange { struct const_iterator { using difference_type = int; using value_type = Solution; using reference = Solution; using iterator_category = std::random_access_iterator_tag; using pointer = void; public: const_iterator() = default; private: friend class SolutionRange; const_iterator(std::shared_ptr flow_, int i); public: MOD_DECL friend bool operator==(const const_iterator &a, const const_iterator &b); MOD_DECL friend bool operator!=(const const_iterator &a, const const_iterator &b); const_iterator &operator++(); const_iterator operator++(int); MOD_DECL friend const_iterator operator+(const const_iterator &a, int i); Solution operator*() const; Solution operator[](int i) const; private: std::shared_ptr flow_; int i = 0; }; using iterator = const_iterator; private: friend class Flow; SolutionRange(std::shared_ptr flow_, int first, int last); public: std::shared_ptr getFlow() const; MOD_DECL friend std::ostream &operator<<(std::ostream &s, const SolutionRange &r); int size() const; const_iterator begin() const; const_iterator end() const; Solution operator[](int i) const; public: void list() const; void print() const; void print(const dg::PrintData &data, const Printer &printer) const; private: std::shared_ptr flow_; int first = 0, last = 0; }; Details ^^^^^^^ .. cpp:namespace-push:: flow::SolutionRange .. type:: const_iterator iterator Random-access iterator types for solutions in a range. .. function:: std::shared_ptr getFlow() :returns: the flow model that produced these solutions. .. function:: friend std::ostream &operator<<(std::ostream &s, const SolutionRange &r) .. function:: int size() const :returns: the number of solutions in the range. .. function:: const_iterator begin() const const_iterator end() const :returns: the begin and end iterators for the range. .. function:: Solution operator[](int i) const :returns: the `i` th solution in the range. :throws: :class:`LogicError` if the index is out of bounds. .. function:: void list() const List overall information about each solution. .. function:: void print() const void print(const dg::PrintData &data, const Printer &printer) const Print solutions using the settings in the given printer and the structure information in the data object. The `data` defaults to `dg::PrintData(getFlow()->getDG())` and `printer` defaults to `Printer()`. :throws: :class:`LogicError` if the given print data does not belong to the underlying derivation graph. .. cpp:namespace-pop:: Class ``flow::Solution`` -------------------------------------------------------------------------------------------------------------------------------- .. class:: flow::Solution A solution for a flow model. Synopsis ^^^^^^^^ .. code-block:: c++ class MOD_DECL Solution { friend class SolutionRange::const_iterator; Solution(std::shared_ptr flow_, int i); public: std::shared_ptr getFlow() const; int getId() const; MOD_DECL friend std::ostream &operator<<(std::ostream &s, const Solution &sol); MOD_DECL friend bool operator==(const Solution &a, const Solution &b); MOD_DECL friend bool operator!=(const Solution &a, const Solution &b); public: boost::variant eval(const LinExp &exp) const; void list() const; std::pair, boost::optional> print() const; std::pair, boost::optional> print(const dg::PrintData &data, const Printer &printer) const; private: std::shared_ptr flow_; int i; }; Details ^^^^^^^ .. cpp:namespace-push:: flow::Solution .. function:: std::shared_ptr getFlow() :returns: the flow model that produced the solution. .. function:: int getId() const :returns: an ID for the solution which is unique among all solutions from the parent :class:`Flow` object. .. function:: friend std::ostream &operator<<(std::ostream &s, const Solution &sol) .. function:: boost::variant eval(const LinExp &exp) const :returns: the value of the given linear expression evaluated on the solution. .. function:: void list() const List overall information about the solution. .. function:: std::pair, boost::optional> \ print() const std::pair, boost::optional> \ print(const dg::PrintData &data, const Printer &printer) const Print the solution using the settings in the given printer and the structure information in the data object. The `data` defaults to `dg::PrintData(getFlow()->getDG())` and `printer` defaults to `Printer()`. :returns: the name of the PDF-files that will be compiled in post-processing for respectively the filtered and unfiltered depictions. If either is not requested by the given `printer` the corresponding entry has no string. :throws: :class:`LogicError` if the given print data does not belong to the underlying derivation graph. .. cpp:namespace-pop:: Class ``flow::SolutionOld`` -------------------------------------------------------------------------------------------------------------------------------- .. class:: flow::SolutionOld An object of this class represents a solution for a specific flow model. Synopsis ^^^^^^^^ .. code-block:: c++ class MOD_DECL SolutionOld { friend class SolutionSet; SolutionOld(std::shared_ptr dgFlow, unsigned int id); public: lib::Flow::Solution makeSolution() const; public: unsigned int getId() const; std::shared_ptr getFlow() const; double eval(const LinExp &exp) const; std::string print(const dg::PrintData &data, const Printer &printer) const; void haxListDerivations() const; // :throws: :class:`LogicError` if at least one graph in the query does not represent a vertex in the underlying derivation graph. bool hasSequence(const causality::FlowQuery &query) const; // :throws: :class:`LogicError` if at least one graph in the query does not represent a vertex in the underlying derivation graph. // :throws: :class:`LogicError` if the sequence does not exist. DGTransition::Sequence getSequence(const causality::FlowQuery &query) const; // :throws: :class:`LogicError` if the two solutions are not on the same derivation graph. bool equal(const SolutionOld &other, const LinExp &vars) const; // object equality, not the same as equal MOD_DECL friend bool operator==(const SolutionOld &lhs, const SolutionOld &rhs); private: std::shared_ptr dgFlow; unsigned int id; }; Details ^^^^^^^ .. cpp:namespace-push:: flow::SolutionOld .. function:: unsigned int getId() const :returns: an id for the solution which is unique among all solutions from the parent :class:`Flow` object. .. function:: std::shared_ptr getFlow() const :returns: the flow model that produced this solution. .. function:: double eval(const LinExp &exp) const :returns: the value of the given linear expression evaluated on the solution. .. function:: void print(const dg::PrintData &data, const Printer &printer) const Print the solution using the settings in the given printer. :returns: the name of the PDF-file that will be compiled in post-processing for the filtered graph. :throws: :class:`LogicError` if the given print data does not belong to the underlying derivation graph. .. function:: void haxListDerivations() const List the solution in more human readable form. Don't expect this function to stay in this form. .. cpp:namespace-pop:: Class ``flow::SolutionSet`` -------------------------------------------------------------------------------------------------------------------------------- .. class:: flow::SolutionSet An object of this class represents the solutions for a specific flow model. Synopsis ^^^^^^^^ .. code-block:: c++ struct MOD_DECL SolutionSet { struct const_iterator { using difference_type = std::size_t; using value_type = SolutionOld; using reference = SolutionOld; using iterator_category = std::forward_iterator_tag; using pointer = void; private: friend class SolutionSet; const_iterator(const SolutionSet &set, unsigned int id); public: bool operator!=(const_iterator other) const; bool operator==(const_iterator other) const; const_iterator operator++(); const_iterator operator++(int); SolutionOld operator*() const; private: const SolutionSet &set; unsigned int id; }; using iterator = const_iterator; public: SolutionSet(std::shared_ptr dgFlow); std::shared_ptr getFlow() const; MOD_DECL friend std::ostream &operator<<(std::ostream &s, const SolutionSet &set); void list() const; unsigned int size() const; void print(const dg::PrintData &data, const Printer &printer) const; const_iterator begin() const; const_iterator end() const; SolutionOld operator[](unsigned int i) const; private: SolutionOld makeSolution(unsigned int id) const; private: std::shared_ptr dgFlow; unsigned int numSolutions; }; Details ^^^^^^^ .. cpp:namespace-push:: flow::SolutionSet .. function:: SolutionSet(std::shared_ptr dgFlow) Construct a representation of the solutions for the given flow model. .. function:: std::shared_ptr getFlow() :returns: the flow model that produced these solutions. .. function:: void list() const List overall information about each solution. .. function:: unsigned int size() const :returns: the number of solutions in the flow model. .. function:: void print(const dg::PrintData &data, const Printer &printer) const Print all solutions using the given flow printer. .. function:: const_iterator begin() const :returns: an iterator to the first solution. .. function:: const_iterator end() const :returns: an iterator to after the last solution. .. function:: Solution operator[](unsigned int i) const :returns: the solution at the given index. :throws: :class:`LogicError` if the index is out of bounds. .. cpp:namespace-pop::