| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 671 人关注过本帖
标题:图论 k 壳分解的问题,希望大家能帮忙解决!感激不尽!
只看楼主 加入收藏
rayven
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-11-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
图论 k 壳分解的问题,希望大家能帮忙解决!感激不尽!
关于图论中k壳分解程序,求大神指点。。。我写的

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define E 4     //输入边(更改数据,要更改节点数)
#define kmax  2

FILE *fp;
FILE *fp3;

int A[E][2]={0};
int ks[kmax][999]={0};   
int k[E][E]={0};
int d[E]={0};
void main()
{
    int i,j,a,b=0,m=0,n,t;
    fp=fopen("自实验数据.txt","r");//输入网络.....................输入网络
    fp3=fopen("ks分解.txt","w");//result
   
       for (i=0;i<E;i++)
    {
        fscanf(fp,"%d %d",&A[i][0],&A[i][1]);
        A[i][0]=A[i][0]-1;
        A[i][1]=A[i][1]-1;
    }
    fclose(fp);

    for(i=0;i<E;i++)
    {
           k[A[i][0]][A[i][1]]=1;
           k[A[i][1]][A[i][0]]=1;   
    }//k转化为邻接矩阵,A为点邻矩阵                                 
         
               
    for(t=1;t<E;t++)
    {               
             for(m=0;m<E;m++)
             {
                 for(n=0;n<E;n++)
                   {
                     if(k[m][n]==1)
                         d[m]+=1;
                   }
               }//-------------求度      
       for(a=0;a<E;a++)
       {  
                    
             if(d[a]==t)
            {
                  for(i=a;i<E;i++)
                     {                        
                         if(d[i]==t)
                    {                          
                                    ks[t-1][b++]=i+1;
                               //-------------------------记录
                    for(i=a;i<E;i++)
                              {               
                            for(j=0;j<E;j++)
                                 {
                               if(d[i]==t)
                                      {
                                       if(k[i][j]==1)
                                      k[i][j]=0;
                                     k[j][i]=0;
                                      }
                                 }//------------------------改0   
                              }  
                                                   
                        }
                    }   
                  break;                                                                                                
                 }
                 
                 if(d[a]==t-1)
            {
                  for(i=a;i<E;i++)
                     {                        
                         if(d[i]==t-1)
                    {                          
                                    ks[t-2][b++]=i+1;
                               //-------------------------记录
                    for(i=a;i<E;i++)
                              {               
                            for(j=0;j<E;j++)
                                 {
                               if(d[i]==t-1)
                                      {
                                       if(k[i][j]==1)
                                      k[i][j]=0;
                                     k[j][i]=0;
                                      }
                                 }//------------------------改0   
                              }  
                                                   
                        }
                    }   
                   break;                                                                                                
                 }                                                                                                   
                 if(a==E-1)
                     break;
                 
             }         
   }        
   
//------------------------------------
        for(i=0;i<kmax;i++)
        {
            fprintf(fp3,"ks=%d层的节点有:",i+1);
            for(j=0;j<b;j++)
            {
                //if(ks[i][j]!=0)//
              fprintf(fp3,"%d",ks[i][j]);
            }
                fprintf(fp3,"\n");
        }
        fclose(fp3);
//输出ks层的节点
}
//-------------------------输出结果


结果有问题,但我不知道哪里错了,求指导!谢谢!
搜索更多相关主题的帖子: include result 网络 
2014-11-24 11:36
playyang123
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:70
专家分:332
注 册:2014-11-17
收藏
得分:20 
不好意思  貌似没看懂
2014-11-24 11:41
rayven
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-11-24
收藏
得分:0 
回复 2 楼 playyang123
这个程序好像是有问题的,你能不能编出k壳分解的程序,急用?
2014-12-04 19:53
巧若拙
Rank: 4
来 自:宁波余姚
等 级:业余侠客
威 望:1
帖 子:159
专家分:273
注 册:2014-8-24
收藏
得分:0 
什么是k 壳分解?
2014-12-04 21:32
rayven
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-11-24
收藏
得分:0 
复杂网络中的一个概念,和图论有关:图论中,根据节点的度(相邻的节点的个数)来进行分层,具体你可以百度一下。不过谢谢了,非常感谢!
2014-12-05 17:47
快速回复:图论 k 壳分解的问题,希望大家能帮忙解决!感激不尽!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026540 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved