void VertexBasedSegmenter::placeSeeds(int index){ regionCentroids[0] = index; clusterIndex[index] = 0; int count = 1; double *distFromSeeds = new double[mesh.getNumVertex()]; while (regionCentroids.size() < NCluster) { for(int iterVerts = 0; iterVerts<mesh.getNumVertex(); iterVerts++){ distFromSeeds[iterVerts] = 0.0; if(!regionCentroids.count(iterVerts)){ distFromSeeds[iterVerts] = mesh.getVertex(iterVerts).distance(mesh.getVertex(regionCentroids[0])); for(int k=1; k<regionCentroids.size(); k++){ if(distFromSeeds[iterVerts] > mesh.getVertex(iterVerts).distance(mesh.getVertex(regionCentroids[k]))) distFromSeeds[iterVerts] = mesh.getVertex(iterVerts).distance(mesh.getVertex(regionCentroids[k])); } } } vertexind furthest = indexOfMax(distFromSeeds); clusterIndex[furthest] = count; regionCentroids[count++] = furthest; //cout<<"Reg "<<count-1<<" vertex "<<regionCentroids[count-1]<<endl; } cout<<"Placed "<<regionCentroids.size()<<" centroids"<<endl; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(11) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main(void) {restartProgram: //宣告與定義(Declaration & Definition) //int array for testing int randArray[100]; //--------------------- //random function initialization //版本:1.00(2) srand((unsigned)time(NULL)); //now rand() is usable :D //rand() range: 0 ~ unsigned int MAX. //assign rand number//print value { // unsigned int assranC; // for(assranC = 0; assranC < 100; assranC++) { randArray[assranC] = rand() % 20; //print value printf("%u\t%u\n", assranC, randArray[assranC]); } } ////assign rand number//print value //callfunc indexOfMax(randArray, sizeof(randArray) / sizeof(int)); //pauseProgram if(pauseProgram()) { goto restartProgram; } //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
// Calculate the mapping order and mapping score void S2MP::calcMappingScore() { _mappingOrder.clearQuick(); // keep track of the number of matching weights equal to zero int coutnMinusOnes = 0; // find the position of each row's max matching weight for (int i = 0; i < (_sp1len - _sp1frst); i++) { // in the case of two matching Max weights, we take the first one int weightPos = indexOfMax(_w.getReference(i)); // set all mappings associated with a meanininglessly small weight to -1 if (_w.getReference(i).getUnchecked(weightPos) < 0.00001) { weightPos = -1; coutnMinusOnes += 1; } // store matching weight position i.e. max weight in this row _mappingOrder.add(weightPos); } // If there are no mappings, return with mappingScore = 0 if (coutnMinusOnes == _mappingOrder.size()) { _mappingScore = 0; return; } // Now detect conflicts/duplicates (two itemsets in sp1 mapped to the same itemset in sp2) for (int i = 0; i < (_sp1len - _sp1frst - 1); i++) { //if we have a none zero matching weight, find conflict and resolve if (_mappingOrder.getUnchecked(i) > -1) { for (int k = i + 1; k < (_sp1len - _sp1frst); k++) { if (_mappingOrder.getUnchecked(i) == _mappingOrder.getUnchecked(k)) solveConflict(i, k); } } } // set _mapping_score to the mean of the weights of the mapped itemsets and return double count = 0.0; double total = 0.0; for (int i = 0; i < _mappingOrder.size(); i++) { if (_mappingOrder.getUnchecked(i) > -1) { total += _w.getReference(i)[_mappingOrder.getUnchecked(i)]; count += 1.0; } } if (count != 0) { _mappingScore = total/count; } else { _mappingScore = 0.0; } }