- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/BFIGImplicantHeap.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "BFIGImplicantHeap.h"
    00015
    00016 #include "BFIGImplicant.h"
    00017
    00019
    00020 using namespace Mers::Generators::BFIG;
    00021 using std::ostream;
    00022
    00024 // Construction/Destruction
    00026
    00027 BFIGImplicantHeap::BFIGImplicantHeap(bool greatestOnTop, double maximumCost,
    00028         bool owner)
    00029         : DynamicHeap(greatestOnTop, DynamicArray::DAHBFIGImplicantHeap, owner),
    00030         mPruneByCost(true), mMaximumCost(maximumCost)
    00031 {
    00032         //fprintf(stderr, "Costs: %f = %f\n", mMaximumCost, maximumCost);
    00033 }
    00034
    00036
    00037 BFIGImplicantHeap::BFIGImplicantHeap(bool greatestOnTop, bool owner)
    00038         : DynamicHeap(greatestOnTop, DynamicArray::DAHBFIGImplicantHeap, owner),
    00039         mPruneByCost(false), mMaximumCost(0)
    00040 {
    00041 }
    00042
    00044
    00045 BFIGImplicantHeap::~BFIGImplicantHeap()
    00046 {
    00047         makeEmpty();
    00048 }
    00049
    00051
    00052 int BFIGImplicantHeap::insert(HeapElement * element)
    00053 {
    00054         //fprintf(stderr, "BFIGImplicantHeap: Insert; MCost(%f), Cost(%f)\n",
    00055         //                              mMaximumCost, element->getBestCost());
    00056         if(mPruneByCost && element->getBestCost() > mMaximumCost) {
    00057                 //fprintf(stderr, "BFIGImplicantHeap: Insert; Rejected\n");
    00058                 if(ownsElements) {
    00059                         delete element;
    00060                 }
    00061                 return 0;
    00062         } else {
    00063                 return DynamicHeap::insert((void *) element);
    00064         }
    00065 }
    00066
    00068
    00069 int BFIGImplicantHeap::peekFirst(HeapElement * &element)
    00070 {
    00071         return DynamicHeap::peekFirst((void * &) element);
    00072 }
    00073
    00075
    00076 int BFIGImplicantHeap::getFirst(HeapElement * &element)
    00077 {
    00078         return DynamicHeap::getFirst((void * &) element);
    00079 }
    00080
    00082
    00083 #ifndef EMBEDDED
    00084 void BFIGImplicantHeap::printElement(ostream &out, void const * element) const
    00085 {
    00086         HeapElement const &e = *(HeapElement const *) element;
    00087
    00088         out << e;
    00089 }
    00090 #endif
    00091
    00093
    00094 void BFIGImplicantHeap::deleteElement(void * element) const
    00095 {
    00096         delete (HeapElement *) element;
    00097 }
    00098
    00100
    00101 void * BFIGImplicantHeap::newElement(void const * element) const
    00102 {
    00103         return new HeapElement(*(HeapElement const *)element);
    00104 }
    00105
    00107
    00108 bool BFIGImplicantHeap::greaterThan(void const * e1, void const * e2) const
    00109 {
    00110         HeapElement const &element1 = *(HeapElement const *) e1;
    00111         HeapElement const &element2 = *(HeapElement const *) e2;
    00112
    00113         return element1 > element2;
    00114 }
    00115
    00117
    00118 bool BFIGImplicantHeap::lessThan(void const * e1, void const * e2) const
    00119 {
    00120         HeapElement const &element1 = *(HeapElement const *) e1;
    00121         HeapElement const &element2 = *(HeapElement const *) e2;
    00122
    00123         return element1 < element2;
    00124 }
    00125
    00127