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