1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
bool CSOINN::SaveNetworkData(const char *fileName)
{
HANDLE hFile;
DWORD dwWriteSize;
int i, nodeNum, edgeNum;
hFile = CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return false;
}
// SOINN data
WriteFile(hFile, &(this->m_dimension), sizeof(int), &dwWriteSize, NULL);// m_dimension
WriteFile(hFile, &(this->m_lambda), sizeof(int), &dwWriteSize, NULL); // m_lambda
WriteFile(hFile, &(this->m_ageMax), sizeof(int), &dwWriteSize, NULL); // m_ageMax
WriteFile(hFile, &(this->m_classNum), sizeof(int), &dwWriteSize, NULL); // m_classNum
WriteFile(hFile, &(this->m_inputNum), sizeof(int), &dwWriteSize, NULL); // m_inputNum
// Node data
nodeNum = (int)m_nodeInfo.size();
WriteFile(hFile, &nodeNum, sizeof(int), &dwWriteSize, NULL);// nodeNum
for (i=0; i<nodeNum; i++)
{
WriteFile(hFile, this->m_nodeInfo[i].m_signal, sizeof(double)*m_dimension, &dwWriteSize, NULL); //m_signal
WriteFile(hFile, this->m_nodeInfo[i].m_neighbor, sizeof(int)*CNode::MAX_NEIGHBOR, &dwWriteSize, NULL); //m_neighbor
WriteFile(hFile, &(this->m_nodeInfo[i].m_neighborNum), sizeof(int), &dwWriteSize, NULL); //m_neighborNum
WriteFile(hFile, &(this->m_nodeInfo[i].m_learningTime), sizeof(int), &dwWriteSize, NULL); //m_learningTime
WriteFile(hFile, &(this->m_nodeInfo[i].m_classID), sizeof(int), &dwWriteSize, NULL); // m_classID
//WriteFile(hFile, &(this->m_nodeInfo[i].m_dimension), sizeof(int), &dwWriteSize, NULL); //m_dimension
}
// Edge data
edgeNum = (int)m_edgeInfo.size();
WriteFile(hFile, &edgeNum, sizeof(int), &dwWriteSize, NULL);// edgeNum
for (i=0; i<edgeNum; i++)
{
WriteFile(hFile, &(this->m_edgeInfo[i].m_from), sizeof(int), &dwWriteSize, NULL); // m_from
WriteFile(hFile, &(this->m_edgeInfo[i].m_to), sizeof(int), &dwWriteSize, NULL); // m_to
WriteFile(hFile, &(this->m_edgeInfo[i].m_age), sizeof(int), &dwWriteSize, NULL); // m_age
}
CloseHandle(hFile);
return true;
}
int _tmain(int argc, _TCHAR* argv[]){
SaveNetworkData(test);
return 0;
}
|