Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n := 5;
- k := 4;
- nr_vertices := k*n - k + 1;
- nr_edges := Binomial(n,2) * k;
- # label -1 implies unlabelled
- VertexLabels:=List([1..nr_vertices],i->-1);;
- # the vertices are indexed 1..nr_vertices
- # with 1 being the center vertex, and the
- # rest split into sets of n-1 vertices
- VertexSets:=[[1]];;
- c:=2;
- for i in [1..k] do
- VertexSets:=Concatenation(VertexSets,[List([c..c+n-2],i->i)]);
- c:=c+n-1;
- od;
- EdgeSet:=[];;
- for i in [2..nr_vertices] do
- EdgeSet:=Concatenation(EdgeSet,[[i,1]]);
- od;
- for i in [1..k] do
- V:=VertexSets[i+1];
- for a in [1..Size(V)] do
- for b in [a+1..Size(V)] do
- EdgeSet:=Concatenation(EdgeSet,[[V[b],V[a]]]);
- od;
- od;
- od;
- AddLabelBacktracking:=function(pos,diffs)
- local s,edge,d,new_diffs;
- for s in [0..nr_edges] do
- # used this vertex label already
- if(ForAny([1..pos-1],i->VertexLabels[i]=s)) then continue; fi;
- new_diffs:=[];
- for edge in Filtered(EdgeSet,e->e[1]=pos and e[2]<pos) do
- d := AbsoluteValue(s - VertexLabels[edge[2]]);
- new_diffs := Concatenation(new_diffs,[d]);
- od;
- # Print(new_diffs,"\n");
- # labeling vertex pos with label s would repeat an edge value
- if(Intersection(new_diffs,diffs) <> []) then continue; fi;
- if(Size(new_diffs) <> Size(Set(new_diffs))) then continue; fi;
- VertexLabels[pos] := s;
- # Print(pos," ",diffs," ",new_diffs," ",VertexLabels,"\n");
- if(pos < nr_vertices) then
- AddLabelBacktracking(pos+1,Union(new_diffs,diffs));
- else
- Print("found one!!! ",VertexLabels,"\n");
- fi;
- VertexLabels[pos] := -1;
- od;
- end;;
- AddLabelBacktracking(1,[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement