// file: $isip/class/dstr/BiGraphVertex/BiGraphVertex.h // version: $Id: BiGraphVertex.h 10636 2007-01-26 22:18:09Z tm334 $ // // make sure definitions are only made once // #ifndef ISIP_BIGRAPH_VERTEX #define ISIP_BIGRAPH_VERTEX // isip include files // #ifndef ISIP_DOUBLE_LINKED_LIST #include #endif #ifndef ISIP_MEMORY_MANAGER #include #endif #ifndef ISIP_STRING #include #endif // forward class definitions: // we must define the BiGraph class and the BiGraphArc class here first because // the header files might be short-circuited by the ifndef. // template class BiGraph; template class BiGraphArc; // BiGraphVertex: a generic BiGraphVertex. the main purpose of a vertex is // to hold a list of arcs originating from the given vertex. // template class BiGraphVertex : public Node { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 41100; static const int32 ERR_NULLD = 41101; static const int32 ERR_NOPAR = 41102; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // adjacency list manipulation methods // DoubleLinkedList< BiGraphArc > parents_d; DoubleLinkedList< BiGraphArc > children_d; // what BiGraph does this vertex belong to // BiGraph* parent_graph_d; // define the memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // static methods // static const String& name(); // this class doesn't have a diagnose method, its functionality is // tested in BiGraph::diagnose // // debug methods: // setDebug is inherited from the DoubleLinkedList template class // bool8 debug(const unichar* message) const; // method: destructor // ~BiGraphVertex() { removeAllArcsChild(); removeAllArcsParent(); } // method: default constructor // BiGraphVertex() { parent_graph_d = (BiGraph*)NULL; setAllocationModeChild(DstrBase::USER); setAllocationModeParent(DstrBase::USER); } // method: copy constructor // BiGraphVertex(const BiGraphVertex& arg) { parent_graph_d = (BiGraph*)NULL; setAllocationModeChild(DstrBase::USER); setAllocationModeParent(DstrBase::USER); assign(arg); } // assign methods // bool8 assign(const BiGraphVertex& copy_vertex); // method: operator= // BiGraphVertex& operator=(const BiGraphVertex& arg) { assign(arg); return *this; } // i/o methods: // these methods are not needed since BiGraph takes care of it's own I/O. // // method: eq // determines if the contents of the vertex are equivalent. // adjacency lists & weights are ignored. // bool8 eq(const BiGraphVertex& arg) const { return Node::eq(arg); } // method: new // void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return (mgr_d.setGrow(grow_size)); } // other memory management methods: // bool8 clear(Integral::CMODE cmode = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods: // parent bigraph manipulation methods // //--------------------------------------------------------------------------- // method: setParentGraph // bool8 setParentGraph(BiGraph* parent) { parent_graph_d = parent; return true; } // method: getParentGraph // BiGraph* getParentGraph() const { return parent_graph_d; } //--------------------------------------------------------------------------- // // class-specific public methods: // vertex manipulation methods // //--------------------------------------------------------------------------- // insert/remove a vertex to/from the adjacency list: // these methods assume that the user is taking care of updating the // parent BiGraphs, end vertices, etc. // bool8 insertArcChild(BiGraphVertex* vertex, float64 weight = BiGraphArc::DEF_WEIGHT, bool8 is_epsilon = BiGraphArc::DEF_EPSILON); bool8 insertArcParent(BiGraphVertex* vertex, float64 weight = BiGraphArc::DEF_WEIGHT, bool8 is_epsilon = BiGraphArc::DEF_EPSILON); bool8 insertArcChild(BiGraphVertex* vertex, bool8 is_epsilon = BiGraphArc::DEF_EPSILON); bool8 insertArcParent(BiGraphVertex* vertex, bool8 is_epsilon = BiGraphArc::DEF_EPSILON); bool8 removeArcChild(BiGraphVertex* vertex); bool8 removeArcParent(BiGraphVertex* vertex); bool8 removeArcChild(); bool8 removeArcParent(); bool8 removeAllArcsChild(); bool8 removeAllArcsParent(); // is this vertex adjacent? // bool8 isAdjacentChild(BiGraphVertex* vertex) const; bool8 isAdjacentParent(BiGraphVertex* vertex) const; // method: isStart // bool8 isStart() const { if (parent_graph_d == (BiGraph*)NULL) { return Error::handle(name(), L"isStart - undefined parent", Error::ARG, __FILE__, __LINE__); } return (this == parent_graph_d->getStart()); } // method: isTerm // bool8 isTerm() const { if (parent_graph_d == (BiGraph*)NULL) { return Error::handle(name(), L"isTerm - undefined parent", Error::ARG, __FILE__, __LINE__); } return (this == parent_graph_d->getTerm()); } //--------------------------------------------------------------------------- // // class-specific public methods: // vertex comparison methods // //--------------------------------------------------------------------------- // compares the siblings of the two vertices and arc weights to see if // the two vertices has a similar structure // bool8 compareVertices(const BiGraphVertex& compare_vertex_a) const; //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list retrieval methods // //--------------------------------------------------------------------------- // method: getParents // DoubleLinkedList< BiGraphArc >* getParents() { return &parents_d; } // method: getChildren // DoubleLinkedList< BiGraphArc >* getChildren() { return &children_d; } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list positioning methods // //-------------------------------------------------------------------------- // method: gotoFirstChild // bool8 gotoFirstChild() { return children_d.gotoFirst(); } // method: gotoLastChild // bool8 gotoLastChild() { return children_d.gotoLast(); } // method: gotoNextChild // bool8 gotoNextChild() { return children_d.gotoNext(); } // method: gotoPrevChild // bool8 gotoPrevChild() { return children_d.gotoPrev(); } // method: gotoMarkChild // bool8 gotoMarkChild() { return children_d.gotoMark(); } // method: gotoPositionChild // bool8 gotoPositionChild(int32 arg) { return children_d.gotoPosition(arg); } // method: getPositionChild // int32 getPositionChild() const { return const_cast > & > (children_d).getPosition(); } // method: gotoFirstParent // bool8 gotoFirstParent() { return parents_d.gotoFirst(); } // method: gotoLastParent // bool8 gotoLastParent() { return parents_d.gotoLast(); } // method: gotoNextParent // bool8 gotoNextParent() { return parents_d.gotoNext(); } // method: gotoPrevParent // bool8 gotoPrevParent() { return parents_d.gotoPrev(); } // method: gotoMarkParent // bool8 gotoMarkParent() { return parents_d.gotoMark(); } // method: gotoPositionParent // bool8 gotoPositionParent(int32 arg) { return parents_d.gotoPosition(arg); } // method: getPositionParent // int32 getPositionParent() const { return const_cast >& > (parents_d).getPosition(); } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list marking methods // //-------------------------------------------------------------------------- // method: markIsSetChild // bool8 markIsSetChild() const { return const_cast >& > (children_d).markIsSet(); } // method: isMarkedElementChild // bool8 isMarkedElementChild() const { return const_cast >& > (children_d).isMarkedElement(); } // method: clearMarkChild // bool8 clearMarkChild() const { return const_cast >& > (children_d).clearMark(); } // method: setMarkChild // bool8 setMarkChild() const { return const_cast >& > (children_d).setMark(); } // method: markIsSetParent // bool8 markIsSetParent() const { return const_cast >& > (parents_d).markIsSet(); } // method: isMarkedElementParent // bool8 isMarkedElementParent() const { return const_cast >& > (parents_d).isMarkedElement(); } // method: clearMarkParent // bool8 clearMarkParent() const { return const_cast >& > (parents_d).clearMark(); } // method: setMarkParent // bool8 setMarkParent() const { return const_cast >& > (parents_d).setMark(); } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list access methods // //-------------------------------------------------------------------------- // method: getFirstChild // BiGraphArc* getFirstChild() { return children_d.getFirst(); } // method: getLastChild // BiGraphArc* getLastChild() { return children_d.getLast(); } // method: getNextChild // BiGraphArc* getNextChild() { return children_d.getNext(); } // method: getPrevChild // BiGraphArc* getPrevChild() { return children_d.getPrev(); } // method: getMarkChild // BiGraphArc* getMarkChild() { return children_d.getMark(); } // method: getCurrChild // BiGraphArc* getCurrChild() { return children_d.getCurr(); } // method: getFirstChild // BiGraphArc* getFirstChild() const { return const_cast >& > (children_d).getFirst(); } // method: getLastChild // BiGraphArc* getLastChild() const { return const_cast >& > (children_d).getLast(); } // method: getNextChild // BiGraphArc* getNextChild() const { return const_cast >& > (children_d).getNext(); } // method: getPrevChild // BiGraphArc* getPrevChild() const { return const_cast >& > (children_d).getPrev(); } // method: getMarkChild // BiGraphArc* getMarkChild() const { return const_cast >& > (children_d).getMark(); } // method: getCurrChild // BiGraphArc* getCurrChild() const { return const_cast >& > (children_d).getCurr(); } // method: getFirstParent // BiGraphArc* getFirstParent() { return parents_d.getFirst(); } // method: getLastParent // BiGraphArc* getLastParent() { return parents_d.getLast(); } // method: getNextParent // BiGraphArc* getNextParent() { return parents_d.getNext(); } // method: getPrevParent // BiGraphArc* getPrevParent() { return parents_d.getPrev(); } // method: getMarkParent // BiGraphArc* getMarkParent() { return parents_d.getMark(); } // method: getCurrParent // BiGraphArc* getCurrParent() { return parents_d.getCurr(); } // method: getFirstParent // BiGraphArc* getFirstParent() const { return const_cast >& > (parents_d).getFirst(); } // method: getLastParent // BiGraphArc* getLastParent() const { return const_cast >& > (parents_d).getLast(); } // method: getNextParent // BiGraphArc* getNextParent() const { return const_cast >& > (parents_d).getNext(); } // method: getPrevParent // BiGraphArc* getPrevParent() const { return const_cast >& > (parents_d).getPrev(); } // method: getMarkParent // BiGraphArc* getMarkParent() const { return const_cast >& > (parents_d).getMark(); } // method: getCurrParent // BiGraphArc* getCurrParent() const { return const_cast >& > (parents_d).getCurr(); } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list insert-remove methods // //-------------------------------------------------------------------------- // method: insertChild // bool8 insertChild(BiGraphArc* arg) { return children_d.insert(arg); } // method: insertChild // bool8 insertChild(DoubleLinkedList >& arg) { return children_d.insert(arg); } // method: removeChild // bool8 removeChild(BiGraphArc*& arg) { return children_d.remove(arg); } // method: removeChild // bool8 removeChild() { return children_d.remove(); } // method: insertFirstChild // bool8 insertFirstChild(BiGraphArc* arg) { return children_d.insertFirst(arg); } // method: insertFirstChild // bool8 insertFirstChild(DoubleLinkedList >& arg) { return children_d.insertFirst(arg); } // method: removeFirstChild // bool8 removeFirstChild(BiGraphArc*& arg) { return children_d.removeFirst(arg); } // method: removeFirstChild // bool8 removeFirstChild() { return children_d.removeFirst(); } // method: insertLastChild // bool8 insertLastChild(BiGraphArc* arg) { return children_d.insertLast(arg); } // method: insertLastChild // bool8 insertLastChild(DoubleLinkedList >& arg) { return children_d.insertLast(arg); } // method: removeLastChild // bool8 removeLastChild(BiGraphArc*& arg) { return children_d.removeLast(arg); } // method: removeLastChild // bool8 removeLastChild() { return children_d.removeLast(); } // method: insertParent // bool8 insertParent(BiGraphArc* arg) { return parents_d.insert(arg); } // method: insertParent // bool8 insertParent(DoubleLinkedList >& arg) { return parents_d.insert(arg); } // method: removeParent // bool8 removeParent(BiGraphArc*& arg) { return parents_d.remove(arg); } // method: removeParent // bool8 removeParent() { return parents_d.remove(); } // method: insertFirstParent // bool8 insertFirstParent(BiGraphArc* arg) { return parents_d.insertFirst(arg); } // method: insertFirstParent // bool8 insertFirstParent(DoubleLinkedList >& arg) { return parents_d.insertFirst(arg); } // method: removeFirstParent // bool8 removeFirstParent(BiGraphArc*& arg) { return parents_d.removeFirst(arg); } // method: removeFirstParent // bool8 removeFirstParent() { return parents_d.removeFirst(); } // method: insertLastParent // bool8 insertLastParent(BiGraphArc* arg) { return parents_d.insertLast(arg); } // method: insertLastParent // bool8 insertLastParent(DoubleLinkedList >& arg) { return parents_d.insertLast(arg); } // method: removeLastParent // bool8 removeLastParent(BiGraphArc*& arg) { return parents_d.removeLast(arg); } // method: removeLastParent // bool8 removeLastParent() { return parents_d.removeLast(); } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list property methods // //-------------------------------------------------------------------------- // method: isEmptyChild // bool8 isEmptyChild() const { return const_cast >& > (children_d).isEmpty(); } // method: isFirstChild // bool8 isFirstChild() const { return const_cast >& > (children_d).isFirst(); } // method: isLastChild // bool8 isLastChild() const { return const_cast >& > (children_d).isLast(); } // method: lengthChild // int32 lengthChild() const { return const_cast >& > (children_d).length(); } // method: findChild // bool8 findChild(const BiGraphArc* arg) { return const_cast >& > (children_d).find(arg); } // method: containsChild // bool8 containsChild(const BiGraphArc* arg) const { return const_cast >& > (children_d).contains(arg); } // method: isEmptyParent // bool8 isEmptyParent() const { return const_cast >& > (parents_d).isEmpty(); } // method: isFirstParent // bool8 isFirstParent() const { return const_cast >& > (parents_d).isFirst(); } // method: isLastParent // bool8 isLastParent() const { return const_cast >& > (parents_d).isLast(); } // method: lengthParent // int32 lengthParent() const { return const_cast >& > (parents_d).length(); } // method: findParent // bool8 findParent(const BiGraphArc* arg) { return const_cast >& > (parents_d).find(arg); } // method: containsParent // bool8 containsParent(const BiGraphArc* arg) const { return const_cast >& > (parents_d).contains(arg); } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list ordering methods // //-------------------------------------------------------------------------- // method: sortChild // bool8 sortChild(Integral::ORDER sort_order = Integral::ASCENDING, DstrBase::SORT_ALGO = DstrBase::DEF_SORT_ALGO) { return children_d.sort(sort_order); } // method: reverseChild // bool8 reverseChild() { return children_d.reverse(); } // method: swapChild // bool8 swapChild(int32 i, int32 j) { return children_d.swap(i, j); } // method: sortParent // bool8 sortParent(Integral::ORDER sort_order = Integral::ASCENDING, DstrBase::SORT_ALGO = DstrBase::DEF_SORT_ALGO) { return parents_d.sort(sort_order); } // method: reverseParent // bool8 reverseParent() { return parents_d.reverse(); } // method: swapParent // bool8 swapParent(int32 i, int32 j) { return parents_d.swap(i, j); } //--------------------------------------------------------------------------- // // class-specific public methods: // adjacency list allocation methods // //-------------------------------------------------------------------------- // method: getAllocationModeChild // DstrBase::ALLOCATION getAllocationModeChild() const { return const_cast >& > (children_d).getAllocationMode(); } // method: setAllocationModeChild // bool8 setAllocationModeChild(DstrBase::ALLOCATION arg) { return children_d.setAllocationMode(arg); } // method: getAllocationModeParent // DstrBase::ALLOCATION getAllocationModeParent() const { return const_cast >& > (parents_d).getAllocationMode(); } // method: setAllocationModeParent // bool8 setAllocationModeParent(DstrBase::ALLOCATION arg) { return parents_d.setAllocationMode(arg); } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // friend class // template friend class BiGraphVertexDiagnose; }; // in order to allow BiGraph to reference BiGraphVertex's constants, it // must be included after the class definition. // #ifndef ISIP_BI_GRAPH #include #endif #ifndef ISIP_BIGRAPH_ARC #include #endif //----------------------------------------------------------------------------- // // we define non-integral constants at the end of class definition for // templates (for non-templates these are defined in the default constructor) // //----------------------------------------------------------------------------- // constants: required constants such as the class name // template const String BiGraphVertex::CLASS_NAME(L"BiGraphVertex"); template const String BiGraphVertex::DEF_PARAM(L"vertex"); // static instantiations: the memory manager // template MemoryManager BiGraphVertex::mgr_d(sizeof(BiGraphVertex), CLASS_NAME); // below are all the methods for the BiGraphVertex template class // // --------------------------------------------------------------------- // // required static methods // //---------------------------------------------------------------------- // method: name // // arguments: none // // return: a static String& containing the class name // // this method returns the class name // template const String& BiGraphVertex::name() { // create the static name string for this class and return it // static String cname(CLASS_NAME); cname.clear(); cname.concat(CLASS_NAME); cname.concat(L"<"); cname.concat(TObject::name()); cname.concat(L">"); // return the name // return cname; } // --------------------------------------------------------------------- // // required debug methods // //---------------------------------------------------------------------- // method: debug // // arguments: // const unichar* message: (input) information message // // return: a bool8 value indicating status // // this method dumps the contents of an object to the console // template bool8 BiGraphVertex::debug(const unichar* message_a) const { // build a debug string // String output; String value; output.debugStr(name(), message_a, L""); Console::put(output); Console::increaseIndention(); // dump a pointer to the current vertex // value.assign(this); output.debugStr(name(), message_a, L"this", value); Console::put(output); // dump a pointer to the parent BiGraph // value.assign(parent_graph_d); output.debugStr(name(), message_a, L"parent_graph_d", value); Console::put(output); // dump the internal item if it exists // Node::debug(L"item"); // call the parent debug method to debug the list itself // parents_d.debug(L"parents arcs"); // call the parent debug method to debug the list itself // children_d.debug(L"children arcs"); // that's it for sub-items, decrease indentation // Console::decreaseIndention(); // exit gracefully // return true; } //------------------------------------------------------------------------ // // required assign methods // //------------------------------------------------------------------------- // method: assign // // arguments: // const BiGraphVertex& arg: (input) the vertex to copy // // return: a bool8 value indicating status // // this method copies the contents of the input to this list // template bool8 BiGraphVertex::assign(const BiGraphVertex& arg_a) { // it may be necessary to clear this vertex // clear(); // call the parent assign method which handles the arc list elements // children_d.assign(*(const_cast& > (arg_a).getChildren())); // call the parent assign method which handles the arc list elements // parents_d.assign(*(const_cast& > (arg_a).getParents())); // call the Node assign method to assign the object // Node::assign(arg_a); // set the parent BiGraph // setParentGraph(arg_a.parent_graph_d); // exit gracefully // return true; } //------------------------------------------------------------------------- // // required clear method // //------------------------------------------------------------------------- // method: clear // // arguments: // Integral::CMODE cmode_a: (input) clear mode // // return: a bool8 value indicating status // // this method clears the reference to the internal data. // template bool8 BiGraphVertex::clear(Integral::CMODE cmode_a) { // switch on cmode // if (cmode_a == Integral::RETAIN) { if (this->item_d != (TObject*)NULL) { this->item_d->clear(cmode_a); } } else if ((cmode_a == Integral::RESET) || (cmode_a == Integral::RELEASE)) { // clear the references to the data // this->item_d = (TObject*)NULL; // clear the reference to the parent BiGraph // parent_graph_d = (BiGraph*)NULL; } else { // deallocate the allocated memory if necessary // if (this->item_d != (TObject*)NULL) { this->item_d->clear(Integral::FREE); delete this->item_d; this->item_d = (TObject*)NULL; } // clear the reference to the parent BiGraph // parent_graph_d = (BiGraph*)NULL; } // clear the arc list // bool8 return_val = removeAllArcsChild(); return_val &= removeAllArcsParent(); // exit gracefully // return return_val; } //--------------------------------------------------------------------------- // // class-specific public methods: // vertex manipulation methods // //--------------------------------------------------------------------------- // method: insertArcChild // // arguments: // BiGraphVertex* vertex: (input) the vertex to connect to // float64 weight: (input) the weight on the generated arc // bool8 is_epsilon: (input) is this an epsilon transition? // // return: a bool8 value indicating status // // this method inserts a weighted arc connecting this vertex to the input // vertex. // template bool8 BiGraphVertex::insertArcChild(BiGraphVertex* vertex_a, float64 weight_a, bool8 is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex*)NULL) { return Error::handle(name(), L"insertArcChild", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc* new_arc = new BiGraphArc(vertex_a, weight_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertChild(new_arc); // exit gracefully // return true; } // method: insertArcParent // // arguments: // BiGraphVertex* vertex: (input) the vertex to connect to // float64 weight: (input) the weight on the generated arc // bool8 is_epsilon: (input) is this an epsilon transition? // // return: a bool8 value indicating status // // this method inserts a weighted arc connecting this vertex to the input // vertex. // template bool8 BiGraphVertex::insertArcParent(BiGraphVertex* vertex_a, float64 weight_a, bool8 is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex*)NULL) { return Error::handle(name(), L"insertArcParent", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc* new_arc = new BiGraphArc(vertex_a, weight_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertParent(new_arc); // exit gracefully // return true; } // method: insertArcChild // // arguments: // BiGraphVertex* vertex: (input) the vertex to connect to // bool8 is_epsilon: (input) is this an epsilon transition? // // return: a bool8 value indicating status // // this method inserts an arc connecting this vertex to the input // vertex. // template bool8 BiGraphVertex::insertArcChild(BiGraphVertex* vertex_a, bool8 is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex*)NULL) { return Error::handle(name(), L"insertArcChild", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc* new_arc = new BiGraphArc(vertex_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertChild(new_arc); // exit gracefully // return true; } // method: insertArcParent // // arguments: // BiGraphVertex* vertex: (input) the vertex to connect to // bool8 is_epsilon: (input) is this an epsilon transition? // // return: a bool8 value indicating status // // this method inserts an arc connecting this vertex to the input // vertex. // template bool8 BiGraphVertex::insertArcParent(BiGraphVertex* vertex_a, bool8 is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex*)NULL) { return Error::handle(name(), L"insertArcParent", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc* new_arc = new BiGraphArc(vertex_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertParent(new_arc); // exit gracefully // return true; } // method: removeArcChild // // arguments: // BiGraphVertex* vertex: (input) the vertex to unlink from // // return: a bool8 value indicating status // // this method unlinks this vertex from the input vertex. if the BiGraph is // not directed, then an arc from the input vertex is removed as well // template bool8 BiGraphVertex::removeArcChild(BiGraphVertex* vertex_a) { // make sure the list is not empty // if (this->isEmptyChild()) { return false; } // save the current state // this->setMarkChild(); // find the input vertex in the adjacency list by looping over all arcs // BiGraphArc* tmp_item = (BiGraphArc*)NULL; if (this->gotoFirstChild()) { tmp_item = this->getCurrChild(); } // declare temporary objects // BiGraphVertex* tmp_vert = (BiGraphVertex*) NULL; // loop over each element and look for the input vertex // bool8 vertex_found = false; while ((tmp_item != (BiGraphArc*)NULL) && !vertex_found) { // get the vertex out of the arc // tmp_vert = tmp_item->getVertex(); // check to see if the found vertex is the one we are looking for // if (tmp_vert == vertex_a) { vertex_found = true; } else { if (this->gotoNextChild()) { tmp_item = this->getCurrChild(); } else { tmp_item = (BiGraphArc*)NULL; } } } // if we found the vertex then break the arcs, else return an error. // if (vertex_found) { // if the found vertex was at the current node position then remove the // node // if (this->getMarkChild() == tmp_item) { // remove the arc from the graph // bool8 status = false; BiGraphArc* graph_arc; status = removeChild(graph_arc); delete graph_arc; if (!status) { return false; } } else { // remove the node // bool8 status = false; BiGraphArc* graph_arc; status = removeChild(graph_arc); delete graph_arc; if (!status) { return false; } } } else { return false; } // restore the saved state // this->gotoMarkChild(); // exit gracefully // return true; } // method: removeArcParent // // arguments: // BiGraphVertex* vertex: (input) the vertex to unlink from // // return: a bool8 value indicating status // // this method unlinks this vertex from the input vertex. if the BiGraph is // not directed, then an arc from the input vertex is removed as well // template bool8 BiGraphVertex::removeArcParent(BiGraphVertex* vertex_a) { // make sure the list is not empty // if (this->isEmptyParent()) { return false; } // save the current state // this->setMarkParent(); // find the input vertex in the adjacency list by looping over all arcs // BiGraphArc* tmp_item = (BiGraphArc*)NULL; if (this->gotoFirstParent()) { tmp_item = this->getCurrParent(); } // declare temporary objects // BiGraphVertex* tmp_vert = (BiGraphVertex*) NULL; // loop over each element and look for the input vertex // bool8 vertex_found = false; while ((tmp_item != (BiGraphArc*)NULL) && !vertex_found) { // get the vertex out of the arc // tmp_vert = tmp_item->getVertex(); // check to see if the found vertex is the one we are looking for // if (tmp_vert == vertex_a) { vertex_found = true; } else { if (this->gotoNextParent()) { tmp_item = this->getCurrParent(); } else { tmp_item = (BiGraphArc*)NULL; } } } // if we found the vertex then break the arcs, else return an error. // if (vertex_found) { // if the found vertex was at the current node position then remove the // node // if (this->getMarkParent() == tmp_item) { // remove the arc from the graph // bool8 status = false; BiGraphArc* graph_arc; status = removeParent(graph_arc); delete graph_arc; if (!status) { return false; } } else { // remove the node // bool8 status = false; BiGraphArc* graph_arc; status = removeParent(graph_arc); delete graph_arc; if (!status) { return false; } } } else { return false; } // restore the saved state // this->gotoMarkParent(); // exit gracefully // return true; } // method: removeArcChild // // arguments: none // // return: a bool8 value indicating status // // this method unlinks this vertex from the vertex linked by the current arc // in the list. if the BiGraph is not directed, then an arc from the found // vertex is removed as well // template bool8 BiGraphVertex::removeArcChild() { // if the adjacency list is empty then return false // if (isEmptyChild()) { return false; } // remove this arc // bool8 status = false; BiGraphArc* bigraph_arc; status = removeChild(bigraph_arc); delete bigraph_arc; // exit gracefully // return status; } // method: removeArcParent // // arguments: none // // return: a bool8 value indicating status // // this method unlinks this vertex from the vertex linked by the current arc // in the list. if the BiGraph is not directed, then an arc from the found // vertex is removed as well // template bool8 BiGraphVertex::removeArcParent() { // if the adjacency list is empty then return false // if (isEmptyParent()) { return false; } // remove this arc // bool8 status = false; BiGraphArc* bigraph_arc; status = removeParent(bigraph_arc); delete bigraph_arc; // exit gracefully // return status; } // method: removeAllArcsChild // // arguments: none // // return: a bool8 value indicating status // // this method removes all arcs extending from this vertex // template bool8 BiGraphVertex::removeAllArcsChild() { // declare a return value // bool8 return_val = true; // loop until no arcs remain // while (!isEmptyChild()) { // remove the forward link // bool8 status = false; BiGraphArc* bigraph_arc; status = removeChild(bigraph_arc); delete bigraph_arc; // exit gracefully // return_val &= status; } // exit gracefully // return return_val; } // method: removeAllArcsParent // // arguments: none // // return: a bool8 value indicating status // // this method removes all arcs extending from this vertex // template bool8 BiGraphVertex::removeAllArcsParent() { // declare a return value // bool8 return_val = true; // loop until no arcs remain // while (!isEmptyParent()) { // remove the forward link // bool8 status = false; BiGraphArc* bigraph_arc; status = removeParent(bigraph_arc); delete bigraph_arc; // exit gracefully // return_val &= status; } // exit gracefully // return return_val; } // method: isAdjacentChild // // arguments: // BiGraphVertex* vertex: (input) the vertex to find // // return: bool8 flag indicating whether or not the vertex was found // // this method finds the input vertex in the adjacency list for this // vertex // template bool8 BiGraphVertex::isAdjacentChild(BiGraphVertex* vertex_a) const { // make sure the list is not empty // if (isEmptyChild()) { return false; } // save the current state // this->setMarkChild(); // find the input vertex in the adjacency list by looping over all arcs // BiGraphArc* tmp_item = (BiGraphArc *)NULL; if (const_cast* >(this)->gotoFirstChild()) { tmp_item = this->getCurrChild(); } // declare temporary objects // BiGraphVertex* tmp_vert = (BiGraphVertex*) NULL; // loop over each element and look for the input vertex // bool8 vertex_found = false; while ((tmp_item != (BiGraphArc *)NULL) && !vertex_found) { // get the vertex out of the node // tmp_vert = tmp_item->getVertex(); // check to see if the found vertex is the one we are looking for // if (tmp_vert == vertex_a) { vertex_found = true; } else { if (const_cast* >(this)->gotoNextChild()) { tmp_item = this->getCurrChild(); } else { tmp_item = (BiGraphArc *)NULL; } } } // restore the saved state // const_cast* >(this)->gotoMarkChild(); // exit gracefully // return vertex_found; } // method: isAdjacentParent // // arguments: // BiGraphVertex* vertex: (input) the vertex to find // // return: bool8 flag indicating whether or not the vertex was found // // this method finds the input vertex in the adjacency list for this // vertex // template bool8 BiGraphVertex::isAdjacentParent(BiGraphVertex* vertex_a) const { // make sure the list is not empty // if (isEmptyParent()) { return false; } // save the current state // this->setMarkParent(); // find the input vertex in the adjacency list by looping over all arcs // BiGraphArc* tmp_item = (BiGraphArc *)NULL; if (const_cast* >(this)->gotoFirstParent()) { tmp_item = this->getCurrParent(); } // declare temporary objects // BiGraphVertex* tmp_vert = (BiGraphVertex*) NULL; // loop over each element and look for the input vertex // bool8 vertex_found = false; while ((tmp_item != (BiGraphArc *)NULL) && !vertex_found) { // get the vertex out of the node // tmp_vert = tmp_item->getVertex(); // check to see if the found vertex is the one we are looking for // if (tmp_vert == vertex_a) { vertex_found = true; } else { if (const_cast* >(this)->gotoNextParent()) { tmp_item = this->getCurrParent(); } else { tmp_item = (BiGraphArc *)NULL; } } } // restore the saved state // const_cast* >(this)->gotoMarkParent(); // exit gracefully // return vertex_found; } //--------------------------------------------------------------------------- // // class-specific public methods: // vertex comparison methods // //--------------------------------------------------------------------------- // method: compareVertices // // arguments: // const BiGraphVertex& compare_vertex: (input) the vertex to compare // // return: bool8 value indicating test of equivalence // // this method compares two vertices for equivalent structure // template bool8 BiGraphVertex::compareVertices(const BiGraphVertex& vertex_a) const { // declare the output variable // bool8 arc_equal = false; // check for null items in either vertex // if (this->item_d == (TObject*)NULL) { if (vertex_a.item_d != (TObject*)NULL) { return false; } } else if (vertex_a.item_d == (TObject*)NULL) { return false; } // make sure that the vertices have the same number of arcs // if (this->lengthChild() != vertex_a.lengthChild()) { // if the lengths are different then the number of arcs in the // vertex are different // return false; } // save the current states // this->setMarkChild(); vertex_a.setMarkChild(); // iterate over all arcs contained in the current vertex // bool8 more_nodes = const_cast< BiGraphVertex* >(this)->gotoFirstChild(); while (more_nodes) { // get the current arc associated with the vertex // arc_equal = false; BiGraphArc* this_arc = const_cast< BiGraphVertex* > (this)->getCurrChild(); // iterate over all arcs associated with the input vertex // bool8 more_nodes1 = const_cast< BiGraphVertex& >(vertex_a).gotoFirstChild(); while (more_nodes1) { // get the current arc associated with the vertex // BiGraphArc* input_arc = const_cast< BiGraphVertex& > (vertex_a).getCurrChild(); // check if the arcs are similar // if (this_arc->eq(*input_arc)) { arc_equal = true; } // get the next arc in the vertex // more_nodes1 = const_cast< BiGraphVertex& >(vertex_a).gotoNextChild(); } // if none of the arcs in the input vector are similar exit // if (!arc_equal) { const_cast< BiGraphVertex* >(this)->gotoMarkChild(); const_cast< BiGraphVertex& >(vertex_a).gotoMarkChild(); return false; } // get the next arc in the vertex // more_nodes = const_cast< BiGraphVertex* >(this)->gotoNextChild(); } // reset the current pointer and return true // const_cast< BiGraphVertex* >(this)->gotoMarkChild(); const_cast< BiGraphVertex& >(vertex_a).gotoMarkChild(); // make sure that the vertices have the same number of arcs // if (this->lengthParent() != vertex_a.lengthParent()) { // if the lengths are different then the number of arcs in the // vertex are different // return false; } // save the current states // this->setMarkParent(); vertex_a.setMarkParent(); // iterate over all arcs contained in the current vertex // more_nodes = const_cast< BiGraphVertex* >(this)->gotoFirstParent(); while (more_nodes) { // get the current arc associated with the vertex // arc_equal = false; BiGraphArc* this_arc = const_cast< BiGraphVertex* > (this)->getCurrParent(); // iterate over all arcs associated with the input vertex // bool8 more_nodes1 = const_cast< BiGraphVertex& >(vertex_a).gotoFirstParent(); while (more_nodes1) { // get the current arc associated with the vertex // BiGraphArc* input_arc = const_cast< BiGraphVertex& > (vertex_a).getCurrParent(); // check if the arcs are similar // if (this_arc->eq(*input_arc)) { arc_equal = true; } // get the next arc in the vertex // more_nodes1 = const_cast< BiGraphVertex& >(vertex_a).gotoNextParent(); } // if none of the arcs in the input vector are similar exit // if (!arc_equal) { const_cast< BiGraphVertex* >(this)->gotoMarkParent(); const_cast< BiGraphVertex& >(vertex_a).gotoMarkParent(); return false; } // get the next arc in the vertex // more_nodes = const_cast< BiGraphVertex* >(this)->gotoNextParent(); } // reset the current pointer and return true // const_cast< BiGraphVertex* >(this)->gotoMarkParent(); const_cast< BiGraphVertex& >(vertex_a).gotoMarkParent(); // exit gracefully // return true; } // end of include file // #endif