| 329 | |
| 330 | |
| 331 | int |
| 332 | Graph::merge(Graph &other) { |
| 333 | |
| 334 | int result =0; |
| 335 | VertexIter &otherVertices = other.getVertices(); |
| 336 | Vertex *vertexPtrOther; |
| 337 | |
| 338 | // loop through other creating vertices if tag not the same in this |
| 339 | while ((vertexPtrOther = otherVertices()) != 0) { |
| 340 | int vertexTag = vertexPtrOther->getTag(); |
| 341 | Vertex *vertexPtr = this->getVertexPtr(vertexTag); |
| 342 | if (vertexPtr == 0) { |
| 343 | int vertexRef = vertexPtrOther->getRef(); |
| 344 | vertexPtr = new Vertex(vertexTag, vertexRef); |
| 345 | if (vertexPtr == 0) { |
| 346 | opserr << "Graph::merge - out of memory\n"; |
| 347 | return -1; |
| 348 | } |
| 349 | this->addVertex(vertexPtr, false); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | |
| 354 | // loop through other adding all the edges that exist in other |
| 355 | VertexIter &otherVertices2 = other.getVertices(); |
| 356 | while ((vertexPtrOther = otherVertices2()) != 0) { |
| 357 | int vertexTag = vertexPtrOther->getTag(); |
| 358 | const ID &adjacency = vertexPtrOther->getAdjacency(); |
| 359 | for (int i=0; i<adjacency.Size(); i++) { |
| 360 | if (this->addEdge(vertexTag, adjacency(i)) < 0) { |
| 361 | opserr << "Graph::merge - could not add an edge!\n"; |
| 362 | return -2; |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return result; |
| 368 | } |
| 369 | |
| 370 | |
| 371 | void |