Browse code

Added copyright message to help. Implemented invalid edge addition to pattern guessing.

Zoltan Puskas authored on 25/11/2011 00:09:01
Showing 1 changed files

... ...
@@ -105,6 +105,7 @@ void subtree_to_file(const struct tree_node * const node,
105 105
 void print_summary(const struct tree_node * const root_node);
106 106
 void print_random_patterns(const struct tree_node * const root_node, int len);
107 107
 void fill_guess_matrix(char* nodelist, int block_matrix[][10]);
108
+void disable_guess_edge(char* edge, int block_matrix[][10]);
108 109
 
109 110
 /*
110 111
  * Main function, program entry.
... ...
@@ -119,12 +120,19 @@ int main(int argc, char *argv[])
119 120
     int gen_pattern_len = 0;
120 121
     FILE *pattern_file = NULL;
121 122
     char *guess_node_list;
123
+    int i, j;
122 124
 
123 125
     if (argc < 2) {
124
-        fprintf(stderr, "No arguments specified.\n");
125 126
         print_help(argv[0]);
126 127
     }
127 128
 
129
+    /* init all transitions to illegal in the guess matrix */
130
+    for(i=0; i<MAX_POINTS+1; i++) {
131
+        for(j=0; j<10; j++) {
132
+            guess_matrix[i][j] = -1;
133
+        }
134
+    }
135
+
128 136
     /* currently no arguments are accepted */
129 137
     while((opt = getopt(argc, argv, "sr:o:g:e:h")) != -1) {
130 138
         switch (opt) {
... ...
@@ -152,7 +160,7 @@ int main(int argc, char *argv[])
152 160
             guess_node_list = optarg;
153 161
             break;
154 162
         case 'e':
155
-            printf("Edge: %d\n", atoi(optarg));
163
+            disable_guess_edge(optarg, guess_matrix);
156 164
             break;
157 165
         case 'h':
158 166
         default:
... ...
@@ -223,6 +231,10 @@ int main(int argc, char *argv[])
223 231
 void print_help(const char* argv0)
224 232
 {
225 233
     fprintf(stderr,
234
+            "Aupatterns. (c) 2011 Zoltan Puskas <zoltan@sinustrom.info>\n");
235
+    fprintf(stderr,
236
+            "This software is provided under the 3-clause BSD licese.\n\n");
237
+    fprintf(stderr,
226 238
             "Usage: %s [-s] [-r LENGTH] [-o FILE] [-g NODES] [-e EDGE] [-h]\n",
227 239
             argv0);
228 240
     fprintf(stderr, "\n");
... ...
@@ -443,7 +455,8 @@ void print_summary(const struct tree_node * const root_node)
443 455
     }
444 456
     printf("-------------------------------------------\n");
445 457
     printf("Number of all available patterns: %d\n", sum);
446
-    printf("Number of valid patterns (length >= 4): %d\n", valid_sum);
458
+    printf("Number of valid patterns (length >= 4): %d (Bruteforce* %d mins)\n",
459
+            valid_sum, valid_sum/5);
447 460
     printf("(* assuming 5 tries in 30 seconds and then a 30 second timeout)\n");
448 461
 
449 462
     return;
... ...
@@ -492,14 +505,7 @@ void fill_guess_matrix(char* nodelist, int block_matrix[][10])
492 505
 {
493 506
     int nodes[MAX_POINTS] = {0};
494 507
     int i,j;
495
-    
496
-    /* init all transitions to illegal */
497
-    for(i=0; i<MAX_POINTS+1; i++) {
498
-        for(j=0; j<10; j++) {
499
-            block_matrix[i][j] = -1;
500
-        }
501
-    }
502
-
508
+     
503 509
     /* add nodes to be used of guessing */
504 510
     for(i=0, j=0; nodelist[i]!='\0'; i++)
505 511
     {
... ...
@@ -514,11 +520,45 @@ void fill_guess_matrix(char* nodelist, int block_matrix[][10])
514 520
     {
515 521
         for(j = 0; j < MAX_POINTS+1; j++)
516 522
         {
517
-            block_matrix[nodes[i]][nodes[j]] =
523
+            /* if not edge not disabled previously */
524
+            if (block_matrix[nodes[i]][nodes[j]] != -2)
525
+            {
526
+                block_matrix[nodes[i]][nodes[j]] =
518 527
                     pattern_block_matrix[nodes[i]][nodes[j]];
528
+            }
519 529
         }
520 530
     }
521 531
     
522 532
     return;
523 533
 }
534
+/*
535
+ * Disable specific edges in the guess matrix.
536
+ *
537
+ * \param edge edge to disable
538
+ * \param block_matrix the transition matrix to be modified
539
+ */
540
+void disable_guess_edge(char* edge, int block_matrix[][10])
541
+{
542
+    int node[2] = {0, 0};
543
+    int i;
544
+
545
+    /* extract edge information */
546
+    for (i=0; edge[i] != '\0' && i < 2; i++) {
547
+        node[i] = edge[i] - '0';
548
+        if (node[i] < 1 || node[i] > MAX_POINTS) {
549
+            node[i] = 0;
550
+        }
551
+    }
552
+
553
+    /* not a valid edge */
554
+    if (node[0] == node[1] || node[0] == 0 || node[1] == 0)
555
+    {
556
+        return;
557
+    }
558
+
559
+    block_matrix[node[0]][node[1]] = -2;
560
+    block_matrix[node[1]][node[0]] = -2;
561
+    
562
+    return;
563
+}
524 564