Vertex.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.5 $
00022 // $Date: 2005/11/10 01:07:59 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/graph/graph/Vertex.cpp,v $
00024                                                                         
00025 // Written: fmk 
00026 // Created: 11/96
00027 // Revision: A
00028 //
00029 // Description: This file contains the class implementation for Vertex.
00030 // Vertex is an element of a graph.
00031 //
00032 // What: "@(#) Vertex.C, revA"
00033 
00034 #include <Vertex.h>
00035 #include <Channel.h>
00036 #include <FEM_ObjectBroker.h>
00037 #include <Vector.h>
00038 
00039 Vertex::Vertex(int tag, int ref, double weight, int color)
00040 :TaggedObject(tag), myRef(ref), myWeight(weight), myColor(color), 
00041  myDegree(0), myTmp(0), myAdjacency(0, 8)
00042 {
00043 
00044 }    
00045 
00046 
00047 Vertex::Vertex(const Vertex &other) 
00048 :TaggedObject(other.getTag()), myRef(other.myRef), myWeight(other.myWeight), myColor(other.myColor), 
00049  myDegree(other.myDegree), myTmp(0), myAdjacency(other.myAdjacency)
00050 {
00051 
00052 }
00053 
00054 Vertex::~Vertex()
00055 {
00056 
00057 }    
00058 
00059 void 
00060 Vertex::setWeight(double newWeight) 
00061 { 
00062     myWeight = newWeight;
00063 }
00064 
00065 void 
00066 Vertex::setColor(int newColor) 
00067 {
00068     myColor = newColor;
00069 }
00070 
00071 void 
00072 Vertex::setTmp(int newTmp) 
00073 {
00074     myTmp = newTmp;
00075 }
00076 
00077 int 
00078 Vertex::getRef(void) const 
00079 {
00080     return myRef;
00081 }
00082 
00083 double
00084 Vertex::getWeight(void) const 
00085 {
00086     return myWeight;
00087 }
00088 
00089 int 
00090 Vertex::getColor(void) const
00091 {
00092     return myColor;
00093 }
00094 
00095 int 
00096 Vertex::getTmp(void) const
00097 {
00098     return myTmp;
00099 }
00100 
00101 int 
00102 Vertex::addEdge(int otherTag)
00103 {
00104     // don't allow itself to be added
00105     if (otherTag == this->getTag())
00106       return 0;
00107 
00108     // check the otherVertex has not already been added
00109     return myAdjacency.insert(otherTag);
00110 }
00111 
00112 
00113 int 
00114 Vertex::getDegree(void) const
00115 {
00116     return myDegree;
00117 }
00118 
00119 const ID &
00120 Vertex::getAdjacency(void) const
00121 {
00122     return myAdjacency;
00123 }
00124 
00125 void
00126 Vertex::Print(OPS_Stream &s, int flag)
00127 {
00128     s << this->getTag() << " " ;
00129     s << myRef << " ";
00130     if (flag == 1) 
00131         s << myWeight << " " ;
00132     else if (flag ==2) 
00133         s << myColor << " " ;
00134     else if (flag == 3)
00135         s << myWeight << " " << myColor << " " ;    
00136     else if (flag == 4)
00137       s << myWeight << " " << myColor << " " << myTmp << " " ;
00138 
00139     s << "ADJACENCY: " << myAdjacency;          
00140 }
00141 
00142 
00143 int 
00144 Vertex::sendSelf(int commitTag, Channel &theChannel)
00145 {
00146   // send the tag/ref/color/degree/tmp, an indication if weighted & size of adjacency
00147   static ID idData(7);
00148   idData(0) = this->getTag();
00149   idData(1) = myRef;
00150   idData(2) = myColor;
00151   idData(3) = myDegree;
00152   idData(4) = myTmp;
00153   if (myWeight == 0.0)
00154     idData(5) = 0;
00155   else
00156     idData(5) = 1;
00157   idData(6) = myAdjacency.Size();
00158 
00159   if (theChannel.sendID(0, commitTag, idData) < 0) {
00160     opserr << "Graph::sendSelf() - failed to receive the initial data\n";
00161     return -1;
00162   }
00163 
00164   // if weighted, send the weight
00165   if (myWeight != 0.0) {
00166     static Vector vectData(1);
00167     vectData(0) = myWeight;
00168     if (theChannel.sendVector(0, commitTag, vectData) < 0) {
00169       opserr << "Graph::rendSelf() - failed to receive the weight\n";
00170       return -2;
00171     }
00172   }    
00173 
00174   // finally send the adjacency
00175   if (theChannel.sendID(0, commitTag, myAdjacency) < 0) {
00176     opserr << "Graph::sendSelf() - failed to receive the adjacency data\n";
00177     return -1;
00178   }  
00179 
00180   return 0;
00181 }
00182 
00183 
00184 int 
00185 Vertex::recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker)
00186 {
00187   // recv the tag/ref/color/degree/tmp, an indication if weighted & size of adjacency
00188   static ID idData(7);
00189   if (theChannel.recvID(0, commitTag, idData) < 0) {
00190     opserr << "Graph::recvSelf() - failed to receive the initial data\n";
00191     return -1;
00192   }
00193   this->setTag(idData(0));
00194   myRef = idData(1);
00195   myColor = idData(2);
00196   myDegree = idData(3);
00197   myTmp = idData(4);
00198 
00199   // if weighted, receive the weight
00200   if (idData(5) == 1) {
00201     static Vector vectData(1);
00202     if (theChannel.recvVector(0, commitTag, vectData) < 0) {
00203       opserr << "Graph::recvSelf() - failed to receive the weight\n";
00204       return -2;
00205     }
00206     myWeight = vectData(0);
00207   }    
00208 
00209   // resize the adjacency & receive it
00210   //  myAdjacency[idData(6)-1] = 0;
00211   int *adjacencyData;
00212   adjacencyData = new int[idData[6]];
00213   myAdjacency.setData(adjacencyData, idData[6], true);
00214 
00215   if (theChannel.recvID(0, commitTag, myAdjacency) < 0) {
00216     opserr << "Graph::recvSelf() - failed to receive the initial data\n";
00217     return -3;
00218   }
00219   return 0;
00220 }

Generated on Mon Oct 23 15:05:12 2006 for OpenSees by doxygen 1.5.0