Пример #1
0
Parameters *GetParameters(int argc, char *argv[])
{
   Parameters *parameters;

   parameters = (Parameters *) malloc(sizeof(Parameters));
   if (parameters == NULL)
      OutOfMemoryError("GetParameters:parameters");

   // initialize default parameter settings
   parameters->directed = TRUE;
   parameters->labelList = AllocateLabelList();

   return parameters;
}
Пример #2
0
int main(int argc, char **argv)
{
   Graph *g1, *g2;
   LabelList *labelList = NULL;
   BOOLEAN directed = TRUE; // 'e' edges are considered directed
   ULONG maxVertices;
   VertexMap *mapping;
   double matchCost;

   if (argc != 3) 
   {
      fprintf(stderr, "usage: %s <graph file> <graph file>\n", argv[0]);
      exit(1);
   }
   labelList = AllocateLabelList();
   g1 = ReadGraph(argv[1], labelList, directed);
   g2 = ReadGraph(argv[2], labelList, directed);

   if (g1->numVertices < g2->numVertices) 
   {
      maxVertices = g2->numVertices;
      mapping = (VertexMap *) malloc(sizeof(VertexMap) * maxVertices);
      matchCost = InexactGraphMatch(g2, g1, labelList, MAX_DOUBLE, mapping);
   } 
   else 
   {
      maxVertices = g1->numVertices;
      mapping = (VertexMap *) malloc(sizeof(VertexMap) * maxVertices);
      matchCost = InexactGraphMatch(g1, g2, labelList, MAX_DOUBLE, mapping);
   }

   printf("Match Cost = %f\n", matchCost);
   PrintMapping(mapping, maxVertices);

   free(mapping);

   return 0;
}
Пример #3
0
Parameters *GetParameters(int argc, char *argv[])
{
   Parameters *parameters;
   int i;
   double doubleArg;
   ULONG ulongArg;
   BOOLEAN limitSet = FALSE;
   FILE *outputFile;
   ULONG argumentExists;

   parameters = (Parameters *) malloc(sizeof(Parameters));
   if (parameters == NULL)
      OutOfMemoryError("parameters");

   // initialize default parameter settings
   parameters->directed = TRUE;
   parameters->limit = 0;
   parameters->numBestSubs = 3;
   parameters->beamWidth = 4;
   parameters->valueBased = FALSE;
   parameters->prune = FALSE;
   strcpy(parameters->outFileName, "none");
   parameters->outputToFile = FALSE;
   parameters->outputLevel = 2;
   parameters->allowInstanceOverlap = FALSE;
   parameters->threshold = 0.0;
   parameters->evalMethod = EVAL_MDL;
   parameters->iterations = 1;
   strcpy(parameters->psInputFileName, "none");
   parameters->predefinedSubs = FALSE;
   parameters->minVertices = 1;
   parameters->maxVertices = 0; // i.e., infinity
   parameters->compress = FALSE;

   parameters->mdl = FALSE;
   parameters->mdlThreshold = 0.0;
   parameters->mpsThreshold = 0.0;
   parameters->prob = FALSE;
   parameters->mps = FALSE;
   parameters->maxAnomalousScore = MAX_DOUBLE;
   parameters->minAnomalousScore = 0.0;
   parameters->noAnomalyDetection = TRUE;
   parameters->norm = 1;
   parameters->similarity = 1.0;

   if (argc < 2)
   {
      fprintf(stderr, "input graph file name must be supplied\n");
      exit(1);
   }

   // process command-line options
   i = 1;
   while (i < (argc - 1))
   {
      if (strcmp(argv[i], "-beam") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg == 0) 
         {
            fprintf(stderr, "%s: beam must be greater than zero\n", argv[0]);
            exit(1);
         }
         parameters->beamWidth = ulongArg;
      }
      else if (strcmp(argv[i], "-compress") == 0)
      {
         parameters->compress = TRUE;
      }
      else if (strcmp(argv[i], "-eval") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if ((ulongArg < 1) || (ulongArg > 3)) 
         {
            fprintf(stderr, "%s: eval must be 1-3\n", argv[0]);
            exit(1);
         }
         parameters->evalMethod = ulongArg;
      } 
      else if (strcmp(argv[i], "-iterations") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         parameters->iterations = ulongArg;
      } 
      else if (strcmp(argv[i], "-limit") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg == 0) 
         {
            fprintf(stderr, "%s: limit must be greater than zero\n", argv[0]);
            exit(1);
         }
         parameters->limit = ulongArg;
         limitSet = TRUE;
      }
      else if (strcmp(argv[i], "-maxsize") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg == 0) 
         {
            fprintf(stderr, "%s: maxsize must be greater than zero\n", argv[0]);
            exit(1);
         }
         parameters->maxVertices = ulongArg;
      }
      else if (strcmp(argv[i], "-minsize") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg == 0) 
         {
            fprintf(stderr, "%s: minsize must be greater than zero\n", argv[0]);
            exit(1);
         }
         parameters->minVertices = ulongArg;
      }
      else if (strcmp(argv[i], "-nsubs") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg == 0) 
         {
            fprintf(stderr, "%s: nsubs must be greater than zero\n", argv[0]);
            exit(1);
         }
         parameters->numBestSubs = ulongArg;
      }
      else if (strcmp(argv[i], "-out") == 0) 
      {
         i++;
         strcpy(parameters->outFileName, argv[i]);
         parameters->outputToFile = TRUE;
      }
      else if (strcmp(argv[i], "-output") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if ((ulongArg < 1) || (ulongArg > 5)) 
         {
            fprintf(stderr, "%s: output must be 1-5\n", argv[0]);
            exit(1);
         }
         parameters->outputLevel = ulongArg;
      }
      else if (strcmp(argv[i], "-overlap") == 0) 
      {
         parameters->allowInstanceOverlap = TRUE;
      }
      else if (strcmp(argv[i], "-prune") == 0) 
      {
         parameters->prune = TRUE;
      }
      else if (strcmp(argv[i], "-ps") == 0) 
      {
         i++;
         strcpy(parameters->psInputFileName, argv[i]);
         parameters->predefinedSubs = TRUE;
      }
      else if (strcmp(argv[i], "-threshold") == 0) 
      {
         i++;
         sscanf(argv[i], "%lf", &doubleArg);
         if ((doubleArg < (double) 0.0) || (doubleArg > (double) 1.0))
         {
            fprintf(stderr, "%s: threshold must be 0.0-1.0\n", argv[0]);
            exit(1);
         }
         parameters->threshold = doubleArg;
      }
      else if (strcmp(argv[i], "-undirected") == 0) 
      {
         parameters->directed = FALSE;
      }
      else if (strcmp(argv[i], "-valuebased") == 0) 
      {
         parameters->valueBased = TRUE;
      }
      else if (strcmp(argv[i], "-mdl") == 0) 
      {
         i++;
         argumentExists = sscanf(argv[i], "%lf", &doubleArg);
         if ((argumentExists != 1) || (doubleArg <= (double) 0.0) || 
             (doubleArg >= (double) 1.0))
         {
            fprintf(stderr, "%s: Information Theoretic (MDL) threshold must be greater than 0.0 and less than 1.0\n", argv[0]);
            exit(1);
         }
         parameters->mdl = TRUE;
         parameters->mdlThreshold = doubleArg;
      }
      else if (strcmp(argv[i], "-prob") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg < 2)
         {
            fprintf(stderr, "%s: you must include a value greater than 1 as a parameter to the probabilistic anomaly detection method.\n", argv[0]);
            exit(1);
         }
         parameters->prob = TRUE;
         parameters->iterations = ulongArg;  // overrides -iterations specification
         parameters->maxAnomalousScore = 1.0;  // overrides default of MAX_DOUBLE
      }
      else if (strcmp(argv[i], "-mps") == 0) 
      {
         i++;
         argumentExists = sscanf(argv[i], "%lf", &doubleArg);
         if ((argumentExists != 1) || (doubleArg <= (double) 0.0) || 
             (doubleArg >= (double) 1.0))
         {
            fprintf(stderr, "%s: Maximum Partial Substructure (MPS) threshold must be greater than 0.0 and less than 1.0\n", argv[0]);
            exit(1);
         }
         parameters->mps = TRUE;
         parameters->mpsThreshold = doubleArg;
      }
      else if (strcmp(argv[i], "-maxAnomalousScore") == 0) 
      {
         i++;
         argumentExists = sscanf(argv[i], "%lf", &doubleArg);
         if ((argumentExists != 1) || (doubleArg <= (double) 0.0) || 
             (doubleArg >= (double) MAX_DOUBLE))
         {
            fprintf(stderr, "%s: maximum anomalous score must be greater than 0.0 and less than %lf\n", 
	            argv[0],MAX_DOUBLE);
            exit(1);
         }
	 //
	 // NOTE:  This check assumes that the user has specified a max
	 // anomalous score AFTER specifying they want to run the GBAD-P 
	 // algorithm.
	 //
         if (((doubleArg <= (double) 0.0) || (doubleArg >= 1.0)) &&
	     (parameters->prob))
         {
            fprintf(stderr, "%s: maximum anomalous score must be greater than 0.0 and less than 1.0\n",argv[0]);
            exit(1);
         }
         parameters->maxAnomalousScore = doubleArg;
      }
      else if (strcmp(argv[i], "-minAnomalousScore") == 0) 
      {
         i++;
         argumentExists = sscanf(argv[i], "%lf", &doubleArg);
         if ((argumentExists != 1) || (doubleArg < (double) 0.0) || 
             (doubleArg >= (double) MAX_DOUBLE))
         {
            fprintf(stderr, "%s: minimum anomalous score must be greater than or equal to 0.0 and less than %lf\n", argv[0],MAX_DOUBLE);
            exit(1);
         }
         parameters->minAnomalousScore = doubleArg;
      }
      else if (strcmp(argv[i], "-norm") == 0) 
      {
         i++;
         sscanf(argv[i], "%lu", &ulongArg);
         if (ulongArg < 1)
         {
            fprintf(stderr, "%s: you must specify a value of 1 or greater.\n", argv[0]);
            exit(1);
         }
         parameters->norm = ulongArg;
      }
      else if (strcmp(argv[i], "-sim") == 0) 
      {
         i++;
         sscanf(argv[i], "%lf", &doubleArg);
         if ((doubleArg < (double) 0.0) || (doubleArg > (double) 1.0))
        {
            fprintf(stderr, "%s: similarity measurement must be between 0.0 and 1.0.\n", argv[0]);
            exit(1);
         }
         parameters->similarity = doubleArg;
      }
      else 
      {
         fprintf(stderr, "%s: unknown option %s\n", argv[0], argv[i]);
         exit(1);
      }
      i++;
   }

   if ((parameters->mdl) || (parameters->prob) || (parameters->mps)) 
      parameters->noAnomalyDetection = FALSE;

   if (parameters->iterations == 0)
      parameters->iterations = MAX_UNSIGNED_LONG; // infinity

   // initialize log2Factorial[0..1]
   parameters->log2Factorial = (double *) malloc(2 * sizeof(double));
   if (parameters->log2Factorial == NULL)
      OutOfMemoryError("GetParameters:parameters->log2Factorial");
   parameters->log2FactorialSize = 2;
   parameters->log2Factorial[0] = 0; // lg(0!)
   parameters->log2Factorial[1] = 0; // lg(1!)

   // read graphs from input file
   strcpy(parameters->inputFileName, argv[argc - 1]);
   parameters->labelList = AllocateLabelList();
   parameters->posGraph = NULL;
   parameters->numPosEgs = 0;
   parameters->posEgsVertexIndices = NULL;

   ReadInputFile(parameters);
   if (parameters->evalMethod == EVAL_MDL)
   {
      parameters->posGraphDL = MDL(parameters->posGraph,
                                  parameters->labelList->numLabels, parameters);
   }

   // read predefined substructures
   parameters->numPreSubs = 0;
   if (parameters->predefinedSubs)
      ReadPredefinedSubsFile(parameters);

   parameters->incrementList = malloc(sizeof(IncrementList));
   parameters->incrementList->head = NULL;

   // create output file, if given
   if (parameters->outputToFile) 
   {
      outputFile = fopen(parameters->outFileName, "w");
      if (outputFile == NULL) 
      {
         printf("ERROR: unable to write to output file %s\n",
                parameters->outFileName);
         exit(1);
      }
      fclose(outputFile);
   }  

   if (parameters->numPosEgs == 0)
   {
      fprintf(stderr, "ERROR: no positive graphs defined\n");
      exit(1);
   }

   // Check bounds on discovered substructures' number of vertices
   if (parameters->maxVertices == 0)
      parameters->maxVertices = parameters->posGraph->numVertices;
   if (parameters->maxVertices < parameters->minVertices)
   {
      fprintf(stderr, "ERROR: minsize exceeds maxsize\n");
      exit(1);
   }

   // Set limit accordingly
   if (parameters->limit == 0)
   {
      parameters->limit = parameters->posGraph->numEdges / 2;
   }

   return parameters;
}
Пример #4
0
Parameters *GetParameters(int argc, char *argv[])
{
   Parameters *parameters;
   int i;
   double doubleArg;

   if (argc < 3)
   {
      fprintf(stderr, "%s: not enough arguments\n", argv[0]);
      exit(1);
   }

   parameters = (Parameters *) malloc(sizeof(Parameters));
   if (parameters == NULL)
      OutOfMemoryError("GetParameters:parameters");

   // initialize default parameter settings
   parameters->directed = TRUE;
   parameters->allowInstanceOverlap = FALSE;
   parameters->threshold = 0.0;
   parameters->outputToFile = FALSE;
   parameters->posGraph = NULL;
   parameters->negGraph = NULL;

   // process command-line options
   i = 1;
   while (i < (argc - 2))
   {
      if (strcmp(argv[i], "-dot") == 0)
      {
         i++;
         strcpy(parameters->outFileName, argv[i]);
         parameters->outputToFile = TRUE;
      } 
      else if (strcmp(argv[i], "-overlap") == 0) 
      {
         parameters->allowInstanceOverlap = TRUE;
      } 
      else if (strcmp(argv[i], "-threshold") == 0) 
      {
         i++;
         sscanf(argv[i], "%lf", &doubleArg);
         if ((doubleArg < 0.0) || (doubleArg > 1.0)) 
         {
            fprintf(stderr, "%s: threshold must be 0.0-1.0\n", argv[0]);
            exit(1);
         }
         parameters->threshold = doubleArg;
      } 
      else 
      {
         fprintf(stderr, "%s: unknown option %s\n", argv[0], argv[i]);
         exit(1);
      }
      i++;
   }

   // initialize log2Factorial[0..1]
   parameters->log2Factorial = (double *) malloc(2 * sizeof(double));
   if (parameters->log2Factorial == NULL)
      OutOfMemoryError("GetParameters:paramters->log2Factorial");
   parameters->log2FactorialSize = 2;
   parameters->log2Factorial[0] = 0; // lg(0!)
   parameters->log2Factorial[1] = 0; // lg(1!)

   parameters->labelList = AllocateLabelList();

   return parameters;
}