⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aoe网dlg.cpp

📁 AOE网算法
💻 CPP
字号:
// AOE网Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "AOE网.h"
#include "AOE网Dlg.h"

#include<stdio.h> 

#include<stdlib.h> 

#include<iomanip.h> 

#include <process.h> 

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif




/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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()

/////////////////////////////////////////////////////////////////////////////
// CAOEDlg dialog

CAOEDlg::CAOEDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAOEDlg::IDD, pParent)
{

	
	vexnode* Graphicmap=(vexnode*)malloc(eventnumber*sizeof(vexnode));

	//{{AFX_DATA_INIT(CAOEDlg)
	eventnumber = 0;
	activitynumber = 0;
	begin = 0;
	end = 0;
	duttem = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAOEDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAOEDlg)
	DDX_Control(pDX, IDC_LIST1, output);
	DDX_Text(pDX, IDC_EDIT1, eventnumber);
	DDX_Text(pDX, IDC_EDIT2, activitynumber);
	DDX_Text(pDX, IDC_EDIT3, begin);
	DDX_Text(pDX, IDC_EDIT4, end);
	DDX_Text(pDX, IDC_EDIT5, duttem);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAOEDlg, CDialog)
	//{{AFX_MSG_MAP(CAOEDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_LBUTTONDOWN()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAOEDlg message handlers

BOOL CAOEDlg::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 CAOEDlg::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 CAOEDlg::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 CAOEDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}




void CAOEDlg::OnButton2() 
{
	
	   UpdateData(1);

       static edgenode *p; 
		
       p=(edgenode*)malloc(sizeof(edgenode)); 

       p->adjvex =end-1; 

       p->dut =duttem; 

       Graphicmap[end-1].id ++; 

       p->next =Graphicmap[begin-1].link ; 

       Graphicmap[begin-1].link =p; 

	   static int k=0;
	   k++;
		
   // } 
	   static totaltime=0;

	   if(k==activitynumber)
		SearchMapPath(Graphicmap,eventnumber,activitynumber,totaltime); 

 } 



int CAOEDlg::SearchMapPath(vexnode* Graphicmap,int eventnumber,int activitynumber,int& totaltime) 

{ 

    int i,j,k,m=0; 

    int front=-1,rear=-1; 

    int* topologystack=(int*)malloc(eventnumber*sizeof(int));//用来保存拓扑排列 

    int* vl=(int*)malloc(eventnumber*sizeof(int));//用来表示在不推迟整个工程的前提下,VJ允许最迟发生的时间 

    int* ve=(int*)malloc(eventnumber*sizeof(int));//用来表示Vj最早发生时间 

    int* l=(int*)malloc(activitynumber*sizeof(int));//用来表示活动Ai最迟完成开始时间 

    int* e=(int*)malloc(activitynumber*sizeof(int));//表示活动最早开始时间 

    edgenode *p; 

    totaltime=0; 

    for(i=0;i<eventnumber;i++) ve[i]=0; 

    for(i=0;i<eventnumber;i++) 

    { 

       if(Graphicmap[i].id==0) 

       { 

         topologystack[++rear]=i; 

         m++; 

       } 

    } 

    while(front!=rear) 

    { 

       front++; 

       j=topologystack[front]; 

       m++; 

       p=Graphicmap[j].link ; 

       while(p) 

       { 

           k=p->adjvex ; 

           Graphicmap[k].id --; 

           if(ve[j]+p->dut >ve[k]) 

              ve[k]=ve[j]+p->dut ; 

           if(Graphicmap[k].id ==0) 

              topologystack[++rear]=k; 

           p=p->next ; 

       } 

    } 

    if(m<eventnumber) 

    { 
	   MessageBox("本程序所建立的图有回路不可计算出关键路径");

       return 0; 

    } 

    totaltime=ve[eventnumber-1]; 

    for(i=0;i<eventnumber;i++) 

       vl[i]=totaltime; 

    for(i=eventnumber-2;i>=0;i--) 

    { 

       j=topologystack[i]; 

       p=Graphicmap[j].link ; 

       while(p) 

       { 

           k=p->adjvex ; 

           if((vl[k]-p->dut )<vl[j]) 

              vl[j]=vl[k]-p->dut ; 

           p=p->next ; 

       } 

    } 

    i=0; 

	output.AddString("| 起点 | 终点 |  最早开始时间  |  最迟开始时间  | 差值 |   备注   |");

    for(j=0;j<eventnumber;j++) 

    { 

       p=Graphicmap[j].link; 

       while(p) 

       { 

           k=p->adjvex ; 

           e[++i]=ve[j]; 

           l[i]=vl[k]-p->dut; 

  
		   static CString value="";

		   value.Format("    %d      %d          %d                %d            %d   ",Graphicmap[j].projectname+1,Graphicmap[k].projectname+1,e[i],l[i],l[i]-e[i]);
 

           if(l[i]==e[i]) 

              value=value+" 关键活动 "; 
			
		   output.AddString(value) ;


           p=p->next ; 

       } 

    } 

	CString str;
    str.Format("整个工程所用的最短时间为:%d个单位时间\n",totaltime); 
	output.AddString(str);
	UpdateData(0);

    return 1; 

} 

void CAOEDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnLButtonDown(nFlags, point);
}

void CAOEDlg::OnButton1() 
{

	// TODO: Add your control notification handler code here
	UpdateData(1);
	Graphicmap=(vexnode*)malloc(eventnumber*sizeof(vexnode));
    for(int i=0;i<eventnumber;i++) 

    { 

       Graphicmap[i].projectname=i; 

       Graphicmap[i].id =0; 

       Graphicmap[i].link =NULL; 

    }   	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -