标签:
可图化的度序列其表示的图并不唯一,即画出来的图有可能不是同构体,主要原因是由度序列产生生成矩阵的时候方法并不唯一。
例子:度序列 [3 4 2 3 4 2]
图1
图2
注意度数为3 的两个顶点在图1中并不连接,在图2中却相连,说明图1图2不是同构。
对于可图化序列的简单图绘制需要用到生成矩阵,表示了随着顶点数增加而图拓展的过程。距离如下,度序列为 ,其相应的度序列矩阵为
生成矩阵的第i行等于度序列矩阵的第i行减去它的第i+1行得到,若度序列矩阵出现负值,则该序列不可图。
对一定图顶点着色,正常着色法要求相邻顶点颜色不能相同,其需要的的最小颜色数目为该图的色数。
本程序采用最小度优先法对图进行着色,对度序列为[3 4 2 4 3 2]的两种不同图分布进行了实验,实验结果表明需要的最少色数都为4,结果与图论经典算法色数相同,没有最大度优先的Welsh-Powell算法好。
该序列的第一种图:
本算法最少正常色数为4,最大度优先的Welsh-Powell算法为3;
本算法最少正常色数为4,最大度优先的Welsh-Powell算法为4。
序列可图化判定、简单图绘制(需要用到生成矩阵)、顶点正常着色的MATLAB程序如下:
1 %2015.5.30 by anchor 2 %To judge a sequence is degree sequence or not and draw up a simple graph 3 %and color the vertex 4 5 clc;clear all;clear 6 7 %% ==================== Part 1: Input Sequence ==================== 8 fprintf(‘please input the sequence \n‘); 9 DegreeSeq = str2num(input(‘The sequence DegreeSeq:‘,‘S‘)); 10 %Input sequence from txt 11 DegreeSeq=sort(DegreeSeq,‘descend‘); 12 LenDegreeSeq=length(DegreeSeq); 13 %% ==================== Part 2: Preliminary Judgment ==================== 14 if mod(sum(DegreeSeq),2) == 1 || (DegreeSeq(1)>LenDegreeSeq-1 ||DegreeSeq(LenDegreeSeq)<0) 15 disp(‘this sequence is not degree sequence‘); 16 return; 17 end 18 %% ==================== Part 3: Degree Matrix & Generative Matrix ==================== 19 %acoording to the theorem but no descending sort 20 DegreeMat=zeros(LenDegreeSeq,LenDegreeSeq); 21 GenerativeMat = zeros(LenDegreeSeq,LenDegreeSeq); 22 DegreeMat(1,:)=DegreeSeq; 23 for i = 1:LenDegreeSeq-1 24 MaxDegree=max(DegreeSeq); 25 LocMaxDegree=(find(DegreeSeq==MaxDegree,1)); 26 DegreeSeq(LocMaxDegree)=0; 27 location = MaxNLocation(DegreeSeq,MaxDegree); 28 DegreeSeq(location)=DegreeSeq(location)-1; 29 DegreeMat(i+1,:)=DegreeSeq; 30 if min(DegreeMat(i+1,:)) < 0 31 disp(‘this sequence is not degree sequence‘); 32 return; 33 end 34 GenerativeMat(i,:) = DegreeMat(i,:) - DegreeMat(i+1,:); 35 end 36 % GenerativeMat=[4 1 1 1 0 1;0 3 1 1 1 0;0 0 1 0 1 0;0 0 0 1 0 1;0 0 0 0 0 0;0 0 0 0 0 0]; 37 %% ==================== Part 4: Draw Up Simple Graph ==================== 38 if DegreeMat(LenDegreeSeq,LenDegreeSeq)==0 39 disp(‘this sequence is degree sequence‘); 40 end 41 42 [x,y]=NUniteCircle(LenDegreeSeq+1); 43 scatter(x,y,‘p‘,‘filled‘);%将每个点单独画成五角星 44 hold on; 45 46 for i = 1:LenDegreeSeq 47 j = LenDegreeSeq-i+1; 48 MaxDegree=max(GenerativeMat(j,:)); 49 if MaxDegree ~= 0 50 Temp = GenerativeMat(j,:); 51 LocMaxTemp = find(Temp == MaxDegree,1); 52 Temp(LocMaxTemp) = 0; 53 LocNonZero=find(Temp~=0); 54 for k=1:length(LocNonZero) 55 plot([x(LocNonZero(k)) x(LocMaxTemp)],[y(LocNonZero(k)) y(LocMaxTemp)]); 56 hold on; 57 end 58 end 59 end 60 pause; 61 disp(‘现在开始顶点着色‘); 62 %% ==================== Part 5: Color The Vertex ==================== 63 color = rand(GenerativeMat(1,1)+1,3); 64 colorsequence = 1:(GenerativeMat(1,1)+1); 65 colorSchedule = 1; 66 for i = 1:LenDegreeSeq 67 j = LenDegreeSeq-i+1; 68 MaxDegree=max(GenerativeMat(j,:)); 69 if MaxDegree ~= 0 70 Temp = GenerativeMat(j,:); 71 LocMaxTemp = find(Temp == MaxDegree,1); 72 Temp(LocMaxTemp) = 0; 73 Color0Postion = max((find(Temp == 0))); 74 Color1Postion = find(Temp == 1); 75 colorSchedule = min(setdiff(colorsequence,VertexColo(Color1Postion))); 76 plot(x(LocMaxTemp),y(LocMaxTemp),‘p‘,‘color‘,color(colorSchedule,:),‘linewidth‘,3); hold on; 77 end 78 plot(x(j),y(j),‘p‘,‘color‘,color(colorSchedule,:),‘linewidth‘,3); hold on; 79 hold on; 80 VertexColo(j) = colorSchedule; 81 end
标签:
原文地址:http://www.cnblogs.com/LaoAnchor/p/4540460.html