Beispiel #1
0
int main(int argc, char* argv[]){
   int i, n=8;
   List S = newList();
   Graph G = newGraph(n);
   Graph T=NULL, C=NULL;

   for(i=1; i<=n; i++) append(S, i);

   addArc(G, 1,2);
   addArc(G, 1,5);
   addArc(G, 2,5);
   addArc(G, 2,6);
   addArc(G, 3,2);
   addArc(G, 3,4);
   addArc(G, 3,6);
   addArc(G, 3,7);
   addArc(G, 3,8);
   addArc(G, 6,5);
   addArc(G, 6,7);
   addArc(G, 8,4);
   addArc(G, 8,7);
   printGraph(stdout, G);

   DFS(G, S);
   fprintf(stdout, "\n");
   fprintf(stdout, "x:  d  f  p\n");
   for(i=1; i<=n; i++){
      fprintf(stdout, "%d: %2d %2d %2d\n", i, getDiscover(G, i), getFinish(G, i), getParent(G, i));
   }
   fprintf(stdout, "\n");
   printList(stdout, S);
   fprintf(stdout, "\n");

   T = transpose(G);
   C = copyGraph(G);
   fprintf(stdout, "\n");
   printGraph(stdout, C);
   fprintf(stdout, "\n");
   printGraph(stdout, T);
   fprintf(stdout, "\n");

   DFS(T, S);
   fprintf(stdout, "\n");
   fprintf(stdout, "x:  d  f  p\n");
   for(i=1; i<=n; i++){
      fprintf(stdout, "%d: %2d %2d %2d\n", i, getDiscover(T, i), getFinish(T, i), getParent(T, i));
   }
   fprintf(stdout, "\n");
   printList(stdout, S);
   fprintf(stdout, "\n");

   freeList(&S);
   freeGraph(&G);
   freeGraph(&T);
   freeGraph(&C);
   return(0);
}
/*main------------------------------------------------------------------------*/
int main(int argc, char* argv[]) {

    //input validation
    if (argc != 2) {
        printf("Usage: %s output\n", argv[0]);
        exit(1);
    }

    //open file
    FILE *out;
    out = fopen(argv[1], "w");

    //new graph
    Graph G = newGraph(10);
    Graph T;
    List S = newList();
    int i;
    for (i = 1; i <= 9; i++) {
        addArc(G, i, i + 1);
    }
    addArc(G, 1, 2);

    //add graph and print out the adjacency fields
    for (i = 1; i <= getOrder(G); i++) {
        append(S, i);
    }
    fprintf(out, "\nThe adjacency list of G is:\n");
    printGraph(out, G);

    //Run DFS and get the transpose
    DFS(G, S);
    T = transpose(G);
    fprintf(out, "\nTranspose of G is:\n");
    printGraph(out, T);

    //print out fields
    fprintf(out, "Order of G is %d\n", getOrder(G));
    fprintf(out, "Size of G is %d.\n", getSize(G));
    fprintf(out, "Parent of 10 is %d.\n", getParent(G, 10));
    fprintf(out, "Parent of 3 is %d.\n", getParent(G, 3));
    fprintf(out, "Discover time of 1 is %d.\n", getDiscover(G, 1));
    fprintf(out, "Finish time of 1 is %d.\n", getFinish(G, 1));
    fprintf(out, "Discover time of 9 is %d.\n", getDiscover(G, 9));
    fprintf(out, "Finish time of 9 is %d.\n", getFinish(G, 9));

    //close file
    fclose(out);

    //exit
    return (0);
}
Beispiel #3
0
Coordinate getInsertionMarkerPosition(InsertionMarker * marker)
{
	if (marker->isStart)
		return getStart(marker->annot);
	else
		return getFinish(marker->annot);
}
Beispiel #4
0
void Box::print(){
  std::cout << "=== Box ===" << std::endl; 
  std::cout << "Corner 1: <" << corner1.x << ",  " << corner1.y << ", " << corner1.z << ">" << std::endl; 
  std::cout << "Corner 2: <" << corner2.x << ",  " << corner2.y << ", " << corner2.z << ">" << std::endl; 
  getPigment().printPigment();
  getFinish().printFinish();
  std::cout << std::endl;
}
Beispiel #5
0
MainMenuScene::MainMenuScene()
{
    setName("MainMenuScene");
    //create background
    spSprite sky = new Sprite;
    sky->setResAnim(res::ui.getResAnim("bg"));
    sky->attachTo(_view);
    sky->setSize(getStage()->getSize());


    //create logo
    spSprite logo = new Sprite;
    logo->setResAnim(res::ui.getResAnim("logo2"));
    logo->attachTo(_view);
    logo->setPosition(_view->getSize() - logo->getSize());



    //create play button at center
    spSprite btn = new MyButton;
    btn->setName("play");
    btn->setResAnim(res::ui.getResAnim("play"));
    btn->setAnchor(0.5f, 0.5f);
    btn->setPosition(_view->getSize() / 2);
    btn->attachTo(_view);

    //handle click to button
    btn->addEventListener(TouchEvent::CLICK, CLOSURE(this, &MainMenuScene::onEvent));


    //create menu button
    btn = new MyButton;
    btn->setName("exit");
    btn->setResAnim(res::ui.getResAnim("menu"));
    btn->setAnchor(0.5f, 0.5f);
    btn->attachTo(_view);

    //align it to top right
    btn->setX(_view->getWidth() - btn->getWidth() / 2);
    btn->setY(btn->getHeight() / 2);

    btn->addEventListener(TouchEvent::CLICK, CLOSURE(this, &MainMenuScene::onEvent));

	addBackHandler(getFinish());
}
Beispiel #6
0
int main(int argc, char* argv[]){
   int order = 8;	//the number of nodes in our Graph G
   Graph G = newGraph(order);
   List S = newList();

   //insert numbers into List S
   for(int i=1; i<=8; i++){
      append(S, i);
   }
   
   printf("Here is our Graph G when first initialized\n");
   printGraph(stdout, G);
   printf("Here is our List S\n");
   printList(stdout, S);
   printf("\n\n");


   //calling addArc() to assign edges to our Graph G
   addArc(G, 1, 2);
   addArc(G, 2, 3);
   addArc(G, 3, 4);
   addArc(G, 4, 3);
   addArc(G, 4, 8);
   addArc(G, 8, 8);
   addArc(G, 7, 8);
   addArc(G, 3, 7);
   addArc(G, 7, 6);
   addArc(G, 6, 7);
   addArc(G, 2, 6);
   addArc(G, 5, 6);
   addArc(G, 5, 1);
   addArc(G, 2, 5); 

   printf("Here is the adjacency list representation of G after adding our directed edges\n");
   printGraph(stdout, G);
   printf("\n");
   
   //Test that transpose() works properly
   Graph T = transpose(G);
   printf("Here is the transpose of G:\n");
   printGraph(stdout, T);

   printf("The order of G is: %d\n", getOrder(G));
   printf("The size of G is: %d\n", getSize(G));
   printf("The parent of node 2 is: %d\n", getParent(G, 2));
   printf("The discover time of node 2 is: %d\n", getDiscover(G, 2));
   printf("The finish tim of node 2 is: %d\n\n\n", getFinish(G, 2));

   DFS(G,S);

   printf("Here is our List S after running DFS():\n");
   printList(stdout, S);
   printf("\n");   
   //Test that discover time, finish time, and parent fields correct after call to DFS()
   for(int i = 1; i<=order; i++){
      printf("Node %d: discovery time = %d ; finish time = %d ; parent = %d\n", 
               i, getDiscover(G, i), getFinish(G, i), getParent(G, i));
   }

   //Test that copyGraph() works properly
   Graph C = copyGraph(G);
   printf("Here is the copy of G:\n");
   printGraph(stdout, C);
   for(int i = 1; i<=order; i++){
      printf("Node %d: discovery time = %d ; finish time = %d ; parent = %d\n", 
               i, getDiscover(C, i), getFinish(C, i), getParent(C, i));
   }

   freeList(&S);
   freeGraph(&G);
   freeGraph(&T);
   freeGraph(&C);
   return(0);
}
Beispiel #7
0
int main(int argc, char* argv[]){
   int i, n=8;
   List S = newList();
   Graph G = newGraph(n);
   Graph T=NULL, C=NULL;

   Graph G_undir = newGraph(35);
   for(i=1; i<35; i++) {
      if( i%7!=0 ) addEdge(G_undir, i, i+1);
      if( i<=28 ) addEdge(G_undir, i, i+7);
   }
   printf("The Order of this undirected graph is: %d\n", getOrder(G_undir));
   printf("The Size of this undirected graph is: %d\n", getSize(G_undir));
   printf("Adjacency list representation of G_undir: \n");
   printGraph(stdout, G_undir);
   printf("\n");

   for(i=1; i<=n; i++) append(S, i);

   addArc(G, 1,2);
   addArc(G, 1,5);
   addArc(G, 2,5);
   addArc(G, 2,6);
   addArc(G, 3,2);
   addArc(G, 3,4);
   addArc(G, 3,6);
   addArc(G, 3,7);
   addArc(G, 3,8);
   addArc(G, 6,5);
   addArc(G, 6,7);
   addArc(G, 8,4);
   addArc(G, 8,7);
   printf("The Order of this graph is: %d\n", getOrder(G));
   printf("The Size of this graph is: %d\n", getSize(G));
   printf("Adjacency list representation of G: \n");
   printGraph(stdout, G);

   DFS(G, S);
   fprintf(stdout, "\n");
   fprintf(stdout, "x:  d  f  p\n");
   for(i=1; i<=n; i++){
      fprintf(stdout, "%d: %2d %2d %2d\n", i, getDiscover(G, i), getFinish(G, i), getParent(G, i));
   }
   fprintf(stdout, "\n");
   printList(stdout, S);
   fprintf(stdout, "\n");

   T = transpose(G);
   C = copyGraph(G);
   fprintf(stdout, "\n");
   printGraph(stdout, C);
   fprintf(stdout, "\n");
   printGraph(stdout, T);
   fprintf(stdout, "\n");

   DFS(T, S);
   fprintf(stdout, "\n");
   fprintf(stdout, "x:  d  f  p\n");
   for(i=1; i<=n; i++){
      fprintf(stdout, "%d: %2d %2d %2d\n", i, getDiscover(T, i), getFinish(T, i), getParent(T, i));
   }
   fprintf(stdout, "\n");
   printList(stdout, S);
   fprintf(stdout, "\n");

   freeList(&S);
   freeGraph(&G);
   freeGraph(&T);
   freeGraph(&C);
   return(0);
}