Esempio n. 1
0
File: main.c Progetto: pgrz/porr
int main (int argc, char **argv )
{
    if (argc < 4 || argc > 5)
    {
        usage();
    }

    vertex_count=str2int(argv[1]);
    edge_count=str2int(argv[2]);
    max_weight=str2int(argv[3]);
    
    if(argc == 5)
    {
        int il = str2int(argv[4]);
        if((il >= ERROR && il <= DEBUG) || (il == TEST))
        {
            level = il;
        }
    }

    //Seed init
    srand( ( unsigned short ) time( NULL ) );

    //Fix imbalanced graph
    max_edges = (vertex_count * ( vertex_count - 1 )) / 2;
    edge_count = (edge_count > max_edges) ?  max_edges : edge_count;

    random_graph();

    if(adj_matrix != 0)
    {
        print_graph();

        runAlgorithm(DIJKSTRA);
        if(valid > 0)
        {
            runAlgorithm(AUCTION);
            log(TEST, -1, "%d\t%d\t%d\t%d\t%d\t%f\t%f", vertex_count, edge_count, max_weight, dijk_dist, auct_dist, dijk_time, auct_time);
        }

    }
    else
    {
        log(WARNING, -1, "Graph not generated!");
    }

    return 0;
}
Esempio n. 2
0
rspfRefPtr<rspfImageData> rspfTwoColorView::getTile(const rspfIrect& rect,
                                                       rspf_uint32 resLevel)
{
   rspf_uint32 tileIdx = 0;
   if(m_byPassFlag||!isSourceEnabled())
   {
      return getNextTile(tileIdx, 0, rect, resLevel);
   }
   if(!m_twoColorTile.valid())
   {
      allocate();
   }
   if(!m_twoColorTile.valid())
   {
      return m_twoColorTile;
   }
   m_twoColorTile->setImageRectangle(rect);
   m_twoColorTile->makeBlank();
   
   rspfRefPtr<rspfImageData> newData = m_newInput->getTile(rect, resLevel);
   rspfRefPtr<rspfImageData> oldData = m_oldInput->getTile(rect, resLevel);

   runAlgorithm(newData.get(), oldData.get());

   m_twoColorTile->validate();

   return m_twoColorTile;
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(WIDTH,HEIGHT);
    glOrtho(0,WIDTH,HEIGHT,0,0,10);
    glutCreateWindow("Walk Of A King");
    runAlgorithm();
    return 0;
}
Esempio n. 4
0
void ttCatchgame::draw(){
    ofSetColor(0, 100);
    ofRect(0, 0, ofGetWidth(), ofGetHeight());
    // distance detection
    ofPoint dist = cursorIn-targetPos;
    if (dist.length()< targetSize+cursorSize &&
        control->bAllTouch == true)
        indicator += increaseSpeed;
    else if (dist.length()>=targetSize+cursorSize && indicator>=0)
        indicator -= decreaseSpeed;
    
    //outline
//    ofSetColor(255,200);
//    logo->draw(start.x-logo->getWidth()/2, start.y-logo->getHeight()/2);
    ofSetColor(255,200);
    ofNoFill();
    ofCircle(start, goal);
    
    //indicator
    ofSetColor(255,200);
    ofFill();
    ofCircle(start, indicator);
    
    
    
    //cursorIn
    ofColor cursorColor = ofColor::blanchedAlmond;
    if (dist.length()<targetSize+cursorSize) cursorColor = ofColor::cadetBlue;
    ofSetColor(cursorColor,200);
    ofCircle(cursorIn, cursorSize);
    
    //moving prompt
    ofColor targetColor = ofColor::crimson;
    float alpha = abs(sin(ofGetElapsedTimef()*3)*50);
    ofSetColor(targetColor,150+alpha);
    runAlgorithm(3);
    ofCircle(targetPos, targetSize);
    
    if (indicator>goal)bFinish = true;
    
    
}
Esempio n. 5
0
int main( int argc, char *argv[]){
   runAlgorithm(argc, argv, qsort_gcc);
   return 0;
}
int main(int argc, char** argv){
  std::cout << "LANDMARK ESTIMATOR" << std::endl;
  std::cout << "==================" << std::endl;
  
  // check the input
  if(argc < 2){
    std::cout << "Usage: LadmarksEstimator <traj_file>\n";
    exit(0);
  }
  
  init();
  
  // create structures for storing datas
  std::vector<RobotPosition*> * poses = new std::vector<RobotPosition*>();  // absolute poses
  std::vector<RobotPosition*> * transformations = new std::vector<RobotPosition*>();
  std::list<Landmark *> landmarks_list;	// this is a buffer
  
  // add the first node
  transformations->push_back(new RobotPosition(0,0,0));
  
  // load other nodes from file
  readTrajFromFile(std::string(argv[1]), transformations);
  
  if(transformations->size() < 1){
    std::cout << "no infos loaded... quitting" << std::endl;
    exit(0);
  }
  
  runAlgorithm(poses, transformations, &landmarks_list);
  
  bool first_run = true;
  
  while(true){	// exit is performed inside handleEvents method
    std::cout << std::endl << std::endl <<  "algorithm finished. Now press:"<<std::endl;
    std::cout << "\tR key to rerun the algorithm assuming the new poses as initial guess" << std::endl;
    std::cout << "\tESC to quit" <<std::endl;
    next_run = false;
    printState(&landmarks_list, poses);
    while(!next_run){
      handleEvents(_drawer->getWindow());
      _drawer->draw();
      usleep(200);
    }
    _drawer->clearAll();
    
    // when the program arrives here, it means that the user has asked for another algorithm round
    
    //std::vector<RobotPosition*> * newtransformations = new std::vector<RobotPosition*>();
    transformations->clear();
    posesToTransformations(poses, transformations);
    
    // remove old stuff
    landmarks_list.clear();
    poses->clear();
    optimizer->clear();	// this also calls delete method on the poses and landmarks involved
    
    // reset id counter
    next_id = 0;
    
    // change parameters?
    //_confirm_obs += 5;
    //_optimize_every += 10;
    
    // relaunch the algorithm
    runAlgorithm(poses ,transformations, &landmarks_list);
  }

  return 0;
}
Esempio n. 7
0
int getCommands()
{
	printf("Welcome to the Keyboard Layout Optimizer. If you have questions or comments, contact Michael Dickens by email ([email protected]) or leave a comment at http://mathematicalmulticore.wordpress.com/category/keyboards/.\n");
	printf("Type \"help\" for a listing of commands.\n\n");

	int length = 5000;
	char cmd[length];

	do {
		printf(">>> ");
		fgets(cmd, length, stdin);

		cmd[strlen(cmd)-1] = '\0'; // Remove the newline.

		if (streq(cmd, "help")) {
			printf("algorithm: Run the keyboard optimization algorithm.\n");
			printf("best swap <filename>: For the first layout in <filename>, print the single swap that would improve the layout the most.\n");
			printf("compare <filename>: Print information about the keyboards in <filename>. The keyboards must be in the proper format.\n");
			printf("damaging <filename>: Find the most damaging digraphs for the keyboard layouts in <filename>.\n");
			printf("game: Play a keyboard layout game.\n");
			printf("get <variable>: Get the value of the specified variable.\n");
			printf("improve <filename>: Try to improve the first keyboard in <filename>. The keyboard must be in the proper format.\n");
			printf("make typing data: Use the files in freq_types to customize character and digraph frequency.\n");
            printf("run: See 'algorithm'.\n");
			printf("set <variable> <value>: Set the specified variable to the given value.\n");
			printf("setksize <K_setting>: Set the keyboard type. Type \"setksize help\" for more information.\n");
			printf("test fitness: Test that the fitness functions are working properly.\n");
			printf("use <keys>: Use <keys> in the keyboard layout instead of the default.\n");
			printf("worst <filename>: Find the worst digraphs for the keyboard layouts in <filename>.\n");
			printf("variables: Print all variables that can be modified.\n");
			printf("quit: Quit the keyboard optimization program.\n");
			printf("\n");

		} else if (streq(cmd, "algorithm") || streq(cmd, "run")) {
			printf("Running the keyboard optimization algorithm. Press ctrl-C to quit.\n\n");
			runAlgorithm();

		} else if (streqn(cmd, "best swap ", strlen("best swap "))) {
			const char *const filename = cmd + strlen("best swap ");
			FILE *file = fopen(filename, "r");
			CHECK_FILE_FOR_NULL(file, filename);
			
			Keyboard k;
			if (layoutFromFile(file, &k) != -1) {
				bestSwap(&k);
			}

			fclose(file);

		} else if (streqn(cmd, "compare ", 8)) {
			compare(cmd + 8);

		} else if (streqn(cmd, "damaging ", 9)) {
			const char *const filename = cmd + 9;
			worstDigraphsFromFile(filename, TRUE);

		} else if (streq(cmd, "game")) {
			game();

		} else if (streqn(cmd, "get ", 4)) {
			getValue(cmd + 4);

		} else if (streqn(cmd, "improve ", strlen("improve "))) {
			improveFromFile(cmd + 8);

		} else if (streq(cmd, "make typing data")) {
			makeTypingData();

		} else if (streqn(cmd, "set ", strlen("set "))) {
			setValue(cmd + 4);

		} else if (streqn(cmd, "setksize ", strlen("setksize "))) {
			size_t str_len = strlen("setksize ");
			if (streq(cmd + str_len, "no")) {
				setksize(K_NO);
				printf("Keyboard set to non-full. All user-defined values have been reset.\n\n");
			} else if (streq(cmd + str_len, "standard")) {
				setksize(K_STANDARD);
				printf("Keyboard set to full standard. All user-defined values have been reset.\n\n");
			} else if (streq(cmd + str_len, "kinesis")) {
				setksize(K_KINESIS);
				printf("Keyboard set to full Kinesis. All user-defined values have been reset.\n\n");
			} else if (streq(cmd + str_len, "iphone")) {
				setksize(K_IPHONE);
				printf("Keyboard set to iPhone. All user-defined values have been reset.\n\n");
			} else {
				printf("Undefined input. Valid inputs: \"setksize no\" (do not use full keyboard), \"setksize standard\" (use standard full keyboard), \"setksize kinesis\" (use Kinesis full keyboard).\n\n");
			}

		} else if (streq(cmd, "test fitness")) {
			testFitness();
		
		} else if (streqn(cmd, "use ", 4)) {
			strcpy(keysToInclude, cmd + 4);
			initTypingData();
			
			printf("Now using keys: %s\n\n", cmd + 4);

		} else if (streq(cmd, "variables")) {
			printf("Boolean variables should be set to 0 for false and 1 for true. Variables not specified as booleans are integers.\n");
            
            int i;
            for (i = 0; i < variablesLength; ++i) {
                printf("\t%s", variables[i].name);
                if (variables[i].description)
                    printf(": %s", variables[i].description);
                printf("\n");
            }
            
            printf("\n");

		} else if (streqn(cmd, "worst ", 6)) {
			const char *const filename = cmd + 6;
			worstDigraphsFromFile(filename, FALSE);

		} else if (streq(cmd, "quit")) {
			printf("Goodbye!\n");
			break;

		} else {
			printf("Unknown command. Type \"help\" for a listing of commands.\n\n");
		}


	} while (strcmp(cmd, "exit") != 0);

	return 0;
}
Esempio n. 8
0
int main( int argc, char *argv[]){
   srand(time(NULL));
   runAlgorithm(argc, argv, quicksort);
   return 0;
}