00001 #include "Annealer.h"
00002
00003 #include <fstream>
00004 #include <vector>
00005 #include <algorithm>
00006 #include <cmath>
00007 #include <cstdlib>
00008
00009 using namespace parquetfp;
00010
00011
00012 IslandNodes::IslandNodes()
00013 {
00014 }
00015
00016 IslandNodes::~IslandNodes()
00017 {
00018 delete &voltage;
00019 delete &groupID;
00020 delete [] &nodes;
00021 }
00022
00023 IslandNodes::IslandNodes(int node0, int node1, int group, int vdd)
00024 {
00025 nodes.push_back(node0);
00026 nodes.push_back(node1);
00027 groupID = group;
00028 voltage = vdd;
00029 }
00030
00031 void IslandNodes::setGroupID(int group)
00032 {
00033 groupID = group;
00034 }
00035
00036 SetOfVoltages::SetOfVoltages()
00037 {
00038 numCurrentGroups = 0;
00039 }
00040
00041 SetOfVoltages::~SetOfVoltages()
00042 {
00043 int i;
00044 delete &numCurrentGroups;
00045
00046 for(i=0;i<islandNodes.size();i++){
00047 delete &islandNodes[i];
00048 }
00049 delete [] &islandNodes;
00050 }
00051
00052
00053 void SetOfVoltages::addIslandNodes(int vdd, int node0, int node1)
00054 {
00055 for(int i = 0; i < islandNodes.size(); i++) {
00056 if(islandNodes[i].voltage == vdd){
00057 if((islandNodes[i].nodes[0] == node0) && (islandNodes[i].nodes[1] == node1))
00058 return;
00059 else if((islandNodes[i].nodes[1] == node0) && (islandNodes[i].nodes[0] == node1))
00060 return;
00061 }
00062 }
00063 islandNodes.push_back(IslandNodes(node0,node1,numCurrentGroups,vdd));
00064
00065 numCurrentGroups++;
00066 }
00067
00068 void SetOfVoltages::createVoltageIslands()
00069 {
00070 int i,j, currentID, currentVoltage, currentNode0, currentNode1;
00071 for(i = 0; i<islandNodes.size();i++){
00072 currentID = islandNodes[i].groupID;
00073 currentVoltage = islandNodes[i].voltage;
00074 currentNode0 = islandNodes[i].nodes[0];
00075 currentNode1 = islandNodes[i].nodes[1];
00076 for(j=0;j<islandNodes.size();j++){
00077 if( (islandNodes[j].voltage == currentVoltage) && (islandNodes[j].groupID != currentID) ){
00078 if( (islandNodes[j].nodes[0] == currentNode0) || (islandNodes[j].nodes[1] == currentNode0) ){
00079 islandNodes[j].setGroupID(currentID);
00080 if(islandNodes[j].nodes[0] == currentNode0){
00081 islandNodes[j].nodes.erase(islandNodes[j].nodes.begin() + 0);
00082 }
00083 else{
00084 islandNodes[j].nodes.erase(islandNodes[j].nodes.begin() + 1);
00085 }
00086 numCurrentGroups--;
00087 }
00088 else if( (islandNodes[j].nodes[0] == currentNode1) || (islandNodes[j].nodes[1] == currentNode1) ){
00089 islandNodes[j].setGroupID(currentID);
00090 if(islandNodes[j].nodes[0] == currentNode1){
00091 islandNodes[j].nodes.erase(islandNodes[j].nodes.begin() + 0);
00092 }
00093 else{
00094 islandNodes[j].nodes.erase(islandNodes[j].nodes.begin() + 1);
00095 }
00096 numCurrentGroups--;
00097 }
00098 }
00099 }
00100 }
00101 arrangeGroups();
00102
00103 }
00104
00105 void SetOfVoltages::printIslands()
00106 {
00107 int i,j,k,currentID,printVoltage=1;
00108 for(i=0;i<numCurrentGroups;i++){
00109 currentID = i;
00110 for(j=0;j<islandNodes.size();j++){
00111 if( (islandNodes[j].groupID == currentID) ){
00112 if(printVoltage){
00113 printVoltage = 0;
00114 cout << "nodes in voltage island " << islandNodes[j].voltage << endl;
00115 }
00116 for(k=0;k<islandNodes[j].nodes.size();k++){
00117 cout << islandNodes[j].nodes[k] << " ";
00118 }
00119 }
00120 }
00121 cout << endl;
00122 printVoltage = 1;
00123 }
00124 }
00125
00126 void SetOfVoltages::arrangeGroups()
00127 {
00128 int i,j,k,idCounter=islandNodes.size(),currentID;
00129 for(i=0;i<islandNodes.size();i++){
00130 currentID = islandNodes[i].groupID;
00131 if(currentID < islandNodes.size()){
00132 for(j=0;j<islandNodes.size();j++){
00133 if(islandNodes[j].groupID == currentID)
00134 islandNodes[j].groupID = idCounter;
00135 }
00136 idCounter++;
00137 }
00138 }
00139 for(i=0;i<islandNodes.size();i++){
00140 islandNodes[i].groupID -= islandNodes.size();
00141 }
00142 }
00143
00144 int SetOfVoltages::numIslandNodes()
00145 {
00146 int i, j, count=0;
00147
00148 for(i=0;i<islandNodes.size();i++){
00149 for(j=0;j<islandNodes[i].nodes.size();j++){
00150 count++;
00151 }
00152 }
00153
00154 return count;
00155 }
00156
00157 int SetOfVoltages::numIslandInGroup(int groupID)
00158 {
00159 int j, k, currentID, count;
00160
00161 currentID = groupID;
00162 count = 0;
00163 for(j=0;j<islandNodes.size();j++){
00164 if( (islandNodes[j].groupID == currentID) ){
00165 for(k=0;k<islandNodes[j].nodes.size();k++){
00166 count++;
00167 }
00168 }
00169 }
00170 return count;
00171 }
00172
00173 int SetOfVoltages::voltageInGroup(int groupID)
00174 {
00175
00176 int j, k, currentID;
00177
00178 currentID = groupID;
00179 for(j=0;j<islandNodes.size();j++){
00180 if( (islandNodes[j].groupID == currentID) ){
00181 return islandNodes[j].voltage;
00182 }
00183 }
00184
00185 }
00186
00187 int SetOfVoltages::maxIslandNodes()
00188 {
00189 int i, j, k, currentID, count=0, prev_count=0;
00190
00191 for(i=0;i<numCurrentGroups;i++){
00192 currentID = i;
00193 count = 0;
00194 for(j=0;j<islandNodes.size();j++){
00195 if( (islandNodes[j].groupID == currentID) ){
00196 for(k=0;k<islandNodes[j].nodes.size();k++){
00197 count++;
00198 }
00199 }
00200 }
00201 if(prev_count > count) count = prev_count;
00202 prev_count = count;
00203 }
00204
00205 return count;
00206 }
00207