00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <SwapHeavierToLighterNeighbours.h>
00039 #include <Graph.h>
00040 #include <VertexIter.h>
00041 #include <Vertex.h>
00042 #include <ID.h>
00043
00044
00045 SwapHeavierToLighterNeighbours::SwapHeavierToLighterNeighbours()
00046 :numReleases(1), factorGreater(1.0)
00047 {
00048
00049 }
00050
00051 SwapHeavierToLighterNeighbours::
00052 SwapHeavierToLighterNeighbours(double factGreater,
00053 int releases)
00054 :numReleases(releases),factorGreater(factGreater)
00055 {
00056 if (releases < 1)
00057 numReleases = 1;
00058 }
00059
00060
00061 SwapHeavierToLighterNeighbours::~SwapHeavierToLighterNeighbours()
00062 {
00063
00064 }
00065
00066 int
00067 SwapHeavierToLighterNeighbours::balance(Graph &theWeightedGraph)
00068 {
00069
00070 DomainPartitioner *thePartitioner = this->getDomainPartitioner();
00071 if (thePartitioner == 0) {
00072 opserr << "SwapHeavierToLighterNeighbours::balance";
00073 opserr << "- No DomainPartitioner has been set\n";
00074 return -1;
00075 }
00076
00077 int res = 0;
00078
00079 for (int ii=0; ii<numReleases; ii++) {
00080 VertexIter &theVertices = theWeightedGraph.getVertices();
00081 Vertex *vertexPtr;
00082 while ((vertexPtr = theVertices()) != 0) {
00083 int vertexTag = vertexPtr->getTag();
00084 double vertexLoad = vertexPtr->getWeight();
00085 const ID &adjacency = vertexPtr->getAdjacency();
00086 int size = adjacency.Size();
00087 for (int j=0; j<size; j++) {
00088 int otherVertexTag = adjacency(j);
00089 Vertex *otherVertexPtr
00090 = theWeightedGraph.getVertexPtr(otherVertexTag);
00091 double otherVertexLoad = otherVertexPtr->getWeight();
00092
00093 if (vertexLoad > otherVertexLoad && otherVertexLoad != 0)
00094 if (vertexLoad/otherVertexLoad > factorGreater) {
00095 res = thePartitioner->
00096 swapBoundary(vertexTag,otherVertexTag);
00097 if (res < 0) {
00098 opserr << "WARNING SwapHeavierToLighterNeighbours";
00099 opserr << "::balance - DomainPartitioner returned ";
00100 opserr << res << endln;
00101 return res;
00102 }
00103 }
00104
00105 if (vertexLoad != 0 && otherVertexLoad == 0) {
00106 res = thePartitioner->
00107 swapBoundary(vertexTag,otherVertexTag);
00108 if (res < 0) {
00109 opserr << "WARNING SwapHeavierToLighterNeighbours";
00110 opserr << "::balance - DomainPartitioner returned ";
00111 opserr << res << endln;
00112 return res;
00113 }
00114 }
00115 }
00116 }
00117 }
00118
00119
00120 return res;
00121
00122 }