read number of vertices and edges from commandline

main
josch 12 years ago
parent 5a8a5983b2
commit 6cb40f2011

@ -11,7 +11,7 @@
import std.stdio; import std.stdio;
int nVertices = 16; // number of vertices int nVertices = 0; // number of vertices
int start = 0; // starting vertex index int start = 0; // starting vertex index
int [][] Ak; // integer array size n of lists int [][] Ak; // integer array size n of lists
// ie the arcs from the vertex // ie the arcs from the vertex
@ -189,7 +189,8 @@ bool circuit(int v) { // based on Johnson s logical procedure CIRCUIT
return f; return f;
} }
void setupGlobals() { // presupposes nVertices is set up void setupGlobals(string[] args) { // presupposes nVertices is set up
nVertices = std.conv.parse!int(args[1]);
Ak.length = nVertices; // Ak[i][0] is the number of members, Ak[i][1]..Ak[i][n] ARE the members, i>0 Ak.length = nVertices; // Ak[i][0] is the number of members, Ak[i][1]..Ak[i][n] ARE the members, i>0
B.length = nVertices; // B[i][0] is the number of members, B[i][1]..B[i][n] ARE the members , i>0 B.length = nVertices; // B[i][0] is the number of members, B[i][1]..B[i][n] ARE the members , i>0
blocked.length = nVertices; // we use blocked [0]..blocked[n-1], i> = 0 blocked.length = nVertices; // we use blocked [0]..blocked[n-1], i> = 0
@ -199,38 +200,12 @@ void setupGlobals() { // presupposes nVertices is set up
blocked[i] = false; blocked[i] = false;
} }
addToList(Ak[0], 2); for (int i = 2; i < args.length; i++) {
addToList(Ak[0], 10); string[] vertices = std.array.split(args[i], ",");
addToList(Ak[0], 14); int v1 = std.conv.parse!int(vertices[0]);
addToList(Ak[1], 5); int v2 = std.conv.parse!int(vertices[1]);
addToList(Ak[1], 8); addToList(Ak[v1], v2);
addToList(Ak[2], 7); }
addToList(Ak[2], 9);
addToList(Ak[3], 3);
addToList(Ak[3], 4);
addToList(Ak[3], 6);
addToList(Ak[4], 5);
addToList(Ak[4], 13);
addToList(Ak[4], 15);
addToList(Ak[6], 13);
addToList(Ak[8], 0);
addToList(Ak[8], 4);
addToList(Ak[8], 8);
addToList(Ak[9], 9);
addToList(Ak[10], 7);
addToList(Ak[10], 11);
addToList(Ak[11], 6);
addToList(Ak[12], 1);
addToList(Ak[12], 1);
addToList(Ak[12], 2);
addToList(Ak[12], 10);
addToList(Ak[12], 12);
addToList(Ak[12], 14);
addToList(Ak[13], 3);
addToList(Ak[13], 12);
addToList(Ak[13], 15);
addToList(Ak[14], 11);
addToList(Ak[15], 0);
lengthHistogram.length = nVertices+1; // will use as [1]...[n] to histogram circuits by length lengthHistogram.length = nVertices+1; // will use as [1]...[n] to histogram circuits by length
// [0] for zero length circuits, which are impossible // [0] for zero length circuits, which are impossible
@ -246,8 +221,20 @@ void setupGlobals() { // presupposes nVertices is set up
} }
} }
int main() { /*
setupGlobals(); * to replicate the result from figure 10 in the paper, run the program as
* follows:
*
* ./circuits_hawick 16 0,2 0,10 0,14 1,5 1,8 2,7 2,9 3,3 3,4 3,6 4,5 4,13 \
* 4,15 6,13 8,0 8,4 8,8 9,9 10,7 10,11 11,6 12,1 12,1 12,2 12,10 12,12 \
* 12,14 13,3 13,12 13,15 14,11 15,0
*/
int main(string[] args) {
if (args.length < 3) {
std.stdio.writefln("usage: %s num_vertices [v1,v2...]", args[0]);
return 1;
}
setupGlobals(args);
stackClear(); stackClear();
start = 0; start = 0;
bool verbose = false; bool verbose = false;

Loading…
Cancel
Save