?? test3dlg.cpp
字號:
// TEST3Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "TEST3.h"
#include "TEST3Dlg.h"
#include "math.h"
#include "time.h"
#include "memory.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
typedef struct Side{// 路徑中的節點
int point; // 節點編號
struct Side *next;
}DefSide;
typedef struct Result{// 最短路徑屬性
int flag; // 標記
int start; // 路徑的起始點,(除源點)
int totalValue; // 整條路徑的總權值
DefSide *thead; // 路徑經過的各個節點
}DefResult;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTEST3Dlg dialog
CTEST3Dlg::CTEST3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTEST3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTEST3Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTEST3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTEST3Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTEST3Dlg, CDialog)
//{{AFX_MSG_MAP(CTEST3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, Onlength)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTEST3Dlg message handlers
BOOL CTEST3Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CTEST3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTEST3Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTEST3Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int m_Link1[600000]={0}; //存放連接邊的起點
int m_Link2[600000]={0}; //存放連接邊的終邊
int *m_Node;
int *m_OutDegree; //存放節點的出度、入度
int *m_InDegree;
int *m_OutWeight; //存放節點的出權、入權
int *m_InWeight;
int *m_NodeWeight; //存放點權
int *m_InWeightVsNum,*m_OutWeightVsNum,*m_EdgeWeightVsNum,*m_NodeWeightVsNum;
int *m_DegreeVsNum,*m_OutDegreeVsNum,*m_InDegreeVsNum; //存放網絡所有的邊
int *m_Edge;
int *m_Degree; //存放網絡節點的度
int m_EdgeWeight[17][17]; //表示兩節點之間邊的權重,如m_EdgeWeight[i][j]表示 i和j之間的邊的權重值
long int m_Nodeptr=1; //存放網絡所有節點的當前存儲位置指針
float m_ClusterCo,m_MeanLean;
void CTEST3Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
FILE *fp,*fp1,*Node,*fp_outmeasure,*fp_out;
long int m_TotalDegree=0; //存放網絡所有節點的總度
long int m_TotalEdgeWeight=0; //存放網絡所有邊的總權重
long int m_Degreeptr=0; //存放網絡節點度的當前存儲位置指針
long int m_Edgeptr=0; //存放網絡所有邊的當前存儲位置指針
long int m_OutDegreeptr=0; //存放網絡節點出度的當前存儲位置指針
long int m_InDegreeptr=0; //存放網絡節點入度的當前存儲位置指針
//屏蔽點的代碼是用來計算度分布的
long int m_MaxDegree,m_MaxOutDegree,m_MaxInDegree,m_MaxInWeight,m_MaxOutWeight,m_MaxEdgeWeight,m_MaxNodeWeight;
m_MaxDegree=m_MaxOutDegree=m_MaxInDegree=m_MaxInWeight=m_MaxOutWeight=m_MaxEdgeWeight=m_MaxNodeWeight=0;
long int i,j;
char line[256],line2[256],line3[256];
int m_Temp;
m_Node=(int *)calloc(1,sizeof(int)*17);
m_Degree=(int *)calloc(1,sizeof(int)*17);
m_OutDegree=(int *)calloc(1,sizeof(int)*17);
m_InDegree=(int *)calloc(1,sizeof(int)*17);
m_NodeWeight=(int *)calloc(1,sizeof(int)*17);
m_OutWeight=(int *)calloc(1,sizeof(int)*17);
m_InWeight=(int *)calloc(1,sizeof(int)*17);
m_Edge=(int *)calloc(1,sizeof(int)*1200);
for(i=0;i<17433;i++)
{ m_Node[i]=0; //為網絡節點存儲區清零
m_Degree[i]=0; //為網絡節點度存儲區清零
m_OutDegree[i]=0; //為網絡節點出度存儲區清零
m_InDegree[i]=0; //為網絡節點入度存儲區清零
m_OutWeight[i]=0; //為網絡節點出度存儲區清零
m_InWeight[i]=0; //為網絡節點入度存儲區清零
}
for(i=0;i<1200000;i++)
m_Edge[i]=0; //為網絡邊存儲區清零
for(i=0;i<17433;i++)
{ for(j=0;j<17433;j++)
m_EdgeWeight[i][j]=0; //為網絡邊標志存儲區清零
}
fp=fopen("authorid.txt","r"); //打開文本文件authorid
if(fp==NULL)
{
printf("cannot open this file\n");
exit(0);
}
fp1=fopen("p_authorid.txt","r"); //打開文本文件p_authorid
if(fp==NULL)
{
printf("cannot open this file\n");
exit(0);
}
Node=fopen("node.txt","r"); //打開文本文件node
if(fp==NULL)
{
printf("cannot open this file\n");
exit(0);
}
//獲取authorid文本文件的數據,即連接的起點
i=0;
j=1;
fgets(line,256,fp);
while (!feof(fp))
{
m_Temp=atoi(line);
m_Link1[i]=m_Temp;
i++;
j++;
fgets(line,256,fp);
}
//獲取p_authorid文本文件的數據,即連接的終點
i=0;
fgets(line2,256,fp1);
while (!feof(fp1))
{
m_Temp=atoi(line2);
m_Link2[i]=m_Temp;
i++;
fgets(line2,256,fp1);
}
//獲取node文本文件的數據
i=0;
fgets(line3,256,Node);
while (!feof(Node))
{
m_Temp=atoi(line3);
m_Node[i]=m_Temp;
i++;
m_Nodeptr++;
fgets(line3,256,Node);
}
for(i=0;i<j;i++)
{
if(m_EdgeWeight[m_Link1[i]][m_Link2[i]]!=0) //看節點Link1[i]和節點Link2[i]之間是否已經存在邊
{
m_EdgeWeight[m_Link1[i]][m_Link2[i]]++; //如果已經存在,則只是把邊的權重進行加1
m_OutWeight[m_Link1[i]]++; //連接的起點的出權加1
m_InWeight[m_Link2[i]]++; //連接的終點的入權加1
}
else
{
m_EdgeWeight[m_Link1[i]][m_Link2[i]]=1; //為邊的權重賦值為1
m_OutDegree[m_Link1[i]]++; //連接的起點的出度加1
m_InDegree[m_Link2[i]]++; //連接的終點的入度加1
m_OutWeight[m_Link1[i]]++; //連接的起點的出權加1
m_InWeight[m_Link2[i]]++; //連接的終點的入權加1
m_TotalDegree=m_TotalDegree+2; //網絡總度加2
m_Degree[m_Link1[i]]++; //節點的度加1
m_Degree[m_Link2[i]]++; //節點的度加1
m_Edge[m_Edgeptr]=m_Link1[i]; //存儲邊
m_Edgeptr=m_Edgeptr+1;
m_Edge[m_Edgeptr]=m_Link2[i];
m_Edgeptr=m_Edgeptr+1; //邊的存儲位置指針加1
}
m_NodeWeight[m_Link1[i]]=m_InWeight[m_Link1[i]]+m_OutWeight[m_Link1[i]]; //計算點權,為點入權與點出權的和
m_NodeWeight[m_Link2[i]]=m_InWeight[m_Link2[i]]+m_OutWeight[m_Link2[i]]; //計算點權,為點入權與點出權的和
}
/* fp_outmeasure=fopen("Results.txt","w+");
fp_out=fopen("2.txt","w+");
for(i=0;i<41;i++)
{ fprintf(fp_outmeasure,"%d\n",m_InWeight[i]);
fprintf(fp_out,"%d\n",m_OutWeight[i]);}
{ for(j=0;j<41;j++)
if(m_EdgeWeight[i][j]!=0)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -