1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
#(C) Graham Ellis, 2005-2006
#####################################################################
#####################################################################
InstallGlobalFunction(PolytopalGenerators,
function(GG,v)
local
Points, Vertices,
Action,
G, D, CG, N,
proj,
StringToVector,
input,
EdgeGenerators,
Faces, FacesFinal, FacesFn,
Index, IndexFn, tmplst,
Count,
tmp, x, w, i, y, p,
AppendTo, PrintTo,
tmpInlog, tmp2Inlog,tmp3Inlog, tmp4Inlog, tmpDir;
AppendTo:=HAP_AppendTo;
PrintTo:=HAP_PrintTo;
tmpDir:=DirectoryTemporary();
tmpInlog:=Filename(tmpDir,"tmpIn.log");
tmp2Inlog:=Filename(tmpDir,"tmp2In.log");
tmp3Inlog:=Filename(tmpDir,"tmp3In.log");
tmp4Inlog:=Filename(tmpDir,"tmp4In.log");
if not (IsPermGroup(GG) or IsMatrixGroup(GG)) then
Print("The group G must be a permutation or matrix group.\n");
return fail;
fi;
if IsPermGroup(GG) then
GG:=Image(PermToMatrixGroup(GG));
fi;
#####################################################################
Action:=function(g,V) ;
return g*V;; #This actually works!
end;
#####################################################################
G:=[];
tmplst:=[];
for x in GG do
w:=Action(x,v);
if not w in tmplst and not w=v then
Add(G,x);
Add(tmplst,w);
fi;
od;
D:=Length(v);
CG:=List([1..D], i->0); #CG will eventually be the centre of gravity
Points:=[]; #of the polytope.
Vertices:=[];
EdgeGenerators:=[];
###################### CALCULATE CENTRE OF GRAVITY ##################
for x in G do
Add(Points, Action(x,v));
od;
Points:=SSortedList(Points);
G:=[];
for w in Points do
for x in GG do
if Action(x,v)=w then Add(G,x); break; fi;
##if Action(x,v) in Points then Add(G,x); fi;
od;
od;
for w in Points do
CG:=CG+w;
od;
CG:=CG/Size(Points);
##################### CENTRE OF GRAVITY DONE ########################
################# PROJECTION ################################
N:=CG-v; #This might be parallel to an edge!!!
proj:=function(w)
local k, m ;
m:=(w-v)*N;
k:= ((CG-v)*N)/m;
return v+(k*(w-v));
end;
#############################################################
################## CALCULATE HULL OF PROJECTED POINTS ###############
for i in [1..Length(Points)] do
Points[i]:=proj(Points[i]);
od;
AppendTo(tmpInlog,"POINTS","\n");
for p in Points do
AppendTo(tmpInlog,1);
for i in [1..Length(p)] do
AppendTo(tmpInlog," ",p[i]);
od;
AppendTo(tmpInlog,"\n");
od;
#Exec(Concatenation(POLYMAKE_PATH,tmpInlog," beneath_beyond VERTICES > ",tmp3Inlog)); #Added "beneath_beyond"
Exec(Concatenation(POLYMAKE_PATH,tmpInlog," VERTICES > ",tmp3Inlog));
################# HULL CALCULATED ###################################
#####################################################################
StringToVector:=function(s)
local V,x,y;
V:=[]; y:=[];
for x in s do
if not x=' ' then Append(y,[x]);
else
Append(V,[Rat(Chomp(y))]); y:=[];
fi;
od;
Append(V,[Rat(Chomp(y))]);
return V{[2..Length(V)]};
end;
#####################################################################
################# READ VERTICES #####################################
input:=InputTextFile(tmp3Inlog);
tmp:=ReadLine(input);
tmp:=ReadLine(input);
i:=1;
while tmp[1]='1' do
Vertices[i]:=tmp;
tmp:=ReadLine(input);
i:=i+1;
od;
Apply(Vertices, s->StringToVector(s));
RemoveFile(tmp3Inlog);
################ VERTICES READ ######################################
################ RECOVER THE EDGE GENERATORS ########################
for w in Points do
p:=w;
if p in Vertices then
x:=G[Position(Points,w)];
EdgeGenerators[Position(Vertices,p)]:=x;
fi;
od;
################ EDGE GENERATORS RECOVERED ##########################
################ READ HASSE DIAGRAM #################################
Exec(Concatenation(POLYMAKE_PATH,tmpInlog," \"HASSE_DIAGRAM -> FACES\" >",tmp2Inlog));
#Exec(Concatenation(POLYMAKE_PATH,tmpInlog," \"HASSE_DIAGRAM -> DIMS\" >",tmp4Inlog));
Exec(Concatenation(POLYMAKE_PATH,tmpInlog," \"F_VECTOR\" >",tmp4Inlog));
RemoveFile(tmpInlog);
Filename(tmpDir,tmp);
RemoveFile(tmp);
Faces:=[];
Index:=[];
#############################################################
IndexFn:=function(tmp)
local V,x,y;
V:=[];
y:=[];
for x in tmp do
if (not x=' ') and (not x='\n') then Append(y,[x]);
else
Append(V,[Rat(Chomp(y))]); y:=[]; fi;
od;
return V;
end;
############################################################
############################################################
FacesFn:=function(tmp)
local V,x,y;
V:=[]; y:=[];
for x in tmp do
if (not x='<') and (not x='(') and (not x='{') then
if (not x=' ') and (not x='}') then Append(y,[x]);
else
if Length(y)>0 then
Append(V,[Rat(Chomp(y))]); y:=[]; fi; fi;
fi;
if x='}' then break; fi;
od;
if Length(V)>0 then
return [V];
else
return []; fi;
end;
############################################################
input:=InputTextFile(tmp4Inlog);
tmp:=ReadLine(input);
tmp:=ReadLine(input);
#Index:=IndexFn(tmp);
tmp:= IndexFn(tmp); #Modified July 2019
Index:=[1]; #because Polymake has
for i in [1..Length(tmp)] do #discontinued the DIMS
Add(Index,Index[i]+tmp[i]); #property.
od; #
RemoveFile(tmp4Inlog);
input:=InputTextFile(tmp2Inlog);
tmp:=ReadLine(input);
tmp:=ReadLine(input);
while Length(tmp)>2 do
Append(Faces, FacesFn(tmp));
tmp:=ReadLine(input);
od;
RemoveFile(tmp2Inlog);
if Length(Faces[1])=1 then
FacesFinal:=[];
for i in [1..Length(Index)-1] do
Append(FacesFinal,[[Index[i]..Index[i+1]-1]]);
od;
Append(FacesFinal,[[Index[i+1]]]);
FacesFinal:=(List(FacesFinal,x->List(x,i->Faces[i])));
else
FacesFinal:=[[1..Index[1]]];
for i in [1..Length(Index)-1] do
Append(FacesFinal,[[Index[i]+1..Index[i+1]]]);
od;
FacesFinal:=Reversed(List(FacesFinal,x->List(x,i->Faces[i])));
fi;
RemoveFile(tmpInlog);
RemoveFile(tmp2Inlog);
RemoveFile(tmp4Inlog);
RemoveFile(tmp3Inlog);
RemoveFile(Filename(tmpDir," "));
############### HASSE DIAGRAM READ ##################################
return rec(
generators:=EdgeGenerators,
hasseDiagram:=FacesFinal,
vector:=v);
end);
#####################################################################
|