LCOV - code coverage report
Current view: top level - source - FunctionOntologicalClass.cpp (source / functions) Hit Total Coverage
Test: LibForBES Unit Tests Lines: 74 80 92.5 %
Date: 2016-04-18 Functions: 22 25 88.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* 
       2             :  * File:   FunctionOntologicalClass.cpp
       3             :  * Author: Pantelis Sopasakis
       4             :  * 
       5             :  * Created on October 28, 2015, 8:07 PM
       6             :  * 
       7             :  * ForBES is free software: you can redistribute it and/or modify
       8             :  * it under the terms of the GNU Lesser General Public License as published by
       9             :  * the Free Software Foundation, either version 3 of the License, or
      10             :  * (at your option) any later version.
      11             :  *  
      12             :  * ForBES is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      15             :  * GNU Lesser General Public License for more details.
      16             :  * 
      17             :  * You should have received a copy of the GNU Lesser General Public License
      18             :  * along with ForBES. If not, see <http://www.gnu.org/licenses/>.
      19             :  */
      20             : 
      21             : #include "FunctionOntologicalClass.h"
      22             : #include "FunctionOntologyRegistry.h"
      23             : 
      24          33 : FunctionOntologicalClass::FunctionOntologicalClass(
      25             :         bool does_define_conjugate,
      26             :         bool does_define_conjugate_grad,
      27             :         bool does_define_f,
      28             :         bool does_define_grad,
      29             :         bool does_define_prox,
      30             :         bool does_define_hessian,
      31             :         bool does_define_hessian_conj,
      32             :         std::string name,
      33             :         const FunctionOntologicalClass& super) :
      34             : m_name(name),
      35             : m_defines_f(does_define_f),
      36             : m_defines_grad(does_define_grad),
      37             : m_defines_conjugate(does_define_conjugate),
      38             : m_defines_conjugate_grad(does_define_conjugate_grad),
      39             : m_defines_prox(does_define_prox),
      40             : m_defines_hessian(does_define_hessian),
      41          33 : m_defines_hessian_conj(does_define_hessian_conj) {
      42          33 :     superClasses.push_back(super);
      43          33 : }
      44             : 
      45         713 : FunctionOntologicalClass::~FunctionOntologicalClass() {
      46         713 : }
      47             : 
      48          95 : FunctionOntologicalClass::FunctionOntologicalClass(std::string name) : m_name(name) {
      49          95 :     m_defines_f = false;
      50          95 :     m_defines_grad = false;
      51          95 :     m_defines_prox = false;
      52          95 :     m_defines_conjugate = false;
      53          95 :     m_defines_conjugate_grad = false;
      54          95 :     m_defines_hessian = false;
      55          95 :     m_defines_hessian_conj = false;
      56          95 : }
      57             : 
      58             : //LCOV_EXCL_START
      59             : 
      60             : std::ostream& operator<<(std::ostream& os, const FunctionOntologicalClass& obj) {
      61             :     os << "Function class : " << obj.m_name << "\n";
      62             :     os << " * f()              : " << (obj.m_defines_f ? "YES" : "NO") << "\n";
      63             :     os << " * grad[f]()        : " << (obj.m_defines_grad ? "YES" : "NO") << "\n";
      64             :     os << " * hess[f]()        : " << (obj.m_defines_hessian ? "YES" : "NO") << "\n";
      65             :     os << " * f*()             : " << (obj.m_defines_conjugate ? "YES" : "NO") << "\n";
      66             :     os << " * grad[f*]()       : " << (obj.m_defines_conjugate_grad ? "YES" : "NO") << "\n";
      67             :     os << " * hess[f*]()       : " << (obj.m_defines_hessian_conj ? "YES" : "NO") << "\n";
      68             :     os << " * prox(gamma*f)()  : " << (obj.m_defines_prox ? "YES" : "NO") << "\n";
      69             :     os << "Super-classes... \n";
      70             :     std::list<FunctionOntologicalClass> li = obj.superClasses;
      71             :     size_t i = 1;
      72             :     for (std::list<FunctionOntologicalClass>::iterator it = li.begin(); it != li.end(); ++it) {
      73             :         std::cout << " " << i << ". " << it->getName() << "\n";
      74             :         i++;
      75             :     }
      76             :     return os;
      77             : }
      78             : //LCOV_EXCL_STOP
      79             : 
      80          31 : bool FunctionOntologicalClass::defines_conjugate() const {
      81          31 :     return m_defines_conjugate;
      82             : }
      83             : 
      84          20 : bool FunctionOntologicalClass::defines_conjugate_grad() const {
      85          20 :     return m_defines_conjugate_grad;
      86             : }
      87             : 
      88          46 : bool FunctionOntologicalClass::defines_f() const {
      89          46 :     return m_defines_f;
      90             : }
      91             : 
      92          26 : bool FunctionOntologicalClass::defines_grad() const {
      93          26 :     return m_defines_grad;
      94             : }
      95             : 
      96          36 : bool FunctionOntologicalClass::defines_prox() const {
      97          36 :     return m_defines_prox;
      98             : }
      99             : 
     100          30 : std::list<FunctionOntologicalClass> FunctionOntologicalClass::getSuperclasses() const {
     101          30 :     return superClasses;
     102             : }
     103             : 
     104          79 : void FunctionOntologicalClass::add_superclass(FunctionOntologicalClass fun_ont_class) {
     105          79 :     superClasses.push_back(fun_ont_class);
     106          79 : }
     107             : 
     108          48 : void FunctionOntologicalClass::set_defines_conjugate(bool define_conjugate) {
     109          48 :     m_defines_conjugate = define_conjugate;
     110          48 : }
     111             : 
     112          58 : void FunctionOntologicalClass::set_defines_f(bool define_f) {
     113          58 :     m_defines_f = define_f;
     114          58 : }
     115             : 
     116          37 : void FunctionOntologicalClass::set_defines_conjugate_grad(bool define_conjugate_grad) {
     117          37 :     m_defines_conjugate_grad = define_conjugate_grad;
     118          37 : }
     119             : 
     120          30 : void FunctionOntologicalClass::set_defines_prox(bool define_prox) {
     121          30 :     m_defines_prox = define_prox;
     122          30 : }
     123             : 
     124          53 : void FunctionOntologicalClass::set_defines_grad(bool define_grad) {
     125          53 :     m_defines_grad = define_grad;
     126          53 : }
     127             : 
     128           4 : bool FunctionOntologicalClass::defines_hessian() const {
     129           4 :     return m_defines_hessian;
     130             : }
     131             : 
     132           4 : bool FunctionOntologicalClass::defines_hessian_conj() const {
     133           4 :     return m_defines_hessian_conj;
     134             : }
     135             : 
     136           0 : void FunctionOntologicalClass::set_defines_hessian(bool define_hessian) {
     137           0 :     m_defines_hessian = define_hessian;
     138           0 : }
     139             : 
     140           0 : void FunctionOntologicalClass::set_defines_hessian_conj(bool define_hessian_conj) {
     141           0 :     m_defines_hessian_conj = define_hessian_conj;
     142           0 : }
     143             : 
     144         115 : std::string FunctionOntologicalClass::getName() const {
     145         115 :     return this -> m_name;
     146             : }
     147             : 
     148          23 : bool FunctionOntologicalClass::is_quadratic() {
     149          23 :     string quad_name = FunctionOntologyRegistry::quadratic().getName();
     150          23 :     if (getName().compare(quad_name) == 0) return true;
     151          16 :     bool gauge = false;
     152          32 :     std::list<FunctionOntologicalClass> superclasses = getSuperclasses();
     153          93 :     for (std::list<FunctionOntologicalClass>::iterator cl = superclasses.begin();
     154          62 :             cl != superclasses.end();
     155             :             ++cl) {
     156          21 :         if ((*cl).getName().compare(quad_name) == 0) {
     157           6 :             gauge = true;
     158           6 :             break;
     159             :         }
     160             :     }
     161          39 :     return gauge;
     162             : }
     163             : 
     164          10 : bool FunctionOntologicalClass::is_conjugate_quadratic() {
     165          10 :     string conj_quad_name = FunctionOntologyRegistry::conj_quadratic().getName();
     166          10 :     if (getName().compare(conj_quad_name) == 0) return true;
     167          10 :     bool gauge = false;
     168          20 :     std::list<FunctionOntologicalClass> superclasses = getSuperclasses();
     169          51 :     for (std::list<FunctionOntologicalClass>::iterator cl = superclasses.begin();
     170          34 :             cl != superclasses.end();
     171             :             ++cl) {
     172          11 :         if ((*cl).getName().compare(conj_quad_name) == 0) {
     173           4 :             gauge = true;
     174           4 :             break;
     175             :         }
     176             :     }
     177          20 :     return gauge;
     178          87 : }
     179             : 
     180             : 

Generated by: LCOV version 1.10