Advertisement
Guest User

Untitled

a guest
Jun 14th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. n := 5;
  2. k := 4;
  3.  
  4. nr_vertices := k*n - k + 1;
  5. nr_edges := Binomial(n,2) * k;
  6.  
  7. # label -1 implies unlabelled
  8. VertexLabels:=List([1..nr_vertices],i->-1);;
  9.  
  10. # the vertices are indexed 1..nr_vertices
  11. # with 1 being the center vertex, and the
  12. # rest split into sets of n-1 vertices
  13.  
  14. VertexSets:=[[1]];;
  15. c:=2;
  16. for i in [1..k] do
  17. VertexSets:=Concatenation(VertexSets,[List([c..c+n-2],i->i)]);
  18. c:=c+n-1;
  19. od;
  20.  
  21. EdgeSet:=[];;
  22. for i in [2..nr_vertices] do
  23. EdgeSet:=Concatenation(EdgeSet,[[i,1]]);
  24. od;
  25. for i in [1..k] do
  26. V:=VertexSets[i+1];
  27. for a in [1..Size(V)] do
  28. for b in [a+1..Size(V)] do
  29. EdgeSet:=Concatenation(EdgeSet,[[V[b],V[a]]]);
  30. od;
  31. od;
  32. od;
  33.  
  34. AddLabelBacktracking:=function(pos,diffs)
  35. local s,edge,d,new_diffs;
  36.  
  37. for s in [0..nr_edges] do
  38. # used this vertex label already
  39. if(ForAny([1..pos-1],i->VertexLabels[i]=s)) then continue; fi;
  40.  
  41. new_diffs:=[];
  42. for edge in Filtered(EdgeSet,e->e[1]=pos and e[2]<pos) do
  43. d := AbsoluteValue(s - VertexLabels[edge[2]]);
  44. new_diffs := Concatenation(new_diffs,[d]);
  45. od;
  46. # Print(new_diffs,"\n");
  47.  
  48. # labeling vertex pos with label s would repeat an edge value
  49. if(Intersection(new_diffs,diffs) <> []) then continue; fi;
  50. if(Size(new_diffs) <> Size(Set(new_diffs))) then continue; fi;
  51.  
  52. VertexLabels[pos] := s;
  53.  
  54. # Print(pos," ",diffs," ",new_diffs," ",VertexLabels,"\n");
  55.  
  56. if(pos < nr_vertices) then
  57. AddLabelBacktracking(pos+1,Union(new_diffs,diffs));
  58. else
  59. Print("found one!!! ",VertexLabels,"\n");
  60. fi;
  61.  
  62. VertexLabels[pos] := -1;
  63. od;
  64. end;;
  65.  
  66. AddLabelBacktracking(1,[]);
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement