65,206
社区成员
发帖
与我相关
我的任务
分享
#include "IRGraph.h"
#include "../../Analysis/Sort/sorting.h"
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <string.h>
IRGraph::IRGraph()
{
this->filepath[0] = 0;
igraph_empty(&this->g, 0, 0);
this->nodeNames = NULL;
this->attrNames = NULL;
this->attrValues = NULL;
this->centrality = NULL;
this->clusterNum = 0;
this->membership = NULL;
this->clusterSize = NULL;
this->clusterSelectionStatusChanged = NULL;
this->nodeIsClusterCore = NULL;
this->distToCluster = NULL;
this->selected = NULL;
this->usedFocusKey = 0;
}
IRGraph::~IRGraph()
{
igraph_destroy(&g);
if (this->nodeNames != NULL)
delete [] this->nodeNames;
if (this->attrNames != NULL)
delete [] this->attrNames;
if (this->attrValues != NULL)
delete [] this->attrValues;
if (this->centrality != NULL)
delete [] this->centrality;
if (this->membership != NULL)
delete [] this->membership;
if (this->clusterSize != NULL)
delete [] this->clusterSize;
if (this->clusterSelectionStatusChanged != NULL)
delete [] this->clusterSelectionStatusChanged;
if (this->nodeIsClusterCore != NULL)
delete [] this->nodeIsClusterCore;
if (this->distToCluster != NULL)
delete [] this->distToCluster;
if (this->selected != NULL)
delete [] this->selected;
IPHash::iterator it;
it = nodeInFocusHash.begin();
while (it != nodeInFocusHash.end())
{
delete [] (bool *)(it->second);
it ++;
}
nodeInFocusHash.clear();
it = distToFocusHash.begin();
while (it != distToFocusHash.end())
{
delete [] (int *)(it->second);
it ++;
}
distToFocusHash.clear();
}
void IRGraph::LoadGraphEdgeList(char *filename)
{
strcpy(this->filepath, filename);
FILE *fp = fopen(filename, "r");
igraph_read_graph_edgelist(&g, fp, 0, 0);
fclose(fp);
this->nodeNum = igraph_vcount(&g);
this->edgeNum = igraph_ecount(&g);
// Assign some node information (label ...)
this->nodeNames = new char [this->nodeNum][128];
for (int i=0; i<this->nodeNum; i++)
sprintf(this->nodeNames[i], "Node%d", i);
}
void IRGraph::LoadGraphGML(char *filename)
{
strcpy(this->filepath, filename);
// Read graph information
FILE *fp = fopen(filename, "r");
igraph_read_graph_gml(&g, fp);
fclose(fp);
this->nodeNum = igraph_vcount(&g);
this->edgeNum = igraph_ecount(&g);
// Read node information (label attribute)
this->nodeNames = new char [this->nodeNum][128];
std::ifstream stream;
char line[1024];
int id = -1;
std::string s, name, value;
std::string::size_type index1, index2;
stream.open(filename);
while (!stream.eof())
{
stream.getline(line, 1024);
s = line;
index1 = s.find_first_not_of(' ');
index2 = s.find_last_not_of(' ');
if (index1 == std::string::npos || index2 == std::string::npos)
continue;
s = s.substr(index1, index2-index1+1);
index1 = s.find_first_of(' ');
if (index1 == std::string::npos)
continue;
name = s.substr(0, index1);
value = s.substr(index1+1);
if (value.at(0) == '\"' && value.at(value.length() - 1) == '\"')
value = value.substr(1, value.length() - 2);
if (name.compare("id") == 0)
id = atoi(value.c_str());
else if (name.compare("label") == 0)
{
if (id >=0 && id < this->nodeNum)
strcpy(this->nodeNames[id], value.c_str());
}
else if (name.compare("attribute") == 0)
{
if (id >=0 && id <= this->nodeNum)
{
int i = 0;
std::string::size_type p1, p2;
p1 = p2 = 0;
while (p2 != std::string::npos && i < this->attrNum)
{
p2 = value.find_first_of(' ', p1);
if (p2 != std::string::npos)
{
this->attrValues[id][i++] = atof(value.substr(p1, p2-p1).c_str());
p1 = p2 + 1;
}
else
this->attrValues[id][i++] = atof(value.substr(p1).c_str());
}
}
}
else if (name.compare("attribute_list") == 0)
{
std::string buf[128];
int n = 0;
std::string::size_type p1, p2;
p1 = p2 = 0;
while (p2 != std::string::npos)
{
p2 = value.find_first_of(' ', p1);
if (p2 != std::string::npos)
{
buf[n++] = value.substr(p1, p2-p1);
p1 = p2 + 1;
}
else
buf[n++] = value.substr(p1);
}
if (n > 0)
{
int i, j;
this->attrNum = n;
this->attrNames = new char [n][128];
for (i=0; i<n; i++)
strcpy(this->attrNames[i], buf[i].c_str());
this->attrValues = new double * [this->nodeNum];
for (i=0; i<this->nodeNum; i++)
{
this->attrValues[i] = new double [n];
for (j=0; j<n; j++)
this->attrValues[i][j] = 0.0;
}
}
}
}
stream.close();
}

bool IRGraph::IsClusterCore(int id)
{
return this->nodeIsClusterCore[id];
}
void IRGraph::CalDistToCluster()
{
int i, j, member;
int n = this->nodeNum;
if (this->distToCluster == NULL)
{
this->distToCluster = new int * [n];
for (i=0; i<n; i++)
this->distToCluster[i] = new int [this->clusterNum];
}
for (i=0; i<n; i++)
{
for (j=0; j<this->clusterNum; j++)
this->distToCluster[i][j] = 2 * n;
}
igraph_vs_t from;
igraph_matrix_t pathLen;
igraph_matrix_init(&pathLen, 1, n);
int len;
for (i=0; i<n; i++)
{
if (this->nodeIsClusterCore[i])
{
member = this->membership[i];
igraph_vs_1(&from, i);
igraph_shortest_paths(&g, &pathLen, from, IGRAPH_ALL);
for (j=0; j<n; j++)
{
if (MATRIX(pathLen, 0, j) > 2.0 * n)
len = 2 * n;
else
len = (int)(MATRIX(pathLen, 0, j) + 0.01);
if (len < this->distToCluster[j][member])
this->distToCluster[j][member] = len;
}
}
}
igraph_matrix_destroy(&pathLen);
}
int IRGraph::GetDistToCluster(int id, int clusterIndex)
{
return this->distToCluster[id][clusterIndex];
}
void IRGraph::ClearSelection()
{
for (int i=0; i<this->nodeNum; i++)
SetNodeSelected(i, false);
}
bool* IRGraph::GetSelection()
{
return this->selected;
}
void IRGraph::SetNodeSelected(int id, bool s)
{
if (this->selected[id] != s)
{
int member = this->GetNodeMembership(id);
wxASSERT(member >=0 && member <this->clusterNum);
this->clusterSelectionStatusChanged[member] = true;
}
this->selected[id] = s;
}
bool IRGraph::IsNodeSelected(int id)
{
return this->selected[id];
}
bool IRGraph::IsClusterSelectionStatusChanged(int clusterID)
{
wxASSERT(clusterID >=0 && clusterID <this->clusterNum);
return this->clusterSelectionStatusChanged[clusterID];
}
void IRGraph::SetClusterSelectionStatusChanged(int clusterID, bool s)
{
wxASSERT(clusterID >=0 && clusterID <this->clusterNum);
this->clusterSelectionStatusChanged[clusterID] = s;
}
int IRGraph::CreateFocusFromSelection()
{
bool *nodeIsFocused = new bool [this->nodeNum];
int *distance = new int [this->nodeNum];
int i, j, len;
for (i=0; i<this->nodeNum; i++)
{
nodeIsFocused[i] = this->selected[i];
distance[i] = 2 * this->nodeNum;
}
igraph_vs_t from;
igraph_matrix_t pathLen;
igraph_matrix_init(&pathLen, 1, this->nodeNum);
for (i=0; i<this->nodeNum; i++)
{
if (nodeIsFocused[i])
{
igraph_vs_1(&from, i);
igraph_shortest_paths(&this->g, &pathLen, from, IGRAPH_ALL);
for (j=0; j<this->nodeNum; j++)
{
if (MATRIX(pathLen, 0, j) > 2.0 * this->nodeNum)
len = 2 * this->nodeNum;
else
len = (int)(MATRIX(pathLen, 0, j) + 0.01);
if (len < distance[j])
distance[j] = len;
}
}
}
igraph_matrix_destroy(&pathLen);
this->nodeInFocusHash[usedFocusKey] = nodeIsFocused;
this->distToFocusHash[usedFocusKey] = distance;
usedFocusKey ++;
return usedFocusKey - 1;
}
void IRGraph::RemoveFocus(int keyIndex)
{
bool *nodeInFocusArray = (bool *)this->nodeInFocusHash[keyIndex];
if (nodeInFocusArray != NULL)
delete [] nodeInFocusArray;
this->nodeInFocusHash.erase(keyIndex);
int *distToFocusArray = (int *)this->distToFocusHash[keyIndex];
if (distToFocusArray != NULL)
delete [] distToFocusArray;
this->distToFocusHash.erase(keyIndex);
}
int IRGraph::GetFocusSize(int keyIndex)
{
int size = 0;
bool *nodeInFocusArray = (bool *)this->nodeInFocusHash[keyIndex];
if (nodeInFocusArray != NULL)
{
for (int i=0; i<this->nodeNum; i++)
{
if (nodeInFocusArray[i])
size++;
}
}
return size;
}
bool IRGraph::IsNodeInFocus(int id, int keyIndex)
{
bool *nodeInFocusArray = (bool *)this->nodeInFocusHash[keyIndex];
return (nodeInFocusArray != NULL) ? nodeInFocusArray[id] : false;
}
int IRGraph::GetDistToFocus(int id, int keyIndex)
{
int *distToFocusArray = (int *)this->distToFocusHash[keyIndex];
return (distToFocusArray != NULL) ? distToFocusArray[id] : 999999999;
}
IIHash IRGraph::FindNodeByName(std::string label)
{
IIHash ids;
int i, j;
for (int i=0; i<(int)label.size();++i)
label[i] = tolower(label[i]);
int size = GetNodeNum();
for (i = 0; i < size; i++)
{
std::string name = GetNodeName(i);
for (j = 0; j < (int)name.size(); ++j)
name[j] = tolower(name[j]);
if (name.find(label) != std::string::npos)
ids[i] = i;
}
return ids;
}
void IRGraph::SetAttrValue(int id, int i, double value)
{
this->attrValues[id][i] = value;
}
void IRGraph::CalCentrality()
{
igraph_arpack_options_t options;
igraph_vector_t igraph_centrality;
igraph_arpack_options_init(&options);
igraph_vector_init(&igraph_centrality, 0);
igraph_eigenvector_centrality(&g, &igraph_centrality, NULL, /*scale=*/1, /*weights=*/NULL, &options);
if (this->centrality != NULL)
delete [] this->centrality;
this->centrality = new double [this->nodeNum];
for (int i=0; i<this->nodeNum; i++)
this->centrality[i] = VECTOR(igraph_centrality)[i];
}
double IRGraph::GetNodeCentrality(int id)
{
return centrality[id];
}
void IRGraph::CalCluster()
{
if (this->membership != NULL)
delete [] this->membership;
this->membership = new int [this->nodeNum];
igraph_vector_t tmp_membership;
igraph_integer_t no;
igraph_vector_init(&tmp_membership, 0);
igraph_clusters(&g, &tmp_membership, NULL, &no, IGRAPH_WEAK);
if (no > 1) // if there are more than one component, don't do clustering
{
int member, i;
this->clusterNum = 0;
for (i=0; i<this->nodeNum; i++)
{
member = (int)(VECTOR(tmp_membership)[i] + 0.01);
this->membership[i] = member;
if (member > this->clusterNum)
this->clusterNum = member;
}
this->clusterNum ++;
igraph_vector_destroy(&tmp_membership);
}
else //there is one component, then do clustering
{
bool use_igraph_algorithm = false;
if (use_igraph_algorithm) // use the clustering algorithm in igraph
{
igraph_arpack_options_t options;
igraph_arpack_options_init(&options);
igraph_community_leading_eigenvector(&g, NULL, &tmp_membership, igraph_vcount(&g), &options);
int member, i;
this->clusterNum = 0;
for (i=0; i<this->nodeNum; i++)
{
member = (int)(VECTOR(tmp_membership)[i] + 0.01);
this->membership[i] = member;
if (member > this->clusterNum)
this->clusterNum = member;
}
this->clusterNum ++;
igraph_vector_destroy(&tmp_membership);
}
else //use MCL for clustering
{
char result[1024];
strcpy(result, this->filepath);
strcat(result, ".clu");
FILE *fp = fopen(result, "r");
if (fp == NULL)
{
char mclFile[1024], cmdline[2048];
strcpy(mclFile, this->filepath);
strcat(mclFile, ".mcl");
this->SaveSelection(mclFile);
sprintf(cmdline, "mcltool\\mcl.exe %s -o %s --abc", mclFile, result);
system(cmdline);
fp = fopen(result, "r");
}
char *line = new char [65536];
this->clusterNum = 0;
char seps[4];
strcpy(seps, " \t");
char *token, *next_token;
while (fgets(line, 65536, fp) != NULL)
{
token = strtok_s(line, seps, &next_token);
while (token != NULL)
{
this->membership[atoi(token)] = this->clusterNum;
token = strtok_s(NULL, seps, &next_token);
}
this->clusterNum ++;
}
fclose(fp);
}
}
}
void IRGraph::SortCluster(int sortMode)
{
int i, j;
if (this->clusterSize != NULL)
delete [] this->clusterSize;
this->clusterSize = new int [this->clusterNum];
if (sortMode == 1) // sort by average centrality, need number to get average value
{
for (i=0; i<this->clusterNum; i++)
this->clusterSize[i] = 0;
for (i=0; i<this->nodeNum; i++)
this->clusterSize[this->membership[i]] ++;
}
SortStruct *sortArray = new SortStruct[this->clusterNum];
for (i=0; i<this->clusterNum; i++)
{
sortArray[i].number = i;
sortArray[i].value = 0;
}
for (i=0; i<this->nodeNum; i++)
{
if (sortMode == 0) // sort by number of nodes in the cluster
sortArray[this->membership[i]].value += 1.0;
else if (sortMode == 1) // sort by average centrality
sortArray[membership[i]].value += centrality[i];
}
if (sortMode == 1) // sort by average centrality, need number to get average value
{
for (i=0; i<this->clusterNum; i++)
sortArray[i].value /= (double)this->clusterSize[i];
}
qsort(sortArray, this->clusterNum, sizeof(SortStruct), DecreaseSort);
for (i=0; i<this->nodeNum; i++)
{
for (j=0; j<this->clusterNum; j++)
{
if (this->membership[i] == sortArray[j].number)
{
this->membership[i] = j;
break;
}
}
}
delete [] sortArray;
// Reset cluster size since clusters are reordered
for (i=0; i<this->clusterNum; i++)
this->clusterSize[i] = 0;
for (i=0; i<this->nodeNum; i++)
this->clusterSize[this->membership[i]] ++;
// Reset clusterSelectionStatusChanged array
if (this->clusterSelectionStatusChanged != NULL)
delete [] this->clusterSelectionStatusChanged;
this->clusterSelectionStatusChanged = new bool [this->clusterNum];
for (i = 0; i < this->clusterNum; i++)
this->clusterSelectionStatusChanged[i] = true;
}
int IRGraph::GetClusterNum()
{
return this->clusterNum;
}
int IRGraph::GetClusterSize(int index)
{
return this->clusterSize[index];
}
int IRGraph::GetNodeMembership(int id)
{
return this->membership[id];
}
void IRGraph::CalClusterCore(double threshold)
{
if (this->nodeIsClusterCore == NULL)
this->nodeIsClusterCore = new bool [this->nodeNum];
int i;
double *maxCentrality = new double [this->clusterNum];
int *maxCentIndex = new int [this->clusterNum];
for (i=0; i<this->clusterNum; i++)
maxCentrality[i] = -100.0;
int member;
double cent1;
for (i=0; i<this->nodeNum; i++)
{
cent1 = this->centrality[i];
this->nodeIsClusterCore[i] = (cent1 > threshold);
member = this->membership[i];
if (maxCentrality[member] < cent1)
{
maxCentrality[member] = cent1;
maxCentIndex[member] = i;
}
}
// Each group has at least one core node. Set max centrality node as a core node.
for (i=0; i<this->clusterNum; i++)
{
this->nodeIsClusterCore[maxCentIndex[i]] = true;
}
delete [] maxCentrality;
delete [] maxCentIndex;
}
void IRGraph::LoadFamousGraph(char *name)
{
igraph_famous(&g, name);
this->nodeNum = igraph_vcount(&g);
this->edgeNum = igraph_ecount(&g);
}
void IRGraph::LoadAttrFromOkc(char *filename, int &node_num)
{
int i, j;
FILE *fp = fopen(filename, "r");
fscanf(fp, "%d%d", &this->attrNum, &node_num);
// Assign image file name
this->nodeNames = new char [node_num][128];
this->attrNames = new char [this->attrNum][128];
for (i=0; i<this->attrNum; i++)
fscanf(fp, "%s", this->attrNames[i]);
this->attrValues = new double * [node_num];
for (i=0; i<node_num; i++)
{
fscanf(fp, "%s", this->nodeNames[i]);
this->attrValues[i] = new double [this->attrNum];
for (j=0; j<this->attrNum; j++)
fscanf(fp, "%lf", &this->attrValues[i][j]);
}
fclose(fp);
}
void IRGraph::LoadGraphFromMatrix(char *filename, int n, double threshold)
{
strcpy(this->filepath, filename);
char graphFile[512];
strcpy(graphFile, "data\\temp_edgelist.txt");
FILE *fp1, *fp2;
fp1 = fopen(graphFile, "w");
fp2 = fopen(filename, "r");
int i, j;
char *p1, *p2;
char *buffer = new char [32768];
for (i=0; i<n; i++)
{
fgets(buffer, 32768, fp2);
p1 = buffer;
for (j=0; j<n; j++)
{
p2 = strchr(p1, ' ');
if (i < j)
{
if (p2 != NULL)
*p2 = 0;
if (atof(p1) < threshold)
fprintf(fp1, "%d %d\n", i, j);
}
p1 = p2 + 1;
}
}
fclose(fp1);
fclose(fp2);
delete [] buffer;
fp1 = fopen(graphFile, "r");
igraph_empty(&g, n, 0);
igraph_read_graph_edgelist(&g, fp1, n, 0);
this->nodeNum = igraph_vcount(&g);
this->edgeNum = igraph_ecount(&g);
fclose(fp1);
remove(graphFile);
}
void IRGraph::SaveSelection(char *filename)
{
char *suffix = strrchr(filename, '.');
if (suffix == NULL)
return;
if (strcmp(suffix, ".gml") == 0)
{
int i, j;
FILE *fp = fopen(filename, "w");
fprintf(fp, "Creator \"wxVisTool.exe\"\n");
fprintf(fp, "graph\n");
fprintf(fp, "[\n");
fprintf(fp, " directed 0\n");
if (this->attrNum > 0 && this->attrNames != NULL)
{
fprintf(fp, " attribute_list \"");
for (i=0; i<this->attrNum; i++)
{
if (i > 0)
fprintf(fp, " ");
fprintf(fp, "%s", this->attrNames[i]);
}
fprintf(fp, "\"\n");
}
int *newId = new int [this->nodeNum];
int id = 0;
for (i=0; i<this->nodeNum; i++)
{
if (this->selected[i])
{
newId[i] = id;
fprintf(fp, " node\n");
fprintf(fp, " [\n");
fprintf(fp, " id %d\n", id);
fprintf(fp, " label \"%s\"\n", this->nodeNames[i]);
fprintf(fp, " attribute \"");
for (j=0; j<this->attrNum; j++)
{
if (j > 0)
fprintf(fp, " ");
fprintf(fp, "%lf", this->attrValues[i][j]);
}
fprintf(fp, "\"\n");
fprintf(fp, " ]\n");
id++;
}
}
int *edges = new int [this->edgeNum * 2];
this->GetAllGraphEdges(edges);
for (i=0; i<this->edgeNum; i++)
{
if (this->selected[edges[i*2]] && this->selected[edges[i*2+1]])
{
fprintf(fp, " edge\n");
fprintf(fp, " [\n");
fprintf(fp, " source %d\n", newId[edges[i*2]]);
fprintf(fp, " target %d\n", newId[edges[i*2+1]]);
fprintf(fp, " ]\n");
}
}
fprintf(fp, "]\n");
fclose(fp);
delete [] newId;
delete [] edges;
}
else if (strcmp(suffix, ".mcl") == 0)
{
int *edges = new int [this->edgeNum * 2];
this->GetAllGraphEdges(edges);
FILE *fp = fopen(filename, "w");
for (int i=0; i<this->edgeNum; i++)
{
fprintf(fp, "%d %d 1.0\n", edges[i*2], edges[i*2+1]);
}
fclose(fp);
delete [] edges;
}
}
bool IRGraph::CreateIOV(std::string fileName)
{
if (this->attrNum <= 0 || this->attrNames == NULL)
return false;
int i, j, k;
//create okc file
std::string okcFile = fileName + ".okc";
std::ofstream outposfile(okcFile.c_str());
int dimNum = this->attrNum;
int itemNum = this->nodeNum;
outposfile << dimNum << " " << itemNum << std::endl;
for (i = 0; i < dimNum; i++)
outposfile << this->attrNames[i] << std::endl;
for (i = 0; i < itemNum; i++)
{
outposfile << this->nodeNames[i] << " ";
for (j = 0; j < dimNum; j++)
outposfile << this->attrValues[i][j] << " ";
outposfile << std::endl;
}
outposfile.close();
// create iov file
outposfile.open(fileName.c_str());
double **dis_matrix = new double *[itemNum];
for (i = 0; i < itemNum; i++)
dis_matrix[i] = new double[itemNum];
double sum1, sum2;
for (i = 0; i < itemNum; i++)
{
for (j = 0; j < itemNum; j++)
{
sum1 = 0;
sum2 = 0;
for (k = 0; k < dimNum; k++)
{
if (fabs(this->attrValues[i][k]-this->attrValues[j][k]) > 0.5)
sum1 += 1;
if ((this->attrValues[i][k] + this->attrValues[j][k]) > 0.5)
sum2 += 1;
}
if (sum2 < 0.5)
dis_matrix[i][j] = dis_matrix[j][i] = 1;
else
dis_matrix[i][j] = dis_matrix[j][i] = sum1/sum2;
}
}
for (i = 0; i < itemNum; i++)
{
for (j = 0; j < itemNum; j++)
outposfile << dis_matrix[i][j] << " ";
outposfile << std::endl;
}
outposfile.close();
for (i = 0; i < itemNum; i++)
{
delete [] dis_matrix[i];
}
delete [] dis_matrix;
}
void IRGraph::CalAll()
{
int i, j;
char result[1024];
strcpy(result, this->filepath);
strcat(result, ".res");
FILE *fp = fopen(result, "r");
if (fp == NULL)
{
CalCentrality();
CalCluster();
SortCluster(0);
CalClusterCore(-1.0);
CalDistToCluster();
fp = fopen(result, "w");
for (i=0; i<this->nodeNum; i++)
fprintf(fp, "%lf\n", this->centrality[i]);
fprintf(fp, "%d\n", this->clusterNum);
for (i=0; i<this->nodeNum; i++)
fprintf(fp, "%d\n", this->membership[i]);
for (i=0; i<this->clusterNum; i++)
fprintf(fp, "%d\n", this->clusterSize[i]);
for (i=0; i<this->nodeNum; i++)
fprintf(fp, "%d\n", this->nodeIsClusterCore[i]);
for (i=0; i<this->nodeNum; i++)
{
for (j=0; j<this->clusterNum; j++)
fprintf(fp, "%d\n", this->distToCluster[i][j]);
}
}
else
{
if (this->centrality != NULL)
delete [] this->centrality;
this->centrality = new double [this->nodeNum];
for (i=0; i<this->nodeNum; i++)
fscanf(fp, "%lf", &this->centrality[i]);
if (this->membership != NULL)
delete [] this->membership;
if (this->clusterSize != NULL)
delete [] this->clusterSize;
if (this->clusterSelectionStatusChanged != NULL)
delete [] this->clusterSelectionStatusChanged;
fscanf(fp, "%d", &this->clusterNum);
this->membership = new int [this->nodeNum];
for (i=0; i<this->nodeNum; i++)
fscanf(fp, "%d", &this->membership[i]);
this->clusterSize = new int [this->clusterNum];
for (i=0; i<this->clusterNum; i++)
fscanf(fp, "%d", &this->clusterSize[i]);
this->clusterSelectionStatusChanged = new bool [this->clusterNum];
for (i=0; i<this->clusterNum; i++)
this->clusterSelectionStatusChanged[i] = true;
if (this->nodeIsClusterCore == NULL)
this->nodeIsClusterCore = new bool [this->nodeNum];
for (i=0; i<this->nodeNum; i++)
fscanf(fp, "%d", &this->nodeIsClusterCore[i]);
if (this->distToCluster == NULL)
{
this->distToCluster = new int * [this->nodeNum];
for (i=0; i<this->nodeNum; i++)
this->distToCluster[i] = new int [this->clusterNum];
}
for (i=0; i<this->nodeNum; i++)
{
for (j=0; j<this->clusterNum; j++)
fscanf(fp, "%d", &this->distToCluster[i][j]);
}
}
fclose(fp);
this->selected = new bool [this->nodeNum];
for (int i=0; i<this->nodeNum; i++)
this->selected[i] = false;
}
char *IRGraph::GetFilePath()
{
return this->filepath;
}
igraph_t *IRGraph::GetIGraph()
{
return &g;
}
int IRGraph::GetGraphVCount()
{
return this->nodeNum;
}
int IRGraph::GetGraphECount()
{
return this->edgeNum;
}
void IRGraph::GetAllGraphEdges(int *edges)
{
int i;
igraph_es_t es;
igraph_eit_t eit;
igraph_integer_t eid, from, to;
igraph_es_all(&es, IGRAPH_EDGEORDER_FROM);
igraph_eit_create(&g, es, &eit);
i = 0;
while (!IGRAPH_EIT_END(eit)) {
eid = IGRAPH_EIT_GET(eit);
igraph_edge(&g, eid, &from, &to);
edges[i++] = from;
edges[i++] = to;
IGRAPH_EIT_NEXT(eit);
}
igraph_eit_destroy(&eit);
igraph_es_destroy(&es);
}
int IRGraph::GetNodeNum()
{
return this->nodeNum;
}
int IRGraph::GetEdgeNum()
{
return this->edgeNum;
}
char *IRGraph::GetNodeName(int id)
{
return this->nodeNames[id];
}
int IRGraph::GetAttrNum()
{
return this->attrNum;
}
char *IRGraph::GetAttrName(int i)
{
return this->attrNames[i];
}
double IRGraph::GetAttrValue(int id, int i)
{
return this->attrValues[id][i];
}