Exemple #1
0
void outputTree(Knoten **wurzel) {
  if (*wurzel != nullptr) {
    outputTree(&(*wurzel)->left);
    std::printf("%d\n", (*wurzel)->data);
    outputTree(&(*wurzel)->right);
  }
}
Exemple #2
0
static void outputTree(Node **wurzel) {
  if (*wurzel != nullptr) {
    outputTree(&(*wurzel)->left);
    printf("%-20s%10d%10d\n",
           (*wurzel)->data.name,
           (*wurzel)->data.erstesVorkommen,
           (*wurzel)->data.anzahl);
    outputTree(&(*wurzel)->right);
  }
}
Exemple #3
0
void EFMGenerator::generateCombinations(int metaboliteIndex, int inputCount, int outputCount) {
   bptInput.init();
   bptOutput.init();
   bptNonpart.init();
   //Identify input, output and non-participating pathways for the given metabolite
   int prevSize = pathways.size();
   for (int i = prevSize - 1, in = 0, out = inputCount; i >= 0; i--) {
      if (pathways[i].isInput(metaboliteIndex)) {
         pathwaysPtr[in++] = &pathways[i];
         bptInput.addPathway(&pathways[i]);
      } else if (pathways[i].isOutput(metaboliteIndex)) {
         pathwaysPtr[out++] = &pathways[i];
         bptOutput.addPathway(&pathways[i]);
      } else {
         bptNonpart.addPathway(&pathways[i]);
      }
   }
   //Create reversible trees for inputs and outputs
   ReversibleTree inputTree(pathwaysPtr, 0, inputCount);
   ReversibleTree outputTree(pathwaysPtr, inputCount, inputCount + outputCount);
   //Generate combinations
   generateCombinations(inputTree.getRoot(), outputTree.getRoot());
   //Update list of pathways in the network
   for (int i = pathways.size() - 1; i >= prevSize; i--) {
      pathways[i].updateMetaboliteCoefficients(metaboliteIndex);
   }
   for (int i = prevSize - 1; i >= 0; i--) {
      if (pathways[i].isInput(metaboliteIndex) || pathways[i].isOutput(metaboliteIndex)) {
         pathways.remove(i);
      }
   }
   clearBPTNodePool();
   clearRevNodePool();
}
TargetDescriptorConstPtr ConcolicTargetGenerator::permuteTarget(EventHandlerDescriptorConstPtr eventHandler,
                                       TargetDescriptorConstPtr oldTarget,
                                       ExecutionResultConstPtr result) const
{
    // Notice that this function can be called multiple times with the same "oldTarget" and "result", because of how Artemis functions.
    // In this case the concolic analysis can return new explorations until there is nothing left to explore in the execution tree.

    // We only start the symbolic session for the last event to be executed, and permuteTarget is only called for the
    // last event in an event sequence! -- we can assume that the event sequence reaching this event is constant.

    // oldTarget should be of type ConcolicTargetDescriptor
    ConcolicTargetDescriptorConstPtr target = oldTarget.dynamicCast<const ConcolicTarget>();
    assert(!target.isNull());

    QString eventName = eventHandler->toString();

    // Request suggestions of new targets to explore from the concolic analysis.
    ConcolicAnalysis::ExplorationResult exploration = target->getAnalysis()->nextExploration();

    if (!exploration.newExploration) {
        Log::debug("Could not find any new exploration");
        outputTree(target->getAnalysis()->getExecutionTree(), eventName, target->getAnalysis()->getExplorationIndex());
        return TargetDescriptorConstPtr(NULL);
    }

    Log::debug("Found solution for new target value:");
    printSolution(exploration.solution);

    outputTree(target->getAnalysis()->getExecutionTree(), eventName, target->getAnalysis()->getExplorationIndex());

    // The symbolic variable for the target will be TARGET_0.
    Symbolvalue newTarget = exploration.solution->findSymbol("SYM_TARGET_0");
    assert(newTarget.found); // TODO: should probably be a soft requirement once we are sure everything is working??
    QString targetXPath = QString::fromStdString(newTarget.string);

    // If a target is found, then return a ConcolicTarget with the context and a representation (xpath) of the target.
    // The runtime will call "get" on the target in the next iteration and use the xpath to find the real target.

    return TargetDescriptorConstPtr(new ConcolicTarget(eventHandler, targetXPath, target->getAnalysis(), exploration.target));

}
Exemple #5
0
int main(int argc, char const *argv[]) {
  Knoten *baum    = nullptr;
  int     eingabe = 0;
  float   zahl    = 574.4;
  std::printf("%lx\n", *(unsigned long *)(&zahl));

  for (int i = 0; i < 5; i++) {
    printf("Bitte Zahl[%d]: ", i);
    std::scanf("%d", &eingabe);
    insertNode(&baum, eingabe);
  }
  outputTree(&baum);
  return 0;
}
Exemple #6
0
/* function main begins program execution */
int main(void)
{ 
   int i; /* counter to loop from 1-10 */
   int item; /* variable to hold random values */
   TreeNodePtr rootPtr = NULL; /* tree initially empty */

   srand( time( NULL ) ); 
   printf( "The numbers being placed in the tree are:\n" );

   /* insert random values between 1 and 15 in the tree */
   for ( i = 1; i <= 10; i++ ) { 
      item = 1 + rand() % 10;
      printf( "%3d", item );
      insertNode( &rootPtr, item );
   } /* end for */

   printf("\n\nInsert the value to remove: ");
   scanf("%d", &item);

   if( deleteNode( &rootPtr, item ) ) {
      printf("Value not found or value is root: %d\n", item);
      return -1;
   }

   /* traverse the tree preOrder */
   printf( "\nThe preOrder traversal is:\n" );
   preOrder( rootPtr );

   /* traverse the tree inOrder */
   printf( "\n\nThe inOrder traversal is:\n" );
   inOrder( rootPtr );

   /* traverse the tree postOrder */
   printf( "\n\nThe postOrder traversal is:\n" );
   postOrder( rootPtr );

   /* traverse the tree levelOrder */
   printf( "\n\nThe levelOrder traversal is:\n" );
   levelOrder( rootPtr );

   puts("\n\nShow the tree\n\n");
   outputTree(rootPtr, 0);

   putchar('\n');

   return 0; /* indicates successful termination */

} /* end main */
Exemple #7
0
/* 
 * Show a binary tree
*/
void outputTree(TreeNodePtr root, int totalSpaces)
{
   int i;
   TreeNodePtr currentNode = root;

   while( currentNode != NULL ) {

      outputTree(currentNode->rightPtr, totalSpaces + 5);

      for(i = 1; i <= totalSpaces; i++)
	 putchar(' ');
      printf("%d\n", currentNode->data);

      currentNode = currentNode->leftPtr;
      totalSpaces += 5;
   }

} /* eof outputTree() */
Exemple #8
0
auto_ptr<AlignmentSteps> RootedClusterTree::treeFromDistMatrix(RootedGuideTree* phyloTree,DistMatrix* distMat, Alignment *alignPtr,
                                           int seq1, int nSeqs, string& phylipName)
{
    OutputFile phylipPhyTreeFile;
    auto_ptr<AlignmentSteps> progSteps;
    try
    {
        // Test to see if the inputs are valid
        if(seq1 < 1 || nSeqs < 1)
        {
            cerr << "Invalid inputs into treeFromDistMatrix \n"
                 << "seq1 = " << seq1 << " nSeqs = " << nSeqs << "\n"
                 << "Need to end program!\n";
            exit(1);
            return progSteps;
        }

        float dist;
        string path;
        verbose = false;
        firstSeq = seq1;
        lastSeq = firstSeq + nSeqs - 1;

        SeqInfo info;
        info.firstSeq = firstSeq;
        info.lastSeq = lastSeq;
        info.numSeqs = nSeqs;

        utilityObject->getPath(userParameters->getSeqName(), &path);

        if(nSeqs >= 2)
        {
            string name = phylipName;
            if(!phylipPhyTreeFile.openFile(&name,
                             "\nEnter name for new GUIDE TREE           file  ", &path, "dnd",
                             "Guide tree"))
            {
                return progSteps;
            }
            phylipName = name;
        }
        else
        {
            return progSteps;
        }

        RootedTreeOutput outputTree(&info);

        ofstream* ptrToFile = phylipPhyTreeFile.getPtrToFile();

        if (nSeqs == 2)
        {
            dist = (*distMat)(firstSeq, firstSeq + 1) / 2.0;
            if(ptrToFile->is_open())
            {
                (*ptrToFile) <<  "(" << alignPtr->getName(firstSeq) << ":"
                             << setprecision(5)
                             << dist << "," << alignPtr->getName(firstSeq + 1) << ":"
                             << setprecision(5) << dist <<");\n";
            }
            progSteps.reset(new AlignmentSteps);
            vector<int> groups;
            groups.resize(nSeqs + 1, 0);
            groups[1] = 1;
            groups[2] = 2;
        }
        else
        {
            UPGMAAlgorithm clusAlgorithm;
            progSteps = clusAlgorithm.generateTree(phyloTree, distMat, &info, false);
            outputTree.printPhylipTree(phyloTree, ptrToFile, alignPtr, distMat);
        }
        return progSteps;
    }
    catch(const exception &ex)
    {
        cerr << "ERROR: Error has occured in treeFromDistMatrix. "
             << "Need to terminate program.\n"
             << ex.what();
        exit(1);
    }
    catch(...)
    {
        cerr << "ERROR: Error has occured in treeFromDistMatrix. "
             << "Need to terminate program.\n";
        exit(1);
    }
}
Exemple #9
0
void RootedClusterTree::treeFromAlignment(TreeNames* treeNames, Alignment *alignPtr)
{
    try
    {
        OutputFile phylipPhyTreeFile;
        OutputFile clustalPhyTreeFile;
        OutputFile distancesPhyTreeFile;
        OutputFile nexusPhyTreeFile;
        OutputFile pimFile;

        RootedGuideTree phyloTree;

        string path;
        int j;
        int overspill = 0;
        int totalDists;
        numSeqs = alignPtr->getNumSeqs(); // NOTE class variable

        /**
         * Check if numSeqs is ok
         */
        if(!checkIfConditionsMet(numSeqs, 2))
        {
            return;
        }

        firstSeq = 1;
        lastSeq = numSeqs;

        // The SeqInfo struct is passed to reduce the number of parameters passed!
        SeqInfo info;
        info.firstSeq = firstSeq;
        info.lastSeq = lastSeq;
        info.numSeqs = numSeqs;

        RootedTreeOutput outputTree(&info); // No bootstrap!

        utilityObject->getPath(userParameters->getSeqName(), &path);

        /**
         * Open the required output files.
         */
        if(!openFilesForTreeFromAlignment(&clustalPhyTreeFile, &phylipPhyTreeFile,
                        &distancesPhyTreeFile, &nexusPhyTreeFile, &pimFile, treeNames, &path))
        {
            return; // Problem opeing one of the files, cannot continue!
        }

        int _lenFirstSeq = alignPtr->getSeqLength(firstSeq);

        bootPositions.clear();
        bootPositions.resize(_lenFirstSeq + 2);

        for (j = 1; j <= _lenFirstSeq; ++j)
        {
            bootPositions[j] = j;
        }

        /**
         * Calculate quickDist and overspill
         */
        overspill = calcQuickDistMatForAll(clustalPhyTreeFile.getPtrToFile(),
                       phylipPhyTreeFile.getPtrToFile(), nexusPhyTreeFile.getPtrToFile(),
                       pimFile.getPtrToFile(), distancesPhyTreeFile.getPtrToFile(), alignPtr);

        // check if any distances overflowed the distance corrections
        if (overspill > 0)
        {
            totalDists = (numSeqs *(numSeqs - 1)) / 2;
            overspillMessage(overspill, totalDists);
        }

        if (userParameters->getOutputTreeClustal())
        {
            verbose = true;
        }
        // Turn on file output


        if (userParameters->getOutputTreeClustal() ||
            userParameters->getOutputTreePhylip()
            || userParameters->getOutputTreeNexus())
        {
            UPGMAAlgorithm clusAlgorithm;
            clusAlgorithm.setVerbose(true);
            clusAlgorithm.generateTree(&phyloTree, quickDistMat.get(), &info, false,
                                       clustalPhyTreeFile.getPtrToFile());
            clusAlgorithm.setVerbose(false);
        }

        if (userParameters->getOutputTreePhylip())
        {
            outputTree.printPhylipTree(&phyloTree, phylipPhyTreeFile.getPtrToFile(), alignPtr,
                                        quickDistMat.get());
        }

        if (userParameters->getOutputTreeNexus())
        {
            outputTree.printNexusTree(&phyloTree, nexusPhyTreeFile.getPtrToFile(), alignPtr,
                                       quickDistMat.get());
        }

        /** Free up resources!!!!! */

        treeGaps.clear();
        bootPositions.clear();

    }
    catch(const exception& ex)
    {
        cerr << ex.what() << endl;
        utilityObject->error("Terminating program. Cannot continue\n");
        exit(1);
    }
}
Exemple #10
0
// Wrapper
void outputWordlist(Node **wurzel) {
  printf("\nAusgabe der Wortliste: \n\n");
  printf("%-20s%10s%10s\n", "Name", "First", "Anzahl");
  outputTree(wurzel);
}