Austin Schuh | 405fa6c | 2015-09-06 18:13:55 -0700 | [diff] [blame] | 1 | (* IOPolyhedra.m: written by Komei Fukuda; Version-980111 *) |
| 2 | |
| 3 | ReadPolyhedraData[filename_String]:= |
| 4 | Block[{rf,outlist={},row={},m,n,i,val,st=" ",ty}, |
| 5 | rf=OpenRead[filename]; |
| 6 | While[st=!=EndOfFile && st=!="begin", |
| 7 | st=Read[rf,String]; |
| 8 | ]; |
| 9 | {m,n,ty}=Read[rf,{Number,Number,Word}]; |
| 10 | st=Skip[rf,String]; |
| 11 | Print["m=", m,", n=",n, " type=", ty]; |
| 12 | Do[ |
| 13 | If[ty!="rational", |
| 14 | row=Read[rf,Table[Number,{n}]], |
| 15 | row=Read[rf,Table[Word,{n}]];row=ToExpression[row] |
| 16 | ]; |
| 17 | AppendTo[outlist,row], |
| 18 | {i,m} |
| 19 | ]; |
| 20 | Close[rf]; |
| 21 | outlist |
| 22 | ]; |
| 23 | |
| 24 | |
| 25 | ReadIncidenceData[filename_String]:= |
| 26 | Block[{rf,outlist={},row={},m,n,n1,i,val,st=" ",inc,colon}, |
| 27 | rf=OpenRead[filename]; |
| 28 | While[st=!=EndOfFile && st=!="begin", |
| 29 | st=Read[rf,String]; |
| 30 | ]; |
| 31 | {m,n,n1}=Read[rf,{Number,Number,Number}]; |
| 32 | Print["m=", m,", n=",n]; |
| 33 | Do[ |
| 34 | {inc}=Read[rf,{Number}]; |
| 35 | colon=Read[rf,{Word}]; |
| 36 | row=Read[rf,Table[Number,{Abs[inc]}]]; |
| 37 | If[inc>0, |
| 38 | AppendTo[outlist,row], |
| 39 | AppendTo[outlist,Complement[Range[n1],row]] |
| 40 | ], |
| 41 | {i,m} |
| 42 | ]; |
| 43 | Close[rf]; |
| 44 | outlist |
| 45 | ]; |
| 46 | |
| 47 | |
| 48 | ReadAdjacencyData[filename_String]:= |
| 49 | Block[{rf,outlist={},row={},v,num,i,val,st=" ",deg,colon}, |
| 50 | rf=OpenRead[filename]; |
| 51 | While[st=!=EndOfFile && st=!="begin", |
| 52 | st=Read[rf,String]; |
| 53 | ]; |
| 54 | {v}=Read[rf,{Number}]; |
| 55 | Print["v =", v]; |
| 56 | Do[ |
| 57 | {num, deg}=Read[rf,{Number, Number}]; |
| 58 | colon=Read[rf,{Word}]; |
| 59 | If[deg >0, row=Read[rf,Table[Number,{deg}]], row={}]; |
| 60 | AppendTo[outlist,row], |
| 61 | {i,v} |
| 62 | ]; |
| 63 | Close[rf]; |
| 64 | outlist |
| 65 | ]; |
| 66 | |
| 67 | |
| 68 | WritePolyhedraIne[a_List,b_List,filename_String,type_String:"real"]:= |
| 69 | Block[{wf,m,n,i,j,str}, |
| 70 | wf=OpenWrite[filename]; |
| 71 | {m,n}=Dimensions[a]; |
| 72 | Write[wf,OutputForm["H-representation"]]; |
| 73 | Write[wf,OutputForm["begin"]]; |
| 74 | Write[wf,m,OutputForm[" "],n+1,OutputForm[" "],OutputForm[type]]; |
| 75 | Do[ |
| 76 | str=""; |
| 77 | Do[ |
| 78 | If[j==0, |
| 79 | str=StringJoin[str," ",ToString[b[[i]]]], |
| 80 | str=StringJoin[str," ",ToString[-a[[i,j]],FormatType->InputForm]] |
| 81 | ], |
| 82 | {j,0,n} |
| 83 | ]; |
| 84 | Write[wf,OutputForm[str]], |
| 85 | {i,m} |
| 86 | ]; |
| 87 | Write[wf,OutputForm["end"]]; |
| 88 | Write[wf,OutputForm["incidence"]]; |
| 89 | Write[wf,OutputForm["input_incidence"]]; |
| 90 | Write[wf,OutputForm["input_adjacency"]]; |
| 91 | Write[wf,OutputForm["adjacency"]]; |
| 92 | Close[wf]; |
| 93 | ]; |
| 94 | |
| 95 | VEtoIne[a_List,b_List,filename_String]:=WritePolyhedraIne[a,b,filename]; |
| 96 | |
| 97 | WritePolyhedraExt[a_List,filename_String,type_String:"real"]:= |
| 98 | Block[{wf,m,n,i,j,str}, |
| 99 | wf=OpenWrite[filename]; |
| 100 | {m,n}=Dimensions[a]; |
| 101 | Write[wf,OutputForm["V-representation"]]; |
| 102 | Write[wf,OutputForm["begin"]]; |
| 103 | Write[wf,m,OutputForm[" "],n+1,OutputForm[" "],OutputForm[type]]; |
| 104 | Do[ |
| 105 | str=""; |
| 106 | Do[ |
| 107 | If[j==0, |
| 108 | str=StringJoin[str," ",ToString[1]], |
| 109 | str=StringJoin[str," ",ToString[a[[i,j]],FormatType->InputForm]] |
| 110 | ], |
| 111 | {j,0,n} |
| 112 | ]; |
| 113 | Write[wf,OutputForm[str]], |
| 114 | {i,m} |
| 115 | ]; |
| 116 | Write[wf,OutputForm["end"]]; |
| 117 | Write[wf,OutputForm["hull"]]; |
| 118 | Write[wf,OutputForm["incidence"]]; |
| 119 | Write[wf,OutputForm["input_incidence"]]; |
| 120 | Write[wf,OutputForm["input_adjacency"]]; |
| 121 | Write[wf,OutputForm["adjacency"]]; |
| 122 | Close[wf]; |
| 123 | ]; |