| 270 | |
| 271 | |
| 272 | int |
| 273 | Graph::merge(Graph &other) { |
| 274 | |
| 275 | int result =0; |
| 276 | VertexIter &otherVertices = other.getVertices(); |
| 277 | Vertex *vertexPtrOther; |
| 278 | |
| 279 | // loop through other creating vertices if tag not the same in this |
| 280 | while ((vertexPtrOther = otherVertices()) != 0) { |
| 281 | int vertexTag = vertexPtrOther->getTag(); |
| 282 | Vertex *vertexPtr = this->getVertexPtr(vertexTag); |
| 283 | if (vertexPtr == 0) { |
| 284 | int vertexRef = vertexPtrOther->getRef(); |
| 285 | vertexPtr = new Vertex(vertexTag, vertexRef); |
| 286 | if (vertexPtr == 0) { |
| 287 | opserr << "Graph::merge - out of memory\n"; |
| 288 | return -1; |
| 289 | } |
| 290 | this->addVertex(vertexPtr, false); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | |
| 295 | // loop through other adding all the edges that exist in other |
| 296 | VertexIter &otherVertices2 = other.getVertices(); |
| 297 | while ((vertexPtrOther = otherVertices2()) != 0) { |
| 298 | int vertexTag = vertexPtrOther->getTag(); |
| 299 | const ID &adjacency = vertexPtrOther->getAdjacency(); |
| 300 | for (int i=0; i<adjacency.Size(); i++) { |
| 301 | if (this->addEdge(vertexTag, adjacency(i)) < 0) { |
| 302 | opserr << "Graph::merge - could not add an edge!\n"; |
| 303 | return -2; |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | return result; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | void |