void UCIParser<double, std::string>::StoreLastLabel() { // see if it was already stored as a string label if (m_lastLabelIsString) return; StoreLabel(0); // we already stored a numeric version of this label in the numbers array // so get rid of that, the user wants it as a string m_numbers->pop_back(); PrepareStartNumber(); }
ULONG ReadLabel(FILE *fp, LabelList *labelList, ULONG *pLineNo) { char token[TOKEN_LEN]; char *endptr; Label label; ReadToken(token, fp, pLineNo); label.labelType = NUMERIC_LABEL; label.labelValue.numericLabel = strtod(token, &endptr); if (*endptr != '\0') { label.labelType = STRING_LABEL; label.labelValue.stringLabel = token; } return StoreLabel(&label, labelList); }
void UCIParser<NumType, LabelType>::DoneWithValue() { // if we are storing it if (m_numbers != NULL) { NumType FinalResult = 0; if (m_current_state == Exponent) { FinalResult = (NumType)(m_partialResult * pow(10.0, m_exponentMultiplier * m_builtUpNumber)); } else if (m_divider != 0) { FinalResult = (NumType)(m_partialResult + (m_builtUpNumber / m_divider)); } else { FinalResult = (NumType) m_builtUpNumber; } FinalResult = (NumType)(FinalResult * m_wholeNumberMultiplier); // if it's a label, store in label location instead of number location int index = m_elementsConvertedThisLine; bool stored = false; if (m_startLabels <= index && index < m_startLabels + m_dimLabels) { StoreLabel(FinalResult); stored = true; } if (m_startFeatures <= index && index < m_startFeatures + m_dimFeatures) { m_numbers->push_back(FinalResult); m_totalNumbersConverted++; m_numbersConvertedThisLine++; m_elementsConvertedThisLine++; m_lastLabelIsString = false; stored = true; } // if we haven't stored anything we need to skip the current symbol, so increment if (!stored) { m_elementsConvertedThisLine++; } } PrepareStartNumber(); }
int main(int argc, char **argv) { Parameters *parameters; ULONG numLabels; Graph *g1; Graph *g2; Graph *g2compressed; InstanceList *instanceList; ULONG numInstances; ULONG subSize, graphSize, compressedSize; double subDL, graphDL, compressedDL; double value; Label label; parameters = GetParameters(argc, argv); g1 = ReadGraph(argv[argc - 2], parameters->labelList, parameters->directed); g2 = ReadGraph(argv[argc - 1], parameters->labelList, parameters->directed); instanceList = FindInstances(g1, g2, parameters); numInstances = CountInstances(instanceList); printf("Found %lu instances.\n\n", numInstances); g2compressed = CompressGraph(g2, instanceList, parameters); // Compute and print compression-based measures subSize = GraphSize(g1); graphSize = GraphSize(g2); compressedSize = GraphSize(g2compressed); value = ((double) graphSize) / (((double) subSize) + ((double) compressedSize)); printf("Size of graph = %lu\n", graphSize); printf("Size of substructure = %lu\n", subSize); printf("Size of compressed graph = %lu\n", compressedSize); printf("Value = %f\n\n", value); // Compute and print MDL based measures numLabels = parameters->labelList->numLabels; subDL = MDL(g1, numLabels, parameters); graphDL = MDL(g2, numLabels, parameters); numLabels++; // add one for new "SUB" vertex label if ((parameters->allowInstanceOverlap) && (InstancesOverlap(instanceList))) numLabels++; // add one for new "OVERLAP" edge label compressedDL = MDL(g2compressed, numLabels, parameters); // add extra bits to describe where external edges connect to instances compressedDL += ExternalEdgeBits(g2compressed, g1, numInstances); value = graphDL / (subDL + compressedDL); printf("DL of graph = %f\n", graphDL); printf("DL of substructure = %f\n", subDL); printf("DL of compressed graph = %f\n", compressedDL); printf("Value = %f\n\n", value); if (parameters->outputToFile) { // first, actually add "SUB" and "OVERLAP" labels label.labelType = STRING_LABEL; label.labelValue.stringLabel = SUB_LABEL_STRING; StoreLabel(& label, parameters->labelList); label.labelValue.stringLabel = OVERLAP_LABEL_STRING; StoreLabel(& label, parameters->labelList); parameters->posGraph = g2compressed; WriteGraphToDotFile(parameters->outFileName, parameters); printf("Compressed graph written to dot file %s\n", parameters->outFileName); } FreeGraph(g2compressed); FreeInstanceList(instanceList); FreeGraph(g1); FreeGraph(g2); FreeParameters(parameters); return 0; }
void UCIParser<double, std::string>::DoneWithLabel() { if (m_labels != NULL) StoreLabel(0); // store the string label PrepareStartNumber(); }